mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 1353867
- Change WindowProxy type. r=bzbarsky
Add a WindowProxyHolder type and generate binding code that takes or returns it whenever the WebIDL refers to the WindowProxy type. This patch just makes the WindowProxyHolder hold a strong reference to a nsPIDOMWindowOuter. Differential Revision: https://phabricator.services.mozilla.com/D12650 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f557e273ca
commit
a17049feac
@ -15,6 +15,10 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
template <typename>
|
||||
struct Nullable;
|
||||
class WindowProxyHolder;
|
||||
|
||||
#define NS_CONTENTFRAMEMESSAGEMANAGER_IID \
|
||||
{ \
|
||||
0x97e192a6, 0xab7a, 0x4c8f, { \
|
||||
@ -33,8 +37,7 @@ class ContentFrameMessageManager : public DOMEventTargetHelper,
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CONTENTFRAMEMESSAGEMANAGER_IID)
|
||||
|
||||
virtual already_AddRefed<nsPIDOMWindowOuter> GetContent(
|
||||
ErrorResult& aError) = 0;
|
||||
virtual Nullable<WindowProxyHolder> GetContent(ErrorResult& aError) = 0;
|
||||
virtual already_AddRefed<nsIDocShell> GetDocShell(ErrorResult& aError) = 0;
|
||||
virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() = 0;
|
||||
virtual uint64_t ChromeOuterWindowID() = 0;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "mozilla/dom/MessageManagerBinding.h"
|
||||
#include "mozilla/dom/SameProcessMessageQueue.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
@ -147,13 +148,16 @@ void InProcessTabChildMessageManager::CacheFrameLoader(
|
||||
mFrameLoader = aFrameLoader;
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter>
|
||||
InProcessTabChildMessageManager::GetContent(ErrorResult& aError) {
|
||||
Nullable<WindowProxyHolder> InProcessTabChildMessageManager::GetContent(
|
||||
ErrorResult& aError) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> content;
|
||||
if (mDocShell) {
|
||||
content = mDocShell->GetWindow();
|
||||
}
|
||||
return content.forget();
|
||||
if (!content) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(content);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIEventTarget>
|
||||
|
@ -65,8 +65,7 @@ class InProcessTabChildMessageManager final
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
virtual already_AddRefed<nsPIDOMWindowOuter> GetContent(
|
||||
ErrorResult& aError) override;
|
||||
Nullable<WindowProxyHolder> GetContent(ErrorResult& aError) override;
|
||||
virtual already_AddRefed<nsIDocShell> GetDocShell(
|
||||
ErrorResult& aError) override {
|
||||
nsCOMPtr<nsIDocShell> docShell(mDocShell);
|
||||
|
67
dom/base/WindowProxyHolder.h
Normal file
67
dom/base/WindowProxyHolder.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 mozilla_dom_WindowProxyHolder_h__
|
||||
#define mozilla_dom_WindowProxyHolder_h__
|
||||
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/**
|
||||
* This class is used for passing arguments and the return value for WebIDL
|
||||
* binding code that takes/returns a WindowProxy object and for WebIDL
|
||||
* unions/dictionaries that contain a WindowProxy member. It should never
|
||||
* contain null; if the value in WebIDL is nullable the binding code will use a
|
||||
* Nullable<WindowProxyHolder>.
|
||||
*/
|
||||
class WindowProxyHolder {
|
||||
public:
|
||||
WindowProxyHolder() = default;
|
||||
explicit WindowProxyHolder(nsPIDOMWindowOuter* aWin) : mWindow(aWin) {
|
||||
MOZ_ASSERT(mWindow, "Don't set WindowProxyHolder to null.");
|
||||
}
|
||||
explicit WindowProxyHolder(already_AddRefed<nsPIDOMWindowOuter>&& aWin)
|
||||
: mWindow(std::move(aWin)) {
|
||||
MOZ_ASSERT(mWindow, "Don't set WindowProxyHolder to null.");
|
||||
}
|
||||
WindowProxyHolder& operator=(nsPIDOMWindowOuter* aWin) {
|
||||
mWindow = aWin;
|
||||
MOZ_ASSERT(mWindow, "Don't set WindowProxyHolder to null.");
|
||||
return *this;
|
||||
}
|
||||
WindowProxyHolder& operator=(already_AddRefed<nsPIDOMWindowOuter>&& aWin) {
|
||||
mWindow = std::move(aWin);
|
||||
MOZ_ASSERT(mWindow, "Don't set WindowProxyHolder to null.");
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsPIDOMWindowOuter* get() const {
|
||||
MOZ_ASSERT(mWindow, "WindowProxyHolder hasn't been initialized.");
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
private:
|
||||
friend void ImplCycleCollectionUnlink(WindowProxyHolder& aProxy);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> mWindow;
|
||||
};
|
||||
|
||||
inline void ImplCycleCollectionTraverse(
|
||||
nsCycleCollectionTraversalCallback& aCallback, WindowProxyHolder& aProxy,
|
||||
const char* aName, uint32_t aFlags = 0) {
|
||||
CycleCollectionNoteChild(aCallback, aProxy.get(), "mWindow", aFlags);
|
||||
}
|
||||
|
||||
inline void ImplCycleCollectionUnlink(WindowProxyHolder& aProxy) {
|
||||
aProxy.mWindow = nullptr;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_WindowProxyHolder_h__ */
|
@ -235,6 +235,7 @@ EXPORTS.mozilla.dom += [
|
||||
'VisualViewport.h',
|
||||
'WebKitCSSMatrix.h',
|
||||
'WindowOrientationObserver.h',
|
||||
'WindowProxyHolder.h',
|
||||
]
|
||||
|
||||
if CONFIG['FUZZING']:
|
||||
|
@ -294,6 +294,7 @@
|
||||
#include "mozilla/net/ChannelEventQueue.h"
|
||||
#include "mozilla/net/RequestContextService.h"
|
||||
#include "StorageAccessPermissionRequest.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
|
||||
#define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0)
|
||||
#define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1)
|
||||
@ -3366,6 +3367,14 @@ nsresult nsIDocument::GetSrcdocData(nsAString& aSrcdocData) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Nullable<WindowProxyHolder> nsIDocument::GetDefaultView() const {
|
||||
nsPIDOMWindowOuter* win = GetWindow();
|
||||
if (!win) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(win);
|
||||
}
|
||||
|
||||
Element* nsIDocument::GetActiveElement() {
|
||||
// Get the focused element.
|
||||
Element* focusedElement = GetRetargetedFocusedElement();
|
||||
|
@ -2546,7 +2546,7 @@ bool nsGlobalWindowInner::HasActiveSpeechSynthesis() {
|
||||
|
||||
#endif
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowInner::GetParent(
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowInner::GetParent(
|
||||
ErrorResult& aError) {
|
||||
FORWARD_TO_OUTER_OR_THROW(GetParentOuter, (), aError, nullptr);
|
||||
}
|
||||
@ -3306,7 +3306,7 @@ double nsGlobalWindowInner::GetScrollY(ErrorResult& aError) {
|
||||
|
||||
uint32_t nsGlobalWindowInner::Length() { FORWARD_TO_OUTER(Length, (), 0); }
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowInner::GetTop(
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowInner::GetTop(
|
||||
mozilla::ErrorResult& aError) {
|
||||
FORWARD_TO_OUTER_OR_THROW(GetTopOuter, (), aError, nullptr);
|
||||
}
|
||||
@ -3684,14 +3684,15 @@ void nsGlobalWindowInner::ReleaseEvents() {
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowInner::Open(
|
||||
const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
|
||||
ErrorResult& aError) {
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowInner::Open(const nsAString& aUrl,
|
||||
const nsAString& aName,
|
||||
const nsAString& aOptions,
|
||||
ErrorResult& aError) {
|
||||
FORWARD_TO_OUTER_OR_THROW(OpenOuter, (aUrl, aName, aOptions, aError), aError,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowInner::OpenDialog(
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowInner::OpenDialog(
|
||||
JSContext* aCx, const nsAString& aUrl, const nsAString& aName,
|
||||
const nsAString& aOptions, const Sequence<JS::Value>& aExtraArgument,
|
||||
ErrorResult& aError) {
|
||||
@ -3881,7 +3882,7 @@ void nsGlobalWindowInner::Btoa(const nsAString& aBinaryData,
|
||||
// EventTarget
|
||||
//*****************************************************************************
|
||||
|
||||
nsPIDOMWindowOuter* nsGlobalWindowInner::GetOwnerGlobalForBindings() {
|
||||
nsPIDOMWindowOuter* nsGlobalWindowInner::GetOwnerGlobalForBindingsInternal() {
|
||||
return nsPIDOMWindowOuter::GetFromCurrentInner(this);
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
||||
|
||||
bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult& aRv) final;
|
||||
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
|
||||
|
||||
virtual nsIGlobalObject* GetOwnerGlobal() const override;
|
||||
|
||||
@ -623,7 +623,8 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
||||
nsDOMWindowList* GetFrames() final;
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetFrames(mozilla::ErrorResult& aError);
|
||||
uint32_t Length();
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetTop(mozilla::ErrorResult& aError);
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetTop(
|
||||
mozilla::ErrorResult& aError);
|
||||
|
||||
protected:
|
||||
explicit nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow);
|
||||
@ -637,15 +638,15 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
||||
void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
|
||||
mozilla::ErrorResult& aError);
|
||||
void GetEvent(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval);
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetParent(mozilla::ErrorResult& aError);
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetParent(
|
||||
mozilla::ErrorResult& aError);
|
||||
nsPIDOMWindowOuter* GetScriptableParent() override;
|
||||
mozilla::dom::Element* GetFrameElement(nsIPrincipal& aSubjectPrincipal,
|
||||
mozilla::ErrorResult& aError);
|
||||
mozilla::dom::Element* GetFrameElement() override;
|
||||
already_AddRefed<nsPIDOMWindowOuter> Open(const nsAString& aUrl,
|
||||
const nsAString& aName,
|
||||
const nsAString& aOptions,
|
||||
mozilla::ErrorResult& aError);
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> Open(
|
||||
const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
|
||||
mozilla::ErrorResult& aError);
|
||||
nsDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError);
|
||||
nsDOMOfflineResourceList* GetApplicationCache() override;
|
||||
|
||||
@ -857,7 +858,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
||||
|
||||
bool ShouldResistFingerprinting();
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> OpenDialog(
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> OpenDialog(
|
||||
JSContext* aCx, const nsAString& aUrl, const nsAString& aName,
|
||||
const nsAString& aOptions,
|
||||
const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "mozilla/dom/Timeout.h"
|
||||
#include "mozilla/dom/TimeoutHandler.h"
|
||||
#include "mozilla/dom/TimeoutManager.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
#include "mozilla/dom/WindowOrientationObserver.h"
|
||||
@ -2624,19 +2625,13 @@ bool nsPIDOMWindowOuter::GetServiceWorkersTestingEnabled() {
|
||||
return topWindow->mServiceWorkersTestingEnabled;
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::GetParentOuter() {
|
||||
if (!mDocShell) {
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowOuter::GetParentOuter() {
|
||||
nsPIDOMWindowOuter* parent = GetScriptableParent();
|
||||
if (!parent) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> parent;
|
||||
if (mDocShell->GetIsMozBrowser()) {
|
||||
parent = this;
|
||||
} else {
|
||||
parent = GetParent();
|
||||
}
|
||||
|
||||
return parent.forget();
|
||||
return WindowProxyHolder(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2647,8 +2642,16 @@ already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::GetParentOuter() {
|
||||
* mozbrowser>, we will return |this| as its own parent.
|
||||
*/
|
||||
nsPIDOMWindowOuter* nsGlobalWindowOuter::GetScriptableParent() {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> parent = GetParentOuter();
|
||||
return parent.get();
|
||||
if (!mDocShell) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (mDocShell->GetIsMozBrowser()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> parent = GetParent();
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2769,7 +2772,8 @@ already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::GetContentInternal(
|
||||
// If we're contained in <iframe mozbrowser>, then GetContent is the same as
|
||||
// window.top.
|
||||
if (mDocShell && mDocShell->GetIsInMozBrowser()) {
|
||||
return GetTopOuter();
|
||||
domWindow = GetScriptableTop();
|
||||
return domWindow.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> primaryContent;
|
||||
@ -3550,9 +3554,12 @@ uint32_t nsGlobalWindowOuter::Length() {
|
||||
return windows ? windows->GetLength() : 0;
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::GetTopOuter() {
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowOuter::GetTopOuter() {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> top = GetScriptableTop();
|
||||
return top.forget();
|
||||
if (!top) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(top.forget());
|
||||
}
|
||||
|
||||
nsPIDOMWindowOuter* nsGlobalWindowOuter::GetChildWindow(
|
||||
@ -5227,12 +5234,15 @@ void nsGlobalWindowOuter::FireAbuseEvents(
|
||||
aPopupWindowFeatures);
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::OpenOuter(
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowOuter::OpenOuter(
|
||||
const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
|
||||
ErrorResult& aError) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window;
|
||||
aError = OpenJS(aUrl, aName, aOptions, getter_AddRefs(window));
|
||||
return window.forget();
|
||||
if (!window) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(window.forget());
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowOuter::Open(const nsAString& aUrl,
|
||||
@ -5302,7 +5312,7 @@ nsresult nsGlobalWindowOuter::OpenDialog(const nsAString& aUrl,
|
||||
_retval);
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::OpenDialogOuter(
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowOuter::OpenDialogOuter(
|
||||
JSContext* aCx, const nsAString& aUrl, const nsAString& aName,
|
||||
const nsAString& aOptions, const Sequence<JS::Value>& aExtraArgument,
|
||||
ErrorResult& aError) {
|
||||
@ -5325,7 +5335,10 @@ already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::OpenDialogOuter(
|
||||
nullptr, // aLoadState
|
||||
false, // aForceNoOpener
|
||||
getter_AddRefs(dialog));
|
||||
return dialog.forget();
|
||||
if (!dialog) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(dialog.forget());
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::GetFramesOuter() {
|
||||
@ -6090,7 +6103,7 @@ bool nsGlobalWindowOuter::FindOuter(const nsAString& aString,
|
||||
// EventTarget
|
||||
//*****************************************************************************
|
||||
|
||||
nsPIDOMWindowOuter* nsGlobalWindowOuter::GetOwnerGlobalForBindings() {
|
||||
nsPIDOMWindowOuter* nsGlobalWindowOuter::GetOwnerGlobalForBindingsInternal() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
||||
|
||||
bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult& aRv) final;
|
||||
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
|
||||
|
||||
virtual nsIGlobalObject* GetOwnerGlobal() const override;
|
||||
|
||||
@ -529,7 +529,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetFramesOuter();
|
||||
nsDOMWindowList* GetFrames() final;
|
||||
uint32_t Length();
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetTopOuter();
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetTopOuter();
|
||||
|
||||
nsresult GetPrompter(nsIPrompt** aPrompt) override;
|
||||
|
||||
@ -542,16 +542,15 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
||||
nsPIDOMWindowOuter* GetSanitizedOpener(nsPIDOMWindowOuter* aOpener);
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetOpener() override;
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetParentOuter();
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetParentOuter();
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetParent() override;
|
||||
nsPIDOMWindowOuter* GetScriptableParent() override;
|
||||
nsPIDOMWindowOuter* GetScriptableParentOrNull() override;
|
||||
mozilla::dom::Element* GetFrameElementOuter(nsIPrincipal& aSubjectPrincipal);
|
||||
mozilla::dom::Element* GetFrameElement() override;
|
||||
already_AddRefed<nsPIDOMWindowOuter> OpenOuter(const nsAString& aUrl,
|
||||
const nsAString& aName,
|
||||
const nsAString& aOptions,
|
||||
mozilla::ErrorResult& aError);
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> OpenOuter(
|
||||
const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
|
||||
mozilla::ErrorResult& aError);
|
||||
nsresult Open(const nsAString& aUrl, const nsAString& aName,
|
||||
const nsAString& aOptions, nsDocShellLoadState* aLoadState,
|
||||
bool aForceNoOpener, nsPIDOMWindowOuter** _retval) override;
|
||||
@ -615,7 +614,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
||||
|
||||
bool ShouldResistFingerprinting();
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> OpenDialogOuter(
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> OpenDialogOuter(
|
||||
JSContext* aCx, const nsAString& aUrl, const nsAString& aName,
|
||||
const nsAString& aOptions,
|
||||
const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
|
||||
|
@ -3079,7 +3079,8 @@ class nsIDocument : public nsINode,
|
||||
return GetFuncStringContentList<nsCachableElementsByNameNodeList>(
|
||||
this, MatchNameAttribute, nullptr, UseExistingNameString, aName);
|
||||
}
|
||||
nsPIDOMWindowOuter* GetDefaultView() const { return GetWindow(); }
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetDefaultView()
|
||||
const;
|
||||
Element* GetActiveElement();
|
||||
bool HasFocus(mozilla::ErrorResult& rv) const;
|
||||
nsIHTMLCollection* Applets();
|
||||
|
@ -1047,7 +1047,7 @@ EventListenerManager* nsINode::GetExistingListenerManager() const {
|
||||
return nsContentUtils::GetExistingListenerManagerForNode(this);
|
||||
}
|
||||
|
||||
nsPIDOMWindowOuter* nsINode::GetOwnerGlobalForBindings() {
|
||||
nsPIDOMWindowOuter* nsINode::GetOwnerGlobalForBindingsInternal() {
|
||||
bool dummy;
|
||||
auto* window = static_cast<nsGlobalWindowInner*>(
|
||||
OwnerDoc()->GetScriptHandlingObject(dummy));
|
||||
|
@ -944,7 +944,7 @@ class nsINode : public mozilla::dom::EventTarget {
|
||||
|
||||
virtual bool IsApzAware() const override;
|
||||
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
|
||||
virtual nsIGlobalObject* GetOwnerGlobal() const override;
|
||||
|
||||
using mozilla::dom::EventTarget::DispatchEvent;
|
||||
|
@ -1077,8 +1077,8 @@ nsObjectLoadingContent::GetFrameLoader() {
|
||||
return loader.forget();
|
||||
}
|
||||
|
||||
void nsObjectLoadingContent::PresetOpenerWindow(mozIDOMWindowProxy* aWindow,
|
||||
mozilla::ErrorResult& aRv) {
|
||||
void nsObjectLoadingContent::PresetOpenerWindow(
|
||||
const Nullable<WindowProxyHolder>& aOpenerWindow, ErrorResult& aRv) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,9 @@ template <typename T>
|
||||
class Sequence;
|
||||
struct MozPluginParameter;
|
||||
class HTMLIFrameElement;
|
||||
template <typename T>
|
||||
struct Nullable;
|
||||
class WindowProxyHolder;
|
||||
class XULFrameElement;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
@ -235,7 +238,8 @@ class nsObjectLoadingContent : public nsImageLoadingContent,
|
||||
|
||||
bool IsRewrittenYoutubeEmbed() const { return mRewrittenYoutubeEmbed; }
|
||||
|
||||
void PresetOpenerWindow(mozIDOMWindowProxy* aOpenerWindow,
|
||||
void PresetOpenerWindow(const mozilla::dom::Nullable<
|
||||
mozilla::dom::WindowProxyHolder>& aOpenerWindow,
|
||||
mozilla::ErrorResult& aRv);
|
||||
|
||||
protected:
|
||||
|
@ -106,7 +106,7 @@ nsresult nsWindowRoot::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsPIDOMWindowOuter* nsWindowRoot::GetOwnerGlobalForBindings() {
|
||||
nsPIDOMWindowOuter* nsWindowRoot::GetOwnerGlobalForBindingsInternal() {
|
||||
return GetWindow();
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ class nsWindowRoot final : public nsPIWindowRoot {
|
||||
virtual mozilla::dom::EventTarget* GetParentTarget() override {
|
||||
return mParent;
|
||||
}
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
|
||||
virtual nsIGlobalObject* GetOwnerGlobal() const override;
|
||||
|
||||
nsIGlobalObject* GetParentObject();
|
||||
|
@ -1126,6 +1126,11 @@ bool VariantToJsval(JSContext* aCx, nsIVariant* aVariant,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WrapObject(JSContext* cx, const WindowProxyHolder& p,
|
||||
JS::MutableHandle<JS::Value> rval) {
|
||||
return ToJSValue(cx, p.get(), rval);
|
||||
}
|
||||
|
||||
static int CompareIdsAtIndices(const void* aElement1, const void* aElement2,
|
||||
void* aClosure) {
|
||||
const uint16_t index1 = *static_cast<const uint16_t*>(aElement1);
|
||||
@ -3223,14 +3228,14 @@ nsresult UnwrapArgImpl(JSContext* cx, JS::Handle<JSObject*> src,
|
||||
return wrappedJS->QueryInterface(iid, ppArg);
|
||||
}
|
||||
|
||||
nsresult UnwrapWindowProxyImpl(JSContext* cx, JS::Handle<JSObject*> src,
|
||||
nsPIDOMWindowOuter** ppArg) {
|
||||
nsresult UnwrapWindowProxyArg(JSContext* cx, JS::Handle<JSObject*> src,
|
||||
WindowProxyHolder& ppArg) {
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner;
|
||||
nsresult rv = UnwrapArg<nsPIDOMWindowInner>(cx, src, getter_AddRefs(inner));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> outer = inner->GetOuterWindow();
|
||||
outer.forget(ppArg);
|
||||
ppArg = outer.forget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -54,13 +54,11 @@ class CustomElementReactionsStack;
|
||||
class MessageManagerGlobal;
|
||||
template <typename KeyType, typename ValueType>
|
||||
class Record;
|
||||
class WindowProxyHolder;
|
||||
|
||||
nsresult UnwrapArgImpl(JSContext* cx, JS::Handle<JSObject*> src,
|
||||
const nsIID& iid, void** ppArg);
|
||||
|
||||
nsresult UnwrapWindowProxyImpl(JSContext* cx, JS::Handle<JSObject*> src,
|
||||
nsPIDOMWindowOuter** ppArg);
|
||||
|
||||
/** Convert a jsval to an XPCOM pointer. Caller must not assume that src will
|
||||
keep the XPCOM pointer rooted. */
|
||||
template <class Interface>
|
||||
@ -70,12 +68,8 @@ inline nsresult UnwrapArg(JSContext* cx, JS::Handle<JSObject*> src,
|
||||
reinterpret_cast<void**>(ppArg));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline nsresult UnwrapArg<nsPIDOMWindowOuter>(JSContext* cx,
|
||||
JS::Handle<JSObject*> src,
|
||||
nsPIDOMWindowOuter** ppArg) {
|
||||
return UnwrapWindowProxyImpl(cx, src, ppArg);
|
||||
}
|
||||
nsresult UnwrapWindowProxyArg(JSContext* cx, JS::Handle<JSObject*> src,
|
||||
WindowProxyHolder& ppArg);
|
||||
|
||||
bool ThrowInvalidThis(JSContext* aCx, const JS::CallArgs& aArgs,
|
||||
bool aSecurityError, const char* aInterfaceName);
|
||||
@ -1424,6 +1418,9 @@ inline bool WrapObject(JSContext* cx, JSObject& p,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WrapObject(JSContext* cx, const WindowProxyHolder& p,
|
||||
JS::MutableHandle<JS::Value> rval);
|
||||
|
||||
// Given an object "p" that inherits from nsISupports, wrap it and return the
|
||||
// result. Null is returned on wrapping failure. This is somewhat similar to
|
||||
// WrapObject() above, but does NOT allow Xrays around the result, since we
|
||||
|
@ -1487,8 +1487,7 @@ DOMInterfaces = {
|
||||
},
|
||||
|
||||
'WindowProxy': {
|
||||
'nativeType': 'nsPIDOMWindowOuter',
|
||||
'headerFile': 'nsPIDOMWindow.h',
|
||||
'nativeType': 'mozilla::dom::WindowProxyHolder',
|
||||
'concrete': False
|
||||
},
|
||||
|
||||
|
@ -1388,6 +1388,11 @@ def UnionTypes(unionTypes, config):
|
||||
# refs, so we'll need the header to handler
|
||||
# those.
|
||||
headers.add(typeDesc.headerFile)
|
||||
elif typeDesc.interface.identifier.name == "WindowProxy":
|
||||
# In UnionTypes.h we need to see the declaration of the
|
||||
# WindowProxyHolder that we use to store the WindowProxy, so
|
||||
# we have its sizeof and know how big to make our union.
|
||||
headers.add(typeDesc.headerFile)
|
||||
else:
|
||||
declarations.add((typeDesc.nativeType, False))
|
||||
implheaders.add(typeDesc.headerFile)
|
||||
@ -5491,6 +5496,28 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||
declArgs=declArgs,
|
||||
dealWithOptional=isOptional)
|
||||
|
||||
if descriptor.interface.identifier.name == "WindowProxy":
|
||||
declType = CGGeneric("mozilla::dom::WindowProxyHolder")
|
||||
if type.nullable():
|
||||
declType = CGTemplatedType("Nullable", declType)
|
||||
windowProxyHolderRef = "${declName}.SetValue()"
|
||||
else:
|
||||
windowProxyHolderRef = "${declName}"
|
||||
|
||||
failureCode = onFailureBadType(failureCode, descriptor.interface.identifier.name).define()
|
||||
templateBody = fill("""
|
||||
JS::Rooted<JSObject*> source(cx, &$${val}.toObject());
|
||||
if (NS_FAILED(UnwrapWindowProxyArg(cx, source, ${windowProxyHolderRef}))) {
|
||||
$*{onFailure}
|
||||
}
|
||||
""",
|
||||
windowProxyHolderRef=windowProxyHolderRef,
|
||||
onFailure=failureCode)
|
||||
templateBody = wrapObjectTemplate(templateBody, type,
|
||||
"${declName}.SetNull();\n", failureCode)
|
||||
return JSToNativeConversionInfo(templateBody, declType=declType,
|
||||
dealWithOptional=isOptional)
|
||||
|
||||
# This is an interface that we implement as a concrete class
|
||||
# or an XPCOM interface.
|
||||
|
||||
@ -6675,6 +6702,16 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
|
||||
if type.isGeckoInterface() and not type.isCallbackInterface():
|
||||
descriptor = descriptorProvider.getDescriptor(type.unroll().inner.identifier.name)
|
||||
if type.nullable():
|
||||
if descriptor.interface.identifier.name == "WindowProxy":
|
||||
template, infal = getWrapTemplateForType(type.inner, descriptorProvider,
|
||||
"%s.Value()" % result, successCode,
|
||||
returnsNewObject, exceptionCode,
|
||||
spiderMonkeyInterfacesAreStructs)
|
||||
return ("if (%s.IsNull()) {\n" % result +
|
||||
indent(setNull()) +
|
||||
"}\n" +
|
||||
template, infal)
|
||||
|
||||
wrappingCode = ("if (!%s) {\n" % (result) +
|
||||
indent(setNull()) +
|
||||
"}\n")
|
||||
@ -6996,8 +7033,14 @@ def getRetvalDeclarationForType(returnType, descriptorProvider,
|
||||
return result, None, None, None, None
|
||||
if returnType.isGeckoInterface() or returnType.isPromise():
|
||||
if returnType.isGeckoInterface():
|
||||
typeName = descriptorProvider.getDescriptor(
|
||||
returnType.unroll().inner.identifier.name).nativeType
|
||||
typeName = returnType.unroll().inner.identifier.name
|
||||
if typeName == "WindowProxy":
|
||||
result = CGGeneric("WindowProxyHolder")
|
||||
if returnType.nullable():
|
||||
result = CGTemplatedType("Nullable", result)
|
||||
return result, None, None, None, None
|
||||
|
||||
typeName = descriptorProvider.getDescriptor(typeName).nativeType
|
||||
else:
|
||||
typeName = "Promise"
|
||||
if isMember:
|
||||
@ -9834,11 +9877,13 @@ def getUnionAccessorSignatureType(type, descriptorProvider):
|
||||
descriptor = descriptorProvider.getDescriptor(
|
||||
type.unroll().inner.identifier.name)
|
||||
typeName = CGGeneric(descriptor.nativeType)
|
||||
# Allow null pointers for old-binding classes.
|
||||
if type.unroll().inner.isExternal():
|
||||
typeName = CGWrapper(typeName, post="*")
|
||||
else:
|
||||
if not type.unroll().inner.isExternal():
|
||||
typeName = CGWrapper(typeName, post="&")
|
||||
elif descriptor.interface.identifier.name == "WindowProxy":
|
||||
typeName = CGGeneric("WindowProxyHolder const&")
|
||||
else:
|
||||
# Allow null pointers for old-binding classes.
|
||||
typeName = CGWrapper(typeName, post="*")
|
||||
return typeName
|
||||
|
||||
if type.isSpiderMonkeyInterface():
|
||||
@ -14476,6 +14521,9 @@ class CGNativeMember(ClassMethod):
|
||||
|
||||
if type.isGeckoInterface() and not type.isCallbackInterface():
|
||||
iface = type.unroll().inner
|
||||
if iface.identifier.name == "WindowProxy":
|
||||
return "WindowProxyHolder", True, False
|
||||
|
||||
argIsPointer = type.nullable() or iface.isExternal()
|
||||
forceOwningType = (iface.isCallback() or isMember)
|
||||
if argIsPointer:
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "mozilla/dom/HTMLIFrameElement.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsVariant.h"
|
||||
#include "mozilla/dom/BrowserElementDictionariesBinding.h"
|
||||
@ -234,7 +235,8 @@ BrowserElementParent::OpenWindowInProcess(nsPIDOMWindowOuter* aOpenerWindow,
|
||||
|
||||
if (!aForceNoOpener) {
|
||||
ErrorResult res;
|
||||
popupFrameElement->PresetOpenerWindow(aOpenerWindow, res);
|
||||
popupFrameElement->PresetOpenerWindow(WindowProxyHolder(aOpenerWindow),
|
||||
res);
|
||||
MOZ_ASSERT(!res.Failed());
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ class DOMEventTargetHelper : public dom::EventTarget,
|
||||
return mListenerManager && mListenerManager->HasListenersFor(aTypeWithOn);
|
||||
}
|
||||
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override {
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override {
|
||||
return nsPIDOMWindowOuter::GetFromCurrentInner(GetOwner());
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "mozilla/dom/EventTarget.h"
|
||||
#include "mozilla/dom/EventTargetBinding.h"
|
||||
#include "mozilla/dom/ConstructibleEventTarget.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
@ -182,5 +184,14 @@ void EventTarget::DispatchEvent(Event& aEvent, ErrorResult& aRv) {
|
||||
Unused << DispatchEvent(aEvent, CallerType::NonSystem, IgnoreErrors());
|
||||
}
|
||||
|
||||
Nullable<WindowProxyHolder> EventTarget::GetOwnerGlobalForBindings() {
|
||||
nsPIDOMWindowOuter* win = GetOwnerGlobalForBindingsInternal();
|
||||
if (!win) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return WindowProxyHolder(win);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -34,6 +34,9 @@ class EventListener;
|
||||
class EventListenerOptionsOrBoolean;
|
||||
class EventHandlerNonNull;
|
||||
class GlobalObject;
|
||||
template <typename>
|
||||
struct Nullable;
|
||||
class WindowProxyHolder;
|
||||
|
||||
// IID for the dom::EventTarget interface
|
||||
#define NS_EVENTTARGET_IID \
|
||||
@ -175,7 +178,8 @@ class EventTarget : public nsISupports, public nsWrapperCache {
|
||||
// Returns an outer window that corresponds to the inner window this event
|
||||
// target is associated with. Will return null if the inner window is not the
|
||||
// current inner or if there is no window around at all.
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() = 0;
|
||||
Nullable<WindowProxyHolder> GetOwnerGlobalForBindings();
|
||||
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() = 0;
|
||||
|
||||
// The global object this event target is associated with, if any.
|
||||
// This may be an inner window or some other global object. This
|
||||
|
@ -108,7 +108,7 @@ void MessageEvent::GetSource(
|
||||
|
||||
if (!aParam.mSource.IsNull()) {
|
||||
if (aParam.mSource.Value().IsWindowProxy()) {
|
||||
event->mWindowSource = aParam.mSource.Value().GetAsWindowProxy();
|
||||
event->mWindowSource = aParam.mSource.Value().GetAsWindowProxy().get();
|
||||
} else if (aParam.mSource.Value().IsMessagePort()) {
|
||||
event->mPortSource = aParam.mSource.Value().GetAsMessagePort();
|
||||
} else {
|
||||
@ -144,7 +144,7 @@ void MessageEvent::InitMessageEvent(
|
||||
|
||||
if (!aSource.IsNull()) {
|
||||
if (aSource.Value().IsWindowProxy()) {
|
||||
mWindowSource = aSource.Value().GetAsWindowProxy();
|
||||
mWindowSource = aSource.Value().GetAsWindowProxy().get();
|
||||
} else if (aSource.Value().IsMessagePort()) {
|
||||
mPortSource = &aSource.Value().GetAsMessagePort();
|
||||
} else {
|
||||
|
@ -9,7 +9,9 @@
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/UIEventBinding.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
#include "nsPresContext.h"
|
||||
@ -47,7 +49,12 @@ class UIEvent : public Event {
|
||||
bool cancelableArg, nsGlobalWindowInner* viewArg,
|
||||
int32_t detailArg);
|
||||
|
||||
nsPIDOMWindowOuter* GetView() const { return mView; }
|
||||
Nullable<WindowProxyHolder> GetView() const {
|
||||
if (!mView) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(mView);
|
||||
}
|
||||
|
||||
int32_t Detail() const { return mDetail; }
|
||||
|
||||
|
@ -374,11 +374,14 @@ int32_t HTMLObjectElement::TabIndexDefault() {
|
||||
return IsFocusableForTabIndex() ? 0 : -1;
|
||||
}
|
||||
|
||||
nsPIDOMWindowOuter* HTMLObjectElement::GetContentWindow(
|
||||
Nullable<WindowProxyHolder> HTMLObjectElement::GetContentWindow(
|
||||
nsIPrincipal& aSubjectPrincipal) {
|
||||
nsIDocument* doc = GetContentDocument(aSubjectPrincipal);
|
||||
if (doc) {
|
||||
return doc->GetWindow();
|
||||
nsPIDOMWindowOuter* win = doc->GetWindow();
|
||||
if (win) {
|
||||
return WindowProxyHolder(win);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -16,6 +16,9 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class HTMLFormSubmission;
|
||||
template <typename T>
|
||||
struct Nullable;
|
||||
class WindowProxyHolder;
|
||||
|
||||
class HTMLObjectElement final : public nsGenericHTMLFormElement,
|
||||
public nsObjectLoadingContent,
|
||||
@ -121,7 +124,7 @@ class HTMLObjectElement final : public nsGenericHTMLFormElement,
|
||||
}
|
||||
using nsObjectLoadingContent::GetContentDocument;
|
||||
|
||||
nsPIDOMWindowOuter* GetContentWindow(nsIPrincipal& aSubjectPrincipal);
|
||||
Nullable<WindowProxyHolder> GetContentWindow(nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
using nsIConstraintValidation::GetValidationMessage;
|
||||
using nsIConstraintValidation::SetCustomValidity;
|
||||
|
@ -71,7 +71,7 @@ nsGenericHTMLFrameElement::~nsGenericHTMLFrameElement() {
|
||||
|
||||
nsIDocument* nsGenericHTMLFrameElement::GetContentDocument(
|
||||
nsIPrincipal& aSubjectPrincipal) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = GetContentWindow();
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = GetContentWindowInternal();
|
||||
if (!win) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -89,7 +89,7 @@ nsIDocument* nsGenericHTMLFrameElement::GetContentDocument(
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter>
|
||||
nsGenericHTMLFrameElement::GetContentWindow() {
|
||||
nsGenericHTMLFrameElement::GetContentWindowInternal() {
|
||||
EnsureFrameLoader();
|
||||
|
||||
if (!mFrameLoader) {
|
||||
@ -107,12 +107,15 @@ nsGenericHTMLFrameElement::GetContentWindow() {
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = doc_shell->GetWindow();
|
||||
return win.forget();
|
||||
}
|
||||
|
||||
Nullable<WindowProxyHolder> nsGenericHTMLFrameElement::GetContentWindow() {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = GetContentWindowInternal();
|
||||
if (!win) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return win.forget();
|
||||
return WindowProxyHolder(win.forget());
|
||||
}
|
||||
|
||||
void nsGenericHTMLFrameElement::EnsureFrameLoader() {
|
||||
@ -150,10 +153,11 @@ nsGenericHTMLFrameElement::GetFrameLoader() {
|
||||
return loader.forget();
|
||||
}
|
||||
|
||||
void nsGenericHTMLFrameElement::PresetOpenerWindow(mozIDOMWindowProxy* aWindow,
|
||||
ErrorResult& aRv) {
|
||||
void nsGenericHTMLFrameElement::PresetOpenerWindow(
|
||||
const Nullable<WindowProxyHolder>& aOpenerWindow, ErrorResult& aRv) {
|
||||
MOZ_ASSERT(!mFrameLoader);
|
||||
mOpenerWindow = nsPIDOMWindowOuter::From(aWindow);
|
||||
mOpenerWindow =
|
||||
aOpenerWindow.IsNull() ? nullptr : aOpenerWindow.Value().get();
|
||||
}
|
||||
|
||||
void nsGenericHTMLFrameElement::InternalSetFrameLoader(
|
||||
|
@ -19,8 +19,11 @@
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
template <typename>
|
||||
struct Nullable;
|
||||
class WindowProxyHolder;
|
||||
class XULFrameElement;
|
||||
}
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#define NS_GENERICHTMLFRAMEELEMENT_IID \
|
||||
@ -84,7 +87,8 @@ class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
|
||||
void SwapFrameLoaders(nsIFrameLoaderOwner* aOtherLoaderOwner,
|
||||
mozilla::ErrorResult& rv);
|
||||
|
||||
void PresetOpenerWindow(mozIDOMWindowProxy* aOpenerWindow,
|
||||
void PresetOpenerWindow(const mozilla::dom::Nullable<
|
||||
mozilla::dom::WindowProxyHolder>& aOpenerWindow,
|
||||
mozilla::ErrorResult& aRv);
|
||||
|
||||
static void InitStatics();
|
||||
@ -112,7 +116,7 @@ class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
|
||||
void EnsureFrameLoader();
|
||||
void LoadSrc();
|
||||
nsIDocument* GetContentDocument(nsIPrincipal& aSubjectPrincipal);
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetContentWindow();
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetContentWindow();
|
||||
|
||||
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
||||
const nsAttrValue* aValue,
|
||||
@ -165,6 +169,8 @@ class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
|
||||
const nsAttrValueOrString* aValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
bool aNotify);
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetContentWindowInternal();
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsGenericHTMLFrameElement,
|
||||
|
@ -1138,7 +1138,7 @@ void nsHTMLDocument::SetCookie(const nsAString& aCookie, ErrorResult& rv) {
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> nsHTMLDocument::Open(
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> nsHTMLDocument::Open(
|
||||
JSContext* /* unused */, const nsAString& aURL, const nsAString& aName,
|
||||
const nsAString& aFeatures, bool aReplace, ErrorResult& rv) {
|
||||
MOZ_ASSERT(nsContentUtils::CanCallerAccess(this),
|
||||
@ -1159,7 +1159,10 @@ already_AddRefed<nsPIDOMWindowOuter> nsHTMLDocument::Open(
|
||||
nsCOMPtr<nsPIDOMWindowOuter> newWindow;
|
||||
// XXXbz We ignore aReplace for now.
|
||||
rv = win->OpenJS(aURL, aName, aFeatures, getter_AddRefs(newWindow));
|
||||
return newWindow.forget();
|
||||
if (!newWindow) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(newWindow.forget());
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDocument> nsHTMLDocument::Open(
|
||||
|
@ -30,6 +30,9 @@ class nsILoadGroup;
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class HTMLAllCollection;
|
||||
template <typename T>
|
||||
struct Nullable;
|
||||
class WindowProxyHolder;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
@ -150,7 +153,7 @@ class nsHTMLDocument : public nsIDocument, public nsIHTMLDocument {
|
||||
already_AddRefed<nsIDocument> Open(
|
||||
JSContext* cx, const mozilla::dom::Optional<nsAString>& /* unused */,
|
||||
const nsAString& aReplace, mozilla::ErrorResult& aError);
|
||||
already_AddRefed<nsPIDOMWindowOuter> Open(
|
||||
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> Open(
|
||||
JSContext* cx, const nsAString& aURL, const nsAString& aName,
|
||||
const nsAString& aFeatures, bool aReplace, mozilla::ErrorResult& rv);
|
||||
void Close(mozilla::ErrorResult& rv);
|
||||
|
@ -25,7 +25,9 @@
|
||||
#include "mozilla/dom/indexedDB/PIndexedDBPermissionRequestChild.h"
|
||||
#include "mozilla/dom/MessageManagerBinding.h"
|
||||
#include "mozilla/dom/MouseEventBinding.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/PaymentRequestChild.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "mozilla/gfx/CrossProcessPaint.h"
|
||||
#include "mozilla/IMEStateManager.h"
|
||||
#include "mozilla/ipc/URIUtils.h"
|
||||
@ -3259,7 +3261,7 @@ void TabChildMessageManager::MarkForCC() {
|
||||
MessageManagerGlobal::MarkForCC();
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> TabChildMessageManager::GetContent(
|
||||
Nullable<WindowProxyHolder> TabChildMessageManager::GetContent(
|
||||
ErrorResult& aError) {
|
||||
if (!mTabChild) {
|
||||
aError.Throw(NS_ERROR_NULL_POINTER);
|
||||
@ -3267,7 +3269,10 @@ already_AddRefed<nsPIDOMWindowOuter> TabChildMessageManager::GetContent(
|
||||
}
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window =
|
||||
do_GetInterface(mTabChild->WebNavigation());
|
||||
return window.forget();
|
||||
if (!window) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(window.forget());
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDocShell> TabChildMessageManager::GetDocShell(
|
||||
|
@ -94,8 +94,7 @@ class TabChildMessageManager : public ContentFrameMessageManager,
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
virtual already_AddRefed<nsPIDOMWindowOuter> GetContent(
|
||||
ErrorResult& aError) override;
|
||||
virtual Nullable<WindowProxyHolder> GetContent(ErrorResult& aError) override;
|
||||
virtual already_AddRefed<nsIDocShell> GetDocShell(
|
||||
ErrorResult& aError) override;
|
||||
virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() override;
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/TimeEventBinding.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
|
||||
class nsGlobalWindowInner;
|
||||
|
||||
@ -34,7 +36,12 @@ class TimeEvent final : public Event {
|
||||
|
||||
int32_t Detail() const { return mDetail; }
|
||||
|
||||
nsPIDOMWindowOuter* GetView() const { return mView; }
|
||||
Nullable<WindowProxyHolder> GetView() const {
|
||||
if (!mView) {
|
||||
return nullptr;
|
||||
}
|
||||
return WindowProxyHolder(mView);
|
||||
}
|
||||
|
||||
TimeEvent* AsTimeEvent() final { return this; }
|
||||
|
||||
|
@ -133,7 +133,7 @@ WebBrowserPersistLocalDocument::GetReferrer(nsAString& aReferrer) {
|
||||
|
||||
NS_IMETHODIMP
|
||||
WebBrowserPersistLocalDocument::GetContentDisposition(nsAString& aCD) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetDefaultView();
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow();
|
||||
if (NS_WARN_IF(!window)) {
|
||||
aCD.SetIsVoid(true);
|
||||
return NS_OK;
|
||||
@ -176,7 +176,7 @@ WebBrowserPersistLocalDocument::GetPrincipal(nsIPrincipal** aPrincipal) {
|
||||
}
|
||||
|
||||
already_AddRefed<nsISHEntry> WebBrowserPersistLocalDocument::GetHistory() {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetDefaultView();
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow();
|
||||
if (NS_WARN_IF(!window)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -48,19 +48,27 @@ already_AddRefed<nsIWebNavigation> XULFrameElement::GetWebNavigation() {
|
||||
return webnav.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMWindowOuter> XULFrameElement::GetContentWindow() {
|
||||
Nullable<WindowProxyHolder> XULFrameElement::GetContentWindow() {
|
||||
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = docShell->GetWindow();
|
||||
return win.forget();
|
||||
if (win) {
|
||||
return WindowProxyHolder(win.forget());
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsIDocument* XULFrameElement::GetContentDocument() {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = GetContentWindow();
|
||||
return win ? win->GetDoc() : nullptr;
|
||||
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = docShell->GetWindow();
|
||||
if (win) {
|
||||
return win->GetDoc();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void XULFrameElement::LoadSrc() {
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
@ -32,7 +34,7 @@ class XULFrameElement final : public nsXULElement, public nsIFrameLoaderOwner {
|
||||
// XULFrameElement.webidl
|
||||
nsIDocShell* GetDocShell();
|
||||
already_AddRefed<nsIWebNavigation> GetWebNavigation();
|
||||
already_AddRefed<nsPIDOMWindowOuter> GetContentWindow();
|
||||
Nullable<WindowProxyHolder> GetContentWindow();
|
||||
nsIDocument* GetContentDocument();
|
||||
|
||||
// nsIFrameLoaderOwner / MozFrameLoaderOwner
|
||||
@ -45,8 +47,9 @@ class XULFrameElement final : public nsXULElement, public nsIFrameLoaderOwner {
|
||||
mFrameLoader = aFrameLoader;
|
||||
}
|
||||
|
||||
void PresetOpenerWindow(mozIDOMWindowProxy* aWindow, ErrorResult& aRv) {
|
||||
mOpener = do_QueryInterface(aWindow);
|
||||
void PresetOpenerWindow(const Nullable<WindowProxyHolder>& aWindow,
|
||||
ErrorResult& aRv) {
|
||||
mOpener = aWindow.IsNull() ? nullptr : aWindow.Value().get();
|
||||
}
|
||||
|
||||
void SwapFrameLoaders(mozilla::dom::HTMLIFrameElement& aOtherLoaderOwner,
|
||||
|
@ -396,7 +396,7 @@ already_AddRefed<nsPIDOMWindowOuter> GetTopWindow(nsPIDOMWindowInner* aWindow) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> pwin;
|
||||
auto* outer = nsGlobalWindowOuter::Cast(aWindow->GetOuterWindow());
|
||||
if (outer) {
|
||||
pwin = outer->GetTopOuter();
|
||||
pwin = outer->GetScriptableTop();
|
||||
}
|
||||
|
||||
if (!pwin) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Variant.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "mozilla/extensions/MatchGlob.h"
|
||||
#include "mozilla/extensions/MatchPattern.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@ -113,8 +114,8 @@ class MozDocumentMatcher : public nsISupports, public nsWrapperCache {
|
||||
bool MatchesLoadInfo(const URLInfo& aURL, nsILoadInfo* aLoadInfo) const {
|
||||
return Matches({aURL, aLoadInfo});
|
||||
}
|
||||
bool MatchesWindow(nsPIDOMWindowOuter* aWindow) const {
|
||||
return Matches(aWindow);
|
||||
bool MatchesWindow(const dom::WindowProxyHolder& aWindow) const {
|
||||
return Matches(aWindow.get());
|
||||
}
|
||||
|
||||
WebExtensionPolicy* GetExtension() { return mExtension; }
|
||||
|
@ -445,12 +445,13 @@ bool WebExtensionPolicy::CanAccessContext(nsILoadContext* aContext) const {
|
||||
return mPrivateBrowsingAllowed || !aContext->UsePrivateBrowsing();
|
||||
}
|
||||
|
||||
bool WebExtensionPolicy::CanAccessWindow(nsPIDOMWindowOuter* aWindow) const {
|
||||
bool WebExtensionPolicy::CanAccessWindow(
|
||||
const dom::WindowProxyHolder& aWindow) const {
|
||||
if (mPrivateBrowsingAllowed) {
|
||||
return true;
|
||||
}
|
||||
// match browsing mode with policy
|
||||
nsIDocShell* docShell = aWindow->GetDocShell();
|
||||
nsIDocShell* docShell = aWindow.get()->GetDocShell();
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
|
||||
return !(loadContext && loadContext->UsePrivateBrowsing());
|
||||
}
|
||||
@ -674,7 +675,7 @@ void DocumentObserver::Disconnect() {
|
||||
void DocumentObserver::NotifyMatch(MozDocumentMatcher& aMatcher,
|
||||
nsPIDOMWindowOuter* aWindow) {
|
||||
IgnoredErrorResult rv;
|
||||
mCallbacks->OnNewDocument(aMatcher, aWindow, rv);
|
||||
mCallbacks->OnNewDocument(aMatcher, dom::WindowProxyHolder(aWindow), rv);
|
||||
}
|
||||
|
||||
void DocumentObserver::NotifyMatch(MozDocumentMatcher& aMatcher,
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/WebExtensionPolicyBinding.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "mozilla/extensions/MatchPattern.h"
|
||||
|
||||
#include "jspubtd.h"
|
||||
@ -128,7 +129,7 @@ class WebExtensionPolicy final : public nsISupports,
|
||||
|
||||
bool CanAccessContext(nsILoadContext* aContext) const;
|
||||
|
||||
bool CanAccessWindow(nsPIDOMWindowOuter* aWindow) const;
|
||||
bool CanAccessWindow(const dom::WindowProxyHolder& aWindow) const;
|
||||
|
||||
static void GetActiveExtensions(
|
||||
dom::GlobalObject& aGlobal,
|
||||
|
@ -45,7 +45,7 @@ class DynamicFrameEventFilter final : public nsIDOMEventListener {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsPIDOMWindowOuter* outer = target->GetOwnerGlobalForBindings();
|
||||
nsPIDOMWindowOuter* outer = target->GetOwnerGlobalForBindingsInternal();
|
||||
if (!outer) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user