File: query_in_omnibox.h

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (70 lines) | stat: -rw-r--r-- 2,918 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_OMNIBOX_BROWSER_QUERY_IN_OMNIBOX_H_
#define COMPONENTS_OMNIBOX_BROWSER_QUERY_IN_OMNIBOX_H_

#include "base/macros.h"
#include "base/strings/string16.h"
#include "components/security_state/core/security_state.h"
#include "url/gurl.h"

class AutocompleteClassifier;
class TemplateURLService;

// This class holds the business logic for Query in Omnibox shared between both
// Android and Desktop.
class QueryInOmnibox {
 public:
  QueryInOmnibox(AutocompleteClassifier* autocomplete_classifier,
                 TemplateURLService* template_url_service);

  // Returns true if the toolbar should display the search terms. When this
  // method returns true, the extracted search terms will be filled into
  // |search_terms| if its not nullptr.
  //
  // This method will return false if any of the following are true:
  //  - Query in Omnibox is disabled
  //  - |security_level| is insufficient to show search terms instead of the URL
  //  - |url| is not from the default search provider
  //  - There are no search terms to extract from |url|
  //  - The extracted search terms look too much like a URL (could confuse user)
  //
  // This method can be called with nullptr |search_terms| if the caller wants
  // to check the display status only.
  bool GetDisplaySearchTerms(security_state::SecurityLevel security_level,
                             const GURL& url,
                             base::string16* search_terms);

  //  Sets a flag telling the model to ignore the security level in its check
  // for whether to display search terms or not. This is useful for avoiding the
  // flicker that occurs when loading a SRP URL before our SSL state updates.
  void set_ignore_security_level(bool ignore_security_level) {
    ignore_security_level_ = ignore_security_level;
  }

 private:
  // Extracts search terms from |url|. Returns an empty string if |url| is not
  // from the default search provider, if there are no search terms in |url|,
  // or if the extracted search terms look too much like a URL.
  base::string16 ExtractSearchTermsInternal(const GURL& url);

  // If true, the security level preconditions are ignored for displaying the
  // query in the omnibox.
  bool ignore_security_level_ = false;

  // Because extracting search terms from a URL string is relatively expensive,
  // and we want to support cheap calls to GetDisplaySearchTerms, cache the
  // result of the last-parsed URL string.
  base::string16 cached_search_terms_;
  GURL cached_url_;

  // Non-owning weak pointers.
  AutocompleteClassifier* const autocomplete_classifier_;
  TemplateURLService* const template_url_service_;

  DISALLOW_COPY_AND_ASSIGN(QueryInOmnibox);
};

#endif  // COMPONENTS_OMNIBOX_BROWSER_QUERY_IN_OMNIBOX_H_