summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 23:51:09 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 23:51:09 +0000
commit39755c360cd4c5884f590aa0548cdd72d30dbdb0 (patch)
treebf599e2be3b4b226f7be5ca4a3327d22e4561f2b /content
parent84ec056834c1625b7b7d316817b018564f76e22a (diff)
downloadchromium_src-39755c360cd4c5884f590aa0548cdd72d30dbdb0.zip
chromium_src-39755c360cd4c5884f590aa0548cdd72d30dbdb0.tar.gz
chromium_src-39755c360cd4c5884f590aa0548cdd72d30dbdb0.tar.bz2
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
TBR=aa@chromium.org Review URL: http://codereview.chromium.org/6905045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/DEPS4
-rw-r--r--content/browser/renderer_host/render_view_host.cc36
-rw-r--r--content/browser/renderer_host/render_view_host.h3
-rw-r--r--content/browser/renderer_host/render_view_host_delegate.h6
-rw-r--r--content/browser/tab_contents/background_contents.h1
-rw-r--r--content/browser/tab_contents/tab_contents.cc16
-rw-r--r--content/browser/tab_contents/tab_contents.h3
-rw-r--r--content/browser/webui/web_ui.cc29
-rw-r--r--content/browser/webui/web_ui.h15
-rw-r--r--content/common/view_messages.h2
-rw-r--r--content/renderer/web_ui_bindings.cc19
11 files changed, 80 insertions, 54 deletions
diff --git a/content/DEPS b/content/DEPS
index 991fd7d3..bf29db6 100644
--- a/content/DEPS
+++ b/content/DEPS
@@ -8,13 +8,9 @@ include_rules = [
# When the src\content refactoring is complete, this will be unnecessary (and
# in fact, a layering violation).
"+chrome",
-
# The following directories have been refactored, so no new dependencies
# should be added from these directories.
"-chrome/browser/printing",
- "-chrome/browser/extensions",
- "-chrome/common/extensions",
- "-chrome/renderer/extensions",
# The subdirectories in content/ will manually allow their own include
# directories in content/ so we disallow all of them.
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index b6fd42f..0b7a4a4 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -21,6 +21,7 @@
#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"
@@ -762,6 +763,7 @@ 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)
@@ -1086,6 +1088,40 @@ 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 281bfeb..c9e7027 100644
--- a/content/browser/renderer_host/render_view_host.h
+++ b/content/browser/renderer_host/render_view_host.h
@@ -544,6 +544,9 @@ 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 f95a76d..f4f0783 100644
--- a/content/browser/renderer_host/render_view_host_delegate.h
+++ b/content/browser/renderer_host/render_view_host_delegate.h
@@ -45,6 +45,7 @@ class SkBitmap;
class SSLClientAuthHandler;
class SSLAddCertHandler;
class TabContents;
+struct ExtensionHostMsg_DomMessage_Params;
struct ViewHostMsg_CreateWindow_Params;
struct ViewHostMsg_FrameNavigate_Params;
struct WebApplicationInfo;
@@ -488,6 +489,11 @@ 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 ef03cd4..e544fde 100644
--- a/content/browser/tab_contents/background_contents.h
+++ b/content/browser/tab_contents/background_contents.h
@@ -67,6 +67,7 @@ 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 e84ca34..7c113a3 100644
--- a/content/browser/tab_contents/tab_contents.cc
+++ b/content/browser/tab_contents/tab_contents.cc
@@ -375,9 +375,6 @@ 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)
@@ -2019,6 +2016,19 @@ 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 f690393..17992dc 100644
--- a/content/browser/tab_contents/tab_contents.h
+++ b/content/browser/tab_contents/tab_contents.h
@@ -73,6 +73,7 @@ class TabContentsObserver;
class TabContentsSSLHelper;
class TabContentsView;
class URLPattern;
+struct ExtensionHostMsg_DomMessage_Params;
struct RendererPreferences;
struct ThumbnailScore;
struct ViewHostMsg_FrameNavigate_Params;
@@ -806,6 +807,8 @@ 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 87a14204..636f9e8 100644
--- a/content/browser/webui/web_ui.cc
+++ b/content/browser/webui/web_ui.cc
@@ -12,16 +12,11 @@
#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 {
@@ -65,32 +60,16 @@ WebUI::~WebUI() {
const WebUI::TypeID WebUI::kNoWebUI = NULL;
-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;
- }
-
+void WebUI::ProcessWebUIMessage(
+ const ExtensionHostMsg_DomMessage_Params& params) {
// Look up the callback for this message.
MessageCallbackMap::const_iterator callback =
- message_callbacks_.find(message);
+ message_callbacks_.find(params.name);
if (callback == message_callbacks_.end())
return;
// Forward this message and content on.
- callback->second->Run(&args);
+ callback->second->Run(&params.arguments);
}
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 e44f1bd..402d2fd 100644
--- a/content/browser/webui/web_ui.h
+++ b/content/browser/webui/web_ui.h
@@ -11,10 +11,8 @@
#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;
@@ -24,20 +22,15 @@ 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 : public IPC::Channel::Listener {
+class WebUI {
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,
@@ -59,6 +52,10 @@ class WebUI : public IPC::Channel::Listener {
// 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,
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index a6d7997..4602f17 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -1619,7 +1619,7 @@ IPC_MESSAGE_ROUTED1(ViewHostMsg_DidContentsPreferredSizeChange,
IPC_MESSAGE_ROUTED3(ViewHostMsg_WebUISend,
GURL /* source_url */,
std::string /* message */,
- ListValue /* args */)
+ std::string /* args (as a JSON string) */)
// A renderer sends this to the browser process when it wants to
// create a ppapi plugin. The browser will create the plugin process if
diff --git a/content/renderer/web_ui_bindings.cc b/content/renderer/web_ui_bindings.cc
index 1c42dbb..868d17a 100644
--- a/content/renderer/web_ui_bindings.cc
+++ b/content/renderer/web_ui_bindings.cc
@@ -4,6 +4,7 @@
#include "content/renderer/web_ui_bindings.h"
+#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util-inl.h"
#include "base/values.h"
@@ -68,17 +69,14 @@ void WebUIBindings::send(const CppArgumentList& args, CppVariant* result) {
return;
const std::string message = args[0].ToString();
- // If they've provided an optional message parameter, convert that into a
- // Value to send to the browser process.
- scoped_ptr<Value> content;
+ // If they've provided an optional message parameter, convert that into JSON.
+ std::string content;
if (args.size() == 2) {
if (!args[1].isObject())
return;
- content.reset(CreateValueFromCppVariant(args[1]));
- CHECK(content->IsType(Value::TYPE_LIST));
- } else {
- content.reset(new ListValue());
+ scoped_ptr<Value> value(CreateValueFromCppVariant(args[1]));
+ base::JSONWriter::Write(value.get(), /* pretty_print= */ false, &content);
}
// Retrieve the source frame's url
@@ -88,11 +86,8 @@ void WebUIBindings::send(const CppArgumentList& args, CppVariant* result) {
source_url = webframe->url();
// Send the message up to the browser.
- sender()->Send(new ViewHostMsg_WebUISend(
- routing_id(),
- source_url,
- message,
- *(static_cast<ListValue*>(content.get()))));
+ sender()->Send(
+ new ViewHostMsg_WebUISend(routing_id(), source_url, message, content));
}
void DOMBoundBrowserObject::SetProperty(const std::string& name,