зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1748313 - Fix unified build failures hit after adding webidl bindings for the proxy WebExtensions API namespace. r=asuth,willdurand
Differential Revision: https://phabricator.services.mozilla.com/D167599
This commit is contained in:
Родитель
783c6acbee
Коммит
63e96cf5d1
|
@ -38,72 +38,6 @@ using mozilla::ipc::PBackgroundChild;
|
|||
|
||||
namespace mozilla::dom {
|
||||
|
||||
static bool IsServiceWorkersTestingEnabledInWindow(JSObject* const aGlobal) {
|
||||
if (const nsCOMPtr<nsPIDOMWindowInner> innerWindow =
|
||||
Navigator::GetWindowFromGlobal(aGlobal)) {
|
||||
if (auto* bc = innerWindow->GetBrowsingContext()) {
|
||||
return bc->Top()->ServiceWorkersTestingEnabled();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsInPrivateBrowsing(JSContext* const aCx) {
|
||||
if (const nsCOMPtr<nsIGlobalObject> global = xpc::CurrentNativeGlobal(aCx)) {
|
||||
if (const nsCOMPtr<nsIPrincipal> principal = global->PrincipalOrNull()) {
|
||||
return principal->GetPrivateBrowsingId() > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aGlobal) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!StaticPrefs::dom_serviceWorkers_enabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// xpc::CurrentNativeGlobal below requires rooting
|
||||
JS::Rooted<JSObject*> global(aCx, aGlobal);
|
||||
|
||||
if (IsInPrivateBrowsing(aCx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow a webextension principal to register a service worker script with
|
||||
// a moz-extension url only if 'extensions.service_worker_register.allowed'
|
||||
// is true.
|
||||
if (!StaticPrefs::extensions_serviceWorkerRegister_allowed()) {
|
||||
nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(aCx);
|
||||
if (principal && BasePrincipal::Cast(principal)->AddonPolicy()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSecureContextOrObjectIsFromSecureContext(aCx, global)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return StaticPrefs::dom_serviceWorkers_testing_enabled() ||
|
||||
IsServiceWorkersTestingEnabledInWindow(global);
|
||||
}
|
||||
|
||||
bool ServiceWorkerVisible(JSContext* aCx, JSObject* aGlobal) {
|
||||
if (NS_IsMainThread()) {
|
||||
// We want to expose ServiceWorker interface only when
|
||||
// navigator.serviceWorker is available. Currently it may not be available
|
||||
// with some reasons:
|
||||
// 1. navigator.serviceWorker is not supported in workers. (bug 1131324)
|
||||
return ServiceWorkersEnabled(aCx, aGlobal);
|
||||
}
|
||||
|
||||
// We are already in ServiceWorker and interfaces need to be exposed for e.g.
|
||||
// globalThis.registration.serviceWorker. Note that navigator.serviceWorker
|
||||
// is still not supported. (bug 1131324)
|
||||
return IS_INSTANCE_OF(ServiceWorkerGlobalScope, aGlobal);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<ServiceWorker> ServiceWorker::Create(
|
||||
nsIGlobalObject* aOwner, const ServiceWorkerDescriptor& aDescriptor) {
|
||||
|
|
|
@ -31,10 +31,6 @@ struct StructuredSerializeOptions;
|
|||
} \
|
||||
}
|
||||
|
||||
bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
bool ServiceWorkerVisible(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
class ServiceWorker final : public DOMEventTargetHelper {
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_SERVICEWORKER_IID)
|
||||
|
|
|
@ -9,7 +9,12 @@
|
|||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
#include "mozilla/StaticPrefs_extensions.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/ClientInfo.h"
|
||||
#include "mozilla/dom/Navigator.h"
|
||||
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
|
||||
#include "mozilla/dom/ServiceWorkerRegistrarTypes.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIPrincipal.h"
|
||||
|
@ -18,6 +23,72 @@
|
|||
|
||||
namespace mozilla::dom {
|
||||
|
||||
static bool IsServiceWorkersTestingEnabledInWindow(JSObject* const aGlobal) {
|
||||
if (const nsCOMPtr<nsPIDOMWindowInner> innerWindow =
|
||||
Navigator::GetWindowFromGlobal(aGlobal)) {
|
||||
if (auto* bc = innerWindow->GetBrowsingContext()) {
|
||||
return bc->Top()->ServiceWorkersTestingEnabled();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsInPrivateBrowsing(JSContext* const aCx) {
|
||||
if (const nsCOMPtr<nsIGlobalObject> global = xpc::CurrentNativeGlobal(aCx)) {
|
||||
if (const nsCOMPtr<nsIPrincipal> principal = global->PrincipalOrNull()) {
|
||||
return principal->GetPrivateBrowsingId() > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aGlobal) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!StaticPrefs::dom_serviceWorkers_enabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// xpc::CurrentNativeGlobal below requires rooting
|
||||
JS::Rooted<JSObject*> global(aCx, aGlobal);
|
||||
|
||||
if (IsInPrivateBrowsing(aCx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow a webextension principal to register a service worker script with
|
||||
// a moz-extension url only if 'extensions.service_worker_register.allowed'
|
||||
// is true.
|
||||
if (!StaticPrefs::extensions_serviceWorkerRegister_allowed()) {
|
||||
nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(aCx);
|
||||
if (principal && BasePrincipal::Cast(principal)->AddonPolicy()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSecureContextOrObjectIsFromSecureContext(aCx, global)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return StaticPrefs::dom_serviceWorkers_testing_enabled() ||
|
||||
IsServiceWorkersTestingEnabledInWindow(global);
|
||||
}
|
||||
|
||||
bool ServiceWorkerVisible(JSContext* aCx, JSObject* aGlobal) {
|
||||
if (NS_IsMainThread()) {
|
||||
// We want to expose ServiceWorker interface only when
|
||||
// navigator.serviceWorker is available. Currently it may not be available
|
||||
// with some reasons:
|
||||
// 1. navigator.serviceWorker is not supported in workers. (bug 1131324)
|
||||
return ServiceWorkersEnabled(aCx, aGlobal);
|
||||
}
|
||||
|
||||
// We are already in ServiceWorker and interfaces need to be exposed for e.g.
|
||||
// globalThis.registration.serviceWorker. Note that navigator.serviceWorker
|
||||
// is still not supported. (bug 1131324)
|
||||
return IS_INSTANCE_OF(ServiceWorkerGlobalScope, aGlobal);
|
||||
}
|
||||
|
||||
bool ServiceWorkerRegistrationDataIsValid(
|
||||
const ServiceWorkerRegistrationData& aData) {
|
||||
return !aData.scope().IsEmpty() && !aData.currentWorkerURL().IsEmpty() &&
|
||||
|
|
|
@ -55,6 +55,10 @@ void ServiceWorkerScopeAndScriptAreValid(const ClientInfo& aClientInfo,
|
|||
nsIURI* aScopeURI, nsIURI* aScriptURI,
|
||||
ErrorResult& aRv);
|
||||
|
||||
bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
bool ServiceWorkerVisible(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -11,8 +11,11 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsTHashMap.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "mozilla/WeakPtr.h"
|
||||
#include "xpcpublic.h"
|
||||
|
||||
class nsIGlobalObject;
|
||||
class nsIURI;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
|
|
@ -5,12 +5,15 @@
|
|||
|
||||
#include "ExtensionTest.h"
|
||||
#include "ExtensionEventManager.h"
|
||||
#include "ExtensionAPICallFunctionNoReturn.h"
|
||||
|
||||
#include "js/Equality.h" // JS::StrictlyEqual
|
||||
#include "js/PropertyAndElement.h" // JS_GetProperty
|
||||
#include "mozilla/dom/ExtensionTestBinding.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "js/RegExp.h"
|
||||
#include "mozilla/dom/WorkerScope.h"
|
||||
#include "prenv.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace extensions {
|
||||
|
|
Загрузка…
Ссылка в новой задаче