Firstly we need to find a usable ScriptLoader for code in the content script sandbox, for that we use the normal ScriptLoader associated with DOMWindow wrapped by the sandbox. Secondly we need to execute the module in the global of the sandbox instead of the "ScriptGlobal" the ScriptLoader is actually associated with. The main behavior change here comes from using xpc::NativeGlobal in HostImportModuleDynamically and passing that global around inside ScriptFetchOptions. To ensure that content-scripts and the webpage don't share imported modules, the module map (mFetchingModules and mFetchedModules) now uses a complex key of <URI, Global>. The Global is a nullptr for normal imports from a webpage. Differential Revision: https://phabricator.services.mozilla.com/D107076
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
/* 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 ModuleMapKey_h__
|
|
#define ModuleMapKey_h__
|
|
|
|
#include "nsURIHashKey.h"
|
|
#include "nsIGlobalObject.h"
|
|
|
|
namespace mozilla::dom {
|
|
|
|
class ModuleMapKey : public nsURIHashKey {
|
|
public:
|
|
using KeyType = const ModuleMapKey&;
|
|
using KeyTypePointer = const ModuleMapKey*;
|
|
|
|
ModuleMapKey() = default;
|
|
ModuleMapKey(const nsIURI* aURI, nsIGlobalObject* aWebExtGlobal);
|
|
explicit ModuleMapKey(const ModuleMapKey* aKey);
|
|
ModuleMapKey(ModuleMapKey&& aToMove) noexcept;
|
|
|
|
ModuleMapKey& operator=(const ModuleMapKey& aOther) = default;
|
|
|
|
KeyType GetKey() const { return *this; }
|
|
KeyTypePointer GetKeyPointer() const { return this; }
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
bool KeyEquals(KeyTypePointer aOther) const;
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey);
|
|
|
|
private:
|
|
nsCOMPtr<nsIGlobalObject> mWebExtGlobal;
|
|
};
|
|
|
|
} // namespace mozilla::dom
|
|
|
|
#endif
|