| 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 9187a08a87d217ecf89616d16618d851df31ad68..9f8c50b5c6ab7019df464277e03eb3a2d3baef37 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);
|
| }
|
|
|