Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: chrome/browser/extensions/api/messaging/native_message_process_host.cc

Issue 16226004: Replace JSON (de)serialization of extension messages with direct Value pickling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable test on win Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/messaging/native_message_process_host.cc
diff --git a/chrome/browser/extensions/api/messaging/native_message_process_host.cc b/chrome/browser/extensions/api/messaging/native_message_process_host.cc
index a856d2bab4cc1d4dbe0a51c82fbe5fc23bdeb0d1..1f713d39ffd17ce6b0a5734d69ccb1788a29a340 100644
--- a/chrome/browser/extensions/api/messaging/native_message_process_host.cc
+++ b/chrome/browser/extensions/api/messaging/native_message_process_host.cc
@@ -5,7 +5,9 @@
#include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/files/file_path.h"
+#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/platform_file.h"
#include "base/process_util.h"
@@ -42,6 +44,8 @@ const char kForbiddenError[] =
"Access to the specified native messaging host is forbidden.";
const char kHostInputOuputError[] =
"Error when communicating with the native messaging host.";
+const char kInvalidJsonError[] =
+ "Message must be valid JSON";
} // namespace
@@ -268,10 +272,35 @@ void NativeMessageProcessHost::ProcessIncomingData(
if (incoming_data_.size() < message_size + kMessageHeaderSize)
return;
+ scoped_ptr<base::ListValue> message(new base::ListValue());
+ {
+ std::string message_as_json =
+ incoming_data_.substr(kMessageHeaderSize, message_size);
+ int error_code;
+ std::string error_message;
+ scoped_ptr<base::Value> message_as_value(
+ base::JSONReader::ReadAndReturnError(message_as_json,
+ 0, // no flags
+ &error_code,
+ &error_message));
+ if (!message_as_value) {
+ base::JSONReader::JsonParseError parse_error =
+ static_cast<base::JSONReader::JsonParseError>(error_code);
+ LOG(ERROR) << "Native Messaging host sent message with invalid JSON \""
+ << message_as_json << "\": " << error_message << " ("
+ << base::JSONReader::ErrorCodeToString(parse_error) << "), "
+ << "message size " << message_size << ", "
+ << "incoming data size " << incoming_data_.size() << ".";
+ Close(kInvalidJsonError);
+ return;
+ }
+ message->Append(message_as_value.release());
+ }
+
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(&Client::PostMessageFromNativeProcess, weak_client_ui_,
destination_port_,
- incoming_data_.substr(kMessageHeaderSize, message_size)));
+ base::Passed(&message)));
incoming_data_.erase(0, kMessageHeaderSize + message_size);
}

Powered by Google App Engine
This is Rietveld 408576698