Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/ui/search/search_ipc_router.cc

Issue 178253008: Redoing Issue 36073011: Allowing file:/// in Instant Extended's Most Visited links. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fixes; more symmetry to logImpression() and logNavigation(). Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/search_ipc_router.h" 5 #include "chrome/browser/ui/search/search_ipc_router.h"
6 6
7 #include "chrome/browser/search/search.h" 7 #include "chrome/browser/search/search.h"
8 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 10
11 namespace {
12
13 bool IsProviderValid(const base::string16& provider) {
14 // Only allow string of 8 alphanumeric characters or less as providers.
15 // The empty string is considered valid and should be treated as if no
16 // provider were specified.
17 if (provider.length() > 8)
18 return false;
19 for (base::string16::const_iterator it = provider.begin();
20 it != provider.end(); ++it) {
21 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it))
22 return false;
23 }
24 return true;
25 }
26
27 } // namespace
28
11 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, 29 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents,
12 Delegate* delegate, scoped_ptr<Policy> policy) 30 Delegate* delegate, scoped_ptr<Policy> policy)
13 : WebContentsObserver(web_contents), 31 : WebContentsObserver(web_contents),
14 delegate_(delegate), 32 delegate_(delegate),
15 policy_(policy.Pass()), 33 policy_(policy.Pass()),
16 is_active_tab_(false) { 34 is_active_tab_(false) {
17 DCHECK(web_contents); 35 DCHECK(web_contents);
18 DCHECK(delegate); 36 DCHECK(delegate);
19 DCHECK(policy_.get()); 37 DCHECK(policy_.get());
20 } 38 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, 153 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
136 OnSearchBoxNavigate); 154 OnSearchBoxNavigate);
137 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, 155 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem,
138 OnDeleteMostVisitedItem); 156 OnDeleteMostVisitedItem);
139 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion, 157 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion,
140 OnUndoMostVisitedDeletion); 158 OnUndoMostVisitedDeletion);
141 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions, 159 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions,
142 OnUndoAllMostVisitedDeletions); 160 OnUndoAllMostVisitedDeletions);
143 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogEvent, OnLogEvent); 161 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogEvent, OnLogEvent);
144 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogImpression, OnLogImpression); 162 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogImpression, OnLogImpression);
163 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogNavigation, OnLogNavigation);
145 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown, 164 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown,
146 OnPasteAndOpenDropDown); 165 OnPasteAndOpenDropDown);
147 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck, 166 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck,
148 OnChromeIdentityCheck); 167 OnChromeIdentityCheck);
149 IPC_MESSAGE_UNHANDLED(handled = false) 168 IPC_MESSAGE_UNHANDLED(handled = false)
150 IPC_END_MESSAGE_MAP() 169 IPC_END_MESSAGE_MAP()
151 return handled; 170 return handled;
152 } 171 }
153 172
154 void SearchIPCRouter::OnInstantSupportDetermined(int page_id, 173 void SearchIPCRouter::OnInstantSupportDetermined(int page_id,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 delegate_->OnInstantSupportDetermined(true); 260 delegate_->OnInstantSupportDetermined(true);
242 if (!policy_->ShouldProcessLogEvent()) 261 if (!policy_->ShouldProcessLogEvent())
243 return; 262 return;
244 263
245 delegate_->OnLogEvent(event); 264 delegate_->OnLogEvent(event);
246 } 265 }
247 266
248 void SearchIPCRouter::OnLogImpression(int page_id, 267 void SearchIPCRouter::OnLogImpression(int page_id,
249 int position, 268 int position,
250 const base::string16& provider) const { 269 const base::string16& provider) const {
251 if (!web_contents()->IsActiveEntry(page_id)) 270 if (!web_contents()->IsActiveEntry(page_id) || !IsProviderValid(provider))
252 return; 271 return;
253 272
254 // Only allow string of 8 alphanumeric characters or less as providers.
255 if (provider.length() > 8)
256 return;
257 for (base::string16::const_iterator it = provider.begin();
258 it != provider.end(); ++it) {
259 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it))
260 return;
261 }
262
263 delegate_->OnInstantSupportDetermined(true); 273 delegate_->OnInstantSupportDetermined(true);
264 // Logging impressions is controlled by the same policy as logging events. 274 // Logging impressions is controlled by the same policy as logging events.
265 if (!policy_->ShouldProcessLogEvent()) 275 if (!policy_->ShouldProcessLogEvent())
266 return; 276 return;
267 277
268 delegate_->OnLogImpression(position, provider); 278 delegate_->OnLogImpression(position, provider);
269 } 279 }
270 280
281 void SearchIPCRouter::OnLogNavigation(int page_id,
282 int position,
283 const base::string16& provider) const {
284 if (!web_contents()->IsActiveEntry(page_id) || !IsProviderValid(provider))
285 return;
286
287 delegate_->OnInstantSupportDetermined(true);
288 // Logging navigations is controlled by the same policy as logging events.
289 if (!policy_->ShouldProcessLogEvent())
290 return;
291
292 delegate_->OnLogNavigation(position, provider);
293 }
294
271 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_id, 295 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_id,
272 const base::string16& text) const { 296 const base::string16& text) const {
273 if (!web_contents()->IsActiveEntry(page_id)) 297 if (!web_contents()->IsActiveEntry(page_id))
274 return; 298 return;
275 299
276 delegate_->OnInstantSupportDetermined(true); 300 delegate_->OnInstantSupportDetermined(true);
277 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_)) 301 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_))
278 return; 302 return;
279 303
280 delegate_->PasteIntoOmnibox(text); 304 delegate_->PasteIntoOmnibox(text);
(...skipping 14 matching lines...) Expand all
295 319
296 void SearchIPCRouter::set_delegate(Delegate* delegate) { 320 void SearchIPCRouter::set_delegate(Delegate* delegate) {
297 DCHECK(delegate); 321 DCHECK(delegate);
298 delegate_ = delegate; 322 delegate_ = delegate;
299 } 323 }
300 324
301 void SearchIPCRouter::set_policy(scoped_ptr<Policy> policy) { 325 void SearchIPCRouter::set_policy(scoped_ptr<Policy> policy) {
302 DCHECK(policy.get()); 326 DCHECK(policy.get());
303 policy_.reset(policy.release()); 327 policy_.reset(policy.release());
304 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698