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

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: Clean up 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: 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 68c5529d55ea8d86eeaf69d6b5891f783f3a670a..dbb2c4a3ddb57654eddfa7c299bcad7ec65f3831 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -22,6 +22,7 @@
#include "build/build_config.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_isolated_world_ids.h"
+#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/crash_keys.h"
@@ -1390,3 +1391,48 @@ bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() {
return true;
#endif
}
+
+std::string ChromeContentRendererClient::OverrideFlashEmbedWithHTML(
+ const std::string& str_url) {
+ DCHECK(!str_url.empty());
+ GURL url = GURL(str_url);
mlamouri (slow - plz ping) 2016/07/28 13:05:12 You should move the `url` declaration after the Fe
kdsilva 2016/07/28 15:17:16 Done.
+
+ // 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. 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.
+ //
mlamouri (slow - plz ping) 2016/07/28 13:05:12 style: remove this //
kdsilva 2016/07/28 15:17:16 Done.
+ if (!base::FeatureList::IsEnabled(features::kOverrideFlashEmbed)) {
+ return "";
+ }
mlamouri (slow - plz ping) 2016/07/28 13:05:12 style: no { }
kdsilva 2016/07/28 15:17:16 Done.
+
+ if (!url.DomainIs("youtube.com") || url.path().find("/v/") != 0
+ || str_url.find("enablejsapi=1") != std::string::npos)
+ return "";
+
+ std::string ret_url = str_url;
+ ret_url.replace(ret_url.find("/v/"), 3, "/embed/");
+
+ // If the website is using an invalid YouTube URL, we'll try and
+ // fix the URL by ensuring that IF there are multiple parameters,
mlamouri (slow - plz ping) 2016/07/28 13:05:12 s/IF/if/
kdsilva 2016/07/28 15:17:17 Done.
+ // the parameter string begins with a "?" and then follows with a "&"
+ // for each subsequent parameter.
+ size_t index = ret_url.find_first_of("&?");
+ bool invalid_url = index != std::string::npos && ret_url.at(index) == '&';
+
+ if (!invalid_url)
+ return ret_url;
+
+ // Replace all instances of ? with &
mlamouri (slow - plz ping) 2016/07/28 13:05:12 Is this the fastest way to do what you want to do?
kdsilva 2016/07/28 15:17:16 Done.
+ size_t start_pos = 0;
+ while ((start_pos = ret_url.find("?", start_pos)) != std::string::npos) {
+ ret_url.replace(start_pos, 1, "&");
+ start_pos += 1;
+ }
+
+ // ? should appear first before all parameters
+ ret_url.replace(index, 1, "?");
+ return ret_url;
+}

Powered by Google App Engine
This is Rietveld 408576698