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_isolated_world_ids.h" | 24 #include "chrome/common/chrome_isolated_world_ids.h" |
25 #include "chrome/common/chrome_features.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" |
34 #include "chrome/grit/renderer_resources.h" | 35 #include "chrome/grit/renderer_resources.h" |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1383 // chrome.system.network.getNetworkInterfaces provides the same | 1384 // chrome.system.network.getNetworkInterfaces provides the same |
1384 // information. Also, the enforcement of sending and binding UDP is already done | 1385 // information. Also, the enforcement of sending and binding UDP is already done |
1385 // by chrome extension permission model. | 1386 // by chrome extension permission model. |
1386 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { | 1387 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { |
1387 #if defined(ENABLE_EXTENSIONS) | 1388 #if defined(ENABLE_EXTENSIONS) |
1388 return !IsStandaloneExtensionProcess(); | 1389 return !IsStandaloneExtensionProcess(); |
1389 #else | 1390 #else |
1390 return true; | 1391 return true; |
1391 #endif | 1392 #endif |
1392 } | 1393 } |
1394 | |
1395 std::string ChromeContentRendererClient::OverrideFlashEmbedWithHTML( | |
1396 const std::string& str_url) { | |
1397 DCHECK(!str_url.empty()); | |
1398 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.
| |
1399 | |
1400 // We'll only modify YouTube Flash embeds. The URLs can be recognized since | |
1401 // they're in the following form: youtube.com/v/VIDEO_ID. So, we check to see | |
1402 // if the given URL does follow that format. We don't modify | |
1403 // any URLs that contain the enablejsapi=1 parameter since the page may be | |
1404 // interacting with the YouTube Flash player in Javascript and we don't | |
1405 // want to break working content. | |
1406 // | |
mlamouri (slow - plz ping)
2016/07/28 13:05:12
style: remove this //
kdsilva
2016/07/28 15:17:16
Done.
| |
1407 if (!base::FeatureList::IsEnabled(features::kOverrideFlashEmbed)) { | |
1408 return ""; | |
1409 } | |
mlamouri (slow - plz ping)
2016/07/28 13:05:12
style: no { }
kdsilva
2016/07/28 15:17:16
Done.
| |
1410 | |
1411 if (!url.DomainIs("youtube.com") || url.path().find("/v/") != 0 | |
1412 || str_url.find("enablejsapi=1") != std::string::npos) | |
1413 return ""; | |
1414 | |
1415 std::string ret_url = str_url; | |
1416 ret_url.replace(ret_url.find("/v/"), 3, "/embed/"); | |
1417 | |
1418 // If the website is using an invalid YouTube URL, we'll try and | |
1419 // 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.
| |
1420 // the parameter string begins with a "?" and then follows with a "&" | |
1421 // for each subsequent parameter. | |
1422 size_t index = ret_url.find_first_of("&?"); | |
1423 bool invalid_url = index != std::string::npos && ret_url.at(index) == '&'; | |
1424 | |
1425 if (!invalid_url) | |
1426 return ret_url; | |
1427 | |
1428 // 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.
| |
1429 size_t start_pos = 0; | |
1430 while ((start_pos = ret_url.find("?", start_pos)) != std::string::npos) { | |
1431 ret_url.replace(start_pos, 1, "&"); | |
1432 start_pos += 1; | |
1433 } | |
1434 | |
1435 // ? should appear first before all parameters | |
1436 ret_url.replace(index, 1, "?"); | |
1437 return ret_url; | |
1438 } | |
OLD | NEW |