diff --git a/src/core/renderer/web_channel_ipc_transport.cpp b/src/core/renderer/web_channel_ipc_transport.cpp index 173b403a58f9411fca2054bb98d21c9507a19d4e..f34e1310ba48f954ae8898b2be35c34228d1589c 100644 --- a/src/core/renderer/web_channel_ipc_transport.cpp +++ b/src/core/renderer/web_channel_ipc_transport.cpp @@ -68,25 +68,30 @@ private: WebChannelTransport() { } virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate *isolate) override; - void NativeQtSendMessage(gin::Arguments *args) + bool NativeQtSendMessage(gin::Arguments *args) { content::RenderView *renderView = GetRenderView(args->isolate()); if (!renderView || args->Length() != 1) - return; + return false; v8::Handle<v8::Value> val; args->GetNext(&val); if (!val->IsString() && !val->IsStringObject()) - return; + return false; v8::String::Utf8Value utf8(val->ToString()); QByteArray valueData(*utf8, utf8.length()); QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(valueData, &error); - if (error.error != QJsonParseError::NoError) + if (error.error != QJsonParseError::NoError) { qWarning("%s %d: Parsing error: %s",__FILE__, __LINE__, qPrintable(error.errorString())); + return false; + } int size = 0; const char *rawData = doc.rawData(&size); + if (size == 0) + return false; renderView->Send(new WebChannelIPCTransportHost_SendMessage(renderView->GetRoutingID(), std::vector<char>(rawData, rawData + size))); + return true; } DISALLOW_COPY_AND_ASSIGN(WebChannelTransport); diff --git a/src/core/renderer_host/web_channel_ipc_transport_host.cpp b/src/core/renderer_host/web_channel_ipc_transport_host.cpp index aef16f0a0259e521226b5191db0c88e7ca672933..1cd4e4063a7848fc9909d44225a7638f624a8636 100644 --- a/src/core/renderer_host/web_channel_ipc_transport_host.cpp +++ b/src/core/renderer_host/web_channel_ipc_transport_host.cpp @@ -87,6 +87,7 @@ void WebChannelIPCTransportHost::sendMessage(const QJsonObject &message) void WebChannelIPCTransportHost::onWebChannelMessage(const std::vector<char> &message) { + Q_ASSERT(!message.empty()); QJsonDocument doc = QJsonDocument::fromRawData(message.data(), message.size(), QJsonDocument::BypassValidation); Q_ASSERT(doc.isObject()); Q_EMIT messageReceived(doc.object(), this);