summaryrefslogtreecommitdiffstats
path: root/content/browser/webui
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 16:37:58 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 16:37:58 +0000
commitef9df9238ae4c6255d103865649573f480d2fec9 (patch)
treef9ca1fb19dee6dbc153de1a04a7c4b59744e7981 /content/browser/webui
parent5d5513afd7ecb03270839c375117aef7d65301c5 (diff)
downloadchromium_src-ef9df9238ae4c6255d103865649573f480d2fec9.zip
chromium_src-ef9df9238ae4c6255d103865649573f480d2fec9.tar.gz
chromium_src-ef9df9238ae4c6255d103865649573f480d2fec9.tar.bz2
Revert "Revert 83100 - Remove weird dependency on extensions from webui.Re-plumb extension request messages in a more sane way.Before, each RVH had ProcessWebUIMessage(), which wasserving as a manual way of plumbing both WebUI andextension messages to the right place, even though onlya few RVHD responded to either message.Instead of this, we now just teach more of the stack howto handle IPC messages in general, and delegate them upthrough the stack, giving each layer a chance to handlethem if it knows how.The result is simpler and smaller:179 insertions(+), 252 deletions(-)BUG=80311Review URL: http://codereview.chromium.org/6901021"
This reverts commit 643b280cedd9f0b76948686f39f50f295aba362f. TBR=mpcomplete@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/webui')
-rw-r--r--content/browser/webui/web_ui.cc29
-rw-r--r--content/browser/webui/web_ui.h15
2 files changed, 34 insertions, 10 deletions
diff --git a/content/browser/webui/web_ui.cc b/content/browser/webui/web_ui.cc
index 636f9e8..87a14204 100644
--- a/content/browser/webui/web_ui.cc
+++ b/content/browser/webui/web_ui.cc
@@ -12,11 +12,16 @@
#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 +65,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(&params.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,