From c5353a7809676163451349afa434ad221d2ea3b6 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 29 Apr 2020 19:29:06 +0000 Subject: [PATCH] Bug 1630691: Part 1 - Get rid of most of the remaining mozbrowser API. r=nika,mtigley,bradwerth Differential Revision: https://phabricator.services.mozilla.com/D71226 --- dom/base/FragmentOrElement.cpp | 6 - dom/base/nsContentUtils.cpp | 21 - dom/base/nsContentUtils.h | 9 - dom/base/nsFocusManager.cpp | 49 +- dom/base/nsFrameLoader.cpp | 20 +- dom/browser-element/BrowserElementChild.js | 39 - .../BrowserElementChildPreload.js | 1069 +---------------- .../BrowserElementCopyPaste.js | 138 --- dom/browser-element/BrowserElementParent.jsm | 389 +----- dom/events/EventStateManager.cpp | 4 - dom/html/nsBrowserElement.cpp | 83 -- dom/ipc/jar.mn | 1 - dom/webidl/BrowserElement.webidl | 47 - dom/webidl/HTMLIFrameElement.webidl | 7 - dom/webidl/moz.build | 4 - 15 files changed, 30 insertions(+), 1856 deletions(-) delete mode 100644 dom/browser-element/BrowserElementCopyPaste.js delete mode 100644 dom/webidl/BrowserElement.webidl diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 52579805549a..c0ce8d087b7c 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -1019,12 +1019,6 @@ bool nsIContent::IsFocusable(int32_t* aTabIndex, bool aWithMouse) { // Ensure that the return value and aTabIndex are consistent in the case // we're in userfocusignored context. if (focusable || (aTabIndex && *aTabIndex != -1)) { - if (nsContentUtils::IsUserFocusIgnored(this)) { - if (aTabIndex) { - *aTabIndex = -1; - } - return false; - } return focusable; } return false; diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 93d6d24ef8ac..281baecee2b8 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -6181,27 +6181,6 @@ bool nsContentUtils::IsSubDocumentTabbable(nsIContent* aContent) { return true; } -bool nsContentUtils::IsUserFocusIgnored(nsINode* aNode) { - if (!StaticPrefs::dom_mozBrowserFramesEnabled()) { - return false; - } - - // Check if our mozbrowser iframe ancestors has ignoreuserfocus attribute. - while (aNode) { - nsCOMPtr browserFrame = do_QueryInterface(aNode); - if (browserFrame && - aNode->AsElement()->HasAttr(kNameSpaceID_None, - nsGkAtoms::ignoreuserfocus) && - browserFrame->GetReallyIsBrowser()) { - return true; - } - nsPIDOMWindowOuter* win = aNode->OwnerDoc()->GetWindow(); - aNode = win ? win->GetFrameElementInternal() : nullptr; - } - - return false; -} - bool nsContentUtils::HasScrollgrab(nsIContent* aContent) { // If we ever standardize this feature we'll want to hook this up properly // again. For now we're removing all the DOM-side code related to it but diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 237344ebfebc..c81cc6a69d74 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -2483,15 +2483,6 @@ class nsContentUtils { */ static bool IsSubDocumentTabbable(nsIContent* aContent); - /** - * Returns if aNode ignores user focus. - * - * @param aNode node to test - * - * @return Whether the node ignores user focus. - */ - static bool IsUserFocusIgnored(nsINode* aNode); - /** * Returns if aContent has the 'scrollgrab' property. * aContent may be null (in this case false is returned). diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 4eaaad5032e8..99deaa270cd1 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -1785,8 +1785,7 @@ bool nsFocusManager::IsNonFocusableRoot(nsIContent* aContent) { Document* doc = aContent->GetComposedDoc(); NS_ASSERTION(doc, "aContent must have current document"); return aContent == doc->GetRootElement() && - (doc->HasFlag(NODE_IS_EDITABLE) || !aContent->IsEditable() || - nsContentUtils::IsUserFocusIgnored(aContent)); + (doc->HasFlag(NODE_IS_EDITABLE) || !aContent->IsEditable()); } Element* nsFocusManager::FlushAndCheckIfFocusable(Element* aElement, @@ -1819,7 +1818,7 @@ Element* nsFocusManager::FlushAndCheckIfFocusable(Element* aElement, // the root content can always be focused, // except in userfocusignored context. if (aElement == doc->GetRootElement()) { - return nsContentUtils::IsUserFocusIgnored(aElement) ? nullptr : aElement; + return aElement; } // cannot focus content in print preview mode. Only the root can be focused. @@ -2514,10 +2513,7 @@ void nsFocusManager::SendFocusOrBlurEvent( aRelatedTarget = nullptr; } - bool dontDispatchEvent = - eventTargetDoc && nsContentUtils::IsUserFocusIgnored(eventTargetDoc); - - if (!dontDispatchEvent && aDocument && aDocument->EventHandlingSuppressed()) { + if (aDocument && aDocument->EventHandlingSuppressed()) { for (uint32_t i = mDelayedBlurFocusEvents.Length(); i > 0; --i) { // if this event was already queued, remove it and append it to the end if (mDelayedBlurFocusEvents[i - 1].mEventMessage == aEventMessage && @@ -2550,17 +2546,12 @@ void nsFocusManager::FireFocusOrBlurEvent(EventMessage aEventMessage, nsISupports* aTarget, bool aWindowRaised, bool aIsRefocus, EventTarget* aRelatedTarget) { - nsCOMPtr eventTarget = do_QueryInterface(aTarget); - nsCOMPtr eventTargetDoc = GetDocumentHelper(eventTarget); nsCOMPtr currentWindow = mFocusedWindow; nsCOMPtr targetWindow = do_QueryInterface(aTarget); nsCOMPtr targetDocument = do_QueryInterface(aTarget); nsCOMPtr currentFocusedContent = currentWindow ? currentWindow->GetFocusedElement() : nullptr; - bool dontDispatchEvent = - eventTargetDoc && nsContentUtils::IsUserFocusIgnored(eventTargetDoc); - #ifdef ACCESSIBILITY nsAccessibilityService* accService = GetAccService(); if (accService) { @@ -2572,25 +2563,23 @@ void nsFocusManager::FireFocusOrBlurEvent(EventMessage aEventMessage, } #endif - if (!dontDispatchEvent) { - nsContentUtils::AddScriptRunner( - new FocusBlurEvent(aTarget, aEventMessage, aPresShell->GetPresContext(), - aWindowRaised, aIsRefocus, aRelatedTarget)); + nsContentUtils::AddScriptRunner( + new FocusBlurEvent(aTarget, aEventMessage, aPresShell->GetPresContext(), + aWindowRaised, aIsRefocus, aRelatedTarget)); - // Check that the target is not a window or document before firing - // focusin/focusout. Other browsers do not fire focusin/focusout on window, - // despite being required in the spec, so follow their behavior. - // - // As for document, we should not even fire focus/blur, but until then, we - // need this check. targetDocument should be removed once bug 1228802 is - // resolved. - if (!targetWindow && !targetDocument) { - EventMessage focusInOrOutMessage = - aEventMessage == eFocus ? eFocusIn : eFocusOut; - FireFocusInOrOutEvent(focusInOrOutMessage, aPresShell, aTarget, - currentWindow, currentFocusedContent, - aRelatedTarget); - } + // Check that the target is not a window or document before firing + // focusin/focusout. Other browsers do not fire focusin/focusout on window, + // despite being required in the spec, so follow their behavior. + // + // As for document, we should not even fire focus/blur, but until then, we + // need this check. targetDocument should be removed once bug 1228802 is + // resolved. + if (!targetWindow && !targetDocument) { + EventMessage focusInOrOutMessage = + aEventMessage == eFocus ? eFocusIn : eFocusOut; + FireFocusInOrOutEvent(focusInOrOutMessage, aPresShell, aTarget, + currentWindow, currentFocusedContent, + aRelatedTarget); } } diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 1588865c503d..2f8c00aaa799 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -3174,18 +3174,16 @@ void nsFrameLoader::InitializeBrowserAPI() { if (!OwnerIsMozBrowserFrame()) { return; } - if (!IsRemoteFrame()) { - nsresult rv = EnsureMessageManager(); - if (NS_WARN_IF(NS_FAILED(rv))) { - return; - } - if (mMessageManager) { - mMessageManager->LoadFrameScript( - NS_LITERAL_STRING("chrome://global/content/BrowserElementChild.js"), - /* allowDelayedLoad = */ true, - /* aRunInGlobalScope */ true, IgnoreErrors()); - } + + nsresult rv = EnsureMessageManager(); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; } + mMessageManager->LoadFrameScript( + NS_LITERAL_STRING("chrome://global/content/BrowserElementChild.js"), + /* allowDelayedLoad = */ true, + /* aRunInGlobalScope */ true, IgnoreErrors()); + nsCOMPtr browserFrame = do_QueryInterface(mOwnerContent); if (browserFrame) { browserFrame->InitializeBrowserAPI(); diff --git a/dom/browser-element/BrowserElementChild.js b/dom/browser-element/BrowserElementChild.js index 80e968c724b0..5522175535e8 100644 --- a/dom/browser-element/BrowserElementChild.js +++ b/dom/browser-element/BrowserElementChild.js @@ -17,48 +17,12 @@ function debug(msg) { // mozbrowser API clients. docShell.isActive = true; -function parentDocShell(docshell) { - if (!docshell) { - return null; - } - let treeitem = docshell.QueryInterface(Ci.nsIDocShellTreeItem); - return treeitem.parent - ? treeitem.parent.QueryInterface(Ci.nsIDocShell) - : null; -} - -function isTopBrowserElement(docShell) { - while (docShell) { - docShell = parentDocShell(docShell); - if (docShell && docShell.isMozBrowser) { - return false; - } - } - return true; -} - var BrowserElementIsReady; debug(`Might load BE scripts: BEIR: ${BrowserElementIsReady}`); if (!BrowserElementIsReady) { debug("Loading BE scripts"); if (!("BrowserElementIsPreloaded" in this)) { - if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) { - // general content apps - if (isTopBrowserElement(docShell)) { - Services.scriptloader.loadSubScript( - "chrome://global/content/BrowserElementCopyPaste.js", - this - ); - } - } else { - // rocketbar in system app and other in-process case (ex. B2G desktop client) - Services.scriptloader.loadSubScript( - "chrome://global/content/BrowserElementCopyPaste.js", - this - ); - } - Services.scriptloader.loadSubScript( "chrome://global/content/BrowserElementChildPreload.js", this @@ -71,9 +35,6 @@ if (!BrowserElementIsReady) { if (api) { api.destroy(); } - if ("CopyPasteAssistent" in this) { - CopyPasteAssistent.destroy(); - } BrowserElementIsReady = false; } diff --git a/dom/browser-element/BrowserElementChildPreload.js b/dom/browser-element/BrowserElementChildPreload.js index 3313eb782b89..bc6cc1d9bb57 100644 --- a/dom/browser-element/BrowserElementChildPreload.js +++ b/dom/browser-element/BrowserElementChildPreload.js @@ -19,14 +19,6 @@ var { BrowserElementPromptService } = ChromeUtils.import( "resource://gre/modules/BrowserElementPromptService.jsm" ); -var kLongestReturnedString = 128; - -var Timer = Components.Constructor( - "@mozilla.org/timer;1", - "nsITimer", - "initWithCallback" -); - function sendAsyncMsg(msg, data) { // Ensure that we don't send any messages before BrowserElementChild.js // finishes loading. @@ -42,46 +34,7 @@ function sendAsyncMsg(msg, data) { sendAsyncMessage("browser-element-api:call", data); } -function sendSyncMsg(msg, data) { - // Ensure that we don't send any messages before BrowserElementChild.js - // finishes loading. - if (!BrowserElementIsReady) { - return undefined; - } - - if (!data) { - data = {}; - } - - data.msg_name = msg; - return sendSyncMessage("browser-element-api:call", data); -} - -var CERTIFICATE_ERROR_PAGE_PREF = "security.alternate_certificate_error_page"; - -var OBSERVED_EVENTS = [ - "xpcom-shutdown", - "audio-playback", - "activity-done", - "will-launch-app", -]; - var LISTENED_EVENTS = [ - { type: "DOMTitleChanged", useCapture: true, wantsUntrusted: false }, - { type: "DOMLinkAdded", useCapture: true, wantsUntrusted: false }, - { type: "MozScrolledAreaChanged", useCapture: true, wantsUntrusted: false }, - { type: "MozDOMFullscreen:Request", useCapture: true, wantsUntrusted: false }, - { - type: "MozDOMFullscreen:NewOrigin", - useCapture: true, - wantsUntrusted: false, - }, - { type: "MozDOMFullscreen:Exit", useCapture: true, wantsUntrusted: false }, - { type: "DOMMetaAdded", useCapture: true, wantsUntrusted: false }, - { type: "DOMMetaChanged", useCapture: true, wantsUntrusted: false }, - { type: "DOMMetaRemoved", useCapture: true, wantsUntrusted: false }, - { type: "scrollviewchange", useCapture: true, wantsUntrusted: false }, - { type: "click", useCapture: false, wantsUntrusted: false }, // This listens to unload events from our message manager, but /not/ from // the |content| window. That's because the window's unload event doesn't // bubble, and we're not using a capturing listener. If we'd used @@ -90,16 +43,6 @@ var LISTENED_EVENTS = [ { type: "unload", useCapture: false, wantsUntrusted: false }, ]; -// We are using the system group for those events so if something in the -// content called .stopPropagation() this will still be called. -var LISTENED_SYSTEM_EVENTS = [ - { type: "DOMWindowClose", useCapture: false }, - { type: "DOMWindowCreated", useCapture: false }, - { type: "DOMWindowResize", useCapture: false }, - { type: "contextmenu", useCapture: false }, - { type: "scroll", useCapture: false }, -]; - /** * The BrowserElementChild implements one half of