File: omnibox_util.h

package info (click to toggle)
chromium 139.0.7258.127-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,096 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (109 lines) | stat: -rw-r--r-- 4,158 bytes parent folder | download | duplicates (5)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_APP_LIST_SEARCH_OMNIBOX_OMNIBOX_UTIL_H_
#define CHROME_BROWSER_ASH_APP_LIST_SEARCH_OMNIBOX_OMNIBOX_UTIL_H_

#include <memory>
#include <string>
#include <vector>

#include "ash/public/cpp/app_list/app_list_types.h"
#include "chromeos/crosapi/mojom/launcher_search.mojom.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "ui/base/page_transition_types.h"

class AutocompleteController;
class FaviconCache;
class GURL;

namespace bookmarks {

class BookmarkModel;

}  // namespace bookmarks

namespace app_list {

class OmniboxResult;

// The magic number 1500 is the highest score of an omnibox result.
// See comments in autocomplete_provider.h.
inline constexpr double kMaxOmniboxScore = 1500.0;

// Traffic annotation details for fetching Omnibox image icons.
inline constexpr net::NetworkTrafficAnnotationTag kOmniboxTrafficAnnotation =
    net::DefineNetworkTrafficAnnotation("cros_launcher_omnibox", R"(
        semantics {
          sender: "Chrome OS Launcher"
          description:
            "Chrome OS provides search suggestions when a user types a query "
            "into the launcher. This request downloads an image icon for a "
            "suggested result in order to provide more information."
          trigger:
            "Change of results for the query typed by the user into the "
            "launcher."
          data:
            "URL of the image to be downloaded. This URL corresponds to "
            "search suggestions for the user's query."
          destination: GOOGLE_OWNED_SERVICE
        }
        policy {
          cookies_allowed: NO
          setting:
            "Search autocomplete and suggestions can be disabled in Chrome OS "
            "settings. Image icons cannot be disabled separately to this."
          policy_exception_justification:
            "No content is uploaded or saved, this request downloads a "
            "publicly available image."
        })");

// Some omnibox answers overtrigger on short queries. This controls the minimum
// query length before they are displayed.
inline constexpr size_t kMinQueryLengthForCommonAnswers = 4u;

// Returns the tag vector for the given text type.
ash::SearchResultTags TagsForText(const std::u16string& text,
                                  crosapi::mojom::SearchResult::TextType type);

// Whether this URL points to a Drive location.
bool IsDriveUrl(const GURL& url);

// Removes duplicate results from the given list, with higher-priority results
// taking precedence over lower. After calling this function, the list will be
// sorted in descending order of priority.
void RemoveDuplicateResults(
    std::vector<std::unique_ptr<OmniboxResult>>& results);

// Returns the UI page transition that corresponds to the given crosapi page
// transition.
ui::PageTransition PageTransitionToUiPageTransition(
    crosapi::mojom::SearchResult::PageTransition transition);

// Creates an Omnibox answer card result from the AutocompleteMatch. Match must
// either have its answer field populated or be a calculator result.
crosapi::mojom::SearchResultPtr CreateAnswerResult(
    const AutocompleteMatch& match,
    AutocompleteController* controller,
    std::u16string_view query,
    const AutocompleteInput& input);

// Creates an Omnibox search result from the AutocompleteMatch. Match must not
// have its answer field populated or be a calculator result.
crosapi::mojom::SearchResultPtr CreateResult(
    const AutocompleteMatch& match,
    AutocompleteController* controller,
    FaviconCache* favicon_cache,
    bookmarks::BookmarkModel* bookmark_model,
    const AutocompleteInput& input);

// Convenience function to compare crosapi bools.
inline bool OptionalBoolIsTrue(crosapi::mojom::SearchResult::OptionalBool b) {
  return b == crosapi::mojom::SearchResult::OptionalBool::kTrue;
}

}  // namespace app_list

#endif  // CHROME_BROWSER_ASH_APP_LIST_SEARCH_OMNIBOX_OMNIBOX_UTIL_H_