Skip to content

Commit

Permalink
Backout of changesets 05eb8219c3e5, 1ecd2a9ffb67 (Bug 769117) for bus…
Browse files Browse the repository at this point in the history
…tage on CLOSED TREE
  • Loading branch information
qdot committed Jan 13, 2016
1 parent 24be047 commit 07a31d9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 135 deletions.
3 changes: 0 additions & 3 deletions build/pgo/server-locations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,3 @@ https://sha256ee.example.com:443 privileged,cer
https://ssl3.example.com:443 privileged,ssl3
https://rc4.example.com:443 privileged,rc4
https://ssl3rc4.example.com:443 privileged,ssl3,rc4

# Hosts for youtube rewrite tests
https://mochitest.youtube.com:443
61 changes: 17 additions & 44 deletions dom/base/nsObjectLoadingContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);

static const char *kPrefJavaMIME = "plugin.java.mime";
static const char *kPrefYoutubeRewrite = "plugins.rewrite_youtube_embeds";

using namespace mozilla;
using namespace mozilla::dom;
Expand Down Expand Up @@ -715,8 +714,7 @@ nsObjectLoadingContent::nsObjectLoadingContent()
, mActivated(false)
, mIsStopping(false)
, mIsLoading(false)
, mScriptRequested(false)
, mRewrittenYoutubeEmbed(false) {}
, mScriptRequested(false) {}

nsObjectLoadingContent::~nsObjectLoadingContent()
{
Expand Down Expand Up @@ -1484,7 +1482,7 @@ nsObjectLoadingContent::CheckJavaCodebase()
}

bool
nsObjectLoadingContent::ShouldRewriteYoutubeEmbed(nsIURI* aURI)
nsObjectLoadingContent::IsYoutubeEmbed()
{
nsCOMPtr<nsIContent> thisContent =
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
Expand All @@ -1502,41 +1500,25 @@ nsObjectLoadingContent::ShouldRewriteYoutubeEmbed(nsIURI* aURI)
NS_WARNING("Could not get TLD service!");
return false;
}

nsAutoCString currentBaseDomain;
bool ok = NS_SUCCEEDED(tldService->GetBaseDomain(aURI, 0, currentBaseDomain));
bool ok = NS_SUCCEEDED(tldService->GetBaseDomain(mURI, 0, currentBaseDomain));
if (!ok) {
// Data URIs (commonly used for things like svg embeds) won't parse
// correctly, so just fail silently here.
// Data URIs won't parse correctly, so just fail silently here.
return false;
}

// See if URL is referencing youtube
if (!currentBaseDomain.EqualsLiteral("youtube.com")) {
nsAutoCString domain("youtube.com");
if (!StringEndsWith(domain, currentBaseDomain)) {
return false;
}

// We should only rewrite URLs with paths starting with "/v/", as we shouldn't
// touch object nodes with "/embed/" urls that already do that right thing.
nsAutoCString path;
aURI->GetPath(path);
if (!StringBeginsWith(path, NS_LITERAL_CSTRING("/v/"))) {
return false;
}

// See if requester is planning on using the JS API.
nsAutoCString uri;
aURI->GetSpec(uri);
mURI->GetSpec(uri);
// Only log urls that are rewritable, e.g. not using enablejsapi=1
if (uri.Find("enablejsapi=1", true, 0, -1) != kNotFound) {
return false;
}

// If we've made it this far, we've got a rewritable embed. Log it in
// telemetry.
Telemetry::Accumulate(Telemetry::YOUTUBE_REWRITABLE_EMBED_SEEN, 1);

// Even if node is rewritable, only rewrite if the pref tells us we should.
return Preferences::GetBool(kPrefYoutubeRewrite);
return true;
}

bool
Expand Down Expand Up @@ -1787,27 +1769,13 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
NS_NOTREACHED("Unrecognized plugin-loading tag");
}

mRewrittenYoutubeEmbed = false;
// Note that the baseURI changing could affect the newURI, even if uriStr did
// not change.
if (!uriStr.IsEmpty()) {
rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(newURI),
uriStr,
thisContent->OwnerDoc(),
newBaseURI);
if (ShouldRewriteYoutubeEmbed(newURI)) {
// Switch out video access url formats, which should possibly allow HTML5
// video loading.
uriStr.ReplaceSubstring(NS_LITERAL_STRING("/v/"),
NS_LITERAL_STRING("/embed/"));
rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(newURI),
uriStr,
thisContent->OwnerDoc(),
newBaseURI);
mRewrittenYoutubeEmbed = true;
newMime = NS_LITERAL_CSTRING("text/html");
}

if (NS_SUCCEEDED(rv)) {
NS_TryToSetImmutable(newURI);
} else {
Expand Down Expand Up @@ -1971,9 +1939,9 @@ nsObjectLoadingContent::UpdateObjectParameters(bool aJavaURI)
newType = eType_Null;
newMime.Truncate();
} else if (newChannel) {
// If newChannel is set above, we considered it in setting newMime
newType = GetTypeOfContent(newMime);
LOG(("OBJLC [%p]: Using channel type", this));
// If newChannel is set above, we considered it in setting newMime
newType = GetTypeOfContent(newMime);
LOG(("OBJLC [%p]: Using channel type", this));
} else if (((caps & eAllowPluginSkipChannel) || !newURI) &&
GetTypeOfContent(newMime) == eType_Plugin) {
newType = eType_Plugin;
Expand Down Expand Up @@ -2202,6 +2170,11 @@ nsObjectLoadingContent::LoadObject(bool aNotify,
return NS_OK;
}

// Check whether this is a youtube embed.
if (IsYoutubeEmbed()) {
Telemetry::Accumulate(Telemetry::YOUTUBE_REWRITABLE_EMBED_SEEN, 1);
}

//
// Security checks
//
Expand Down
28 changes: 1 addition & 27 deletions dom/base/nsObjectLoadingContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,6 @@ class nsObjectLoadingContent : public nsImageLoadingContent
*/
virtual nsContentPolicyType GetContentPolicyType() const = 0;

// True if object represents an object/embed tag pointing to a flash embed
// for a youtube video. When possible (see IsRewritableYoutubeEmbed function
// comments for details), we change these to try to load HTML5 versions of
// videos.
bool mRewrittenYoutubeEmbed : 1;

private:

// Object parameter changes returned by UpdateObjectParameters
Expand Down Expand Up @@ -525,27 +519,7 @@ class nsObjectLoadingContent : public nsImageLoadingContent
*/
nsPluginFrame* GetExistingFrame();

/**
* Used for identifying whether we can rewrite a youtube flash embed to
* possibly use HTML5 instead.
*
* Returns true if plugin.rewrite_youtube_embeds pref is true and the
* element this nsObjectLoadingContent instance represents:
*
* - is an embed or object node
* - has a URL pointing at the youtube.com domain, using "/v/" style video
* path reference, and without enablejsapi=1 in the path
*
* Having the enablejsapi flag means the document that contains the element
* could possibly be manipulating the youtube video elsewhere on the page
* via javascript. We can't rewrite these kinds of elements without possibly
* breaking content, which we want to avoid.
*
* If we can rewrite the URL, we change the "/v/" to "/embed/", and change
* our type to eType_Document so that we render similarly to an iframe
* embed.
*/
bool ShouldRewriteYoutubeEmbed(nsIURI* uri);
bool IsYoutubeEmbed();

// Helper class for SetupProtoChain
class SetupProtoChainRunner final : public nsIRunnable
Expand Down
1 change: 0 additions & 1 deletion dom/base/test/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -859,4 +859,3 @@ skip-if = buildapp == 'b2g' #no ssl support
[test_performance_translate.html]
[test_bug1198095.html]
[test_bug1187157.html]
[test_bug769117.html]
51 changes: 0 additions & 51 deletions dom/base/test/test_bug769117.html

This file was deleted.

5 changes: 0 additions & 5 deletions dom/html/HTMLSharedObjectElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@ HTMLSharedObjectElement::GetCapabilities() const
if (mNodeInfo->Equals(nsGkAtoms::embed)) {
capabilities |= eSupportSVG | eSupportImages;
}
// If this is a rewritten youtube flash embed, add documents to capabilities
// so that we can render HTML5 if possible.
if (mRewrittenYoutubeEmbed) {
capabilities |= eSupportDocuments;
}

return capabilities;
}
Expand Down
4 changes: 0 additions & 4 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5140,7 +5140,3 @@ pref("webextensions.tests", false);

// Allow customization of the fallback directory for file uploads
pref("dom.input.fallbackUploadDir", "");

// Turn rewriting of youtube embeds on/off
pref("plugins.rewrite_youtube_embeds", true);

0 comments on commit 07a31d9

Please sign in to comment.