Bug 1637487 - Factor out updating root Document security flags. r=ckerschb
☠☠ backed out by efbb5dd6bf7b ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 13 May 2020 17:49:02 +0000
changeset 529724 1a64ef10e773eef321a110c47d803757dc56bd4a
parent 529723 d1709ebb7f4668b2ef3a53c38bf96fa88d790c7c
child 529725 65bb1114df87c026c534f9a6afa96bc865e5505c
push id37414
push usernbeleuzu@mozilla.com
push dateThu, 14 May 2020 02:40:10 +0000
treeherdermozilla-central@045d696faa87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1637487
milestone78.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 1637487 - Factor out updating root Document security flags. r=ckerschb Depends on D75022 Differential Revision: https://phabricator.services.mozilla.com/D75023
dom/security/nsMixedContentBlocker.cpp
--- a/dom/security/nsMixedContentBlocker.cpp
+++ b/dom/security/nsMixedContentBlocker.cpp
@@ -815,83 +815,91 @@ nsresult nsMixedContentBlocker::ShouldLo
   // If the content is display content, and the pref says display content should
   // be blocked, block it.
   if (classification == eMixedDisplay) {
     if (!StaticPrefs::security_mixed_content_block_display_content() ||
         allowMixedContent) {
       LogMixedContentMessage(classification, aContentLocation, topInnerWindowID,
                              eUserOverride, requestingLocation);
       *aDecision = nsIContentPolicy::ACCEPT;
-      // See if mixed display content has already loaded on the page or if the
-      // state needs to be updated here. If mixed display hasn't loaded
-      // previously, then we need to call OnSecurityChange() to update the UI.
-      if (rootDoc->GetHasMixedDisplayContentLoaded()) {
-        return NS_OK;
-      }
-      rootDoc->SetHasMixedDisplayContentLoaded(true);
-
       if (rootHasSecureConnection) {
         broken = true;
       }
       // User has overriden the pref and the root is not https;
       // mixed display content was allowed on an https subframe.
       newState |= nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT;
     } else {
       *aDecision = nsIContentPolicy::REJECT_REQUEST;
       LogMixedContentMessage(classification, aContentLocation, topInnerWindowID,
                              eBlocked, requestingLocation);
-      if (rootDoc->GetHasMixedDisplayContentBlocked()) {
-        return NS_OK;
-      }
-
-      rootDoc->SetHasMixedDisplayContentBlocked(true);
       newState |= nsIWebProgressListener::STATE_BLOCKED_MIXED_DISPLAY_CONTENT;
     }
   } else {
     MOZ_ASSERT(classification == eMixedScript);
     // If the content is active content, and the pref says active content should
     // be blocked, block it unless the user has choosen to override the pref
     if (!StaticPrefs::security_mixed_content_block_active_content() ||
         allowMixedContent) {
       LogMixedContentMessage(classification, aContentLocation, topInnerWindowID,
                              eUserOverride, requestingLocation);
       *aDecision = nsIContentPolicy::ACCEPT;
-      // See if the state will change here. If it will, only then do we need to
-      // call OnSecurityChange() to update the UI.
-      if (rootDoc->GetHasMixedActiveContentLoaded()) {
-        return NS_OK;
-      }
-      rootDoc->SetHasMixedActiveContentLoaded(true);
 
       if (rootHasSecureConnection) {
         broken = true;
       }
 
       // User has already overriden the pref and the root is not https;
       // mixed active content was allowed on an https subframe.
       newState |= nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT;
     } else {
       // User has not overriden the pref by Disabling protection. Reject the
       // request and update the security state.
       *aDecision = nsIContentPolicy::REJECT_REQUEST;
       LogMixedContentMessage(classification, aContentLocation, topInnerWindowID,
                              eBlocked, requestingLocation);
-      // See if the pref will change here. If it will, only then do we need to
-      // call OnSecurityChange() to update the UI.
-      if (rootDoc->GetHasMixedActiveContentBlocked()) {
-        return NS_OK;
-      }
-      rootDoc->SetHasMixedActiveContentBlocked(true);
-
       // The user has not overriden the pref, so make sure they still have an
       // option by calling nativeDocShell which will invoke the doorhanger
       newState |= nsIWebProgressListener::STATE_BLOCKED_MIXED_ACTIVE_CONTENT;
     }
   }
 
+  // Check if the new flags we computed match the current state on the doc.
+  // This is really painful, and life would be eaiser if the doc had the same
+  // flags instead of bools.
+  bool stateChanged =
+      ((newState & nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT) ==
+       rootDoc->GetHasMixedActiveContentLoaded()) ||
+      ((newState &
+        nsIWebProgressListener::STATE_BLOCKED_MIXED_ACTIVE_CONTENT) ==
+       rootDoc->GetHasMixedActiveContentBlocked()) ||
+      ((newState &
+        nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT) ==
+       rootDoc->GetHasMixedDisplayContentLoaded()) ||
+      ((newState &
+        nsIWebProgressListener::STATE_BLOCKED_MIXED_DISPLAY_CONTENT) ==
+       rootDoc->GetHasMixedDisplayContentBlocked());
+
+  if (!stateChanged) {
+    return NS_OK;
+  }
+
+  // Copy the new state onto the Document flags.
+  if (newState & nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT) {
+    rootDoc->SetHasMixedActiveContentLoaded(true);
+  }
+  if (newState & nsIWebProgressListener::STATE_BLOCKED_MIXED_ACTIVE_CONTENT) {
+    rootDoc->SetHasMixedActiveContentBlocked(true);
+  }
+  if (newState & nsIWebProgressListener::STATE_LOADED_MIXED_DISPLAY_CONTENT) {
+    rootDoc->SetHasMixedDisplayContentLoaded(true);
+  }
+  if (newState & nsIWebProgressListener::STATE_BLOCKED_MIXED_DISPLAY_CONTENT) {
+    rootDoc->SetHasMixedDisplayContentBlocked(true);
+  }
+
   if (broken) {
     // reset state security flag
     state = state >> 4 << 4;
     // set state security flag to broken, since there is mixed content
     state |= nsIWebProgressListener::STATE_IS_BROKEN;
 
     // If mixed display content is loaded, make sure to include that in the
     // state.