diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 22:55:01 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 22:55:01 +0000 |
commit | 6e95706dcc9a205e78b1d4820427754d16a50465 (patch) | |
tree | 6bca69c386a5199bc88f59f0f92afc6dd6734fc3 /chrome/browser/tab_contents | |
parent | 1ffdb40816d6a92cbcb7eb6c2386232c561abc56 (diff) | |
download | chromium_src-6e95706dcc9a205e78b1d4820427754d16a50465.zip chromium_src-6e95706dcc9a205e78b1d4820427754d16a50465.tar.gz chromium_src-6e95706dcc9a205e78b1d4820427754d16a50465.tar.bz2 |
Move a bunch of functions from WebContents to TabContents. Change the services
used by the getters I moved to take a TabContents instead of a WebContents.
Review URL: http://codereview.chromium.org/96010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 59 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 133 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 58 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.h | 143 |
4 files changed, 188 insertions, 205 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 252e2b2..fcf7bdd 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -95,9 +95,28 @@ void TabContents::RegisterUserPrefs(PrefService* prefs) { } bool TabContents::SupportsURL(GURL* url) { + // TODO(brettw) remove this function. return true; } +AutofillManager* TabContents::GetAutofillManager() { + if (autofill_manager_.get() == NULL) + autofill_manager_.reset(new AutofillManager(this)); + 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)); + return plugin_installer_.get(); +} + const GURL& TabContents::GetURL() const { // We may not have a navigation entry yet NavigationEntry* entry = controller_.GetActiveEntry(); @@ -400,6 +419,46 @@ void TabContents::DidMoveOrResize(ConstrainedWindow* window) { #endif } +void TabContents::StartFinding(const string16& find_text, + bool forward_direction) { + // If find_text is empty, it means FindNext was pressed with a keyboard + // shortcut so unless we have something to search for we return early. + if (find_text.empty() && find_text_.empty()) + return; + + // This is a FindNext operation if we are searching for the same text again, + // or if the passed in search text is empty (FindNext keyboard shortcut). The + // exception to this is if the Find was aborted (then we don't want FindNext + // because the highlighting has been cleared and we need it to reappear). We + // therefore treat FindNext after an aborted Find operation as a full fledged + // Find. + bool find_next = (find_text_ == find_text || find_text.empty()) && + !find_op_aborted_; + if (!find_next) + current_find_request_id_ = find_request_id_counter_++; + + if (!find_text.empty()) + find_text_ = find_text; + + find_op_aborted_ = false; + + // Keep track of what the last search was across the tabs. + *find_prepopulate_text_ = find_text; + + render_view_host()->StartFinding(current_find_request_id_, + find_text_, + forward_direction, + false, // case sensitive + find_next); +} + +void TabContents::StopFinding(bool clear_selection) { + find_ui_active_ = false; + find_op_aborted_ = true; + find_result_ = FindNotificationDetails(); + render_view_host()->StopFinding(clear_selection); +} + #if defined(OS_WIN) // TODO(brettw) This should be on the TabContentsView. void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) { diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index a7d5833..8fe5529 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -7,6 +7,7 @@ #include "build/build_config.h" +#include <map> #include <string> #include <vector> @@ -34,7 +35,6 @@ #include "webkit/glue/password_form.h" #include "webkit/glue/webpreferences.h" - #if defined(OS_MACOSX) || defined(OS_LINUX) // Remove when we've finished porting the supporting classes. #include "chrome/common/temp_scaffolding_stubs.h" @@ -47,31 +47,47 @@ class Rect; class Size; } namespace views { -class RootView; class WindowDelegate; } +namespace base { +class WaitableEvent; +} +namespace webkit_glue { +struct WebApplicationInfo; +} +namespace IPC { +class Message; +} +class AutofillForm; class AutofillManager; class BlockedPopupContainer; +class DOMUI; class DOMUIContents; class DownloadItem; class DownloadShelf; -class InfoBarView; class LoadNotificationDetails; class PasswordManager; class PluginInstaller; class Profile; +class RenderViewHost; class TabContentsDelegate; class TabContentsFactory; class SkBitmap; class SiteInstance; class TabContentsView; +struct ThumbnailScore; +struct ViewHostMsg_FrameNavigate_Params; +struct ViewHostMsg_DidPrintPage_Params; class WebContents; // Describes what goes in the main content area of a tab. WebContents is // the only type of TabContents, and these should be merged together. class TabContents : public PageNavigator, - public NotificationObserver { + public NotificationObserver, + public RenderViewHostDelegate, + public RenderViewHostManager::Delegate, + public SelectFileDialog::Listener { public: // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it // what has changed. Combine them to update more than one thing. @@ -99,7 +115,7 @@ class TabContents : public PageNavigator, PropertyBag* property_bag() { return &property_bag_; } // Returns this object as a WebContents if it is one, and NULL otherwise. - virtual WebContents* AsWebContents() { return NULL; } + virtual WebContents* AsWebContents() = 0; // Const version of above for situations where const TabContents*'s are used. WebContents* AsWebContents() const { @@ -125,6 +141,37 @@ class TabContents : public PageNavigator, // to the actual URL that will be used. It can be modified as needed. bool SupportsURL(GURL* url); + // 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(); + + // Returns the SavePackage which manages the page saving job. May be NULL. + SavePackage* save_package() const { return save_package_.get(); } + + // Return the currently active RenderProcessHost and RenderViewHost. Each of + // these may change over time. + RenderProcessHost* process() const { + return render_manager_.current_host()->process(); + } + RenderViewHost* render_view_host() const { + return render_manager_.current_host(); + } + + // The TabContentsView will never change and is guaranteed non-NULL. + TabContentsView* view() const { + return view_.get(); + } + +#ifdef UNIT_TEST + // Expose the render manager for testing. + RenderViewHostManager* render_manager() { return &render_manager_; } +#endif + // Tab navigation state ------------------------------------------------------ // Returns the current navigation properties, which if a navigation is @@ -185,6 +232,13 @@ class TabContents : public PageNavigator, // "waiting" or "loading." bool waiting_for_response() const { return waiting_for_response_; } + bool is_starred() const { return is_starred_; } + + const std::wstring& encoding() const { return encoding_; } + void set_encoding(const std::wstring& encoding) { + encoding_ = encoding; + } + // Internal state ------------------------------------------------------------ // This flag indicates whether the tab contents is currently being @@ -366,6 +420,75 @@ class TabContents : public PageNavigator, // Called when a ConstrainedWindow we own is moved or resized. void DidMoveOrResize(ConstrainedWindow* window); + // Interstitials ------------------------------------------------------------- + + // Various other systems need to know about our interstitials. + bool showing_interstitial_page() const { + return render_manager_.interstitial_page() != NULL; + } + + // Sets the passed passed interstitial as the currently showing interstitial. + // |interstitial_page| should be non NULL (use the remove_interstitial_page + // method to unset the interstitial) and no interstitial page should be set + // when there is already a non NULL interstitial page set. + void set_interstitial_page(InterstitialPage* interstitial_page) { + render_manager_.set_interstitial_page(interstitial_page); + } + + // Unsets the currently showing interstitial. + void remove_interstitial_page() { + render_manager_.remove_interstitial_page(); + } + + // Returns the currently showing interstitial, NULL if no interstitial is + // showing. + InterstitialPage* interstitial_page() const { + return render_manager_.interstitial_page(); + } + + // Find in Page -------------------------------------------------------------- + + // Starts the Find operation by calling StartFinding on the Tab. This function + // can be called from the outside as a result of hot-keys, so it uses the + // last remembered search string as specified with set_find_string(). This + // function does not block while a search is in progress. The controller will + // receive the results through the notification mechanism. See Observe(...) + // for details. + void StartFinding(const string16& find_text, bool forward_direction); + + // Stops the current Find operation. If |clear_selection| is true, it will + // also clear the selection on the focused frame. + void StopFinding(bool clear_selection); + + // Accessors/Setters for find_ui_active_. + bool find_ui_active() const { return find_ui_active_; } + void set_find_ui_active(bool find_ui_active) { + find_ui_active_ = find_ui_active; + } + + // Setter for find_op_aborted_. + void set_find_op_aborted(bool find_op_aborted) { + find_op_aborted_ = find_op_aborted; + } + + // Used _only_ by testing to set the current request ID, since it calls + // StartFinding on the RenderViewHost directly, rather than by using + // StartFinding's more limited API. + void set_current_find_request_id(int current_find_request_id) { + current_find_request_id_ = current_find_request_id; + } + + // Accessor for find_text_. Used to determine if this WebContents has any + // active searches. + string16 find_text() const { return find_text_; } + + // Accessor for find_prepopulate_text_. Used to access the last search + // string entered, whatever tab that search was performed in. + string16 find_prepopulate_text() const { return *find_prepopulate_text_; } + + // Accessor for find_result_. + const FindNotificationDetails& find_result() const { return find_result_; } + protected: friend class NavigationController; // Used to access the child_windows_ (ConstrainedWindowList) for testing diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index dcd566c..2832765 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -317,24 +317,6 @@ void WebContents::RegisterUserPrefs(PrefService* prefs) { IDS_STATIC_ENCODING_LIST); } -AutofillManager* WebContents::GetAutofillManager() { - if (autofill_manager_.get() == NULL) - autofill_manager_.reset(new AutofillManager(this)); - return autofill_manager_.get(); -} - -PasswordManager* WebContents::GetPasswordManager() { - if (password_manager_.get() == NULL) - password_manager_.reset(new PasswordManager(this)); - return password_manager_.get(); -} - -PluginInstaller* WebContents::GetPluginInstaller() { - if (plugin_installer_.get() == NULL) - plugin_installer_.reset(new PluginInstaller(this)); - return plugin_installer_.get(); -} - const string16& WebContents::GetTitle() const { DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ? render_manager_.pending_dom_ui() : render_manager_.dom_ui(); @@ -637,46 +619,6 @@ void WebContents::CreateShortcut() { render_view_host()->GetApplicationInfo(pending_install_.page_id); } -void WebContents::StartFinding(const string16& find_text, - bool forward_direction) { - // If find_text is empty, it means FindNext was pressed with a keyboard - // shortcut so unless we have something to search for we return early. - if (find_text.empty() && find_text_.empty()) - return; - - // This is a FindNext operation if we are searching for the same text again, - // or if the passed in search text is empty (FindNext keyboard shortcut). The - // exception to this is if the Find was aborted (then we don't want FindNext - // because the highlighting has been cleared and we need it to reappear). We - // therefore treat FindNext after an aborted Find operation as a full fledged - // Find. - bool find_next = (find_text_ == find_text || find_text.empty()) && - !find_op_aborted_; - if (!find_next) - current_find_request_id_ = find_request_id_counter_++; - - if (!find_text.empty()) - find_text_ = find_text; - - find_op_aborted_ = false; - - // Keep track of what the last search was across the tabs. - *find_prepopulate_text_ = find_text; - - render_view_host()->StartFinding(current_find_request_id_, - find_text_, - forward_direction, - false, // case sensitive - find_next); -} - -void WebContents::StopFinding(bool clear_selection) { - find_ui_active_ = false; - find_op_aborted_ = true; - find_result_ = FindNotificationDetails(); - render_view_host()->StopFinding(clear_selection); -} - void WebContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, bool success, const std::wstring& prompt) { diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index a896bb6..dc239ad 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -5,41 +5,11 @@ #ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_H_ #define CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_H_ -#include <map> -#include <string> -#include <vector> - #include "chrome/browser/tab_contents/tab_contents.h" -class AutofillForm; -class DOMUI; -class InterstitialPageDelegate; -class LoadNotificationDetails; -class RenderProcessHost; -class RenderViewHost; -class RenderWidgetHost; -struct ThumbnailScore; -struct ViewHostMsg_FrameNavigate_Params; -struct ViewHostMsg_DidPrintPage_Params; - -namespace base { -class WaitableEvent; -} - -namespace webkit_glue { -struct WebApplicationInfo; -} - -namespace IPC { -class Message; -} - // WebContents represents the contents of a tab that shows web pages. It embeds // a RenderViewHost (via RenderViewHostManager) to actually display the page. -class WebContents : public TabContents, - public RenderViewHostDelegate, - public RenderViewHostManager::Delegate, - public SelectFileDialog::Listener { +class WebContents : public TabContents { public: // If instance is NULL, then creates a new process for this view. Otherwise // initialize with a process already created for a different WebContents. @@ -53,48 +23,6 @@ class WebContents : public TabContents, static void RegisterUserPrefs(PrefService* prefs); - // Getters ------------------------------------------------------------------- - - // 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(); - - // Returns the SavePackage which manages the page saving job. May be NULL. - SavePackage* save_package() const { return save_package_.get(); } - - // Return the currently active RenderProcessHost and RenderViewHost. Each of - // these may change over time. - RenderProcessHost* process() const { - return render_manager_.current_host()->process(); - } - RenderViewHost* render_view_host() const { - return render_manager_.current_host(); - } - - // The TabContentsView will never change and is guaranteed non-NULL. - TabContentsView* view() const { - return view_.get(); - } - -#ifdef UNIT_TEST - // Expose the render manager for testing. - RenderViewHostManager* render_manager() { return &render_manager_; } -#endif - - // Page state getters & setters ---------------------------------------------- - - bool is_starred() const { return is_starred_; } - - const std::wstring& encoding() const { return encoding_; } - void set_encoding(const std::wstring& encoding) { - encoding_ = encoding; - } - // Window stuff -------------------------------------------------------------- // Returns true if the location bar should be focused by default rather than @@ -138,75 +66,6 @@ class WebContents : public TabContents, // Tell Gears to create a shortcut for the current page. void CreateShortcut(); - // Interstitials ------------------------------------------------------------- - - // Various other systems need to know about our interstitials. - bool showing_interstitial_page() const { - return render_manager_.interstitial_page() != NULL; - } - - // Sets the passed passed interstitial as the currently showing interstitial. - // |interstitial_page| should be non NULL (use the remove_interstitial_page - // method to unset the interstitial) and no interstitial page should be set - // when there is already a non NULL interstitial page set. - void set_interstitial_page(InterstitialPage* interstitial_page) { - render_manager_.set_interstitial_page(interstitial_page); - } - - // Unsets the currently showing interstitial. - void remove_interstitial_page() { - render_manager_.remove_interstitial_page(); - } - - // Returns the currently showing interstitial, NULL if no interstitial is - // showing. - InterstitialPage* interstitial_page() const { - return render_manager_.interstitial_page(); - } - - // Find in Page -------------------------------------------------------------- - - // Starts the Find operation by calling StartFinding on the Tab. This function - // can be called from the outside as a result of hot-keys, so it uses the - // last remembered search string as specified with set_find_string(). This - // function does not block while a search is in progress. The controller will - // receive the results through the notification mechanism. See Observe(...) - // for details. - void StartFinding(const string16& find_text, bool forward_direction); - - // Stops the current Find operation. If |clear_selection| is true, it will - // also clear the selection on the focused frame. - void StopFinding(bool clear_selection); - - // Accessors/Setters for find_ui_active_. - bool find_ui_active() const { return find_ui_active_; } - void set_find_ui_active(bool find_ui_active) { - find_ui_active_ = find_ui_active; - } - - // Setter for find_op_aborted_. - void set_find_op_aborted(bool find_op_aborted) { - find_op_aborted_ = find_op_aborted; - } - - // Used _only_ by testing to set the current request ID, since it calls - // StartFinding on the RenderViewHost directly, rather than by using - // StartFinding's more limited API. - void set_current_find_request_id(int current_find_request_id) { - current_find_request_id_ = current_find_request_id; - } - - // Accessor for find_text_. Used to determine if this WebContents has any - // active searches. - string16 find_text() const { return find_text_; } - - // Accessor for find_prepopulate_text_. Used to access the last search - // string entered, whatever tab that search was performed in. - string16 find_prepopulate_text() const { return *find_prepopulate_text_; } - - // Accessor for find_result_. - const FindNotificationDetails& find_result() const { return find_result_; } - // Misc state & callbacks ---------------------------------------------------- // Set whether the contents should block javascript message boxes or not. |