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

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: Remove unused consts. 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox); 152 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox);
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_LogMostVisitedImpression,
163 OnLogMostVisitedImpression);
164 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogMostVisitedNavigation,
165 OnLogMostVisitedNavigation);
145 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown, 166 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown,
146 OnPasteAndOpenDropDown); 167 OnPasteAndOpenDropDown);
147 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck, 168 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck,
148 OnChromeIdentityCheck); 169 OnChromeIdentityCheck);
149 IPC_MESSAGE_UNHANDLED(handled = false) 170 IPC_MESSAGE_UNHANDLED(handled = false)
150 IPC_END_MESSAGE_MAP() 171 IPC_END_MESSAGE_MAP()
151 return handled; 172 return handled;
152 } 173 }
153 174
154 void SearchIPCRouter::OnInstantSupportDetermined(int page_id, 175 void SearchIPCRouter::OnInstantSupportDetermined(int page_id,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 if (!web_contents()->IsActiveEntry(page_id)) 259 if (!web_contents()->IsActiveEntry(page_id))
239 return; 260 return;
240 261
241 delegate_->OnInstantSupportDetermined(true); 262 delegate_->OnInstantSupportDetermined(true);
242 if (!policy_->ShouldProcessLogEvent()) 263 if (!policy_->ShouldProcessLogEvent())
243 return; 264 return;
244 265
245 delegate_->OnLogEvent(event); 266 delegate_->OnLogEvent(event);
246 } 267 }
247 268
248 void SearchIPCRouter::OnLogImpression(int page_id, 269 void SearchIPCRouter::OnLogMostVisitedImpression(
249 int position, 270 int page_id, int position, const base::string16& provider) const {
250 const base::string16& provider) const { 271 if (!web_contents()->IsActiveEntry(page_id) || !IsProviderValid(provider))
251 if (!web_contents()->IsActiveEntry(page_id))
252 return; 272 return;
253 273
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); 274 delegate_->OnInstantSupportDetermined(true);
264 // Logging impressions is controlled by the same policy as logging events. 275 // Logging impressions is controlled by the same policy as logging events.
265 if (!policy_->ShouldProcessLogEvent()) 276 if (!policy_->ShouldProcessLogEvent())
266 return; 277 return;
267 278
268 delegate_->OnLogImpression(position, provider); 279 delegate_->OnLogMostVisitedImpression(position, provider);
280 }
281
282 void SearchIPCRouter::OnLogMostVisitedNavigation(
283 int page_id, int position, 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_->OnLogMostVisitedNavigation(position, provider);
269 } 293 }
270 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;
(...skipping 16 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