diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-08 16:01:14 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-08 16:01:14 +0000 |
commit | c10e43176b94575aa519c0e8a514f462513adf2b (patch) | |
tree | b1e9573e53ad3e0942f7e1e20aa4ccdedc454972 /chrome | |
parent | 5c1620e7425963dde54190bee49f571b8dab7149 (diff) | |
download | chromium_src-c10e43176b94575aa519c0e8a514f462513adf2b.zip chromium_src-c10e43176b94575aa519c0e8a514f462513adf2b.tar.gz chromium_src-c10e43176b94575aa519c0e8a514f462513adf2b.tar.bz2 |
<webview>: Throw exception if content is not ready for script injection.
Throw exception if executeScript or insertCSS fails because the content is
not ready (hasn't loaded yet).
BUG=247512
Test=WebViewTest.Shim
Review URL: https://chromiumcodereview.appspot.com/16124007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205062 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/renderer/resources/extensions/web_view_experimental.js | 16 | ||||
-rw-r--r-- | chrome/test/data/extensions/platform_apps/web_view/shim/main.js | 16 |
2 files changed, 30 insertions, 2 deletions
diff --git a/chrome/renderer/resources/extensions/web_view_experimental.js b/chrome/renderer/resources/extensions/web_view_experimental.js index 18862cd..923ed65 100644 --- a/chrome/renderer/resources/extensions/web_view_experimental.js +++ b/chrome/renderer/resources/extensions/web_view_experimental.js @@ -42,6 +42,10 @@ var ERROR_MSG_NEWWINDOW_ACTION_ALREADY_TAKEN = '<webview>: ' + /** @type {string} */ var ERROR_MSG_WEBVIEW_EXPECTED = '<webview> element expected.'; +/** @type {string} */ +var ERROR_MSG_CANNOT_INJECT_SCRIPT = '<webview>: ' + + 'Script cannot be injected into content until the page has loaded.'; + /** * @private */ @@ -113,14 +117,22 @@ WebView.prototype.setupPermissionEvent_ = function() { */ WebView.prototype.setupExecuteCodeAPI_ = function() { var self = this; + var validateCall = function() { + if (!self.browserPluginNode_.getGuestInstanceId()) { + throw new Error(ERROR_MSG_CANNOT_INJECT_SCRIPT); + } + }; + this.webviewNode_['executeScript'] = function(var_args) { + validateCall(); var args = [self.browserPluginNode_.getGuestInstanceId()].concat( - Array.prototype.slice.call(arguments)); + Array.prototype.slice.call(arguments)); chrome.webview.executeScript.apply(null, args); } this.webviewNode_['insertCSS'] = function(var_args) { + validateCall(); var args = [self.browserPluginNode_.getGuestInstanceId()].concat( - Array.prototype.slice.call(arguments)); + Array.prototype.slice.call(arguments)); chrome.webview.insertCSS.apply(null, args); } }; diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js index a172e4d..9978a9b 100644 --- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js +++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js @@ -212,6 +212,22 @@ chrome.test.getConfig(function(config) { }, 0); }, + function webViewExecuteScriptFail() { + var webview = document.createElement('webview'); + document.body.appendChild(webview); + setTimeout(function() { + try { + webview.executeScript( + {code:'document.body.style.backgroundColor = "red";'}, + function(results) { + chrome.test.fail(); + }); + } catch (e) { + chrome.test.succeed(); + } + }, 0); + }, + function webViewExecuteScript() { var webview = document.createElement('webview'); webview.setAttribute('partition', arguments.callee.name); |