Commit 6d9c8f57 authored by Lucas Furukawa Gadani's avatar Lucas Furukawa Gadani Committed by Commit Bot

Portals: Add HTMLPortalElement.

This CL adds an HTMLPortalElement to represent portals, and creates a mojo
connection to the browser-exposed interface when the element is attached
to the document.

Bug: 865565
Change-Id: Ib4e8053969d3e7ec138db84aae211b9a97a19b3c
Reviewed-on: https://chromium-review.googlesource.com/1167111
Commit-Queue: Lucas Gadani <lfg@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583752}
parent 88ec13d7
......@@ -487,6 +487,9 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
FeaturesFromSwitch(command_line, switches::kDisableBlinkFeatures)) {
WebRuntimeFeatures::EnableFeatureFromString(feature, false);
}
WebRuntimeFeatures::EnablePortals(
base::FeatureList::IsEnabled(blink::features::kPortals));
};
} // namespace content
<!DOCTYPE html>
<title>Portals API test</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<body>
<script>
test(function() {
assert_true(document.createElement('portal') instanceof HTMLPortalElement);
}, "portal element exists")
</script>
</body>
......@@ -863,6 +863,7 @@ html element param
property valueType
html element picture
html element plaintext
html element portal
html element pre
property width
html element progress
......
......@@ -3416,6 +3416,9 @@ interface HTMLParamElement : HTMLElement
interface HTMLPictureElement : HTMLElement
attribute @@toStringTag
method constructor
interface HTMLPortalElement : HTMLElement
attribute @@toStringTag
method constructor
interface HTMLPreElement : HTMLElement
attribute @@toStringTag
getter width
......
......@@ -130,6 +130,7 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnablePermissionsAPI(bool);
BLINK_PLATFORM_EXPORT static void EnablePictureInPicture(bool);
BLINK_PLATFORM_EXPORT static void EnablePictureInPictureAPI(bool);
BLINK_PLATFORM_EXPORT static void EnablePortals(bool);
BLINK_PLATFORM_EXPORT static void EnablePreciseMemoryInfo(bool);
BLINK_PLATFORM_EXPORT static void EnablePreloadDefaultIsMetadata(bool);
BLINK_PLATFORM_EXPORT static void EnablePreloadImageSrcSetEnabled(bool);
......
......@@ -278,6 +278,7 @@ core_idl_files =
"html/forms/validity_state.idl",
"html/media/html_audio_element.idl",
"html/media/media_error.idl",
"html/portal/html_portal_element.idl",
"html/track/audio_track_list.idl",
"html/track/html_track_element.idl",
"html/track/text_track.idl",
......
......@@ -498,6 +498,8 @@ blink_core_sources("html") {
"media/picture_in_picture_interstitial.h",
"plugin_document.cc",
"plugin_document.h",
"portal/html_portal_element.cc",
"portal/html_portal_element.h",
"rel_list.cc",
"rel_list.h",
"shadow/details_marker_control.cc",
......
......@@ -358,6 +358,11 @@
name: "plaintext",
interfaceName: "HTMLElement",
},
{
name: "portal",
interfaceName: "HTMLPortalElement",
interfaceHeaderDir: "third_party/blink/renderer/core/html/portal",
},
"pre",
{
name: "progress",
......
// Copyright 2018 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 "third_party/blink/renderer/core/html/portal/html_portal_element.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/html_unknown_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
HTMLPortalElement::HTMLPortalElement(Document& document)
: HTMLFrameOwnerElement(HTMLNames::portalTag, document) {}
HTMLPortalElement::~HTMLPortalElement() {}
HTMLElement* HTMLPortalElement::Create(Document& document) {
if (RuntimeEnabledFeatures::PortalsEnabled())
return new HTMLPortalElement(document);
return HTMLUnknownElement::Create(HTMLNames::portalTag, document);
}
HTMLPortalElement::InsertionNotificationRequest HTMLPortalElement::InsertedInto(
ContainerNode* node) {
auto result = HTMLFrameOwnerElement::InsertedInto(node);
Document& document = GetDocument();
if (node->IsInDocumentTree() && document.IsHTMLDocument()) {
document.GetFrame()->GetInterfaceProvider().GetInterface(
mojo::MakeRequest(&portal_ptr_));
}
return result;
}
void HTMLPortalElement::RemovedFrom(ContainerNode* node) {
HTMLFrameOwnerElement::RemovedFrom(node);
Document& document = GetDocument();
if (node->IsInDocumentTree() && document.IsHTMLDocument()) {
portal_ptr_.reset();
}
}
} // namespace blink
// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_CORE_HTML_PORTAL_HTML_PORTAL_ELEMENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_PORTAL_HTML_PORTAL_ELEMENT_H_
#include "third_party/blink/public/mojom/portal/portal.mojom-blink.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
namespace blink {
class Document;
// The HTMLPortalElement implements the <portal> HTML element. The portal
// element can be used to embed another top-level browsing context, which can be
// activated using script. The portal element is still under development and not
// part of the HTML standard. It can be enabled by passing
// --enable-features=Portals. See
// https://github.com/KenjiBaheux/portals/blob/master/explainer.md for more
// details.
class CORE_EXPORT HTMLPortalElement : public HTMLFrameOwnerElement {
DEFINE_WRAPPERTYPEINFO();
public:
static HTMLElement* Create(Document&);
~HTMLPortalElement() override;
private:
explicit HTMLPortalElement(Document&);
// Node overrides
InsertionNotificationRequest InsertedInto(ContainerNode*) override;
void RemovedFrom(ContainerNode*) override;
// HTMLFrameOwnerElement overrides
ParsedFeaturePolicy ConstructContainerPolicy(Vector<String>*) const override {
return ParsedFeaturePolicy();
}
mojom::blink::PortalPtr portal_ptr_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_PORTAL_HTML_PORTAL_ELEMENT_H_
// Copyright 2018 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.
// https://github.com/KenjiBaheux/portals/blob/master/explainer.md
[HTMLConstructor, RuntimeEnabled=Portals]
interface HTMLPortalElement : HTMLElement {
};
......@@ -316,6 +316,10 @@ void WebRuntimeFeatures::EnablePictureInPictureAPI(bool enable) {
RuntimeEnabledFeatures::SetPictureInPictureAPIEnabled(enable);
}
void WebRuntimeFeatures::EnablePortals(bool enable) {
RuntimeEnabledFeatures::SetPortalsEnabled(enable);
}
void WebRuntimeFeatures::EnablePreloadDefaultIsMetadata(bool enable) {
RuntimeEnabledFeatures::SetPreloadDefaultIsMetadataEnabled(enable);
}
......
......@@ -941,6 +941,10 @@
name: "PictureInPictureControl",
status: "experimental",
},
{
name: "Portals",
status: "test",
},
{
name: "PostMessageOptions",
status: "experimental",
......
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