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..9d785a2ac88a397141fa5ad93ab6ba5319ff01d9 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" |
@@ -1390,3 +1391,45 @@ bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { |
return true; |
#endif |
} |
+ |
+std::string ChromeContentRendererClient::OverrideFlashEmbedWithHTML( |
+ const std::string& str_url) { |
+ DCHECK(!str_url.empty()); |
+ if (!base::FeatureList::IsEnabled(features::kOverrideYouTubeFlashEmbed)) |
+ return ""; |
mlamouri (slow - plz ping)
2016/07/28 19:46:54
nit: leave spaces around the `if` block:
```
DCHEC
kdsilva
2016/07/29 17:59:06
Done.
|
+ GURL url = GURL(str_url); |
+ |
+ // 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. |
+ 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, |
+ // 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; |
+ |
+ // ? should appear first before all parameters |
+ ret_url.replace(index, 1, "?"); |
+ |
+ // Replace all instances of ? (after the first) with & |
+ size_t start_pos = index + 1; |
+ while ((start_pos = ret_url.find("?", start_pos)) != std::string::npos) { |
mlamouri (slow - plz ping)
2016/07/28 19:46:54
That really sounds like something that should be w
kdsilva
2016/07/29 17:59:06
Done.
|
+ ret_url.replace(start_pos, 1, "&"); |
+ start_pos += 1; |
+ } |
+ return ret_url; |
+} |