summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 03:09:42 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 03:09:42 +0000
commitb5a1d11cc70ab12c69e579d132204863a780eb75 (patch)
treea9300148dd2434b645ad7fe1716cce2f9e42e064 /chrome
parentcd124097edce07ef5e0a7f80105e81c7982b81a1 (diff)
downloadchromium_src-b5a1d11cc70ab12c69e579d132204863a780eb75.zip
chromium_src-b5a1d11cc70ab12c69e579d132204863a780eb75.tar.gz
chromium_src-b5a1d11cc70ab12c69e579d132204863a780eb75.tar.bz2
Make TabContentsObserver handle registration automatically, as well as exposing getters for TC, routing_id, and sending messages.
Review URL: http://codereview.chromium.org/6537004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75226 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete_history_manager.cc32
-rw-r--r--chrome/browser/autocomplete_history_manager.h5
-rw-r--r--chrome/browser/autocomplete_history_manager_unittest.cc12
-rw-r--r--chrome/browser/autofill/autofill_manager.cc42
-rw-r--r--chrome/browser/autofill/autofill_manager.h9
-rw-r--r--chrome/browser/desktop_notification_handler.cc6
-rw-r--r--chrome/browser/desktop_notification_handler.h21
-rw-r--r--chrome/browser/download/save_package.cc48
-rw-r--r--chrome/browser/download/save_package.h2
-rw-r--r--chrome/browser/download/save_package_unittest.cc2
-rw-r--r--chrome/browser/fav_icon_helper.cc12
-rw-r--r--chrome/browser/fav_icon_helper.h3
-rw-r--r--chrome/browser/password_manager/password_manager.cc6
-rw-r--r--chrome/browser/password_manager/password_manager.h3
-rw-r--r--chrome/browser/password_manager/password_manager_unittest.cc11
-rw-r--r--chrome/browser/plugin_observer.cc22
-rw-r--r--chrome/browser/plugin_observer.h1
-rw-r--r--chrome/browser/prerender/prerender_plt_recorder.cc5
-rw-r--r--chrome/browser/prerender/prerender_plt_recorder.h2
-rw-r--r--chrome/browser/printing/print_preview_message_handler.cc11
-rw-r--r--chrome/browser/printing/print_preview_message_handler.h5
-rw-r--r--chrome/browser/printing/print_view_manager.cc30
-rw-r--r--chrome/browser/printing/print_view_manager.h7
-rw-r--r--chrome/browser/safe_browsing/malware_details.cc8
-rw-r--r--chrome/browser/safe_browsing/malware_details.h1
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page.cc8
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc64
-rw-r--r--chrome/browser/tab_contents/tab_contents.h10
-rw-r--r--chrome/browser/tab_contents/tab_contents_observer.cc23
-rw-r--r--chrome/browser/tab_contents/tab_contents_observer.h27
-rw-r--r--chrome/browser/ui/browser.cc2
-rw-r--r--chrome/browser/ui/browser.h2
-rw-r--r--chrome/browser/ui/browser_window.h2
-rw-r--r--chrome/browser/ui/find_bar/find_tab_helper.cc28
-rw-r--r--chrome/browser/ui/find_bar/find_tab_helper.h6
-rw-r--r--chrome/browser/ui/search_engines/search_engine_tab_helper.cc28
-rw-r--r--chrome/browser/ui/search_engines/search_engine_tab_helper.h4
-rw-r--r--chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h4
-rw-r--r--chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc8
-rw-r--r--chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h8
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.cc20
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc5
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h2
43 files changed, 273 insertions, 284 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc
index 2acdcfc..112e063 100644
--- a/chrome/browser/autocomplete_history_manager.cc
+++ b/chrome/browser/autocomplete_history_manager.cc
@@ -74,10 +74,10 @@ bool IsSSN(const string16& text) {
AutocompleteHistoryManager::AutocompleteHistoryManager(
TabContents* tab_contents)
- : tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
pending_query_handle_(0),
query_id_(0) {
- profile_ = tab_contents_->profile();
+ profile_ = tab_contents->profile();
// May be NULL in unit tests.
web_data_service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
autofill_enabled_.Init(prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL);
@@ -191,11 +191,14 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
}
AutocompleteHistoryManager::AutocompleteHistoryManager(
- Profile* profile, WebDataService* wds) : tab_contents_(NULL),
- profile_(profile),
- web_data_service_(wds),
- pending_query_handle_(0),
- query_id_(0) {
+ TabContents* tab_contents,
+ Profile* profile,
+ WebDataService* wds)
+ : TabContentsObserver(tab_contents),
+ profile_(profile),
+ web_data_service_(wds),
+ pending_query_handle_(0),
+ query_id_(0) {
autofill_enabled_.Init(
prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL);
}
@@ -232,15 +235,12 @@ void AutocompleteHistoryManager::SendSuggestions(
}
}
- RenderViewHost* host = tab_contents_->render_view_host();
- if (host) {
- host->Send(new AutoFillMsg_SuggestionsReturned(host->routing_id(),
- query_id_,
- autofill_values_,
- autofill_labels_,
- autofill_icons_,
- autofill_unique_ids_));
- }
+ Send(new AutoFillMsg_SuggestionsReturned(routing_id(),
+ query_id_,
+ autofill_values_,
+ autofill_labels_,
+ autofill_icons_,
+ autofill_unique_ids_));
query_id_ = 0;
autofill_values_.clear();
diff --git a/chrome/browser/autocomplete_history_manager.h b/chrome/browser/autocomplete_history_manager.h
index fd4387f..796e610 100644
--- a/chrome/browser/autocomplete_history_manager.h
+++ b/chrome/browser/autocomplete_history_manager.h
@@ -51,7 +51,9 @@ class AutocompleteHistoryManager : public TabContentsObserver,
friend class AutoFillManagerTest;
// For tests.
- AutocompleteHistoryManager(Profile* profile, WebDataService* wds);
+ AutocompleteHistoryManager(TabContents* tab_contents,
+ Profile* profile,
+ WebDataService* wds);
void SendSuggestions(const std::vector<string16>* suggestions);
void CancelPendingQuery();
@@ -59,7 +61,6 @@ class AutocompleteHistoryManager : public TabContentsObserver,
private:
void OnRemoveAutocompleteEntry(const string16& name, const string16& value);
- TabContents* tab_contents_;
Profile* profile_;
scoped_refptr<WebDataService> web_data_service_;
diff --git a/chrome/browser/autocomplete_history_manager_unittest.cc b/chrome/browser/autocomplete_history_manager_unittest.cc
index 09d343f..6645263 100644
--- a/chrome/browser/autocomplete_history_manager_unittest.cc
+++ b/chrome/browser/autocomplete_history_manager_unittest.cc
@@ -9,6 +9,8 @@
#include "base/task.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete_history_manager.h"
+#include "chrome/browser/renderer_host/test/test_render_view_host.h"
+#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_browser_process_test.h"
@@ -26,19 +28,19 @@ class MockWebDataService : public WebDataService {
void(const std::vector<webkit_glue::FormField>&)); // NOLINT
};
-class AutocompleteHistoryManagerTest : public TestingBrowserProcessTest {
+class AutocompleteHistoryManagerTest : public RenderViewHostTestHarness {
protected:
AutocompleteHistoryManagerTest()
- : ui_thread_(BrowserThread::UI, &message_loop_) {
+ : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {
}
virtual void SetUp() {
+ RenderViewHostTestHarness::SetUp();
web_data_service_ = new MockWebDataService();
- autocomplete_manager_.reset(
- new AutocompleteHistoryManager(&profile_, web_data_service_));
+ autocomplete_manager_.reset(new AutocompleteHistoryManager(
+ contents(), &profile_, web_data_service_));
}
- MessageLoopForUI message_loop_;
BrowserThread ui_thread_;
TestingProfile profile_;
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 17dcbe7..5861a4c 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -211,9 +211,9 @@ bool FormIsHTTPS(FormStructure* form) {
} // namespace
AutoFillManager::AutoFillManager(TabContents* tab_contents)
- : tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
personal_data_(NULL),
- download_manager_(tab_contents_->profile()),
+ download_manager_(tab_contents->profile()),
disable_download_manager_requests_(false),
metric_logger_(new AutoFillMetrics),
cc_infobar_(NULL) {
@@ -221,7 +221,7 @@ AutoFillManager::AutoFillManager(TabContents* tab_contents)
// |personal_data_| is NULL when using TestTabContents.
personal_data_ =
- tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager();
+ tab_contents->profile()->GetOriginalProfile()->GetPersonalDataManager();
download_manager_.SetObserver(this);
}
@@ -277,12 +277,12 @@ bool AutoFillManager::OnMessageReceived(const IPC::Message& message) {
void AutoFillManager::OnFormSubmitted(const FormData& form) {
// Let AutoComplete know as well.
- tab_contents_->autocomplete_history_manager()->OnFormSubmitted(form);
+ tab_contents()->autocomplete_history_manager()->OnFormSubmitted(form);
if (!IsAutoFillEnabled())
return;
- if (tab_contents_->profile()->IsOffTheRecord())
+ if (tab_contents()->profile()->IsOffTheRecord())
return;
// Don't save data that was submitted through JavaScript.
@@ -381,7 +381,7 @@ void AutoFillManager::OnQueryFormFieldAutoFill(
// Add the results from AutoComplete. They come back asynchronously, so we
// hand off what we generated and they will send the results back to the
// renderer.
- tab_contents_->autocomplete_history_manager()->OnGetAutocompleteSuggestions(
+ tab_contents()->autocomplete_history_manager()->OnGetAutocompleteSuggestions(
query_id, field.name(), field.value(), values, labels, icons, unique_ids);
}
@@ -518,22 +518,22 @@ void AutoFillManager::OnShowAutoFillDialog() {
return;
}
- ShowAutoFillDialog(tab_contents_->GetContentNativeView(),
+ ShowAutoFillDialog(tab_contents()->GetContentNativeView(),
personal_data_,
- tab_contents_->profile()->GetOriginalProfile());
+ tab_contents()->profile()->GetOriginalProfile());
}
void AutoFillManager::OnDidFillAutoFillFormData() {
NotificationService::current()->Notify(
NotificationType::AUTOFILL_DID_FILL_FORM_DATA,
- Source<RenderViewHost>(tab_contents_->render_view_host()),
+ Source<RenderViewHost>(tab_contents()->render_view_host()),
NotificationService::NoDetails());
}
void AutoFillManager::OnDidShowAutoFillSuggestions() {
NotificationService::current()->Notify(
NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS,
- Source<RenderViewHost>(tab_contents_->render_view_host()),
+ Source<RenderViewHost>(tab_contents()->render_view_host()),
NotificationService::NoDetails());
}
@@ -558,7 +558,8 @@ void AutoFillManager::OnHeuristicsRequestError(
}
bool AutoFillManager::IsAutoFillEnabled() const {
- PrefService* prefs = tab_contents_->profile()->GetPrefs();
+ PrefService* prefs =
+ const_cast<AutoFillManager*>(this)->tab_contents()->profile()->GetPrefs();
// Migrate obsolete AutoFill pref.
if (prefs->FindPreference(prefs::kFormAutofillEnabled)) {
@@ -675,10 +676,10 @@ void AutoFillManager::ImportFormData(const FormStructure& submitted_form) {
// If credit card information was submitted, show an infobar to offer to save
// it.
- if (imported_credit_card && tab_contents_) {
+ if (imported_credit_card && tab_contents()) {
imported_credit_card_.reset(imported_credit_card);
- tab_contents_->AddInfoBar(new AutoFillCCInfoBarDelegate(tab_contents_,
- this));
+ tab_contents()->AddInfoBar(new AutoFillCCInfoBarDelegate(tab_contents(),
+ this));
}
}
@@ -713,18 +714,9 @@ void AutoFillManager::OnInfoBarClosed(bool should_save) {
personal_data_->SaveImportedCreditCard(*imported_credit_card_);
}
-AutoFillManager::AutoFillManager()
- : tab_contents_(NULL),
- personal_data_(NULL),
- download_manager_(NULL),
- disable_download_manager_requests_(true),
- metric_logger_(new AutoFillMetrics),
- cc_infobar_(NULL) {
-}
-
AutoFillManager::AutoFillManager(TabContents* tab_contents,
PersonalDataManager* personal_data)
- : tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
personal_data_(personal_data),
download_manager_(NULL),
disable_download_manager_requests_(true),
@@ -748,7 +740,7 @@ bool AutoFillManager::GetHost(const std::vector<AutoFillProfile*>& profiles,
if (profiles.empty() && credit_cards.empty())
return false;
- *host = tab_contents_->render_view_host();
+ *host = tab_contents()->render_view_host();
if (!*host)
return false;
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index aff0abc..8cc2420 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -45,9 +45,6 @@ class AutoFillManager : public TabContentsObserver,
// Registers our Enable/Disable AutoFill pref.
static void RegisterUserPrefs(PrefService* prefs);
- // Returns the TabContents hosting this AutoFillManager.
- TabContents* tab_contents() const { return tab_contents_; }
-
// TabContentsObserver implementation.
virtual void DidNavigateMainFramePostCommit(
const NavigationController::LoadCommittedDetails& details,
@@ -80,7 +77,6 @@ class AutoFillManager : public TabContentsObserver,
protected:
// For tests.
- AutoFillManager();
AutoFillManager(TabContents* tab_contents,
PersonalDataManager* personal_data);
@@ -187,11 +183,6 @@ class AutoFillManager : public TabContentsObserver,
void LogMetricsAboutSubmittedForm(const webkit_glue::FormData& form,
const FormStructure* submitted_form);
- // The TabContents hosting this AutoFillManager.
- // Weak reference.
- // May not be NULL.
- TabContents* tab_contents_;
-
// The personal data manager, used to save and load personal data to/from the
// web database. This is overridden by the AutoFillManagerTest.
// Weak reference.
diff --git a/chrome/browser/desktop_notification_handler.cc b/chrome/browser/desktop_notification_handler.cc
index 7f6cab2..69108a51 100644
--- a/chrome/browser/desktop_notification_handler.cc
+++ b/chrome/browser/desktop_notification_handler.cc
@@ -87,3 +87,9 @@ RenderProcessHost* DesktopNotificationHandler::GetRenderProcessHost() {
return tab_ ? tab_->GetRenderProcessHost() : process_;
}
+DesktopNotificationHandlerForTC::DesktopNotificationHandlerForTC(
+ TabContents* tab_contents,
+ RenderProcessHost* process)
+ : TabContentsObserver(tab_contents),
+ DesktopNotificationHandler(tab_contents, process) {
+}
diff --git a/chrome/browser/desktop_notification_handler.h b/chrome/browser/desktop_notification_handler.h
index d8c37cf..17a6801 100644
--- a/chrome/browser/desktop_notification_handler.h
+++ b/chrome/browser/desktop_notification_handler.h
@@ -7,17 +7,18 @@
#pragma once
#include "chrome/browser/tab_contents/tab_contents_observer.h"
-#include "ipc/ipc_message.h"
struct ViewHostMsg_ShowNotification_Params;
class RenderProcessHost;
// Per-tab Desktop notification handler. Handles desktop notification IPCs
// coming in from the renderer.
-class DesktopNotificationHandler : public TabContentsObserver {
+class DesktopNotificationHandler {
public:
- explicit DesktopNotificationHandler(TabContents* tab_contents,
- RenderProcessHost* process);
+ // tab_contents will be NULL when this object is used with non-tab contents,
+ // i.e. ExtensionHost.
+ DesktopNotificationHandler(TabContents* tab_contents,
+ RenderProcessHost* process);
virtual ~DesktopNotificationHandler() {}
// TabContentsObserver implementation.
@@ -43,5 +44,17 @@ class DesktopNotificationHandler : public TabContentsObserver {
DISALLOW_COPY_AND_ASSIGN(DesktopNotificationHandler);
};
+// A wrapper around DesktopNotificationHandler that implements
+// TabContentsObserver.
+class DesktopNotificationHandlerForTC : public TabContentsObserver,
+ public DesktopNotificationHandler {
+ public:
+ // tab_contents will be NULL when this object is used with non-tab contents,
+ // i.e. ExtensionHost.
+ DesktopNotificationHandlerForTC(TabContents* tab_contents,
+ RenderProcessHost* process);
+};
+
+
#endif // CHROME_BROWSER_DESKTOP_NOTIFICATION_HANDLER_H_
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index 01edafe..80d6c93 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -157,8 +157,8 @@ SavePackage::SavePackage(TabContents* tab_contents,
SavePackageType save_type,
const FilePath& file_full_path,
const FilePath& directory_full_path)
- : file_manager_(NULL),
- tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
+ file_manager_(NULL),
download_(NULL),
page_url_(GetUrlToBeSaved()),
saved_main_file_path_(file_full_path),
@@ -184,8 +184,8 @@ SavePackage::SavePackage(TabContents* tab_contents,
}
SavePackage::SavePackage(TabContents* tab_contents)
- : file_manager_(NULL),
- tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
+ file_manager_(NULL),
download_(NULL),
page_url_(GetUrlToBeSaved()),
title_(tab_contents->GetTitle()),
@@ -208,8 +208,8 @@ SavePackage::SavePackage(TabContents* tab_contents)
SavePackage::SavePackage(TabContents* tab_contents,
const FilePath& file_full_path,
const FilePath& directory_full_path)
- : file_manager_(NULL),
- tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
+ file_manager_(NULL),
download_(NULL),
saved_main_file_path_(file_full_path),
saved_main_directory_path_(directory_full_path),
@@ -265,7 +265,7 @@ GURL SavePackage::GetUrlToBeSaved() {
// rather than the displayed one (returned by GetURL) which may be
// different (like having "view-source:" on the front).
NavigationEntry* active_entry =
- tab_contents_->controller().GetActiveEntry();
+ tab_contents()->controller().GetActiveEntry();
return active_entry->url();
}
@@ -305,7 +305,7 @@ bool SavePackage::Init() {
wait_state_ = START_PROCESS;
// Initialize the request context and resource dispatcher.
- Profile* profile = tab_contents_->profile();
+ Profile* profile = tab_contents()->profile();
if (!profile) {
NOTREACHED();
return false;
@@ -315,7 +315,7 @@ bool SavePackage::Init() {
// Create the fake DownloadItem and display the view.
DownloadManager* download_manager =
- tab_contents_->profile()->GetDownloadManager();
+ tab_contents()->profile()->GetDownloadManager();
download_ = new DownloadItem(download_manager,
saved_main_file_path_,
page_url_,
@@ -325,7 +325,7 @@ bool SavePackage::Init() {
// to be alive as long as the Profile is alive.
download_manager->SavePageAsDownloadStarted(download_);
- tab_contents_->OnStartDownload(download_);
+ tab_contents()->OnStartDownload(download_);
// Check save type and process the save page job.
if (save_type_ == SAVE_AS_COMPLETE_HTML) {
@@ -715,8 +715,8 @@ void SavePackage::CheckFinish() {
&SaveFileManager::RenameAllFiles,
final_names,
dir,
- tab_contents_->GetRenderProcessHost()->id(),
- tab_contents_->render_view_host()->routing_id(),
+ tab_contents()->GetRenderProcessHost()->id(),
+ tab_contents()->render_view_host()->routing_id(),
id()));
}
@@ -849,7 +849,7 @@ void SavePackage::SaveCanceled(SaveItem* save_item) {
// the save source. Parameter process_all_remaining_items indicates whether
// we need to save all remaining items.
void SavePackage::SaveNextFile(bool process_all_remaining_items) {
- DCHECK(tab_contents_);
+ DCHECK(tab_contents());
DCHECK(waiting_item_queue_.size());
do {
@@ -865,8 +865,8 @@ void SavePackage::SaveNextFile(bool process_all_remaining_items) {
save_item->Start();
file_manager_->SaveURL(save_item->url(),
save_item->referrer(),
- tab_contents_->GetRenderProcessHost()->id(),
- tab_contents_->render_view_host()->routing_id(),
+ tab_contents()->GetRenderProcessHost()->id(),
+ routing_id(),
save_item->save_source(),
save_item->full_path(),
request_context_getter_.get(),
@@ -996,7 +996,7 @@ void SavePackage::GetSerializedHtmlDataForCurrentPageWithLocalLinks() {
// Get the relative directory name.
FilePath relative_dir_name = saved_main_directory_path_.BaseName();
- tab_contents_->render_view_host()->
+ tab_contents()->render_view_host()->
GetSerializedHtmlDataForCurrentPageWithLocalLinks(
saved_links, saved_file_paths, relative_dir_name);
}
@@ -1071,7 +1071,7 @@ void SavePackage::GetAllSavableResourceLinksForCurrentPage() {
return;
wait_state_ = RESOURCES_LIST;
- tab_contents_->render_view_host()->
+ tab_contents()->render_view_host()->
GetAllSavableResourceLinksForCurrentPage(page_url_);
}
@@ -1254,11 +1254,11 @@ FilePath SavePackage::GetSaveDirPreference(PrefService* prefs) {
void SavePackage::GetSaveInfo() {
// Can't use tab_contents_ in the file thread, so get the data that we need
// before calling to it.
- PrefService* prefs = tab_contents_->profile()->GetPrefs();
+ PrefService* prefs = tab_contents()->profile()->GetPrefs();
FilePath website_save_dir = GetSaveDirPreference(prefs);
FilePath download_save_dir = prefs->GetFilePath(
prefs::kDownloadDefaultDirectory);
- std::string mime_type = tab_contents_->contents_mime_type();
+ std::string mime_type = tab_contents()->contents_mime_type();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
@@ -1311,7 +1311,7 @@ void SavePackage::CreateDirectoryOnFileThread(
void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path,
bool can_save_as_complete) {
DownloadPrefs* download_prefs =
- tab_contents_->profile()->GetDownloadManager()->download_prefs();
+ tab_contents()->profile()->GetDownloadManager()->download_prefs();
int file_type_index =
SavePackageTypeToIndex(
static_cast<SavePackageType>(download_prefs->save_file_type()));
@@ -1382,7 +1382,7 @@ void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path,
file_type_index,
default_extension,
platform_util::GetTopLevel(
- tab_contents_->GetNativeView()),
+ tab_contents()->GetNativeView()),
NULL);
} else {
// Just use 'suggested_path' instead of opening the dialog prompt.
@@ -1395,7 +1395,7 @@ void SavePackage::ContinueSave(const FilePath& final_name,
int index) {
// Ensure the filename is safe.
saved_main_file_path_ = final_name;
- download_util::GenerateSafeFileName(tab_contents_->contents_mime_type(),
+ download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(),
&saved_main_file_path_);
// The option index is not zero-based.
@@ -1404,7 +1404,7 @@ void SavePackage::ContinueSave(const FilePath& final_name,
saved_main_directory_path_ = saved_main_file_path_.DirName();
- PrefService* prefs = tab_contents_->profile()->GetPrefs();
+ PrefService* prefs = tab_contents()->profile()->GetPrefs();
StringPrefMember save_file_path;
save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL);
#if defined(OS_POSIX)
@@ -1414,7 +1414,7 @@ void SavePackage::ContinueSave(const FilePath& final_name,
#endif
// If user change the default saving directory, we will remember it just
// like IE and FireFox.
- if (!tab_contents_->profile()->IsOffTheRecord() &&
+ if (!tab_contents()->profile()->IsOffTheRecord() &&
save_file_path.GetValue() != path_string) {
save_file_path.SetValue(path_string);
}
diff --git a/chrome/browser/download/save_package.h b/chrome/browser/download/save_package.h
index 59e27f3..829f1ae 100644
--- a/chrome/browser/download/save_package.h
+++ b/chrome/browser/download/save_package.h
@@ -269,8 +269,6 @@ class SavePackage : public base::RefCountedThreadSafe<SavePackage>,
// Non-owning pointer for handling file writing on the file thread.
SaveFileManager* file_manager_;
- TabContents* tab_contents_;
-
// We use a fake DownloadItem here in order to reuse the DownloadItemView.
// This class owns the pointer.
DownloadItem* download_;
diff --git a/chrome/browser/download/save_package_unittest.cc b/chrome/browser/download/save_package_unittest.cc
index 908fab7..5dd5d78 100644
--- a/chrome/browser/download/save_package_unittest.cc
+++ b/chrome/browser/download/save_package_unittest.cc
@@ -351,7 +351,7 @@ static const struct SuggestedSaveNameTestCase {
TEST_F(SavePackageTest, TestSuggestedSaveNames) {
for (size_t i = 0; i < arraysize(kSuggestedSaveNames); ++i) {
scoped_refptr<SavePackage> save_package(
- new SavePackage(NULL, FilePath(), FilePath()));
+ new SavePackage(contents(), FilePath(), FilePath()));
save_package->page_url_ = GURL(kSuggestedSaveNames[i].page_url);
save_package->title_ = kSuggestedSaveNames[i].page_title;
diff --git a/chrome/browser/fav_icon_helper.cc b/chrome/browser/fav_icon_helper.cc
index 0f19eca..27edcc5 100644
--- a/chrome/browser/fav_icon_helper.cc
+++ b/chrome/browser/fav_icon_helper.cc
@@ -23,7 +23,7 @@
#include "ui/gfx/favicon_size.h"
FavIconHelper::FavIconHelper(TabContents* tab_contents)
- : tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
got_fav_icon_url_(false),
got_fav_icon_from_history_(false),
fav_icon_expired_(false) {
@@ -65,7 +65,7 @@ int FavIconHelper::DownloadImage(const GURL& image_url,
}
Profile* FavIconHelper::profile() {
- return tab_contents_->profile();
+ return tab_contents()->profile();
}
FaviconService* FavIconHelper::GetFaviconService() {
@@ -109,7 +109,7 @@ void FavIconHelper::UpdateFavIcon(NavigationEntry* entry,
return;
entry->favicon().set_bitmap(image);
- tab_contents_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB);
+ tab_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB);
}
void FavIconHelper::OnUpdateFavIconURL(int32 page_id, const GURL& icon_url) {
@@ -170,9 +170,9 @@ void FavIconHelper::OnDidDownloadFavIcon(int id,
}
NavigationEntry* FavIconHelper::GetEntry() {
- NavigationEntry* entry = tab_contents_->controller().GetActiveEntry();
+ NavigationEntry* entry = tab_contents()->controller().GetActiveEntry();
if (entry && entry->url() == url_ &&
- tab_contents_->IsActiveEntry(entry->page_id())) {
+ tab_contents()->IsActiveEntry(entry->page_id())) {
return entry;
}
// If the URL has changed out from under us (as will happen with redirects)
@@ -282,7 +282,7 @@ int FavIconHelper::ScheduleDownload(const GURL& url,
const GURL& image_url,
int image_size,
ImageDownloadCallback* callback) {
- const int download_id = tab_contents_->render_view_host()->DownloadFavIcon(
+ const int download_id = tab_contents()->render_view_host()->DownloadFavIcon(
image_url, image_size);
if (download_id) {
diff --git a/chrome/browser/fav_icon_helper.h b/chrome/browser/fav_icon_helper.h
index 3ec480f..0084979 100644
--- a/chrome/browser/fav_icon_helper.h
+++ b/chrome/browser/fav_icon_helper.h
@@ -161,9 +161,6 @@ class FavIconHelper : public TabContentsObserver {
// Returns true if the favicon should be saved.
bool ShouldSaveFavicon(const GURL& url);
- // Hosting TabContents. We callback into this when done.
- TabContents* tab_contents_;
-
// Used for history requests.
CancelableRequestConsumer cancelable_consumer_;
diff --git a/chrome/browser/password_manager/password_manager.cc b/chrome/browser/password_manager/password_manager.cc
index a847958..bc8d660 100644
--- a/chrome/browser/password_manager/password_manager.cc
+++ b/chrome/browser/password_manager/password_manager.cc
@@ -50,8 +50,10 @@ static void ReportMetrics(bool password_manager_enabled) {
UserMetrics::RecordAction(UserMetricsAction("PasswordManager_Disabled"));
}
-PasswordManager::PasswordManager(PasswordManagerDelegate* delegate)
- : login_managers_deleter_(&pending_login_managers_),
+PasswordManager::PasswordManager(TabContents* tab_contents,
+ PasswordManagerDelegate* delegate)
+ : TabContentsObserver(tab_contents),
+ login_managers_deleter_(&pending_login_managers_),
delegate_(delegate),
observer_(NULL) {
DCHECK(delegate_);
diff --git a/chrome/browser/password_manager/password_manager.h b/chrome/browser/password_manager/password_manager.h
index 547f1f3..5562d01 100644
--- a/chrome/browser/password_manager/password_manager.h
+++ b/chrome/browser/password_manager/password_manager.h
@@ -30,7 +30,8 @@ class PasswordManager : public LoginModel,
static void RegisterUserPrefs(PrefService* prefs);
// The delegate passed in is required to outlive the PasswordManager.
- explicit PasswordManager(PasswordManagerDelegate* delegate);
+ PasswordManager(TabContents* tab_contents,
+ PasswordManagerDelegate* delegate);
virtual ~PasswordManager();
// Called by a PasswordFormManager when it decides a form can be autofilled
diff --git a/chrome/browser/password_manager/password_manager_unittest.cc b/chrome/browser/password_manager/password_manager_unittest.cc
index d0b7f4f..9ad7445 100644
--- a/chrome/browser/password_manager/password_manager_unittest.cc
+++ b/chrome/browser/password_manager/password_manager_unittest.cc
@@ -11,6 +11,8 @@
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/password_manager/password_manager_delegate.h"
#include "chrome/browser/password_manager/password_store.h"
+#include "chrome/browser/renderer_host/test/test_render_view_host.h"
+#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -73,18 +75,20 @@ ACTION_P(SaveToScopedPtr, scoped) {
scoped->reset(arg0);
}
-class PasswordManagerTest : public testing::Test {
+class PasswordManagerTest : public RenderViewHostTestHarness {
public:
PasswordManagerTest()
- : ui_thread_(BrowserThread::UI, &message_loop_) {}
+ : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {}
protected:
virtual void SetUp() {
+ RenderViewHostTestHarness::SetUp();
+
store_ = new MockPasswordStore();
profile_.reset(new TestingProfileWithPasswordStore(store_));
EXPECT_CALL(delegate_, GetProfileForPasswordManager())
.WillRepeatedly(Return(profile_.get()));
- manager_.reset(new PasswordManager(&delegate_));
+ manager_.reset(new PasswordManager(contents(), &delegate_));
EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors())
.WillRepeatedly(Return(false));
}
@@ -110,7 +114,6 @@ class PasswordManagerTest : public testing::Test {
PasswordManager* manager() { return manager_.get(); }
// We create a UI thread to satisfy PasswordStore.
- MessageLoopForUI message_loop_;
BrowserThread ui_thread_;
scoped_ptr<Profile> profile_;
diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc
index 0d0831c..02e002a 100644
--- a/chrome/browser/plugin_observer.cc
+++ b/chrome/browser/plugin_observer.cc
@@ -244,7 +244,7 @@ bool OutdatedPluginInfoBarDelegate::LinkClicked(
// PluginObserver -------------------------------------------------------------
PluginObserver::PluginObserver(TabContents* tab_contents)
- : tab_contents_(tab_contents) {
+ : TabContentsObserver(tab_contents) {
}
PluginObserver::~PluginObserver() {
@@ -264,7 +264,7 @@ bool PluginObserver::OnMessageReceived(const IPC::Message& message) {
PluginInstallerInfoBarDelegate* PluginObserver::GetPluginInstaller() {
if (plugin_installer_ == NULL)
- plugin_installer_.reset(new PluginInstallerInfoBarDelegate(tab_contents_));
+ plugin_installer_.reset(new PluginInstallerInfoBarDelegate(tab_contents()));
return plugin_installer_->AsPluginInstallerInfoBarDelegate();
}
@@ -272,17 +272,17 @@ void PluginObserver::OnMissingPluginStatus(int status) {
// TODO(PORT): pull in when plug-ins work
#if defined(OS_WIN)
if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
- tab_contents_->AddInfoBar(
- new PluginInstallerInfoBarDelegate(tab_contents_));
+ tab_contents()->AddInfoBar(
+ new PluginInstallerInfoBarDelegate(tab_contents()));
return;
}
DCHECK_EQ(webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD,
status);
- for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) {
- InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i);
+ for (size_t i = 0; i < tab_contents()->infobar_count(); ++i) {
+ InfoBarDelegate* delegate = tab_contents()->GetInfoBarDelegateAt(i);
if (delegate->AsPluginInstallerInfoBarDelegate() != NULL) {
- tab_contents_->RemoveInfoBar(delegate);
+ tab_contents()->RemoveInfoBar(delegate);
return;
}
}
@@ -308,7 +308,7 @@ void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) {
}
SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
IDR_INFOBAR_PLUGIN_CRASHED);
- tab_contents_->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents_,
+ tab_contents()->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(),
crash_icon,
l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
true));
@@ -316,9 +316,9 @@ void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) {
void PluginObserver::OnBlockedOutdatedPlugin(const string16& name,
const GURL& update_url) {
- tab_contents_->AddInfoBar(update_url.is_empty() ?
+ tab_contents()->AddInfoBar(update_url.is_empty() ?
static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate(
- tab_contents_, name)) :
- new OutdatedPluginInfoBarDelegate(tab_contents_, name, update_url));
+ tab_contents(), name)) :
+ new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url));
}
diff --git a/chrome/browser/plugin_observer.h b/chrome/browser/plugin_observer.h
index 9f7a6be..2d2f895 100644
--- a/chrome/browser/plugin_observer.h
+++ b/chrome/browser/plugin_observer.h
@@ -30,7 +30,6 @@ class PluginObserver : public TabContentsObserver {
void OnCrashedPlugin(const FilePath& plugin_path);
void OnBlockedOutdatedPlugin(const string16& name, const GURL& update_url);
- TabContents* tab_contents_; // Weak, owns us.
scoped_ptr<InfoBarDelegate> plugin_installer_; // Lazily created.
DISALLOW_COPY_AND_ASSIGN(PluginObserver);
diff --git a/chrome/browser/prerender/prerender_plt_recorder.cc b/chrome/browser/prerender/prerender_plt_recorder.cc
index f13c664..0743800 100644
--- a/chrome/browser/prerender/prerender_plt_recorder.cc
+++ b/chrome/browser/prerender/prerender_plt_recorder.cc
@@ -13,9 +13,8 @@
namespace prerender {
PrerenderPLTRecorder::PrerenderPLTRecorder(TabContents* tab_contents)
- : tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
pplt_load_start_() {
-
}
PrerenderPLTRecorder::~PrerenderPLTRecorder() {
@@ -40,7 +39,7 @@ void PrerenderPLTRecorder::OnDidStartProvisionalLoadForFrame(int64 frame_id,
void PrerenderPLTRecorder::DidStopLoading() {
// Compute the PPLT metric and report it in a histogram, if needed.
- PrerenderManager* pm = tab_contents_->profile()->GetPrerenderManager();
+ PrerenderManager* pm = tab_contents()->profile()->GetPrerenderManager();
if (pm != NULL && !pplt_load_start_.is_null())
pm->RecordPerceivedPageLoadTime(base::TimeTicks::Now() - pplt_load_start_);
diff --git a/chrome/browser/prerender/prerender_plt_recorder.h b/chrome/browser/prerender/prerender_plt_recorder.h
index 34179c0..0d52710 100644
--- a/chrome/browser/prerender/prerender_plt_recorder.h
+++ b/chrome/browser/prerender/prerender_plt_recorder.h
@@ -38,8 +38,6 @@ class PrerenderPLTRecorder : public TabContentsObserver {
virtual void DidStopLoading();
private:
- TabContents* tab_contents_;
-
// System time at which the current load was started for the purpose of
// the perceived page load time (PPLT).
base::TimeTicks pplt_load_start_;
diff --git a/chrome/browser/printing/print_preview_message_handler.cc b/chrome/browser/printing/print_preview_message_handler.cc
index fdf3b30..f7f0218 100644
--- a/chrome/browser/printing/print_preview_message_handler.cc
+++ b/chrome/browser/printing/print_preview_message_handler.cc
@@ -20,9 +20,10 @@
namespace printing {
-PrintPreviewMessageHandler::PrintPreviewMessageHandler(TabContents* owner)
- : owner_(owner) {
- DCHECK(owner);
+PrintPreviewMessageHandler::PrintPreviewMessageHandler(
+ TabContents* tab_contents)
+ : TabContentsObserver(tab_contents) {
+ DCHECK(tab_contents);
}
PrintPreviewMessageHandler::~PrintPreviewMessageHandler() {
@@ -34,7 +35,7 @@ TabContents* PrintPreviewMessageHandler::GetPrintPreviewTab() {
printing::PrintPreviewTabController::GetInstance();
if (!tab_controller)
return NULL;
- return tab_controller->GetPrintPreviewForTab(owner_);
+ return tab_controller->GetPrintPreviewForTab(tab_contents());
}
void PrintPreviewMessageHandler::OnPagesReadyForPreview(
@@ -70,7 +71,7 @@ void PrintPreviewMessageHandler::OnPagesReadyForPreview(
&printing::PrinterQuery::StopWorker));
}
- RenderViewHost* rvh = owner_->render_view_host();
+ RenderViewHost* rvh = tab_contents()->render_view_host();
rvh->Send(new ViewMsg_PrintingDone(rvh->routing_id(),
params.document_cookie,
true));
diff --git a/chrome/browser/printing/print_preview_message_handler.h b/chrome/browser/printing/print_preview_message_handler.h
index 27963b1..e1ef29f 100644
--- a/chrome/browser/printing/print_preview_message_handler.h
+++ b/chrome/browser/printing/print_preview_message_handler.h
@@ -17,7 +17,7 @@ namespace printing {
// TabContents that owns it.
class PrintPreviewMessageHandler : public TabContentsObserver {
public:
- explicit PrintPreviewMessageHandler(TabContents* owner);
+ explicit PrintPreviewMessageHandler(TabContents* tab_contents);
virtual ~PrintPreviewMessageHandler();
void OnPagesReadyForPreview(
@@ -30,9 +30,6 @@ class PrintPreviewMessageHandler : public TabContentsObserver {
// Gets the print preview tab associated with |owner_|.
TabContents* GetPrintPreviewTab();
- // The TabContents that owns this PrintPreviewMessageHandler.
- TabContents* owner_;
-
DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler);
};
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index 1871e31..15cef0a 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -26,12 +26,12 @@ using base::TimeDelta;
namespace printing {
-PrintViewManager::PrintViewManager(TabContents& owner)
- : number_pages_(0),
+PrintViewManager::PrintViewManager(TabContents* tab_contents)
+ : TabContentsObserver(tab_contents),
+ number_pages_(0),
waiting_to_print_(false),
printing_succeeded_(false),
- inside_inner_message_loop_(false),
- owner_(owner) {
+ inside_inner_message_loop_(false) {
}
PrintViewManager::~PrintViewManager() {
@@ -47,7 +47,7 @@ bool PrintViewManager::OnRenderViewGone(RenderViewHost* render_view_host) {
if (!print_job_.get())
return true;
- if (render_view_host != owner_.render_view_host())
+ if (render_view_host != tab_contents()->render_view_host())
return false;
scoped_refptr<PrintedDocument> document(print_job_->document());
@@ -61,14 +61,14 @@ bool PrintViewManager::OnRenderViewGone(RenderViewHost* render_view_host) {
}
string16 PrintViewManager::RenderSourceName() {
- string16 name(owner_.GetTitle());
+ string16 name(tab_contents()->GetTitle());
if (name.empty())
name = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE);
return name;
}
GURL PrintViewManager::RenderSourceUrl() {
- NavigationEntry* entry = owner_.controller().GetActiveEntry();
+ NavigationEntry* entry = tab_contents()->controller().GetActiveEntry();
if (entry)
return entry->virtual_url();
else
@@ -109,7 +109,7 @@ void PrintViewManager::OnDidPrintPage(
if (params.data_size && params.data_size >= 350*1024*1024) {
NOTREACHED() << "size:" << params.data_size;
TerminatePrintJob(true);
- owner_.Stop();
+ tab_contents()->Stop();
return;
}
#endif
@@ -117,7 +117,7 @@ void PrintViewManager::OnDidPrintPage(
base::SharedMemory shared_buf(params.metafile_data_handle, true);
if (!shared_buf.Map(params.data_size)) {
NOTREACHED() << "couldn't map";
- owner_.Stop();
+ tab_contents()->Stop();
return;
}
@@ -127,7 +127,7 @@ void PrintViewManager::OnDidPrintPage(
scoped_ptr<NativeMetafile> metafile(new NativeMetafile());
if (!metafile->Init(shared_buf.memory(), params.data_size)) {
NOTREACHED() << "Invalid metafile header";
- owner_.Stop();
+ tab_contents()->Stop();
return;
}
@@ -217,8 +217,8 @@ bool PrintViewManager::RenderAllMissingPagesNow() {
}
// We can't print if there is no renderer.
- if (!owner_.render_view_host() ||
- !owner_.render_view_host()->IsRenderViewLive()) {
+ if (!tab_contents()->render_view_host() ||
+ !tab_contents()->render_view_host()->IsRenderViewLive()) {
waiting_to_print_ = false;
return false;
}
@@ -275,8 +275,8 @@ bool PrintViewManager::CreateNewPrintJob(PrintJobWorkerOwner* job) {
DisconnectFromCurrentPrintJob();
// We can't print if there is no renderer.
- if (!owner_.render_view_host() ||
- !owner_.render_view_host()->IsRenderViewLive()) {
+ if (!tab_contents()->render_view_host() ||
+ !tab_contents()->render_view_host()->IsRenderViewLive()) {
return false;
}
@@ -315,7 +315,7 @@ void PrintViewManager::DisconnectFromCurrentPrintJob() {
void PrintViewManager::PrintingDone(bool success) {
if (print_job_.get()) {
- owner_.PrintingDone(print_job_->cookie(), success);
+ tab_contents()->PrintingDone(print_job_->cookie(), success);
}
}
diff --git a/chrome/browser/printing/print_view_manager.h b/chrome/browser/printing/print_view_manager.h
index 3f40995..18a4f7e 100644
--- a/chrome/browser/printing/print_view_manager.h
+++ b/chrome/browser/printing/print_view_manager.h
@@ -29,7 +29,7 @@ class PrintViewManager : public NotificationObserver,
public PrintedPagesSource,
public TabContentsObserver {
public:
- explicit PrintViewManager(TabContents& owner);
+ explicit PrintViewManager(TabContents* tab_contents);
virtual ~PrintViewManager();
// Cancels the print job.
@@ -124,11 +124,6 @@ class PrintViewManager : public NotificationObserver,
// print settings are being loaded.
bool inside_inner_message_loop_;
- // PrintViewManager is created as an extension of WebContent specialized for
- // printing-related behavior. Still, access to the renderer is needed so a
- // back reference is kept the the "parent object".
- TabContents& owner_;
-
DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
};
diff --git a/chrome/browser/safe_browsing/malware_details.cc b/chrome/browser/safe_browsing/malware_details.cc
index 5cfa993..d985ad5 100644
--- a/chrome/browser/safe_browsing/malware_details.cc
+++ b/chrome/browser/safe_browsing/malware_details.cc
@@ -63,7 +63,7 @@ MalwareDetails* MalwareDetails::NewMalwareDetails(
MalwareDetails::MalwareDetails(
TabContents* tab_contents,
const SafeBrowsingService::UnsafeResource resource)
- : tab_contents_(tab_contents),
+ : TabContentsObserver(tab_contents),
resource_(resource) {
StartCollection();
}
@@ -142,13 +142,13 @@ void MalwareDetails::StartCollection() {
report_->set_malware_url(resource_.url.spec());
}
- GURL page_url = tab_contents_->GetURL();
+ GURL page_url = tab_contents()->GetURL();
if (IsPublicUrl(page_url)) {
report_->set_page_url(page_url.spec());
}
GURL referrer_url;
- NavigationEntry* nav_entry = tab_contents_->controller().GetActiveEntry();
+ NavigationEntry* nav_entry = tab_contents()->controller().GetActiveEntry();
if (nav_entry) {
referrer_url = nav_entry->referrer();
if (IsPublicUrl(referrer_url)) {
@@ -191,7 +191,7 @@ void MalwareDetails::StartCollection() {
// Get URLs of frames, scripts etc from the DOM.
// OnReceivedMalwareDOMDetails will be called when the renderer replies.
- tab_contents_->render_view_host()->GetMalwareDOMDetails();
+ tab_contents()->render_view_host()->GetMalwareDOMDetails();
}
// When the renderer is done, this is called.
diff --git a/chrome/browser/safe_browsing/malware_details.h b/chrome/browser/safe_browsing/malware_details.h
index 94944f0..bc5f943 100644
--- a/chrome/browser/safe_browsing/malware_details.h
+++ b/chrome/browser/safe_browsing/malware_details.h
@@ -93,7 +93,6 @@ class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>,
void OnReceivedMalwareDOMDetails(
const ViewHostMsg_MalwareDOMDetails_Params& params);
- TabContents* tab_contents_;
const SafeBrowsingService::UnsafeResource resource_;
// For every Url we collect we create a Resource message. We keep
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
index 2f9210c..701ca69 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
@@ -128,8 +128,7 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
unsafe_resources[0].url),
sb_service_(sb_service),
is_main_frame_(IsMainPage(unsafe_resources)),
- unsafe_resources_(unsafe_resources),
- malware_details_(NULL) {
+ unsafe_resources_(unsafe_resources) {
RecordUserAction(SHOW);
if (!is_main_frame_) {
navigation_entry_index_to_remove_ =
@@ -149,7 +148,6 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
CanShowMalwareDetailsOption()) {
malware_details_ = MalwareDetails::NewMalwareDetails(
tab(), unsafe_resources[0]);
- tab_contents->AddObserver(malware_details_);
}
}
@@ -601,10 +599,6 @@ void SafeBrowsingBlockingPage::FinishMalwareDetails() {
if (malware_details_ == NULL)
return; // Not all interstitials have malware details (eg phishing).
- // Stop observing IPC messages from the tab. A subsequent warning page
- // on the same tab will listen instead.
- tab()->RemoveObserver(malware_details_);
-
const PrefService::Preference* pref =
tab()->profile()->GetPrefs()->FindPreference(
prefs::kSafeBrowsingReportingEnabled);
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 2fd6ea1..223668c 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -254,48 +254,29 @@ TabContents::TabContents(Profile* profile,
ALLOW_THIS_IN_INITIALIZER_LIST(view_(
TabContentsView::Create(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
- property_bag_(),
- registrar_(),
- ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
- new printing::PrintViewManager(*this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(print_preview_(
- new printing::PrintPreviewMessageHandler(this))),
- save_package_(),
- autocomplete_history_manager_(),
- autofill_manager_(),
- prerender_plt_recorder_(),
bookmark_drag_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
is_loading_(false),
crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
crashed_error_code_(0),
waiting_for_response_(false),
max_page_id_(-1),
- current_load_start_(),
load_state_(net::LOAD_STATE_IDLE),
- load_state_host_(),
upload_size_(0),
upload_position_(0),
received_page_title_(false),
- contents_mime_type_(),
- encoding_(),
blocked_contents_(NULL),
all_contents_blocked_(false),
dont_notify_render_view_(false),
displayed_insecure_content_(false),
- infobar_delegates_(),
extension_app_(NULL),
capturing_contents_(false),
is_being_destroyed_(false),
notify_disconnection_(false),
- history_requests_(),
#if defined(OS_WIN)
message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
#endif
- last_javascript_message_dismissal_(),
suppress_javascript_messages_(false),
is_showing_before_unload_dialog_(false),
- renderer_preferences_(),
opener_web_ui_type_(WebUIFactory::kNoWebUI),
language_state_(&controller_),
closed_by_user_gesture_(false),
@@ -354,20 +335,10 @@ TabContents::TabContents(Profile* profile,
if (OmniboxSearchHint::IsEnabled(profile))
omnibox_search_hint_.reset(new OmniboxSearchHint(this));
- autofill_manager_.reset(new AutoFillManager(this));
- AddObserver(autofill_manager_.get());
- autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
- AddObserver(autocomplete_history_manager_.get());
- prerender_plt_recorder_.reset(new prerender::PrerenderPLTRecorder(this));
- AddObserver(prerender_plt_recorder_.get());
- AddObserver(&fav_icon_helper_);
- AddObserver(printing_.get());
- desktop_notification_handler_.reset(
- new DesktopNotificationHandler(this, GetRenderProcessHost()));
- AddObserver(desktop_notification_handler_.get());
- plugin_observer_.reset(new PluginObserver(this));
- AddObserver(plugin_observer_.get());
- AddObserver(print_preview_.get());
+ // Can only add observers after render_manager_.Init() is called, since that's
+ // what sets up the render_view_host which TabContentObserver's constructor
+ // uses to get the routing_id.
+ AddObservers();
}
TabContents::~TabContents() {
@@ -427,6 +398,20 @@ TabContents::~TabContents() {
UMA_HISTOGRAM_TIMES("Tab.Close",
base::TimeTicks::Now() - tab_close_start_time_);
}
+
+ FOR_EACH_OBSERVER(TabContentsObserver, observers_, set_tab_contents(NULL));
+}
+
+void TabContents::AddObservers() {
+ printing_.reset(new printing::PrintViewManager(this));
+ print_preview_.reset(new printing::PrintPreviewMessageHandler(this));
+ fav_icon_helper_.reset(new FavIconHelper(this));
+ autofill_manager_.reset(new AutoFillManager(this));
+ autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
+ prerender_plt_recorder_.reset(new prerender::PrerenderPLTRecorder(this));
+ desktop_notification_handler_.reset(
+ new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
+ plugin_observer_.reset(new PluginObserver(this));
}
// static
@@ -1276,7 +1261,7 @@ void TabContents::OnSavePage() {
// Create the save package and possibly prompt the user for the name to save
// the page as. The user prompt is an asynchronous operation that runs on
// another thread.
- SetSavePackage(new SavePackage(this));
+ save_package_ = new SavePackage(this);
save_package_->GetSaveInfo();
}
@@ -1288,17 +1273,10 @@ bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
// Stop the page from navigating.
Stop();
- SetSavePackage(new SavePackage(this, save_type, main_file, dir_path));
+ save_package_ = new SavePackage(this, save_type, main_file, dir_path);
return save_package_->Init();
}
-void TabContents::SetSavePackage(SavePackage* save_package) {
- if (save_package_.get())
- RemoveObserver(save_package_.get());
- save_package_ = save_package;
- AddObserver(save_package);
-}
-
void TabContents::EmailPageLocation() {
std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
@@ -1797,7 +1775,7 @@ void TabContents::DidNavigateMainFramePostCommit(
received_page_title_ = false;
// Get the favicon, either from history or request it from the net.
- fav_icon_helper_.FetchFavIcon(details.entry->url());
+ fav_icon_helper_->FetchFavIcon(details.entry->url());
// Clear all page actions, blocked content notifications and browser actions
// for this tab, unless this is an in-page navigation.
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 6da4023..3e6613d 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -181,7 +181,7 @@ class TabContents : public PageNavigator,
// Returns the FavIconHelper of this TabContents.
FavIconHelper& fav_icon_helper() {
- return fav_icon_helper_;
+ return *fav_icon_helper_.get();
}
// App extensions ------------------------------------------------------------
@@ -557,9 +557,6 @@ class TabContents : public PageNavigator,
bool SavePage(const FilePath& main_file, const FilePath& dir_path,
SavePackage::SavePackageType save_type);
- // Sets save_package_, taking care to register and unregister the observers.
- void SetSavePackage(SavePackage* save_package);
-
// Tells the user's email client to open a compose window containing the
// current page's URL.
void EmailPageLocation();
@@ -752,6 +749,9 @@ class TabContents : public PageNavigator,
// Used to access RVH Delegates.
friend class prerender::PrerenderManager;
+ // Add all the TabContentObservers.
+ void AddObservers();
+
// Message handlers.
void OnDidStartProvisionalLoadForFrame(int64 frame_id,
bool main_frame,
@@ -1079,7 +1079,7 @@ class TabContents : public PageNavigator,
BookmarkDrag* bookmark_drag_;
// Handles downloading favicons.
- FavIconHelper fav_icon_helper_;
+ scoped_ptr<FavIconHelper> fav_icon_helper_;
// Cached web app info data.
WebApplicationInfo web_app_info_;
diff --git a/chrome/browser/tab_contents/tab_contents_observer.cc b/chrome/browser/tab_contents/tab_contents_observer.cc
index 5ad1e1d..738539a 100644
--- a/chrome/browser/tab_contents/tab_contents_observer.cc
+++ b/chrome/browser/tab_contents/tab_contents_observer.cc
@@ -4,6 +4,29 @@
#include "chrome/browser/tab_contents/tab_contents_observer.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+
+TabContentsObserver::TabContentsObserver(TabContents* tab_contents)
+ : tab_contents_(tab_contents),
+ routing_id_(tab_contents->render_view_host()->routing_id()) {
+ tab_contents_->AddObserver(this);
+}
+
+TabContentsObserver::~TabContentsObserver() {
+ if (tab_contents_)
+ tab_contents_->RemoveObserver(this);
+}
+
bool TabContentsObserver::OnMessageReceived(const IPC::Message& message) {
return false;
}
+
+bool TabContentsObserver::Send(IPC::Message* message) {
+ if (!tab_contents_->render_view_host()) {
+ delete message;
+ return false;
+ }
+
+ return tab_contents_->render_view_host()->Send(message);
+}
diff --git a/chrome/browser/tab_contents/tab_contents_observer.h b/chrome/browser/tab_contents/tab_contents_observer.h
index 7e56ed97..55a609c 100644
--- a/chrome/browser/tab_contents/tab_contents_observer.h
+++ b/chrome/browser/tab_contents/tab_contents_observer.h
@@ -26,9 +26,6 @@ class TabContentsObserver : public IPC::Channel::Listener {
virtual void DidStartLoading() { }
virtual void DidStopLoading() { }
- // IPC::Channel::Listener implementation.
- virtual bool OnMessageReceived(const IPC::Message& message);
-
#if 0
// For unifying with delegate...
@@ -43,6 +40,30 @@ class TabContentsObserver : public IPC::Channel::Listener {
virtual void NavigationStateChanged(const TabContents* source,
unsigned changed_flags) { }
#endif
+
+ protected:
+ TabContentsObserver(TabContents* tab_contents);
+ virtual ~TabContentsObserver();
+
+ // IPC::Channel::Listener implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message);
+
+ // IPC::Message::Sender implementation.
+ virtual bool Send(IPC::Message* message);
+
+ TabContents* tab_contents() { return tab_contents_; }
+ int routing_id() { return routing_id_; }
+
+ private:
+ friend class TabContents;
+
+ void set_tab_contents(TabContents* tc) { tab_contents_ = tc; }
+
+ TabContents* tab_contents_;
+ // The routing ID of the associated TabContents.
+ int routing_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabContentsObserver);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index c6e7f18..feebc2d 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -3279,7 +3279,7 @@ void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) {
// Browser, SearchEngineTabHelperDelegate implementation:
void Browser::ConfirmSetDefaultSearchProvider(
- TabContentsWrapper* tab_contents,
+ TabContents* tab_contents,
TemplateURL* template_url,
TemplateURLModel* template_url_model) {
window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url,
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 6ca331c..7c073ef 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -813,7 +813,7 @@ class Browser : public TabHandlerDelegate,
bool starred) OVERRIDE;
// Overridden from SearchEngineTabHelperDelegate:
virtual void ConfirmSetDefaultSearchProvider(
- TabContentsWrapper* tab_contents,
+ TabContents* tab_contents,
TemplateURL* template_url,
TemplateURLModel* template_url_model) OVERRIDE;
virtual void ConfirmAddSearchProvider(const TemplateURL* template_url,
diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h
index 1097e81..b4c6761 100644
--- a/chrome/browser/ui/browser_window.h
+++ b/chrome/browser/ui/browser_window.h
@@ -188,7 +188,7 @@ class BrowserWindow {
// Shows a confirmation dialog box for setting the default search engine
// described by |template_url|. Takes ownership of |template_url|.
virtual void ConfirmSetDefaultSearchProvider(
- TabContentsWrapper* tab_contents,
+ TabContents* tab_contents,
TemplateURL* template_url,
TemplateURLModel* template_url_model) {
// TODO(levin): Implement this for non-Windows platforms and make it pure.
diff --git a/chrome/browser/ui/find_bar/find_tab_helper.cc b/chrome/browser/ui/find_bar/find_tab_helper.cc
index de2b3f7..8a098b8 100644
--- a/chrome/browser/ui/find_bar/find_tab_helper.cc
+++ b/chrome/browser/ui/find_bar/find_tab_helper.cc
@@ -8,22 +8,21 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/find_bar/find_bar_state.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
// static
int FindTabHelper::find_request_id_counter_ = -1;
-FindTabHelper::FindTabHelper(TabContentsWrapper* tab_contents)
- : tab_contents_(tab_contents),
+FindTabHelper::FindTabHelper(TabContents* tab_contents)
+ : TabContentsObserver(tab_contents),
find_ui_active_(false),
find_op_aborted_(false),
current_find_request_id_(find_request_id_counter_++),
last_search_case_sensitive_(false),
last_search_result_() {
- DCHECK(tab_contents_);
}
FindTabHelper::~FindTabHelper() {
@@ -36,7 +35,7 @@ void FindTabHelper::StartFinding(string16 search_string,
// shortcut so unless we have something to search for we return early.
if (search_string.empty() && find_text_.empty()) {
string16 last_search_prepopulate_text =
- FindBarState::GetLastPrepopulateText(tab_contents_->profile());
+ FindBarState::GetLastPrepopulateText(tab_contents()->profile());
// Try the last thing we searched for on this tab, then the last thing
// searched for on any tab.
@@ -70,13 +69,13 @@ void FindTabHelper::StartFinding(string16 search_string,
find_op_aborted_ = false;
// Keep track of what the last search was across the tabs.
- FindBarState* find_bar_state = tab_contents_->profile()->GetFindBarState();
+ FindBarState* find_bar_state = tab_contents()->profile()->GetFindBarState();
find_bar_state->set_last_prepopulate_text(find_text_);
- tab_contents_->render_view_host()->StartFinding(current_find_request_id_,
- find_text_,
- forward_direction,
- case_sensitive,
- find_next);
+ tab_contents()->render_view_host()->StartFinding(current_find_request_id_,
+ find_text_,
+ forward_direction,
+ case_sensitive,
+ find_next);
}
void FindTabHelper::StopFinding(
@@ -94,7 +93,7 @@ void FindTabHelper::StopFinding(
find_text_.clear();
find_op_aborted_ = true;
last_search_result_ = FindNotificationDetails();
- tab_contents_->render_view_host()->StopFinding(selection_action);
+ tab_contents()->render_view_host()->StopFinding(selection_action);
}
bool FindTabHelper::OnMessageReceived(const IPC::Message& message) {
@@ -132,7 +131,7 @@ void FindTabHelper::OnFindReply(int request_id,
final_update);
NotificationService::current()->Notify(
NotificationType::FIND_RESULT_AVAILABLE,
- Source<TabContents>(tab_contents_->tab_contents()),
+ Source<TabContents>(tab_contents()),
Details<FindNotificationDetails>(&last_search_result_));
}
@@ -142,6 +141,5 @@ void FindTabHelper::OnFindReply(int request_id,
// browser using IPC. In an effort to not spam the browser we have the
// browser send an ACK for each FindReply message and have the renderer
// queue up the latest status message while waiting for this ACK.
- tab_contents_->render_view_host()->Send(new ViewMsg_FindReplyACK(
- tab_contents_->render_view_host()->routing_id()));
+ Send(new ViewMsg_FindReplyACK(routing_id()));
}
diff --git a/chrome/browser/ui/find_bar/find_tab_helper.h b/chrome/browser/ui/find_bar/find_tab_helper.h
index 599ac12..377224d 100644
--- a/chrome/browser/ui/find_bar/find_tab_helper.h
+++ b/chrome/browser/ui/find_bar/find_tab_helper.h
@@ -10,12 +10,10 @@
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/find_bar/find_notification_details.h"
-class TabContentsWrapper;
-
// Per-tab find manager. Handles dealing with the life cycle of find sessions.
class FindTabHelper : public TabContentsObserver {
public:
- explicit FindTabHelper(TabContentsWrapper* tab_contents);
+ explicit FindTabHelper(TabContents* tab_contents);
virtual ~FindTabHelper();
// Starts the Find operation by calling StartFinding on the Tab. This function
@@ -70,8 +68,6 @@ class FindTabHelper : public TabContentsObserver {
int active_match_ordinal,
bool final_update);
- TabContentsWrapper* tab_contents_;
-
// Each time a search request comes in we assign it an id before passing it
// over the IPC so that when the results come in we can evaluate whether we
// still care about the results of the search (in some cases we don't because
diff --git a/chrome/browser/ui/search_engines/search_engine_tab_helper.cc b/chrome/browser/ui/search_engines/search_engine_tab_helper.cc
index db1d0dd..82d11f0 100644
--- a/chrome/browser/ui/search_engines/search_engine_tab_helper.cc
+++ b/chrome/browser/ui/search_engines/search_engine_tab_helper.cc
@@ -9,7 +9,7 @@
#include "chrome/browser/search_engines/template_url_fetcher.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/render_messages_params.h"
@@ -23,9 +23,9 @@ bool IsFormSubmit(const NavigationEntry* entry) {
} // namespace
-SearchEngineTabHelper::SearchEngineTabHelper(TabContentsWrapper* tab_contents)
- : tab_contents_(tab_contents) {
- DCHECK(tab_contents_);
+SearchEngineTabHelper::SearchEngineTabHelper(TabContents* tab_contents)
+ : TabContentsObserver(tab_contents) {
+ DCHECK(tab_contents);
}
SearchEngineTabHelper::~SearchEngineTabHelper() {
@@ -57,11 +57,11 @@ void SearchEngineTabHelper::OnPageHasOSDD(
// Make sure page_id is the current page and other basic checks.
DCHECK(doc_url.is_valid());
- if (!tab_contents_->tab_contents()->IsActiveEntry(page_id))
+ if (!tab_contents()->IsActiveEntry(page_id))
return;
- if (!tab_contents_->profile()->GetTemplateURLFetcher())
+ if (!tab_contents()->profile()->GetTemplateURLFetcher())
return;
- if (tab_contents_->profile()->IsOffTheRecord())
+ if (tab_contents()->profile()->IsOffTheRecord())
return;
TemplateURLFetcher::ProviderType provider_type;
@@ -83,8 +83,7 @@ void SearchEngineTabHelper::OnPageHasOSDD(
return;
}
- const NavigationController& controller =
- tab_contents_->tab_contents()->controller();
+ const NavigationController& controller = tab_contents()->controller();
const NavigationEntry* entry = controller.GetLastCommittedEntry();
DCHECK(entry);
@@ -116,11 +115,11 @@ void SearchEngineTabHelper::OnPageHasOSDD(
// Download the OpenSearch description document. If this is successful, a
// new keyword will be created when done.
- tab_contents_->profile()->GetTemplateURLFetcher()->ScheduleDownload(
+ tab_contents()->profile()->GetTemplateURLFetcher()->ScheduleDownload(
keyword,
doc_url,
base_entry->favicon().url(),
- new TemplateURLFetcherUICallbacks(this, tab_contents_),
+ new TemplateURLFetcherUICallbacks(this, tab_contents()),
provider_type);
}
@@ -129,11 +128,10 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary(
if (!params.searchable_form_url.is_valid())
return;
- if (tab_contents_->profile()->IsOffTheRecord())
+ if (tab_contents()->profile()->IsOffTheRecord())
return;
- const NavigationController& controller =
- tab_contents_->tab_contents()->controller();
+ const NavigationController& controller = tab_contents()->controller();
int last_index = controller.last_committed_entry_index();
// When there was no previous page, the last index will be 0. This is
// normally due to a form submit that opened in a new tab.
@@ -157,7 +155,7 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary(
return;
TemplateURLModel* url_model =
- tab_contents_->profile()->GetTemplateURLModel();
+ tab_contents()->profile()->GetTemplateURLModel();
if (!url_model)
return;
diff --git a/chrome/browser/ui/search_engines/search_engine_tab_helper.h b/chrome/browser/ui/search_engines/search_engine_tab_helper.h
index bcb1b0e..e259820 100644
--- a/chrome/browser/ui/search_engines/search_engine_tab_helper.h
+++ b/chrome/browser/ui/search_engines/search_engine_tab_helper.h
@@ -18,7 +18,7 @@ struct ViewHostMsg_PageHasOSDD_Type;
// functionality.
class SearchEngineTabHelper : public TabContentsObserver {
public:
- explicit SearchEngineTabHelper(TabContentsWrapper* tab_contents);
+ explicit SearchEngineTabHelper(TabContents* tab_contents);
virtual ~SearchEngineTabHelper();
SearchEngineTabHelperDelegate* delegate() const { return delegate_; }
@@ -40,8 +40,6 @@ class SearchEngineTabHelper : public TabContentsObserver {
void GenerateKeywordIfNecessary(
const ViewHostMsg_FrameNavigate_Params& params);
- TabContentsWrapper* tab_contents_;
-
// Delegate for notifying our owner about stuff. Not owned by us.
SearchEngineTabHelperDelegate* delegate_;
diff --git a/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h b/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h
index cc7fa88..8c83ea1 100644
--- a/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h
+++ b/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h
@@ -7,7 +7,7 @@
#pragma once
class Profile;
-class TabContentsWrapper;
+class TabContents;
class TemplateURL;
class TemplateURLModel;
@@ -18,7 +18,7 @@ class SearchEngineTabHelperDelegate {
// Shows a confirmation dialog box for setting the default search engine
// described by |template_url|. Takes ownership of |template_url|.
virtual void ConfirmSetDefaultSearchProvider(
- TabContentsWrapper* tab_contents,
+ TabContents* tab_contents,
TemplateURL* template_url,
TemplateURLModel* template_url_model) = 0;
diff --git a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc
index 9c37f78..f10aa7b 100644
--- a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc
+++ b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc
@@ -9,18 +9,18 @@
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
TemplateURLFetcherUICallbacks::TemplateURLFetcherUICallbacks(
SearchEngineTabHelper* tab_helper,
- TabContentsWrapper* tab_contents)
+ TabContents* tab_contents)
: source_(tab_helper),
tab_contents_(tab_contents) {
registrar_.Add(this,
NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab_contents_->tab_contents()));
+ Source<TabContents>(tab_contents_));
}
TemplateURLFetcherUICallbacks::~TemplateURLFetcherUICallbacks() {
@@ -55,7 +55,7 @@ void TemplateURLFetcherUICallbacks::Observe(
const NotificationSource& source,
const NotificationDetails& details) {
DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
- DCHECK(source == Source<TabContents>(tab_contents_->tab_contents()));
+ DCHECK(source == Source<TabContents>(tab_contents_));
source_ = NULL;
tab_contents_ = NULL;
}
diff --git a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h
index c1e6d46..2f994075 100644
--- a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h
+++ b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h
@@ -12,14 +12,14 @@
#include "chrome/common/notification_registrar.h"
class SearchEngineTabHelper;
-class TabContentsWrapper;
+class TabContents;
// Callbacks which display UI for the TemplateURLFetcher.
class TemplateURLFetcherUICallbacks : public TemplateURLFetcherCallbacks,
public NotificationObserver {
public:
explicit TemplateURLFetcherUICallbacks(SearchEngineTabHelper* tab_helper,
- TabContentsWrapper* tab_contents);
+ TabContents* tab_contents);
virtual ~TemplateURLFetcherUICallbacks();
// TemplateURLFetcherCallback implementation.
@@ -40,8 +40,8 @@ class TemplateURLFetcherUICallbacks : public TemplateURLFetcherCallbacks,
// originating tab is closed. If NULL, the engine is not added.
SearchEngineTabHelper* source_;
- // The TabContentsWrapper where this request originated.
- TabContentsWrapper* tab_contents_;
+ // The TabContents where this request originated.
+ TabContents* tab_contents_;
// Handles registering for our notifications.
NotificationRegistrar registrar_;
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
index 3e6a9da..d1d46bfd 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
@@ -22,7 +22,8 @@ static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> >
// TabContentsWrapper, public:
TabContentsWrapper::TabContentsWrapper(TabContents* contents)
- : delegate_(NULL),
+ : TabContentsObserver(contents),
+ delegate_(NULL),
is_starred_(false),
tab_contents_(contents) {
DCHECK(contents);
@@ -30,17 +31,12 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
// go to a Browser.
property_accessor()->SetProperty(contents->property_bag(), this);
- tab_contents()->AddObserver(this);
-
// Create the tab helpers.
- find_tab_helper_.reset(new FindTabHelper(this));
- tab_contents()->AddObserver(find_tab_helper_.get());
+ find_tab_helper_.reset(new FindTabHelper(contents));
password_manager_delegate_.reset(new PasswordManagerDelegateImpl(contents));
password_manager_.reset(
- new PasswordManager(password_manager_delegate_.get()));
- tab_contents()->AddObserver(password_manager_.get());
- search_engine_tab_helper_.reset(new SearchEngineTabHelper(this));
- tab_contents()->AddObserver(search_engine_tab_helper_.get());
+ new PasswordManager(contents, password_manager_delegate_.get()));
+ search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents));
// Register for notifications about URL starredness changing on any profile.
registrar_.Add(this, NotificationType::URLS_STARRED,
@@ -52,12 +48,6 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
TabContentsWrapper::~TabContentsWrapper() {
// We don't want any notifications while we're running our destructor.
registrar_.RemoveAll();
-
- // Unregister observers.
- tab_contents()->RemoveObserver(this);
- tab_contents()->RemoveObserver(find_tab_helper_.get());
- tab_contents()->RemoveObserver(password_manager_.get());
- tab_contents()->RemoveObserver(search_engine_tab_helper_.get());
}
PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() {
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index eb0b90c..b6dd207 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -1046,12 +1046,11 @@ void BrowserView::DisableInactiveFrame() {
}
void BrowserView::ConfirmSetDefaultSearchProvider(
- TabContentsWrapper* tab_contents,
+ TabContents* tab_contents,
TemplateURL* template_url,
TemplateURLModel* template_url_model) {
#if defined(OS_WIN)
- DefaultSearchView::Show(tab_contents->tab_contents(), template_url,
- template_url_model);
+ DefaultSearchView::Show(tab_contents, template_url, template_url_model);
#else
// TODO(levin): Implement for other platforms. Right now this is behind
// a command line flag which is off. http://crbug.com/38475
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index aa738e4..1610d80 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -280,7 +280,7 @@ class BrowserView : public BrowserBubbleHost,
virtual bool IsToolbarVisible() const;
virtual void DisableInactiveFrame();
virtual void ConfirmSetDefaultSearchProvider(
- TabContentsWrapper* tab_contents,
+ TabContents* tab_contents,
TemplateURL* template_url,
TemplateURLModel* template_url_model);
virtual void ConfirmAddSearchProvider(const TemplateURL* template_url,