| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/crash_keys.h" | 27 #include "chrome/common/crash_keys.h" |
| 28 #include "chrome/common/pepper_permission_util.h" | 28 #include "chrome/common/pepper_permission_util.h" |
| 29 #include "chrome/common/render_messages.h" | 29 #include "chrome/common/render_messages.h" |
| 30 #include "chrome/common/secure_origin_whitelist.h" | 30 #include "chrome/common/secure_origin_whitelist.h" |
| 31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 33 #include "chrome/grit/locale_settings.h" | 33 #include "chrome/grit/locale_settings.h" |
| 34 #include "chrome/grit/renderer_resources.h" | 34 #include "chrome/grit/renderer_resources.h" |
| 35 #include "chrome/renderer/app_categorizer.h" |
| 35 #include "chrome/renderer/banners/app_banner_client.h" | 36 #include "chrome/renderer/banners/app_banner_client.h" |
| 36 #include "chrome/renderer/benchmarking_extension.h" | 37 #include "chrome/renderer/benchmarking_extension.h" |
| 37 #include "chrome/renderer/chrome_render_frame_observer.h" | 38 #include "chrome/renderer/chrome_render_frame_observer.h" |
| 38 #include "chrome/renderer/chrome_render_thread_observer.h" | 39 #include "chrome/renderer/chrome_render_thread_observer.h" |
| 39 #include "chrome/renderer/chrome_render_view_observer.h" | 40 #include "chrome/renderer/chrome_render_view_observer.h" |
| 40 #include "chrome/renderer/content_settings_observer.h" | 41 #include "chrome/renderer/content_settings_observer.h" |
| 41 #include "chrome/renderer/external_extension.h" | 42 #include "chrome/renderer/external_extension.h" |
| 42 #include "chrome/renderer/loadtimes_extension_bindings.h" | 43 #include "chrome/renderer/loadtimes_extension_bindings.h" |
| 43 #include "chrome/renderer/media/chrome_key_systems.h" | 44 #include "chrome/renderer/media/chrome_key_systems.h" |
| 44 #include "chrome/renderer/net/net_error_helper.h" | 45 #include "chrome/renderer/net/net_error_helper.h" |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 | 897 |
| 897 #if !defined(DISABLE_NACL) | 898 #if !defined(DISABLE_NACL) |
| 898 // static | 899 // static |
| 899 bool ChromeContentRendererClient::IsNaClAllowed( | 900 bool ChromeContentRendererClient::IsNaClAllowed( |
| 900 const GURL& manifest_url, | 901 const GURL& manifest_url, |
| 901 const GURL& app_url, | 902 const GURL& app_url, |
| 902 bool is_nacl_unrestricted, | 903 bool is_nacl_unrestricted, |
| 903 const Extension* extension, | 904 const Extension* extension, |
| 904 WebPluginParams* params) { | 905 WebPluginParams* params) { |
| 905 // Temporarily allow these whitelisted apps and WebUIs to use NaCl. | 906 // Temporarily allow these whitelisted apps and WebUIs to use NaCl. |
| 906 std::string app_url_host = app_url.host(); | |
| 907 std::string manifest_url_path = manifest_url.path(); | |
| 908 | |
| 909 bool is_whitelisted_web_ui = | 907 bool is_whitelisted_web_ui = |
| 910 app_url.spec() == chrome::kChromeUIAppListStartPageURL; | 908 app_url.spec() == chrome::kChromeUIAppListStartPageURL; |
| 911 | 909 |
| 912 bool is_photo_app = | |
| 913 // Whitelisted apps must be served over https. | |
| 914 app_url.SchemeIsCryptographic() && manifest_url.SchemeIsCryptographic() && | |
| 915 (base::EndsWith(app_url_host, "plus.google.com", | |
| 916 base::CompareCase::INSENSITIVE_ASCII) || | |
| 917 base::EndsWith(app_url_host, "plus.sandbox.google.com", | |
| 918 base::CompareCase::INSENSITIVE_ASCII)) && | |
| 919 manifest_url.DomainIs("ssl.gstatic.com") && | |
| 920 (manifest_url_path.find("s2/oz/nacl/") == 1 || | |
| 921 manifest_url_path.find("photos/nacl/") == 1); | |
| 922 | |
| 923 std::string manifest_fs_host; | |
| 924 if (manifest_url.SchemeIsFileSystem() && manifest_url.inner_url()) { | |
| 925 manifest_fs_host = manifest_url.inner_url()->host(); | |
| 926 } | |
| 927 bool is_hangouts_app = | |
| 928 // Whitelisted apps must be served over secure scheme. | |
| 929 app_url.SchemeIsCryptographic() && manifest_url.SchemeIsFileSystem() && | |
| 930 manifest_url.inner_url()->SchemeIsCryptographic() && | |
| 931 (base::EndsWith(app_url_host, "talkgadget.google.com", | |
| 932 base::CompareCase::INSENSITIVE_ASCII) || | |
| 933 base::EndsWith(app_url_host, "plus.google.com", | |
| 934 base::CompareCase::INSENSITIVE_ASCII) || | |
| 935 base::EndsWith(app_url_host, "plus.sandbox.google.com", | |
| 936 base::CompareCase::INSENSITIVE_ASCII) || | |
| 937 base::EndsWith(app_url_host, "hangouts.google.com", | |
| 938 base::CompareCase::INSENSITIVE_ASCII)) && | |
| 939 // The manifest must be loaded from the host's FileSystem. | |
| 940 (manifest_fs_host == app_url_host); | |
| 941 | |
| 942 bool is_whitelisted_app = is_photo_app || is_hangouts_app; | |
| 943 | |
| 944 bool is_invoked_by_webstore_installed_extension = false; | 910 bool is_invoked_by_webstore_installed_extension = false; |
| 945 bool is_extension_unrestricted = false; | 911 bool is_extension_unrestricted = false; |
| 946 bool is_extension_force_installed = false; | 912 bool is_extension_force_installed = false; |
| 947 #if defined(ENABLE_EXTENSIONS) | 913 #if defined(ENABLE_EXTENSIONS) |
| 948 bool is_extension_from_webstore = extension && extension->from_webstore(); | 914 bool is_extension_from_webstore = extension && extension->from_webstore(); |
| 949 | 915 |
| 950 bool is_invoked_by_extension = app_url.SchemeIs("chrome-extension"); | 916 bool is_invoked_by_extension = app_url.SchemeIs("chrome-extension"); |
| 951 bool is_invoked_by_hosted_app = extension && | 917 bool is_invoked_by_hosted_app = extension && |
| 952 extension->is_hosted_app() && | 918 extension->is_hosted_app() && |
| 953 extension->web_extent().MatchesURL(app_url); | 919 extension->web_extent().MatchesURL(app_url); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 966 | 932 |
| 967 // Allow NaCl under any of the following circumstances: | 933 // Allow NaCl under any of the following circumstances: |
| 968 // 1) An app or URL is explictly whitelisted above. | 934 // 1) An app or URL is explictly whitelisted above. |
| 969 // 2) An extension is loaded unpacked or built-in (component) to Chrome. | 935 // 2) An extension is loaded unpacked or built-in (component) to Chrome. |
| 970 // 3) An extension is force installed by policy. | 936 // 3) An extension is force installed by policy. |
| 971 // 4) An extension is installed from the webstore, and invoked in that | 937 // 4) An extension is installed from the webstore, and invoked in that |
| 972 // context (hosted app URL or chrome-extension:// scheme). | 938 // context (hosted app URL or chrome-extension:// scheme). |
| 973 // 5) --enable-nacl is set. | 939 // 5) --enable-nacl is set. |
| 974 bool is_nacl_allowed_by_location = | 940 bool is_nacl_allowed_by_location = |
| 975 is_whitelisted_web_ui || | 941 is_whitelisted_web_ui || |
| 976 is_whitelisted_app || | 942 AppCategorizer::IsWhitelistedApp(manifest_url, app_url) || |
| 977 is_extension_unrestricted || | 943 is_extension_unrestricted || |
| 978 is_extension_force_installed || | 944 is_extension_force_installed || |
| 979 is_invoked_by_webstore_installed_extension; | 945 is_invoked_by_webstore_installed_extension; |
| 980 bool is_nacl_allowed = is_nacl_allowed_by_location || is_nacl_unrestricted; | 946 bool is_nacl_allowed = is_nacl_allowed_by_location || is_nacl_unrestricted; |
| 981 if (is_nacl_allowed) { | 947 if (is_nacl_allowed) { |
| 982 // Make sure that PPAPI 'dev' interfaces are only available for unpacked | 948 // Make sure that PPAPI 'dev' interfaces are only available for unpacked |
| 983 // and component extensions. Also allow dev interfaces when --enable-nacl | 949 // and component extensions. Also allow dev interfaces when --enable-nacl |
| 984 // is set, but do not allow --enable-nacl to provide dev interfaces to | 950 // is set, but do not allow --enable-nacl to provide dev interfaces to |
| 985 // webstore installed and other normally allowed URLs. | 951 // webstore installed and other normally allowed URLs. |
| 986 WebString dev_attribute = WebString::fromUTF8("@dev"); | 952 WebString dev_attribute = WebString::fromUTF8("@dev"); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 #endif | 1188 #endif |
| 1223 | 1189 |
| 1224 blink::WebSpeechSynthesizer* | 1190 blink::WebSpeechSynthesizer* |
| 1225 ChromeContentRendererClient::OverrideSpeechSynthesizer( | 1191 ChromeContentRendererClient::OverrideSpeechSynthesizer( |
| 1226 blink::WebSpeechSynthesizerClient* client) { | 1192 blink::WebSpeechSynthesizerClient* client) { |
| 1227 return new TtsDispatcher(client); | 1193 return new TtsDispatcher(client); |
| 1228 } | 1194 } |
| 1229 | 1195 |
| 1230 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI( | 1196 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI( |
| 1231 const GURL& url) { | 1197 const GURL& url) { |
| 1232 #if !defined(OS_ANDROID) | 1198 #if defined(OS_ANDROID) |
| 1233 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check | 1199 return false; |
| 1234 // the whitelist in the renderer, since we're only preventing access until | 1200 #else |
| 1235 // these APIs are public and stable. | |
| 1236 std::string url_host = url.host(); | |
| 1237 if (url.SchemeIs("https") && | |
| 1238 (base::EndsWith(url_host, "talkgadget.google.com", | |
| 1239 base::CompareCase::INSENSITIVE_ASCII) || | |
| 1240 base::EndsWith(url_host, "plus.google.com", | |
| 1241 base::CompareCase::INSENSITIVE_ASCII) || | |
| 1242 base::EndsWith(url_host, "plus.sandbox.google.com", | |
| 1243 base::CompareCase::INSENSITIVE_ASCII)) && | |
| 1244 base::StartsWith(url.path(), "/hangouts/", | |
| 1245 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 1246 return true; | |
| 1247 } | |
| 1248 // Allow access for tests. | 1201 // Allow access for tests. |
| 1249 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1202 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1250 switches::kEnablePepperTesting)) { | 1203 switches::kEnablePepperTesting)) { |
| 1251 return true; | 1204 return true; |
| 1252 } | 1205 } |
| 1206 |
| 1207 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check |
| 1208 // the whitelist in the renderer, since we're only preventing access until |
| 1209 // these APIs are public and stable. |
| 1210 return (AppCategorizer::IsHangoutsUrl(url)); |
| 1253 #endif // !defined(OS_ANDROID) | 1211 #endif // !defined(OS_ANDROID) |
| 1254 return false; | |
| 1255 } | 1212 } |
| 1256 | 1213 |
| 1257 void ChromeContentRendererClient::AddSupportedKeySystems( | 1214 void ChromeContentRendererClient::AddSupportedKeySystems( |
| 1258 std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems) { | 1215 std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems) { |
| 1259 AddChromeKeySystems(key_systems); | 1216 AddChromeKeySystems(key_systems); |
| 1260 } | 1217 } |
| 1261 | 1218 |
| 1262 bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource( | 1219 bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource( |
| 1263 const base::string16& source) const { | 1220 const base::string16& source) const { |
| 1264 #if defined(ENABLE_EXTENSIONS) | 1221 #if defined(ENABLE_EXTENSIONS) |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 // chrome.system.network.getNetworkInterfaces provides the same | 1380 // chrome.system.network.getNetworkInterfaces provides the same |
| 1424 // information. Also, the enforcement of sending and binding UDP is already done | 1381 // information. Also, the enforcement of sending and binding UDP is already done |
| 1425 // by chrome extension permission model. | 1382 // by chrome extension permission model. |
| 1426 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { | 1383 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { |
| 1427 #if defined(ENABLE_EXTENSIONS) | 1384 #if defined(ENABLE_EXTENSIONS) |
| 1428 return !IsStandaloneExtensionProcess(); | 1385 return !IsStandaloneExtensionProcess(); |
| 1429 #else | 1386 #else |
| 1430 return true; | 1387 return true; |
| 1431 #endif | 1388 #endif |
| 1432 } | 1389 } |
| OLD | NEW |