summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/tab_contents
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-09 16:09:29 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-09 16:09:29 +0000
commit51d83bdfd5c71099465fba1ae1abb684db6662e3 (patch)
tree4cf0e033bbe60848c59c4d2273d3ee0f59277e1e /chrome/browser/ui/tab_contents
parentac5255b63bc035f48145653d5aaae33bc24b3e4c (diff)
downloadchromium_src-51d83bdfd5c71099465fba1ae1abb684db6662e3.zip
chromium_src-51d83bdfd5c71099465fba1ae1abb684db6662e3.tar.gz
chromium_src-51d83bdfd5c71099465fba1ae1abb684db6662e3.tar.bz2
Create a bunch of TabHelpers and TabObservers, move all TCW functionality into them.
BUG=105872 TEST=no change Review URL: http://codereview.chromium.org/8865004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/tab_contents')
-rw-r--r--chrome/browser/ui/tab_contents/core_tab_helper.cc114
-rw-r--r--chrome/browser/ui/tab_contents/core_tab_helper.h51
-rw-r--r--chrome/browser/ui/tab_contents/core_tab_helper_delegate.cc (renamed from chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.cc)4
-rw-r--r--chrome/browser/ui/tab_contents/core_tab_helper_delegate.h (renamed from chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h)14
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.cc238
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.h89
6 files changed, 215 insertions, 295 deletions
diff --git a/chrome/browser/ui/tab_contents/core_tab_helper.cc b/chrome/browser/ui/tab_contents/core_tab_helper.cc
new file mode 100644
index 0000000..ddd03a1
--- /dev/null
+++ b/chrome/browser/ui/tab_contents/core_tab_helper.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2011 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/ui/tab_contents/core_tab_helper.h"
+
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/renderer_host/web_cache_manager.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/pref_names.h"
+#include "content/browser/renderer_host/render_view_host.h"
+#include "content/public/browser/notification_service.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+CoreTabHelper::CoreTabHelper(TabContentsWrapper* wrapper)
+ : TabContentsObserver(wrapper->tab_contents()),
+ delegate_(NULL),
+ wrapper_(wrapper) {
+ PrefService* prefs = wrapper_->profile()->GetPrefs();
+ if (prefs) {
+ pref_change_registrar_.Init(prefs);
+ pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this);
+ }
+}
+
+CoreTabHelper::~CoreTabHelper() {
+}
+
+string16 CoreTabHelper::GetDefaultTitle() {
+ return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
+}
+
+string16 CoreTabHelper::GetStatusText() const {
+ if (!tab_contents()->IsLoading() ||
+ tab_contents()->load_state().state == net::LOAD_STATE_IDLE) {
+ return string16();
+ }
+
+ switch (tab_contents()->load_state().state) {
+ case net::LOAD_STATE_WAITING_FOR_DELEGATE:
+ return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_DELEGATE,
+ tab_contents()->load_state().param);
+ case net::LOAD_STATE_WAITING_FOR_CACHE:
+ return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
+ case net::LOAD_STATE_WAITING_FOR_APPCACHE:
+ return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_APPCACHE);
+ case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
+ return
+ l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
+ case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
+ return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
+ case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT:
+ return l10n_util::GetStringUTF16(
+ IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
+ case net::LOAD_STATE_RESOLVING_HOST:
+ return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
+ case net::LOAD_STATE_CONNECTING:
+ return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
+ case net::LOAD_STATE_SSL_HANDSHAKE:
+ return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
+ case net::LOAD_STATE_SENDING_REQUEST:
+ if (tab_contents()->upload_size())
+ return l10n_util::GetStringFUTF16Int(
+ IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
+ static_cast<int>((100 * tab_contents()->upload_position()) /
+ tab_contents()->upload_size()));
+ else
+ return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
+ case net::LOAD_STATE_WAITING_FOR_RESPONSE:
+ return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
+ tab_contents()->load_state_host());
+ // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
+ case net::LOAD_STATE_IDLE:
+ case net::LOAD_STATE_READING_RESPONSE:
+ break;
+ }
+
+ return string16();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TabContentsObserver overrides
+
+void CoreTabHelper::DidBecomeSelected() {
+ WebCacheManager::GetInstance()->ObserveActivity(
+ tab_contents()->GetRenderProcessHost()->GetID());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// content::NotificationObserver overrides
+
+void CoreTabHelper::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_PREF_CHANGED: {
+ std::string* pref_name = content::Details<std::string>(details).ptr();
+ DCHECK(content::Source<PrefService>(source).ptr() ==
+ wrapper_->profile()->GetPrefs());
+ if (*pref_name == prefs::kDefaultZoomLevel) {
+ tab_contents()->render_view_host()->SetZoomLevel(
+ tab_contents()->GetZoomLevel());
+ } else {
+ NOTREACHED() << "unexpected pref change notification" << *pref_name;
+ }
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+}
diff --git a/chrome/browser/ui/tab_contents/core_tab_helper.h b/chrome/browser/ui/tab_contents/core_tab_helper.h
new file mode 100644
index 0000000..302fb1c
--- /dev/null
+++ b/chrome/browser/ui/tab_contents/core_tab_helper.h
@@ -0,0 +1,51 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_
+#define CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_
+#pragma once
+
+#include "chrome/browser/prefs/pref_change_registrar.h"
+#include "content/browser/tab_contents/tab_contents_observer.h"
+
+class CoreTabHelperDelegate;
+class TabContentsWrapper;
+
+// Per-tab class to handle functionality that is core to the operation of tabs.
+class CoreTabHelper : public TabContentsObserver,
+ public content::NotificationObserver {
+ public:
+ explicit CoreTabHelper(TabContentsWrapper* wrapper);
+ virtual ~CoreTabHelper();
+
+ CoreTabHelperDelegate* delegate() const { return delegate_; }
+ void set_delegate(CoreTabHelperDelegate* d) { delegate_ = d; }
+
+ // Initial title assigned to NavigationEntries from Navigate.
+ static string16 GetDefaultTitle();
+
+ // Returns a human-readable description the tab's loading state.
+ string16 GetStatusText() const;
+
+ private:
+ // TabContentsObserver overrides:
+ virtual void DidBecomeSelected() OVERRIDE;
+
+ // content::NotificationObserver overrides:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // Delegate for notifying our owner about stuff. Not owned by us.
+ CoreTabHelperDelegate* delegate_;
+
+ // Our owning TabContentsWrapper.
+ TabContentsWrapper* wrapper_;
+
+ PrefChangeRegistrar pref_change_registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(CoreTabHelper);
+};
+
+#endif // CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.cc b/chrome/browser/ui/tab_contents/core_tab_helper_delegate.cc
index 61a2718..e0a0d20 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.cc
+++ b/chrome/browser/ui/tab_contents/core_tab_helper_delegate.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
+#include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
-TabContentsWrapperDelegate::~TabContentsWrapperDelegate() {
+CoreTabHelperDelegate::~CoreTabHelperDelegate() {
}
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h b/chrome/browser/ui/tab_contents/core_tab_helper_delegate.h
index 86924d2..1ff76df 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h
+++ b/chrome/browser/ui/tab_contents/core_tab_helper_delegate.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_DELEGATE_H_
-#define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_DELEGATE_H_
+#ifndef CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_DELEGATE_H_
+#define CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_DELEGATE_H_
#pragma once
#include "base/basictypes.h"
@@ -12,13 +12,17 @@ class TabContentsWrapper;
// Objects implement this interface to get notified about changes in the
// TabContentsWrapper and to provide necessary functionality.
-class TabContentsWrapperDelegate {
+//
+// This is considered part of the TabContentsWrapper "core" interface. If a
+// piece of code interacts with TabContentWrappers, it is guaranteed that it
+// will need to handle all of these callbacks.
+class CoreTabHelperDelegate {
public:
virtual void SwapTabContents(TabContentsWrapper* old_tc,
TabContentsWrapper* new_tc) = 0;
protected:
- virtual ~TabContentsWrapperDelegate();
+ virtual ~CoreTabHelperDelegate();
};
-#endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_DELEGATE_H_
+#endif // CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_DELEGATE_H_
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
index 3f2ffdc..e04443d 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
@@ -10,70 +10,47 @@
#include "chrome/browser/autofill/autofill_external_delegate.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/automation/automation_tab_helper.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/download/download_request_limiter_observer.h"
#include "chrome/browser/extensions/extension_tab_helper.h"
#include "chrome/browser/extensions/extension_webnavigation_api.h"
#include "chrome/browser/external_protocol/external_protocol_observer.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/google/google_util.h"
#include "chrome/browser/history/history_tab_helper.h"
#include "chrome/browser/infobars/infobar_tab_helper.h"
#include "chrome/browser/omnibox_search_hint.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/password_manager_delegate_impl.h"
-#include "chrome/browser/pdf_unsupported_feature.h"
#include "chrome/browser/plugin_observer.h"
-#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prerender/prerender_tab_helper.h"
#include "chrome/browser/printing/print_preview_message_handler.h"
#include "chrome/browser/printing/print_view_manager.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/renderer_host/web_cache_manager.h"
+#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
#include "chrome/browser/sessions/restore_tab_helper.h"
-#include "chrome/browser/safe_browsing/client_side_detection_host.h"
#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
#include "chrome/browser/tab_contents/thumbnail_generator.h"
#include "chrome/browser/translate/translate_tab_helper.h"
+#include "chrome/browser/ui/alternate_error_tab_observer.h"
#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/constrained_window_tab_helper.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/browser/ui/intents/web_intent_picker_factory_impl.h"
#include "chrome/browser/ui/intents/web_intent_picker_controller.h"
+#include "chrome/browser/ui/pdf/pdf_tab_observer.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/sad_tab_observer.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
+#include "chrome/browser/ui/snapshot_tab_helper.h"
#include "chrome/browser/ui/sync/tab_contents_wrapper_synced_tab_delegate.h"
-#include "chrome/common/chrome_notification_types.h"
+#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/render_messages.h"
-#include "content/browser/renderer_host/render_view_host.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_service.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/platform_locale_settings.h"
-#include "ui/base/l10n/l10n_util.h"
namespace {
static base::LazyInstance<base::PropertyAccessor<TabContentsWrapper*> >
g_tab_contents_wrapper_property_accessor = LAZY_INSTANCE_INITIALIZER;
-// The list of prefs we want to observe.
-const char* kPrefsToObserve[] = {
- prefs::kAlternateErrorPagesEnabled,
- prefs::kDefaultZoomLevel,
-#if defined (ENABLE_SAFE_BROWSING)
- prefs::kSafeBrowsingEnabled,
-#endif
-};
-
-const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
-
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -81,22 +58,15 @@ const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
TabContentsWrapper::TabContentsWrapper(TabContents* contents)
: TabContentsObserver(contents),
- delegate_(NULL),
in_destructor_(false),
tab_contents_(contents) {
DCHECK(contents);
DCHECK(!GetCurrentWrapperForContents(contents));
+
// Stash this in the property bag so it can be retrieved without having to
// go to a Browser.
property_accessor()->SetProperty(contents->property_bag(), this);
- PrefService* prefs = profile()->GetPrefs();
- pref_change_registrar_.Init(prefs);
- if (prefs) {
- for (int i = 0; i < kPrefsToObserveLength; ++i)
- pref_change_registrar_.Add(kPrefsToObserve[i], this);
- }
-
// Create the tab helpers.
autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents));
autofill_manager_ = new AutofillManager(this);
@@ -112,6 +82,7 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this));
bookmark_tab_helper_.reset(new BookmarkTabHelper(this));
constrained_window_tab_helper_.reset(new ConstrainedWindowTabHelper(this));
+ core_tab_helper_.reset(new CoreTabHelper(this));
extension_tab_helper_.reset(new ExtensionTabHelper(this));
favicon_tab_helper_.reset(new FaviconTabHelper(contents));
find_tab_helper_.reset(new FindTabHelper(contents));
@@ -124,14 +95,8 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
prerender_tab_helper_.reset(new prerender::PrerenderTabHelper(this));
print_view_manager_.reset(new printing::PrintViewManager(this));
restore_tab_helper_.reset(new RestoreTabHelper(this));
-#if defined(ENABLE_SAFE_BROWSING)
- if (profile()->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
- g_browser_process->safe_browsing_detection_service()) {
- safebrowsing_detection_host_.reset(
- safe_browsing::ClientSideDetectionHost::Create(contents));
- }
-#endif
search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents));
+ snapshot_tab_helper_.reset(new SnapshotTabHelper(this));
ssl_helper_.reset(new TabContentsSSLHelper(this));
synced_tab_delegate_.reset(new TabContentsWrapperSyncedTabDelegate(this));
content_settings_.reset(new TabSpecificContentSettings(contents));
@@ -140,32 +105,34 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
this, new WebIntentPickerFactoryImpl()));
// Create the per-tab observers.
+ alternate_error_page_tab_observer_.reset(
+ new AlternateErrorPageTabObserver(this));
download_request_limiter_observer_.reset(
new DownloadRequestLimiterObserver(contents));
webnavigation_observer_.reset(
new ExtensionWebNavigationTabObserver(contents));
external_protocol_observer_.reset(new ExternalProtocolObserver(contents));
+ if (OmniboxSearchHint::IsEnabled(profile()))
+ omnibox_search_hint_.reset(new OmniboxSearchHint(this));
+ pdf_tab_observer_.reset(new PDFTabObserver(this));
plugin_observer_.reset(new PluginObserver(this));
print_preview_.reset(new printing::PrintPreviewMessageHandler(contents));
sad_tab_observer_.reset(new SadTabObserver(contents));
+ safe_browsing_tab_observer_.reset(
+ new safe_browsing::SafeBrowsingTabObserver(this));
+
// Start the in-browser thumbnailing if the feature is enabled.
if (switches::IsInBrowserThumbnailingEnabled()) {
thumbnail_generation_observer_.reset(new ThumbnailGenerator);
thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get());
}
-
- // Set-up the showing of the omnibox search infobar if applicable.
- if (OmniboxSearchHint::IsEnabled(profile()))
- omnibox_search_hint_.reset(new OmniboxSearchHint(this));
-
- registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllSources());
}
TabContentsWrapper::~TabContentsWrapper() {
in_destructor_ = true;
// Need to tear down infobars before the TabContents goes away.
+ // TODO(avi): Can we get this handled by the tab helper itself?
infobar_tab_helper_.reset();
}
@@ -174,77 +141,17 @@ base::PropertyAccessor<TabContentsWrapper*>*
return g_tab_contents_wrapper_property_accessor.Pointer();
}
-void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled,
- true,
- PrefService::SYNCABLE_PREF);
-}
-
-string16 TabContentsWrapper::GetDefaultTitle() {
- return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
-}
-
-string16 TabContentsWrapper::GetStatusText() const {
- if (!tab_contents()->IsLoading() ||
- tab_contents()->load_state().state == net::LOAD_STATE_IDLE) {
- return string16();
- }
-
- switch (tab_contents()->load_state().state) {
- case net::LOAD_STATE_WAITING_FOR_DELEGATE:
- return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_DELEGATE,
- tab_contents()->load_state().param);
- case net::LOAD_STATE_WAITING_FOR_CACHE:
- return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
- case net::LOAD_STATE_WAITING_FOR_APPCACHE:
- return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_APPCACHE);
- case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
- return
- l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
- case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
- return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
- case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT:
- return l10n_util::GetStringUTF16(
- IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
- case net::LOAD_STATE_RESOLVING_HOST:
- return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
- case net::LOAD_STATE_CONNECTING:
- return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
- case net::LOAD_STATE_SSL_HANDSHAKE:
- return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
- case net::LOAD_STATE_SENDING_REQUEST:
- if (tab_contents()->upload_size())
- return l10n_util::GetStringFUTF16Int(
- IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
- static_cast<int>((100 * tab_contents()->upload_position()) /
- tab_contents()->upload_size()));
- else
- return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
- case net::LOAD_STATE_WAITING_FOR_RESPONSE:
- return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
- tab_contents()->load_state_host());
- // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
- case net::LOAD_STATE_IDLE:
- case net::LOAD_STATE_READING_RESPONSE:
- break;
- }
-
- return string16();
-}
-
TabContentsWrapper* TabContentsWrapper::Clone() {
TabContents* new_contents = tab_contents()->Clone();
TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents);
+ // TODO(avi): Can we generalize this so that knowledge of the functionings of
+ // the tab helpers isn't required here?
new_wrapper->extension_tab_helper()->CopyStateFrom(
*extension_tab_helper_.get());
return new_wrapper;
}
-void TabContentsWrapper::CaptureSnapshot() {
- Send(new ChromeViewMsg_CaptureSnapshot(routing_id()));
-}
-
// static
TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents(
TabContents* contents) {
@@ -268,27 +175,7 @@ Profile* TabContentsWrapper::profile() const {
}
////////////////////////////////////////////////////////////////////////////////
-// TabContentsWrapper implementation:
-
-void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) {
- UpdateAlternateErrorPageURL(render_view_host);
-}
-
-void TabContentsWrapper::DidBecomeSelected() {
- WebCacheManager::GetInstance()->ObserveActivity(
- tab_contents()->GetRenderProcessHost()->GetID());
-}
-
-bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message)
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot)
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature,
- OnPDFHasUnsupportedFeature)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
+// TabContentsObserver overrides
void TabContentsWrapper::TabContentsDestroyed(TabContents* tab) {
// Destruction of the TabContents should only be done by us from our
@@ -296,88 +183,3 @@ void TabContentsWrapper::TabContentsDestroyed(TabContents* tab) {
// will attempt to access the TabContents and we'll crash.
DCHECK(in_destructor_);
}
-
-void TabContentsWrapper::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_GOOGLE_URL_UPDATED:
- UpdateAlternateErrorPageURL(render_view_host());
- break;
- case chrome::NOTIFICATION_PREF_CHANGED: {
- std::string* pref_name_in = content::Details<std::string>(details).ptr();
- DCHECK(content::Source<PrefService>(source).ptr() ==
- profile()->GetPrefs());
- if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
- UpdateAlternateErrorPageURL(render_view_host());
- } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
- tab_contents()->render_view_host()->SetZoomLevel(
- tab_contents()->GetZoomLevel());
- } else if (*pref_name_in == prefs::kSafeBrowsingEnabled) {
- UpdateSafebrowsingDetectionHost();
- } else {
- NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
- }
- break;
- }
- default:
- NOTREACHED();
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Internal helpers
-
-void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) {
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
- content::Source<TabContentsWrapper>(this),
- content::Details<const SkBitmap>(&bitmap));
-}
-
-void TabContentsWrapper::OnPDFHasUnsupportedFeature() {
- PDFHasUnsupportedFeature(this);
-}
-
-GURL TabContentsWrapper::GetAlternateErrorPageURL() const {
- GURL url;
- // Disable alternate error pages when in Incognito mode.
- if (profile()->IsOffTheRecord())
- return url;
-
- PrefService* prefs = profile()->GetPrefs();
- if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
- url = google_util::AppendGoogleLocaleParam(
- GURL(google_util::kLinkDoctorBaseURL));
- url = google_util::AppendGoogleTLDParam(url);
- }
- return url;
-}
-
-void TabContentsWrapper::UpdateAlternateErrorPageURL(RenderViewHost* rvh) {
- rvh->SetAltErrorPageURL(GetAlternateErrorPageURL());
-}
-
-void TabContentsWrapper::UpdateSafebrowsingDetectionHost() {
-#if defined(ENABLE_SAFE_BROWSING)
- PrefService* prefs = profile()->GetPrefs();
- bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled);
- if (safe_browsing &&
- g_browser_process->safe_browsing_detection_service()) {
- if (!safebrowsing_detection_host_.get()) {
- safebrowsing_detection_host_.reset(
- safe_browsing::ClientSideDetectionHost::Create(tab_contents()));
- }
- } else {
- safebrowsing_detection_host_.reset();
- }
- render_view_host()->Send(
- new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(),
- safe_browsing));
-#endif
-}
-
-void TabContentsWrapper::ExitFullscreenMode() {
- if (tab_contents() && render_view_host())
- tab_contents()->render_view_host()->ExitFullscreen();
-}
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
index a17c10d..bbfd333 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
@@ -13,11 +13,10 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/prefs/pref_change_registrar.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
-#include "content/public/browser/notification_registrar.h"
+class AlternateErrorPageTabObserver;
class AutocompleteHistoryManager;
class AutofillManager;
class AutofillExternalDelegate;
@@ -25,6 +24,7 @@ class AutomationTabHelper;
class BlockedContentTabHelper;
class BookmarkTabHelper;
class ConstrainedWindowTabHelper;
+class CoreTabHelper;
class DownloadRequestLimiterObserver;
class ExtensionTabHelper;
class ExtensionWebNavigationTabObserver;
@@ -36,6 +36,7 @@ class InfoBarTabHelper;
class OmniboxSearchHint;
class PasswordManager;
class PasswordManagerDelegate;
+class PDFTabObserver;
class PluginObserver;
class PrefService;
class PrefsTabHelper;
@@ -43,8 +44,8 @@ class Profile;
class RestoreTabHelper;
class SadTabObserver;
class SearchEngineTabHelper;
+class SnapshotTabHelper;
class TabContentsSSLHelper;
-class TabContentsWrapperDelegate;
class TabContentsWrapperSyncedTabDelegate;
class TabSpecificContentSettings;
class ThumbnailGenerator;
@@ -65,7 +66,7 @@ class PrintPreviewMessageHandler;
}
namespace safe_browsing {
-class ClientSideDetectionHost;
+class SafeBrowsingTabObserver;
}
// Wraps TabContents and all of its supporting objects in order to control
@@ -74,8 +75,7 @@ class ClientSideDetectionHost;
// TODO(pinkerton): Eventually, this class will become TabContents as far as
// the browser front-end is concerned, and the current TabContents will be
// renamed to something like WebPage or WebView (ben's suggestions).
-class TabContentsWrapper : public TabContentsObserver,
- public content::NotificationObserver {
+class TabContentsWrapper : public TabContentsObserver {
public:
// Takes ownership of |contents|, which must be heap-allocated (as it lives
// in a scoped_ptr) and can not be NULL.
@@ -86,24 +86,10 @@ class TabContentsWrapper : public TabContentsObserver,
// its property bag to avoid adding additional interfaces.
static base::PropertyAccessor<TabContentsWrapper*>* property_accessor();
- static void RegisterUserPrefs(PrefService* prefs);
-
- // Initial title assigned to NavigationEntries from Navigate.
- static string16 GetDefaultTitle();
-
- // Returns a human-readable description the tab's loading state.
- string16 GetStatusText() const;
-
// Create a TabContentsWrapper with the same state as this one. The returned
// heap-allocated pointer is owned by the caller.
TabContentsWrapper* Clone();
- // Captures a snapshot of the page.
- void CaptureSnapshot();
-
- // Stop this tab rendering in fullscreen mode.
- void ExitFullscreenMode();
-
// Helper to retrieve the existing instance that wraps a given TabContents.
// Returns NULL if there is no such existing instance.
// NOTE: This is not intended for general use. It is intended for situations
@@ -115,9 +101,6 @@ class TabContentsWrapper : public TabContentsObserver,
static const TabContentsWrapper* GetCurrentWrapperForContents(
const TabContents* contents);
- TabContentsWrapperDelegate* delegate() const { return delegate_; }
- void set_delegate(TabContentsWrapperDelegate* d) { delegate_ = d; }
-
TabContents* tab_contents() const { return tab_contents_.get(); }
NavigationController& controller() const {
return tab_contents()->controller();
@@ -155,6 +138,8 @@ class TabContentsWrapper : public TabContentsObserver,
return constrained_window_tab_helper_.get();
}
+ CoreTabHelper* core_tab_helper() { return core_tab_helper_.get(); }
+
ExtensionTabHelper* extension_tab_helper() {
return extension_tab_helper_.get();
}
@@ -186,14 +171,14 @@ class TabContentsWrapper : public TabContentsObserver,
return restore_tab_helper_.get();
}
- safe_browsing::ClientSideDetectionHost* safebrowsing_detection_host() {
- return safebrowsing_detection_host_.get();
- }
-
SearchEngineTabHelper* search_engine_tab_helper() {
return search_engine_tab_helper_.get();
}
+ SnapshotTabHelper* snapshot_tab_helper() {
+ return snapshot_tab_helper_.get();
+ }
+
TabContentsSSLHelper* ssl_helper() { return ssl_helper_.get(); }
TabContentsWrapperSyncedTabDelegate* synced_tab_delegate() {
@@ -215,51 +200,12 @@ class TabContentsWrapper : public TabContentsObserver,
// Overrides -----------------------------------------------------------------
// TabContentsObserver overrides:
- virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
- virtual void DidBecomeSelected() OVERRIDE;
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void TabContentsDestroyed(TabContents* tab) OVERRIDE;
- // content::NotificationObserver overrides:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
private:
FRIEND_TEST_ALL_PREFIXES(
PrefsTabHelperTest, OverridePrefsOnViewCreation);
- // Internal helpers ----------------------------------------------------------
-
- // Message handlers.
- void OnSnapshot(const SkBitmap& bitmap);
- void OnPDFHasUnsupportedFeature();
-
- // Returns the server that can provide alternate error pages. If the returned
- // URL is empty, the default error page built into WebKit will be used.
- GURL GetAlternateErrorPageURL() const;
-
- // Send the alternate error page URL to the renderer.
- void UpdateAlternateErrorPageURL(RenderViewHost* rvh);
-
- // Create or destroy SafebrowsingDetectionHost as needed if the user's
- // safe browsing preference has changed.
- void UpdateSafebrowsingDetectionHost();
-
- // Data for core operation ---------------------------------------------------
-
- // Delegate for notifying our owner about stuff. Not owned by us.
- TabContentsWrapperDelegate* delegate_;
-
- content::NotificationRegistrar registrar_;
- PrefChangeRegistrar pref_change_registrar_;
-
- // Data for current page -----------------------------------------------------
-
- // Shows an info-bar to users when they search from a known search engine and
- // have never used the omnibox for search before.
- scoped_ptr<OmniboxSearchHint> omnibox_search_hint_;
-
// Tab Helpers ---------------------------------------------------------------
// (These provide API for callers and have a getter function listed in the
// "Tab Helpers" section in the member functions area, above.)
@@ -271,6 +217,7 @@ class TabContentsWrapper : public TabContentsObserver,
scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_;
scoped_ptr<BookmarkTabHelper> bookmark_tab_helper_;
scoped_ptr<ConstrainedWindowTabHelper> constrained_window_tab_helper_;
+ scoped_ptr<CoreTabHelper> core_tab_helper_;
scoped_ptr<ExtensionTabHelper> extension_tab_helper_;
scoped_ptr<FaviconTabHelper> favicon_tab_helper_;
scoped_ptr<FindTabHelper> find_tab_helper_;
@@ -293,11 +240,8 @@ class TabContentsWrapper : public TabContentsObserver,
// Handles displaying a web intents picker to the user.
scoped_ptr<WebIntentPickerController> web_intent_picker_controller_;
- // Handles IPCs related to SafeBrowsing client-side phishing detection.
- scoped_ptr<safe_browsing::ClientSideDetectionHost>
- safebrowsing_detection_host_;
-
scoped_ptr<SearchEngineTabHelper> search_engine_tab_helper_;
+ scoped_ptr<SnapshotTabHelper> snapshot_tab_helper_;
scoped_ptr<TabContentsSSLHelper> ssl_helper_;
scoped_ptr<TabContentsWrapperSyncedTabDelegate> synced_tab_delegate_;
@@ -311,12 +255,17 @@ class TabContentsWrapper : public TabContentsObserver,
// (These provide no API for callers; objects that need to exist 1:1 with tabs
// and silently do their thing live here.)
+ scoped_ptr<AlternateErrorPageTabObserver> alternate_error_page_tab_observer_;
scoped_ptr<DownloadRequestLimiterObserver> download_request_limiter_observer_;
scoped_ptr<ExtensionWebNavigationTabObserver> webnavigation_observer_;
scoped_ptr<ExternalProtocolObserver> external_protocol_observer_;
+ scoped_ptr<OmniboxSearchHint> omnibox_search_hint_;
+ scoped_ptr<PDFTabObserver> pdf_tab_observer_;
scoped_ptr<PluginObserver> plugin_observer_;
scoped_ptr<printing::PrintPreviewMessageHandler> print_preview_;
scoped_ptr<SadTabObserver> sad_tab_observer_;
+ scoped_ptr<safe_browsing::SafeBrowsingTabObserver>
+ safe_browsing_tab_observer_;
scoped_ptr<ThumbnailGenerator> thumbnail_generation_observer_;
// TabContents (MUST BE LAST) ------------------------------------------------