diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-05 17:01:18 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-05 17:01:18 +0000 |
commit | 553602e16e938000f103cc7d58e4aac3247508d7 (patch) | |
tree | e35c5fcb46d36b4baf3b4a18a86171001df6c55a /content/browser | |
parent | a6721299849fff3b25e7b2a0e6f16aa0df7a9b11 (diff) | |
download | chromium_src-553602e16e938000f103cc7d58e4aac3247508d7.zip chromium_src-553602e16e938000f103cc7d58e4aac3247508d7.tar.gz chromium_src-553602e16e938000f103cc7d58e4aac3247508d7.tar.bz2 |
Move dispatching and sending of the last extension specific messages out of TabContents and RenderView.I added a TabContents::Registrar helper class for allowing classing to temporarily observe a TabContents. This allows them to easily and safetly filter IPC messages. I used this for ExecuteCodeInTabFunction.
Review URL: http://codereview.chromium.org/6794035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r-- | content/browser/renderer_host/render_view_host.cc | 41 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host.h | 18 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.cc | 37 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.h | 33 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_delegate.cc | 10 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_delegate.h | 9 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_observer.cc | 33 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_observer.h | 36 |
8 files changed, 79 insertions, 138 deletions
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index c0c6fad..3e6ef59 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -29,7 +29,6 @@ #include "chrome/common/spellcheck_messages.h" #include "chrome/common/translate_errors.h" #include "chrome/common/url_constants.h" -#include "chrome/common/web_apps.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/cross_site_request_manager.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" @@ -561,10 +560,6 @@ int RenderViewHost::DownloadFavicon(const GURL& url, int image_size) { return id; } -void RenderViewHost::GetApplicationInfo(int32 page_id) { - Send(new ExtensionMsg_GetApplicationInfo(routing_id(), page_id)); -} - void RenderViewHost::CaptureSnapshot() { Send(new ViewMsg_CaptureSnapshot(routing_id())); } @@ -748,8 +743,6 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { OnMsgDocumentAvailableInMainFrame) IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentOnLoadCompletedInMainFrame, OnMsgDocumentOnLoadCompletedInMainFrame) - IPC_MESSAGE_HANDLER(ViewHostMsg_ExecuteCodeFinished, - OnExecuteCodeFinished) IPC_MESSAGE_HANDLER(ViewHostMsg_ContextMenu, OnMsgContextMenu) IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnMsgOpenURL) IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, @@ -769,7 +762,6 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole) IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK) - IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnExtensionRequest) IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged) IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityNotifications, OnAccessibilityNotifications) @@ -1031,14 +1023,6 @@ void RenderViewHost::OnMsgDocumentOnLoadCompletedInMainFrame(int32 page_id) { delegate_->DocumentOnLoadCompletedInMainFrame(this, page_id); } -void RenderViewHost::OnExecuteCodeFinished(int request_id, bool success) { - std::pair<int, bool> result_details(request_id, success); - NotificationService::current()->Notify( - NotificationType::TAB_CODE_EXECUTED, - NotificationService::AllSources(), - Details<std::pair<int, bool> >(&result_details)); -} - void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); if (!view) @@ -1389,31 +1373,6 @@ void RenderViewHost::ForwardMessageFromExternalHost(const std::string& message, target)); } -void RenderViewHost::OnExtensionRequest( - const ExtensionHostMsg_DomMessage_Params& params) { - if (!ChildProcessSecurityPolicy::GetInstance()-> - HasExtensionBindings(process()->id())) { - // This can happen if someone uses window.open() to open an extension URL - // from a non-extension context. - BlockExtensionRequest(params.request_id); - return; - } - - delegate_->ProcessWebUIMessage(params); -} - -void RenderViewHost::SendExtensionResponse(int request_id, bool success, - const std::string& response, - const std::string& error) { - Send(new ExtensionMsg_Response( - routing_id(), request_id, success, response, error)); -} - -void RenderViewHost::BlockExtensionRequest(int request_id) { - SendExtensionResponse(request_id, false, "", - "Access to extension API denied."); -} - void RenderViewHost::UpdateBrowserWindowId(int window_id) { Send(new ViewMsg_UpdateBrowserWindowId(routing_id(), window_id)); } diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h index ff675a0..0304ec9 100644 --- a/content/browser/renderer_host/render_view_host.h +++ b/content/browser/renderer_host/render_view_host.h @@ -38,13 +38,11 @@ class SkBitmap; class ViewMsg_Navigate; struct ContentSettings; struct ContextMenuParams; -struct ExtensionHostMsg_DomMessage_Params; struct MediaPlayerAction; struct ViewHostMsg_AccessibilityNotification_Params; struct ViewHostMsg_CreateWindow_Params; struct ViewHostMsg_ShowPopup_Params; struct ViewMsg_Navigate_Params; -struct WebApplicationInfo; struct WebDropData; struct WebPreferences; struct UserMetricsAction; @@ -289,11 +287,6 @@ class RenderViewHost : public RenderWidgetHost { // 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 - // the data is available. - void GetApplicationInfo(int32 page_id); - // Captures a snapshot of the page. void CaptureSnapshot(); @@ -441,15 +434,6 @@ class RenderViewHost : public RenderWidgetHost { // Creates a full screen RenderWidget. void CreateNewFullscreenWidget(int route_id); - // Sends the response to an extension api call. - void SendExtensionResponse(int request_id, bool success, - const std::string& response, - const std::string& error); - - // Sends a response to an extension api call that it was blocked for lack of - // permission. - void BlockExtensionRequest(int request_id); - // Tells the renderer which browser window it is being attached to. void UpdateBrowserWindowId(int window_id); @@ -550,7 +534,6 @@ class RenderViewHost : public RenderWidgetHost { void OnMsgDidChangeLoadProgress(double load_progress); void OnMsgDocumentAvailableInMainFrame(); void OnMsgDocumentOnLoadCompletedInMainFrame(int32 page_id); - void OnExecuteCodeFinished(int request_id, bool success); void OnMsgUpdateFaviconURL(int32 page_id, const GURL& icon_url); void OnMsgDidDownloadFavicon(int id, const GURL& image_url, @@ -593,7 +576,6 @@ class RenderViewHost : public RenderWidgetHost { const std::string& value); void OnMsgShouldCloseACK(bool proceed); - void OnExtensionRequest(const ExtensionHostMsg_DomMessage_Params& params); void OnAccessibilityNotifications( const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params); void OnCSSInserted(); diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 7f152f5..d1866ab 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -416,10 +416,6 @@ bool TabContents::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature, OnPDFHasUnsupportedFeature) IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) - IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo, - OnDidGetApplicationInfo) - IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication, - OnInstallApplication) IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated) IPC_MESSAGE_UNHANDLED(handled = false) @@ -846,22 +842,6 @@ void TabContents::AddNewContents(TabContents* new_contents, PopupNotificationVisibilityChanged(blocked_contents_ != NULL); } -bool TabContents::ExecuteCode(int request_id, const std::string& extension_id, - bool is_js_code, const std::string& code_string, - bool all_frames) { - RenderViewHost* host = render_view_host(); - if (!host) - return false; - - ExtensionMsg_ExecuteCode_Params params; - params.request_id = request_id; - params.extension_id = extension_id; - params.is_javascript = is_js_code; - params.code = code_string; - params.all_frames = all_frames; - return host->Send(new ExtensionMsg_ExecuteCode(host->routing_id(), params)); -} - void TabContents::PopupNotificationVisibilityChanged(bool visible) { if (is_being_destroyed_) return; @@ -1794,19 +1774,6 @@ void TabContents::OnGoToEntryAtOffset(int offset) { } } -void TabContents::OnDidGetApplicationInfo(int32 page_id, - const WebApplicationInfo& info) { - web_app_info_ = info; - - if (delegate()) - delegate()->OnDidGetApplicationInfo(this, page_id); -} - -void TabContents::OnInstallApplication(const WebApplicationInfo& info) { - if (delegate()) - delegate()->OnInstallApplication(this, info); -} - void TabContents::OnPageContents(const GURL& url, int32 page_id, const string16& contents, @@ -2250,7 +2217,9 @@ void TabContents::ProcessWebUIMessage( if (!render_manager_.web_ui()) { // This can happen if someone uses window.open() to open an extension URL // from a non-extension context. - render_view_host()->BlockExtensionRequest(params.request_id); + render_view_host()->Send(new ExtensionMsg_Response( + render_view_host()->routing_id(), params.request_id, false, "", + "Access to extension API denied.")); return; } render_manager_.web_ui()->ProcessWebUIMessage(params); diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 9aeaf33..356d2b5 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -30,6 +30,7 @@ #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/page_navigator.h" #include "content/browser/tab_contents/render_view_host_manager.h" +#include "content/browser/tab_contents/tab_contents_observer.h" #include "content/browser/webui/web_ui.h" #include "content/common/notification_registrar.h" #include "content/common/property_bag.h" @@ -217,13 +218,6 @@ class TabContents : public PageNavigator, // space is provided for the favicon, and the favicon is never displayed. virtual bool ShouldDisplayFavicon(); - // Add and remove observers for page navigation notifications. Adding or - // removing multiple times has no effect. The order in which notifications - // are sent to observers is undefined. Clients must be sure to remove the - // observer before they go away. - void AddObserver(TabContentsObserver* observer); - void RemoveObserver(TabContentsObserver* observer); - // Return whether this tab contents is loading a resource. bool is_loading() const { return is_loading_; } @@ -243,10 +237,6 @@ class TabContents : public PageNavigator, encoding_.clear(); } - const WebApplicationInfo& web_app_info() const { - return web_app_info_; - } - const SkBitmap& app_icon() const { return app_icon_; } // Sets an app icon associated with TabContents and fires an INVALIDATE_TITLE @@ -376,12 +366,6 @@ class TabContents : public PageNavigator, const gfx::Rect& initial_pos, bool user_gesture); - // Execute code in this tab. Returns true if the message was successfully - // sent. - bool ExecuteCode(int request_id, const std::string& extension_id, - bool is_js_code, const std::string& code_string, - bool all_frames); - // Called when the blocked popup notification is shown or hidden. virtual void PopupNotificationVisibilityChanged(bool visible); @@ -660,6 +644,16 @@ class TabContents : public PageNavigator, WebUI::TypeID GetWebUITypeForCurrentState(); protected: + friend class TabContentsObserver; + friend class TabContentsObserver::Registrar; + + // Add and remove observers for page navigation notifications. Adding or + // removing multiple times has no effect. The order in which notifications + // are sent to observers is undefined. Clients must be sure to remove the + // observer before they go away. + void AddObserver(TabContentsObserver* observer); + void RemoveObserver(TabContentsObserver* observer); + // from RenderViewHostDelegate. virtual bool OnMessageReceived(const IPC::Message& message); @@ -725,8 +719,6 @@ class TabContents : public PageNavigator, void OnPDFHasUnsupportedFeature(); void OnGoToEntryAtOffset(int offset); - void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); - void OnInstallApplication(const WebApplicationInfo& info); void OnPageContents(const GURL& url, int32 page_id, const string16& contents, @@ -992,9 +984,6 @@ class TabContents : public PageNavigator, // Handles downloading favicons. scoped_ptr<FaviconHelper> favicon_helper_; - // Cached web app info data. - WebApplicationInfo web_app_info_; - // Cached web app icon. SkBitmap app_icon_; diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index 93b572b..5456009 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -189,16 +189,6 @@ bool TabContentsDelegate::ShouldAddNavigationToHistory( return true; } -void TabContentsDelegate::OnDidGetApplicationInfo(TabContents* tab_contents, - int32 page_id) { -} - -// Notification when an application programmatically requests installation. -void TabContentsDelegate::OnInstallApplication( - TabContents* tab_contents, - const WebApplicationInfo& app_info) { -} - gfx::NativeWindow TabContentsDelegate::GetFrameNativeWindow() { return NULL; } diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h index a709a93..d47aac7 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -36,7 +36,6 @@ struct NativeWebKeyboardEvent; class Profile; class RenderViewHost; class TabContents; -struct WebApplicationInfo; // Objects implement this interface to get notified about changes in the // TabContents and to provide necessary functionality. @@ -284,14 +283,6 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { const history::HistoryAddPageArgs& add_page_args, NavigationType::Type navigation_type); - // Notification that a user's request to install an application has completed. - virtual void OnDidGetApplicationInfo(TabContents* tab_contents, - int32 page_id); - - // Notification when an application programmatically requests installation. - virtual void OnInstallApplication(TabContents* tab_contents, - const WebApplicationInfo& app_info); - // Returns the native window framing the view containing the tab contents. virtual gfx::NativeWindow GetFrameNativeWindow(); diff --git a/content/browser/tab_contents/tab_contents_observer.cc b/content/browser/tab_contents/tab_contents_observer.cc index 1a5c3c3..d2eae1c 100644 --- a/content/browser/tab_contents/tab_contents_observer.cc +++ b/content/browser/tab_contents/tab_contents_observer.cc @@ -7,6 +7,24 @@ #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +TabContentsObserver::Registrar::Registrar(TabContentsObserver* observer) + : observer_(observer), tab_(NULL) { +} + +TabContentsObserver::Registrar::~Registrar() { + if (tab_) + tab_->RemoveObserver(observer_); +} + +void TabContentsObserver::Registrar::Observe(TabContents* tab) { + observer_->SetTabContents(tab); + if (tab_) + tab_->RemoveObserver(observer_); + tab_ = tab; + if (tab_) + tab_->AddObserver(observer_); +} + void TabContentsObserver::NavigateToPendingEntry() { } @@ -35,12 +53,15 @@ void TabContentsObserver::RenderViewGone() { void TabContentsObserver::StopNavigation() { } -TabContentsObserver::TabContentsObserver(TabContents* tab_contents) - : tab_contents_(tab_contents), - routing_id_(tab_contents->render_view_host()->routing_id()) { +TabContentsObserver::TabContentsObserver(TabContents* tab_contents) { + SetTabContents(tab_contents); tab_contents_->AddObserver(this); } +TabContentsObserver::TabContentsObserver() + : tab_contents_(NULL), routing_id_(MSG_ROUTING_NONE) { +} + TabContentsObserver::~TabContentsObserver() { if (tab_contents_) tab_contents_->RemoveObserver(this); @@ -62,6 +83,12 @@ bool TabContentsObserver::Send(IPC::Message* message) { return tab_contents_->render_view_host()->Send(message); } +void TabContentsObserver::SetTabContents(TabContents* tab_contents) { + tab_contents_ = tab_contents; + if (tab_contents_) + routing_id_ = tab_contents->render_view_host()->routing_id(); +} + void TabContentsObserver::TabContentsDestroyed() { // Do cleanup so that 'this' can safely be deleted from // OnTabContentsDestroyed. diff --git a/content/browser/tab_contents/tab_contents_observer.h b/content/browser/tab_contents/tab_contents_observer.h index 899fcf7..69d371a 100644 --- a/content/browser/tab_contents/tab_contents_observer.h +++ b/content/browser/tab_contents/tab_contents_observer.h @@ -12,8 +12,29 @@ struct ViewHostMsg_FrameNavigate_Params; // An observer API implemented by classes which are interested in various page // load events from TabContents. They also get a chance to filter IPC messages. -class TabContentsObserver : public IPC::Channel::Listener { +class TabContentsObserver : public IPC::Channel::Listener, + public IPC::Message::Sender { public: + // Use this as a member variable in a class that uses the emptry constructor + // version of this interface. + class Registrar { + public: + explicit Registrar(TabContentsObserver* observer); + ~Registrar(); + + // Call this to start observing a tab. Passing in NULL resets it. + // This can only be used to watch one tab at a time. If you call this and + // you're already observing another tab, the old tab won't be observed + // afterwards. + void Observe(TabContents* tab); + + private: + TabContentsObserver* observer_; + TabContents* tab_; + + DISALLOW_COPY_AND_ASSIGN(Registrar); + }; + virtual void NavigateToPendingEntry(); virtual void DidNavigateMainFramePostCommit( @@ -45,7 +66,15 @@ class TabContentsObserver : public IPC::Channel::Listener { #endif protected: + // Use this constructor when the object is tied to a single TabContents for + // its entire lifetime. explicit TabContentsObserver(TabContents* tab_contents); + + // Use this constructor when the object wants to observe a TabContents for + // part of its lifetime. It can use a TabContentsRegistrar member variable + // to start and stop observing. + TabContentsObserver(); + virtual ~TabContentsObserver(); // Invoked when the TabContents is being destroyed. Gives subclasses a chance @@ -62,6 +91,11 @@ class TabContentsObserver : public IPC::Channel::Listener { TabContents* tab_contents() const { return tab_contents_; } int routing_id() const { return routing_id_; } + protected: + friend class Registrar; + + void SetTabContents(TabContents* tab_contents); + private: friend class TabContents; |