1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h"
6 
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/search/search.h"
9 #include "content/public/browser/web_contents.h"
10 
SearchIPCRouterPolicyImpl(content::WebContents * web_contents)11 SearchIPCRouterPolicyImpl::SearchIPCRouterPolicyImpl(
12     content::WebContents* web_contents)
13     : web_contents_(web_contents), is_incognito_(true) {
14   DCHECK(web_contents);
15 
16   Profile* profile =
17       Profile::FromBrowserContext(web_contents_->GetBrowserContext());
18   if (profile)
19     is_incognito_ = profile->IsOffTheRecord();
20 }
21 
~SearchIPCRouterPolicyImpl()22 SearchIPCRouterPolicyImpl::~SearchIPCRouterPolicyImpl() {}
23 
ShouldProcessFocusOmnibox(bool is_active_tab)24 bool SearchIPCRouterPolicyImpl::ShouldProcessFocusOmnibox(bool is_active_tab) {
25   return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
26 }
27 
ShouldProcessDeleteMostVisitedItem()28 bool SearchIPCRouterPolicyImpl::ShouldProcessDeleteMostVisitedItem() {
29   return !is_incognito_ && search::IsInstantNTP(web_contents_);
30 }
31 
ShouldProcessUndoMostVisitedDeletion()32 bool SearchIPCRouterPolicyImpl::ShouldProcessUndoMostVisitedDeletion() {
33   return !is_incognito_ && search::IsInstantNTP(web_contents_);
34 }
35 
ShouldProcessUndoAllMostVisitedDeletions()36 bool SearchIPCRouterPolicyImpl::ShouldProcessUndoAllMostVisitedDeletions() {
37   return !is_incognito_ && search::IsInstantNTP(web_contents_);
38 }
39 
ShouldProcessAddCustomLink()40 bool SearchIPCRouterPolicyImpl::ShouldProcessAddCustomLink() {
41   return !is_incognito_ && search::IsInstantNTP(web_contents_);
42 }
43 
ShouldProcessUpdateCustomLink()44 bool SearchIPCRouterPolicyImpl::ShouldProcessUpdateCustomLink() {
45   return !is_incognito_ && search::IsInstantNTP(web_contents_);
46 }
47 
ShouldProcessReorderCustomLink()48 bool SearchIPCRouterPolicyImpl::ShouldProcessReorderCustomLink() {
49   return !is_incognito_ && search::IsInstantNTP(web_contents_);
50 }
51 
ShouldProcessDeleteCustomLink()52 bool SearchIPCRouterPolicyImpl::ShouldProcessDeleteCustomLink() {
53   return !is_incognito_ && search::IsInstantNTP(web_contents_);
54 }
55 
ShouldProcessUndoCustomLinkAction()56 bool SearchIPCRouterPolicyImpl::ShouldProcessUndoCustomLinkAction() {
57   return !is_incognito_ && search::IsInstantNTP(web_contents_);
58 }
59 
ShouldProcessResetCustomLinks()60 bool SearchIPCRouterPolicyImpl::ShouldProcessResetCustomLinks() {
61   return !is_incognito_ && search::IsInstantNTP(web_contents_);
62 }
63 
ShouldProcessToggleMostVisitedOrCustomLinks()64 bool SearchIPCRouterPolicyImpl::ShouldProcessToggleMostVisitedOrCustomLinks() {
65   return !is_incognito_ && search::IsInstantNTP(web_contents_);
66 }
67 
ShouldProcessToggleShortcutsVisibility()68 bool SearchIPCRouterPolicyImpl::ShouldProcessToggleShortcutsVisibility() {
69   return !is_incognito_ && search::IsInstantNTP(web_contents_);
70 }
71 
ShouldProcessLogEvent()72 bool SearchIPCRouterPolicyImpl::ShouldProcessLogEvent() {
73   return !is_incognito_ && search::IsInstantNTP(web_contents_);
74 }
75 
ShouldProcessLogSuggestionEventWithValue()76 bool SearchIPCRouterPolicyImpl::ShouldProcessLogSuggestionEventWithValue() {
77   return !is_incognito_ && search::IsInstantNTP(web_contents_);
78 }
79 
ShouldProcessPasteIntoOmnibox(bool is_active_tab)80 bool SearchIPCRouterPolicyImpl::ShouldProcessPasteIntoOmnibox(
81     bool is_active_tab) {
82   return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
83 }
84 
ShouldSendSetInputInProgress(bool is_active_tab)85 bool SearchIPCRouterPolicyImpl::ShouldSendSetInputInProgress(
86     bool is_active_tab) {
87   return is_active_tab && !is_incognito_;
88 }
89 
ShouldSendOmniboxFocusChanged()90 bool SearchIPCRouterPolicyImpl::ShouldSendOmniboxFocusChanged() {
91   return !is_incognito_;
92 }
93 
ShouldSendMostVisitedInfo()94 bool SearchIPCRouterPolicyImpl::ShouldSendMostVisitedInfo() {
95   return !is_incognito_ && search::IsInstantNTP(web_contents_);
96 }
97 
ShouldSendNtpTheme()98 bool SearchIPCRouterPolicyImpl::ShouldSendNtpTheme() {
99   return !is_incognito_ && search::IsInstantNTP(web_contents_);
100 }
101 
ShouldSendLocalBackgroundSelected()102 bool SearchIPCRouterPolicyImpl::ShouldSendLocalBackgroundSelected() {
103   return !is_incognito_ && search::IsInstantNTP(web_contents_);
104 }
105 
ShouldProcessSelectLocalBackgroundImage()106 bool SearchIPCRouterPolicyImpl::ShouldProcessSelectLocalBackgroundImage() {
107   return !is_incognito_ && search::IsInstantNTP(web_contents_);
108 }
109 
ShouldProcessSetCustomBackgroundInfo()110 bool SearchIPCRouterPolicyImpl::ShouldProcessSetCustomBackgroundInfo() {
111   return !is_incognito_ && search::IsInstantNTP(web_contents_);
112 }
113 
ShouldProcessBlocklistSearchSuggestion()114 bool SearchIPCRouterPolicyImpl::ShouldProcessBlocklistSearchSuggestion() {
115   return !is_incognito_ && search::IsInstantNTP(web_contents_);
116 }
117 
118 bool SearchIPCRouterPolicyImpl::
ShouldProcessBlocklistSearchSuggestionWithHash()119     ShouldProcessBlocklistSearchSuggestionWithHash() {
120   return !is_incognito_ && search::IsInstantNTP(web_contents_);
121 }
122 
ShouldProcessSearchSuggestionSelected()123 bool SearchIPCRouterPolicyImpl::ShouldProcessSearchSuggestionSelected() {
124   return !is_incognito_ && search::IsInstantNTP(web_contents_);
125 }
126 
ShouldProcessOptOutOfSearchSuggestions()127 bool SearchIPCRouterPolicyImpl::ShouldProcessOptOutOfSearchSuggestions() {
128   return !is_incognito_ && search::IsInstantNTP(web_contents_);
129 }
130 
ShouldProcessThemeChangeMessages()131 bool SearchIPCRouterPolicyImpl::ShouldProcessThemeChangeMessages() {
132   return !is_incognito_ && search::IsInstantNTP(web_contents_);
133 }
134 
ShouldProcessAutocompleteResultChanged(bool is_active_tab)135 bool SearchIPCRouterPolicyImpl::ShouldProcessAutocompleteResultChanged(
136     bool is_active_tab) {
137   return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
138 }
139 
ShouldProcessAutocompleteMatchImageAvailable(bool is_active_tab)140 bool SearchIPCRouterPolicyImpl::ShouldProcessAutocompleteMatchImageAvailable(
141     bool is_active_tab) {
142   return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
143 }
144 
ShouldProcessQueryAutocomplete(bool is_active_tab)145 bool SearchIPCRouterPolicyImpl::ShouldProcessQueryAutocomplete(
146     bool is_active_tab) {
147   return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
148 }
149 
ShouldProcessStopAutocomplete()150 bool SearchIPCRouterPolicyImpl::ShouldProcessStopAutocomplete() {
151   return !is_incognito_ && search::IsInstantNTP(web_contents_);
152 }
153 
ShouldProcessLogCharTypedToRepaintLatency()154 bool SearchIPCRouterPolicyImpl::ShouldProcessLogCharTypedToRepaintLatency() {
155   return !is_incognito_ && search::IsInstantNTP(web_contents_);
156 }
157 
ShouldProcessBlocklistPromo()158 bool SearchIPCRouterPolicyImpl::ShouldProcessBlocklistPromo() {
159   return !is_incognito_ && search::IsInstantNTP(web_contents_);
160 }
161 
ShouldProcessOpenExtensionsPage()162 bool SearchIPCRouterPolicyImpl::ShouldProcessOpenExtensionsPage() {
163   return !is_incognito_ && search::IsInstantNTP(web_contents_);
164 }
165 
ShouldProcessOpenAutocompleteMatch(bool is_active_tab)166 bool SearchIPCRouterPolicyImpl::ShouldProcessOpenAutocompleteMatch(
167     bool is_active_tab) {
168   return is_active_tab && !is_incognito_ && search::IsInstantNTP(web_contents_);
169 }
170 
ShouldProcessDeleteAutocompleteMatch()171 bool SearchIPCRouterPolicyImpl::ShouldProcessDeleteAutocompleteMatch() {
172   return !is_incognito_ && search::IsInstantNTP(web_contents_);
173 }
174 
175 bool SearchIPCRouterPolicyImpl::
ShouldProcessToggleSuggestionGroupIdVisibility()176     ShouldProcessToggleSuggestionGroupIdVisibility() {
177   return !is_incognito_ && search::IsInstantNTP(web_contents_);
178 }
179