Skip to content

Commit

Permalink
Bug 1282484 - Write structure for pref-configurable fallback rules li…
Browse files Browse the repository at this point in the history
…st, and include initial set of rules. r=qDot

* * *
Bug 1282485 - Plugin fallback rule - don't use fallback when the descendant has an embed element
* * *
Bug 1316102 - Plugin fallback rule - use fallback when it contains a <video> element
* * *
Bug 1282487 - Plugin fallback rule - don't use fallback when it contains links to adobe.com
* * *
Bug 1282486 - Plugin fallback rule - don't use fallback when it contains 'install Flash' instructions

MozReview-Commit-ID: DexVBrAfaTb
  • Loading branch information
felipc committed Jan 24, 2017
1 parent cedca66 commit 00dd3f7
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
85 changes: 84 additions & 1 deletion dom/base/nsObjectLoadingContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static const char *kPrefJavaMIME = "plugin.java.mime";
static const char *kPrefYoutubeRewrite = "plugins.rewrite_youtube_embeds";
static const char *kPrefBlockURIs = "browser.safebrowsing.blockedURIs.enabled";
static const char *kPrefFavorFallbackMode = "plugins.favorfallback.mode";
static const char *kPrefFavorFallbackRules = "plugins.favorfallback.rules";

using namespace mozilla;
using namespace mozilla::dom;
Expand Down Expand Up @@ -3452,7 +3453,89 @@ nsObjectLoadingContent::HasGoodFallback() {
return false;
}

// xxx to be filled
nsTArray<nsCString> rulesList;
nsCString prefString;
if (NS_SUCCEEDED(Preferences::GetCString(kPrefFavorFallbackRules, &prefString))) {
ParseString(prefString, ',', rulesList);
}

for (uint32_t i = 0; i < rulesList.Length(); ++i) {
// RULE "embed":
// Don't use fallback content if the object contains an <embed> inside its
// fallback content.
if (rulesList[i].EqualsLiteral("embed")) {
nsTArray<nsINodeList*> childNodes;
for (nsIContent* child = thisContent->GetFirstChild();
child;
child = child->GetNextNode(thisContent)) {
if (child->IsHTMLElement(nsGkAtoms::embed)) {
return false;
}
}
}

// RULE "video":
// Use fallback content if the object contains a <video> inside its
// fallback content.
if (rulesList[i].EqualsLiteral("video")) {
nsTArray<nsINodeList*> childNodes;
for (nsIContent* child = thisContent->GetFirstChild();
child;
child = child->GetNextNode(thisContent)) {
if (child->IsHTMLElement(nsGkAtoms::video)) {
return true;
}
}
}

// 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->GetHrefURI();
if (href) {
nsAutoCString asciiHost;
nsresult rv = href->GetAsciiHost(asciiHost);
if (NS_SUCCEEDED(rv) &&
!asciiHost.IsEmpty() &&
(asciiHost.EqualsLiteral("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;
}
}

return false;
}
Expand Down
6 changes: 6 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2832,6 +2832,12 @@ pref("plugin.persistentPermissionAlways.intervalInDays", 90);
// "never" - never use favor fallback mode
pref("plugins.favorfallback.mode", "never");

// A comma-separated list of rules to follow when deciding
// whether an object has been provided with good fallback content.
// The valid values can be found at nsObjectLoadingContent::HasGoodFallback.
pref("plugins.favorfallback.rules", "");


// Set IPC timeouts for plugins and tabs, except in leak-checking and
// dynamic analysis builds. (NS_FREE_PERMANENT_DATA is C++ only, so
// approximate its definition here.)
Expand Down

0 comments on commit 00dd3f7

Please sign in to comment.