Bug 1513876 - Implement register a toplevel window global actor. r=nika

Implement register a toplevel window global actor.

Differential Revision: https://phabricator.services.mozilla.com/D15101

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Dai 2019-01-03 16:45:42 +00:00
Родитель 4f56e9160c
Коммит e65b6abd33
8 изменённых файлов: 145 добавлений и 1 удалений

Просмотреть файл

@ -19,6 +19,7 @@
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/IdleDeadline.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "mozilla/dom/ReportingHeader.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/WindowBinding.h" // For IdleRequestCallback/Options
@ -770,5 +771,14 @@ constexpr auto kSkipSelfHosted = JS::SavedFrameSelfHosted::Exclude;
NS_ConvertUTF16toUTF8(aOrigin));
}
/* static */ void ChromeUtils::RegisterWindowActor(
const GlobalObject& aGlobal, const nsAString& aName,
const WindowActorOptions& aOptions, ErrorResult& aRv) {
MOZ_ASSERT(XRE_IsParentProcess());
RefPtr<JSWindowActorService> service = JSWindowActorService::GetSingleton();
service->RegisterWindowActor(aName, aOptions, aRv);
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -27,6 +27,7 @@ struct IdleRequestOptions;
class MozQueryInterface;
class PrecompiledScript;
class Promise;
struct WindowActorOptions;
class ChromeUtils {
private:
@ -172,6 +173,11 @@ class ChromeUtils {
static bool HasReportingHeaderForOrigin(GlobalObject& global,
const nsAString& aOrigin,
ErrorResult& aRv);
static void RegisterWindowActor(const GlobalObject& aGlobal,
const nsAString& aName,
const WindowActorOptions& aOptions,
ErrorResult& aRv);
};
} // namespace dom

Просмотреть файл

@ -379,6 +379,9 @@ partial namespace ChromeUtils {
[ChromeOnly, Throws]
boolean hasReportingHeaderForOrigin(DOMString aOrigin);
[ChromeOnly, Throws]
void registerWindowActor(DOMString aName, WindowActorOptions aOptions);
};
/**
@ -515,6 +518,17 @@ dictionary Base64URLEncodeOptions {
required boolean pad;
};
dictionary WindowActorOptions {
/** This fields are used for configuring individual sides of the actor. */
required WindowActorSidedOptions parent;
required WindowActorSidedOptions child;
};
dictionary WindowActorSidedOptions {
/** The module path which should be loaded for the actor on this side. */
required DOMString moduleURI;
};
enum Base64URLDecodePadding {
/**
* Fails decoding if the input is unpadded. RFC 4648, section 3.2 requires

Просмотреть файл

@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/JSWindowActorService.h"
#include "mozilla/StaticPtr.h"
namespace mozilla {
namespace dom {
struct WindowActorOptions;
namespace {
StaticRefPtr<JSWindowActorService> gJSWindowActorService;
}
JSWindowActorService::JSWindowActorService() {
MOZ_ASSERT(XRE_IsParentProcess());
}
JSWindowActorService::~JSWindowActorService() {
MOZ_ASSERT(XRE_IsParentProcess());
}
/* static */ already_AddRefed<JSWindowActorService>
JSWindowActorService::GetSingleton() {
if (!gJSWindowActorService) {
gJSWindowActorService = new JSWindowActorService();
ClearOnShutdown(&gJSWindowActorService);
}
RefPtr<JSWindowActorService> service = gJSWindowActorService.get();
return service.forget();
}
void JSWindowActorService::RegisterWindowActor(
const nsAString& aName, const WindowActorOptions& aOptions,
ErrorResult& aRv) {
MOZ_ASSERT(XRE_IsParentProcess());
auto entry = mDescriptors.LookupForAdd(aName);
if (entry) {
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
entry.OrInsert([&] { return &aOptions; });
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,36 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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_JSWindowActorService_h
#define mozilla_dom_JSWindowActorService_h
#include "nsDataHashtable.h"
namespace mozilla {
namespace dom {
struct WindowActorOptions;
class JSWindowActorService final {
public:
NS_INLINE_DECL_REFCOUNTING(JSWindowActorService)
static already_AddRefed<JSWindowActorService> GetSingleton();
void RegisterWindowActor(const nsAString& aName,
const WindowActorOptions& aOptions,
ErrorResult& aRv);
private:
JSWindowActorService();
~JSWindowActorService();
nsDataHashtable<nsStringHashKey, const WindowActorOptions*> mDescriptors;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSWindowActorService_h

Просмотреть файл

@ -40,6 +40,7 @@ EXPORTS.mozilla.dom += [
'CPOWManagerGetter.h',
'DocShellMessageUtils.h',
'FilePickerParent.h',
'JSWindowActorService.h',
'MemoryReportRequest.h',
'nsIContentChild.h',
'nsIContentParent.h',
@ -72,6 +73,7 @@ UNIFIED_SOURCES += [
'ContentProcessManager.cpp',
'DocShellMessageUtils.cpp',
'FilePickerParent.cpp',
'JSWindowActorService.cpp',
'MemMapSnapshot.cpp',
'MemoryReportRequest.cpp',
'MMPrinter.cpp',

Просмотреть файл

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(function test_registerWindowActor() {
let windowActorOptions = {
parent: {
moduleURI: "resource:///actors/TestParent.jsm"
},
child: {
moduleURI: "resource:///actors/TestChild.jsm"
},
};
Assert.ok(ChromeUtils, "Should be able to get the ChromeUtils interface");
ChromeUtils.registerWindowActor("Test", windowActorOptions);
Assert.ok(true);
Assert.throws(() =>
ChromeUtils.registerWindowActor("Test", windowActorOptions),
/NotSupportedError/,
"Should throw if register duplicate name.");
});

Просмотреть файл

@ -1,2 +1,2 @@
[test_registerWindowActor.js]
[test_sharedMap.js]