Skip to content

Commit

Permalink
Bug 1616353 - Part 7.1: Introduce a new nsOpenWindowInfo type, r=Gijs…
Browse files Browse the repository at this point in the history
…,kmag

This type replaces the individual properties, like nextRemoteTabId and
presetOpenerWindow, which were passed around by frontend code for window opening
requests performed by Gecko. This new type is intentionally native-only to make
it easier to pass more information down to newly created windows in the future.

Differential Revision: https://phabricator.services.mozilla.com/D67050
  • Loading branch information
mystor committed Apr 7, 2020
1 parent 9bb69d5 commit 20da588
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 4 deletions.
8 changes: 4 additions & 4 deletions toolkit/components/windowwatcher/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TEST_DIRS += ['test']

XPIDL_SOURCES += [
'nsIDialogParamBlock.idl',
'nsIOpenWindowInfo.idl',
'nsIPromptFactory.idl',
'nsIPromptService.idl',
'nsIWindowWatcher.idl',
Expand All @@ -21,18 +22,17 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'windowwatcher'

EXPORTS += [
'nsOpenWindowInfo.h',
'nsPromptUtils.h',
'nsWindowWatcher.h',
]

UNIFIED_SOURCES += [
'nsAutoWindowStateHelper.cpp',
'nsOpenWindowInfo.cpp',
'nsWindowWatcher.cpp',
]

EXPORTS += [
'nsWindowWatcher.h',
]

if CONFIG['MOZ_XUL']:
UNIFIED_SOURCES += [
'nsDialogParamBlock.cpp',
Expand Down
46 changes: 46 additions & 0 deletions toolkit/components/windowwatcher/nsIOpenWindowInfo.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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/. */

#include "nsISupports.idl"

webidl BrowsingContext;

%{ C++
namespace mozilla {
class OriginAttributes;
} // namespace mozilla
%}
[ref] native const_OriginAttributes(const mozilla::OriginAttributes);

/**
* nsIOpenWindowInfo is a helper type which contains details used when opening
* new content windows. This object is used to correctly create new initial
* content documents when creating a new window.
*/
[scriptable, builtinclass, uuid(30359edb-126c-4f65-ae80-07fb158697f9)]
interface nsIOpenWindowInfo : nsISupports {
/** BrowsingContext which requested the creation of this new window */
[infallible]
readonly attribute BrowsingContext parent;

/** If `true`, the content document should be created initially-remote */
[infallible]
readonly attribute boolean isRemote;

/** Should |opener| be set on the newly-created content window? */
[infallible]
readonly attribute boolean forceNoOpener;

[infallible]
readonly attribute unsigned long long nextRemoteBrowserId;

/** Origin Attributes for the to-be-created toplevel BrowsingContext */
[implicit_jscontext, binaryname(ScriptableOriginAttributes)]
readonly attribute jsval originAttributes;

[notxpcom, nostdcall, binaryname(GetOriginAttributes)]
const_OriginAttributes binaryGetOriginAttributes();
};
44 changes: 44 additions & 0 deletions toolkit/components/windowwatcher/nsOpenWindowInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* -*- 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/. */

#include "nsOpenWindowInfo.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/dom/ToJSValue.h"

NS_IMPL_ISUPPORTS(nsOpenWindowInfo, nsIOpenWindowInfo)

NS_IMETHODIMP nsOpenWindowInfo::GetParent(
mozilla::dom::BrowsingContext** aParent) {
*aParent = do_AddRef(mParent).take();
return NS_OK;
}

NS_IMETHODIMP nsOpenWindowInfo::GetIsRemote(bool* aIsRemote) {
*aIsRemote = mIsRemote;
return NS_OK;
}

NS_IMETHODIMP nsOpenWindowInfo::GetForceNoOpener(bool* aForceNoOpener) {
*aForceNoOpener = mForceNoOpener;
return NS_OK;
}

NS_IMETHODIMP nsOpenWindowInfo::GetScriptableOriginAttributes(
JSContext* aCx, JS::MutableHandle<JS::Value> aAttrs) {
bool ok = ToJSValue(aCx, mOriginAttributes, aAttrs);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
}

const OriginAttributes& nsOpenWindowInfo::GetOriginAttributes() {
return mOriginAttributes;
}

NS_IMETHODIMP nsOpenWindowInfo::GetNextRemoteBrowserId(
uint64_t* aNextRemoteBrowserId) {
*aNextRemoteBrowserId = mNextRemoteBrowserId;
return NS_OK;
}
30 changes: 30 additions & 0 deletions toolkit/components/windowwatcher/nsOpenWindowInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* -*- 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 nsOpenWindowInfo_h
#define nsOpenWindowInfo_h

#include "nsIOpenWindowInfo.h"
#include "nsISupportsImpl.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/RefPtr.h"

class nsOpenWindowInfo : public nsIOpenWindowInfo {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOPENWINDOWINFO

bool mForceNoOpener = false;
bool mIsRemote = false;
uint64_t mNextRemoteBrowserId = 0;
OriginAttributes mOriginAttributes;
RefPtr<BrowsingContext> mParent;

private:
virtual ~nsOpenWindowInfo() = default;
};

#endif // nsOpenWindowInfo_h

0 comments on commit 20da588

Please sign in to comment.