Commit bd0ede34 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

Revert "Allow access to closed shadow root from Extension"

This reverts commit fe6e27d6.

Reason for revert: newly-added OpenOrClosedShadowRootInBackgroundPage is very flaky, see https://ci.chromium.org/p/chromium/builders/ci/Win10%20Tests%20x64 or https://ci.chromium.org/p/chromium/builders/ci/Linux%20Chromium%20OS%20ASan%20LSan%20Tests%20%281%29

Original change's description:
> Allow access to closed shadow root from Extension
> 
> This CL introduces chrome.dom.openOrClosedShadowRoot that is a
> read-only property to allow access to the closed shadow root in
> the Extension's content script.
> 
> Bug: 778816
> Change-Id: I933bc5d3996a74f46ee75181c535150901a5a46a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2319951
> Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
> Reviewed-by: Mike West <mkwst@chromium.org>
> Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
> Reviewed-by: Mason Freed <masonfreed@chromium.org>
> Reviewed-by: Kent Tamura <tkent@chromium.org>
> Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#809277}

TBR=peria@chromium.org,yukishiino@chromium.org,rdevlin.cronin@chromium.org,tkent@chromium.org,karandeepb@chromium.org,mkwst@chromium.org,masonfreed@chromium.org,myid.shin@igalia.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 778816
Change-Id: If2a26a4aea10a0e03c9a8bca25ca34965bca9110
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426265Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810056}
parent 5af51966
// Copyright 2020 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 "chrome/browser/extensions/extension_apitest.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test.h"
#include "extensions/test/result_catcher.h"
namespace extensions {
// Test that a content script allows access of the closed shadow root in
// content.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
OpenOrClosedShadowRootInContentScript) {
ASSERT_TRUE(StartEmbeddedTestServer());
const GURL url = embedded_test_server()->GetURL(
"/extensions/test_file_with_closed_shadow_root.html");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"dom/closed_shadow_root_from_content_script")));
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_TRUE(catcher.GetNextResult());
}
// Test that a background script allows access of the closed shadow root in
// background page.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
OpenOrClosedShadowRootInBackgroundPage) {
ASSERT_TRUE(StartEmbeddedTestServer());
const GURL url = embedded_test_server()->GetURL("/empty.html");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"dom/closed_shadow_root_from_background_page")));
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_TRUE(catcher.GetNextResult());
}
} // namespace extensions
...@@ -50,7 +50,6 @@ generated_json_strings("generated_api_json_strings") { ...@@ -50,7 +50,6 @@ generated_json_strings("generated_api_json_strings") {
"app.json", "app.json",
"commands.json", "commands.json",
"declarative_content.json", "declarative_content.json",
"dom.json",
"privacy.json", "privacy.json",
"proxy.json", "proxy.json",
"tts.json", "tts.json",
......
...@@ -321,10 +321,6 @@ ...@@ -321,10 +321,6 @@
"dependencies": ["permission:documentScan"], "dependencies": ["permission:documentScan"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, },
"dom": {
"channel": "dev",
"contexts": ["blessed_extension", "content_script"]
},
"downloads": { "downloads": {
"dependencies": ["permission:downloads"], "dependencies": ["permission:downloads"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
......
// Copyright 2020 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.
[
{
"namespace": "dom",
"description": "Use the <code>chrome.dom</code> API to access special DOM APIs for Extensions",
"functions": [
{
"name": "openOrClosedShadowRoot",
"description": "Gets the open shadow root or the closed shadow root hosted by the specified element. If the element doesn't attach the shadow root, it will return null.",
"type": "function",
"parameters": [
{
"name": "element",
"type": "object",
"isInstanceOf": "HTMLElement",
"additionalProperties": { "type": "any" }
}
],
"returns": {
"name": "shadowRoot",
"description": "See <a href='https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot'>https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot</a>",
"type": "object",
"additionalProperties": { "type": "any" }
}
}
]
}
]
...@@ -1933,7 +1933,6 @@ if (!is_android) { ...@@ -1933,7 +1933,6 @@ if (!is_android) {
"../browser/extensions/extension_context_menu_browsertest.cc", "../browser/extensions/extension_context_menu_browsertest.cc",
"../browser/extensions/extension_csp_bypass_browsertest.cc", "../browser/extensions/extension_csp_bypass_browsertest.cc",
"../browser/extensions/extension_disabled_ui_browsertest.cc", "../browser/extensions/extension_disabled_ui_browsertest.cc",
"../browser/extensions/extension_dom_apitest.cc",
"../browser/extensions/extension_dom_clipboard_apitest.cc", "../browser/extensions/extension_dom_clipboard_apitest.cc",
"../browser/extensions/extension_fileapi_apitest.cc", "../browser/extensions/extension_fileapi_apitest.cc",
"../browser/extensions/extension_function_registration_test.cc", "../browser/extensions/extension_function_registration_test.cc",
......
{
"name": "chrome.dom shadow root test",
"version": "0.1",
"manifest_version": 2,
"description": "tests that a backgournd script from an extension can access the closed shadow root via chrome.dom",
"background": {
"page": "background.html"
}
}
// Copyright 2020 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.
chrome.test.runTests([function() {
var host = document.getElementById('bghost');
var shadowRoot1 = host.attachShadow({mode: 'closed'});
shadowRoot1.appendChild(document.createElement('div'));
let shadowRoot2 = chrome.dom.openOrClosedShadowRoot(host);
chrome.test.assertEq(shadowRoot2.childElementCount, 1);
chrome.test.succeed();
}]);
// Copyright 2020 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.
chrome.test.runTests([function() {
const host = document.getElementById('host');
let shadowRoot = chrome.dom.openOrClosedShadowRoot(host);
chrome.test.assertEq(shadowRoot.childElementCount, 2);
let caughtError;
try {
chrome.dom.openOrClosedShadowRoot(new Object());
} catch (error) {
caughtError = error;
}
var expectedError =
'Error in invocation of dom.openOrClosedShadowRoot(HTMLElement ' +
'element): '
chrome.test.assertEq(caughtError.name, 'TypeError');
chrome.test.assertEq(caughtError.message, expectedError);
chrome.test.succeed();
}]);
{
"name": "chrome.dom shadow root test",
"version": "0.1",
"manifest_version": 2,
"description": "tests that a content script from an extension can access the closed shadow root via chrome.dom",
"content_scripts": [
{
"matches": ["http://127.0.0.1/*"],
"js": ["content-script.js"]
}
]
}
<html>
Test file!
<div id="host"> </div>
<script>
var host = document.getElementById('host');
var shadowRoot = host.attachShadow({mode: 'closed'});
shadowRoot.appendChild(document.createElement('div'));
shadowRoot.appendChild(document.createElement('div'));
</script>
</html>
...@@ -98,8 +98,6 @@ source_set("renderer") { ...@@ -98,8 +98,6 @@ source_set("renderer") {
"display_source_custom_bindings.h", "display_source_custom_bindings.h",
"dom_activity_logger.cc", "dom_activity_logger.cc",
"dom_activity_logger.h", "dom_activity_logger.h",
"dom_hooks_delegate.cc",
"dom_hooks_delegate.h",
"extension_frame_helper.cc", "extension_frame_helper.cc",
"extension_frame_helper.h", "extension_frame_helper.h",
"extension_injection_host.cc", "extension_injection_host.cc",
......
// Copyright 2020 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 "extensions/renderer/dom_hooks_delegate.h"
#include <memory>
#include "extensions/renderer/bindings/api_signature.h"
#include "extensions/renderer/dispatcher.h"
#include "extensions/renderer/script_context.h"
#include "third_party/blink/public/web/web_element.h"
namespace extensions {
DOMHooksDelegate::DOMHooksDelegate() = default;
DOMHooksDelegate::~DOMHooksDelegate() = default;
APIBindingHooks::RequestResult DOMHooksDelegate::HandleRequest(
const std::string& method_name,
const APISignature* signature,
v8::Local<v8::Context> context,
std::vector<v8::Local<v8::Value>>* arguments,
const APITypeReferenceMap& refs) {
using RequestResult = APIBindingHooks::RequestResult;
v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch try_catch(isolate);
APISignature::V8ParseResult parse_result =
signature->ParseArgumentsToV8(context, *arguments, refs);
if (!parse_result.succeeded()) {
if (try_catch.HasCaught()) {
try_catch.ReThrow();
return RequestResult(RequestResult::THROWN);
}
return RequestResult(RequestResult::INVALID_INVOCATION);
}
ScriptContext* script_context =
ScriptContextSet::GetContextByV8Context(context);
DCHECK(script_context);
APIBindingHooks::RequestResult result(
APIBindingHooks::RequestResult::HANDLED);
if (method_name == "dom.openOrClosedShadowRoot") {
DCHECK(parse_result.arguments.has_value());
result.return_value =
OpenOrClosedShadowRoot(script_context, *parse_result.arguments);
} else {
NOTREACHED();
}
return result;
}
v8::Local<v8::Value> DOMHooksDelegate::OpenOrClosedShadowRoot(
ScriptContext* script_context,
const std::vector<v8::Local<v8::Value>>& parsed_arguments) {
DCHECK(script_context->extension());
DCHECK(parsed_arguments[0]->IsObject());
blink::WebElement element =
blink::WebElement::FromV8Value(parsed_arguments[0]);
if (element.IsNull())
return v8::Null(script_context->isolate());
blink::WebNode shadow_root = element.OpenOrClosedShadowRoot();
if (shadow_root.IsNull())
return v8::Null(script_context->isolate());
return shadow_root.ToV8Value(script_context->v8_context()->Global(),
script_context->isolate());
}
} // namespace extensions
// Copyright 2020 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.
#ifndef EXTENSIONS_RENDERER_DOM_HOOKS_DELEGATE_H_
#define EXTENSIONS_RENDERER_DOM_HOOKS_DELEGATE_H_
#include <string>
#include "extensions/renderer/bindings/api_binding_hooks_delegate.h"
#include "v8/include/v8.h"
namespace extensions {
class ScriptContext;
// The custom hooks for the chrome.dom API.
class DOMHooksDelegate : public APIBindingHooksDelegate {
public:
DOMHooksDelegate();
~DOMHooksDelegate() override;
DOMHooksDelegate(const DOMHooksDelegate&) = delete;
DOMHooksDelegate& operator=(const DOMHooksDelegate&) = delete;
// APIBindingHooksDelegate:
APIBindingHooks::RequestResult HandleRequest(
const std::string& method_name,
const APISignature* signature,
v8::Local<v8::Context> context,
std::vector<v8::Local<v8::Value>>* arguments,
const APITypeReferenceMap& refs) override;
private:
v8::Local<v8::Value> OpenOrClosedShadowRoot(
ScriptContext* script_context,
const std::vector<v8::Local<v8::Value>>& parsed_arguments);
};
} // namespace extensions
#endif // EXTENSIONS_RENDERER_DOM_HOOKS_DELEGATE_H_
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "extensions/renderer/console.h" #include "extensions/renderer/console.h"
#include "extensions/renderer/content_setting.h" #include "extensions/renderer/content_setting.h"
#include "extensions/renderer/declarative_content_hooks_delegate.h" #include "extensions/renderer/declarative_content_hooks_delegate.h"
#include "extensions/renderer/dom_hooks_delegate.h"
#include "extensions/renderer/extension_frame_helper.h" #include "extensions/renderer/extension_frame_helper.h"
#include "extensions/renderer/extension_interaction_provider.h" #include "extensions/renderer/extension_interaction_provider.h"
#include "extensions/renderer/extension_js_runner.h" #include "extensions/renderer/extension_js_runner.h"
...@@ -471,8 +470,6 @@ NativeExtensionBindingsSystem::NativeExtensionBindingsSystem( ...@@ -471,8 +470,6 @@ NativeExtensionBindingsSystem::NativeExtensionBindingsSystem(
->SetDelegate(std::make_unique<WebRequestHooks>()); ->SetDelegate(std::make_unique<WebRequestHooks>());
api_system_.GetHooksForAPI("declarativeContent") api_system_.GetHooksForAPI("declarativeContent")
->SetDelegate(std::make_unique<DeclarativeContentHooksDelegate>()); ->SetDelegate(std::make_unique<DeclarativeContentHooksDelegate>());
api_system_.GetHooksForAPI("dom")->SetDelegate(
std::make_unique<DOMHooksDelegate>());
api_system_.GetHooksForAPI("i18n")->SetDelegate( api_system_.GetHooksForAPI("i18n")->SetDelegate(
std::make_unique<I18nHooksDelegate>()); std::make_unique<I18nHooksDelegate>());
api_system_.GetHooksForAPI("runtime")->SetDelegate( api_system_.GetHooksForAPI("runtime")->SetDelegate(
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "third_party/blink/public/web/web_node.h" #include "third_party/blink/public/web/web_node.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "v8/include/v8.h"
namespace gfx { namespace gfx {
class Size; class Size;
...@@ -53,9 +52,6 @@ class BLINK_EXPORT WebElement : public WebNode { ...@@ -53,9 +52,6 @@ class BLINK_EXPORT WebElement : public WebNode {
WebElement() : WebNode() {} WebElement() : WebNode() {}
WebElement(const WebElement& e) = default; WebElement(const WebElement& e) = default;
// Returns the empty WebElement if the argument doesn't represent an Element.
static WebElement FromV8Value(v8::Local<v8::Value>);
WebElement& operator=(const WebElement& e) { WebElement& operator=(const WebElement& e) {
WebNode::Assign(e); WebNode::Assign(e);
return *this; return *this;
...@@ -89,9 +85,6 @@ class BLINK_EXPORT WebElement : public WebNode { ...@@ -89,9 +85,6 @@ class BLINK_EXPORT WebElement : public WebNode {
// element has no ShadowRoot or has a UA ShadowRoot. // element has no ShadowRoot or has a UA ShadowRoot.
WebNode ShadowRoot() const; WebNode ShadowRoot() const;
// Returns the open shadow root or the closed shadow root.
WebNode OpenOrClosedShadowRoot();
// Returns the bounds of the element in Visual Viewport. The bounds // Returns the bounds of the element in Visual Viewport. The bounds
// have been adjusted to include any transformations, including page scale. // have been adjusted to include any transformations, including page scale.
// This function will update the layout if required. // This function will update the layout if required.
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "third_party/blink/public/platform/web_private_ptr.h" #include "third_party/blink/public/platform/web_private_ptr.h"
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/public/platform/web_vector.h"
#include "v8/include/v8.h"
namespace blink { namespace blink {
...@@ -105,9 +104,6 @@ class BLINK_EXPORT WebNode { ...@@ -105,9 +104,6 @@ class BLINK_EXPORT WebNode {
bool IsInsideFocusableElementOrARIAWidget() const; bool IsInsideFocusableElementOrARIAWidget() const;
v8::Local<v8::Value> ToV8Value(v8::Local<v8::Object> creation_context,
v8::Isolate*);
template <typename T> template <typename T>
T To(); T To();
template <typename T> template <typename T>
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "third_party/blink/public/web/web_element.h" #include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/platform/web_rect.h" #include "third_party/blink/public/platform/web_rect.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_element.h"
#include "third_party/blink/renderer/core/css/css_computed_style_declaration.h" #include "third_party/blink/renderer/core/css/css_computed_style_declaration.h"
#include "third_party/blink/renderer/core/css/css_property_names.h" #include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
...@@ -51,12 +50,6 @@ ...@@ -51,12 +50,6 @@
namespace blink { namespace blink {
WebElement WebElement::FromV8Value(v8::Local<v8::Value> value) {
Element* element =
V8Element::ToImplWithTypeCheck(v8::Isolate::GetCurrent(), value);
return WebElement(element);
}
bool WebElement::IsFormControlElement() const { bool WebElement::IsFormControlElement() const {
return ConstUnwrap<Element>()->IsFormControlElement(); return ConstUnwrap<Element>()->IsFormControlElement();
} }
...@@ -154,14 +147,6 @@ WebNode WebElement::ShadowRoot() const { ...@@ -154,14 +147,6 @@ WebNode WebElement::ShadowRoot() const {
return WebNode(root); return WebNode(root);
} }
WebNode WebElement::OpenOrClosedShadowRoot() {
if (IsNull())
return WebNode();
auto* root = ConstUnwrap<Element>()->AuthorShadowRoot();
return WebNode(root);
}
WebRect WebElement::BoundsInViewport() const { WebRect WebElement::BoundsInViewport() const {
return ConstUnwrap<Element>()->BoundsInViewport(); return ConstUnwrap<Element>()->BoundsInViewport();
} }
......
...@@ -151,16 +151,6 @@ bool WebNode::IsInsideFocusableElementOrARIAWidget() const { ...@@ -151,16 +151,6 @@ bool WebNode::IsInsideFocusableElementOrARIAWidget() const {
*this->ConstUnwrap<Node>()); *this->ConstUnwrap<Node>());
} }
v8::Local<v8::Value> WebNode::ToV8Value(v8::Local<v8::Object> creation_context,
v8::Isolate* isolate) {
// We no longer use |creation_context| because it's often misused and points
// to a context faked by user script.
DCHECK(creation_context->CreationContext() == isolate->GetCurrentContext());
if (!private_.Get())
return v8::Local<v8::Value>();
return ToV8(private_.Get(), isolate->GetCurrentContext()->Global(), isolate);
}
bool WebNode::IsElementNode() const { bool WebNode::IsElementNode() const {
return private_->IsElementNode(); return private_->IsElementNode();
} }
......
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