Chromium Code Reviews| 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 2f4ebe61c9e84f915ea5ff91c494ed572651d63a..4fc167dcb33736d5d3dba660e8892b95fcae7a31 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" |
| @@ -1379,3 +1380,47 @@ bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { |
| return true; |
| #endif |
| } |
| + |
| +std::string ChromeContentRendererClient::OverrideFlashEmbedWithHTML( |
| + const std::string& str_url) { |
| + |
| + if (str_url.empty()) |
| + return ""; |
|
mlamouri (slow - plz ping)
2016/07/30 17:46:06
Instead of checking if the string is empty, could
kdsilva
2016/08/01 12:42:44
Done.
|
| + |
| + if (!base::FeatureList::IsEnabled(features::kOverrideYouTubeFlashEmbed)) |
| + return ""; |
| + |
| + GURL url = GURL(str_url); |
|
mlamouri (slow - plz ping)
2016/07/30 17:46:06
Maybe add:
```
if (!url.is_valid())
return "";
`
kdsilva
2016/08/01 12:42:44
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. |
| + 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 & |
| + for (size_t pos = index + 1; |
| + (pos= ret_url.find("?",pos )) != std::string::npos; pos += 1) |
| + ret_url.replace(pos, 1, "&"); |
| + return ret_url; |
| +} |