| 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..fd170c8a24bb5b83ef2619b2257034f2bd3807b1 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,24 @@ 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);
|
| + scoped_ptr<base::Value> message_as_value(
|
| + base::JSONReader::Read(message_as_json));
|
| + if (!message_as_value) {
|
| + LOG(ERROR) << "Native Messaging host sent a message with invalid JSON";
|
| + 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);
|
| }
|
|
|