Bug 1675349: Forbid elements representing blocked plugins from accepting focus r=jmathies
authorDavid Parks <daparks@mozilla.com>
Wed, 18 Nov 2020 15:55:52 +0000
changeset 557828 c0ff7dbb807e2c2e57fbcdae68b8b70942886b04
parent 557827 9036b58142b50ecf80a42c6e8968a387a84c51cd
child 557829 847bd43fd835e0ef3eb3b25aacf0d0ebf2b97b67
push id37962
push userapavel@mozilla.com
push dateWed, 18 Nov 2020 21:51:58 +0000
treeherdermozilla-central@9d797387f57c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmathies
bugs1675349
milestone85.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 1675349: Forbid elements representing blocked plugins from accepting focus r=jmathies As part of the fallback for unsupported plugin elements, we deny them focus. Since elements can be programmatically changed, and object/embed elements can change internal "type" by updating their data/src attributes, and because that type is decided asynchronously, we may need to give up focus if our element has it. Differential Revision: https://phabricator.services.mozilla.com/D95903
dom/base/nsObjectLoadingContent.cpp
dom/html/HTMLEmbedElement.cpp
dom/html/HTMLObjectElement.cpp
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -2616,16 +2616,24 @@ void nsObjectLoadingContent::NotifyState
 
     bool hadProblemState = !(aOldState & pluginProblemState).IsEmpty();
     bool hasProblemState = !(newState & pluginProblemState).IsEmpty();
 
     if (hadProblemState && !hasProblemState) {
       thisEl->NotifyUAWidgetTeardown();
     } else if (!hadProblemState && hasProblemState) {
       thisEl->AttachAndSetUAShadowRoot();
+      // When blocking all plugins, we do not want the element to have focus
+      // so relinquish focus if we are in that state.
+      if (PluginFallbackType() == eFallbackBlockAllPlugins) {
+        nsFocusManager* fm = nsFocusManager::GetFocusManager();
+        if (fm && fm->GetFocusedElement() == thisEl) {
+          fm->ClearFocus(doc->GetWindow());
+        }
+      }
     }
   } else if (aOldType != mType) {
     // If our state changed, then we already recreated frames
     // Otherwise, need to do that here
     RefPtr<PresShell> presShell = doc->GetPresShell();
     if (presShell) {
       presShell->PostRecreateFramesFor(thisEl);
     }
--- a/dom/html/HTMLEmbedElement.cpp
+++ b/dom/html/HTMLEmbedElement.cpp
@@ -158,17 +158,28 @@ nsresult HTMLEmbedElement::AfterMaybeCha
     }
   }
 
   return NS_OK;
 }
 
 bool HTMLEmbedElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
                                        int32_t* aTabIndex) {
-  // Has plugin content: let the plugin decide what to do in terms of
+  // If we have decided that this is a blocked plugin then do not allow focus.
+  if ((Type() == eType_Null) &&
+      (PluginFallbackType() == eFallbackBlockAllPlugins)) {
+    if (aTabIndex) {
+      *aTabIndex = -1;
+    }
+
+    *aIsFocusable = false;
+    return false;
+  }
+
+  // Has non-plugin content: let the plugin decide what to do in terms of
   // internal focus from mouse clicks
   if (aTabIndex) {
     *aTabIndex = TabIndex();
   }
 
   *aIsFocusable = true;
 
   // Let the plugin decide, so override.
--- a/dom/html/HTMLObjectElement.cpp
+++ b/dom/html/HTMLObjectElement.cpp
@@ -284,16 +284,27 @@ bool HTMLObjectElement::IsHTMLFocusable(
     if (aTabIndex) {
       *aTabIndex = -1;
     }
 
     *aIsFocusable = false;
     return false;
   }
 
+  // If we have decided that this is a blocked plugin then do not allow focus.
+  if ((Type() == eType_Null) &&
+      (PluginFallbackType() == eFallbackBlockAllPlugins)) {
+    if (aTabIndex) {
+      *aTabIndex = -1;
+    }
+
+    *aIsFocusable = false;
+    return false;
+  }
+
   const nsAttrValue* attrVal = mAttrs.GetAttr(nsGkAtoms::tabindex);
   bool isFocusable = attrVal && attrVal->Type() == nsAttrValue::eInteger;
 
   // Has plugin content: let the plugin decide what to do in terms of
   // internal focus from mouse clicks
   if (Type() == eType_Plugin) {
     if (aTabIndex) {
       *aTabIndex = isFocusable ? attrVal->GetIntegerValue() : -1;