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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/crash_logging.h" 11 #include "base/debug/crash_logging.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/metrics/user_metrics_action.h" 16 #include "base/metrics/user_metrics_action.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "chrome/common/channel_info.h" 23 #include "chrome/common/channel_info.h"
24 #include "chrome/common/chrome_features.h"
24 #include "chrome/common/chrome_isolated_world_ids.h" 25 #include "chrome/common/chrome_isolated_world_ids.h"
25 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/crash_keys.h" 28 #include "chrome/common/crash_keys.h"
28 #include "chrome/common/pepper_permission_util.h" 29 #include "chrome/common/pepper_permission_util.h"
29 #include "chrome/common/render_messages.h" 30 #include "chrome/common/render_messages.h"
30 #include "chrome/common/secure_origin_whitelist.h" 31 #include "chrome/common/secure_origin_whitelist.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
32 #include "chrome/grit/generated_resources.h" 33 #include "chrome/grit/generated_resources.h"
33 #include "chrome/grit/locale_settings.h" 34 #include "chrome/grit/locale_settings.h"
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 // chrome.system.network.getNetworkInterfaces provides the same 1373 // chrome.system.network.getNetworkInterfaces provides the same
1373 // information. Also, the enforcement of sending and binding UDP is already done 1374 // information. Also, the enforcement of sending and binding UDP is already done
1374 // by chrome extension permission model. 1375 // by chrome extension permission model.
1375 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { 1376 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() {
1376 #if defined(ENABLE_EXTENSIONS) 1377 #if defined(ENABLE_EXTENSIONS)
1377 return !IsStandaloneExtensionProcess(); 1378 return !IsStandaloneExtensionProcess();
1378 #else 1379 #else
1379 return true; 1380 return true;
1380 #endif 1381 #endif
1381 } 1382 }
1383
1384 std::string ChromeContentRendererClient::OverrideFlashEmbedWithHTML(
1385 const std::string& str_url) {
1386 if (!base::FeatureList::IsEnabled(features::kOverrideYouTubeFlashEmbed))
1387 return "";
1388
1389 GURL url = GURL(str_url);
1390 if (!url.is_valid())
1391 return "";
1392
1393 // We'll only modify YouTube Flash embeds. The URLs can be recognized since
1394 // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see
1395 // if the given URL does follow that format. We don't modify
1396 // any URLs that contain the enablejsapi=1 parameter since the page may be
mlamouri (slow - plz ping) 2016/08/01 13:43:59 Can you open a follow-up bug to actually do the re
kdsilva 2016/08/02 15:34:46 Done.
1397 // interacting with the YouTube Flash player in Javascript and we don't
1398 // want to break working content.
1399 if (!url.DomainIs("youtube.com") || url.path().find("/v/") != 0
1400 || str_url.find("enablejsapi=1") != std::string::npos)
1401 return "";
dcheng 2016/08/01 14:50:34 This should just use GURLs, but note that converti
kdsilva 2016/08/02 15:34:46 Done.
1402
1403 std::string ret_url = str_url;
1404 ret_url.replace(ret_url.find("/v/"), 3, "/embed/");
dcheng 2016/08/01 14:50:34 Can we just use GURL and avoid cracking URLs manua
kdsilva 2016/08/02 15:34:46 Done.
1405
1406 // If the website is using an invalid YouTube URL, we'll try and
1407 // fix the URL by ensuring that if there are multiple parameters,
1408 // the parameter string begins with a "?" and then follows with a "&"
1409 // for each subsequent parameter.
dcheng 2016/08/01 14:50:34 Is it important to fix invalid URLs? Wouldn't they
kdsilva 2016/08/02 15:34:46 The Flash video player has some URL correction cap
1410 size_t index = ret_url.find_first_of("&?");
1411 bool invalid_url = index != std::string::npos && ret_url.at(index) == '&';
1412
1413 if (!invalid_url)
1414 return ret_url;
1415
1416 // ? should appear first before all parameters
1417 ret_url.replace(index, 1, "?");
1418
1419 // Replace all instances of ? (after the first) with &
1420 for (size_t pos = index + 1;
1421 (pos= ret_url.find("?",pos )) != std::string::npos; pos += 1)
1422 ret_url.replace(pos, 1, "&");
1423 return ret_url;
1424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698