OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_web_ui.h" | 10 #include "chrome/browser/extensions/extension_web_ui.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 content::WebContents** target_contents) { | 87 content::WebContents** target_contents) { |
88 if (url != GURL(chrome::kChromeUINewTabURL)) | 88 if (url != GURL(chrome::kChromeUINewTabURL)) |
89 return false; | 89 return false; |
90 | 90 |
91 GURL extension_url(url); | 91 GURL extension_url(url); |
92 if (ExtensionWebUI::HandleChromeURLOverride(&extension_url, profile())) { | 92 if (ExtensionWebUI::HandleChromeURLOverride(&extension_url, profile())) { |
93 // If there is an extension overriding the NTP do not use the Instant NTP. | 93 // If there is an extension overriding the NTP do not use the Instant NTP. |
94 return false; | 94 return false; |
95 } | 95 } |
96 | 96 |
| 97 // Make sure the instant WebContents is in a valid state (i.e., has a last |
| 98 // committed entry, no transient entry, and no existing pending entry). |
97 scoped_ptr<content::WebContents> instant_ntp = instant_.ReleaseNTPContents(); | 99 scoped_ptr<content::WebContents> instant_ntp = instant_.ReleaseNTPContents(); |
98 if (!instant_ntp) | 100 if (!instant_ntp || !instant_ntp->GetController().CanPruneAllButVisible()) |
99 return false; | 101 return false; |
100 | 102 |
101 *target_contents = instant_ntp.get(); | 103 *target_contents = instant_ntp.get(); |
102 if (source_contents) { | 104 if (source_contents) { |
103 instant_ntp->GetController().CopyStateFromAndPrune( | 105 CHECK(instant_ntp->GetController().CopyStateFromAndPrune( |
104 &source_contents->GetController()); | 106 &source_contents->GetController())); |
105 ReplaceWebContentsAt( | 107 ReplaceWebContentsAt( |
106 browser_->tab_strip_model()->GetIndexOfWebContents(source_contents), | 108 browser_->tab_strip_model()->GetIndexOfWebContents(source_contents), |
107 instant_ntp.Pass()); | 109 instant_ntp.Pass()); |
108 } else { | 110 } else { |
109 instant_ntp->GetController().PruneAllButActive(); | 111 CHECK(instant_ntp->GetController().PruneAllButVisible()); |
110 // If |source_contents| is NULL, then the caller is responsible for | 112 // If |source_contents| is NULL, then the caller is responsible for |
111 // inserting instant_ntp into the tabstrip and will take ownership. | 113 // inserting instant_ntp into the tabstrip and will take ownership. |
112 ignore_result(instant_ntp.release()); | 114 ignore_result(instant_ntp.release()); |
113 } | 115 } |
114 return true; | 116 return true; |
115 } | 117 } |
116 | 118 |
117 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { | 119 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { |
118 // Unsupported dispositions. | 120 // Unsupported dispositions. |
119 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW) | 121 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 if (!instant_service->IsInstantProcess( | 398 if (!instant_service->IsInstantProcess( |
397 contents->GetRenderProcessHost()->GetID())) | 399 contents->GetRenderProcessHost()->GetID())) |
398 continue; | 400 continue; |
399 | 401 |
400 // Reload the contents to ensure that it gets assigned to a non-priviledged | 402 // Reload the contents to ensure that it gets assigned to a non-priviledged |
401 // renderer. | 403 // renderer. |
402 contents->GetController().Reload(false); | 404 contents->GetController().Reload(false); |
403 } | 405 } |
404 instant_.OnDefaultSearchProviderChanged(); | 406 instant_.OnDefaultSearchProviderChanged(); |
405 } | 407 } |
OLD | NEW |