diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 16:24:33 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 16:24:33 +0000 |
commit | bf5c2ff3931c43b98095d33f8bc1b98379afe16f (patch) | |
tree | 7c87f5a7f693ac8b5a43cf5f2eebe0ac462b1853 /chrome/browser | |
parent | e9d7b6cf453475ad269785f3775700339c8a03fb (diff) | |
download | chromium_src-bf5c2ff3931c43b98095d33f8bc1b98379afe16f.zip chromium_src-bf5c2ff3931c43b98095d33f8bc1b98379afe16f.tar.gz chromium_src-bf5c2ff3931c43b98095d33f8bc1b98379afe16f.tar.bz2 |
Split out some of the RVHDelegate functions into separate sub-classes. To limit
the scope, this patch just contains those delegate functions implemented only
by TabContents, plus the favicon functions implemented by the FavIconHelper.
The only changes are re-ordering and moving the functions, and changes in the
way that the functions are called through the new optional delegate.
Review URL: http://codereview.chromium.org/149239
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20152 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/fav_icon_helper.cc | 66 | ||||
-rw-r--r-- | chrome/browser/fav_icon_helper.h | 17 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 115 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 16 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host_delegate.cc | 15 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host_delegate.h | 232 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 28 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 441 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 90 | ||||
-rw-r--r-- | chrome/browser/worker_host/worker_process_host.cc | 8 |
10 files changed, 580 insertions, 448 deletions
diff --git a/chrome/browser/fav_icon_helper.cc b/chrome/browser/fav_icon_helper.cc index 62a26cd..564c262 100644 --- a/chrome/browser/fav_icon_helper.cc +++ b/chrome/browser/fav_icon_helper.cc @@ -40,28 +40,6 @@ void FavIconHelper::FetchFavIcon(const GURL& url) { } } -void FavIconHelper::SetFavIconURL(const GURL& icon_url) { - NavigationEntry* entry = GetEntry(); - if (!entry) - return; - - got_fav_icon_url_ = true; - - if (!GetHistoryService()) - return; - - if (!fav_icon_expired_ && entry->favicon().is_valid() && - entry->favicon().url() == icon_url) { - // We already have the icon, no need to proceed. - return; - } - - entry->favicon().set_url(icon_url); - - if (got_fav_icon_from_history_) - DownloadFavIconOrAskHistory(entry); -} - Profile* FavIconHelper::profile() { return tab_contents_->profile(); } @@ -126,6 +104,41 @@ void FavIconHelper::UpdateFavIcon(NavigationEntry* entry, tab_contents_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); } +void FavIconHelper::UpdateFavIconURL(RenderViewHost* render_view_host, + int32 page_id, + const GURL& icon_url) { + NavigationEntry* entry = GetEntry(); + if (!entry) + return; + + got_fav_icon_url_ = true; + + if (!GetHistoryService()) + return; + + if (!fav_icon_expired_ && entry->favicon().is_valid() && + entry->favicon().url() == icon_url) { + // We already have the icon, no need to proceed. + return; + } + + entry->favicon().set_url(icon_url); + + if (got_fav_icon_from_history_) + DownloadFavIconOrAskHistory(entry); +} + +void FavIconHelper::DidDownloadFavIcon(RenderViewHost* render_view_host, + int id, + const GURL& image_url, + bool errored, + const SkBitmap& image) { + if (errored) + FavIconDownloadFailed(id); + else + SetFavIcon(id, image_url, image); +} + NavigationEntry* FavIconHelper::GetEntry() { NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); if (entry && entry->url() == url_ && @@ -235,12 +248,11 @@ void FavIconHelper::OnFavIconData( } void FavIconHelper::ScheduleDownload(NavigationEntry* entry) { - const int download_id = tab_contents_->render_view_host()->DownloadImage( + const int download_id = tab_contents_->render_view_host()->DownloadFavIcon( entry->favicon().url(), kFavIconSize); - if (!download_id) { - // Download request failed. - return; - } + if (!download_id) + return; // Download request failed. + // Download ids should be unique. DCHECK(download_requests_.find(download_id) == download_requests_.end()); download_requests_[download_id] = diff --git a/chrome/browser/fav_icon_helper.h b/chrome/browser/fav_icon_helper.h index 3a674d5..adbcaf0 100644 --- a/chrome/browser/fav_icon_helper.h +++ b/chrome/browser/fav_icon_helper.h @@ -12,6 +12,7 @@ #include "base/scoped_ptr.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/history/history.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/common/ref_counted_util.h" #include "googleurl/src/gurl.h" @@ -61,17 +62,13 @@ class TabContents; // at which point we update the favicon of the NavigationEntry and notify // the database to save the favicon. -class FavIconHelper { +class FavIconHelper : public RenderViewHostDelegate::FavIcon { public: explicit FavIconHelper(TabContents* tab_contents); // Initiates loading the favicon for the specified url. void FetchFavIcon(const GURL& url); - // Sets the url of the favicon for the specified page. This is invoked some - // time after FetchFavIcon. - void SetFavIconURL(const GURL& icon_url); - // Sets the image data for the favicon. This is invoked asynchronously after // we request the TabContents to download the favicon. void SetFavIcon(int download_id, @@ -100,6 +97,16 @@ class FavIconHelper { GURL fav_icon_url; }; + // RenderViewHostDelegate::Favicon implementation. + virtual void DidDownloadFavIcon(RenderViewHost* render_view_host, + int id, + const GURL& image_url, + bool errored, + const SkBitmap& image); + virtual void UpdateFavIconURL(RenderViewHost* render_view_host, + int32 page_id, + const GURL& icon_url); + // Return the NavigationEntry for the active entry, or NULL if the active // entries URL does not match that of the URL last passed to FetchFavIcon. NavigationEntry* GetEntry(); diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 4aa5de0..4445099 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -522,14 +522,14 @@ void RenderViewHost::SelectAll() { Send(new ViewMsg_SelectAll(routing_id())); } -int RenderViewHost::DownloadImage(const GURL& url, int image_size) { +int RenderViewHost::DownloadFavIcon(const GURL& url, int image_size) { if (!url.is_valid()) { NOTREACHED(); return 0; } static int next_id = 1; int id = next_id++; - Send(new ViewMsg_DownloadImage(routing_id(), id, url, image_size)); + Send(new ViewMsg_DownloadFavIcon(routing_id(), id, url, image_size)); return id; } @@ -725,7 +725,7 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { OnMsgDidFailProvisionalLoadWithError) IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnMsgFindReply) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFavIconURL, OnMsgUpdateFavIconURL) - IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadImage, OnMsgDidDownloadImage) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadFavIcon, OnMsgDidDownloadFavIcon) IPC_MESSAGE_HANDLER(ViewHostMsg_ContextMenu, OnMsgContextMenu) IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnMsgOpenURL) IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredWidthChange, @@ -775,8 +775,7 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, OnUserMetricsRecordAction) IPC_MESSAGE_HANDLER(ViewHostMsg_MissingPluginStatus, OnMissingPluginStatus); - IPC_MESSAGE_FORWARD(ViewHostMsg_CrashedPlugin, delegate_, - RenderViewHostDelegate::OnCrashedPlugin); + IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin); IPC_MESSAGE_HANDLER(ViewHostMsg_SendCurrentPageAllSavableResourceLinks, OnReceivedSavableResourceLinksForCurrentPage); IPC_MESSAGE_HANDLER(ViewHostMsg_SendSerializedHtmlData, @@ -977,7 +976,12 @@ void RenderViewHost::OnMsgRequestMove(const gfx::Rect& pos) { void RenderViewHost::OnMsgDidRedirectProvisionalLoad(int32 page_id, const GURL& source_url, const GURL& target_url) { - delegate_->DidRedirectProvisionalLoad(page_id, source_url, target_url); + RenderViewHostDelegate::Resource* resource_delegate = + delegate_->GetResourceDelegate(); + if (resource_delegate) { + resource_delegate->DidRedirectProvisionalLoad(page_id, + source_url, target_url); + } } void RenderViewHost::OnMsgDidStartLoading() { @@ -993,8 +997,12 @@ void RenderViewHost::OnMsgDidLoadResourceFromMemoryCache( const std::string& frame_origin, const std::string& main_frame_origin, const std::string& security_info) { - delegate_->DidLoadResourceFromMemoryCache( - url, frame_origin, main_frame_origin, security_info); + RenderViewHostDelegate::Resource* resource_delegate = + delegate_->GetResourceDelegate(); + if (resource_delegate) { + resource_delegate->DidLoadResourceFromMemoryCache( + url, frame_origin, main_frame_origin, security_info); + } } void RenderViewHost::OnMsgDidStartProvisionalLoadForFrame(bool is_main_frame, @@ -1003,8 +1011,12 @@ void RenderViewHost::OnMsgDidStartProvisionalLoadForFrame(bool is_main_frame, FilterURL(ChildProcessSecurityPolicy::GetInstance(), process()->pid(), &validated_url); - delegate_->DidStartProvisionalLoadForFrame(this, is_main_frame, - validated_url); + RenderViewHostDelegate::Resource* resource_delegate = + delegate_->GetResourceDelegate(); + if (resource_delegate) { + resource_delegate->DidStartProvisionalLoadForFrame(this, is_main_frame, + validated_url); + } } void RenderViewHost::OnMsgDidFailProvisionalLoadWithError( @@ -1016,9 +1028,13 @@ void RenderViewHost::OnMsgDidFailProvisionalLoadWithError( FilterURL(ChildProcessSecurityPolicy::GetInstance(), process()->pid(), &validated_url); - delegate_->DidFailProvisionalLoadWithError(this, is_main_frame, - error_code, validated_url, - showing_repost_interstitial); + RenderViewHostDelegate::Resource* resource_delegate = + delegate_->GetResourceDelegate(); + if (resource_delegate) { + resource_delegate->DidFailProvisionalLoadWithError( + this, is_main_frame, error_code, validated_url, + showing_repost_interstitial); + } } void RenderViewHost::OnMsgFindReply(int request_id, @@ -1026,8 +1042,13 @@ void RenderViewHost::OnMsgFindReply(int request_id, const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update) { - delegate_->OnFindReply(request_id, number_of_matches, selection_rect, - active_match_ordinal, final_update); + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + delegate_->GetBrowserIntegrationDelegate(); + if (integration_delegate) { + integration_delegate->OnFindReply(request_id, number_of_matches, + selection_rect, + active_match_ordinal, final_update); + } // Send a notification to the renderer that we are ready to receive more // results from the scoping effort of the Find operation. The FindInPage @@ -1040,15 +1061,20 @@ void RenderViewHost::OnMsgFindReply(int request_id, void RenderViewHost::OnMsgUpdateFavIconURL(int32 page_id, const GURL& icon_url) { - delegate_->UpdateFavIconURL(this, page_id, icon_url); + RenderViewHostDelegate::FavIcon* favicon_delegate = + delegate_->GetFavIconDelegate(); + if (favicon_delegate) + favicon_delegate->UpdateFavIconURL(this, page_id, icon_url); } -void RenderViewHost::OnMsgDidDownloadImage( - int id, - const GURL& image_url, - bool errored, - const SkBitmap& image) { - delegate_->DidDownloadImage(this, id, image_url, errored, image); +void RenderViewHost::OnMsgDidDownloadFavIcon(int id, + const GURL& image_url, + bool errored, + const SkBitmap& image) { + RenderViewHostDelegate::FavIcon* favicon_delegate = + delegate_->GetFavIconDelegate(); + if (favicon_delegate) + favicon_delegate->DidDownloadFavIcon(this, id, image_url, errored, image); } void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { @@ -1060,7 +1086,8 @@ void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { // directly, don't show them in the context menu. ContextMenuParams validated_params(params); const int renderer_id = process()->pid(); - ChildProcessSecurityPolicy* policy = ChildProcessSecurityPolicy::GetInstance(); + ChildProcessSecurityPolicy* policy = + ChildProcessSecurityPolicy::GetInstance(); // We don't validate |unfiltered_link_url| so that this field can be used // when users want to copy the original link URL. @@ -1124,7 +1151,10 @@ void RenderViewHost::OnMsgForwardMessageToExternalHost( } void RenderViewHost::OnMsgDocumentLoadedInFrame() { - delegate_->DocumentLoadedInFrame(); + RenderViewHostDelegate::Resource* resource_delegate = + delegate_->GetResourceDelegate(); + if (resource_delegate) + resource_delegate->DocumentLoadedInFrame(); } void RenderViewHost::DisassociateFromPopupCount() { @@ -1136,7 +1166,10 @@ void RenderViewHost::PopupNotificationVisibilityChanged(bool visible) { } void RenderViewHost::OnMsgGoToEntryAtOffset(int offset) { - delegate_->GoToEntryAtOffset(offset); + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + delegate_->GetBrowserIntegrationDelegate(); + if (integration_delegate) + integration_delegate->GoToEntryAtOffset(offset); } void RenderViewHost::OnMsgSetTooltipText(const std::wstring& tooltip_text) { @@ -1283,18 +1316,35 @@ void RenderViewHost::UnhandledKeyboardEvent( } void RenderViewHost::OnUserGesture() { - delegate_->OnUserGesture(); + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + delegate_->GetBrowserIntegrationDelegate(); + if (integration_delegate) + integration_delegate->OnUserGesture(); } void RenderViewHost::OnMissingPluginStatus(int status) { - delegate_->OnMissingPluginStatus(status); + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + delegate_->GetBrowserIntegrationDelegate(); + if (integration_delegate) + integration_delegate->OnMissingPluginStatus(status); +} + +void RenderViewHost::OnCrashedPlugin(const FilePath& plugin_path) { + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + delegate_->GetBrowserIntegrationDelegate(); + if (integration_delegate) + integration_delegate->OnCrashedPlugin(plugin_path); } void RenderViewHost::UpdateBackForwardListCount() { int back_list_count = 0, forward_list_count = 0; - delegate_->GetHistoryListCount(&back_list_count, &forward_list_count); - Send(new ViewMsg_UpdateBackForwardListCount( - routing_id(), back_list_count, forward_list_count)); + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + delegate_->GetBrowserIntegrationDelegate(); + if (integration_delegate) { + integration_delegate->GetHistoryListCount(&back_list_count, &forward_list_count); + Send(new ViewMsg_UpdateBackForwardListCount( + routing_id(), back_list_count, forward_list_count)); + } } void RenderViewHost::GetAllSavableResourceLinksForCurrentPage( @@ -1317,7 +1367,10 @@ void RenderViewHost::OnReceivedSavableResourceLinksForCurrentPage( void RenderViewHost::OnDidGetApplicationInfo( int32 page_id, const webkit_glue::WebApplicationInfo& info) { - delegate_->OnDidGetApplicationInfo(page_id, info); + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + delegate_->GetBrowserIntegrationDelegate(); + if (integration_delegate) + integration_delegate->OnDidGetApplicationInfo(page_id, info); } void RenderViewHost::GetSerializedHtmlDataForCurrentPageWithLocalLinks( diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index e7e6a81..6d39844 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -262,9 +262,10 @@ class RenderViewHost : public RenderWidgetHost, void Delete(); void SelectAll(); - // Downloads an image notifying the delegate appropriately. The returned - // integer uniquely identifies the download for the lifetime of the browser. - int DownloadImage(const GURL& url, int image_size); + // Downloads an image notifying the FavIcon delegate appropriately. The + // returned integer uniquely identifies the download for the lifetime of the + // browser. + int DownloadFavIcon(const GURL& url, int image_size); // Requests application info for the specified page. This is an asynchronous // request. The delegate is notified by way of OnDidGetApplicationInfo when @@ -457,10 +458,10 @@ class RenderViewHost : public RenderWidgetHost, int active_match_ordinal, bool final_update); void OnMsgUpdateFavIconURL(int32 page_id, const GURL& icon_url); - void OnMsgDidDownloadImage(int id, - const GURL& image_url, - bool errored, - const SkBitmap& image_data); + void OnMsgDidDownloadFavIcon(int id, + const GURL& image_url, + bool errored, + const SkBitmap& image_data); void OnMsgContextMenu(const ContextMenuParams& params); void OnMsgOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition); @@ -513,6 +514,7 @@ class RenderViewHost : public RenderWidgetHost, void OnUserMetricsRecordAction(const std::wstring& action); void OnMissingPluginStatus(int status); + void OnCrashedPlugin(const FilePath& plugin_path); void OnMessageReceived(IPC::Message* msg) { } void OnReceivedSavableResourceLinksForCurrentPage( diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc index 4e05a60..b976176 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.cc +++ b/chrome/browser/renderer_host/render_view_host_delegate.cc @@ -13,10 +13,25 @@ RenderViewHostDelegate::View* RenderViewHostDelegate::GetViewDelegate() const { return NULL; } +RenderViewHostDelegate::BrowserIntegration* +RenderViewHostDelegate::GetBrowserIntegrationDelegate() const { + return NULL; +} + +RenderViewHostDelegate::Resource* +RenderViewHostDelegate::GetResourceDelegate() const { + return NULL; +} + RenderViewHostDelegate::Save* RenderViewHostDelegate::GetSaveDelegate() const { return NULL; } +RenderViewHostDelegate::FavIcon* +RenderViewHostDelegate::GetFavIconDelegate() const { + return NULL; +} + const GURL& RenderViewHostDelegate::GetURL() const { return GURL::EmptyGURL(); } diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index e3fe34a..b1992e8 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -65,6 +65,9 @@ struct WebApplicationInfo; // class RenderViewHostDelegate { public: + // View ---------------------------------------------------------------------- + // Functions that can be routed directly to a view-specific class. + class View { public: // The page is trying to open a new page (e.g. a popup window). The @@ -134,7 +137,111 @@ class RenderViewHostDelegate { virtual void UpdatePreferredWidth(int pref_width) = 0; }; + // BrowserIntegration -------------------------------------------------------- + // Functions that integrate with other browser services. + + class BrowserIntegration { + public: + // Notification the user has made a gesture while focus was on the + // page. This is used to avoid uninitiated user downloads (aka carpet + // bombing), see DownloadRequestManager for details. + virtual void OnUserGesture() = 0; + + // A find operation in the current page completed. + virtual void OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update) = 0; + + // Navigate to the history entry for the given offset from the current + // position within the NavigationController. Makes no change if offset is + // not valid. + virtual void GoToEntryAtOffset(int offset) = 0; + + // The page requests the size of the back and forward lists + // within the NavigationController. + virtual void GetHistoryListCount(int* back_list_count, + int* forward_list_count) = 0; + + // Notification when default plugin updates status of the missing plugin. + virtual void OnMissingPluginStatus(int status) = 0; + + // Notification from the renderer that a plugin instance has crashed. + // + // BrowserIntegration isn't necessarily the best place for this, if you + // need to implement this function somewhere that doesn't need any other + // BrowserIntegration callbacks, feel free to move it elsewhere. + virtual void OnCrashedPlugin(const FilePath& plugin_path) = 0; + + // Notification that a worker process has crashed. + virtual void OnCrashedWorker() = 0; + + // Notification that a request for install info has completed. + virtual void OnDidGetApplicationInfo( + int32 page_id, + const webkit_glue::WebApplicationInfo& app_info) = 0; + }; + + // Resource ------------------------------------------------------------------ + // Notifications of resource loading events. + + class Resource { + public: + // The RenderView is starting a provisional load. + virtual void DidStartProvisionalLoadForFrame( + RenderViewHost* render_view_host, + bool is_main_frame, + const GURL& url) = 0; + + // Notification by the resource loading system (not the renderer) that it + // has started receiving a resource response. This is different than + // DidStartProvisionalLoadForFrame above because this is called for every + // resource (images, automatically loaded subframes, etc.) and provisional + // loads are only for user-initiated navigations. + // + // The pointer ownership is NOT transferred. + virtual void DidStartReceivingResourceResponse( + ResourceRequestDetails* details) = 0; + + // Sent when a provisional load is redirected. + virtual void DidRedirectProvisionalLoad(int32 page_id, + const GURL& source_url, + const GURL& target_url) = 0; + + // Notification by the resource loading system (not the renderer) that a + // resource was redirected. This is different than + // DidRedirectProvisionalLoad above because this is called for every + // resource (images, automatically loaded subframes, etc.) and provisional + // loads are only for user-initiated navigations. + // + // The pointer ownership is NOT transferred. + virtual void DidRedirectResource(ResourceRequestDetails* details) = 0; + + // The RenderView loaded a resource from an in-memory cache. + // |security_info| contains the security info if this resource was + // originally loaded over a secure connection. + virtual void DidLoadResourceFromMemoryCache( + const GURL& url, + const std::string& frame_origin, + const std::string& main_frame_origin, + const std::string& security_info) = 0; + + // The RenderView failed a provisional load with an error. + virtual void DidFailProvisionalLoadWithError( + RenderViewHost* render_view_host, + bool is_main_frame, + int error_code, + const GURL& url, + bool showing_repost_interstitial) = 0; + + // Notification that a document has been loaded in a frame. + virtual void DocumentLoadedInFrame() = 0; + }; + + // Save ---------------------------------------------------------------------- // Interface for saving web pages. + class Save { public: // Notification that we get when we receive all savable links of @@ -157,10 +264,38 @@ class RenderViewHostDelegate { int32 status) = 0; }; + // FavIcon ------------------------------------------------------------------- + // Interface for the renderer to supply favicon information. + + class FavIcon { + public: + // An image that was requested to be downloaded by DownloadImage has + // completed. + // + // TODO(brettw) this should be renamed DidDownloadFavIcon, and the RVH + // function, IPC message, and the RenderView function DownloadImage should + // all be named DownloadFavIcon. + virtual void DidDownloadFavIcon(RenderViewHost* render_view_host, + int id, + const GURL& image_url, + bool errored, + const SkBitmap& image) = 0; + + // The URL for the FavIcon of a page has changed. + virtual void UpdateFavIconURL(RenderViewHost* render_view_host, + int32 page_id, + const GURL& icon_url) = 0; + }; + + // --------------------------------------------------------------------------- + // Returns the current delegate associated with a feature. May return NULL if // there is no corresponding delegate. virtual View* GetViewDelegate() const; + virtual BrowserIntegration* GetBrowserIntegrationDelegate() const; + virtual Resource* GetResourceDelegate() const; virtual Save* GetSaveDelegate() const; + virtual FavIcon* GetFavIconDelegate() const; // Gets the URL that is currently being displayed, if there is one. virtual const GURL& GetURL() const; @@ -223,64 +358,6 @@ class RenderViewHostDelegate { // notion of the throbber stopping. virtual void DidStopLoading(RenderViewHost* render_view_host) {} - // The RenderView is starting a provisional load. - virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host, - bool is_main_frame, - const GURL& url) {} - - // Notification by the resource loading system (not the renderer) that it has - // started receiving a resource response. This is different than - // DidStartProvisionalLoadForFrame above because this is called for every - // resource (images, automatically loaded subframes, etc.) and provisional - // loads are only for user-initiated navigations. - // - // The pointer ownership is NOT transferred. - virtual void DidStartReceivingResourceResponse( - ResourceRequestDetails* details) {} - - // Sent when a provisional load is redirected. - virtual void DidRedirectProvisionalLoad(int32 page_id, - const GURL& source_url, - const GURL& target_url) {} - - // Notification by the resource loading system (not the renderer) that a - // resource was redirected. This is different than DidRedirectProvisionalLoad - // above because this is called for every resource (images, automatically - // loaded subframes, etc.) and provisional loads are only for user-initiated - // navigations. - // - // The pointer ownership is NOT transferred. - virtual void DidRedirectResource(ResourceRequestDetails* details) {} - - // The RenderView loaded a resource from an in-memory cache. - // |security_info| contains the security info if this resource was originally - // loaded over a secure connection. - virtual void DidLoadResourceFromMemoryCache( - const GURL& url, - const std::string& frame_origin, - const std::string& main_frame_origin, - const std::string& security_info) {} - - // The RenderView failed a provisional load with an error. - virtual void DidFailProvisionalLoadWithError( - RenderViewHost* render_view_host, - bool is_main_frame, - int error_code, - const GURL& url, - bool showing_repost_interstitial) {} - - // The URL for the FavIcon of a page has changed. - virtual void UpdateFavIconURL(RenderViewHost* render_view_host, - int32 page_id, const GURL& icon_url) {} - - // An image that was requested to be downloaded by DownloadImage has - // completed. - virtual void DidDownloadImage(RenderViewHost* render_view_host, - int id, - const GURL& image_url, - bool errored, - const SkBitmap& image) {} - // The page wants to open a URL with the specified disposition. virtual void RequestOpenURL(const GURL& url, const GURL& referrer, @@ -305,19 +382,6 @@ class RenderViewHostDelegate { const std::string& origin, const std::string& target) {} - // Notification that a document has been loaded in a frame. - virtual void DocumentLoadedInFrame() {} - - // Navigate to the history entry for the given offset from the current - // position within the NavigationController. Makes no change if offset is - // not valid. - virtual void GoToEntryAtOffset(int offset) {} - - // The page requests the size of the back and forward lists - // within the NavigationController. - virtual void GetHistoryListCount(int* back_list_count, - int* forward_list_count) {} - // A file chooser should be shown. virtual void RunFileChooser(bool multiple_files, const string16& title, @@ -388,15 +452,6 @@ class RenderViewHostDelegate { // associated with the owning render view host. virtual WebPreferences GetWebkitPrefs(); - // Notification when default plugin updates status of the missing plugin. - virtual void OnMissingPluginStatus(int status) {} - - // Notification from the renderer that a plugin instance has crashed. - virtual void OnCrashedPlugin(const FilePath& plugin_path) {} - - // Notification that a worker process has crashed. - virtual void OnCrashedWorker() {} - // Notification from the renderer that JS runs out of memory. virtual void OnJSOutOfMemory() {} @@ -438,26 +493,9 @@ class RenderViewHostDelegate { // Notification that the RenderViewHost's load state changed. virtual void LoadStateChanged(const GURL& url, net::LoadState load_state) {} - // Notification that a request for install info has completed. - virtual void OnDidGetApplicationInfo( - int32 page_id, - const webkit_glue::WebApplicationInfo& app_info) {} - - // Notification the user has made a gesture while focus was on the - // page. This is used to avoid uninitiated user downloads (aka carpet - // bombing), see DownloadRequestManager for details. - virtual void OnUserGesture() {} - // Returns true if this view is used to host an external tab container. virtual bool IsExternalTabContainer() const; - // A find operation in the current page completed. - virtual void OnFindReply(int request_id, - int number_of_matches, - const gfx::Rect& selection_rect, - int active_match_ordinal, - bool final_update) {} - // The RenderView has inserted one css file into page. virtual void DidInsertCSS() {} }; diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 28a64a3..16d8a62 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -114,6 +114,9 @@ const int kMaxOutstandingRequestsCostPerProcess = 26214400; // constructed on the IO thread and run in the UI thread. class NotificationTask : public Task { public: + typedef void (RenderViewHostDelegate::Resource::* ResourceFunction) + (ResourceRequestDetails*); + // Supply the originating URLRequest, a function on RenderViewHostDelegate // to call, and the details to use as the parameter to the given function. // @@ -121,29 +124,34 @@ class NotificationTask : public Task { // allocated on the heap. NotificationTask( URLRequest* request, - void (RenderViewHostDelegate::* function)(ResourceRequestDetails*), + ResourceFunction function, ResourceRequestDetails* details) : function_(function), details_(details) { if (!ResourceDispatcherHost::RenderViewForRequest(request, &render_process_host_id_, - &render_view_host_id_)) + &render_view_host_id_)) { NOTREACHED(); + } } virtual void Run() { RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id_, render_view_host_id_); - if (rvh) - (rvh->delegate()->*function_)(details_.get()); + if (rvh) { + RenderViewHostDelegate::Resource* resource_delegate = + rvh->delegate()->GetResourceDelegate(); + if (resource_delegate) + (resource_delegate->*function_)(details_.get()); + } } private: int render_process_host_id_; int render_view_host_id_; - // The function to call on RenderViewHostDelegate on the UI thread. - void (RenderViewHostDelegate::* function_)(ResourceRequestDetails*); + // The function to call on RenderViewHostDelegate::Resource on the UI thread. + ResourceFunction function_; // The details for the notification. scoped_ptr<ResourceRequestDetails> details_; @@ -1392,7 +1400,7 @@ void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request, // Notify the observers on the UI thread. ui_loop_->PostTask(FROM_HERE, new NotificationTask(request, - &RenderViewHostDelegate::DidStartReceivingResourceResponse, + &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, new ResourceRequestDetails(request, GetCertID(request, process_id)))); } @@ -1417,10 +1425,8 @@ void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request, // Notify the observers on the UI thread. ui_loop_->PostTask(FROM_HERE, new NotificationTask(request, - &RenderViewHostDelegate::DidRedirectResource, - new ResourceRedirectDetails(request, - cert_id, - new_url))); + &RenderViewHostDelegate::Resource::DidRedirectResource, + new ResourceRedirectDetails(request, cert_id, new_url))); } namespace { diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index d239955..4755bff 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1478,14 +1478,230 @@ void TabContents::GenerateKeywordIfNecessary( url_model->Add(new_url); } +void TabContents::OnUserGesture() { + // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. + DownloadRequestManager* drm = g_browser_process->download_request_manager(); + if (drm) + drm->OnUserGesture(this); + controller_.OnUserGesture(); +} + +void TabContents::OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update) { + // Ignore responses for requests other than the one we have most recently + // issued. That way we won't act on stale results when the user has + // already typed in another query. + if (request_id != current_find_request_id_) + return; + + if (number_of_matches == -1) + number_of_matches = last_search_result_.number_of_matches(); + if (active_match_ordinal == -1) + active_match_ordinal = last_search_result_.active_match_ordinal(); + + gfx::Rect selection = selection_rect; + if (selection.IsEmpty()) + selection = last_search_result_.selection_rect(); + + // Notify the UI, automation and any other observers that a find result was + // found. + last_search_result_ = FindNotificationDetails(request_id, number_of_matches, + selection, active_match_ordinal, + final_update); + NotificationService::current()->Notify( + NotificationType::FIND_RESULT_AVAILABLE, + Source<TabContents>(this), + Details<FindNotificationDetails>(&last_search_result_)); +} + +void TabContents::GoToEntryAtOffset(int offset) { + controller_.GoToOffset(offset); +} + +void TabContents::GetHistoryListCount(int* back_list_count, + int* forward_list_count) { + int current_index = controller_.last_committed_entry_index(); + *back_list_count = current_index; + *forward_list_count = controller_.entry_count() - current_index - 1; +} + +void TabContents::OnMissingPluginStatus(int status) { +#if defined(OS_WIN) +// TODO(PORT): pull in when plug-ins work + GetPluginInstaller()->OnMissingPluginStatus(status); +#endif +} + +void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { +#if defined(OS_WIN) +// TODO(PORT): pull in when plug-ins work + DCHECK(!plugin_path.value().empty()); + + std::wstring plugin_name = plugin_path.ToWStringHack(); + scoped_ptr<FileVersionInfo> version_info( + FileVersionInfo::CreateFileVersionInfo(plugin_path)); + if (version_info.get()) { + const std::wstring& product_name = version_info->product_name(); + if (!product_name.empty()) + plugin_name = product_name; + } + AddInfoBar(new SimpleAlertInfoBarDelegate( + this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), + NULL)); +#endif +} + +void TabContents::OnCrashedWorker() { + AddInfoBar(new SimpleAlertInfoBarDelegate( + this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT), + NULL)); +} + +void TabContents::OnDidGetApplicationInfo( + int32 page_id, + const webkit_glue::WebApplicationInfo& info) { + if (pending_install_.page_id != page_id) + return; // The user clicked create on a separate page. Ignore this. + + pending_install_.callback_functor = + new GearsCreateShortcutCallbackFunctor(this); + GearsCreateShortcut( + info, pending_install_.title, pending_install_.url, pending_install_.icon, + NewCallback(pending_install_.callback_functor, + &GearsCreateShortcutCallbackFunctor::Run)); +} + +void TabContents::DidStartProvisionalLoadForFrame( + RenderViewHost* render_view_host, + bool is_main_frame, + const GURL& url) { + ProvisionalLoadDetails details(is_main_frame, + controller_.IsURLInPageNavigation(url), + url, std::string(), false); + NotificationService::current()->Notify( + NotificationType::FRAME_PROVISIONAL_LOAD_START, + Source<NavigationController>(&controller_), + Details<ProvisionalLoadDetails>(&details)); +} + +void TabContents::DidStartReceivingResourceResponse( + ResourceRequestDetails* details) { + NotificationService::current()->Notify( + NotificationType::RESOURCE_RESPONSE_STARTED, + Source<NavigationController>(&controller()), + Details<ResourceRequestDetails>(details)); +} + +void TabContents::DidRedirectResource(ResourceRequestDetails* details) { + NotificationService::current()->Notify( + NotificationType::RESOURCE_RECEIVED_REDIRECT, + Source<NavigationController>(&controller()), + Details<ResourceRequestDetails>(details)); +} + +void TabContents::DidLoadResourceFromMemoryCache( + const GURL& url, + const std::string& frame_origin, + const std::string& main_frame_origin, + const std::string& security_info) { + // Send out a notification that we loaded a resource from our memory cache. + int cert_id = 0, cert_status = 0, security_bits = 0; + SSLManager::DeserializeSecurityInfo(security_info, + &cert_id, &cert_status, + &security_bits); + LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin, + process()->pid(), cert_id, cert_status); + + NotificationService::current()->Notify( + NotificationType::LOAD_FROM_MEMORY_CACHE, + Source<NavigationController>(&controller_), + Details<LoadFromMemoryCacheDetails>(&details)); +} + +void TabContents::DidFailProvisionalLoadWithError( + RenderViewHost* render_view_host, + bool is_main_frame, + int error_code, + const GURL& url, + bool showing_repost_interstitial) { + if (net::ERR_ABORTED == error_code) { + // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. + // This means that the interstitial won't be torn down properly, which is + // bad. But if we have an interstitial, go back to another tab type, and + // then load the same interstitial again, we could end up getting the first + // interstitial's "failed" message (as a result of the cancel) when we're on + // the second one. + // + // We can't tell this apart, so we think we're tearing down the current page + // which will cause a crash later one. There is also some code in + // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented + // out because of this problem. + // + // http://code.google.com/p/chromium/issues/detail?id=2855 + // Because this will not tear down the interstitial properly, if "back" is + // back to another tab type, the interstitial will still be somewhat alive + // in the previous tab type. If you navigate somewhere that activates the + // tab with the interstitial again, you'll see a flash before the new load + // commits of the interstitial page. + if (showing_interstitial_page()) { + LOG(WARNING) << "Discarding message during interstitial."; + return; + } + + // This will discard our pending entry if we cancelled the load (e.g., if we + // decided to download the file instead of load it). Only discard the + // pending entry if the URLs match, otherwise the user initiated a navigate + // before the page loaded so that the discard would discard the wrong entry. + NavigationEntry* pending_entry = controller_.pending_entry(); + if (pending_entry && pending_entry->url() == url) { + controller_.DiscardNonCommittedEntries(); + // Update the URL display. + NotifyNavigationStateChanged(TabContents::INVALIDATE_URL); + } + + render_manager_.RendererAbortedProvisionalLoad(render_view_host); + } + + // Send out a notification that we failed a provisional load with an error. + ProvisionalLoadDetails details(is_main_frame, + controller_.IsURLInPageNavigation(url), + url, std::string(), false); + details.set_error_code(error_code); + + NotificationService::current()->Notify( + NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, + Source<NavigationController>(&controller_), + Details<ProvisionalLoadDetails>(&details)); +} + +void TabContents::DocumentLoadedInFrame() { + controller_.DocumentLoadedInFrame(); +} + RenderViewHostDelegate::View* TabContents::GetViewDelegate() const { return view_.get(); } +RenderViewHostDelegate::BrowserIntegration* + TabContents::GetBrowserIntegrationDelegate() const { + return const_cast<TabContents*>(this); +} + +RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() const { + return const_cast<TabContents*>(this); +} + RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() const { return save_package_.get(); // May be NULL, but we can return NULL. } +RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() const { + return &const_cast<TabContents*>(this)->fav_icon_helper_; +} + RendererPreferences TabContents::GetRendererPrefs() const { if (delegate()) return delegate()->GetRendererPrefs(); @@ -1709,27 +1925,6 @@ void TabContents::DidStopLoading(RenderViewHost* rvh) { SetIsLoading(false, details.get()); } -void TabContents::DidStartProvisionalLoadForFrame( - RenderViewHost* render_view_host, - bool is_main_frame, - const GURL& url) { - ProvisionalLoadDetails details(is_main_frame, - controller_.IsURLInPageNavigation(url), - url, std::string(), false); - NotificationService::current()->Notify( - NotificationType::FRAME_PROVISIONAL_LOAD_START, - Source<NavigationController>(&controller_), - Details<ProvisionalLoadDetails>(&details)); -} - -void TabContents::DidStartReceivingResourceResponse( - ResourceRequestDetails* details) { - NotificationService::current()->Notify( - NotificationType::RESOURCE_RESPONSE_STARTED, - Source<NavigationController>(&controller()), - Details<ResourceRequestDetails>(details)); -} - void TabContents::DidRedirectProvisionalLoad(int32 page_id, const GURL& source_url, const GURL& target_url) { @@ -1743,110 +1938,6 @@ void TabContents::DidRedirectProvisionalLoad(int32 page_id, entry->set_url(target_url); } -void TabContents::DidRedirectResource(ResourceRequestDetails* details) { - NotificationService::current()->Notify( - NotificationType::RESOURCE_RECEIVED_REDIRECT, - Source<NavigationController>(&controller()), - Details<ResourceRequestDetails>(details)); -} - -void TabContents::DidLoadResourceFromMemoryCache( - const GURL& url, - const std::string& frame_origin, - const std::string& main_frame_origin, - const std::string& security_info) { - // Send out a notification that we loaded a resource from our memory cache. - int cert_id = 0, cert_status = 0, security_bits = 0; - SSLManager::DeserializeSecurityInfo(security_info, - &cert_id, &cert_status, - &security_bits); - LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin, - process()->pid(), cert_id, cert_status); - - NotificationService::current()->Notify( - NotificationType::LOAD_FROM_MEMORY_CACHE, - Source<NavigationController>(&controller_), - Details<LoadFromMemoryCacheDetails>(&details)); -} - -void TabContents::DidFailProvisionalLoadWithError( - RenderViewHost* render_view_host, - bool is_main_frame, - int error_code, - const GURL& url, - bool showing_repost_interstitial) { - if (net::ERR_ABORTED == error_code) { - // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. - // This means that the interstitial won't be torn down properly, which is - // bad. But if we have an interstitial, go back to another tab type, and - // then load the same interstitial again, we could end up getting the first - // interstitial's "failed" message (as a result of the cancel) when we're on - // the second one. - // - // We can't tell this apart, so we think we're tearing down the current page - // which will cause a crash later one. There is also some code in - // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented - // out because of this problem. - // - // http://code.google.com/p/chromium/issues/detail?id=2855 - // Because this will not tear down the interstitial properly, if "back" is - // back to another tab type, the interstitial will still be somewhat alive - // in the previous tab type. If you navigate somewhere that activates the - // tab with the interstitial again, you'll see a flash before the new load - // commits of the interstitial page. - if (showing_interstitial_page()) { - LOG(WARNING) << "Discarding message during interstitial."; - return; - } - - // This will discard our pending entry if we cancelled the load (e.g., if we - // decided to download the file instead of load it). Only discard the - // pending entry if the URLs match, otherwise the user initiated a navigate - // before the page loaded so that the discard would discard the wrong entry. - NavigationEntry* pending_entry = controller_.pending_entry(); - if (pending_entry && pending_entry->url() == url) { - controller_.DiscardNonCommittedEntries(); - // Update the URL display. - NotifyNavigationStateChanged(TabContents::INVALIDATE_URL); - } - - render_manager_.RendererAbortedProvisionalLoad(render_view_host); - } - - // Send out a notification that we failed a provisional load with an error. - ProvisionalLoadDetails details(is_main_frame, - controller_.IsURLInPageNavigation(url), - url, std::string(), false); - details.set_error_code(error_code); - - NotificationService::current()->Notify( - NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, - Source<NavigationController>(&controller_), - Details<ProvisionalLoadDetails>(&details)); -} - -void TabContents::UpdateFavIconURL(RenderViewHost* render_view_host, - int32 page_id, - const GURL& icon_url) { - fav_icon_helper_.SetFavIconURL(icon_url); -} - -void TabContents::DidDownloadImage( - RenderViewHost* render_view_host, - int id, - const GURL& image_url, - bool errored, - const SkBitmap& image) { - // A notification for downloading would be more flexible, but for now I'm - // forwarding to the two places that could possibly have initiated the - // request. If we end up with another place invoking DownloadImage, probably - // best to refactor out into notification service, or something similar. - if (errored) - fav_icon_helper_.FavIconDownloadFailed(id); - else - fav_icon_helper_.SetFavIcon(id, image_url, image); -} - void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition) { if (render_manager_.dom_ui()) { @@ -1884,10 +1975,6 @@ void TabContents::ProcessDOMUIMessage(const std::string& message, has_callback); } -void TabContents::DocumentLoadedInFrame() { - controller_.DocumentLoadedInFrame(); -} - void TabContents::ProcessExternalHostMessage(const std::string& message, const std::string& origin, const std::string& target) { @@ -1895,17 +1982,6 @@ void TabContents::ProcessExternalHostMessage(const std::string& message, delegate()->ForwardMessageToExternalHost(message, origin, target); } -void TabContents::GoToEntryAtOffset(int offset) { - controller_.GoToOffset(offset); -} - -void TabContents::GetHistoryListCount(int* back_list_count, - int* forward_list_count) { - int current_index = controller_.last_committed_entry_index(); - *back_list_count = current_index; - *forward_list_count = controller_.entry_count() - current_index - 1; -} - void TabContents::RunFileChooser(bool multiple_files, const string16& title, const FilePath& default_file) { @@ -2094,38 +2170,6 @@ WebPreferences TabContents::GetWebkitPrefs() { return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, isDomUI); } -void TabContents::OnMissingPluginStatus(int status) { -#if defined(OS_WIN) -// TODO(PORT): pull in when plug-ins work - GetPluginInstaller()->OnMissingPluginStatus(status); -#endif -} - -void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { -#if defined(OS_WIN) -// TODO(PORT): pull in when plug-ins work - DCHECK(!plugin_path.value().empty()); - - std::wstring plugin_name = plugin_path.ToWStringHack(); - scoped_ptr<FileVersionInfo> version_info( - FileVersionInfo::CreateFileVersionInfo(plugin_path)); - if (version_info.get()) { - const std::wstring& product_name = version_info->product_name(); - if (!product_name.empty()) - plugin_name = product_name; - } - AddInfoBar(new SimpleAlertInfoBarDelegate( - this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), - NULL)); -#endif -} - -void TabContents::OnCrashedWorker() { - AddInfoBar(new SimpleAlertInfoBarDelegate( - this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT), - NULL)); -} - void TabContents::OnJSOutOfMemory() { AddInfoBar(new SimpleAlertInfoBarDelegate( this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL)); @@ -2198,28 +2242,6 @@ void TabContents::LoadStateChanged(const GURL& url, NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB); } -void TabContents::OnDidGetApplicationInfo( - int32 page_id, - const webkit_glue::WebApplicationInfo& info) { - if (pending_install_.page_id != page_id) - return; // The user clicked create on a separate page. Ignore this. - - pending_install_.callback_functor = - new GearsCreateShortcutCallbackFunctor(this); - GearsCreateShortcut( - info, pending_install_.title, pending_install_.url, pending_install_.icon, - NewCallback(pending_install_.callback_functor, - &GearsCreateShortcutCallbackFunctor::Run)); -} - -void TabContents::OnUserGesture() { - // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. - DownloadRequestManager* drm = g_browser_process->download_request_manager(); - if (drm) - drm->OnUserGesture(this); - controller_.OnUserGesture(); -} - bool TabContents::IsExternalTabContainer() const { if (!delegate()) return false; @@ -2227,37 +2249,6 @@ bool TabContents::IsExternalTabContainer() const { return delegate()->IsExternalTabContainer(); } -void TabContents::OnFindReply(int request_id, - int number_of_matches, - const gfx::Rect& selection_rect, - int active_match_ordinal, - bool final_update) { - // Ignore responses for requests other than the one we have most recently - // issued. That way we won't act on stale results when the user has - // already typed in another query. - if (request_id != current_find_request_id_) - return; - - if (number_of_matches == -1) - number_of_matches = last_search_result_.number_of_matches(); - if (active_match_ordinal == -1) - active_match_ordinal = last_search_result_.active_match_ordinal(); - - gfx::Rect selection = selection_rect; - if (selection.IsEmpty()) - selection = last_search_result_.selection_rect(); - - // Notify the UI, automation and any other observers that a find result was - // found. - last_search_result_ = FindNotificationDetails(request_id, number_of_matches, - selection, active_match_ordinal, - final_update); - NotificationService::current()->Notify( - NotificationType::FIND_RESULT_AVAILABLE, - Source<TabContents>(this), - Details<FindNotificationDetails>(&last_search_result_)); -} - void TabContents::DidInsertCSS() { // This RVHDelegate function is used for extensions and not us. } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index c4f2d2f..5f50c46 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -94,6 +94,8 @@ class TabContents; class TabContents : public PageNavigator, public NotificationObserver, public RenderViewHostDelegate, + public RenderViewHostDelegate::BrowserIntegration, + public RenderViewHostDelegate::Resource, public RenderViewHostManager::Delegate, public SelectFileDialog::Listener { public: @@ -736,8 +738,53 @@ class TabContents : public PageNavigator, // RenderViewHostDelegate ---------------------------------------------------- + // RenderViewHostDelegate::BrowserIntegration implementation. + virtual void OnUserGesture(); + virtual void OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update); + virtual void GoToEntryAtOffset(int offset); + virtual void GetHistoryListCount(int* back_list_count, + int* forward_list_count); + virtual void OnMissingPluginStatus(int status); + virtual void OnCrashedPlugin(const FilePath& plugin_path); + virtual void OnCrashedWorker(); + virtual void OnDidGetApplicationInfo( + int32 page_id, + const webkit_glue::WebApplicationInfo& info); + + // RenderViewHostDelegate::Resource implementation. + virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host, + bool is_main_frame, + const GURL& url); + virtual void DidStartReceivingResourceResponse( + ResourceRequestDetails* details); + virtual void DidRedirectProvisionalLoad(int32 page_id, + const GURL& source_url, + const GURL& target_url); + virtual void DidRedirectResource(ResourceRequestDetails* details); + virtual void DidLoadResourceFromMemoryCache( + const GURL& url, + const std::string& frame_origin, + const std::string& main_frame_origin, + const std::string& security_info); + virtual void DidFailProvisionalLoadWithError( + RenderViewHost* render_view_host, + bool is_main_frame, + int error_code, + const GURL& url, + bool showing_repost_interstitial); + virtual void DocumentLoadedInFrame(); + + // RenderViewHostDelegate implementation. virtual RenderViewHostDelegate::View* GetViewDelegate() const; + virtual RenderViewHostDelegate::BrowserIntegration* + GetBrowserIntegrationDelegate() const; + virtual RenderViewHostDelegate::Resource* GetResourceDelegate() const; virtual RenderViewHostDelegate::Save* GetSaveDelegate() const; + virtual RenderViewHostDelegate::FavIcon* GetFavIconDelegate() const; virtual TabContents* GetAsTabContents(); virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewReady(RenderViewHost* render_view_host); @@ -761,33 +808,6 @@ class TabContents : public PageNavigator, virtual void RequestMove(const gfx::Rect& new_bounds); virtual void DidStartLoading(RenderViewHost* render_view_host); virtual void DidStopLoading(RenderViewHost* render_view_host); - virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host, - bool is_main_frame, - const GURL& url); - virtual void DidStartReceivingResourceResponse( - ResourceRequestDetails* details); - virtual void DidRedirectProvisionalLoad(int32 page_id, - const GURL& source_url, - const GURL& target_url); - virtual void DidRedirectResource(ResourceRequestDetails* details); - virtual void DidLoadResourceFromMemoryCache( - const GURL& url, - const std::string& frame_origin, - const std::string& main_frame_origin, - const std::string& security_info); - virtual void DidFailProvisionalLoadWithError( - RenderViewHost* render_view_host, - bool is_main_frame, - int error_code, - const GURL& url, - bool showing_repost_interstitial); - virtual void UpdateFavIconURL(RenderViewHost* render_view_host, - int32 page_id, const GURL& icon_url); - virtual void DidDownloadImage(RenderViewHost* render_view_host, - int id, - const GURL& image_url, - bool errored, - const SkBitmap& image); virtual void RequestOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition); virtual void DomOperationResponse(const std::string& json_string, @@ -796,13 +816,9 @@ class TabContents : public PageNavigator, const std::string& content, int request_id, bool has_callback); - virtual void DocumentLoadedInFrame(); virtual void ProcessExternalHostMessage(const std::string& message, const std::string& origin, const std::string& target); - virtual void GoToEntryAtOffset(int offset); - virtual void GetHistoryListCount(int* back_list_count, - int* forward_list_count); virtual void RunFileChooser(bool multiple_files, const string16& title, const FilePath& default_file); @@ -831,9 +847,6 @@ class TabContents : public PageNavigator, virtual GURL GetAlternateErrorPageURL() const; virtual RendererPreferences GetRendererPrefs() const; virtual WebPreferences GetWebkitPrefs(); - virtual void OnMissingPluginStatus(int status); - virtual void OnCrashedPlugin(const FilePath& plugin_path); - virtual void OnCrashedWorker(); virtual void OnJSOutOfMemory(); virtual void ShouldClosePage(bool proceed); virtual void OnCrossSiteResponse(int new_render_process_host_id, @@ -845,16 +858,7 @@ class TabContents : public PageNavigator, bool is_during_unload); virtual void RendererResponsive(RenderViewHost* render_view_host); virtual void LoadStateChanged(const GURL& url, net::LoadState load_state); - virtual void OnDidGetApplicationInfo( - int32 page_id, - const webkit_glue::WebApplicationInfo& info); - virtual void OnUserGesture(); virtual bool IsExternalTabContainer() const; - virtual void OnFindReply(int request_id, - int number_of_matches, - const gfx::Rect& selection_rect, - int active_match_ordinal, - bool final_update); virtual void DidInsertCSS(); // SelectFileDialog::Listener ------------------------------------------------ diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc index ecf8a3d..9672dd1 100644 --- a/chrome/browser/worker_host/worker_process_host.cc +++ b/chrome/browser/worker_host/worker_process_host.cc @@ -36,8 +36,12 @@ class WorkerCrashTask : public Task { void Run() { RenderViewHost* host = RenderViewHost::FromID(render_process_id_, render_view_id_); - if (host) - host->delegate()->OnCrashedWorker(); + if (host) { + RenderViewHostDelegate::BrowserIntegration* integration_delegate = + host->delegate()->GetBrowserIntegrationDelegate(); + if (integration_delegate) + integration_delegate->OnCrashedWorker(); + } } private: |