Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. | |
|
beaudoin
2014/03/04 21:33:15
// The empty string is considered valid and should
huangs
2014/03/04 22:10:43
Done.
| |
| 15 if (provider.length() > 8) | |
| 16 return false; | |
| 17 for (base::string16::const_iterator it = provider.begin(); | |
| 18 it != provider.end(); ++it) { | |
| 19 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it)) | |
| 20 return false; | |
| 21 } | |
| 22 return true; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 11 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, | 27 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, |
| 12 Delegate* delegate, scoped_ptr<Policy> policy) | 28 Delegate* delegate, scoped_ptr<Policy> policy) |
| 13 : WebContentsObserver(web_contents), | 29 : WebContentsObserver(web_contents), |
| 14 delegate_(delegate), | 30 delegate_(delegate), |
| 15 policy_(policy.Pass()), | 31 policy_(policy.Pass()), |
| 16 is_active_tab_(false) { | 32 is_active_tab_(false) { |
| 17 DCHECK(web_contents); | 33 DCHECK(web_contents); |
| 18 DCHECK(delegate); | 34 DCHECK(delegate); |
| 19 DCHECK(policy_.get()); | 35 DCHECK(policy_.get()); |
| 20 } | 36 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, | 151 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, |
| 136 OnSearchBoxNavigate); | 152 OnSearchBoxNavigate); |
| 137 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, | 153 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, |
| 138 OnDeleteMostVisitedItem); | 154 OnDeleteMostVisitedItem); |
| 139 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion, | 155 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion, |
| 140 OnUndoMostVisitedDeletion); | 156 OnUndoMostVisitedDeletion); |
| 141 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions, | 157 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions, |
| 142 OnUndoAllMostVisitedDeletions); | 158 OnUndoAllMostVisitedDeletions); |
| 143 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogEvent, OnLogEvent); | 159 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogEvent, OnLogEvent); |
| 144 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogImpression, OnLogImpression); | 160 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogImpression, OnLogImpression); |
| 161 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogNavigation, OnLogNavigation); | |
| 145 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown, | 162 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown, |
| 146 OnPasteAndOpenDropDown); | 163 OnPasteAndOpenDropDown); |
| 147 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck, | 164 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck, |
| 148 OnChromeIdentityCheck); | 165 OnChromeIdentityCheck); |
| 149 IPC_MESSAGE_UNHANDLED(handled = false) | 166 IPC_MESSAGE_UNHANDLED(handled = false) |
| 150 IPC_END_MESSAGE_MAP() | 167 IPC_END_MESSAGE_MAP() |
| 151 return handled; | 168 return handled; |
| 152 } | 169 } |
| 153 | 170 |
| 154 void SearchIPCRouter::OnInstantSupportDetermined(int page_id, | 171 void SearchIPCRouter::OnInstantSupportDetermined(int page_id, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 delegate_->OnInstantSupportDetermined(true); | 258 delegate_->OnInstantSupportDetermined(true); |
| 242 if (!policy_->ShouldProcessLogEvent()) | 259 if (!policy_->ShouldProcessLogEvent()) |
| 243 return; | 260 return; |
| 244 | 261 |
| 245 delegate_->OnLogEvent(event); | 262 delegate_->OnLogEvent(event); |
| 246 } | 263 } |
| 247 | 264 |
| 248 void SearchIPCRouter::OnLogImpression(int page_id, | 265 void SearchIPCRouter::OnLogImpression(int page_id, |
| 249 int position, | 266 int position, |
| 250 const base::string16& provider) const { | 267 const base::string16& provider) const { |
| 251 if (!web_contents()->IsActiveEntry(page_id)) | 268 if (!web_contents()->IsActiveEntry(page_id) || !IsProviderValid(provider)) |
| 252 return; | 269 return; |
| 253 | 270 |
| 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); | 271 delegate_->OnInstantSupportDetermined(true); |
| 264 // Logging impressions is controlled by the same policy as logging events. | 272 // Logging impressions is controlled by the same policy as logging events. |
| 265 if (!policy_->ShouldProcessLogEvent()) | 273 if (!policy_->ShouldProcessLogEvent()) |
| 266 return; | 274 return; |
| 267 | 275 |
| 268 delegate_->OnLogImpression(position, provider); | 276 delegate_->OnLogImpression(position, provider); |
| 269 } | 277 } |
| 270 | 278 |
| 279 void SearchIPCRouter::OnLogNavigation(int page_id, | |
| 280 int position, | |
| 281 const base::string16& provider) const { | |
| 282 if (!web_contents()->IsActiveEntry(page_id) || !IsProviderValid(provider)) | |
| 283 return; | |
| 284 | |
| 285 delegate_->OnInstantSupportDetermined(true); | |
| 286 // Logging navigations is controlled by the same policy as logging events. | |
| 287 if (!policy_->ShouldProcessLogEvent()) | |
| 288 return; | |
| 289 | |
| 290 delegate_->OnLogNavigation(position, provider); | |
| 291 } | |
| 292 | |
| 271 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_id, | 293 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_id, |
| 272 const base::string16& text) const { | 294 const base::string16& text) const { |
| 273 if (!web_contents()->IsActiveEntry(page_id)) | 295 if (!web_contents()->IsActiveEntry(page_id)) |
| 274 return; | 296 return; |
| 275 | 297 |
| 276 delegate_->OnInstantSupportDetermined(true); | 298 delegate_->OnInstantSupportDetermined(true); |
| 277 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_)) | 299 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_)) |
| 278 return; | 300 return; |
| 279 | 301 |
| 280 delegate_->PasteIntoOmnibox(text); | 302 delegate_->PasteIntoOmnibox(text); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 295 | 317 |
| 296 void SearchIPCRouter::set_delegate(Delegate* delegate) { | 318 void SearchIPCRouter::set_delegate(Delegate* delegate) { |
| 297 DCHECK(delegate); | 319 DCHECK(delegate); |
| 298 delegate_ = delegate; | 320 delegate_ = delegate; |
| 299 } | 321 } |
| 300 | 322 |
| 301 void SearchIPCRouter::set_policy(scoped_ptr<Policy> policy) { | 323 void SearchIPCRouter::set_policy(scoped_ptr<Policy> policy) { |
| 302 DCHECK(policy.get()); | 324 DCHECK(policy.get()); |
| 303 policy_.reset(policy.release()); | 325 policy_.reset(policy.release()); |
| 304 } | 326 } |
| OLD | NEW |