summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/accessibility/accessibility_manager.cc5
-rw-r--r--chrome/browser/extensions/api/tabs/tabs_api.cc4
-rw-r--r--chrome/browser/ui/webui/webui_webview_browsertest.cc46
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/data/webui/webview_execute_script_test.js32
5 files changed, 85 insertions, 3 deletions
diff --git a/chrome/browser/chromeos/accessibility/accessibility_manager.cc b/chrome/browser/chromeos/accessibility/accessibility_manager.cc
index 2fcc539..338a86e 100644
--- a/chrome/browser/chromeos/accessibility/accessibility_manager.cc
+++ b/chrome/browser/chromeos/accessibility/accessibility_manager.cc
@@ -62,6 +62,7 @@
#include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h"
#include "extensions/common/extension_resource.h"
+#include "extensions/common/host_id.h"
#include "media/audio/sounds/sounds_manager.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/resource/resource_bundle.h"
@@ -135,7 +136,7 @@ class ContentScriptLoader {
if (success) {
ExtensionMsg_ExecuteCode_Params params;
params.request_id = 0;
- params.extension_id = extension_id_;
+ params.host_id = HostID(HostID::EXTENSIONS, extension_id_);
params.is_javascript = true;
params.code = data;
params.run_at = extensions::UserScript::DOCUMENT_IDLE;
@@ -204,7 +205,7 @@ void InjectChromeVoxContentScript(
// so that it won't interrupt our speech feedback enabled message.
ExtensionMsg_ExecuteCode_Params params;
params.request_id = 0;
- params.extension_id = extension->id();
+ params.host_id = HostID(HostID::EXTENSIONS, extension->id());
params.is_javascript = true;
params.code = "window.INJECTED_AFTER_LOAD = true;";
params.run_at = extensions::UserScript::DOCUMENT_IDLE;
diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc
index 4816da7..229d89a 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -75,6 +75,7 @@
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
+#include "extensions/common/host_id.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/default_locale_handler.h"
#include "extensions/common/message_bundle.h"
@@ -1241,7 +1242,7 @@ bool TabsUpdateFunction::UpdateURL(const std::string &url_string,
}
TabHelper::FromWebContents(web_contents_)->script_executor()->ExecuteScript(
- extension_id(),
+ HostID(HostID::EXTENSIONS, extension_id()),
ScriptExecutor::JAVASCRIPT,
url.GetContent(),
ScriptExecutor::TOP_FRAME,
@@ -1731,6 +1732,7 @@ bool ExecuteCodeInTabFunction::Init() {
execute_tab_id_ = tab_id;
details_ = details.Pass();
+ set_host_id(HostID(HostID::EXTENSIONS, extension()->id()));
return true;
}
diff --git a/chrome/browser/ui/webui/webui_webview_browsertest.cc b/chrome/browser/ui/webui/webui_webview_browsertest.cc
new file mode 100644
index 0000000..9750dba
--- /dev/null
+++ b/chrome/browser/ui/webui/webui_webview_browsertest.cc
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/macros.h"
+#include "base/path_service.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "chrome/test/base/web_ui_browser_test.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+
+class WebUIWebViewBrowserTest : public WebUIBrowserTest {
+ public:
+ WebUIWebViewBrowserTest() {}
+
+ void SetUpOnMainThread() override {
+ WebUIBrowserTest::SetUpOnMainThread();
+ AddLibrary(
+ base::FilePath(FILE_PATH_LITERAL("webview_execute_script_test.js")));
+
+ base::FilePath test_data_dir;
+ PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
+ embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+ }
+
+ GURL GetTestUrl(const std::string& path) const {
+ return embedded_test_server()->base_url().Resolve(path);
+ }
+
+ GURL GetWebViewEnabledWebUIURL() const {
+ return GURL(chrome::kChromeUIChromeSigninURL);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebUIWebViewBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ExecuteScriptCode) {
+ ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL());
+
+ ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest(
+ "testExecuteScriptCode",
+ new base::StringValue(GetTestUrl("empty.html").spec())));
+}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 5f164b34..50a64b7 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -527,6 +527,7 @@
'browser/ui/webui/signin/user_manager_ui_browsertest.cc',
'browser/ui/webui/web_ui_test_handler.cc',
'browser/ui/webui/web_ui_test_handler.h',
+ 'browser/ui/webui/webui_webview_browsertest.cc',
'browser/ui/zoom/zoom_controller_browsertest.cc',
'browser/unload_browsertest.cc',
'common/mac/app_mode_chrome_locator_browsertest.mm',
diff --git a/chrome/test/data/webui/webview_execute_script_test.js b/chrome/test/data/webui/webview_execute_script_test.js
new file mode 100644
index 0000000..e0a4c80c
--- /dev/null
+++ b/chrome/test/data/webui/webview_execute_script_test.js
@@ -0,0 +1,32 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function createWebview() {
+ var webview = document.createElement('webview');
+ document.body.appendChild(webview);
+ return webview;
+}
+
+function testExecuteScriptCode(url) {
+ var webview = createWebview();
+
+ var onGetBackgroundExecuted = function(results) {
+ chrome.send('testResult', [results.length == 1 && results[0] == 'red']);
+ };
+
+ var onSetBackgroundExecuted = function() {
+ webview.executeScript({
+ code: 'document.body.style.backgroundColor;'
+ }, onGetBackgroundExecuted);
+ };
+
+ var onLoadStop = function() {
+ webview.executeScript({
+ code: 'document.body.style.backgroundColor = \'red\';'
+ }, onSetBackgroundExecuted);
+ };
+
+ webview.addEventListener('loadstop', onLoadStop);
+ webview.src = url;
+}