summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 19:13:17 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 19:13:17 +0000
commitf82d57b5aac005760209900be768192f66a38361 (patch)
treec6fd653cf6f6f6b7f6b19ce34ad3492e4758d42d /content
parentfa71e8aecde3d31a2a8e75df8034bdef6e237f35 (diff)
downloadchromium_src-f82d57b5aac005760209900be768192f66a38361.zip
chromium_src-f82d57b5aac005760209900be768192f66a38361.tar.gz
chromium_src-f82d57b5aac005760209900be768192f66a38361.tar.bz2
Revert "Revert 83168 - 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"
This reverts commit ba6603c3cc46f1b83219be906ab36f8f2b3372e2. TBR=mpcomplete@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83188 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/DEPS4
-rw-r--r--content/browser/renderer_host/DEPS1
-rw-r--r--content/browser/renderer_host/browser_render_process_host.h1
-rw-r--r--content/browser/renderer_host/render_message_filter.cc1
-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.cc17
-rw-r--r--content/browser/tab_contents/tab_contents.h3
-rw-r--r--content/browser/webui/web_ui.cc30
-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
14 files changed, 56 insertions, 83 deletions
diff --git a/content/DEPS b/content/DEPS
index bf29db6..991fd7d3 100644
--- a/content/DEPS
+++ b/content/DEPS
@@ -8,9 +8,13 @@ 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/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(&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,
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index 4602f17..a6d7997 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 */,
- std::string /* args (as a JSON string) */)
+ ListValue /* args */)
// 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 868d17a..1c42dbb 100644
--- a/content/renderer/web_ui_bindings.cc
+++ b/content/renderer/web_ui_bindings.cc
@@ -4,7 +4,6 @@
#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"
@@ -69,14 +68,17 @@ 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 JSON.
- std::string content;
+ // If they've provided an optional message parameter, convert that into a
+ // Value to send to the browser process.
+ scoped_ptr<Value> content;
if (args.size() == 2) {
if (!args[1].isObject())
return;
- scoped_ptr<Value> value(CreateValueFromCppVariant(args[1]));
- base::JSONWriter::Write(value.get(), /* pretty_print= */ false, &content);
+ content.reset(CreateValueFromCppVariant(args[1]));
+ CHECK(content->IsType(Value::TYPE_LIST));
+ } else {
+ content.reset(new ListValue());
}
// Retrieve the source frame's url
@@ -86,8 +88,11 @@ 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, content));
+ sender()->Send(new ViewHostMsg_WebUISend(
+ routing_id(),
+ source_url,
+ message,
+ *(static_cast<ListValue*>(content.get()))));
}
void DOMBoundBrowserObject::SetProperty(const std::string& name,