Index: chrome/browser/instant/instant_loader.cc |
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc |
index 629a7a66342921c46adeaa099a43fad56af383b7..d95f11927284e70574e1033a50922229736acc5e 100644 |
--- a/chrome/browser/instant/instant_loader.cc |
+++ b/chrome/browser/instant/instant_loader.cc |
@@ -4,21 +4,12 @@ |
#include "chrome/browser/instant/instant_loader.h" |
-#include "chrome/browser/content_settings/tab_specific_content_settings.h" |
-#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
-#include "chrome/browser/favicon/favicon_tab_helper.h" |
-#include "chrome/browser/history/history_tab_helper.h" |
-#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
-#include "chrome/browser/tab_contents/tab_util.h" |
-#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
-#include "chrome/browser/ui/search/search_tab_helper.h" |
-#include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
-#include "content/public/browser/navigation_entry.h" |
-#include "content/public/browser/notification_source.h" |
-#include "content/public/browser/notification_types.h" |
-#include "content/public/browser/render_widget_host_view.h" |
+#include "base/stringprintf.h" |
+#include "chrome/browser/instant/instant_service.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/search/search.h" |
#include "content/public/browser/site_instance.h" |
-#include "content/public/browser/web_contents_view.h" |
+#include "content/public/browser/web_contents.h" |
namespace { |
@@ -29,188 +20,137 @@ const char kInstantHeader[] = "X-Purpose: Instant"; |
} // namespace |
-InstantLoader::Delegate::~Delegate() { |
-} |
- |
-InstantLoader::InstantLoader(Delegate* delegate) |
- : delegate_(delegate), |
- contents_(NULL), |
- stale_page_timer_(false, false) { |
+InstantLoader::InstantLoader(InstantService* service) |
+ : InstantWebContentsContainer( |
+ ALLOW_THIS_IN_INITIALIZER_LIST(this), service), |
+ service_(service) { |
+ service_->AddObserver(this); |
} |
InstantLoader::~InstantLoader() { |
+ service_->RemoveObserver(this); |
} |
-void InstantLoader::Init(const GURL& instant_url, |
- Profile* profile, |
- const content::WebContents* active_tab, |
- const base::Closure& on_stale_callback) { |
- content::WebContents::CreateParams create_params(profile); |
- create_params.site_instance = content::SiteInstance::CreateForURL( |
- profile, instant_url); |
- SetContents(scoped_ptr<content::WebContents>( |
- content::WebContents::Create(create_params))); |
- instant_url_ = instant_url; |
- on_stale_callback_ = on_stale_callback; |
-} |
- |
-void InstantLoader::Load() { |
- DVLOG(1) << "LoadURL: " << instant_url_; |
- contents_->GetController().LoadURL( |
- instant_url_, content::Referrer(), |
- content::PAGE_TRANSITION_GENERATED, kInstantHeader); |
- contents_->WasHidden(); |
- stale_page_timer_.Start( |
- FROM_HERE, |
- base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS), |
- on_stale_callback_); |
-} |
- |
-void InstantLoader::SetContents(scoped_ptr<content::WebContents> new_contents) { |
- contents_.reset(new_contents.release()); |
- contents_->SetDelegate(this); |
- |
- // Set up various tab helpers. The rest will get attached when (if) the |
- // contents is added to the tab strip. |
- |
- // Tab helpers to control popups. |
- BlockedContentTabHelper::CreateForWebContents(contents()); |
- BlockedContentTabHelper::FromWebContents(contents())-> |
- SetAllContentsBlocked(true); |
- TabSpecificContentSettings::CreateForWebContents(contents()); |
- TabSpecificContentSettings::FromWebContents(contents())-> |
- SetPopupsBlocked(true); |
+void InstantLoader::InitContents() { |
+ if (contents_ && (supports_instant() || contents_->IsLoading())) |
+ return; |
- // A tab helper to catch prerender content swapping shenanigans. |
- CoreTabHelper::CreateForWebContents(contents()); |
- CoreTabHelper::FromWebContents(contents())->set_delegate(this); |
+ GURL instant_url = chrome::search::GetInstantURL(service_->profile()); |
+ if (!instant_url.is_valid()) |
+ return; |
- // Tab helpers used when committing a preview. |
- chrome::search::SearchTabHelper::CreateForWebContents(contents()); |
- HistoryTabHelper::CreateForWebContents(contents()); |
+ content::WebContents::CreateParams create_params(service_->profile(), |
+ content::SiteInstance::CreateForURL(service_->profile(), instant_url)); |
+ contents_.reset(content::WebContents::Create(create_params)); |
- // Observers. |
- extensions::WebNavigationTabObserver::CreateForWebContents(contents()); |
+ SetUpContents(); |
- // Favicons, required by the Task Manager. |
- FaviconTabHelper::CreateForWebContents(contents()); |
+ service_->LogDebugEvent(base::StringPrintf("%p LoadURL '%s'", |
+ this, |
+ instant_url.spec().c_str())); |
- // And some flat-out paranoia. |
- safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(contents()); |
+ contents_->GetController().LoadURL(instant_url, content::Referrer(), |
+ content::PAGE_TRANSITION_GENERATED, kInstantHeader); |
+ contents_->WasHidden(); |
-#if defined(OS_MACOSX) |
- // If |contents_| doesn't yet have a RWHV, SetTakesFocusOnlyOnMouseDown() will |
- // be called later, when NOTIFICATION_RENDER_VIEW_HOST_CHANGED is received. |
- if (content::RenderWidgetHostView* rwhv = |
- contents_->GetRenderWidgetHostView()) |
- rwhv->SetTakesFocusOnlyOnMouseDown(true); |
- registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
- content::Source<content::NavigationController>( |
- &contents_->GetController())); |
-#endif |
+ stale_page_timer_.Start(FROM_HERE, |
+ base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS), |
+ this, &InstantLoader::ReloadContents); |
} |
scoped_ptr<content::WebContents> InstantLoader::ReleaseContents() { |
- contents_->SetDelegate(NULL); |
+ TearDownContents(); |
+ scoped_ptr<content::WebContents> old_contents(contents_.Pass()); |
+ InitContents(); |
+ return old_contents.Pass(); |
+} |
- // Undo tab helper work done in SetContents(). |
+void InstantLoader::RenderViewGone(const content::WebContents* /* contents */) { |
+ DeleteContents(); |
+} |
- BlockedContentTabHelper::FromWebContents(contents())-> |
- SetAllContentsBlocked(false); |
- TabSpecificContentSettings::FromWebContents(contents())-> |
- SetPopupsBlocked(false); |
+void InstantLoader::InitSearchBox(const content::WebContents* /* contents */) { |
+ page_.DisplayInstantResults( |
+ chrome::search::IsInstantPrefEnabled(service_->profile())); |
+ page_.ThemeChanged(service_->theme_info()); |
+ page_.FontChanged(service_->omnibox_font_name(), |
+ service_->omnibox_font_size()); |
+} |
- CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); |
+void InstantLoader::InstantSupportDetermined( |
+ const content::WebContents* /* contents */) { |
+ if (!supports_instant()) |
+ DeleteContents(); |
+ service_->InstantSupportDecided(); |
+} |
-#if defined(OS_MACOSX) |
- if (content::RenderWidgetHostView* rwhv = |
- contents_->GetRenderWidgetHostView()) |
- rwhv->SetTakesFocusOnlyOnMouseDown(false); |
- registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
- content::Source<content::NavigationController>( |
- &contents_->GetController())); |
-#endif |
+void InstantLoader::SetSuggestion(const content::WebContents* /* contents */, |
+ const InstantSuggestion& /* suggestion */) { |
+} |
- return contents_.Pass(); |
+void InstantLoader::NavigateToURL(const content::WebContents* /* contents */, |
+ const GURL& /* url */, |
+ content::PageTransition /* transition */, |
+ WindowOpenDisposition /* disposition */) { |
} |
-void InstantLoader::Observe(int type, |
- const content::NotificationSource& /* source */, |
- const content::NotificationDetails& /* details */) { |
-#if defined(OS_MACOSX) |
- if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { |
- if (content::RenderWidgetHostView* rwhv = |
- contents_->GetRenderWidgetHostView()) |
- rwhv->SetTakesFocusOnlyOnMouseDown(true); |
- return; |
- } |
- NOTREACHED(); |
-#endif |
+void InstantLoader::ShowOverlay(const content::WebContents* /* contents */, |
+ int /* height */, |
+ bool /* is_height_in_pixels */) { |
} |
-void InstantLoader::SwapTabContents(content::WebContents* old_contents, |
- content::WebContents* new_contents) { |
- DCHECK_EQ(old_contents, contents()); |
- // We release here without deleting since the caller has the responsibility |
- // for deleting the old WebContents. |
- ignore_result(ReleaseContents().release()); |
- SetContents(scoped_ptr<content::WebContents>(new_contents)); |
- delegate_->OnSwappedContents(); |
+void InstantLoader::StartKeyCapture( |
+ const content::WebContents* /* contents */) { |
} |
-bool InstantLoader::ShouldSuppressDialogs() { |
- // Messages shown during Instant cancel Instant, so we suppress them. |
- return true; |
+void InstantLoader::StopKeyCapture(const content::WebContents* /* contents */) { |
} |
-bool InstantLoader::ShouldFocusPageAfterCrash() { |
- return false; |
+void InstantLoader::DeleteMostVisitedItem( |
+ const content::WebContents* /* contents */, |
+ const GURL& /* url */) { |
} |
-void InstantLoader::LostCapture() { |
- delegate_->OnMouseUp(); |
+void InstantLoader::UndoMostVisitedItemDeletion( |
+ const content::WebContents* /* contents */, |
+ const GURL& /* url */) { |
} |
-void InstantLoader::WebContentsFocused(content::WebContents* /* contents */) { |
- delegate_->OnFocus(); |
+void InstantLoader::UndoAllMostVisitedItemDeletions( |
+ const content::WebContents* /* contents */) { |
} |
-bool InstantLoader::CanDownload(content::RenderViewHost* /* render_view_host */, |
- int /* request_id */, |
- const std::string& /* request_method */) { |
- // Downloads are disabled. |
- return false; |
+void InstantLoader::InstantStatusChanged() { |
+ if (contents_) |
+ ReloadContents(); |
} |
-void InstantLoader::HandleMouseDown() { |
- delegate_->OnMouseDown(); |
+void InstantLoader::ThemeInfoChanged() { |
+ page_.ThemeChanged(service_->theme_info()); |
} |
-void InstantLoader::HandleMouseUp() { |
- delegate_->OnMouseUp(); |
+void InstantLoader::MostVisitedItemsChanged() { |
+ page_.MostVisitedItems(service_->most_visited_items()); |
} |
-void InstantLoader::HandlePointerActivate() { |
- delegate_->OnMouseDown(); |
+void InstantLoader::InstantSupportDecided() { |
} |
-void InstantLoader::HandleGestureEnd() { |
- delegate_->OnMouseUp(); |
+void InstantLoader::CloseContents(content::WebContents* /* source */) { |
+ DeleteContents(); |
} |
-void InstantLoader::DragEnded() { |
- // If the user drags, we won't get a mouse up (at least on Linux). Commit |
- // the Instant result when the drag ends, so that during the drag the page |
- // won't move around. |
- delegate_->OnMouseUp(); |
+void InstantLoader::TearDownContents() { |
+ InstantWebContentsContainer::TearDownContents(); |
+ stale_page_timer_.Stop(); |
} |
-bool InstantLoader::OnGoToEntryOffset(int /* offset */) { |
- return false; |
+void InstantLoader::DeleteContents() { |
+ TearDownContents(); |
+ contents_.reset(); |
} |
-content::WebContents* InstantLoader::OpenURLFromTab( |
- content::WebContents* source, |
- const content::OpenURLParams& params) { |
- return delegate_->OpenURLFromTab(source, params); |
+void InstantLoader::ReloadContents() { |
+ DeleteContents(); |
+ InitContents(); |
} |