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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
12 #include "components/search/search.h" | 12 #include "components/search/search.h" |
13 #include "content/public/browser/navigation_details.h" | 13 #include "content/public/browser/navigation_details.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 | 15 |
16 namespace { | |
17 | |
18 bool IsProviderValid(const base::string16& provider) { | |
19 // Only allow string of 8 alphanumeric characters or less as providers. | |
20 // The empty string is considered valid and should be treated as if no | |
21 // provider were specified. | |
22 if (provider.length() > 8) | |
23 return false; | |
24 for (base::string16::const_iterator it = provider.begin(); | |
25 it != provider.end(); ++it) { | |
26 if (!base::IsAsciiAlpha(*it) && !base::IsAsciiDigit(*it)) | |
27 return false; | |
28 } | |
29 return true; | |
30 } | |
31 | |
32 } // namespace | |
33 | |
34 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, | 16 SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, |
35 Delegate* delegate, | 17 Delegate* delegate, |
36 std::unique_ptr<Policy> policy) | 18 std::unique_ptr<Policy> policy) |
37 : WebContentsObserver(web_contents), | 19 : WebContentsObserver(web_contents), |
38 delegate_(delegate), | 20 delegate_(delegate), |
39 policy_(std::move(policy)), | 21 policy_(std::move(policy)), |
40 commit_counter_(0), | 22 commit_counter_(0), |
41 is_active_tab_(false) { | 23 is_active_tab_(false) { |
42 DCHECK(web_contents); | 24 DCHECK(web_contents); |
43 DCHECK(delegate); | 25 DCHECK(delegate); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return; | 229 return; |
248 | 230 |
249 delegate_->OnInstantSupportDetermined(true); | 231 delegate_->OnInstantSupportDetermined(true); |
250 if (!policy_->ShouldProcessLogEvent()) | 232 if (!policy_->ShouldProcessLogEvent()) |
251 return; | 233 return; |
252 | 234 |
253 delegate_->OnLogEvent(event, time); | 235 delegate_->OnLogEvent(event, time); |
254 } | 236 } |
255 | 237 |
256 void SearchIPCRouter::OnLogMostVisitedImpression( | 238 void SearchIPCRouter::OnLogMostVisitedImpression( |
257 int page_seq_no, int position, const base::string16& provider) const { | 239 int page_seq_no, int position, NTPLoggingTileSource tile_source) const { |
258 if (page_seq_no != commit_counter_ || !IsProviderValid(provider)) | 240 if (page_seq_no != commit_counter_) |
259 return; | 241 return; |
260 | 242 |
261 delegate_->OnInstantSupportDetermined(true); | 243 delegate_->OnInstantSupportDetermined(true); |
262 // Logging impressions is controlled by the same policy as logging events. | 244 // Logging impressions is controlled by the same policy as logging events. |
263 if (!policy_->ShouldProcessLogEvent()) | 245 if (!policy_->ShouldProcessLogEvent()) |
264 return; | 246 return; |
265 | 247 |
266 delegate_->OnLogMostVisitedImpression(position, provider); | 248 delegate_->OnLogMostVisitedImpression(position, tile_source); |
267 } | 249 } |
268 | 250 |
269 void SearchIPCRouter::OnLogMostVisitedNavigation( | 251 void SearchIPCRouter::OnLogMostVisitedNavigation( |
270 int page_seq_no, int position, const base::string16& provider) const { | 252 int page_seq_no, int position, NTPLoggingTileSource tile_source) const { |
271 if (page_seq_no != commit_counter_ || !IsProviderValid(provider)) | 253 if (page_seq_no != commit_counter_) |
272 return; | 254 return; |
273 | 255 |
274 delegate_->OnInstantSupportDetermined(true); | 256 delegate_->OnInstantSupportDetermined(true); |
275 // Logging navigations is controlled by the same policy as logging events. | 257 // Logging navigations is controlled by the same policy as logging events. |
276 if (!policy_->ShouldProcessLogEvent()) | 258 if (!policy_->ShouldProcessLogEvent()) |
277 return; | 259 return; |
278 | 260 |
279 delegate_->OnLogMostVisitedNavigation(position, provider); | 261 delegate_->OnLogMostVisitedNavigation(position, tile_source); |
280 } | 262 } |
281 | 263 |
282 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_seq_no, | 264 void SearchIPCRouter::OnPasteAndOpenDropDown(int page_seq_no, |
283 const base::string16& text) const { | 265 const base::string16& text) const { |
284 if (page_seq_no != commit_counter_) | 266 if (page_seq_no != commit_counter_) |
285 return; | 267 return; |
286 | 268 |
287 delegate_->OnInstantSupportDetermined(true); | 269 delegate_->OnInstantSupportDetermined(true); |
288 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_)) | 270 if (!policy_->ShouldProcessPasteIntoOmnibox(is_active_tab_)) |
289 return; | 271 return; |
(...skipping 27 matching lines...) Expand all Loading... |
317 | 299 |
318 void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) { | 300 void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) { |
319 DCHECK(delegate); | 301 DCHECK(delegate); |
320 delegate_ = delegate; | 302 delegate_ = delegate; |
321 } | 303 } |
322 | 304 |
323 void SearchIPCRouter::set_policy_for_testing(std::unique_ptr<Policy> policy) { | 305 void SearchIPCRouter::set_policy_for_testing(std::unique_ptr<Policy> policy) { |
324 DCHECK(policy.get()); | 306 DCHECK(policy.get()); |
325 policy_.reset(policy.release()); | 307 policy_.reset(policy.release()); |
326 } | 308 } |
OLD | NEW |