зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1275833 - Add window.customElements and CustomElementsRegistry interface for custom element v1. r=smaug, wchen
--HG-- extra : rebase_source : 5bed500eee0d4902703e4e2159e291779ff69ab5
This commit is contained in:
Родитель
b0b2cf9184
Коммит
7f2bb4c2c9
|
@ -0,0 +1,98 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/CustomElementsRegistry.h"
|
||||
#include "mozilla/dom/CustomElementsRegistryBinding.h"
|
||||
#include "mozilla/dom/WebComponentsBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
|
||||
// Only needed for refcounted objects.
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CustomElementsRegistry, mWindow)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(CustomElementsRegistry)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(CustomElementsRegistry)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CustomElementsRegistry)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
/* static */ bool
|
||||
CustomElementsRegistry::IsCustomElementsEnabled(JSContext* aCx, JSObject* aObject)
|
||||
{
|
||||
JS::Rooted<JSObject*> obj(aCx, aObject);
|
||||
if (Preferences::GetBool("dom.webcomponents.customelements.enabled") ||
|
||||
nsDocument::IsWebComponentsEnabled(aCx, obj)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<CustomElementsRegistry>
|
||||
CustomElementsRegistry::Create(nsPIDOMWindowInner* aWindow)
|
||||
{
|
||||
MOZ_ASSERT(aWindow);
|
||||
MOZ_ASSERT(aWindow->IsInnerWindow());
|
||||
|
||||
if (!aWindow->GetDocShell()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<CustomElementsRegistry> customElementsRegistry =
|
||||
new CustomElementsRegistry(aWindow);
|
||||
return customElementsRegistry.forget();
|
||||
}
|
||||
|
||||
CustomElementsRegistry::CustomElementsRegistry(nsPIDOMWindowInner* aWindow)
|
||||
: mWindow(aWindow)
|
||||
{
|
||||
}
|
||||
|
||||
CustomElementsRegistry::~CustomElementsRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
JSObject*
|
||||
CustomElementsRegistry::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return CustomElementsRegistryBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
nsISupports* CustomElementsRegistry::GetParentObject() const
|
||||
{
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
void CustomElementsRegistry::Define(const nsAString& aName,
|
||||
Function& aFunctionConstructor,
|
||||
const ElementDefinitionOptions& aOptions,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
// TODO: This function will be implemented in bug 1275835
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
void
|
||||
CustomElementsRegistry::Get(JSContext* aCx, const nsAString& aName,
|
||||
JS::MutableHandle<JS::Value> aRetVal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
// TODO: This function will be implemented in bug 1275838
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
CustomElementsRegistry::WhenDefined(const nsAString& name, ErrorResult& aRv)
|
||||
{
|
||||
// TODO: This function will be implemented in bug 1275839
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,61 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_CustomElementsRegistry_h
|
||||
#define mozilla_dom_CustomElementsRegistry_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "mozilla/dom/FunctionBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
struct ElementDefinitionOptions;
|
||||
struct LifecycleCallbacks;
|
||||
class Function;
|
||||
class Promise;
|
||||
|
||||
class CustomElementsRegistry final : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CustomElementsRegistry)
|
||||
|
||||
public:
|
||||
static bool IsCustomElementsEnabled(JSContext* aCx, JSObject* aObject);
|
||||
static already_AddRefed<CustomElementsRegistry> Create(nsPIDOMWindowInner* aWindow);
|
||||
already_AddRefed<nsIDocument> GetOwnerDocument() const;
|
||||
|
||||
private:
|
||||
explicit CustomElementsRegistry(nsPIDOMWindowInner* aWindow);
|
||||
~CustomElementsRegistry();
|
||||
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
||||
|
||||
public:
|
||||
nsISupports* GetParentObject() const;
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void Define(const nsAString& aName, Function& aFunctionConstructor,
|
||||
const ElementDefinitionOptions& aOptions, ErrorResult& aRv);
|
||||
|
||||
void Get(JSContext* cx, const nsAString& name,
|
||||
JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise> WhenDefined(const nsAString& name, ErrorResult& aRv);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
#endif // mozilla_dom_CustomElementsRegistry_h
|
|
@ -156,6 +156,7 @@ EXPORTS.mozilla.dom += [
|
|||
'ChromeNodeList.h',
|
||||
'ChromeUtils.h',
|
||||
'Comment.h',
|
||||
'CustomElementsRegistry.h',
|
||||
'DirectionalityUtils.h',
|
||||
'DocumentFragment.h',
|
||||
'DocumentType.h',
|
||||
|
@ -216,6 +217,7 @@ UNIFIED_SOURCES += [
|
|||
'ChromeUtils.cpp',
|
||||
'Comment.cpp',
|
||||
'Crypto.cpp',
|
||||
'CustomElementsRegistry.cpp',
|
||||
'DirectionalityUtils.cpp',
|
||||
'DocumentFragment.cpp',
|
||||
'DocumentType.cpp',
|
||||
|
|
|
@ -4768,7 +4768,8 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
|
|||
}
|
||||
|
||||
MaybeRescheduleAnimationFrameNotifications();
|
||||
if (Preferences::GetBool("dom.webcomponents.enabled")) {
|
||||
if (Preferences::GetBool("dom.webcomponents.enabled") ||
|
||||
Preferences::GetBool("dom.webcomponents.customelements.enabled")) {
|
||||
mRegistry = new Registry();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1565,6 +1565,7 @@ nsGlobalWindow::CleanUp()
|
|||
mScrollbars = nullptr;
|
||||
mLocation = nullptr;
|
||||
mHistory = nullptr;
|
||||
mCustomElements = nullptr;
|
||||
mFrames = nullptr;
|
||||
mWindowUtils = nullptr;
|
||||
mApplicationCache = nullptr;
|
||||
|
@ -1695,6 +1696,7 @@ nsGlobalWindow::FreeInnerObjects()
|
|||
|
||||
mLocation = nullptr;
|
||||
mHistory = nullptr;
|
||||
mCustomElements = nullptr;
|
||||
|
||||
if (mNavigator) {
|
||||
mNavigator->OnNavigation();
|
||||
|
@ -1877,6 +1879,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocation)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHistory)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCustomElements)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocalStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSessionStorage)
|
||||
|
@ -1950,6 +1953,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
|
|||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocation)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHistory)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCustomElements)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocalStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSessionStorage)
|
||||
if (tmp->mApplicationCache) {
|
||||
|
@ -3832,6 +3836,17 @@ nsGlobalWindow::GetHistory(ErrorResult& aError)
|
|||
return mHistory;
|
||||
}
|
||||
|
||||
CustomElementsRegistry*
|
||||
nsGlobalWindow::CustomElements()
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(IsInnerWindow());
|
||||
if (!mCustomElements) {
|
||||
mCustomElements = CustomElementsRegistry::Create(AsInner());
|
||||
}
|
||||
|
||||
return mCustomElements;
|
||||
}
|
||||
|
||||
Performance*
|
||||
nsPIDOMWindowInner::GetPerformance()
|
||||
{
|
||||
|
|
|
@ -106,6 +106,7 @@ class BarProp;
|
|||
struct ChannelPixelLayout;
|
||||
class Console;
|
||||
class Crypto;
|
||||
class CustomElementsRegistry;
|
||||
class External;
|
||||
class Function;
|
||||
class Gamepad;
|
||||
|
@ -877,6 +878,7 @@ public:
|
|||
nsLocation* GetLocation(mozilla::ErrorResult& aError);
|
||||
nsIDOMLocation* GetLocation() override;
|
||||
nsHistory* GetHistory(mozilla::ErrorResult& aError);
|
||||
mozilla::dom::CustomElementsRegistry* CustomElements() override;
|
||||
mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError);
|
||||
mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError);
|
||||
mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError);
|
||||
|
@ -1837,6 +1839,7 @@ protected:
|
|||
uint32_t mTimeoutFiringDepth;
|
||||
RefPtr<nsLocation> mLocation;
|
||||
RefPtr<nsHistory> mHistory;
|
||||
RefPtr<mozilla::dom::CustomElementsRegistry> mCustomElements;
|
||||
|
||||
// These member variables are used on both inner and the outer windows.
|
||||
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
|
||||
|
|
|
@ -44,6 +44,7 @@ class AudioContext;
|
|||
class Element;
|
||||
class Performance;
|
||||
class ServiceWorkerRegistration;
|
||||
class CustomElementsRegistry;
|
||||
} // namespace dom
|
||||
namespace gfx {
|
||||
class VRDeviceProxy;
|
||||
|
@ -96,7 +97,7 @@ public:
|
|||
const nsPIDOMWindowOuter* AsOuter() const;
|
||||
|
||||
virtual nsPIDOMWindowOuter* GetPrivateRoot() = 0;
|
||||
|
||||
virtual mozilla::dom::CustomElementsRegistry* CustomElements() = 0;
|
||||
// Outer windows only.
|
||||
virtual void ActivateOrDeactivate(bool aActivate) = 0;
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://html.spec.whatwg.org/#dom-window-customelements
|
||||
[Func="CustomElementsRegistry::IsCustomElementsEnabled"]
|
||||
interface CustomElementsRegistry {
|
||||
[Throws]
|
||||
void define(DOMString name, Function functionConstructor,
|
||||
optional ElementDefinitionOptions options);
|
||||
[Throws]
|
||||
any get(DOMString name);
|
||||
[Throws]
|
||||
Promise<void> whenDefined(DOMString name);
|
||||
};
|
||||
|
||||
dictionary ElementDefinitionOptions {
|
||||
DOMString extends;
|
||||
};
|
||||
|
|
@ -261,7 +261,8 @@ partial interface Document {
|
|||
|
||||
//http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn-document-register
|
||||
partial interface Document {
|
||||
[Throws, Func="nsDocument::IsWebComponentsEnabled"]
|
||||
// this is deprecated from CustomElements v0
|
||||
[Throws, Func="CustomElementsRegistry::IsCustomElementsEnabled"]
|
||||
object registerElement(DOMString name, optional ElementRegistrationOptions options);
|
||||
};
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ typedef any Transferable;
|
|||
[PutForwards=href, Unforgeable, Throws,
|
||||
CrossOriginReadable, CrossOriginWritable] readonly attribute Location? location;
|
||||
[Throws] readonly attribute History history;
|
||||
[Func="CustomElementsRegistry::IsCustomElementsEnabled"]
|
||||
readonly attribute CustomElementsRegistry customElements;
|
||||
[Replaceable, Throws] readonly attribute BarProp locationbar;
|
||||
[Replaceable, Throws] readonly attribute BarProp menubar;
|
||||
[Replaceable, Throws] readonly attribute BarProp personalbar;
|
||||
|
|
|
@ -107,6 +107,7 @@ WEBIDL_FILES = [
|
|||
'CSSTransition.webidl',
|
||||
'CSSValue.webidl',
|
||||
'CSSValueList.webidl',
|
||||
'CustomElementsRegistry.webidl',
|
||||
'DataContainerEvent.webidl',
|
||||
'DataTransfer.webidl',
|
||||
'DataTransferItem.webidl',
|
||||
|
|
|
@ -1179,6 +1179,7 @@ pref("dom.event.highrestimestamp.enabled", false);
|
|||
#endif
|
||||
|
||||
pref("dom.webcomponents.enabled", false);
|
||||
pref("dom.webcomponents.customelements.enabled", false);
|
||||
|
||||
pref("javascript.enabled", true);
|
||||
pref("javascript.options.strict", false);
|
||||
|
|
|
@ -50,6 +50,7 @@ user_pref("media.gmp-manager.url.override", "http://%(server)s/dummy-gmp-manager
|
|||
user_pref("dom.w3c_touch_events.enabled", 1);
|
||||
user_pref("dom.undo_manager.enabled", true);
|
||||
user_pref("dom.webcomponents.enabled", true);
|
||||
user_pref("dom.webcomponents.customelements.enabled", true);
|
||||
user_pref("dom.htmlimports.enabled", true);
|
||||
// Existing tests assume there is no font size inflation.
|
||||
user_pref("font.size.inflation.emPerLine", 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче