From e263449d32e9392985c1587f2a0b4e0e77e605a2 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Wed, 18 Feb 2015 18:08:14 +0100 Subject: WebChannel: don't mess with the navigator object The navigator object is actually exposed later on from WebCore using a different mechanism, so the V8 extension approach won't work with it. Better take the chrome extensions approach and expose our own. This should "un-break" the part of the web that was broken by eee482929a. Change-Id: I991be2e12bb9ebcf60ace02721497c3fcd923c7f Reviewed-by: Peter Varga Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Andras Becsi --- src/core/renderer/web_channel_ipc_transport.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/core/renderer/web_channel_ipc_transport.cpp') diff --git a/src/core/renderer/web_channel_ipc_transport.cpp b/src/core/renderer/web_channel_ipc_transport.cpp index 6adff45d5..ebebb01e9 100644 --- a/src/core/renderer/web_channel_ipc_transport.cpp +++ b/src/core/renderer/web_channel_ipc_transport.cpp @@ -51,11 +51,11 @@ static const char kWebChannelTransportExtensionName[] = "v8/WebChannelTransport"; static const char kWebChannelTransportApi[] = - "if (typeof(navigator) === 'undefined')" \ - " navigator = {};" \ - "if (typeof(navigator.qtWebChannelTransport) === 'undefined')" \ - " navigator.qtWebChannelTransport = {};" \ - "navigator.qtWebChannelTransport.send = function(message) {" \ + "if (typeof(qt) === 'undefined')" \ + " qt = {};" \ + "if (typeof(qt.webChannelTransport) === 'undefined')" \ + " qt.webChannelTransport = {};" \ + "qt.webChannelTransport.send = function(message) {" \ " native function NativeQtSendMessage();" \ " NativeQtSendMessage(message);" \ "};"; @@ -135,15 +135,15 @@ void WebChannelIPCTransport::dispatchWebChannelMessage(const std::vector & v8::Context::Scope contextScope(context); v8::Handle global(context->Global()); - v8::Handle navigatorValue(global->Get(v8::String::NewFromUtf8(isolate, "navigator"))); - if (!navigatorValue->IsObject()) + v8::Handle qtObjectValue(global->Get(v8::String::NewFromUtf8(isolate, "qt"))); + if (!qtObjectValue->IsObject()) return; - v8::Handle navigatorQtValue(navigatorValue->ToObject()->Get(v8::String::NewFromUtf8(isolate, "qtWebChannelTransport"))); - if (!navigatorQtValue->IsObject()) + v8::Handle webChannelObjectValue(qtObjectValue->ToObject()->Get(v8::String::NewFromUtf8(isolate, "webChannelTransport"))); + if (!webChannelObjectValue->IsObject()) return; - v8::Handle onmessageCallbackValue(navigatorQtValue->ToObject()->Get(v8::String::NewFromUtf8(isolate, "onmessage"))); + v8::Handle onmessageCallbackValue(webChannelObjectValue->ToObject()->Get(v8::String::NewFromUtf8(isolate, "onmessage"))); if (!onmessageCallbackValue->IsFunction()) { - qWarning("onmessage is not a callable property of navigator.qtWebChannelTransport. Some things might not work as expected."); + qWarning("onmessage is not a callable property of qt.webChannelTransport. Some things might not work as expected."); return; } @@ -156,7 +156,7 @@ void WebChannelIPCTransport::dispatchWebChannelMessage(const std::vector & const int argc = 1; v8::Handle argv[argc]; argv[0] = messageObject; - frame->callFunctionEvenIfScriptDisabled(callback, navigatorQtValue->ToObject(), argc, argv); + frame->callFunctionEvenIfScriptDisabled(callback, webChannelObjectValue->ToObject(), argc, argv); } v8::Extension *WebChannelIPCTransport::getV8Extension() -- cgit v1.2.3