summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-06 18:15:58 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-06 18:15:58 +0000
commite4dad9fbf5a48cb65d085e49c8f7917c8f31300b (patch)
tree3df910ad37afd8d633f16cc47d0f4b46f6647fbf /chrome/browser
parent2a3e3c054891c865540524beb4af96ec68c481ba (diff)
downloadchromium_src-e4dad9fbf5a48cb65d085e49c8f7917c8f31300b.zip
chromium_src-e4dad9fbf5a48cb65d085e49c8f7917c8f31300b.tar.gz
chromium_src-e4dad9fbf5a48cb65d085e49c8f7917c8f31300b.tar.bz2
Modify extension request IPC messages to pass a ListValue instead of a string.
This allows us to pass binary values through extension requests. I use this in my next CL to pass SkBitmaps. BUG=23269 TEST=no Review URL: http://codereview.chromium.org/251093 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28130 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/automation/automation_extension_function.cc4
-rw-r--r--chrome/browser/automation/automation_extension_function.h2
-rw-r--r--chrome/browser/dom_ui/dom_ui.cc16
-rw-r--r--chrome/browser/dom_ui/dom_ui.h2
-rw-r--r--chrome/browser/extensions/extension_dom_ui.cc2
-rw-r--r--chrome/browser/extensions/extension_dom_ui.h2
-rw-r--r--chrome/browser/extensions/extension_function.cc15
-rw-r--r--chrome/browser/extensions/extension_function.h6
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc2
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.h3
-rw-r--r--chrome/browser/extensions/extension_host.cc2
-rw-r--r--chrome/browser/extensions/extension_host.h2
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc25
-rw-r--r--chrome/browser/renderer_host/render_view_host.h3
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h3
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc2
-rw-r--r--chrome/browser/tab_contents/tab_contents.h2
17 files changed, 47 insertions, 46 deletions
diff --git a/chrome/browser/automation/automation_extension_function.cc b/chrome/browser/automation/automation_extension_function.cc
index 89288c0..4849583 100644
--- a/chrome/browser/automation/automation_extension_function.cc
+++ b/chrome/browser/automation/automation_extension_function.cc
@@ -14,8 +14,8 @@
bool AutomationExtensionFunction::enabled_ = false;
-void AutomationExtensionFunction::SetArgs(const std::string& args) {
- args_ = args;
+void AutomationExtensionFunction::SetArgs(const Value* args) {
+ JSONWriter::Write(args, false, &args_);
}
const std::string AutomationExtensionFunction::GetResult() {
diff --git a/chrome/browser/automation/automation_extension_function.h b/chrome/browser/automation/automation_extension_function.h
index 1d1da41..f48adff 100644
--- a/chrome/browser/automation/automation_extension_function.h
+++ b/chrome/browser/automation/automation_extension_function.h
@@ -20,7 +20,7 @@ class AutomationExtensionFunction : public ExtensionFunction {
AutomationExtensionFunction() { }
// ExtensionFunction implementation.
- virtual void SetArgs(const std::string& args);
+ virtual void SetArgs(const Value* args);
virtual const std::string GetResult();
virtual const std::string GetError();
virtual void Run();
diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc
index 2088427..7f38aef 100644
--- a/chrome/browser/dom_ui/dom_ui.cc
+++ b/chrome/browser/dom_ui/dom_ui.cc
@@ -35,7 +35,7 @@ DOMUI::~DOMUI() {
// DOMUI, public: -------------------------------------------------------------
void DOMUI::ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback) {
// Look up the callback for this message.
@@ -44,20 +44,8 @@ void DOMUI::ProcessDOMUIMessage(const std::string& message,
if (callback == message_callbacks_.end())
return;
- // Convert the content JSON into a Value.
- scoped_ptr<Value> value;
- if (!content.empty()) {
- value.reset(JSONReader::Read(content, false));
- if (!value.get()) {
- // The page sent us something that we didn't understand.
- // This probably indicates a programming error.
- NOTREACHED();
- return;
- }
- }
-
// Forward this message and content on.
- callback->second->Run(value.get());
+ callback->second->Run(content);
}
void DOMUI::CallJavascriptFunction(const std::wstring& function_name) {
diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h
index b359abd..ad4c2dc 100644
--- a/chrome/browser/dom_ui/dom_ui.h
+++ b/chrome/browser/dom_ui/dom_ui.h
@@ -41,7 +41,7 @@ class DOMUI {
// Called from TabContents.
virtual void ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback);
diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc
index a718f5c..df4746d 100644
--- a/chrome/browser/extensions/extension_dom_ui.cc
+++ b/chrome/browser/extensions/extension_dom_ui.cc
@@ -54,7 +54,7 @@ void ExtensionDOMUI::RenderViewReused(RenderViewHost* render_view_host) {
}
void ExtensionDOMUI::ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback) {
extension_function_dispatcher_->HandleRequest(message, content, request_id,
diff --git a/chrome/browser/extensions/extension_dom_ui.h b/chrome/browser/extensions/extension_dom_ui.h
index b8ef8dc..a729167 100644
--- a/chrome/browser/extensions/extension_dom_ui.h
+++ b/chrome/browser/extensions/extension_dom_ui.h
@@ -29,7 +29,7 @@ class ExtensionDOMUI
virtual void RenderViewCreated(RenderViewHost* render_view_host);
virtual void RenderViewReused(RenderViewHost* render_view_host);
virtual void ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback);
diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc
index 26adefb..c15c18b 100644
--- a/chrome/browser/extensions/extension_function.cc
+++ b/chrome/browser/extensions/extension_function.cc
@@ -4,24 +4,13 @@
#include "chrome/browser/extensions/extension_function.h"
-#include "base/json_reader.h"
#include "base/json_writer.h"
#include "base/logging.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
-void AsyncExtensionFunction::SetArgs(const std::string& args) {
+void AsyncExtensionFunction::SetArgs(const Value* args) {
DCHECK(!args_); // Should only be called once.
- if (!args.empty()) {
- JSONReader reader;
- args_ = reader.JsonToValue(args, false, false);
-
- // Since we do the serialization in the v8 extension, we should always get
- // valid JSON.
- if (!args_) {
- DCHECK(false);
- return;
- }
- }
+ args_ = args->DeepCopy();
}
const std::string AsyncExtensionFunction::GetResult() {
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index d763696..238f8e4 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -36,8 +36,8 @@ class ExtensionFunction : public base::RefCounted<ExtensionFunction> {
void set_name(const std::string& name) { name_ = name; }
const std::string name() { return name_; }
- // Specifies the raw arguments to the function, as a JSON-encoded string.
- virtual void SetArgs(const std::string& args) = 0;
+ // Specifies the raw arguments to the function, as a JSON value.
+ virtual void SetArgs(const Value* args) = 0;
// Retrieves the results of the function as a JSON-encoded string (may
// be empty).
@@ -103,7 +103,7 @@ class AsyncExtensionFunction : public ExtensionFunction {
AsyncExtensionFunction() : args_(NULL), bad_message_(false) {}
virtual ~AsyncExtensionFunction() {}
- virtual void SetArgs(const std::string& args);
+ virtual void SetArgs(const Value* args);
virtual const std::string GetResult();
virtual const std::string GetError() { return error_; }
virtual void Run() {
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index eb3a92e..d17e575 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -279,7 +279,7 @@ Extension* ExtensionFunctionDispatcher::GetExtension() {
}
void ExtensionFunctionDispatcher::HandleRequest(const std::string& name,
- const std::string& args,
+ const Value* args,
int request_id,
bool has_callback) {
scoped_refptr<ExtensionFunction> function(
diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h
index 492c431e..b987e0e 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.h
+++ b/chrome/browser/extensions/extension_function_dispatcher.h
@@ -19,6 +19,7 @@ class ExtensionHost;
class Profile;
class RenderViewHost;
class RenderViewHostDelegate;
+class Value;
// A factory function for creating new ExtensionFunction instances.
typedef ExtensionFunction* (*ExtensionFunctionFactory)();
@@ -61,7 +62,7 @@ class ExtensionFunctionDispatcher {
~ExtensionFunctionDispatcher();
// Handle a request to execute an extension function.
- void HandleRequest(const std::string& name, const std::string& args,
+ void HandleRequest(const std::string& name, const Value* args,
int request_id, bool has_callback);
// Send a response to a function.
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 766a12e..8bad4ce 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -361,7 +361,7 @@ WebPreferences ExtensionHost::GetWebkitPrefs() {
}
void ExtensionHost::ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback) {
if (extension_function_dispatcher_.get()) {
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index c5aeeba..9e54251 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -103,7 +103,7 @@ class ExtensionHost : public RenderViewHostDelegate,
virtual WebPreferences GetWebkitPrefs();
virtual void ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback);
virtual void RunJavaScriptMessage(const std::wstring& message,
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index d384fec..667faa4 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -10,6 +10,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/gfx/native_widget_types.h"
+#include "base/json_reader.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/waitable_event.h"
@@ -1219,8 +1220,19 @@ void RenderViewHost::OnMsgDOMUISend(
// values here.
const int kRequestId = -1;
const bool kHasCallback = false;
+ scoped_ptr<Value> value;
+ if (!content.empty()) {
+ value.reset(JSONReader::Read(content, false));
+ if (!value.get()) {
+ // The page sent us something that we didn't understand.
+ // This probably indicates a programming error.
+ NOTREACHED() << "Invalid JSON argument in OnMsgDOMUISend.";
+ return;
+ }
+ }
- delegate_->ProcessDOMUIMessage(message, content, kRequestId, kHasCallback);
+ delegate_->ProcessDOMUIMessage(message, value.get(),
+ kRequestId, kHasCallback);
}
void RenderViewHost::OnMsgForwardMessageToExternalHost(
@@ -1633,7 +1645,7 @@ void RenderViewHost::ForwardMessageFromExternalHost(const std::string& message,
}
void RenderViewHost::OnExtensionRequest(const std::string& name,
- const std::string& args,
+ const ListValue& args_holder,
int request_id,
bool has_callback) {
if (!ChildProcessSecurityPolicy::GetInstance()->
@@ -1644,6 +1656,15 @@ void RenderViewHost::OnExtensionRequest(const std::string& name,
return;
}
+ // The renderer sends the args in a 1-element list to make serialization
+ // easier.
+ Value* args = NULL;
+ if (!args_holder.IsType(Value::TYPE_LIST) ||
+ !static_cast<const ListValue*>(&args_holder)->Get(0, &args)) {
+ NOTREACHED();
+ return;
+ }
+
delegate_->ProcessDOMUIMessage(name, args, request_id, has_callback);
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 8fff7cf..37f1215 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -22,6 +22,7 @@
#include "webkit/glue/password_form_dom_manager.h"
#include "webkit/glue/window_open_disposition.h"
+class ListValue;
class RenderViewHostDelegate;
class SiteInstance;
class SkBitmap;
@@ -571,7 +572,7 @@ class RenderViewHost : public RenderWidgetHost,
void OnRemoveAutofillEntry(const std::wstring& field_name,
const std::wstring& value);
- void OnExtensionRequest(const std::string& name, const std::string& args,
+ void OnExtensionRequest(const std::string& name, const ListValue& args,
int request_id, bool has_callback);
void OnExtensionPostMessage(int port_id, const std::string& message);
void OnAccessibilityFocusChange(int acc_obj_id);
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 96ed816..0f853c3 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -19,6 +19,7 @@ class AutofillForm;
struct ContextMenuParams;
class FilePath;
class GURL;
+class Value;
struct NativeWebKeyboardEvent;
class NavigationEntry;
class Profile;
@@ -467,7 +468,7 @@ class RenderViewHostDelegate {
// A message was sent from HTML-based UI.
// By default we ignore such messages.
virtual void ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback) {}
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 315934e..7735a14 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -2208,7 +2208,7 @@ void TabContents::DomOperationResponse(const std::string& json_string,
}
void TabContents::ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback) {
if (!render_manager_.dom_ui()) {
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 3a09eb5..a85c3bb 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -873,7 +873,7 @@ class TabContents : public PageNavigator,
virtual void DomOperationResponse(const std::string& json_string,
int automation_id);
virtual void ProcessDOMUIMessage(const std::string& message,
- const std::string& content,
+ const Value* content,
int request_id,
bool has_callback);
virtual void ProcessExternalHostMessage(const std::string& message,