| 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/instant_ntp_prerenderer.h" | 5 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/content_settings/content_settings_provider.h" | 13 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 14 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search/instant_service.h" | 16 #include "chrome/browser/search/instant_service.h" |
| 17 #include "chrome/browser/search/instant_service_factory.h" | 17 #include "chrome/browser/search/instant_service_factory.h" |
| 18 #include "chrome/browser/search/search.h" | 18 #include "chrome/browser/search/search.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/host_desktop.h" | 21 #include "chrome/browser/ui/host_desktop.h" |
| 22 #include "chrome/browser/ui/search/instant_ntp.h" | 22 #include "chrome/browser/ui/search/instant_ntp.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/common/content_settings.h" | 24 #include "chrome/common/content_settings.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/search_urls.h" |
| 26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 void DeleteNTPSoon(scoped_ptr<InstantNTP> ntp) { | 34 void DeleteNTPSoon(scoped_ptr<InstantNTP> ntp) { |
| 34 if (!ntp) | 35 if (!ntp) |
| 35 return; | 36 return; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 base::Unretained(this))); | 264 base::Unretained(this))); |
| 264 } | 265 } |
| 265 | 266 |
| 266 void InstantNTPPrerenderer::ReloadStaleNTP() { | 267 void InstantNTPPrerenderer::ReloadStaleNTP() { |
| 267 ResetNTP(GetInstantURL()); | 268 ResetNTP(GetInstantURL()); |
| 268 } | 269 } |
| 269 | 270 |
| 270 bool InstantNTPPrerenderer::PageIsCurrent() const { | 271 bool InstantNTPPrerenderer::PageIsCurrent() const { |
| 271 const std::string& instant_url = GetInstantURL(); | 272 const std::string& instant_url = GetInstantURL(); |
| 272 if (instant_url.empty() || | 273 if (instant_url.empty() || |
| 273 !chrome::MatchesOriginAndPath(GURL(ntp()->instant_url()), | 274 !search::MatchesOriginAndPath(GURL(ntp()->instant_url()), |
| 274 GURL(instant_url))) | 275 GURL(instant_url))) |
| 275 return false; | 276 return false; |
| 276 | 277 |
| 277 return ntp()->supports_instant(); | 278 return ntp()->supports_instant(); |
| 278 } | 279 } |
| 279 | 280 |
| 280 bool InstantNTPPrerenderer::ShouldSwitchToLocalNTP() const { | 281 bool InstantNTPPrerenderer::ShouldSwitchToLocalNTP() const { |
| 281 if (!ntp()) | 282 if (!ntp()) |
| 282 return true; | 283 return true; |
| 283 | 284 |
| 284 // Assume users with Javascript disabled do not want the online experience. | 285 // Assume users with Javascript disabled do not want the online experience. |
| 285 if (!IsJavascriptEnabled()) | 286 if (!IsJavascriptEnabled()) |
| 286 return true; | 287 return true; |
| 287 | 288 |
| 288 // Already a local page. Not calling IsLocal() because we want to distinguish | 289 // Already a local page. Not calling IsLocal() because we want to distinguish |
| 289 // between the Google-specific and generic local NTP. | 290 // between the Google-specific and generic local NTP. |
| 290 if (ntp()->instant_url() == GetLocalInstantURL()) | 291 if (ntp()->instant_url() == GetLocalInstantURL()) |
| 291 return false; | 292 return false; |
| 292 | 293 |
| 293 if (PageIsCurrent()) | 294 if (PageIsCurrent()) |
| 294 return false; | 295 return false; |
| 295 | 296 |
| 296 // The preloaded NTP does not support instant yet. If we're not in startup, | 297 // The preloaded NTP does not support instant yet. If we're not in startup, |
| 297 // always fall back to the local NTP. If we are in startup, use the local NTP | 298 // always fall back to the local NTP. If we are in startup, use the local NTP |
| 298 // (unless the finch flag to use the remote NTP is set). | 299 // (unless the finch flag to use the remote NTP is set). |
| 299 return !(InStartup() && chrome::ShouldPreferRemoteNTPOnStartup()); | 300 return !(InStartup() && chrome::ShouldPreferRemoteNTPOnStartup()); |
| 300 } | 301 } |
| OLD | NEW |