Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 if (is_nacl_plugin) { | 398 if (is_nacl_plugin) { |
| 399 is_nacl_enabled = CommandLine::ForCurrentProcess()->HasSwitch( | 399 is_nacl_enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
| 400 switches::kEnableNaCl); | 400 switches::kEnableNaCl); |
| 401 } else { | 401 } else { |
| 402 // If this is an external plugin that handles NaCl mime type, | 402 // If this is an external plugin that handles NaCl mime type, |
| 403 // we want to allow Native Client, because it's how | 403 // we want to allow Native Client, because it's how |
| 404 // NaCl tests for the plugin work. | 404 // NaCl tests for the plugin work. |
| 405 is_nacl_enabled = true; | 405 is_nacl_enabled = true; |
| 406 } | 406 } |
| 407 if (is_nacl_plugin || is_nacl_mime_type) { | 407 if (is_nacl_plugin || is_nacl_mime_type) { |
| 408 if (!IsNaClAllowed(plugin, | 408 if (!IsNaClAllowed(frame, |
| 409 plugin, | |
| 409 url, | 410 url, |
| 410 actual_mime_type, | 411 actual_mime_type, |
| 411 is_nacl_mime_type, | 412 is_nacl_mime_type, |
| 412 is_nacl_enabled, | 413 is_nacl_enabled, |
| 413 params)) { | 414 params)) { |
| 414 frame->addMessageToConsole( | 415 frame->addMessageToConsole( |
| 415 WebConsoleMessage( | 416 WebConsoleMessage( |
| 416 WebConsoleMessage::LevelError, | 417 WebConsoleMessage::LevelError, |
| 417 "Only unpacked extensions and apps installed from the " | 418 "Only unpacked extensions and apps installed from the " |
| 418 "Chrome Web Store can load NaCl modules without enabling " | 419 "Chrome Web Store can load NaCl modules without enabling " |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 RenderThread::Get()->RecordUserMetrics("Plugin_Blocked"); | 478 RenderThread::Get()->RecordUserMetrics("Plugin_Blocked"); |
| 478 observer->DidBlockContentType(content_type, group->identifier()); | 479 observer->DidBlockContentType(content_type, group->identifier()); |
| 479 break; | 480 break; |
| 480 } | 481 } |
| 481 } | 482 } |
| 482 } | 483 } |
| 483 placeholder->SetStatus(status); | 484 placeholder->SetStatus(status); |
| 484 return placeholder->plugin(); | 485 return placeholder->plugin(); |
| 485 } | 486 } |
| 486 | 487 |
| 487 bool ChromeContentRendererClient::IsNaClAllowed( | 488 bool ChromeContentRendererClient::IsNaClAllowed( |
|
Mihai Parparita -not on Chrome
2012/02/10 23:03:33
This is complex enough that a unit tests would be
| |
| 489 WebFrame* frame, | |
| 488 const webkit::WebPluginInfo& plugin, | 490 const webkit::WebPluginInfo& plugin, |
| 489 const GURL& url, | 491 const GURL& url, |
| 490 const std::string& actual_mime_type, | 492 const std::string& actual_mime_type, |
| 491 bool is_nacl_mime_type, | 493 bool is_nacl_mime_type, |
| 492 bool enable_nacl, | 494 bool enable_nacl, |
| 493 WebKit::WebPluginParams& params) { | 495 WebKit::WebPluginParams& params) { |
| 494 GURL manifest_url; | 496 GURL manifest_url; |
| 495 if (is_nacl_mime_type) { | 497 if (is_nacl_mime_type) { |
| 496 manifest_url = url; // Normal embedded NaCl plugin. | 498 manifest_url = url; // Normal embedded NaCl plugin. |
| 497 } else { | 499 } else { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 508 if (content_type.additional_param_names[i] == nacl_attr) { | 510 if (content_type.additional_param_names[i] == nacl_attr) { |
| 509 manifest_url = GURL(content_type.additional_param_values[i]); | 511 manifest_url = GURL(content_type.additional_param_values[i]); |
| 510 break; | 512 break; |
| 511 } | 513 } |
| 512 } | 514 } |
| 513 break; | 515 break; |
| 514 } | 516 } |
| 515 } | 517 } |
| 516 } | 518 } |
| 517 | 519 |
| 518 // Determine if the manifest URL is part of an extension. | 520 // Determine if the manifest is part of an extension. |
| 519 const Extension* extension = | 521 const Extension* extension = |
| 520 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( | 522 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( |
| 521 ExtensionURLInfo(manifest_url)); | 523 ExtensionURLInfo(manifest_url)); |
| 522 // Only component, unpacked, and Chrome Web Store extensions are allowed. | 524 // Only allow component, unpacked, and Chrome Web Store extensions. |
| 523 bool allowed_extension = extension && | 525 bool allowed_extension = extension && |
| 524 (extension->from_webstore() || | 526 (extension->from_webstore() || |
| 525 extension->location() == Extension::COMPONENT || | 527 extension->location() == Extension::COMPONENT || |
| 526 extension->location() == Extension::LOAD); | 528 extension->location() == Extension::LOAD); |
| 527 | 529 |
| 528 // Block any other use of NaCl plugin, unless --enable-nacl is set. | 530 // Check if this NaCl app's top level URL is whitelisted. |
| 529 if (!allowed_extension && !enable_nacl) | 531 bool whitelisted_url = false; |
| 532 GURL top_url = frame->top()->document().url(); | |
| 533 if (top_url.SchemeIs("http") || top_url.SchemeIs("https")) { | |
|
Mihai Parparita -not on Chrome
2012/02/10 23:03:33
Nit: why not merge this into the whilelisted_url b
| |
| 534 whitelisted_url = ((top_url.host() == "plus.google.com" || | |
| 535 top_url.host() == "plus.sandbox.google.com") && | |
| 536 top_url.path().find("/games") == 0); | |
| 537 } | |
| 538 | |
| 539 if (!allowed_extension && !whitelisted_url && !enable_nacl) | |
| 530 return false; | 540 return false; |
| 531 | 541 |
| 532 // Allow dev interfaces for non-extension apps. | 542 // Block dev interfaces for production apps. These are packaged apps from |
| 543 // the Chrome Web Store and apps inside whitelisted URLs. | |
| 533 bool allow_dev_interfaces = true; | 544 bool allow_dev_interfaces = true; |
| 534 if (allowed_extension) { | 545 if (allowed_extension) { |
| 535 // Allow dev interfaces for component and unpacked extensions. | |
| 536 if (extension->location() != Extension::COMPONENT && | 546 if (extension->location() != Extension::COMPONENT && |
| 537 extension->location() != Extension::LOAD) { | 547 extension->location() != Extension::LOAD) { |
| 538 // Whitelist all other allowed extensions. | 548 // Don't block whitelisted apps. |
| 539 allow_dev_interfaces = | 549 allow_dev_interfaces = |
| 540 // PDF Viewer plugin | 550 // PDF Viewer plugin |
| 541 (manifest_url.scheme() == "chrome-extension" && | 551 (manifest_url.SchemeIs("chrome-extension") && |
| 542 manifest_url.host() == "acadkphlmlegjaadjagenfimbpphcgnh"); | 552 manifest_url.host() == "acadkphlmlegjaadjagenfimbpphcgnh"); |
| 543 } | 553 } |
| 554 } else if (whitelisted_url) { | |
| 555 allow_dev_interfaces = false; | |
| 544 } | 556 } |
| 545 | 557 |
| 546 WebString dev_attribute = WebString::fromUTF8("@dev"); | 558 WebString dev_attribute = WebString::fromUTF8("@dev"); |
| 547 if (allow_dev_interfaces) { | 559 if (allow_dev_interfaces) { |
| 548 std::vector<string16> param_names; | 560 std::vector<string16> param_names; |
| 549 std::vector<string16> param_values; | 561 std::vector<string16> param_values; |
| 550 param_names.push_back(dev_attribute); | 562 param_names.push_back(dev_attribute); |
| 551 param_values.push_back(WebString()); | 563 param_values.push_back(WebString()); |
| 552 AppendParams( | 564 AppendParams( |
| 553 param_names, | 565 param_names, |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) { | 872 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) { |
| 861 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory); | 873 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory); |
| 862 } | 874 } |
| 863 | 875 |
| 864 bool ChromeContentRendererClient::AllowSocketAPI(const GURL& url) { | 876 bool ChromeContentRendererClient::AllowSocketAPI(const GURL& url) { |
| 865 return allowed_socket_origins_.find(url.host()) != | 877 return allowed_socket_origins_.find(url.host()) != |
| 866 allowed_socket_origins_.end(); | 878 allowed_socket_origins_.end(); |
| 867 } | 879 } |
| 868 | 880 |
| 869 } // namespace chrome | 881 } // namespace chrome |
| OLD | NEW |