mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1481238 - Create WebIDL interface for BrowsingContext. r=peterv
Expose Chrome only WebIDL to interface with BrowsingContext from script. The API consists of parent, firstChild and nextSibling attributes for BrowsingContext, and the browsingContext attribute for Window. --HG-- extra : rebase_source : 772d25e8b4e5526453545ddb2b1607845f3b65ea
This commit is contained in:
parent
d341a7e83a
commit
82694e9ac3
@ -6,6 +6,7 @@
|
||||
|
||||
#include "BrowsingContext.h"
|
||||
|
||||
#include "mozilla/dom/BrowsingContextBinding.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
@ -131,8 +132,8 @@ BrowsingContext::Attach(BrowsingContext* aParent)
|
||||
MOZ_LOG(GetLog(),
|
||||
LogLevel::Debug,
|
||||
("%s: %s 0x%08" PRIx64 " to 0x%08" PRIx64,
|
||||
wasCached ? "Re-connecting" : "Connecting",
|
||||
XRE_IsParentProcess() ? "Parent" : "Child",
|
||||
wasCached ? "Re-connecting" : "Connecting",
|
||||
Id(),
|
||||
aParent ? aParent->Id() : 0));
|
||||
|
||||
@ -230,6 +231,22 @@ BrowsingContext::OwnerProcessId() const
|
||||
return mProcessId.value();
|
||||
}
|
||||
|
||||
void
|
||||
BrowsingContext::GetChildren(nsTArray<RefPtr<BrowsingContext>>& aChildren)
|
||||
{
|
||||
for (BrowsingContext* context : mChildren) {
|
||||
aChildren.AppendElement(context);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
BrowsingContext::GetRootBrowsingContexts(nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts)
|
||||
{
|
||||
for (BrowsingContext* context : *sRootBrowsingContexts) {
|
||||
aBrowsingContexts.AppendElement(context);
|
||||
}
|
||||
}
|
||||
|
||||
BrowsingContext::~BrowsingContext()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(!isInList());
|
||||
@ -239,6 +256,19 @@ BrowsingContext::~BrowsingContext()
|
||||
}
|
||||
}
|
||||
|
||||
nsISupports*
|
||||
BrowsingContext::GetParentObject() const
|
||||
{
|
||||
return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
|
||||
}
|
||||
|
||||
JSObject*
|
||||
BrowsingContext::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return BrowsingContext_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
static void
|
||||
ImplCycleCollectionUnlink(BrowsingContext::Children& aField)
|
||||
{
|
||||
@ -257,7 +287,7 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(BrowsingContext, mDocShell, mChildren)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BrowsingContext, mDocShell, mChildren)
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(BrowsingContext, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(BrowsingContext, Release)
|
||||
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsIDocShell;
|
||||
|
||||
@ -36,7 +38,8 @@ namespace dom {
|
||||
// BrowsingContext tree for a tab, in both the parent and the child
|
||||
// process.
|
||||
class BrowsingContext
|
||||
: public SupportsWeakPtr<BrowsingContext>
|
||||
: public nsWrapperCache
|
||||
, public SupportsWeakPtr<BrowsingContext>
|
||||
, public LinkedListElement<RefPtr<BrowsingContext>>
|
||||
{
|
||||
public:
|
||||
@ -81,16 +84,28 @@ public:
|
||||
uint64_t OwnerProcessId() const;
|
||||
bool IsOwnedByProcess() const { return mProcessId.isSome(); }
|
||||
|
||||
BrowsingContext* Parent() const { return mParent; }
|
||||
already_AddRefed<BrowsingContext> GetParent()
|
||||
{
|
||||
return do_AddRef(mParent.get());
|
||||
}
|
||||
|
||||
void GetChildren(nsTArray<RefPtr<BrowsingContext>>& aChildren);
|
||||
|
||||
static void GetRootBrowsingContexts(
|
||||
nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts);
|
||||
|
||||
nsISupports* GetParentObject() const;
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext)
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BrowsingContext)
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(BrowsingContext)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(BrowsingContext)
|
||||
|
||||
using Children = AutoCleanLinkedList<RefPtr<BrowsingContext>>;
|
||||
|
||||
private:
|
||||
~BrowsingContext();
|
||||
virtual ~BrowsingContext();
|
||||
|
||||
const uint64_t mBrowsingContextId;
|
||||
|
||||
|
@ -14335,6 +14335,13 @@ nsDocShell::GetBrowsingContext() const
|
||||
return browsingContext.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetBrowsingContext(BrowsingContext** aBrowsingContext)
|
||||
{
|
||||
*aBrowsingContext = do_AddRef(mBrowsingContext).take();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsIDocShell::AttachBrowsingContext(nsIDocShell* aParentDocShell)
|
||||
{
|
||||
|
@ -65,6 +65,7 @@ interface nsILoadURIDelegate;
|
||||
native TabChildRef(already_AddRefed<nsITabChild>);
|
||||
native nsDocShellLoadInfoPtr(nsDocShellLoadInfo*);
|
||||
|
||||
webidl BrowsingContext;
|
||||
webidl ContentFrameMessageManager;
|
||||
webidl EventTarget;
|
||||
|
||||
@ -1190,6 +1191,11 @@ interface nsIDocShell : nsIDocShellTreeItem
|
||||
void DetachBrowsingContext();
|
||||
%}
|
||||
|
||||
/**
|
||||
* BrowsingContext associated with the DocShell.
|
||||
*/
|
||||
readonly attribute BrowsingContext browsingContext;
|
||||
|
||||
/**
|
||||
* Allowed CSS display modes. This needs to be kept in
|
||||
* sync with similar values in nsStyleConsts.h
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "mozilla/PerformanceMetricsCollector.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/IdleDeadline.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
@ -781,5 +782,12 @@ ChromeUtils::RequestIOActivity(GlobalObject& aGlobal, ErrorResult& aRv)
|
||||
return domPromise.forget();
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
ChromeUtils::GetRootBrowsingContexts(GlobalObject& aGlobal,
|
||||
nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts)
|
||||
{
|
||||
BrowsingContext::GetRootBrowsingContexts(aBrowsingContexts);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -21,6 +21,7 @@ class HeapSnapshot;
|
||||
namespace dom {
|
||||
|
||||
class ArrayBufferViewOrArrayBuffer;
|
||||
class BrowsingContext;
|
||||
class IdleRequestCallback;
|
||||
struct IdleRequestOptions;
|
||||
class MozQueryInterface;
|
||||
@ -187,6 +188,10 @@ public:
|
||||
|
||||
static already_AddRefed<Promise>
|
||||
RequestIOActivity(GlobalObject& aGlobal, ErrorResult& aRv);
|
||||
|
||||
static void
|
||||
GetRootBrowsingContexts(GlobalObject& aGlobal,
|
||||
nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
13
dom/chrome-webidl/BrowsingContext.webidl
Normal file
13
dom/chrome-webidl/BrowsingContext.webidl
Normal file
@ -0,0 +1,13 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
[Exposed=(Window, System), ChromeOnly]
|
||||
interface BrowsingContext {
|
||||
readonly attribute BrowsingContext? parent;
|
||||
|
||||
sequence<BrowsingContext> getChildren();
|
||||
|
||||
readonly attribute unsigned long long id;
|
||||
};
|
@ -355,6 +355,9 @@ partial namespace ChromeUtils {
|
||||
*/
|
||||
[Throws]
|
||||
Promise<sequence<IOActivityDataDictionary>> requestIOActivity();
|
||||
|
||||
[ChromeOnly]
|
||||
sequence<BrowsingContext> getRootBrowsingContexts();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,7 @@ PREPROCESSED_WEBIDL_FILES = [
|
||||
]
|
||||
|
||||
WEBIDL_FILES = [
|
||||
'BrowsingContext.webidl',
|
||||
'ChannelWrapper.webidl',
|
||||
'DominatorTree.webidl',
|
||||
'HeapSnapshot.webidl',
|
||||
|
Loading…
Reference in New Issue
Block a user