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