Index: chrome/browser/instant/instant_web_contents_container.cc |
diff --git a/chrome/browser/instant/instant_web_contents_container.cc b/chrome/browser/instant/instant_web_contents_container.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b1ef6e1ea641a779d39374c16b8437da4ad7f2e1 |
--- /dev/null |
+++ b/chrome/browser/instant/instant_web_contents_container.cc |
@@ -0,0 +1,103 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/instant/instant_web_contents_container.h" |
+ |
+#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
+#include "chrome/browser/favicon/favicon_tab_helper.h" |
+#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
+#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
+#include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
+ |
+InstantWebContentsContainer::InstantWebContentsContainer( |
+ InstantPage::Delegate* delegate, |
+ InstantService* service) |
+ : page_(delegate, service) { |
+} |
+ |
+InstantWebContentsContainer::~InstantWebContentsContainer() { |
+} |
+ |
+void InstantWebContentsContainer::SwapTabContents( |
+ content::WebContents* old_contents, |
+ content::WebContents* new_contents) { |
+ DCHECK_EQ(contents_, old_contents); |
+ TearDownContents(); |
+ // Release without deleting. Caller is supposed to delete |old_contents|. |
+ ignore_result(contents_.release()); |
+ contents_.reset(new_contents); |
+ SetUpContents(); |
+ page_.DetermineInstantSupport(); |
+} |
+ |
+content::WebContents* InstantWebContentsContainer::OpenURLFromTab( |
+ content::WebContents* /* source */, |
+ const content::OpenURLParams& params) { |
+ page_.set_supports_instant(false); |
+ |
+ content::NavigationController::LoadURLParams load_params(params.url); |
+ load_params.transition_type = params.transition; |
+ load_params.referrer = params.referrer; |
+ load_params.extra_headers = params.extra_headers; |
+ load_params.is_renderer_initiated = params.is_renderer_initiated; |
+ load_params.transferred_global_request_id = |
+ params.transferred_global_request_id; |
+ load_params.is_cross_site_redirect = params.is_cross_site_redirect; |
+ |
+ contents_->GetController().LoadURLWithParams(load_params); |
+ return contents(); |
+} |
+ |
+bool InstantWebContentsContainer::ShouldFocusPageAfterCrash() { |
+ return false; |
+} |
+ |
+bool InstantWebContentsContainer::CanDownload( |
+ content::RenderViewHost* /* render_view_host */, |
+ int /* request_id */, |
+ const std::string& /* request_method */) { |
+ return false; |
+} |
+ |
+bool InstantWebContentsContainer::OnGoToEntryOffset(int /* offset */) { |
+ return false; |
+} |
+ |
+void InstantWebContentsContainer::SetUpContents() { |
+ contents_->SetDelegate(this); |
+ page_.SetContents(contents()); |
+ page_.set_supports_instant(false); |
+ |
+ // Set up various tab helpers. The rest will get attached when (if) the |
+ // contents is added to the tab strip. |
+ |
+ // Bookmarks (Users can bookmark the Instant NTP. This ensures the bookmarked |
+ // state is correctly set when the contents are swapped into a tab.) |
+ BookmarkTabHelper::CreateForWebContents(contents()); |
+ |
+ // A tab helper to catch prerender content swapping shenanigans. |
+ CoreTabHelper::CreateForWebContents(contents()); |
+ CoreTabHelper::FromWebContents(contents())->set_delegate(this); |
+ |
+ // Observers. |
+ extensions::WebNavigationTabObserver::CreateForWebContents(contents()); |
+ |
+ // Favicons, required by the Task Manager. |
+ FaviconTabHelper::CreateForWebContents(contents()); |
+ |
+ // And some flat-out paranoia. |
+ safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(contents()); |
+} |
+ |
+void InstantWebContentsContainer::TearDownContents() { |
+ if (!contents_) |
+ return; |
+ |
+ contents_->SetDelegate(NULL); |
+ page_.SetContents(NULL); |
+ page_.set_supports_instant(false); |
+ |
+ // Undo tab helper work done in SetUpContents(). |
+ CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); |
+} |