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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 ChromeV8Context* current_context = | 613 ChromeV8Context* current_context = |
614 extension_dispatcher_->v8_context_set().GetCurrent(); | 614 extension_dispatcher_->v8_context_set().GetCurrent(); |
615 return current_context && !current_context->extension_id().empty(); | 615 return current_context && !current_context->extension_id().empty(); |
616 } | 616 } |
617 | 617 |
618 bool ChromeContentRendererClient::ShouldFork(WebFrame* frame, | 618 bool ChromeContentRendererClient::ShouldFork(WebFrame* frame, |
619 const GURL& url, | 619 const GURL& url, |
620 bool is_content_initiated, | 620 bool is_content_initiated, |
621 bool is_initial_navigation, | 621 bool is_initial_navigation, |
622 bool* send_referrer) { | 622 bool* send_referrer) { |
623 const ExtensionSet* extensions = extension_dispatcher_->extensions(); | |
624 | |
625 // Determine if the new URL is an extension (excluding bookmark apps). | |
626 const Extension* new_url_extension = extensions::GetNonBookmarkAppExtension( | |
627 *extensions, ExtensionURLInfo(url)); | |
628 bool is_extension_url = !!new_url_extension; | |
629 | |
623 // If the navigation would cross an app extent boundary, we also need | 630 // If the navigation would cross an app extent boundary, we also need |
624 // to defer to the browser to ensure process isolation. | 631 // to defer to the browser to ensure process isolation. |
625 // TODO(erikkay) This is happening inside of a check to is_content_initiated | 632 // TODO(erikkay) This is happening inside of a check to is_content_initiated |
626 // which means that things like the back button won't trigger it. Is that | 633 // which means that things like the back button won't trigger it. Is that |
627 // OK? | 634 // OK? |
628 if (CrossesExtensionExtents(frame, url, is_initial_navigation)) { | 635 if (CrossesExtensionExtents(frame, url, *extensions, is_extension_url, |
636 is_initial_navigation)) { | |
629 // Include the referrer in this case since we're going from a hosted web | 637 // Include the referrer in this case since we're going from a hosted web |
630 // page. (the packaged case is handled previously by the extension | 638 // page. (the packaged case is handled previously by the extension |
631 // navigation test) | 639 // navigation test) |
632 *send_referrer = true; | 640 *send_referrer = true; |
633 | 641 |
634 if (is_content_initiated) { | 642 if (is_content_initiated) { |
635 const Extension* extension = | 643 const Extension* extension = |
636 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( | 644 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( |
637 ExtensionURLInfo(url)); | 645 ExtensionURLInfo(url)); |
638 if (extension && extension->is_app()) { | 646 if (extension && extension->is_app()) { |
639 UMA_HISTOGRAM_ENUMERATION( | 647 UMA_HISTOGRAM_ENUMERATION( |
640 extension_misc::kAppLaunchHistogram, | 648 extension_misc::kAppLaunchHistogram, |
641 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION, | 649 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION, |
642 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 650 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
643 } | 651 } |
644 } | 652 } |
645 return true; | 653 return true; |
646 } | 654 } |
647 | 655 |
656 // If this is a reload, check whether it has the wrong process type. We | |
657 // should send it to the browser if it's an extension URL (e.g., hosted app) | |
darin (slow to review)
2012/01/30 22:14:48
nit: hosted apps don't use extension URLs, so I'm
Charlie Reis
2012/01/30 22:21:56
The effective URL of a hosted app is actually an e
| |
658 // in a normal process, or if it's a process for an extension that has been | |
659 // uninstalled. | |
660 if (frame->top()->document().url() == url) { | |
661 if (is_extension_url != extension_dispatcher_->is_extension_process()) | |
662 return true; | |
663 } | |
664 | |
648 // Navigating to a new chrome:// scheme (in a new tab) from within a | 665 // Navigating to a new chrome:// scheme (in a new tab) from within a |
649 // chrome:// page must be a browser navigation so that the browser can | 666 // chrome:// page must be a browser navigation so that the browser can |
650 // register the new associated data source. | 667 // register the new associated data source. |
651 if (is_content_initiated && url.SchemeIs(kChromeUIScheme)) | 668 if (is_content_initiated && url.SchemeIs(kChromeUIScheme)) |
652 return true; | 669 return true; |
653 | 670 |
654 return false; | 671 return false; |
655 } | 672 } |
656 | 673 |
657 bool ChromeContentRendererClient::WillSendRequest(WebKit::WebFrame* frame, | 674 bool ChromeContentRendererClient::WillSendRequest(WebKit::WebFrame* frame, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 } | 758 } |
742 | 759 |
743 void ChromeContentRendererClient::SetExtensionDispatcher( | 760 void ChromeContentRendererClient::SetExtensionDispatcher( |
744 ExtensionDispatcher* extension_dispatcher) { | 761 ExtensionDispatcher* extension_dispatcher) { |
745 extension_dispatcher_.reset(extension_dispatcher); | 762 extension_dispatcher_.reset(extension_dispatcher); |
746 } | 763 } |
747 | 764 |
748 bool ChromeContentRendererClient::CrossesExtensionExtents( | 765 bool ChromeContentRendererClient::CrossesExtensionExtents( |
749 WebFrame* frame, | 766 WebFrame* frame, |
750 const GURL& new_url, | 767 const GURL& new_url, |
768 const ExtensionSet& extensions, | |
769 bool is_extension_url, | |
751 bool is_initial_navigation) { | 770 bool is_initial_navigation) { |
752 const ExtensionSet* extensions = extension_dispatcher_->extensions(); | |
753 GURL old_url(frame->top()->document().url()); | 771 GURL old_url(frame->top()->document().url()); |
754 | 772 |
755 // Determine if the new URL is an extension (excluding bookmark apps). | |
756 const Extension* new_url_extension = extensions::GetNonBookmarkAppExtension( | |
757 *extensions, ExtensionURLInfo(new_url)); | |
758 | |
759 // If old_url is still empty and this is an initial navigation, then this is | 773 // If old_url is still empty and this is an initial navigation, then this is |
760 // a window.open operation. We should look at the opener URL. | 774 // a window.open operation. We should look at the opener URL. |
761 if (is_initial_navigation && old_url.is_empty() && frame->opener()) { | 775 if (is_initial_navigation && old_url.is_empty() && frame->opener()) { |
762 // If we're about to open a normal web page from a same-origin opener stuck | 776 // If we're about to open a normal web page from a same-origin opener stuck |
763 // in an extension process, we want to keep it in process to allow the | 777 // in an extension process, we want to keep it in process to allow the |
764 // opener to script it. | 778 // opener to script it. |
765 WebDocument opener_document = frame->opener()->document(); | 779 WebDocument opener_document = frame->opener()->document(); |
766 GURL opener_url = opener_document.url(); | 780 GURL opener_url = opener_document.url(); |
767 WebSecurityOrigin opener_origin = opener_document.securityOrigin(); | 781 WebSecurityOrigin opener_origin = opener_document.securityOrigin(); |
768 bool opener_is_extension_url = !!extensions->GetExtensionOrAppByURL( | 782 bool opener_is_extension_url = !!extensions.GetExtensionOrAppByURL( |
769 ExtensionURLInfo(opener_origin, opener_url)); | 783 ExtensionURLInfo(opener_origin, opener_url)); |
770 WebSecurityOrigin opener = frame->opener()->document().securityOrigin(); | 784 WebSecurityOrigin opener = frame->opener()->document().securityOrigin(); |
771 if (!new_url_extension && | 785 if (!is_extension_url && |
772 !opener_is_extension_url && | 786 !opener_is_extension_url && |
773 extension_dispatcher_->is_extension_process() && | 787 extension_dispatcher_->is_extension_process() && |
774 opener.canRequest(WebURL(new_url))) | 788 opener.canRequest(WebURL(new_url))) |
775 return false; | 789 return false; |
776 | 790 |
777 // In all other cases, we want to compare against the top frame's URL (as | 791 // In all other cases, we want to compare against the top frame's URL (as |
778 // opposed to the opener frame's), since that's what determines the type of | 792 // opposed to the opener frame's), since that's what determines the type of |
779 // process. This allows iframes outside an app to open a popup in the app. | 793 // process. This allows iframes outside an app to open a popup in the app. |
780 old_url = frame->top()->opener()->top()->document().url(); | 794 old_url = frame->top()->opener()->top()->document().url(); |
781 } | 795 } |
782 | 796 |
783 return extensions::CrossesExtensionProcessBoundary( | 797 return extensions::CrossesExtensionProcessBoundary( |
784 *extensions, ExtensionURLInfo(old_url), ExtensionURLInfo(new_url)); | 798 extensions, ExtensionURLInfo(old_url), ExtensionURLInfo(new_url)); |
785 } | 799 } |
786 | 800 |
787 void ChromeContentRendererClient::OnPurgeMemory() { | 801 void ChromeContentRendererClient::OnPurgeMemory() { |
788 DVLOG(1) << "Resetting spellcheck in renderer client"; | 802 DVLOG(1) << "Resetting spellcheck in renderer client"; |
789 RenderThread* thread = RenderThread::Get(); | 803 RenderThread* thread = RenderThread::Get(); |
790 if (spellcheck_.get()) | 804 if (spellcheck_.get()) |
791 thread->RemoveObserver(spellcheck_.get()); | 805 thread->RemoveObserver(spellcheck_.get()); |
792 spellcheck_.reset(new SpellCheck()); | 806 spellcheck_.reset(new SpellCheck()); |
793 thread->AddObserver(spellcheck_.get()); | 807 thread->AddObserver(spellcheck_.get()); |
794 } | 808 } |
(...skipping 24 matching lines...) Expand all Loading... | |
819 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) { | 833 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) { |
820 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory); | 834 factory_manager->RegisterFactory(ChromePPAPIInterfaceFactory); |
821 } | 835 } |
822 | 836 |
823 bool ChromeContentRendererClient::AllowSocketAPI(const GURL& url) { | 837 bool ChromeContentRendererClient::AllowSocketAPI(const GURL& url) { |
824 return allowed_socket_origins_.find(url.host()) != | 838 return allowed_socket_origins_.find(url.host()) != |
825 allowed_socket_origins_.end(); | 839 allowed_socket_origins_.end(); |
826 } | 840 } |
827 | 841 |
828 } // namespace chrome | 842 } // namespace chrome |
OLD | NEW |