Bug 1282484 - Write structure for pref-configurable fallback rules list, 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
This commit is contained in:
Felipe Gomes 2017-01-24 03:08:04 -02:00
Родитель cedca668f6
Коммит 00dd3f7914
2 изменённых файлов: 90 добавлений и 1 удалений

Просмотреть файл

@ -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;
@ -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;
}

Просмотреть файл

@ -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.)