From 602542d6a7ea6313321d9badfe232df3daf12cef Mon Sep 17 00:00:00 2001 From: "asargent@chromium.org" Date: Fri, 20 Apr 2012 02:48:01 +0000 Subject: Use Value objects instead of JSON strings in extension API response IPCs. When we're sending the result of an extension API method call, we currently convert a Value object into a JSON string in the browser process, and then call JSON.parse in javascript on the renderer side. This CL changes that to pass the Value object in the IPC, and uses V8ValueConverter to turn the Value into the appropriate v8 native object, avoiding the need to parse JSON. This is a first step towards supporting binary data for API request parameters and responses. BUG=122675 TEST=No new functionality ; existing unit and browser tests should still pass. Review URL: https://chromiumcodereview.appspot.com/10041047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133133 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/extensions/extension_function.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'chrome/browser/extensions/extension_function.cc') diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc index b278df8..bfd5a70 100644 --- a/chrome/browser/extensions/extension_function.cc +++ b/chrome/browser/extensions/extension_function.cc @@ -85,20 +85,12 @@ void ExtensionFunction::OnQuotaExceeded() { SendResponse(false); } -void ExtensionFunction::SetArgs(const ListValue* args) { +void ExtensionFunction::SetArgs(const base::ListValue* args) { DCHECK(!args_.get()); // Should only be called once. args_.reset(args->DeepCopy()); } -const std::string ExtensionFunction::GetResult() { - std::string json; - // Some functions might not need to return any results. - if (result_.get()) - base::JSONWriter::Write(result_.get(), &json); - return json; -} - -Value* ExtensionFunction::GetResultValue() { +const Value* ExtensionFunction::GetResultValue() { return result_.get(); } @@ -130,8 +122,14 @@ void ExtensionFunction::SendResponseImpl(base::ProcessHandle process, return; } + // Value objects can't be directly serialized in our IPC code, so we wrap the + // result_ Value with a ListValue (also transferring ownership of result_). + base::ListValue result_wrapper; + if (result_.get()) + result_wrapper.Append(result_.release()); + ipc_sender->Send(new ExtensionMsg_Response( - routing_id, request_id_, success, GetResult(), GetError())); + routing_id, request_id_, success, result_wrapper, GetError())); } void ExtensionFunction::HandleBadMessage(base::ProcessHandle process) { -- cgit v1.1