diff options
Diffstat (limited to 'content/browser')
-rw-r--r-- | content/browser/renderer_host/DEPS | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/browser_render_process_host.h | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.cc | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host.cc | 36 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host.h | 3 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host_delegate.h | 6 | ||||
-rw-r--r-- | content/browser/tab_contents/background_contents.h | 1 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.cc | 17 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.h | 3 | ||||
-rw-r--r-- | content/browser/webui/web_ui.cc | 30 | ||||
-rw-r--r-- | content/browser/webui/web_ui.h | 15 |
11 files changed, 39 insertions, 75 deletions
diff --git a/content/browser/renderer_host/DEPS b/content/browser/renderer_host/DEPS index d8e9a30..b12c3bd 100644 --- a/content/browser/renderer_host/DEPS +++ b/content/browser/renderer_host/DEPS @@ -1,4 +1,5 @@ include_rules = [ "+content/renderer", # For single-process mode. "+third_party/zlib", + "+chrome/common/extensions" ] diff --git a/content/browser/renderer_host/browser_render_process_host.h b/content/browser/renderer_host/browser_render_process_host.h index 37be1f1..822da69 100644 --- a/content/browser/renderer_host/browser_render_process_host.h +++ b/content/browser/renderer_host/browser_render_process_host.h @@ -15,7 +15,6 @@ #include "base/platform_file.h" #include "base/process.h" #include "base/timer.h" -#include "chrome/common/extensions/extension.h" #include "content/browser/child_process_launcher.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/common/notification_observer.h" diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index ad28245..945dcfc 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -25,6 +25,7 @@ #include "chrome/browser/platform_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/extensions/extension.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_thread.h" diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index 0b7a4a4..b6fd42f 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -21,7 +21,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/icon_messages.h" #include "chrome/common/render_messages.h" #include "chrome/common/translate_errors.h" @@ -763,7 +762,6 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { OnMsgDidContentsPreferredSizeChange) IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse, OnMsgDomOperationResponse) - IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnMsgWebUISend) IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardMessageToExternalHost, OnMsgForwardMessageToExternalHost) IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText) @@ -1088,40 +1086,6 @@ void RenderViewHost::OnMsgDomOperationResponse( Details<DomOperationNotificationDetails>(&details)); } -void RenderViewHost::OnMsgWebUISend( - const GURL& source_url, const std::string& message, - const std::string& content) { - if (!ChildProcessSecurityPolicy::GetInstance()-> - HasWebUIBindings(process()->id())) { - NOTREACHED() << "Blocked unauthorized use of WebUIBindings."; - return; - } - - scoped_ptr<Value> value; - if (!content.empty()) { - value.reset(base::JSONReader::Read(content, false)); - if (!value.get() || !value->IsType(Value::TYPE_LIST)) { - // The page sent us something that we didn't understand. - // This probably indicates a programming error. - NOTREACHED() << "Invalid JSON argument in OnMsgWebUISend."; - return; - } - } - - ExtensionHostMsg_DomMessage_Params params; - params.name = message; - if (value.get()) - params.arguments.Swap(static_cast<ListValue*>(value.get())); - params.source_url = source_url; - // WebUI doesn't use these values yet. - // TODO(aa): When WebUI is ported to ExtensionFunctionDispatcher, send real - // values here. - params.request_id = -1; - params.has_callback = false; - params.user_gesture = false; - delegate_->ProcessWebUIMessage(params); -} - void RenderViewHost::OnMsgForwardMessageToExternalHost( const std::string& message, const std::string& origin, const std::string& target) { diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h index c9e7027..281bfeb 100644 --- a/content/browser/renderer_host/render_view_host.h +++ b/content/browser/renderer_host/render_view_host.h @@ -544,9 +544,6 @@ class RenderViewHost : public RenderWidgetHost { void OnMsgDidContentsPreferredSizeChange(const gfx::Size& new_size); void OnMsgDomOperationResponse(const std::string& json_string, int automation_id); - void OnMsgWebUISend(const GURL& source_url, - const std::string& message, - const std::string& content); void OnMsgForwardMessageToExternalHost(const std::string& message, const std::string& origin, const std::string& target); diff --git a/content/browser/renderer_host/render_view_host_delegate.h b/content/browser/renderer_host/render_view_host_delegate.h index f4f0783..f95a76d 100644 --- a/content/browser/renderer_host/render_view_host_delegate.h +++ b/content/browser/renderer_host/render_view_host_delegate.h @@ -45,7 +45,6 @@ class SkBitmap; class SSLClientAuthHandler; class SSLAddCertHandler; class TabContents; -struct ExtensionHostMsg_DomMessage_Params; struct ViewHostMsg_CreateWindow_Params; struct ViewHostMsg_FrameNavigate_Params; struct WebApplicationInfo; @@ -489,11 +488,6 @@ class RenderViewHostDelegate : public IPC::Channel::Listener { virtual void DomOperationResponse(const std::string& json_string, int automation_id) {} - // A message was sent from HTML-based UI. - // By default we ignore such messages. - virtual void ProcessWebUIMessage( - const ExtensionHostMsg_DomMessage_Params& params) {} - // A message for external host. By default we ignore such messages. // |receiver| can be a receiving script and |message| is any // arbitrary string that makes sense to the receiver. diff --git a/content/browser/tab_contents/background_contents.h b/content/browser/tab_contents/background_contents.h index e544fde..ef03cd4 100644 --- a/content/browser/tab_contents/background_contents.h +++ b/content/browser/tab_contents/background_contents.h @@ -67,7 +67,6 @@ class BackgroundContents : public RenderViewHostDelegate, virtual void DidNavigate(RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params); virtual WebPreferences GetWebkitPrefs(); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); virtual void RunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, const GURL& frame_url, diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 6c72691..2a0a0d5 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -52,7 +52,6 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/content_restriction.h" -#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/icon_messages.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -366,6 +365,9 @@ void TabContents::AddObservers() { } bool TabContents::OnMessageReceived(const IPC::Message& message) { + if (web_ui() && web_ui()->OnMessageReceived(message)) + return true; + ObserverListBase<TabContentsObserver>::Iterator it(observers_); TabContentsObserver* observer; while ((observer = it.GetNext()) != NULL) @@ -2007,19 +2009,6 @@ void TabContents::DomOperationResponse(const std::string& json_string, int automation_id) { } -void TabContents::ProcessWebUIMessage( - const ExtensionHostMsg_DomMessage_Params& params) { - 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()->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); -} - void TabContents::ProcessExternalHostMessage(const std::string& message, const std::string& origin, const std::string& target) { diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 17992dc..f690393 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -73,7 +73,6 @@ class TabContentsObserver; class TabContentsSSLHelper; class TabContentsView; class URLPattern; -struct ExtensionHostMsg_DomMessage_Params; struct RendererPreferences; struct ThumbnailScore; struct ViewHostMsg_FrameNavigate_Params; @@ -807,8 +806,6 @@ class TabContents : public PageNavigator, WindowOpenDisposition disposition); virtual void DomOperationResponse(const std::string& json_string, int automation_id); - virtual void ProcessWebUIMessage( - const ExtensionHostMsg_DomMessage_Params& params); virtual void ProcessExternalHostMessage(const std::string& message, const std::string& origin, const std::string& target); diff --git a/content/browser/webui/web_ui.cc b/content/browser/webui/web_ui.cc index 636f9e8..995a229 100644 --- a/content/browser/webui/web_ui.cc +++ b/content/browser/webui/web_ui.cc @@ -10,13 +10,17 @@ #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/render_messages.h" +#include "content/browser/child_process_security_policy.h" +#include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" #include "content/browser/webui/generic_handler.h" #include "content/common/bindings_policy.h" +#include "content/common/view_messages.h" +#include "ipc/ipc_message.h" +#include "ipc/ipc_message_macros.h" namespace { @@ -60,16 +64,32 @@ WebUI::~WebUI() { const WebUI::TypeID WebUI::kNoWebUI = NULL; -void WebUI::ProcessWebUIMessage( - const ExtensionHostMsg_DomMessage_Params& params) { +bool WebUI::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(WebUI, message) + IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void WebUI::OnWebUISend(const GURL& source_url, + const std::string& message, + const ListValue& args) { + if (!ChildProcessSecurityPolicy::GetInstance()-> + HasWebUIBindings(tab_contents_->GetRenderProcessHost()->id())) { + NOTREACHED() << "Blocked unauthorized use of WebUIBindings."; + return; + } + // Look up the callback for this message. MessageCallbackMap::const_iterator callback = - message_callbacks_.find(params.name); + message_callbacks_.find(message); if (callback == message_callbacks_.end()) return; // Forward this message and content on. - callback->second->Run(¶ms.arguments); + callback->second->Run(&args); } void WebUI::CallJavascriptFunction(const std::string& function_name) { diff --git a/content/browser/webui/web_ui.h b/content/browser/webui/web_ui.h index 402d2fd..e44f1bd 100644 --- a/content/browser/webui/web_ui.h +++ b/content/browser/webui/web_ui.h @@ -11,8 +11,10 @@ #include <vector> #include "base/callback.h" +#include "base/compiler_specific.h" #include "base/string16.h" #include "content/common/page_transition_types.h" +#include "ipc/ipc_channel.h" class DictionaryValue; class WebUIMessageHandler; @@ -22,15 +24,20 @@ class Profile; class RenderViewHost; class TabContents; class Value; -struct ExtensionHostMsg_DomMessage_Params; // A WebUI sets up the datasources and message handlers for a given HTML-based // UI. It is contained by a WebUIManager. -class WebUI { +class WebUI : public IPC::Channel::Listener { public: explicit WebUI(TabContents* contents); virtual ~WebUI(); + // IPC message handling. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + virtual void OnWebUISend(const GURL& source_url, + const std::string& message, + const ListValue& args); + // Called by RenderViewHost when the RenderView is first created. This is // *not* called for every page load because in some cases // RenderViewHostManager will reuse RenderView instances. In those cases, @@ -52,10 +59,6 @@ class WebUI { // won't be run in that case. virtual void DidBecomeActiveForReusedRenderView() {} - // Called from TabContents. - virtual void ProcessWebUIMessage( - const ExtensionHostMsg_DomMessage_Params& params); - // Used by WebUIMessageHandlers. typedef Callback1<const ListValue*>::Type MessageCallback; void RegisterMessageCallback(const std::string& message, |