OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 break; | 467 break; |
468 } | 468 } |
469 } | 469 } |
470 break; | 470 break; |
471 } | 471 } |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 // Determine if the manifest URL is part of an extension. | 475 // Determine if the manifest URL is part of an extension. |
476 const Extension* extension = | 476 const Extension* extension = |
477 extension_dispatcher_->extensions()->GetByURL( | 477 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( |
478 ExtensionURLInfo(manifest_url)); | 478 ExtensionURLInfo(manifest_url)); |
479 // Only component, unpacked, and Chrome Web Store extensions are allowed. | 479 // Only component, unpacked, and Chrome Web Store extensions are allowed. |
480 bool allowed_extension = extension && | 480 bool allowed_extension = extension && |
481 (extension->from_webstore() || | 481 (extension->from_webstore() || |
482 extension->location() == Extension::COMPONENT || | 482 extension->location() == Extension::COMPONENT || |
483 extension->location() == Extension::LOAD); | 483 extension->location() == Extension::LOAD); |
484 | 484 |
485 // Block any other use of NaCl plugin, unless --enable-nacl is set. | 485 // Block any other use of NaCl plugin, unless --enable-nacl is set. |
486 if (!allowed_extension && !enable_nacl) | 486 if (!allowed_extension && !enable_nacl) |
487 return false; | 487 return false; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 std::string* error_html, | 541 std::string* error_html, |
542 string16* error_description) { | 542 string16* error_description) { |
543 const GURL failed_url = error.unreachableURL; | 543 const GURL failed_url = error.unreachableURL; |
544 const Extension* extension = NULL; | 544 const Extension* extension = NULL; |
545 const bool is_repost = | 545 const bool is_repost = |
546 error.reason == net::ERR_CACHE_MISS && | 546 error.reason == net::ERR_CACHE_MISS && |
547 error.domain == WebString::fromUTF8(net::kErrorDomain) && | 547 error.domain == WebString::fromUTF8(net::kErrorDomain) && |
548 EqualsASCII(failed_request.httpMethod(), "POST"); | 548 EqualsASCII(failed_request.httpMethod(), "POST"); |
549 | 549 |
550 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) { | 550 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) { |
551 extension = extension_dispatcher_->extensions()->GetByURL( | 551 extension = extension_dispatcher_->extensions()->GetExtensionOrAppByURL( |
552 ExtensionURLInfo(failed_url)); | 552 ExtensionURLInfo(failed_url)); |
553 } | 553 } |
554 | 554 |
555 if (error_html) { | 555 if (error_html) { |
556 // Use a local error page. | 556 // Use a local error page. |
557 int resource_id; | 557 int resource_id; |
558 DictionaryValue error_strings; | 558 DictionaryValue error_strings; |
559 if (extension) { | 559 if (extension) { |
560 LocalizedError::GetAppErrorStrings(error, failed_url, extension, | 560 LocalizedError::GetAppErrorStrings(error, failed_url, extension, |
561 &error_strings); | 561 &error_strings); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 // which means that things like the back button won't trigger it. Is that | 610 // which means that things like the back button won't trigger it. Is that |
611 // OK? | 611 // OK? |
612 if (CrossesExtensionExtents(frame, url, is_initial_navigation)) { | 612 if (CrossesExtensionExtents(frame, url, is_initial_navigation)) { |
613 // Include the referrer in this case since we're going from a hosted web | 613 // Include the referrer in this case since we're going from a hosted web |
614 // page. (the packaged case is handled previously by the extension | 614 // page. (the packaged case is handled previously by the extension |
615 // navigation test) | 615 // navigation test) |
616 *send_referrer = true; | 616 *send_referrer = true; |
617 | 617 |
618 if (is_content_initiated) { | 618 if (is_content_initiated) { |
619 const Extension* extension = | 619 const Extension* extension = |
620 extension_dispatcher_->extensions()->GetByURL(ExtensionURLInfo(url)); | 620 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( |
| 621 ExtensionURLInfo(url)); |
621 if (extension && extension->is_app()) { | 622 if (extension && extension->is_app()) { |
622 UMA_HISTOGRAM_ENUMERATION( | 623 UMA_HISTOGRAM_ENUMERATION( |
623 extension_misc::kAppLaunchHistogram, | 624 extension_misc::kAppLaunchHistogram, |
624 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION, | 625 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION, |
625 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 626 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
626 } | 627 } |
627 } | 628 } |
628 return true; | 629 return true; |
629 } | 630 } |
630 | 631 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 } | 728 } |
728 | 729 |
729 void ChromeContentRendererClient::SetExtensionDispatcher( | 730 void ChromeContentRendererClient::SetExtensionDispatcher( |
730 ExtensionDispatcher* extension_dispatcher) { | 731 ExtensionDispatcher* extension_dispatcher) { |
731 extension_dispatcher_.reset(extension_dispatcher); | 732 extension_dispatcher_.reset(extension_dispatcher); |
732 } | 733 } |
733 | 734 |
734 const Extension* ChromeContentRendererClient::GetNonBookmarkAppExtension( | 735 const Extension* ChromeContentRendererClient::GetNonBookmarkAppExtension( |
735 const ExtensionSet* extensions, const GURL& url) { | 736 const ExtensionSet* extensions, const GURL& url) { |
736 // Exclude bookmark apps, which do not use the app process model. | 737 // Exclude bookmark apps, which do not use the app process model. |
737 const Extension* extension = extensions->GetByURL(ExtensionURLInfo(url)); | 738 const Extension* extension = extensions->GetExtensionOrAppByURL( |
| 739 ExtensionURLInfo(url)); |
738 if (extension && extension->from_bookmark()) | 740 if (extension && extension->from_bookmark()) |
739 extension = NULL; | 741 extension = NULL; |
740 return extension; | 742 return extension; |
741 } | 743 } |
742 | 744 |
743 bool ChromeContentRendererClient::CrossesExtensionExtents( | 745 bool ChromeContentRendererClient::CrossesExtensionExtents( |
744 WebFrame* frame, | 746 WebFrame* frame, |
745 const GURL& new_url, | 747 const GURL& new_url, |
746 bool is_initial_navigation) { | 748 bool is_initial_navigation) { |
747 const ExtensionSet* extensions = extension_dispatcher_->extensions(); | 749 const ExtensionSet* extensions = extension_dispatcher_->extensions(); |
748 GURL old_url(frame->top()->document().url()); | 750 GURL old_url(frame->top()->document().url()); |
749 | 751 |
750 // Determine if the new URL is an extension (excluding bookmark apps). | 752 // Determine if the new URL is an extension (excluding bookmark apps). |
751 const Extension* new_url_extension = GetNonBookmarkAppExtension(extensions, | 753 const Extension* new_url_extension = GetNonBookmarkAppExtension(extensions, |
752 new_url); | 754 new_url); |
753 | 755 |
754 // If old_url is still empty and this is an initial navigation, then this is | 756 // If old_url is still empty and this is an initial navigation, then this is |
755 // a window.open operation. We should look at the opener URL. | 757 // a window.open operation. We should look at the opener URL. |
756 if (is_initial_navigation && old_url.is_empty() && frame->opener()) { | 758 if (is_initial_navigation && old_url.is_empty() && frame->opener()) { |
757 // If we're about to open a normal web page from a same-origin opener stuck | 759 // If we're about to open a normal web page from a same-origin opener stuck |
758 // in an extension process, we want to keep it in process to allow the | 760 // in an extension process, we want to keep it in process to allow the |
759 // opener to script it. | 761 // opener to script it. |
760 WebDocument opener_document = frame->opener()->document(); | 762 WebDocument opener_document = frame->opener()->document(); |
761 GURL opener_url = opener_document.url(); | 763 GURL opener_url = opener_document.url(); |
762 WebSecurityOrigin opener_origin = opener_document.securityOrigin(); | 764 WebSecurityOrigin opener_origin = opener_document.securityOrigin(); |
763 bool opener_is_extension_url = !!extensions->GetByURL( | 765 bool opener_is_extension_url = !!extensions->GetExtensionOrAppByURL( |
764 ExtensionURLInfo(opener_origin, opener_url)); | 766 ExtensionURLInfo(opener_origin, opener_url)); |
765 WebSecurityOrigin opener = frame->opener()->document().securityOrigin(); | 767 WebSecurityOrigin opener = frame->opener()->document().securityOrigin(); |
766 if (!new_url_extension && | 768 if (!new_url_extension && |
767 !opener_is_extension_url && | 769 !opener_is_extension_url && |
768 extension_dispatcher_->is_extension_process() && | 770 extension_dispatcher_->is_extension_process() && |
769 opener.canRequest(WebURL(new_url))) | 771 opener.canRequest(WebURL(new_url))) |
770 return false; | 772 return false; |
771 | 773 |
772 // In all other cases, we want to compare against the top frame's URL (as | 774 // In all other cases, we want to compare against the top frame's URL (as |
773 // opposed to the opener frame's), since that's what determines the type of | 775 // opposed to the opener frame's), since that's what determines the type of |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) { | 832 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) { |
831 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory); | 833 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory); |
832 } | 834 } |
833 | 835 |
834 bool ChromeContentRendererClient::AllowSocketAPI(const GURL& url) { | 836 bool ChromeContentRendererClient::AllowSocketAPI(const GURL& url) { |
835 return allowed_socket_origins_.find(url.host()) != | 837 return allowed_socket_origins_.find(url.host()) != |
836 allowed_socket_origins_.end(); | 838 allowed_socket_origins_.end(); |
837 } | 839 } |
838 | 840 |
839 } // namespace chrome | 841 } // namespace chrome |
OLD | NEW |