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/search/instant_service.h" | 5 #include "chrome/browser/search/instant_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram_macros.h" | |
11 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 12 #include "build/build_config.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/favicon/fallback_icon_service_factory.h" | 14 #include "chrome/browser/favicon/fallback_icon_service_factory.h" |
16 #include "chrome/browser/favicon/large_icon_service_factory.h" | 15 #include "chrome/browser/favicon/large_icon_service_factory.h" |
17 #include "chrome/browser/history/top_sites_factory.h" | 16 #include "chrome/browser/history/top_sites_factory.h" |
18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/search/instant_io_context.h" | 18 #include "chrome/browser/search/instant_io_context.h" |
20 #include "chrome/browser/search/instant_service_observer.h" | 19 #include "chrome/browser/search/instant_service_observer.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #endif | 55 #endif |
57 | 56 |
58 #if defined(ENABLE_THEMES) | 57 #if defined(ENABLE_THEMES) |
59 #include "chrome/browser/themes/theme_properties.h" | 58 #include "chrome/browser/themes/theme_properties.h" |
60 #include "chrome/browser/themes/theme_service.h" | 59 #include "chrome/browser/themes/theme_service.h" |
61 #include "chrome/browser/themes/theme_service_factory.h" | 60 #include "chrome/browser/themes/theme_service_factory.h" |
62 #endif // defined(ENABLE_THEMES) | 61 #endif // defined(ENABLE_THEMES) |
63 | 62 |
64 namespace { | 63 namespace { |
65 | 64 |
66 // Used in a histogram; don't reorder, insert new values only at the end, and | |
67 // keep in sync with "NtpMostVisitedScheme" in histograms.xml. | |
68 enum class HistogramScheme { | |
69 OTHER, | |
70 OTHER_WEBSAFE, | |
71 HTTP, | |
72 HTTPS, | |
73 FTP, | |
74 FILE, | |
75 CHROME, | |
76 EXTENSION, | |
77 JAVASCRIPT, | |
78 // Insert new values here. | |
79 COUNT | |
80 }; | |
81 | |
82 const char kLocalNTPSuggestionService[] = "LocalNTPSuggestionsService"; | 65 const char kLocalNTPSuggestionService[] = "LocalNTPSuggestionsService"; |
83 const char kLocalNTPSuggestionServiceEnabled[] = "Enabled"; | 66 const char kLocalNTPSuggestionServiceEnabled[] = "Enabled"; |
84 | 67 |
85 bool IsLocalNTPSuggestionServiceEnabled() { | 68 bool IsLocalNTPSuggestionServiceEnabled() { |
86 return base::StartsWith( | 69 return base::StartsWith( |
87 base::FieldTrialList::FindFullName(kLocalNTPSuggestionService), | 70 base::FieldTrialList::FindFullName(kLocalNTPSuggestionService), |
88 kLocalNTPSuggestionServiceEnabled, base::CompareCase::INSENSITIVE_ASCII); | 71 kLocalNTPSuggestionServiceEnabled, base::CompareCase::INSENSITIVE_ASCII); |
89 } | 72 } |
90 | 73 |
91 } // namespace | 74 } // namespace |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 default: | 284 default: |
302 NOTREACHED() << "Unexpected notification type in InstantService."; | 285 NOTREACHED() << "Unexpected notification type in InstantService."; |
303 } | 286 } |
304 } | 287 } |
305 | 288 |
306 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) { | 289 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) { |
307 rph->Send(new ChromeViewMsg_SetSearchURLs( | 290 rph->Send(new ChromeViewMsg_SetSearchURLs( |
308 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_))); | 291 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_))); |
309 } | 292 } |
310 | 293 |
311 bool InstantService::IsValidURLForNavigation(const GURL& url) const { | |
312 HistogramScheme scheme = HistogramScheme::OTHER; | |
313 if (url.SchemeIs(url::kHttpScheme)) { | |
314 scheme = HistogramScheme::HTTP; | |
315 } else if (url.SchemeIs(url::kHttpsScheme)) { | |
316 scheme = HistogramScheme::HTTPS; | |
317 } else if (url.SchemeIs(url::kFtpScheme)) { | |
318 scheme = HistogramScheme::FTP; | |
319 } else if (url.SchemeIsFile()) { | |
320 scheme = HistogramScheme::FILE; | |
321 } else if (url.SchemeIs(content::kChromeUIScheme)) { | |
322 scheme = HistogramScheme::CHROME; | |
323 } else if (url.SchemeIs(extensions::kExtensionScheme)) { | |
324 scheme = HistogramScheme::EXTENSION; | |
325 } else if (url.SchemeIs(url::kJavaScriptScheme)) { | |
326 scheme = HistogramScheme::JAVASCRIPT; | |
327 } else if (content::ChildProcessSecurityPolicy::GetInstance() | |
328 ->IsWebSafeScheme(url.scheme())) { | |
329 scheme = HistogramScheme::OTHER_WEBSAFE; | |
330 } | |
331 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisitedScheme", | |
332 static_cast<int32_t>(scheme), | |
333 static_cast<int32_t>(HistogramScheme::COUNT)); | |
334 | |
335 // Certain URLs are privileged and should never be considered valid | |
336 // navigation targets. | |
337 // TODO(treib): Ideally this should deny by default and only allow if the | |
338 // scheme passes the content::ChildProcessSecurityPolicy::IsWebSafeScheme() | |
339 // check. | |
340 if (url.SchemeIs(content::kChromeUIScheme)) | |
341 return false; | |
342 | |
343 // javascript: URLs never make sense as a most visited item either. | |
344 if (url.SchemeIs(url::kJavaScriptScheme)) | |
345 return false; | |
346 | |
347 for (const auto& item : most_visited_items_) { | |
348 if (item.url == url) | |
349 return true; | |
350 } | |
351 for (const auto& item : suggestions_items_) { | |
352 if (item.url == url) | |
353 return true; | |
354 } | |
355 return false; | |
356 } | |
357 | |
358 void InstantService::OnRendererProcessTerminated(int process_id) { | 294 void InstantService::OnRendererProcessTerminated(int process_id) { |
359 process_ids_.erase(process_id); | 295 process_ids_.erase(process_id); |
360 | 296 |
361 if (instant_io_context_.get()) { | 297 if (instant_io_context_.get()) { |
362 content::BrowserThread::PostTask( | 298 content::BrowserThread::PostTask( |
363 content::BrowserThread::IO, FROM_HERE, | 299 content::BrowserThread::IO, FROM_HERE, |
364 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, | 300 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, |
365 instant_io_context_, process_id)); | 301 instant_io_context_, process_id)); |
366 } | 302 } |
367 } | 303 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 526 } |
591 | 527 |
592 void InstantService::ResetInstantSearchPrerenderer() { | 528 void InstantService::ResetInstantSearchPrerenderer() { |
593 if (!search::ShouldPrefetchSearchResults()) | 529 if (!search::ShouldPrefetchSearchResults()) |
594 return; | 530 return; |
595 | 531 |
596 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); | 532 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); |
597 instant_prerenderer_.reset( | 533 instant_prerenderer_.reset( |
598 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); | 534 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); |
599 } | 535 } |
OLD | NEW |