diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 19:30:34 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 19:30:34 +0000 |
commit | d5f942bab2af72892413a3080fb7468b0bbef713 (patch) | |
tree | ec5e97ea265fba45bb1f6102bc1aed4001f9898b /chrome/browser/web_contents.h | |
parent | e711c4dded8a24f780c039e545d7378937e1388b (diff) | |
download | chromium_src-d5f942bab2af72892413a3080fb7468b0bbef713.zip chromium_src-d5f942bab2af72892413a3080fb7468b0bbef713.tar.gz chromium_src-d5f942bab2af72892413a3080fb7468b0bbef713.tar.bz2 |
Reorganize the declarations to have some grouping and logical ordering in tab contents and web contents. Reorder the derived classes overrides to match, and reorder the definitions of the functions to match the order in the header file.
This doesn't actually change any code. I removed a few functions that were declared but never implemented (!) as well as some that were marked vitual but were never overridden. I renamed some things to make them more consistent.
Review URL: http://codereview.chromium.org/5005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2634 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_contents.h')
-rw-r--r-- | chrome/browser/web_contents.h | 377 |
1 files changed, 175 insertions, 202 deletions
diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h index 1e23645..780b34a 100644 --- a/chrome/browser/web_contents.h +++ b/chrome/browser/web_contents.h @@ -28,11 +28,14 @@ class SadTabView; struct WebDropData; class WebDropTarget; +// 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 ChromeViews::HWNDViewContainer, public SelectFileDialog::Listener, + public NotificationObserver, public WebApp::Observer { public: // If instance is NULL, then creates a new process for this view. Otherwise @@ -48,82 +51,78 @@ class WebContents : public TabContents, static void RegisterUserPrefs(PrefService* prefs); - virtual void CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds); - virtual HWND GetContainerHWND() const { return GetHWND(); } - virtual void GetContainerBounds(gfx::Rect *out) const; - virtual void ShowContents(); - virtual void HideContents(); - virtual void SizeContents(const gfx::Size& size); + // Getters ------------------------------------------------------------------- - // TabContents - virtual WebContents* AsWebContents() { return this; } - virtual SiteInstance* GetSiteInstance() const { - return render_manager_.current_host()->site_instance(); + // 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, RenderViewHost, and + // SiteInstance, respectively. Each of these may change over time. Callers + // should be aware that the SiteInstance could be deleted if its ref count + // drops to zero (i.e., if all RenderViewHosts and NavigationEntries that + // use it are deleted). + RenderProcessHost* process() const { + return render_manager_.current_host()->process(); } - virtual bool NavigateToPendingEntry(bool reload); - virtual void Stop(); - virtual void DidBecomeSelected(); - virtual void WasHidden(); + RenderViewHost* render_view_host() const { + return render_manager_.current_host(); + } + RenderWidgetHostView* view() const { + return render_manager_.current_view(); + } + + bool is_starred() const { return is_starred_; } + + // TabContents (public overrides) -------------------------------------------- + virtual void Destroy(); + virtual WebContents* AsWebContents() { return this; } + virtual SiteInstance* GetSiteInstance() const; virtual SkBitmap GetFavIcon(); virtual std::wstring GetStatusText() const; - - // Find functions + virtual bool NavigateToPendingEntry(bool reload); + virtual void Stop(); virtual void StartFinding(int request_id, const std::wstring& search_string, bool forward, bool match_case, bool find_next); virtual void StopFinding(bool clear_selection); - virtual void OpenFindInPageWindow(const Browser& browser); - virtual void ReparentFindWindow(HWND new_parent); - virtual bool AdvanceFindSelection(bool forward_direction); - virtual bool IsFindWindowFullyVisible(); - virtual bool GetFindInPageWindowLocation(int* x, int* y); - - bool is_starred() const { return is_starred_; } - - // Set whether the contents should block javascript message boxes or not. - // Default is not to block any message boxes. - void set_suppress_javascript_messages( - bool suppress_javascript_messages) { - suppress_javascript_messages_ = suppress_javascript_messages; - } - - // Various other systems need to know about our interstitials. - bool showing_interstitial_page() const { - return render_manager_.showing_interstitial_page(); - } - bool showing_repost_interstitial() const { - return render_manager_.showing_repost_interstitial(); - } - - // Overridden from TabContents to remember at what time the download bar was - // shown. - void SetDownloadShelfVisible(bool visible); - - // Returns the SavePackage which manages the page saving job. May be NULL. - SavePackage* save_package() const { return save_package_.get(); } - - // Whether or not the info bar is visible. This delegates to - // the ChromeFrame method InfoBarVisibilityChanged. - void SetInfoBarVisible(bool visible); - virtual bool IsInfoBarVisible() { return info_bar_visible_; } - - // Whether or not the FindInPage bar is visible. - void SetFindInPageVisible(bool visible); - + virtual void Cut(); + virtual void Copy(); + virtual void Paste(); + virtual void DidBecomeSelected(); + virtual void WasHidden(); + virtual void ShowContents(); + virtual void HideContents(); + virtual void SizeContents(const gfx::Size& size); + virtual HWND GetContentHWND(); + virtual void CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds); + virtual HWND GetContainerHWND() const { return GetHWND(); } + virtual void GetContainerBounds(gfx::Rect *out) const; // Create the InfoBarView and returns it if none has been created. // Just returns existing InfoBarView if it is already created. virtual InfoBarView* GetInfoBarView(); + virtual bool IsInfoBarVisible() { return info_bar_visible_; } + virtual void SetDownloadShelfVisible(bool visible); - // Prepare for saving page. - void OnSavePage(); + // Find in page -------------------------------------------------------------- - // Save page with the main HTML file path, the directory for saving resources, - // and the save type: HTML only or complete web page. - void SavePage(const std::wstring& main_file, const std::wstring& dir_path, - SavePackage::SavePackageType save_type); + // TODO(brettw) these should be commented. + void OpenFindInPageWindow(const Browser& browser); + void ReparentFindWindow(HWND new_parent); + bool AdvanceFindSelection(bool forward_direction); + bool IsFindWindowFullyVisible(); + bool GetFindInPageWindowLocation(int* x, int* y); + void SetFindInPageVisible(bool visible); + + // Web apps ------------------------------------------------------------------ // Sets the WebApp for this WebContents. void SetWebApp(WebApp* web_app); @@ -135,57 +134,16 @@ class WebContents : public TabContents, // Tell Gears to create a shortcut for the current page. void CreateShortcut(); - // JavascriptMessageBoxHandler calls this when the dialog is closed. - void OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, bool success, - const std::wstring& prompt); + // Interstitials ------------------------------------------------------------- - // Returns the PasswordManager, creating it if necessary. - PasswordManager* GetPasswordManager(); - - // Returns the PluginInstaller, creating it if necessary. - PluginInstaller* GetPluginInstaller(); - - // Return the currently active RenderProcessHost, RenderViewHost, and - // SiteInstance, respectively. Each of these may change over time. Callers - // should be aware that the SiteInstance could be deleted if its ref count - // drops to zero (i.e., if all RenderViewHosts and NavigationEntries that - // use it are deleted). - RenderProcessHost* process() const { - return render_manager_.current_host()->process(); - } - RenderViewHost* render_view_host() const { - return render_manager_.current_host(); + // Various other systems need to know about our interstitials. + bool showing_interstitial_page() const { + return render_manager_.showing_interstitial_page(); } - RenderWidgetHostView* view() const { - return render_manager_.current_view(); + bool showing_repost_interstitial() const { + return render_manager_.showing_repost_interstitial(); } - // Overridden from TabContents to return the window of the - // RenderWidgetHostView. - virtual HWND GetContentHWND(); - - // Handling the drag and drop of files into the content area. - virtual bool CanDisplayFile(const std::wstring& full_path); - - // Displays asynchronously a print preview (generated by the renderer) if not - // already displayed and ask the user for its preferred print settings with - // the "Print..." dialog box. (managed by the print worker thread). - // TODO(maruel): Creates a snapshot of the renderer to be used for the new - // tab for the printing facility. - void PrintPreview(); - - // Prints the current document immediately. Since the rendering is - // asynchronous, the actual printing will not be completed on the return of - // this function. Returns false if printing is impossible at the moment. - bool PrintNow(); - - virtual void WillCaptureContents(); - virtual void DidCaptureContents(); - - virtual void Cut(); - virtual void Copy(); - virtual void Paste(); - // The rest of the system wants to interact with the delegate our render view // host manager has. See those setters for more. InterstitialPageDelegate* interstitial_page_delegate() const { @@ -215,15 +173,45 @@ class WebContents : public TabContents, render_manager_.HideInterstitialPage(wait_for_navigation, proceed); } - // Allows the WebContents to react when a cross-site response is ready to be - // delivered to a pending RenderViewHost. We must first run the onunload - // handler of the old RenderViewHost before we can allow it to proceed. - void OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id) { - render_manager_.OnCrossSiteResponse(new_render_process_host_id, - new_request_id); + // Misc state & callbacks ---------------------------------------------------- + + // Set whether the contents should block javascript message boxes or not. + // Default is not to block any message boxes. + void set_suppress_javascript_messages( + bool suppress_javascript_messages) { + suppress_javascript_messages_ = suppress_javascript_messages; } + // JavascriptMessageBoxHandler calls this when the dialog is closed. + void OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, + bool success, + const std::wstring& prompt); + + // Whether or not the info bar is visible. This delegates to + // the ChromeFrame method InfoBarVisibilityChanged. See also IsInfoBarVisible + // (a TabContents override). + void SetInfoBarVisible(bool visible); + + // Prepare for saving page. + void OnSavePage(); + + // Save page with the main HTML file path, the directory for saving resources, + // and the save type: HTML only or complete web page. + void SavePage(const std::wstring& main_file, const std::wstring& dir_path, + SavePackage::SavePackageType save_type); + + // Displays asynchronously a print preview (generated by the renderer) if not + // already displayed and ask the user for its preferred print settings with + // the "Print..." dialog box. (managed by the print worker thread). + // TODO(maruel): Creates a snapshot of the renderer to be used for the new + // tab for the printing facility. + void PrintPreview(); + + // Prints the current document immediately. Since the rendering is + // asynchronous, the actual printing will not be completed on the return of + // this function. Returns false if printing is impossible at the moment. + bool PrintNow(); + // Returns true if the active NavigationEntry's page_id equals page_id. bool IsActiveEntry(int32 page_id); @@ -235,17 +223,19 @@ class WebContents : public TabContents, bool notify_disconnection() const { return notify_disconnection_; } protected: - FRIEND_TEST(WebContentsTest, UpdateTitle); - // Should be deleted via CloseContents. virtual ~WebContents(); - // RenderViewHostDelegate + // TabContents (private overrides) ------------------------------------------- + + virtual void SetInitialFocus(bool reverse); + virtual void SetIsLoading(bool is_loading, LoadNotificationDetails* details); + + // RenderViewHostDelegate ---------------------------------------------------- + virtual RenderViewHostDelegate::FindInPage* GetFindInPageDelegate() const; virtual RenderViewHostDelegate::Save* GetSaveDelegate() const; - virtual Profile* GetProfile() const; - virtual void CreateView(int route_id, HANDLE modal_dialog_event); virtual void CreateWidget(int route_id); virtual void ShowView(int route_id, @@ -257,7 +247,6 @@ class WebContents : public TabContents, virtual void RendererGone(RenderViewHost* render_view_host); virtual void DidNavigate(RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params); - virtual void UpdateRenderViewSize(); virtual void UpdateState(RenderViewHost* render_view_host, int32 page_id, const GURL& url, @@ -321,8 +310,12 @@ class WebContents : public TabContents, IPC::Message* reply_msg); virtual void PasswordFormsSeen(const std::vector<PasswordForm>& forms); virtual void TakeFocus(bool reverse); + virtual void PageHasOSDD(RenderViewHost* render_view_host, + int32 page_id, const GURL& url, bool autodetected); + virtual void InspectElementReply(int num_resources); virtual void DidGetPrintedPagesCount(int cookie, int number_pages); virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); + virtual void HandleKeyboardEvent(const WebKeyboardEvent& event); virtual GURL GetAlternateErrorPageURL() const; virtual WebPreferences GetWebkitPrefs(); virtual void OnMissingPluginStatus(int status); @@ -331,41 +324,47 @@ class WebContents : public TabContents, virtual void ShouldClosePage(bool proceed) { render_manager_.ShouldClosePage(proceed); } + // Allows the WebContents to react when a cross-site response is ready to be + // delivered to a pending RenderViewHost. We must first run the onunload + // handler of the old RenderViewHost before we can allow it to proceed. + void OnCrossSiteResponse(int new_render_process_host_id, + int new_request_id) { + render_manager_.OnCrossSiteResponse(new_render_process_host_id, + new_request_id); + } virtual bool CanBlur() const; virtual void RendererUnresponsive(RenderViewHost* render_view_host); virtual void RendererResponsive(RenderViewHost* render_view_host); virtual void LoadStateChanged(const GURL& url, net::LoadState load_state); - - // Notification that a page has an OpenSearch description document available - // at url. This 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. - virtual void PageHasOSDD(RenderViewHost* render_view_host, - int32 page_id, const GURL& url, bool autodetected); - virtual void OnDidGetApplicationInfo( int32 page_id, const webkit_glue::WebApplicationInfo& info); - // Overridden from TabContents. - virtual void SetInitialFocus(bool reverse); - - // Handle reply from inspect element request - virtual void InspectElementReply(int num_resources); - - // Handle keyboard events not processed by the renderer. - virtual void HandleKeyboardEvent(const WebKeyboardEvent& event); - - // Notifies the RenderWidgetHost instance about the fact that the - // page is loading, or done loading and calls the base implementation. - void SetIsLoading(bool is_loading, LoadNotificationDetails* details); + // SelectFileDialog::Listener ------------------------------------------------ - // Overridden from SelectFileDialog::Listener: virtual void FileSelected(const std::wstring& path, void* params); virtual void FileSelectionCanceled(void* params); - // Another part of RenderViewHostManager::Delegate. - // + // RenderViewHostManager::Delegate ------------------------------------------- + + virtual void BeforeUnloadFiredFromRenderManager( + bool proceed, + bool* proceed_to_fire_unload); + virtual void DidStartLoadingFromRenderManager( + RenderViewHost* render_view_host, int32 page_id) { + DidStartLoading(render_view_host, page_id); + } + virtual void RendererGoneFromRenderManager(RenderViewHost* render_view_host) { + RendererGone(render_view_host); + } + virtual void UpdateRenderViewSizeForRenderManager(); + virtual void NotifySwappedFromRenderManager() { + NotifySwapped(); + } + virtual NavigationController* GetControllerForRenderManager() { + return controller(); + } + // Initializes the given renderer if necessary and creates the view ID // corresponding to this view host. If this method is not called and the // process is not shared, then the WebContents will act as though the renderer @@ -382,6 +381,7 @@ class WebContents : public TabContents, RenderViewHost* render_view_host); private: + FRIEND_TEST(WebContentsTest, UpdateTitle); friend class TestWebContents; // When CreateShortcut is invoked RenderViewHost::GetApplicationInfo is @@ -400,17 +400,14 @@ class WebContents : public TabContents, GearsCreateShortcutCallbackFunctor* callback_functor; }; - void ScrollCommon(UINT message, int scroll_type, short position, - HWND scrollbar); - bool ScrollZoom(int scroll_type); - void WheelZoom(int distance); + // NotificationObserver ------------------------------------------------------ - // Backend for LoadURL that optionally creates a history entry. The - // transition type will be ignored if a history entry is not created. - void LoadURL(const std::wstring& url, bool create_history_entry, - PageTransition::Type transition); + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Windows events ------------------------------------------------------------ - // Windows Event handlers virtual void OnDestroy(); virtual void OnHScroll(int scroll_type, short position, HWND scrollbar); virtual void OnMouseLeave(); @@ -424,33 +421,14 @@ class WebContents : public TabContents, virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param); virtual void OnNCPaint(HRGN rgn); - // Callback from HistoryService for our request for a favicon. - void OnFavIconData(HistoryService::Handle handle, - bool know_favicon, - scoped_refptr<RefCountedBytes> data, - bool expired); - - // NotificationObserver implementation. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // Helper functions for sending notifications. - void NotifySwapped(); - void NotifyConnected(); - void NotifyDisconnected(); - - // Called by OnMsgNavigate to update history state. - virtual void UpdateHistoryForNavigation(const GURL& display_url, - const ViewHostMsg_FrameNavigate_Params& params); - - // If params has a searchable form, this tries to create a new keyword. - void GenerateKeywordIfNecessary( - const ViewHostMsg_FrameNavigate_Params& params); + // Backend for all scroll messages, the |message| parameter indicates which + // one it is. + void ScrollCommon(UINT message, int scroll_type, short position, + HWND scrollbar); - // Sets up the View that holds the rendered web page, receives messages for - // it and contains page plugins. - RenderWidgetHostHWND* CreatePageView(RenderViewHost* render_view_host); + // TODO(brettw) comment these. They're confusing. + bool ScrollZoom(int scroll_type); + void WheelZoom(int distance); // Navigation helpers -------------------------------------------------------- // @@ -505,35 +483,33 @@ class WebContents : public TabContents, void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, RenderViewHost* rvh); - // RenderViewHostManager::Delegate pass-throughs ----------------------------- + // Called by OnMsgNavigate to update history state. Overridden by subclasses + // that don't want to be added to history. + virtual void UpdateHistoryForNavigation(const GURL& display_url, + const ViewHostMsg_FrameNavigate_Params& params); - virtual void BeforeUnloadFiredFromRenderManager( - bool proceed, - bool* proceed_to_fire_unload); - virtual void DidStartLoadingFromRenderManager( - RenderViewHost* render_view_host, int32 page_id) { - DidStartLoading(render_view_host, page_id); - } - virtual void RendererGoneFromRenderManager(RenderViewHost* render_view_host) { - RendererGone(render_view_host); - } - virtual void UpdateRenderViewSizeForRenderManager() { - UpdateRenderViewSize(); - } - virtual void NotifySwappedFromRenderManager() { - NotifySwapped(); - } - virtual NavigationController* GetControllerForRenderManager() { - return controller(); - } + // Misc view stuff ----------------------------------------------------------- - // --------------------------------------------------------------------------- + // Sets up the View that holds the rendered web page, receives messages for + // it and contains page plugins. + RenderWidgetHostHWND* CreatePageView(RenderViewHost* render_view_host); // Enumerate and 'un-parent' any plugin windows that are children // of this web contents. void DetachPluginWindows(); static BOOL CALLBACK EnumPluginWindowsCallback(HWND window, LPARAM param); + // Misc non-view stuff ------------------------------------------------------- + + // Helper functions for sending notifications. + void NotifySwapped(); + void NotifyConnected(); + void NotifyDisconnected(); + + // If params has a searchable form, this tries to create a new keyword. + void GenerateKeywordIfNecessary( + const ViewHostMsg_FrameNavigate_Params& params); + // Data ---------------------------------------------------------------------- // Manages creation and swapping of render views. @@ -603,9 +579,6 @@ class WebContents : public TabContents, // The SadTab renderer. scoped_ptr<SadTabView> sad_tab_; - // This flag is true while we are in the photo-booth. See dragged_tab.cc. - bool capturing_contents_; - // Handles downloading favicons. FavIconHelper fav_icon_helper_; |