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