| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/crash_logging.h" | 8 #include "base/debug/crash_logging.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 return GURL(); | 767 return GURL(); |
| 768 } | 768 } |
| 769 | 769 |
| 770 // static | 770 // static |
| 771 bool ChromeContentRendererClient::IsNaClAllowed( | 771 bool ChromeContentRendererClient::IsNaClAllowed( |
| 772 const GURL& manifest_url, | 772 const GURL& manifest_url, |
| 773 const GURL& app_url, | 773 const GURL& app_url, |
| 774 bool is_nacl_unrestricted, | 774 bool is_nacl_unrestricted, |
| 775 const Extension* extension, | 775 const Extension* extension, |
| 776 WebPluginParams* params) { | 776 WebPluginParams* params) { |
| 777 // Temporarily allow these URLs to run NaCl apps, as long as the manifest is | 777 // Temporarily allow these whitelisted apps to use NaCl. |
| 778 // also whitelisted. We should remove this code when PNaCl ships. | 778 std::string app_url_host = app_url.host(); |
| 779 bool is_whitelisted_url = | 779 std::string manifest_url_path = manifest_url.path(); |
| 780 bool is_whitelisted_app = |
| 781 // Whitelisted apps must be served over https. |
| 780 app_url.SchemeIs("https") && | 782 app_url.SchemeIs("https") && |
| 781 (app_url.host() == "plus.google.com" || | |
| 782 app_url.host() == "plus.sandbox.google.com") && | |
| 783 manifest_url.SchemeIs("https") && | 783 manifest_url.SchemeIs("https") && |
| 784 manifest_url.host() == "ssl.gstatic.com" && | 784 // Photos app. |
| 785 ((manifest_url.path().find("s2/oz/nacl/") == 1) || | 785 (((EndsWith(app_url_host, "plus.google.com", false) || |
| 786 (manifest_url.path().find("photos/nacl/") == 1)); | 786 EndsWith(app_url_host, "plus.sandbox.google.com", false)) && |
| 787 manifest_url.DomainIs("ssl.gstatic.com") && |
| 788 (manifest_url_path.find("s2/oz/nacl/") == 1 || |
| 789 manifest_url_path.find("photos/nacl/") == 1)) || |
| 790 // Chat app. |
| 791 ((EndsWith(app_url_host, "talk.google.com", false) || |
| 792 EndsWith(app_url_host, "talkgadget.google.com", false)) && |
| 793 manifest_url.DomainIs("ssl.gstatic.com") && |
| 794 manifest_url_path.find("chat/apps/fx") == 1)); |
| 787 | 795 |
| 788 bool is_extension_from_webstore = | 796 bool is_extension_from_webstore = |
| 789 extension && extension->from_webstore(); | 797 extension && extension->from_webstore(); |
| 790 | 798 |
| 791 bool is_invoked_by_hosted_app = extension && | 799 bool is_invoked_by_hosted_app = extension && |
| 792 extension->is_hosted_app() && | 800 extension->is_hosted_app() && |
| 793 extension->web_extent().MatchesURL(app_url); | 801 extension->web_extent().MatchesURL(app_url); |
| 794 | 802 |
| 795 // Allow built-in extensions and extensions under development. | 803 // Allow built-in extensions and extensions under development. |
| 796 bool is_extension_unrestricted = extension && | 804 bool is_extension_unrestricted = extension && |
| 797 (extension->location() == extensions::Manifest::COMPONENT || | 805 (extension->location() == extensions::Manifest::COMPONENT || |
| 798 extensions::Manifest::IsUnpackedLocation(extension->location())); | 806 extensions::Manifest::IsUnpackedLocation(extension->location())); |
| 799 | 807 |
| 800 bool is_invoked_by_extension = app_url.SchemeIs("chrome-extension"); | 808 bool is_invoked_by_extension = app_url.SchemeIs("chrome-extension"); |
| 801 | 809 |
| 802 // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces. | 810 // The NaCl PDF viewer is always allowed and can use 'Dev' interfaces. |
| 803 bool is_nacl_pdf_viewer = | 811 bool is_nacl_pdf_viewer = |
| 804 (is_extension_from_webstore && | 812 (is_extension_from_webstore && |
| 805 manifest_url.SchemeIs("chrome-extension") && | 813 manifest_url.SchemeIs("chrome-extension") && |
| 806 manifest_url.host() == "acadkphlmlegjaadjagenfimbpphcgnh"); | 814 manifest_url.host() == "acadkphlmlegjaadjagenfimbpphcgnh"); |
| 807 | 815 |
| 808 // Allow Chrome Web Store extensions, built-in extensions and extensions | 816 // Allow Chrome Web Store extensions, built-in extensions and extensions |
| 809 // under development if the invocation comes from a URL with an extension | 817 // under development if the invocation comes from a URL with an extension |
| 810 // scheme. Also allow invocations if they are from whitelisted URLs or | 818 // scheme. Also allow invocations if they are from whitelisted URLs or |
| 811 // if --enable-nacl is set. | 819 // if --enable-nacl is set. |
| 812 bool is_nacl_allowed = is_nacl_unrestricted || | 820 bool is_nacl_allowed = is_nacl_unrestricted || |
| 813 is_whitelisted_url || | 821 is_whitelisted_app || |
| 814 is_nacl_pdf_viewer || | 822 is_nacl_pdf_viewer || |
| 815 is_invoked_by_hosted_app || | 823 is_invoked_by_hosted_app || |
| 816 (is_invoked_by_extension && | 824 (is_invoked_by_extension && |
| 817 (is_extension_from_webstore || | 825 (is_extension_from_webstore || |
| 818 is_extension_unrestricted)); | 826 is_extension_unrestricted)); |
| 819 if (is_nacl_allowed) { | 827 if (is_nacl_allowed) { |
| 820 bool app_can_use_dev_interfaces = is_nacl_pdf_viewer; | 828 bool app_can_use_dev_interfaces = is_nacl_pdf_viewer; |
| 821 // Make sure that PPAPI 'dev' interfaces aren't available for production | 829 // Make sure that PPAPI 'dev' interfaces aren't available for production |
| 822 // apps unless they're whitelisted. | 830 // apps unless they're whitelisted. |
| 823 WebString dev_attribute = WebString::fromUTF8("@dev"); | 831 WebString dev_attribute = WebString::fromUTF8("@dev"); |
| 824 if ((!is_whitelisted_url && !is_extension_from_webstore) || | 832 if ((!is_whitelisted_app && !is_extension_from_webstore) || |
| 825 app_can_use_dev_interfaces) { | 833 app_can_use_dev_interfaces) { |
| 826 // Add the special '@dev' attribute. | 834 // Add the special '@dev' attribute. |
| 827 std::vector<string16> param_names; | 835 std::vector<string16> param_names; |
| 828 std::vector<string16> param_values; | 836 std::vector<string16> param_values; |
| 829 param_names.push_back(dev_attribute); | 837 param_names.push_back(dev_attribute); |
| 830 param_values.push_back(WebString()); | 838 param_values.push_back(WebString()); |
| 831 AppendParams( | 839 AppendParams( |
| 832 param_names, | 840 param_names, |
| 833 param_values, | 841 param_values, |
| 834 ¶ms->attributeNames, | 842 ¶ms->attributeNames, |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 return false; | 1287 return false; |
| 1280 | 1288 |
| 1281 WebString tag_name = container->element().shadowHost().tagName(); | 1289 WebString tag_name = container->element().shadowHost().tagName(); |
| 1282 return tag_name.equals(WebString::fromUTF8(kWebViewTagName)) || | 1290 return tag_name.equals(WebString::fromUTF8(kWebViewTagName)) || |
| 1283 tag_name.equals(WebString::fromUTF8(kAdViewTagName)); | 1291 tag_name.equals(WebString::fromUTF8(kAdViewTagName)); |
| 1284 } | 1292 } |
| 1285 | 1293 |
| 1286 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI( | 1294 bool ChromeContentRendererClient::AllowPepperMediaStreamAPI( |
| 1287 const GURL& url) { | 1295 const GURL& url) { |
| 1288 #if !defined(OS_ANDROID) | 1296 #if !defined(OS_ANDROID) |
| 1289 std::string host = url.host(); | 1297 // Allow only the Chat app to use the MediaStream APIs. It's OK to check |
| 1290 // Allow only the Hangouts app to use the MediaStream APIs. It's OK to check | |
| 1291 // the whitelist in the renderer, since we're only preventing access until | 1298 // the whitelist in the renderer, since we're only preventing access until |
| 1292 // these APIs are public and stable. | 1299 // these APIs are public and stable. |
| 1293 if (url.SchemeIs(extensions::kExtensionScheme) && | 1300 std::string url_host = url.host(); |
| 1294 !host.compare("hpcogiolnobbkijnnkdahioejpdcdoph")) { | 1301 if (url.SchemeIs("https") && |
| 1302 (EndsWith(url_host, "talk.google.com", false) || |
| 1303 EndsWith(url_host, "talkgadget.google.com", false))) { |
| 1295 return true; | 1304 return true; |
| 1296 } | 1305 } |
| 1297 // Allow access for tests. | 1306 // Allow access for tests. |
| 1298 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1307 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1299 switches::kEnablePepperTesting)) { | 1308 switches::kEnablePepperTesting)) { |
| 1300 return true; | 1309 return true; |
| 1301 } | 1310 } |
| 1302 #endif // !defined(OS_ANDROID) | 1311 #endif // !defined(OS_ANDROID) |
| 1303 return false; | 1312 return false; |
| 1304 } | 1313 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1317 // SiteIsolationPolicy is off by default. We would like to activate cross-site | 1326 // SiteIsolationPolicy is off by default. We would like to activate cross-site |
| 1318 // document blocking (for UMA data collection) for normal renderer processes | 1327 // document blocking (for UMA data collection) for normal renderer processes |
| 1319 // running a normal web page from the Internet. We only turn on | 1328 // running a normal web page from the Internet. We only turn on |
| 1320 // SiteIsolationPolicy for a renderer process that does not have the extension | 1329 // SiteIsolationPolicy for a renderer process that does not have the extension |
| 1321 // flag on. | 1330 // flag on. |
| 1322 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1331 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 1323 return !command_line->HasSwitch(switches::kExtensionProcess); | 1332 return !command_line->HasSwitch(switches::kExtensionProcess); |
| 1324 } | 1333 } |
| 1325 | 1334 |
| 1326 } // namespace chrome | 1335 } // namespace chrome |
| OLD | NEW |