Bug 1432856 - Added console logging for DOM fullscreen leave on window open or raise. r=smaug
☠☠ backed out by d94afce0c18b ☠ ☠
authorpbz <pbz@mozilla.com>
Mon, 16 Dec 2019 21:07:37 +0000
changeset 507298 62fc84c8ce9978f4df6d65ac6e8d8e4939b0bb65
parent 507297 a8a4fa63f5b20f2dcc0b11e0496076e435c7e83c
child 507299 49d03dd89b1759bdf28f50ad5330d5a2f9651803
push id103347
push userpzuhlcke@mozilla.com
push dateMon, 16 Dec 2019 21:26:02 +0000
treeherderautoland@3d08c3cce533 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1432856
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1432856 - Added console logging for DOM fullscreen leave on window open or raise. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D55813
dom/base/nsFocusManager.cpp
dom/locales/en-US/chrome/dom/dom.properties
toolkit/components/windowwatcher/nsWindowWatcher.cpp
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -25,36 +25,39 @@
 #include "nsIBaseWindow.h"
 #include "nsIAppWindow.h"
 #include "nsViewManager.h"
 #include "nsFrameSelection.h"
 #include "mozilla/dom/Document.h"
 #include "mozilla/dom/Selection.h"
 #include "nsXULPopupManager.h"
 #include "nsMenuPopupFrame.h"
+#include "nsIScriptError.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIPrincipal.h"
 #include "nsIObserverService.h"
 #include "nsIObjectFrame.h"
 #include "BrowserChild.h"
 #include "nsFrameLoader.h"
 #include "nsHTMLDocument.h"
 #include "nsNumberControlFrame.h"
 #include "nsNetUtil.h"
 #include "nsRange.h"
+#include "nsFrameLoaderOwner.h"
 
 #include "mozilla/AccessibleCaretEventHub.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/ElementBinding.h"
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "mozilla/dom/HTMLSlotElement.h"
 #include "mozilla/dom/BrowserBridgeChild.h"
 #include "mozilla/dom/Text.h"
+#include "mozilla/dom/WindowGlobalParent.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/HTMLEditor.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/PresShell.h"
@@ -66,20 +69,16 @@
 #ifdef MOZ_XUL
 #  include "nsIDOMXULMenuListElement.h"
 #endif
 
 #ifdef ACCESSIBILITY
 #  include "nsAccessibilityService.h"
 #endif
 
-#ifndef XP_MACOSX
-#  include "nsIScriptError.h"
-#endif
-
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::widget;
 
 // Two types of focus pr logging are available:
 //   'Focus' for normal focus manager calls
 //   'FocusNavigation' for tab and document navigation
 LazyLogModule gFocusLog("Focus");
@@ -1142,16 +1141,47 @@ void nsFocusManager::ActivateOrDeactivat
   }
 
   // Look for any remote child frames, iterate over them and send the activation
   // notification.
   nsContentUtils::CallOnAllRemoteChildren(aWindow, ActivateOrDeactivateChild,
                                           (void*)aActive);
 }
 
+// Retrieves innerWindowId of the window of the last focused element to
+// log a warning to the website console.
+void LogWarningFullscreenWindowRaise(Element* aElement) {
+  nsCOMPtr<nsFrameLoaderOwner> frameLoaderOwner(do_QueryInterface(aElement));
+  NS_ENSURE_TRUE_VOID(frameLoaderOwner);
+
+  RefPtr<nsFrameLoader> frameLoader = frameLoaderOwner->GetFrameLoader();
+  NS_ENSURE_TRUE_VOID(frameLoaderOwner);
+
+  RefPtr<BrowsingContext> browsingContext = frameLoader->GetBrowsingContext();
+  NS_ENSURE_TRUE_VOID(browsingContext);
+
+  WindowGlobalParent* windowGlobalParent =
+      browsingContext->Canonical()->GetCurrentWindowGlobal();
+  NS_ENSURE_TRUE_VOID(windowGlobalParent);
+
+  // Log to console
+  nsAutoString localizedMsg;
+  nsTArray<nsString> params;
+  nsresult rv = nsContentUtils::FormatLocalizedString(
+      nsContentUtils::eDOM_PROPERTIES, "FullscreenExitWindowRaise", params,
+      localizedMsg);
+
+  NS_ENSURE_SUCCESS_VOID(rv);
+
+  Unused << nsContentUtils::ReportToConsoleByWindowID(
+      localizedMsg, nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM"),
+      windowGlobalParent->InnerWindowId(),
+      windowGlobalParent->GetDocumentURI());
+}
+
 void nsFocusManager::SetFocusInner(Element* aNewContent, int32_t aFlags,
                                    bool aFocusChanged, bool aAdjustWidget) {
   // if the element is not focusable, just return and leave the focus as is
   RefPtr<Element> elementToFocus =
       FlushAndCheckIfFocusable(aNewContent, aFlags);
   if (!elementToFocus) {
     return;
   }
@@ -1234,19 +1264,23 @@ void nsFocusManager::SetFocusInner(Eleme
     dsti->GetInProcessRootTreeItem(getter_AddRefs(root));
     newRootWindow = root ? root->GetWindow() : nullptr;
 
     isElementInActiveWindow = (mActiveWindow && newRootWindow == mActiveWindow);
   }
 
   // Exit fullscreen if a website focuses another window
   if (StaticPrefs::full_screen_api_exit_on_windowRaise() &&
-      !isElementInActiveWindow && aFlags & (FLAG_RAISE | FLAG_NONSYSTEMCALLER)) {
+      !isElementInActiveWindow &&
+      aFlags & (FLAG_RAISE | FLAG_NONSYSTEMCALLER)) {
     if (Document* doc = mActiveWindow ? mActiveWindow->GetDoc() : nullptr) {
       if (doc->GetFullscreenElement()) {
+        if (XRE_IsParentProcess()) {
+          LogWarningFullscreenWindowRaise(mFocusedElement);
+        }
         Document::AsyncExitFullscreen(doc);
       }
     }
   }
 
   // Exit fullscreen if we're focusing a windowed plugin on a non-MacOSX
   // system. We don't control event dispatch to windowed plugins on non-MacOSX,
   // so we can't display the "Press ESC to leave fullscreen mode" warning on
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -62,16 +62,18 @@ FullscreenDeniedMouseEventOnlyLeftBtn=Re
 FullscreenDeniedNotHTMLSVGOrMathML=Request for fullscreen was denied because requesting element is not <svg>, <math>, or an HTML element.
 FullscreenDeniedNotInDocument=Request for fullscreen was denied because requesting element is no longer in its document.
 FullscreenDeniedMovedDocument=Request for fullscreen was denied because requesting element has moved document.
 FullscreenDeniedLostWindow=Request for fullscreen was denied because we no longer have a window.
 FullscreenDeniedSubDocFullscreen=Request for fullscreen was denied because a subdocument of the document requesting fullscreen is already fullscreen.
 FullscreenDeniedNotDescendant=Request for fullscreen was denied because requesting element is not a descendant of the current fullscreen element.
 FullscreenDeniedNotFocusedTab=Request for fullscreen was denied because requesting element is not in the currently focused tab.
 FullscreenDeniedFeaturePolicy=Request for fullscreen was denied because of FeaturePolicy directives.
+FullscreenExitWindowRaise=Exited fullscreen because a window was raised.
+FullscreenExitWindowOpen=Exited fullscreen because a window was opened.
 RemovedFullscreenElement=Exited fullscreen because fullscreen element was removed from document.
 FocusedWindowedPluginWhileFullscreen=Exited fullscreen because windowed plugin was focused.
 PointerLockDeniedDisabled=Request for pointer lock was denied because Pointer Lock API is disabled by user preference.
 PointerLockDeniedInUse=Request for pointer lock was denied because the pointer is currently controlled by a different document.
 PointerLockDeniedNotInDocument=Request for pointer lock was denied because the requesting element is not in a document.
 PointerLockDeniedSandboxed=Request for pointer lock was denied because Pointer Lock API is restricted via sandbox.
 PointerLockDeniedHidden=Request for pointer lock was denied because the document is not visible.
 PointerLockDeniedNotFocused=Request for pointer lock was denied because the document is not focused.
--- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp
+++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp
@@ -30,16 +30,17 @@
 #include "mozilla/dom/Document.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include "nsIDOMChromeWindow.h"
 #include "nsIPrompt.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIScreen.h"
 #include "nsIScreenManager.h"
 #include "nsIScriptContext.h"
+#include "nsIScriptError.h"
 #include "nsIObserverService.h"
 #include "nsXPCOM.h"
 #include "nsIURI.h"
 #include "nsIWebBrowser.h"
 #include "nsIWebBrowserChrome.h"
 #include "nsIWebNavigation.h"
 #include "nsIWindowCreator.h"
 #include "nsIXULRuntime.h"
@@ -1314,17 +1315,19 @@ nsresult nsWindowWatcher::OpenWindowInte
   if (StaticPrefs::full_screen_api_exit_on_windowOpen() && aCalledFromJS &&
       !nsContentUtils::LegacyIsCallerChromeOrNativeCode() && parentWindow &&
       parentWindow->GetFullScreen()) {
     nsCOMPtr<nsPIDOMWindowOuter> parentTopWindow =
         parentWindow->GetBrowsingContext()->Top()->GetDOMWindow();
     if (Document* doc = parentTopWindow ? parentTopWindow->GetDoc() : nullptr) {
       if (doc->GetFullscreenElement()) {
         Document::AsyncExitFullscreen(doc);
-        // TODO: nsContentUtils::ReportToConsole
+        nsContentUtils::ReportToConsole(
+            nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM"), doc,
+            nsContentUtils::eDOM_PROPERTIES, "FullscreenExitWindowOpen");
       }
     }
   }
 
   if (aForceNoOpener && windowIsNew) {
     NS_RELEASE(*aResult);
   }