diff options
Diffstat (limited to 'chrome/browser/tab_contents')
| -rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 162 | ||||
| -rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 31 | ||||
| -rw-r--r-- | chrome/browser/tab_contents/web_navigation_observer.h | 57 |
3 files changed, 96 insertions, 154 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 26b77ce..5f091ee 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -55,7 +55,6 @@ #include "chrome/browser/metrics/metric_event_duration_details.h" #include "chrome/browser/modal_html_dialog_delegate.h" #include "chrome/browser/omnibox_search_hint.h" -#include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/plugin_installer.h" #include "chrome/browser/prefs/pref_service.h" @@ -82,6 +81,7 @@ #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" +#include "chrome/browser/tab_contents/web_navigation_observer.h" #include "chrome/browser/translate/page_translated_details.h" #include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_switches.h" @@ -330,7 +330,6 @@ TabContents::TabContents(Profile* profile, save_package_(), autocomplete_history_manager_(), autofill_manager_(), - password_manager_(), plugin_installer_(), bookmark_drag_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), @@ -566,12 +565,6 @@ AutoFillManager* TabContents::GetAutoFillManager() { return autofill_manager_.get(); } -PasswordManager* TabContents::GetPasswordManager() { - if (password_manager_.get() == NULL) - password_manager_.reset(new PasswordManager(this)); - return password_manager_.get(); -} - PluginInstaller* TabContents::GetPluginInstaller() { if (plugin_installer_.get() == NULL) plugin_installer_.reset(new PluginInstaller(this)); @@ -767,6 +760,14 @@ std::wstring TabContents::GetStatusText() const { return std::wstring(); } +void TabContents::AddNavigationObserver(WebNavigationObserver* observer) { + web_navigation_observers_.AddObserver(observer); +} + +void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) { + web_navigation_observers_.RemoveObserver(observer); +} + void TabContents::SetIsCrashed(bool state) { if (state == is_crashed_) return; @@ -899,10 +900,9 @@ bool TabContents::NavigateToEntry( return false; } - // Clear any provisional password saves - this stops password infobars - // showing up on pages the user navigates to while the right page is - // loading. - GetPasswordManager()->ClearProvisionalSave(); + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + NavigateToPendingEntry()); if (reload_type != NavigationController::NO_RELOAD && !profile()->IsOffTheRecord()) { @@ -1642,13 +1642,6 @@ void TabContents::DidNavigateMainFramePostCommit( // clear the bubble when a user navigates to a named anchor in the same // page. UpdateTargetURL(details.entry->page_id(), GURL()); - - // UpdateHelpersForDidNavigate will handle the case where the password_form - // origin is valid. - // TODO(brettw) bug 1343111: Password manager stuff in here needs to be - // cleaned up and covered by tests. - if (!params.password_form.origin.is_valid()) - GetPasswordManager()->DidNavigate(); } // The keyword generator uses the navigation entries, so must be called after @@ -1710,6 +1703,10 @@ void TabContents::DidNavigateMainFramePostCommit( // Update the starred state. UpdateStarredStateForCurrentURL(); + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidNavigateMainFramePostCommit(details, params)); + // Clear the cache of forms in AutoFill. if (autofill_manager_.get()) autofill_manager_->Reset(); @@ -1724,11 +1721,9 @@ void TabContents::DidNavigateAnyFramePostCommit( // reload the page to stop blocking. suppress_javascript_messages_ = false; - // Notify the password manager of the navigation or form submit. - // TODO(brettw) bug 1343111: Password manager stuff in here needs to be - // cleaned up and covered by tests. - if (params.password_form.origin.is_valid()) - GetPasswordManager()->ProvisionallySavePassword(params.password_form); + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidNavigateAnyFramePostCommit(details, params)); // Let the LanguageState clear its state. language_state_.DidNavigate(details); @@ -2640,10 +2635,15 @@ void TabContents::RequestMove(const gfx::Rect& new_bounds) { void TabContents::DidStartLoading() { SetIsLoading(true, NULL); + if (content_restrictions_) { content_restrictions_= 0; delegate()->ContentRestrictionsChanged(this); } + + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidStartLoading()); } void TabContents::DidStopLoading() { @@ -2663,11 +2663,11 @@ void TabContents::DidStopLoading() { controller_.GetCurrentEntryIndex())); } - // Tell PasswordManager we've finished a page load, which serves as a - // green light to save pending passwords and reset itself. - GetPasswordManager()->DidStopLoading(); - SetIsLoading(false, details.get()); + + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidStopLoading()); } void TabContents::DocumentOnLoadCompletedInMainFrame( @@ -2789,16 +2789,6 @@ void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, } } -void TabContents::PasswordFormsFound( - const std::vector<webkit_glue::PasswordForm>& forms) { - GetPasswordManager()->PasswordFormsFound(forms); -} - -void TabContents::PasswordFormsVisible( - const std::vector<webkit_glue::PasswordForm>& visible_forms) { - GetPasswordManager()->PasswordFormsVisible(visible_forms); -} - // Checks to see if we should generate a keyword based on the OSDD, and if // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. void TabContents::PageHasOSDD( @@ -3233,99 +3223,3 @@ void TabContents::SetAppIcon(const SkBitmap& app_icon) { app_icon_ = app_icon; NotifyNavigationStateChanged(INVALIDATE_TITLE); } - -// After a successful *new* login attempt, we take the PasswordFormManager in -// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while -// the user makes up their mind with the "save password" infobar. Note if the -// login is one we already know about, the end of the line is -// provisional_save_manager_ because we just update it on success and so such -// forms never end up in an infobar. -class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { - public: - SavePasswordInfoBarDelegate(TabContents* tab_contents, - PasswordFormManager* form_to_save) - : ConfirmInfoBarDelegate(tab_contents), - form_to_save_(form_to_save), - infobar_response_(NO_RESPONSE) {} - - virtual ~SavePasswordInfoBarDelegate() {} - - // Begin ConfirmInfoBarDelegate implementation. - virtual void InfoBarClosed() { - UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", - infobar_response_, NUM_RESPONSE_TYPES); - delete this; - } - - virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; } - - virtual string16 GetMessageText() const { - return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); - } - - virtual SkBitmap* GetIcon() const { - return ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_INFOBAR_SAVE_PASSWORD); - } - - virtual int GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; - } - - virtual string16 GetButtonLabel(InfoBarButton button) const { - if (button == BUTTON_OK) - return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON); - if (button == BUTTON_CANCEL) - return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); - NOTREACHED(); - return string16(); - } - - virtual bool Accept() { - DCHECK(form_to_save_.get()); - form_to_save_->Save(); - infobar_response_ = REMEMBER_PASSWORD; - return true; - } - - virtual bool Cancel() { - DCHECK(form_to_save_.get()); - form_to_save_->PermanentlyBlacklist(); - infobar_response_ = DONT_REMEMBER_PASSWORD; - return true; - } - // End ConfirmInfoBarDelegate implementation. - - private: - // The PasswordFormManager managing the form we're asking the user about, - // and should update as per her decision. - scoped_ptr<PasswordFormManager> form_to_save_; - - // Used to track the results we get from the info bar. - enum ResponseType { - NO_RESPONSE = 0, - REMEMBER_PASSWORD, - DONT_REMEMBER_PASSWORD, - NUM_RESPONSE_TYPES, - }; - ResponseType infobar_response_; - - DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); -}; - -void TabContents::FillPasswordForm( - const webkit_glue::PasswordFormFillData& form_data) { - render_view_host()->FillPasswordForm(form_data); -} - -void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) { - AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save)); -} - -Profile* TabContents::GetProfileForPasswordManager() { - return profile(); -} - -bool TabContents::DidLastPageLoadEncounterSSLErrors() { - return controller().ssl_manager()->ProcessedSSLErrorFromRequest(); -} diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index f8bad82..2a69a14 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -25,7 +25,6 @@ #include "chrome/browser/find_notification_details.h" #include "chrome/browser/js_modal_dialog.h" #include "chrome/browser/prefs/pref_change_registrar.h" -#include "chrome/browser/password_manager/password_manager_delegate.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/tab_contents/constrained_window.h" #include "chrome/browser/tab_contents/language_state.h" @@ -72,7 +71,6 @@ class FileSelectHelper; class InfoBarDelegate; class LoadNotificationDetails; class OmniboxSearchHint; -class PasswordManager; class PluginInstaller; class Profile; struct RendererPreferences; @@ -88,6 +86,7 @@ class URLPattern; struct ThumbnailScore; struct ViewHostMsg_DomMessage_Params; struct ViewHostMsg_FrameNavigate_Params; +class WebNavigationObserver; struct WebPreferences; // Describes what goes in the main content area of a tab. TabContents is @@ -100,7 +99,6 @@ class TabContents : public PageNavigator, public RenderViewHostManager::Delegate, public JavaScriptAppModalDialogDelegate, public ImageLoadingTracker::Observer, - public PasswordManagerDelegate, public TabSpecificContentSettings::Delegate { public: // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it @@ -157,9 +155,6 @@ class TabContents : public PageNavigator, // Returns the AutoFillManager, creating it if necessary. AutoFillManager* GetAutoFillManager(); - // Returns the PasswordManager, creating it if necessary. - PasswordManager* GetPasswordManager(); - // Returns the PluginInstaller, creating it if necessary. PluginInstaller* GetPluginInstaller(); @@ -269,6 +264,13 @@ class TabContents : public PageNavigator, // Returns a human-readable description the tab's loading state. virtual std::wstring GetStatusText() const; + // Add and remove observers for page navigation notifications. Adding or + // removing multiple times has no effect. The order in which notifications + // are sent to observers is undefined. Clients must be sure to remove the + // observer before they go away. + void AddNavigationObserver(WebNavigationObserver* observer); + void RemoveNavigationObserver(WebNavigationObserver* observer); + // Return whether this tab contents is loading a resource. bool is_loading() const { return is_loading_; } @@ -695,13 +697,6 @@ class TabContents : public PageNavigator, // state by various UI elements. TabSpecificContentSettings* GetTabSpecificContentSettings() const; - // PasswordManagerDelegate implementation. - virtual void FillPasswordForm( - const webkit_glue::PasswordFormFillData& form_data); - virtual void AddSavePasswordInfoBar(PasswordFormManager* form_to_save); - virtual Profile* GetProfileForPasswordManager(); - virtual bool DidLastPageLoadEncounterSSLErrors(); - // Updates history with the specified navigation. This is called by // OnMsgNavigate to update history state. void UpdateHistoryForNavigation( @@ -982,10 +977,6 @@ class TabContents : public PageNavigator, virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, IPC::Message* reply_msg); - virtual void PasswordFormsFound( - const std::vector<webkit_glue::PasswordForm>& forms); - virtual void PasswordFormsVisible( - const std::vector<webkit_glue::PasswordForm>& visible_forms); virtual void PageHasOSDD(RenderViewHost* render_view_host, int32 page_id, const GURL& url, @@ -1095,9 +1086,6 @@ class TabContents : public PageNavigator, // AutoFillManager, lazily created. scoped_ptr<AutoFillManager> autofill_manager_; - // PasswordManager, lazily created. - scoped_ptr<PasswordManager> password_manager_; - // PluginInstaller, lazily created. scoped_ptr<PluginInstaller> plugin_installer_; @@ -1304,6 +1292,9 @@ class TabContents : public PageNavigator, // remember it. bool temporary_zoom_settings_; + // A list of observers notified when page state changes. Weak references. + ObserverList<WebNavigationObserver> web_navigation_observers_; + // Content restrictions, used to disable print/copy etc based on content's // (full-page plugins for now only) permissions. int content_restrictions_; diff --git a/chrome/browser/tab_contents/web_navigation_observer.h b/chrome/browser/tab_contents/web_navigation_observer.h new file mode 100644 index 0000000..b42e658 --- /dev/null +++ b/chrome/browser/tab_contents/web_navigation_observer.h @@ -0,0 +1,57 @@ +// Copyright (c) 2010 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_TAB_CONTENTS_WEB_NAVIGATION_OBSERVER_H_ +#define CHROME_BROWSER_TAB_CONTENTS_WEB_NAVIGATION_OBSERVER_H_ + +#include "chrome/browser/tab_contents/navigation_controller.h" + +struct ViewHostMsg_FrameNavigate_Params; + +// An observer API implemented by classes which are interested in various page +// load events from TabContents. + +// TODO(pink): Is it worth having a bitfield where certain clients can only +// register for certain events? Is the extra function call worth the added pain +// on the caller to build the bitfield? + +class WebNavigationObserver { + public: + // For removing PasswordManager deps... + + virtual void NavigateToPendingEntry() { } + + virtual void DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { } + virtual void DidNavigateAnyFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { } + + virtual void DidStartLoading() { } + virtual void DidStopLoading() { } + + // TODO(pinkerton): Not sure the best place for these. + virtual void PasswordFormsFound( + const std::vector<webkit_glue::PasswordForm>& forms) { } + virtual void PasswordFormsVisible( + const std::vector<webkit_glue::PasswordForm>& visible_forms) { } + +#if 0 + // For unifying with delegate... + + // Notifies the delegate that this contents is starting or is done loading + // some resource. The delegate should use this notification to represent + // loading feedback. See TabContents::is_loading() + virtual void LoadingStateChanged(TabContents* contents) { } + // Called to inform the delegate that the tab content's navigation state + // changed. The |changed_flags| indicates the parts of the navigation state + // that have been updated, and is any combination of the + // |TabContents::InvalidateTypes| bits. + virtual void NavigationStateChanged(const TabContents* source, + unsigned changed_flags) { } +#endif +}; + +#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_NAVIGATION_OBSERVER_H_ |
