2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2000-11-04 11:21:20 +03:00
|
|
|
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-10-18 03:05:16 +04:00
|
|
|
#include "mozilla/dom/WindowRootBinding.h"
|
2000-11-04 11:21:20 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsWindowRoot.h"
|
2010-02-20 19:07:03 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2000-11-04 11:21:20 +03:00
|
|
|
#include "nsLayoutCID.h"
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsContentCID.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsString.h"
|
2010-02-20 19:07:03 +03:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsFocusManager.h"
|
2013-03-22 04:05:20 +04:00
|
|
|
#include "nsIContent.h"
|
2010-02-20 19:07:03 +03:00
|
|
|
#include "nsIControllers.h"
|
2013-09-23 03:23:30 +04:00
|
|
|
#include "nsIController.h"
|
2014-10-18 03:05:16 +04:00
|
|
|
#include "xpcpublic.h"
|
2007-09-23 20:10:12 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2019-04-10 00:38:15 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2017-10-31 02:14:51 +03:00
|
|
|
#include "mozilla/dom/HTMLTextAreaElement.h"
|
2018-02-21 01:10:44 +03:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2019-02-22 22:28:50 +03:00
|
|
|
#include "mozilla/dom/JSWindowActorService.h"
|
2007-09-23 18:05:27 +04:00
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
#ifdef MOZ_XUL
|
2017-02-02 18:32:58 +03:00
|
|
|
# include "nsXULElement.h"
|
2010-02-20 19:07:03 +03:00
|
|
|
#endif
|
|
|
|
|
2013-04-17 01:16:08 +04:00
|
|
|
using namespace mozilla;
|
2013-04-06 04:44:15 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsWindowRoot::nsWindowRoot(nsPIDOMWindowOuter* aWindow) {
|
2000-11-04 11:21:20 +03:00
|
|
|
mWindow = aWindow;
|
2019-06-03 18:12:24 +03:00
|
|
|
mShowFocusRings = StaticPrefs::browser_display_show_focus_rings();
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowRoot::~nsWindowRoot() {
|
2006-01-19 05:43:39 +03:00
|
|
|
if (mListenerManager) {
|
|
|
|
mListenerManager->Disconnect();
|
|
|
|
}
|
2019-02-22 22:28:50 +03:00
|
|
|
|
|
|
|
JSWindowActorService::UnregisterWindowRoot(this);
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsWindowRoot, mWindow, mListenerManager,
|
|
|
|
mParent)
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsWindowRoot)
|
2013-01-29 17:44:01 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2018-04-20 07:49:30 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2005-12-03 10:42:40 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIWindowRoot)
|
2013-01-29 17:44:01 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
|
2005-12-03 10:42:40 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 14:11:31 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsWindowRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsWindowRoot)
|
2000-11-04 11:21:20 +03:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
bool nsWindowRoot::DispatchEvent(Event& aEvent, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) {
|
2006-03-07 20:08:51 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2014-03-18 08:48:21 +04:00
|
|
|
nsresult rv = EventDispatcher::DispatchDOMEvent(
|
2018-04-05 20:42:41 +03:00
|
|
|
static_cast<EventTarget*>(this), nullptr, &aEvent, nullptr, &status);
|
|
|
|
bool retval = !aEvent.DefaultPrevented(aCallerType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
return retval;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:42 +03:00
|
|
|
bool nsWindowRoot::ComputeDefaultWantsUntrusted(ErrorResult& aRv) {
|
|
|
|
return false;
|
2018-04-05 20:42:42 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 03:32:04 +04:00
|
|
|
EventListenerManager* nsWindowRoot::GetOrCreateListenerManager() {
|
|
|
|
if (!mListenerManager) {
|
2011-06-24 06:18:01 +04:00
|
|
|
mListenerManager =
|
2014-03-17 10:56:53 +04:00
|
|
|
new EventListenerManager(static_cast<EventTarget*>(this));
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2009-06-23 15:23:52 +04:00
|
|
|
return mListenerManager;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 03:32:04 +04:00
|
|
|
EventListenerManager* nsWindowRoot::GetExistingListenerManager() const {
|
|
|
|
return mListenerManager;
|
|
|
|
}
|
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
void nsWindowRoot::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = true;
|
|
|
|
aVisitor.mForceContentDispatch = true; // FIXME! Bug 329119
|
2006-03-07 20:08:51 +03:00
|
|
|
// To keep mWindow alive
|
2010-02-20 19:07:03 +03:00
|
|
|
aVisitor.mItemData = static_cast<nsISupports*>(mWindow);
|
2017-12-18 19:07:36 +03:00
|
|
|
aVisitor.SetParentTarget(mParent, false);
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
|
|
|
|
2014-03-18 08:48:20 +04:00
|
|
|
nsresult nsWindowRoot::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
2006-03-07 20:08:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:26:56 +03:00
|
|
|
nsPIDOMWindowOuter* nsWindowRoot::GetOwnerGlobalForBindingsInternal() {
|
2019-01-02 16:27:05 +03:00
|
|
|
return mWindow;
|
2013-05-31 01:46:39 +04:00
|
|
|
}
|
|
|
|
|
2015-05-12 22:56:39 +03:00
|
|
|
nsIGlobalObject* nsWindowRoot::GetOwnerGlobal() const {
|
|
|
|
nsCOMPtr<nsIGlobalObject> global =
|
|
|
|
do_QueryInterface(mWindow->GetCurrentInnerWindow());
|
|
|
|
// We're still holding a ref to it, so returning the raw pointer is ok...
|
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
2007-07-06 17:47:50 +04:00
|
|
|
nsPIDOMWindowOuter* nsWindowRoot::GetWindow() { return mWindow; }
|
|
|
|
|
2017-09-07 16:54:49 +03:00
|
|
|
nsresult nsWindowRoot::GetControllers(bool aForVisibleWindow,
|
|
|
|
nsIControllers** aResult) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2010-02-20 19:07:03 +03:00
|
|
|
|
|
|
|
// XXX: we should fix this so there's a generic interface that
|
|
|
|
// describes controllers, so this code would have no special
|
|
|
|
// knowledge of what object might have controllers.
|
|
|
|
|
2017-09-07 16:54:49 +03:00
|
|
|
nsFocusManager::SearchRange searchRange =
|
|
|
|
aForVisibleWindow ? nsFocusManager::eIncludeVisibleDescendants
|
|
|
|
: nsFocusManager::eIncludeAllDescendants;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2017-09-07 16:54:49 +03:00
|
|
|
nsIContent* focusedContent = nsFocusManager::GetFocusedDescendant(
|
|
|
|
mWindow, searchRange, getter_AddRefs(focusedWindow));
|
2010-02-20 19:07:03 +03:00
|
|
|
if (focusedContent) {
|
|
|
|
#ifdef MOZ_XUL
|
2018-03-22 00:39:04 +03:00
|
|
|
RefPtr<nsXULElement> xulElement = nsXULElement::FromNode(focusedContent);
|
2017-02-02 18:32:58 +03:00
|
|
|
if (xulElement) {
|
|
|
|
ErrorResult rv;
|
|
|
|
*aResult = xulElement->GetControllers(rv);
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return rv.StealNSResult();
|
|
|
|
}
|
2010-02-20 19:07:03 +03:00
|
|
|
#endif
|
|
|
|
|
2017-10-31 02:14:51 +03:00
|
|
|
HTMLTextAreaElement* htmlTextArea =
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLTextAreaElement::FromNode(focusedContent);
|
2010-02-20 19:07:03 +03:00
|
|
|
if (htmlTextArea) return htmlTextArea->GetControllers(aResult);
|
|
|
|
|
2018-02-21 01:10:44 +03:00
|
|
|
HTMLInputElement* htmlInputElement =
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement::FromNode(focusedContent);
|
2010-02-20 19:07:03 +03:00
|
|
|
if (htmlInputElement) return htmlInputElement->GetControllers(aResult);
|
|
|
|
|
|
|
|
if (focusedContent->IsEditable() && focusedWindow)
|
|
|
|
return focusedWindow->GetControllers(aResult);
|
|
|
|
} else {
|
2016-01-30 20:05:36 +03:00
|
|
|
return focusedWindow->GetControllers(aResult);
|
2010-02-20 19:07:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-07 16:54:49 +03:00
|
|
|
nsresult nsWindowRoot::GetControllerForCommand(const char* aCommand,
|
|
|
|
bool aForVisibleWindow,
|
2010-02-20 19:07:03 +03:00
|
|
|
nsIController** _retval) {
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2010-02-20 19:07:03 +03:00
|
|
|
|
2011-10-15 11:27:57 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2017-09-07 16:54:49 +03:00
|
|
|
GetControllers(aForVisibleWindow, getter_AddRefs(controllers));
|
2011-10-15 11:27:57 +04:00
|
|
|
if (controllers) {
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
controllers->GetControllerForCommand(aCommand,
|
|
|
|
getter_AddRefs(controller));
|
|
|
|
if (controller) {
|
|
|
|
controller.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-20 19:07:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 16:54:49 +03:00
|
|
|
nsFocusManager::SearchRange searchRange =
|
|
|
|
aForVisibleWindow ? nsFocusManager::eIncludeVisibleDescendants
|
|
|
|
: nsFocusManager::eIncludeAllDescendants;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2017-09-07 16:54:49 +03:00
|
|
|
nsFocusManager::GetFocusedDescendant(mWindow, searchRange,
|
|
|
|
getter_AddRefs(focusedWindow));
|
2010-02-20 19:07:03 +03:00
|
|
|
while (focusedWindow) {
|
2011-10-15 11:27:57 +04:00
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
|
|
|
focusedWindow->GetControllers(getter_AddRefs(controllers));
|
|
|
|
if (controllers) {
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
controllers->GetControllerForCommand(aCommand,
|
|
|
|
getter_AddRefs(controller));
|
2010-02-20 19:07:03 +03:00
|
|
|
if (controller) {
|
2011-10-15 11:27:57 +04:00
|
|
|
controller.forget(_retval);
|
2010-02-20 19:07:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXndeakin P3 is this casting safe?
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowOuter* win = nsGlobalWindowOuter::Cast(focusedWindow);
|
2010-02-20 19:07:03 +03:00
|
|
|
focusedWindow = win->GetPrivateParent();
|
|
|
|
}
|
2016-04-26 11:23:17 +03:00
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-12-09 18:48:27 +03:00
|
|
|
void nsWindowRoot::GetEnabledDisabledCommandsForControllers(
|
|
|
|
nsIControllers* aControllers,
|
2019-05-21 20:06:06 +03:00
|
|
|
nsTHashtable<nsCStringHashKey>& aCommandsHandled,
|
2014-12-09 18:48:27 +03:00
|
|
|
nsTArray<nsCString>& aEnabledCommands,
|
|
|
|
nsTArray<nsCString>& aDisabledCommands) {
|
|
|
|
uint32_t controllerCount;
|
|
|
|
aControllers->GetControllerCount(&controllerCount);
|
|
|
|
for (uint32_t c = 0; c < controllerCount; c++) {
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
aControllers->GetControllerAt(c, getter_AddRefs(controller));
|
|
|
|
|
|
|
|
nsCOMPtr<nsICommandController> commandController(
|
|
|
|
do_QueryInterface(controller));
|
|
|
|
if (commandController) {
|
2019-05-21 20:06:06 +03:00
|
|
|
// All of our default command controllers have 20-60 commands. Let's just
|
|
|
|
// leave enough space here for all of them so we probably don't need to
|
|
|
|
// heap-allocate.
|
|
|
|
AutoTArray<nsCString, 64> commands;
|
|
|
|
if (NS_SUCCEEDED(commandController->GetSupportedCommands(commands))) {
|
|
|
|
for (auto& commandStr : commands) {
|
2014-12-09 18:48:27 +03:00
|
|
|
// Use a hash to determine which commands have already been handled by
|
|
|
|
// earlier controllers, as the earlier controller's result should get
|
|
|
|
// priority.
|
2019-05-21 20:06:06 +03:00
|
|
|
if (aCommandsHandled.EnsureInserted(commandStr)) {
|
2017-06-17 01:06:04 +03:00
|
|
|
// We inserted a new entry into aCommandsHandled.
|
2014-12-09 18:48:27 +03:00
|
|
|
bool enabled = false;
|
2019-05-21 20:06:06 +03:00
|
|
|
controller->IsCommandEnabled(commandStr.get(), &enabled);
|
2014-12-09 18:48:27 +03:00
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
aEnabledCommands.AppendElement(commandStr);
|
|
|
|
} else {
|
|
|
|
aDisabledCommands.AppendElement(commandStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWindowRoot::GetEnabledDisabledCommands(
|
|
|
|
nsTArray<nsCString>& aEnabledCommands,
|
|
|
|
nsTArray<nsCString>& aDisabledCommands) {
|
2019-05-21 20:06:06 +03:00
|
|
|
nsTHashtable<nsCStringHashKey> commandsHandled;
|
2014-12-09 18:48:27 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2017-09-07 16:54:49 +03:00
|
|
|
GetControllers(false, getter_AddRefs(controllers));
|
2014-12-09 18:48:27 +03:00
|
|
|
if (controllers) {
|
|
|
|
GetEnabledDisabledCommandsForControllers(
|
|
|
|
controllers, commandsHandled, aEnabledCommands, aDisabledCommands);
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2017-09-07 16:54:49 +03:00
|
|
|
nsFocusManager::GetFocusedDescendant(mWindow,
|
|
|
|
nsFocusManager::eIncludeAllDescendants,
|
|
|
|
getter_AddRefs(focusedWindow));
|
2014-12-09 18:48:27 +03:00
|
|
|
while (focusedWindow) {
|
|
|
|
focusedWindow->GetControllers(getter_AddRefs(controllers));
|
|
|
|
if (controllers) {
|
|
|
|
GetEnabledDisabledCommandsForControllers(
|
|
|
|
controllers, commandsHandled, aEnabledCommands, aDisabledCommands);
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowOuter* win = nsGlobalWindowOuter::Cast(focusedWindow);
|
2014-12-09 18:48:27 +03:00
|
|
|
focusedWindow = win->GetPrivateParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
already_AddRefed<nsINode> nsWindowRoot::GetPopupNode() {
|
2018-01-31 22:49:26 +03:00
|
|
|
nsCOMPtr<nsINode> popupNode = do_QueryReferent(mPopupNode);
|
|
|
|
return popupNode.forget();
|
2010-02-20 19:07:03 +03:00
|
|
|
}
|
|
|
|
|
2018-01-31 22:49:26 +03:00
|
|
|
void nsWindowRoot::SetPopupNode(nsINode* aNode) {
|
2016-06-23 17:14:19 +03:00
|
|
|
mPopupNode = do_GetWeakReference(aNode);
|
2010-02-20 19:07:03 +03:00
|
|
|
}
|
|
|
|
|
2014-10-18 03:05:16 +04:00
|
|
|
nsIGlobalObject* nsWindowRoot::GetParentObject() {
|
|
|
|
return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
|
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* nsWindowRoot::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return mozilla::dom::WindowRoot_Binding::Wrap(aCx, this, aGivenProto);
|
2014-10-18 03:05:16 +04:00
|
|
|
}
|
|
|
|
|
2019-04-25 07:05:40 +03:00
|
|
|
void nsWindowRoot::AddBrowser(nsIRemoteTab* aBrowser) {
|
|
|
|
nsWeakPtr weakBrowser = do_GetWeakReference(aBrowser);
|
2015-06-08 08:39:39 +03:00
|
|
|
mWeakBrowsers.PutEntry(weakBrowser);
|
|
|
|
}
|
|
|
|
|
2019-04-25 07:05:40 +03:00
|
|
|
void nsWindowRoot::RemoveBrowser(nsIRemoteTab* aBrowser) {
|
|
|
|
nsWeakPtr weakBrowser = do_GetWeakReference(aBrowser);
|
2015-06-08 08:39:39 +03:00
|
|
|
mWeakBrowsers.RemoveEntry(weakBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWindowRoot::EnumerateBrowsers(BrowserEnumerator aEnumFunc, void* aArg) {
|
|
|
|
// Collect strong references to all browsers in a separate array in
|
|
|
|
// case aEnumFunc alters mWeakBrowsers.
|
2019-04-25 07:05:40 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIRemoteTab>> remoteTabs;
|
2015-07-22 19:42:01 +03:00
|
|
|
for (auto iter = mWeakBrowsers.ConstIter(); !iter.Done(); iter.Next()) {
|
2019-04-25 07:05:40 +03:00
|
|
|
nsCOMPtr<nsIRemoteTab> remoteTab(do_QueryReferent(iter.Get()->GetKey()));
|
|
|
|
if (remoteTab) {
|
|
|
|
remoteTabs.AppendElement(remoteTab);
|
2015-07-22 19:42:01 +03:00
|
|
|
}
|
|
|
|
}
|
2015-06-08 08:39:39 +03:00
|
|
|
|
2019-04-25 07:05:40 +03:00
|
|
|
for (uint32_t i = 0; i < remoteTabs.Length(); ++i) {
|
|
|
|
aEnumFunc(remoteTabs[i], aArg);
|
2015-06-08 08:39:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
already_AddRefed<EventTarget> NS_NewWindowRoot(nsPIDOMWindowOuter* aWindow) {
|
2013-04-06 04:44:15 +04:00
|
|
|
nsCOMPtr<EventTarget> result = new nsWindowRoot(aWindow);
|
2019-02-22 22:28:50 +03:00
|
|
|
|
|
|
|
RefPtr<JSWindowActorService> wasvc = JSWindowActorService::GetSingleton();
|
|
|
|
if (wasvc) {
|
|
|
|
wasvc->RegisterWindowRoot(result);
|
|
|
|
}
|
|
|
|
|
2013-04-06 04:44:15 +04:00
|
|
|
return result.forget();
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|