Bug 1591892 - Expose {window, self}.crossOriginIsolated r=bzbarsky

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Yaron Tausky 2019-11-15 12:25:57 +00:00
Родитель 513f38c497
Коммит e65a2c3ebb
9 изменённых файлов: 30 добавлений и 8 удалений

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

@ -2359,7 +2359,7 @@ void nsGlobalWindowInner::UpdateTopInnerWindow() {
mTopInnerWindow->UpdateWebSocketCount(-(int32_t)mNumOfOpenWebSockets);
}
bool nsGlobalWindowInner::IsCrossOriginIsolated() const {
bool nsGlobalWindowInner::IsSharedMemoryAllowed() const {
MOZ_ASSERT(NS_IsMainThread());
if (StaticPrefs::
@ -2367,6 +2367,12 @@ bool nsGlobalWindowInner::IsCrossOriginIsolated() const {
return true;
}
return CrossOriginIsolated();
}
bool nsGlobalWindowInner::CrossOriginIsolated() const {
MOZ_ASSERT(NS_IsMainThread());
if (!StaticPrefs::dom_postMessage_sharedArrayBuffer_withCOOP_COEP()) {
return false;
}

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

@ -940,8 +940,10 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
return GetExtantDoc() && GetExtantDoc()->IsInSyncOperation();
}
bool IsSharedMemoryAllowed() const;
// https://whatpr.org/html/4734/structured-data.html#cross-origin-isolated
bool IsCrossOriginIsolated() const;
bool CrossOriginIsolated() const;
protected:
// Web IDL helpers

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

@ -6058,7 +6058,7 @@ void nsGlobalWindowOuter::PostMessageMozOuter(JSContext* aCx,
JS::CloneDataPolicy clonePolicy;
if (GetDocGroup() && callerInnerWindow &&
callerInnerWindow->IsCrossOriginIsolated()) {
callerInnerWindow->IsSharedMemoryAllowed()) {
clonePolicy.allowSharedMemory();
}
event->Write(aCx, aMessage, aTransfer, clonePolicy, aError);

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

@ -14,6 +14,7 @@
[Exposed=(Window,Worker)]
interface mixin WindowOrWorkerGlobalScope {
[Replaceable] readonly attribute USVString origin;
readonly attribute boolean crossOriginIsolated;
// base64 utility methods
[Throws]

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

@ -104,12 +104,12 @@ void Worker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
JS::CloneDataPolicy clonePolicy;
if (NS_IsMainThread()) {
nsGlobalWindowInner* win = nsContentUtils::CallerInnerWindow();
if (win && win->IsCrossOriginIsolated()) {
if (win && win->IsSharedMemoryAllowed()) {
clonePolicy.allowSharedMemory();
}
} else {
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
if (worker && worker->IsCrossOriginIsolated()) {
if (worker && worker->IsSharedMemoryAllowed()) {
clonePolicy.allowSharedMemory();
}
}

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

@ -3950,7 +3950,7 @@ void WorkerPrivate::PostMessageToParent(
}
JS::CloneDataPolicy clonePolicy;
if (IsCrossOriginIsolated()) {
if (IsSharedMemoryAllowed()) {
clonePolicy.allowSharedMemory();
}
runnable->Write(aCx, aMessage, transferable, clonePolicy, aRv);
@ -4974,7 +4974,7 @@ const nsAString& WorkerPrivate::Id() {
return mId;
}
bool WorkerPrivate::IsCrossOriginIsolated() const {
bool WorkerPrivate::IsSharedMemoryAllowed() const {
AssertIsOnWorkerThread();
if (StaticPrefs::
@ -4982,6 +4982,12 @@ bool WorkerPrivate::IsCrossOriginIsolated() const {
return true;
}
return CrossOriginIsolated();
}
bool WorkerPrivate::CrossOriginIsolated() const {
AssertIsOnWorkerThread();
if (!StaticPrefs::dom_postMessage_sharedArrayBuffer_withCOOP_COEP()) {
return false;
}

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

@ -896,8 +896,10 @@ class WorkerPrivate : public RelativeTimeline {
const nsID& AgentClusterId() const { return mAgentClusterId; }
bool IsSharedMemoryAllowed() const;
// https://whatpr.org/html/4734/structured-data.html#cross-origin-isolated
bool IsCrossOriginIsolated() const;
bool CrossOriginIsolated() const;
private:
WorkerPrivate(

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

@ -386,6 +386,10 @@ void WorkerGlobalScope::GetOrigin(nsAString& aOrigin) const {
aOrigin = mWorkerPrivate->Origin();
}
bool WorkerGlobalScope::CrossOriginIsolated() const {
return mWorkerPrivate->CrossOriginIsolated();
}
void WorkerGlobalScope::Atob(const nsAString& aAtob, nsAString& aOutput,
ErrorResult& aRv) const {
mWorkerPrivate->AssertIsOnWorkerThread();

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

@ -142,6 +142,7 @@ class WorkerGlobalScope : public DOMEventTargetHelper,
void ClearInterval(int32_t aHandle);
void GetOrigin(nsAString& aOrigin) const;
bool CrossOriginIsolated() const;
void Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const;
void Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const;