diff options
author | Moonchild <moonchild@palemoon.org> | 2021-08-15 11:45:53 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-08-15 14:31:05 +0000 |
commit | 8226d379d275f6cc79c4bbd1b3d33dfde4df3e78 (patch) | |
tree | 8cf24927ca044ba2c278fe540ef096186a62b40b | |
parent | 02882c368084ffff532d185571910bbe4f052531 (diff) | |
download | uxp-8226d379d275f6cc79c4bbd1b3d33dfde4df3e78.tar.gz |
Issue #1797 - Implement WindowOrWorkerGlobalScope.originRELBASE_20210817RC_20210815
Resolves #1797
-rw-r--r-- | dom/base/nsGlobalWindow.cpp | 7 | ||||
-rw-r--r-- | dom/base/nsGlobalWindow.h | 1 | ||||
-rw-r--r-- | dom/webidl/WindowOrWorkerGlobalScope.webidl | 5 | ||||
-rw-r--r-- | dom/workers/WorkerPrivate.cpp | 3 | ||||
-rw-r--r-- | dom/workers/WorkerPrivate.h | 6 | ||||
-rw-r--r-- | dom/workers/WorkerScope.cpp | 7 | ||||
-rw-r--r-- | dom/workers/WorkerScope.h | 3 | ||||
-rw-r--r-- | dom/workers/Workers.h | 1 |
8 files changed, 30 insertions, 3 deletions
diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 293a522efe..fa2f4ad798 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -9892,6 +9892,13 @@ nsGlobalWindow::Btoa(const nsAString& aBinaryData, aError = nsContentUtils::Btoa(aBinaryData, aAsciiBase64String); } +void +nsGlobalWindow::GetOrigin(nsAString& aOrigin) +{ + MOZ_ASSERT(IsInnerWindow()); + nsContentUtils::GetUTFOrigin(GetPrincipal(), aOrigin); +} + //***************************************************************************** // nsGlobalWindow::nsIDOMEventTarget //***************************************************************************** diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index c9c661dd53..00ac023fce 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -958,6 +958,7 @@ public: mozilla::ErrorResult& aError); void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String, mozilla::ErrorResult& aError); + void GetOrigin(nsAString& aOrigin); mozilla::dom::DOMStorage* GetSessionStorage(mozilla::ErrorResult& aError); mozilla::dom::DOMStorage* GetLocalStorage(mozilla::ErrorResult& aError); diff --git a/dom/webidl/WindowOrWorkerGlobalScope.webidl b/dom/webidl/WindowOrWorkerGlobalScope.webidl index 8f0d0029ff..dddf2d17c4 100644 --- a/dom/webidl/WindowOrWorkerGlobalScope.webidl +++ b/dom/webidl/WindowOrWorkerGlobalScope.webidl @@ -13,9 +13,8 @@ // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin [NoInterfaceObject, Exposed=(Window,Worker)] interface WindowOrWorkerGlobalScope { - // XXXbz We don't implement 'origin' yet on either window or worker globals. - // See bug 1306170. - // [Replaceable] readonly attribute USVString origin; + // .origin on Window or Worker globals + [Replaceable] readonly attribute USVString origin; // base64 utility methods [Throws] diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 5edf7dc4a5..1d9459cd07 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1759,6 +1759,7 @@ WorkerLoadInfo::StealFrom(WorkerLoadInfo& aOther) mPrincipalInfo = aOther.mPrincipalInfo.forget(); mDomain = aOther.mDomain; + mOrigin = aOther.mOrigin; mServiceWorkerCacheName = aOther.mServiceWorkerCacheName; mWindowID = aOther.mWindowID; mServiceWorkerID = aOther.mServiceWorkerID; @@ -3623,6 +3624,8 @@ WorkerPrivateParent<Derived>::SetPrincipal(nsIPrincipal* aPrincipal, mLoadInfo.mPrincipalInfo = new PrincipalInfo(); mLoadInfo.mOriginAttributes = nsContentUtils::GetOriginAttributes(aLoadGroup); + nsContentUtils::GetUTFOrigin(aPrincipal, mLoadInfo.mOrigin); + MOZ_ALWAYS_SUCCEEDS( PrincipalToPrincipalInfo(aPrincipal, mLoadInfo.mPrincipalInfo)); } diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index ee84448068..b638c1ef11 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -624,6 +624,12 @@ public: return mLoadInfo.mPrincipal; } + const nsAString& + Origin() const + { + return mLoadInfo.mOrigin; + } + nsILoadGroup* GetLoadGroup() const { diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index 081f0f1065..ec42364b52 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -357,6 +357,13 @@ WorkerGlobalScope::Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& } void +WorkerGlobalScope::GetOrigin(nsAString& aOrigin) const +{ + mWorkerPrivate->AssertIsOnWorkerThread(); + aOrigin = mWorkerPrivate->Origin(); +} + +void WorkerGlobalScope::Dump(const Optional<nsAString>& aString) const { mWorkerPrivate->AssertIsOnWorkerThread(); diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h index 43b6d633ca..8d06152da2 100644 --- a/dom/workers/WorkerScope.h +++ b/dom/workers/WorkerScope.h @@ -145,6 +145,9 @@ public: void Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const; + void + GetOrigin(nsAString& aOrigin) const; + IMPL_EVENT_HANDLER(online) IMPL_EVENT_HANDLER(offline) diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index b7d75b09c8..6b0a0158d2 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -245,6 +245,7 @@ struct WorkerLoadInfo nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo; nsCString mDomain; + nsString mOrigin; // Derived from mPrincipal; can be used on worker threads. nsString mServiceWorkerCacheName; |