Commit 37d18e87 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Add sendWebKitMessage JavaScript function to common.js

This function will be reused by features in order to communicate back to
the native application from any arbitrary frame.

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I729c1c1b5faba803b7b334ae73674e5b017ef587
Reviewed-on: https://chromium-review.googlesource.com/896615
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533904}
parent 916bc9b0
...@@ -703,4 +703,20 @@ __gCrWeb['common'] = __gCrWeb.common; ...@@ -703,4 +703,20 @@ __gCrWeb['common'] = __gCrWeb.common;
return new URL(url_one).origin == new URL(url_two).origin; return new URL(url_one).origin == new URL(url_two).origin;
} }
/**
* Posts |message| to the webkit message handler specified by |handlerName|.
*
* @param {string} handlerName The name of the webkit message handler.
* @param {Object} message The message to post to the handler.
*/
__gCrWeb.common.sendWebKitMessage = function(handlerName, message) {
// A web page can override |window.webkit| with any value. Deleting the
// object ensures that original and working implementation of
// window.webkit is restored.
var oldWebkit = window.webkit;
delete window['webkit'];
window.webkit.messageHandlers[handlerName].postMessage(message);
window.webkit = oldWebkit;
}
}()); // End of anonymous object }()); // End of anonymous object
...@@ -77,16 +77,10 @@ __gCrWeb['message'] = __gCrWeb.message; ...@@ -77,16 +77,10 @@ __gCrWeb['message'] = __gCrWeb.message;
delete Object.prototype.toJSON; delete Object.prototype.toJSON;
queueObject.queue.forEach(function(command) { queueObject.queue.forEach(function(command) {
// A web page can override |window.webkit| with any value. Deleting the __gCrWeb.common.sendWebKitMessage(queueObject.scheme, {
// object ensures that original and working implementation of "crwCommand": command,
// window.webkit is restored. "crwWindowId": window.top.__gCrWeb['windowId']
var oldWebkit = window.webkit; });
delete window['webkit'];
window.webkit.messageHandlers[queueObject.scheme].postMessage({
"crwCommand": command,
"crwWindowId": window.top.__gCrWeb['windowId']
});
window.webkit = oldWebkit;
}); });
queueObject.reset(); queueObject.reset();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment