/* -*- 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/. */
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;
}
// 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.
// If this is the parent process, check if a child browsing context from // another process is focused, and ask if it has a controller actor that // supports the command. if (XRE_IsParentProcess()) {
nsFocusManager* fm = nsFocusManager::GetFocusManager(); if (!fm) { return NS_ERROR_FAILURE;
}
// Unfortunately, messages updating the active/focus state in the focus // manager don't happen fast enough in the case when switching focus between // processes when clicking on a chrome UI element while a child tab is // focused, so we need to check whether the focus manager thinks a child // frame is focused as well.
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
nsIContent* focusedContent = nsFocusManager::GetFocusedDescendant(
mWindow, nsFocusManager::eIncludeAllDescendants,
getter_AddRefs(focusedWindow));
RefPtr<nsFrameLoaderOwner> loaderOwner = do_QueryObject(focusedContent); if (loaderOwner) { // Only check browsing contexts if a remote frame is focused. If chrome is // focused, just check the controllers directly below.
RefPtr<nsFrameLoader> frameLoader = loaderOwner->GetFrameLoader(); if (frameLoader && frameLoader->IsRemoteFrame()) { // GetActiveBrowsingContextInChrome actually returns the top-level // browsing context if the focus is in a child process tab, or null if // the focus is in chrome.
BrowsingContext* focusedBC =
fm->GetActiveBrowsingContextInChrome()
? fm->GetFocusedBrowsingContextInChrome()
: nullptr; if (focusedBC) { // At this point, it is known that a child process is focused, so ask // its Controllers actor if the command is supported.
nsCOMPtr<nsIController> controller = do_QueryActor( "Controllers", focusedBC->Canonical()->GetCurrentWindowGlobal()); if (controller) { bool supported;
controller->SupportsCommand(aCommand, &supported); if (supported) {
controller.forget(_retval); return NS_OK;
}
}
}
}
}
}
// XXXndeakin P3 is this casting safe?
nsGlobalWindowOuter* win = nsGlobalWindowOuter::Cast(focusedWindow);
focusedWindow = win->GetPrivateParent();
}
return NS_OK;
}
void nsWindowRoot::GetEnabledDisabledCommandsForControllers(
nsIControllers* aControllers, nsTHashSet<nsCString>& 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) { // 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) { // 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.EnsureInserted(commandStr)) { // We inserted a new entry into aCommandsHandled. bool enabled = false;
controller->IsCommandEnabled(commandStr.get(), &enabled);
void nsWindowRoot::EnumerateBrowsers(BrowserEnumerator aEnumFunc, void* aArg) { // Collect strong references to all browsers in a separate array in // case aEnumFunc alters mWeakBrowsers.
nsTArray<nsCOMPtr<nsIRemoteTab>> remoteTabs; for (constauto& key : mWeakBrowsers) {
nsCOMPtr<nsIRemoteTab> remoteTab(do_QueryReferent(key)); if (remoteTab) {
remoteTabs.AppendElement(remoteTab);
}
}
for (uint32_t i = 0; i < remoteTabs.Length(); ++i) {
aEnumFunc(remoteTabs[i], aArg);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.