Bug 1282486 - Plugin fallback rule - don't use fallback when it contains 'install Flash' instructions draft
authorFelipe Gomes <felipc@gmail.com>
Tue, 08 Nov 2016 17:40:46 -0200
changeset 435461 2c5b46a5f38a791ffabf6eaec654d18dc6d967f7
parent 435460 1dc758adb52cc2dd80510136f0303a8793f91e83
child 536324 b2ed0a72aaa6351db59d558d0c6be9c772765f5f
push id35058
push userfelipc@gmail.com
push dateTue, 08 Nov 2016 19:41:18 +0000
bugs1282486
milestone52.0a1
Bug 1282486 - Plugin fallback rule - don't use fallback when it contains 'install Flash' instructions MozReview-Commit-ID: 5e9tgoU1vob
dom/base/nsObjectLoadingContent.cpp
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -3628,31 +3628,49 @@ nsObjectLoadingContent::HasGoodFallback(
     // RULE "adobelink":
     // Don't use fallback content when it has a link to adobe's website.
     if (rulesList[i].EqualsLiteral("adobelink")) {
       nsTArray<nsINodeList*> childNodes;
       for (nsIContent* child = thisContent->GetFirstChild();
            child;
            child = child->GetNextNode(thisContent)) {
         if (child->IsHTMLElement(nsGkAtoms::a)) {
-          nsCOMPtr<nsIURI> href = child->GetHerfURI();
+          nsCOMPtr<nsIURI> href = child->GetHrefURI();
           if (href) {
             nsAutoCString asciiHost;
             nsresult rv = href->GetAsciiHost(asciiHost);
-            if (!asciiHost.IsEmpty() &&
+            if (NS_SUCCEEDED(rv) &&
+                !asciiHost.IsEmpty() &&
                 (asciiHost.EqualsLiteral("adobe.com") ||
-                 asciiHost.EqualsLiteral("www.adobe.com") ||
-                 asciiHost.EqualsLiteral("get.adobe.com"))) {
+                 StringEndsWith(asciiHost, NS_LITERAL_CSTRING(".adobe.com")))) {
               return false;
             }
           }
         }
       }
     }
 
+    // RULE "installinstructions":
+    // Don't use fallback content when the text content on the fallback appears
+    // to contain instructions to install or download Flash.
+    if (rulesList[i].EqualsLiteral("installinstructions")) {
+      nsAutoString textContent;
+      ErrorResult rv;
+      thisContent->GetTextContent(textContent, rv);
+      bool hasText =
+        !rv.Failed() &&
+        (CaseInsensitiveFindInReadable(NS_LITERAL_STRING("Flash"), textContent) ||
+         CaseInsensitiveFindInReadable(NS_LITERAL_STRING("Install"), textContent) ||
+         CaseInsensitiveFindInReadable(NS_LITERAL_STRING("Download"), textContent));
+
+      if (hasText) {
+        return false;
+      }
+    }
+
     // RULE "true":
     // By having a rule that returns true, we can put it at the end of the rules list
     // to change the default-to-false behavior to be default-to-true.
     if (rulesList[i].EqualsLiteral("true")) {
       return true;
     }
   }