diff options
| author | hanxi <hanxi@chromium.org> | 2015-03-09 13:46:59 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2015-03-09 20:47:49 +0000 |
| commit | 79f7a57302cae3f7afcd53c6dff542e32bada999 (patch) | |
| tree | ffa0c8be372fff6f9c02f7a83e05928cb6472c65 /chrome/browser | |
| parent | 7b41c6561705c1645d65313d116f35c582bd6247 (diff) | |
| download | chromium_src-79f7a57302cae3f7afcd53c6dff542e32bada999.zip chromium_src-79f7a57302cae3f7afcd53c6dff542e32bada999.tar.gz chromium_src-79f7a57302cae3f7afcd53c6dff542e32bada999.tar.bz2 | |
Enable <webview>.executeScript outside of Apps and Extensions [1]
This patch enables javascript code injection like <webview>.executeScript({code: ...}), but does not include file injection like <webview>.executeScript({file: ...}). File injection will be in another patch.
BUG=434081
Review URL: https://codereview.chromium.org/942533003
Cr-Commit-Position: refs/heads/master@{#319727}
Diffstat (limited to 'chrome/browser')
| -rw-r--r-- | chrome/browser/chromeos/accessibility/accessibility_manager.cc | 5 | ||||
| -rw-r--r-- | chrome/browser/extensions/api/tabs/tabs_api.cc | 4 | ||||
| -rw-r--r-- | chrome/browser/ui/webui/webui_webview_browsertest.cc | 46 |
3 files changed, 52 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()))); +} |
