Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit ffdcf2e

Browse files
committed
Bug 1870807 - Amend test globals to allow checking the cookie jar. r=dom-storage-reviewers,timhuang,asuth
Differential Revision: https://phabricator.services.mozilla.com/D236999
1 parent 1426295 commit ffdcf2e

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

js/xpconnect/src/SandboxPrivate.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,20 @@ class SandboxPrivate final : public nsIGlobalObject,
7272
return GetWrapperPreserveColor();
7373
}
7474

75+
nsICookieJarSettings* GetCookieJarSettings() override {
76+
MOZ_ASSERT(NS_IsMainThread());
77+
return mCookieJarSettings;
78+
}
79+
7580
mozilla::StorageAccess GetStorageAccess() final {
7681
MOZ_ASSERT(NS_IsMainThread());
7782
if (mozilla::StaticPrefs::dom_serviceWorkers_testing_enabled()) {
7883
// XXX: This is a hack to workaround bug 1732159 and is not intended
7984
return mozilla::StorageAccess::eAllow;
8085
}
81-
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
82-
mozilla::net::CookieJarSettings::Create(mPrincipal);
86+
8387
return mozilla::StorageAllowedForServiceWorker(mPrincipal,
84-
cookieJarSettings);
88+
mCookieJarSettings);
8589
}
8690

8791
void ForgetGlobalObject(JSObject* obj) { ClearWrapper(obj); }
@@ -118,12 +122,17 @@ class SandboxPrivate final : public nsIGlobalObject,
118122
bool IsXPCSandbox() override { return true; }
119123

120124
private:
121-
explicit SandboxPrivate(nsIPrincipal* principal) : mPrincipal(principal) {}
125+
explicit SandboxPrivate(nsIPrincipal* principal)
126+
: mPrincipal(principal),
127+
mCookieJarSettings(
128+
mozilla::net::CookieJarSettings::Create(mPrincipal)) {}
122129

123130
virtual ~SandboxPrivate() = default;
124131

125132
nsCOMPtr<nsIPrincipal> mPrincipal;
126133

134+
nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
135+
127136
RefPtr<JS::loader::ModuleLoaderBase> mModuleLoader;
128137
};
129138

js/xpconnect/src/SystemGlobal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "js/HeapAPI.h"
2121

22+
class nsICookieJarSettings;
2223
class XPCWrappedNative;
2324

2425
// The shared system global (used by ChromeUtils.importESModule), and also
@@ -58,6 +59,11 @@ class SystemGlobal final : public nsIGlobalObject,
5859
return mModuleLoader;
5960
}
6061

62+
nsICookieJarSettings* GetCookieJarSettings() override {
63+
MOZ_ASSERT(NS_IsMainThread());
64+
return mCookieJarSettings;
65+
}
66+
6167
mozilla::StorageAccess GetStorageAccess() final {
6268
MOZ_ASSERT(NS_IsMainThread());
6369
return mozilla::StorageAccess::eAllow;
@@ -95,6 +101,7 @@ class SystemGlobal final : public nsIGlobalObject,
95101

96102
const nsID mAgentClusterId;
97103
nsCOMPtr<nsIPrincipal> mPrincipal;
104+
nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
98105
XPCWrappedNative* mWrapper;
99106

100107
RefPtr<JS::loader::ModuleLoaderBase> mModuleLoader;

js/xpconnect/src/XPCRuntimeService.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mozilla/dom/IndexedDatabaseManager.h"
1616
#include "mozilla/ipc/BackgroundUtils.h"
1717
#include "mozilla/ipc/PBackgroundSharedTypes.h"
18+
#include "mozilla/net/CookieJarSettings.h"
1819

1920
using namespace mozilla::dom;
2021

@@ -24,7 +25,8 @@ NS_IMPL_ISUPPORTS(SystemGlobal, nsIXPCScriptable, nsIGlobalObject, nsIClassInfo,
2425
SystemGlobal::SystemGlobal()
2526
: mAgentClusterId(nsID::GenerateUUID()),
2627
mPrincipal(nsContentUtils::GetSystemPrincipal()),
27-
mWrapper(nullptr){}
28+
mCookieJarSettings(mozilla::net::CookieJarSettings::Create(mPrincipal)),
29+
mWrapper(nullptr) {}
2830
// XXX(nika): It appears we don't have support for mayresolve hooks in
2931
// nsIXPCScriptable, and I don't really want to add it because I'd rather just
3032
// kill nsIXPCScriptable alltogether, so we don't use it here.
@@ -42,8 +44,7 @@ SystemGlobal::SystemGlobal()
4244
XPC_SCRIPTABLE_DONT_REFLECT_INTERFACE_NAMES)
4345
#include "xpc_map_end.h" /* This will #undef the above */
4446

45-
JSObject
46-
* SystemGlobal::GetGlobalJSObject() {
47+
JSObject* SystemGlobal::GetGlobalJSObject() {
4748
if (mWrapper) {
4849
return mWrapper->GetFlatJSObject();
4950
}

0 commit comments

Comments
 (0)