File: lens_overlay_url_builder.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (138 lines) | stat: -rw-r--r-- 5,902 bytes parent folder | download | duplicates (3)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2024 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_UI_LENS_LENS_OVERLAY_URL_BUILDER_H_
#define CHROME_BROWSER_UI_LENS_LENS_OVERLAY_URL_BUILDER_H_

#include <map>
#include <optional>
#include <string>

#include "base/time/time.h"
#include "components/lens/lens_overlay_invocation_source.h"
#include "third_party/lens_server_proto/lens_overlay_cluster_info.pb.h"
#include "third_party/lens_server_proto/lens_overlay_request_id.pb.h"
#include "third_party/lens_server_proto/lens_overlay_selection_type.pb.h"
#include "url/gurl.h"

namespace lens {

void AppendTranslateParamsToMap(std::map<std::string, std::string>& params,
                                const std::string& query,
                                const std::string& content_language);

void AppendStickinessSignalForFormula(
    std::map<std::string, std::string>& params,
    const std::string& formula);

GURL AppendCommonSearchParametersToURL(const GURL& url_to_modify,
                                       bool use_dark_mode);

GURL AppendVideoContextParamToURL(const GURL& url_to_modify,
                                  std::optional<GURL> page_url);

GURL AppendDarkModeParamToURL(const GURL& url_to_modify, bool use_dark_mode);

GURL AppendInvocationSourceParamToURL(
    const GURL& url_to_modify,
    lens::LensOverlayInvocationSource invocation_source);

GURL BuildTextOnlySearchURL(
    base::Time query_start_time,
    const std::string& text_query,
    std::optional<GURL> page_url,
    std::optional<std::string> page_title,
    std::map<std::string, std::string> additional_search_query_params,
    lens::LensOverlayInvocationSource invocation_source,
    lens::LensOverlaySelectionType lens_selection_type,
    bool use_dark_mode);

GURL BuildLensSearchURL(
    base::Time query_start_time,
    std::optional<std::string> text_query,
    std::optional<GURL> page_url,
    std::optional<std::string> page_title,
    std::unique_ptr<lens::LensOverlayRequestId> request_id,
    lens::LensOverlayClusterInfo cluster_info,
    std::map<std::string, std::string> additional_search_query_params,
    lens::LensOverlayInvocationSource invocation_source,
    bool use_dark_mode);

// Returns the value of the text query parameter value from the provided search
// URL if any. Empty string otherwise.
const std::string GetTextQueryParameterValue(const GURL& url);

// Returns the value of the lens mode parameter value from the provided search
// URL if any. Empty string otherwise.
const std::string GetLensModeParameterValue(const GURL& url);

// Returns true if the two URLs have the same base url, and the same query
// parameters. This differs from comparing two GURLs using == since this method
// will ensure equivalence even if there are empty query params, viewport
// params, or different query param ordering.
bool AreSearchUrlsEquivalent(const GURL& a, const GURL& b);

// Returns whether the given |url| contains all the common search query
// parameters required to properly enable the lens overlay results in the side
// panel. This does not check the value of these query parameters.
bool HasCommonSearchQueryParameters(const GURL& url);

// Returns whether the given |url| is a valid lens overlay search URL. This
// could differ from values in common APIs since the search URL is set via a
// finch configured flag.
bool IsValidSearchResultsUrl(const GURL& url);

// Returns whether the `url` is a valid lens overlay search URL but contains
// parameters known not to be supported in the side panel and thus should be
// opened in a new tab.
bool ShouldOpenSearchURLInNewTab(const GURL& url);

// Returns whether the given |url| is a valid lens overlay search redirect URL.
// This could differ from values in common APIs since the search URL is set via
// a finch configured flag.
GURL GetSearchResultsUrlFromRedirectUrl(const GURL& url);

// Removes parameters that frequently change on the SRP URL due to redirects or
// client changes without changing the actual results. This allows us to compare
// search url's accurately in AddQueryToHistory when the side panel is resized
// or when the SRP redirects to append parameters unrelated to the search
// results.
GURL RemoveIgnoredSearchURLParameters(const GURL& url);

// Remove parameters that cause the SRP to be rendered for the side panel. Used
// when opening the SRP in a new tab.
GURL RemoveSidePanelURLParameters(const GURL& url);

// Returns the URL to open in a new tab by adding a unique vsrid to the side
// panel new tab URL. If the given URL is empty, or is a URL for a contextual
// query, returns an empty URL since they cannot be opened in a new tab.
GURL GetSidePanelNewTabUrl(const GURL& side_panel_url, std::string vsrid);

// Builds the appropriate translate service URL for fetching supported
// languages.
GURL BuildTranslateLanguagesURL(std::string_view country,
                                std::string_view language);

// Returns whether |lens_selection_type| should be considered as a text-only
// selection type.
bool IsLensTextSelectionType(
    lens::LensOverlaySelectionType lens_selection_type);

// Returns whether `first_url` is equal to `second_url` when the text fragment
// is stripped from the ref if it exists at all. This fragment is stripped from
// both URLs.
bool URLsMatchWithoutTextFragment(const GURL& first_url,
                                  const GURL& second_url);

// Adds the `text_fragments` and `pdf_page_number` to the ref attribute of `url`
// without modifying any part of the rest of the URL. Any information in the
// current ref of `url` is discarded.
GURL AddPDFScrollToParametersToUrl(
    const GURL& url,
    const std::vector<std::string>& text_fragments,
    int pdf_page_number);

}  // namespace lens

#endif  // CHROME_BROWSER_UI_LENS_LENS_OVERLAY_URL_BUILDER_H_