OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/instant/instant_web_contents_container.h" |
| 6 |
| 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
| 8 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 9 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
| 10 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 11 |
| 12 InstantWebContentsContainer::InstantWebContentsContainer( |
| 13 InstantPage::Delegate* delegate, |
| 14 InstantService* service) |
| 15 : page_(delegate, service) { |
| 16 } |
| 17 |
| 18 InstantWebContentsContainer::~InstantWebContentsContainer() { |
| 19 } |
| 20 |
| 21 void InstantWebContentsContainer::SwapTabContents( |
| 22 content::WebContents* old_contents, |
| 23 content::WebContents* new_contents) { |
| 24 DCHECK_EQ(contents_, old_contents); |
| 25 TearDownContents(); |
| 26 // Release without deleting. Caller is supposed to delete |old_contents|. |
| 27 ignore_result(contents_.release()); |
| 28 contents_.reset(new_contents); |
| 29 SetUpContents(); |
| 30 page_.DetermineInstantSupport(); |
| 31 } |
| 32 |
| 33 content::WebContents* InstantWebContentsContainer::OpenURLFromTab( |
| 34 content::WebContents* /* source */, |
| 35 const content::OpenURLParams& params) { |
| 36 page_.set_supports_instant(false); |
| 37 |
| 38 content::NavigationController::LoadURLParams load_params(params.url); |
| 39 load_params.transition_type = params.transition; |
| 40 load_params.referrer = params.referrer; |
| 41 load_params.extra_headers = params.extra_headers; |
| 42 load_params.is_renderer_initiated = params.is_renderer_initiated; |
| 43 load_params.transferred_global_request_id = |
| 44 params.transferred_global_request_id; |
| 45 load_params.is_cross_site_redirect = params.is_cross_site_redirect; |
| 46 |
| 47 contents_->GetController().LoadURLWithParams(load_params); |
| 48 return contents(); |
| 49 } |
| 50 |
| 51 bool InstantWebContentsContainer::ShouldFocusPageAfterCrash() { |
| 52 return false; |
| 53 } |
| 54 |
| 55 bool InstantWebContentsContainer::CanDownload( |
| 56 content::RenderViewHost* /* render_view_host */, |
| 57 int /* request_id */, |
| 58 const std::string& /* request_method */) { |
| 59 return false; |
| 60 } |
| 61 |
| 62 bool InstantWebContentsContainer::OnGoToEntryOffset(int /* offset */) { |
| 63 return false; |
| 64 } |
| 65 |
| 66 void InstantWebContentsContainer::SetUpContents() { |
| 67 contents_->SetDelegate(this); |
| 68 page_.SetContents(contents()); |
| 69 page_.set_supports_instant(false); |
| 70 |
| 71 // Set up various tab helpers. The rest will get attached when (if) the |
| 72 // contents is added to the tab strip. |
| 73 |
| 74 // A tab helper to catch prerender content swapping shenanigans. |
| 75 CoreTabHelper::CreateForWebContents(contents()); |
| 76 CoreTabHelper::FromWebContents(contents())->set_delegate(this); |
| 77 |
| 78 // Observers. |
| 79 extensions::WebNavigationTabObserver::CreateForWebContents(contents()); |
| 80 |
| 81 // Favicons, required by the Task Manager. |
| 82 FaviconTabHelper::CreateForWebContents(contents()); |
| 83 |
| 84 // And some flat-out paranoia. |
| 85 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(contents()); |
| 86 } |
| 87 |
| 88 void InstantWebContentsContainer::TearDownContents() { |
| 89 if (!contents_) |
| 90 return; |
| 91 |
| 92 contents_->SetDelegate(NULL); |
| 93 page_.SetContents(NULL); |
| 94 page_.set_supports_instant(false); |
| 95 |
| 96 // Undo tab helper work done in SetUpContents(). |
| 97 CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); |
| 98 } |
OLD | NEW |