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

Unified Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 2154233003: Rewrite YouTube Flash embeds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 4 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: chrome/renderer/chrome_content_renderer_client.cc
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index 11fd9c54a74b045e7ae339dc5575504e89986da3..ca5b06b68576d4b1a475ac824db48af0f95cf6d6 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -21,6 +21,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/common/channel_info.h"
+#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_isolated_world_ids.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -1389,3 +1390,58 @@ bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() {
return true;
#endif
}
+
+GURL ChromeContentRendererClient::OverrideFlashEmbedWithHTML(const GURL& url) {
+ if (!base::FeatureList::IsEnabled(features::kOverrideYouTubeFlashEmbed))
+ return GURL();
+
+ if (!url.is_valid())
+ return GURL();
+
+ // We'll only modify YouTube Flash embeds. The URLs can be recognized since
+ // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see
+ // if the given URL does follow that format.
+ if (!url.DomainIs("youtube.com") && !url.DomainIs("youtube-nocookie.com"))
+ return GURL();
+ if (url.path().find("/v/") != 0)
+ return GURL();
+
+ std::string url_str = url.spec();
+
+ // 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 a "&"
+ // for each subsequent parameter. We do this because the Flash video player
+ // has some URL correction capabilities so we don't want this move to HTML5
+ // to break webpages that used to work.
+ size_t index = url_str.find_first_of("&?");
+ bool invalid_url = index != std::string::npos && url_str.at(index) == '&';
+
+ if (invalid_url) {
+ // ? should appear first before all parameters
+ url_str.replace(index, 1, "?");
+
+ // Replace all instances of ? (after the first) with &
+ for (size_t pos = index + 1;
+ (pos = url_str.find("?", pos)) != std::string::npos; pos += 1) {
+ url_str.replace(pos, 1, "&");
+ }
+ }
+
+ GURL corrected_url = GURL(url_str);
+
+ // We don't modify any URLs that contain the enablejsapi=1 parameter
+ // since the page may be interacting with the YouTube Flash player in
+ // Javascript and we don't want to break working content.
+ if (corrected_url.query().find("enablejsapi=1") != std::string::npos)
+ return GURL();
+
+ // Change the path to use the YouTube HTML5 API
+ std::string path = corrected_url.path();
+ path.replace(path.find("/v/"), 3, "/embed/");
+
+ url::Replacements<char> r;
+ r.SetPath(path.c_str(), url::Component(0, path.length()));
+
+ return corrected_url.ReplaceComponents(r);
+}
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.h ('k') | chrome/renderer/chrome_content_renderer_client_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698