Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Unified Diff: third_party/WebKit/Source/core/html/HTMLEmbedElement.cpp

Issue 2132403003: Rewriting YouTube Flash embeds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewriting YouTube Flash embeds Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLEmbedElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLEmbedElement.cpp b/third_party/WebKit/Source/core/html/HTMLEmbedElement.cpp
index dfb698dacd38e11963dcac100fb43ce12cac9db6..12d91dcc6a717023d50f215b73301eb4ef0b4881 100644
--- a/third_party/WebKit/Source/core/html/HTMLEmbedElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLEmbedElement.cpp
@@ -146,9 +146,48 @@ void HTMLEmbedElement::updateWidgetInternal()
if (!layoutObject())
return;
+ // If necessary (and possible), we will rewrite a YouTube Flash embed
+ // to use HTML5 instead.
+ KURL url = KURL(ParsedURLStringTag(), m_url);
Mike West 2016/07/12 13:56:08 Nit: `s/ParsedURLStringTag()/ParsedURLString/`. N
+ String base = SecurityOrigin::create(url)->domain();
+
+ // If the site is going to be accessing the YouTube Flash player using the
+ // JS APIs, we don't want to modify the player.
+ if (m_url.find("enablejsapi=1") == (size_t) -1
+ && rewriteYouTubeFlashEmbeds(base) && url.path().startsWith("/v/")) {
+
+ // If the website is using an invalid YouTube URL, we'll try and
+ // fix the url by ensuring that IF there are multiple parameters,
+ // the parameter string begins with a "?" and then follows with "&"
+ // for each subsequent parameter.
+ size_t indexAmp = m_url.find("&");
+ bool invalidUrl = false;
+ size_t indexQm = m_url.find("?");
+
+ if (indexQm == (size_t) -1 || indexQm > indexAmp) {
+ invalidUrl = true;
+ }
+
+ if (invalidUrl) {
+ m_url.replace("?", "&");
+ m_url.replace(indexAmp, 1, "?");
+ }
+
+ m_url.replace("/v/", "/embed/");
+ m_serviceType = "text/html";
+ }
+
requestObject(m_url, m_serviceType, paramNames, paramValues);
}
+bool HTMLEmbedElement::rewriteYouTubeFlashEmbeds(String const & baseUrl)
+{
+ if (baseUrl == String("www.youtube.com")) {
+ return true;
+ }
+ return false;
+}
+
bool HTMLEmbedElement::layoutObjectIsNeeded(const ComputedStyle& style)
{
if (isImageType())

Powered by Google App Engine
This is Rietveld 408576698