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-08-05 06:40:18 +04:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2011-06-11 11:52:24 +04:00
|
|
|
#include "nsIDOMHTMLTextAreaElement.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"
|
2015-06-08 08:39:39 +03:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2007-09-23 18:05:27 +04:00
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#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;
|
2015-02-06 19:26:29 +03:00
|
|
|
MOZ_ASSERT(mWindow->IsOuterWindow());
|
2016-06-09 14:59:31 +03:00
|
|
|
|
|
|
|
// Keyboard indicators are not shown on Mac by default.
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
mShowAccelerators = false;
|
|
|
|
mShowFocusRings = false;
|
|
|
|
#else
|
|
|
|
mShowAccelerators = true;
|
|
|
|
mShowFocusRings = true;
|
|
|
|
#endif
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowRoot::~nsWindowRoot()
|
|
|
|
{
|
2006-01-19 05:43:39 +03:00
|
|
|
if (mListenerManager) {
|
|
|
|
mListenerManager->Disconnect();
|
|
|
|
}
|
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
|
2007-05-14 13:11:38 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEventTarget)
|
2005-12-03 10:42:40 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIWindowRoot)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
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
|
|
|
|
2011-06-24 06:17:58 +04:00
|
|
|
NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot)
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
if (RefPtr<EventListenerManager> elm = GetExistingListenerManager()) {
|
2011-06-24 06:18:02 +04:00
|
|
|
elm->RemoveEventListener(aType, aListener, aUseCapture);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2011-11-25 05:09:58 +04:00
|
|
|
NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsWindowRoot)
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindowRoot::DispatchEvent(nsIDOMEvent* aEvt, bool *aRetVal)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2006-03-07 20:08:51 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2014-03-18 08:48:21 +04:00
|
|
|
nsresult rv = EventDispatcher::DispatchDOMEvent(
|
2013-04-20 02:18:33 +04:00
|
|
|
static_cast<EventTarget*>(this), nullptr, aEvt, nullptr, &status);
|
2011-06-24 06:17:59 +04:00
|
|
|
*aRetVal = (status != nsEventStatus_eConsumeNoDefault);
|
2006-03-07 20:08:51 +03:00
|
|
|
return rv;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2007-02-16 02:04:33 +03:00
|
|
|
nsresult
|
2013-10-02 07:46:04 +04:00
|
|
|
nsWindowRoot::DispatchDOMEvent(WidgetEvent* aEvent,
|
2007-02-16 02:04:33 +03:00
|
|
|
nsIDOMEvent* aDOMEvent,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
2014-03-18 08:48:21 +04:00
|
|
|
return EventDispatcher::DispatchDOMEvent(static_cast<EventTarget*>(this),
|
|
|
|
aEvent, aDOMEvent,
|
|
|
|
aPresContext, aEventStatus);
|
2007-02-16 02:04:33 +03:00
|
|
|
}
|
|
|
|
|
2005-04-29 03:48:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener *aListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseCapture, bool aWantsUntrusted,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aOptionalArgc)
|
2005-04-29 03:48:28 +04:00
|
|
|
{
|
2011-06-24 06:17:59 +04:00
|
|
|
NS_ASSERTION(!aWantsUntrusted || aOptionalArgc > 1,
|
2010-01-13 16:50:01 +03:00
|
|
|
"Won't check if this is chrome, you want to set "
|
2011-10-17 18:59:28 +04:00
|
|
|
"aWantsUntrusted to false or make the aWantsUntrusted "
|
2010-01-13 16:50:01 +03:00
|
|
|
"explicit by making optional_argc non-zero.");
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = GetOrCreateListenerManager();
|
2011-06-24 06:18:02 +04:00
|
|
|
NS_ENSURE_STATE(elm);
|
2011-08-18 13:45:00 +04:00
|
|
|
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
|
|
|
|
return NS_OK;
|
2005-04-29 03:48:28 +04:00
|
|
|
}
|
|
|
|
|
2013-04-17 01:16:08 +04:00
|
|
|
void
|
|
|
|
nsWindowRoot::AddEventListener(const nsAString& aType,
|
2013-09-24 04:25:17 +04:00
|
|
|
EventListener* aListener,
|
2016-04-26 11:23:17 +03:00
|
|
|
const AddEventListenerOptionsOrBoolean& aOptions,
|
2013-04-17 01:16:08 +04:00
|
|
|
const Nullable<bool>& aWantsUntrusted,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value();
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = GetOrCreateListenerManager();
|
2013-04-17 01:16:08 +04:00
|
|
|
if (!elm) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-26 11:23:17 +03:00
|
|
|
elm->AddEventListener(aType, aListener, aOptions, wantsUntrusted);
|
2013-04-17 01:16:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-25 05:09:58 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::AddSystemEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener *aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
bool aWantsUntrusted,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aOptionalArgc)
|
2011-11-25 05:09:58 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aWantsUntrusted || aOptionalArgc > 1,
|
|
|
|
"Won't check if this is chrome, you want to set "
|
|
|
|
"aWantsUntrusted to false or make the aWantsUntrusted "
|
|
|
|
"explicit by making optional_argc non-zero.");
|
|
|
|
|
|
|
|
return NS_AddSystemEventListener(this, aType, aListener, aUseCapture,
|
|
|
|
aWantsUntrusted);
|
|
|
|
}
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager*
|
2013-10-23 03:32:04 +04:00
|
|
|
nsWindowRoot::GetOrCreateListenerManager()
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2013-10-23 03:32:04 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager*
|
2013-10-23 03:32:04 +04:00
|
|
|
nsWindowRoot::GetExistingListenerManager() const
|
|
|
|
{
|
|
|
|
return mListenerManager;
|
|
|
|
}
|
|
|
|
|
2011-06-24 06:17:58 +04:00
|
|
|
nsIScriptContext*
|
|
|
|
nsWindowRoot::GetContextForEventHandlers(nsresult* aRv)
|
|
|
|
{
|
|
|
|
*aRv = NS_OK;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-06-24 06:17:58 +04:00
|
|
|
}
|
2005-12-03 10:42:40 +03:00
|
|
|
|
2007-02-16 03:03:57 +03:00
|
|
|
nsresult
|
2014-03-18 08:48:19 +04:00
|
|
|
nsWindowRoot::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2006-03-07 20:08:51 +03:00
|
|
|
{
|
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);
|
2010-02-20 20:05:20 +03:00
|
|
|
aVisitor.mParentTarget = mParent;
|
2006-03-07 20:08:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-16 03:03:57 +03:00
|
|
|
nsresult
|
2014-03-18 08:48:20 +04:00
|
|
|
nsWindowRoot::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
2006-03-07 20:08:51 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter*
|
2015-05-12 22:56:39 +03:00
|
|
|
nsWindowRoot::GetOwnerGlobalForBindings()
|
2013-05-31 01:46:39 +04:00
|
|
|
{
|
|
|
|
return GetWindow();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter*
|
2007-07-06 17:47:50 +04:00
|
|
|
nsWindowRoot::GetWindow()
|
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2010-02-20 19:07:03 +03:00
|
|
|
nsresult
|
|
|
|
nsWindowRoot::GetControllers(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.
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2010-02-20 19:07:03 +03:00
|
|
|
nsIContent* focusedContent =
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFocusManager::GetFocusedDescendant(mWindow, true, getter_AddRefs(focusedWindow));
|
2010-02-20 19:07:03 +03:00
|
|
|
if (focusedContent) {
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(focusedContent));
|
|
|
|
if (xulElement)
|
|
|
|
return xulElement->GetControllers(aResult);
|
|
|
|
#endif
|
|
|
|
|
2011-06-11 11:52:24 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> htmlTextArea =
|
2010-02-20 19:07:03 +03:00
|
|
|
do_QueryInterface(focusedContent);
|
|
|
|
if (htmlTextArea)
|
|
|
|
return htmlTextArea->GetControllers(aResult);
|
|
|
|
|
2010-08-05 06:40:18 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> htmlInputElement =
|
2010-02-20 19:07:03 +03:00
|
|
|
do_QueryInterface(focusedContent);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsWindowRoot::GetControllerForCommand(const char * aCommand,
|
|
|
|
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;
|
|
|
|
GetControllers(getter_AddRefs(controllers));
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFocusManager::GetFocusedDescendant(mWindow, true, 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?
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow *win = nsGlobalWindow::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,
|
|
|
|
nsTHashtable<nsCharPtrHashKey>& aCommandsHandled,
|
|
|
|
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) {
|
|
|
|
uint32_t commandsCount;
|
|
|
|
char** commands;
|
|
|
|
if (NS_SUCCEEDED(commandController->GetSupportedCommands(&commandsCount, &commands))) {
|
|
|
|
for (uint32_t e = 0; e < commandsCount; e++) {
|
|
|
|
// Use a hash to determine which commands have already been handled by
|
|
|
|
// earlier controllers, as the earlier controller's result should get
|
|
|
|
// priority.
|
|
|
|
if (!aCommandsHandled.Contains(commands[e])) {
|
|
|
|
aCommandsHandled.PutEntry(commands[e]);
|
|
|
|
|
|
|
|
bool enabled = false;
|
|
|
|
controller->IsCommandEnabled(commands[e], &enabled);
|
|
|
|
|
|
|
|
const nsDependentCSubstring commandStr(commands[e], strlen(commands[e]));
|
|
|
|
if (enabled) {
|
|
|
|
aEnabledCommands.AppendElement(commandStr);
|
|
|
|
} else {
|
|
|
|
aDisabledCommands.AppendElement(commandStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(commandsCount, commands);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindowRoot::GetEnabledDisabledCommands(nsTArray<nsCString>& aEnabledCommands,
|
|
|
|
nsTArray<nsCString>& aDisabledCommands)
|
|
|
|
{
|
|
|
|
nsTHashtable<nsCharPtrHashKey> commandsHandled;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
|
|
|
GetControllers(getter_AddRefs(controllers));
|
|
|
|
if (controllers) {
|
|
|
|
GetEnabledDisabledCommandsForControllers(controllers, commandsHandled,
|
|
|
|
aEnabledCommands, aDisabledCommands);
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
2014-12-09 18:48:27 +03:00
|
|
|
nsFocusManager::GetFocusedDescendant(mWindow, true, getter_AddRefs(focusedWindow));
|
|
|
|
while (focusedWindow) {
|
|
|
|
focusedWindow->GetControllers(getter_AddRefs(controllers));
|
|
|
|
if (controllers) {
|
|
|
|
GetEnabledDisabledCommandsForControllers(controllers, commandsHandled,
|
|
|
|
aEnabledCommands, aDisabledCommands);
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow* win = nsGlobalWindow::Cast(focusedWindow);
|
2014-12-09 18:48:27 +03:00
|
|
|
focusedWindow = win->GetPrivateParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
nsIDOMNode*
|
|
|
|
nsWindowRoot::GetPopupNode()
|
2010-02-20 19:07:03 +03:00
|
|
|
{
|
2016-06-23 17:14:19 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> popupNode = do_QueryReferent(mPopupNode);
|
|
|
|
return popupNode;
|
2010-02-20 19:07:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindowRoot::SetPopupNode(nsIDOMNode* 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());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
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
|
|
|
nsWindowRoot::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-10-18 03:05:16 +04:00
|
|
|
{
|
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
|
|
|
return mozilla::dom::WindowRootBinding::Wrap(aCx, this, aGivenProto);
|
2014-10-18 03:05:16 +04:00
|
|
|
}
|
|
|
|
|
2015-06-08 08:39:39 +03:00
|
|
|
void
|
|
|
|
nsWindowRoot::AddBrowser(mozilla::dom::TabParent* aBrowser)
|
|
|
|
{
|
|
|
|
nsWeakPtr weakBrowser = do_GetWeakReference(static_cast<nsITabParent*>(aBrowser));
|
|
|
|
mWeakBrowsers.PutEntry(weakBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindowRoot::RemoveBrowser(mozilla::dom::TabParent* aBrowser)
|
|
|
|
{
|
|
|
|
nsWeakPtr weakBrowser = do_GetWeakReference(static_cast<nsITabParent*>(aBrowser));
|
|
|
|
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.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<TabParent>> tabParents;
|
2015-07-22 19:42:01 +03:00
|
|
|
for (auto iter = mWeakBrowsers.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsCOMPtr<nsITabParent> tabParent(do_QueryReferent(iter.Get()->GetKey()));
|
|
|
|
if (TabParent* tab = TabParent::GetFrom(tabParent)) {
|
|
|
|
tabParents.AppendElement(tab);
|
|
|
|
}
|
|
|
|
}
|
2015-06-08 08:39:39 +03:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < tabParents.Length(); ++i) {
|
|
|
|
aEnumFunc(tabParents[i], aArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-04-06 04:44:15 +04:00
|
|
|
already_AddRefed<EventTarget>
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_NewWindowRoot(nsPIDOMWindowOuter* aWindow)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2013-04-06 04:44:15 +04:00
|
|
|
nsCOMPtr<EventTarget> result = new nsWindowRoot(aWindow);
|
|
|
|
return result.forget();
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|