OLD | NEW |
---|---|
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 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1382 // chrome.system.network.getNetworkInterfaces provides the same | 1383 // chrome.system.network.getNetworkInterfaces provides the same |
1383 // information. Also, the enforcement of sending and binding UDP is already done | 1384 // information. Also, the enforcement of sending and binding UDP is already done |
1384 // by chrome extension permission model. | 1385 // by chrome extension permission model. |
1385 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { | 1386 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { |
1386 #if defined(ENABLE_EXTENSIONS) | 1387 #if defined(ENABLE_EXTENSIONS) |
1387 return !IsStandaloneExtensionProcess(); | 1388 return !IsStandaloneExtensionProcess(); |
1388 #else | 1389 #else |
1389 return true; | 1390 return true; |
1390 #endif | 1391 #endif |
1391 } | 1392 } |
1393 | |
1394 GURL ChromeContentRendererClient::OverrideFlashEmbedWithHTML(const GURL& url) { | |
1395 if (!base::FeatureList::IsEnabled(features::kOverrideYouTubeFlashEmbed)) | |
1396 return GURL(); | |
1397 | |
1398 if (!url.is_valid()) | |
1399 return GURL(); | |
1400 | |
1401 // We'll only modify YouTube Flash embeds. The URLs can be recognized since | |
1402 // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see | |
1403 // if the given URL does follow that format. | |
1404 if (!url.DomainIs("youtube.com") || url.path().find("/v/") != 0) | |
Mike West
2016/08/04 12:41:38
I'd suggest that we handle `youtube-nocookie.com`
kdsilva
2016/08/05 11:06:02
Done.
| |
1405 return GURL(); | |
1406 | |
1407 std::string url_str = url.spec(); | |
1408 | |
1409 // If the website is using an invalid YouTube URL, we'll try and | |
1410 // fix the URL by ensuring that if there are multiple parameters, | |
1411 // the parameter string begins with a "?" and then follows with a "&" | |
1412 // for each subsequent parameter. We do this because the Flash video player | |
1413 // has some URL correction capabilities so we don't want this move to HTML5 | |
1414 // to break webpages that used to work. | |
1415 size_t index = url_str.find_first_of("&?"); | |
1416 bool invalid_url = index != std::string::npos && url_str.at(index) == '&'; | |
1417 | |
1418 if (invalid_url) { | |
1419 // ? should appear first before all parameters | |
1420 url_str.replace(index, 1, "?"); | |
1421 | |
1422 // Replace all instances of ? (after the first) with & | |
1423 for (size_t pos = index + 1; | |
1424 (pos = url_str.find("?",pos )) != std::string::npos; pos += 1) | |
Mike West
2016/08/04 12:41:38
Nit: Please add braces here, as the for loop is mu
kdsilva
2016/08/05 11:06:02
Done. Looks like `git cl format` did fix the inden
| |
1425 url_str.replace(pos, 1, "&"); | |
1426 } | |
1427 | |
1428 GURL corrected_url = GURL(url_str); | |
Mike West
2016/08/04 12:41:38
Nit: Did you consider wrapping this up in the `url
kdsilva
2016/08/05 11:06:02
Ack.
| |
1429 | |
1430 // We don't modify any URLs that contain the enablejsapi=1 parameter | |
1431 // since the page may be interacting with the YouTube Flash player in | |
1432 // Javascript and we don't want to break working content. | |
1433 if (corrected_url.query().find("enablejsapi=1") != std::string::npos) | |
Mike West
2016/08/04 12:41:38
This will also match `?XXXenablejsapi=1` and `?a=e
kdsilva
2016/08/05 11:06:02
Ack. Happy to discuss, but I think this is okay fo
| |
1434 return GURL(); | |
1435 | |
1436 // Change the path to use the YouTube HTML5 API | |
1437 std::string path = corrected_url.path(); | |
1438 path.replace(path.find("/v/"), 3, "/embed/"); | |
1439 | |
1440 url::Replacements<char> r; | |
1441 r.SetPath(path.c_str(), url::Component(0, path.length())); | |
1442 | |
1443 return corrected_url.ReplaceComponents(r); | |
1444 } | |
OLD | NEW |