Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 7624011: Keep normal popups opened from same-origin iframes in an extension process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to canRequest. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "content/renderer/render_view.h" 65 #include "content/renderer/render_view.h"
66 #include "grit/generated_resources.h" 66 #include "grit/generated_resources.h"
67 #include "grit/locale_settings.h" 67 #include "grit/locale_settings.h"
68 #include "grit/renderer_resources.h" 68 #include "grit/renderer_resources.h"
69 #include "net/base/net_errors.h" 69 #include "net/base/net_errors.h"
70 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" 70 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
71 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 71 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
72 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 72 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
73 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 73 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
74 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" 74 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
75 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
75 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" 78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
79 #include "ui/base/l10n/l10n_util.h" 80 #include "ui/base/l10n/l10n_util.h"
80 #include "ui/base/resource/resource_bundle.h" 81 #include "ui/base/resource/resource_bundle.h"
81 #include "webkit/plugins/npapi/plugin_list.h" 82 #include "webkit/plugins/npapi/plugin_list.h"
82 #include "webkit/plugins/ppapi/plugin_module.h" 83 #include "webkit/plugins/ppapi/plugin_module.h"
83 84
84 using autofill::AutofillAgent; 85 using autofill::AutofillAgent;
85 using autofill::FormManager; 86 using autofill::FormManager;
86 using autofill::PasswordAutofillManager; 87 using autofill::PasswordAutofillManager;
87 using WebKit::WebCache; 88 using WebKit::WebCache;
88 using WebKit::WebDataSource; 89 using WebKit::WebDataSource;
89 using WebKit::WebFrame; 90 using WebKit::WebFrame;
90 using WebKit::WebPlugin; 91 using WebKit::WebPlugin;
91 using WebKit::WebPluginParams; 92 using WebKit::WebPluginParams;
93 using WebKit::WebSecurityOrigin;
92 using WebKit::WebSecurityPolicy; 94 using WebKit::WebSecurityPolicy;
93 using WebKit::WebString; 95 using WebKit::WebString;
96 using WebKit::WebURL;
94 using WebKit::WebURLError; 97 using WebKit::WebURLError;
95 using WebKit::WebURLRequest; 98 using WebKit::WebURLRequest;
96 using WebKit::WebURLResponse; 99 using WebKit::WebURLResponse;
97 using WebKit::WebVector; 100 using WebKit::WebVector;
98 101
99 namespace { 102 namespace {
100 103
101 const char* kNaClPluginMimeType = "application/x-nacl"; 104 const char* kNaClPluginMimeType = "application/x-nacl";
102 const char* kNaClPluginManifestAttribute = "nacl"; 105 const char* kNaClPluginManifestAttribute = "nacl";
103 106
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 bool ChromeContentRendererClient::AllowPopup(const GURL& creator) { 569 bool ChromeContentRendererClient::AllowPopup(const GURL& creator) {
567 // Extensions and apps always allowed to create unrequested popups. The second 570 // Extensions and apps always allowed to create unrequested popups. The second
568 // check is necessary to include content scripts. 571 // check is necessary to include content scripts.
569 return extension_dispatcher_->extensions()->GetByURL(creator) || 572 return extension_dispatcher_->extensions()->GetByURL(creator) ||
570 bindings_utils::GetInfoForCurrentContext(); 573 bindings_utils::GetInfoForCurrentContext();
571 } 574 }
572 575
573 bool ChromeContentRendererClient::ShouldFork(WebFrame* frame, 576 bool ChromeContentRendererClient::ShouldFork(WebFrame* frame,
574 const GURL& url, 577 const GURL& url,
575 bool is_content_initiated, 578 bool is_content_initiated,
579 bool is_initial_navigation,
576 bool* send_referrer) { 580 bool* send_referrer) {
577 // If the navigation would cross an app extent boundary, we also need 581 // If the navigation would cross an app extent boundary, we also need
578 // to defer to the browser to ensure process isolation. 582 // to defer to the browser to ensure process isolation.
579 // TODO(erikkay) This is happening inside of a check to is_content_initiated 583 // TODO(erikkay) This is happening inside of a check to is_content_initiated
580 // which means that things like the back button won't trigger it. Is that 584 // which means that things like the back button won't trigger it. Is that
581 // OK? 585 // OK?
582 if (!CrossesExtensionExtents(frame, url)) 586 if (!CrossesExtensionExtents(frame, url, is_initial_navigation))
583 return false; 587 return false;
584 588
585 // Include the referrer in this case since we're going from a hosted web 589 // Include the referrer in this case since we're going from a hosted web
586 // page. (the packaged case is handled previously by the extension 590 // page. (the packaged case is handled previously by the extension
587 // navigation test) 591 // navigation test)
588 *send_referrer = true; 592 *send_referrer = true;
589 593
590 if (is_content_initiated) { 594 if (is_content_initiated) {
591 const Extension* extension = 595 const Extension* extension =
592 extension_dispatcher_->extensions()->GetByURL(url); 596 extension_dispatcher_->extensions()->GetByURL(url);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 668
665 *override_state = WebKit::WebPageVisibilityStatePrerender; 669 *override_state = WebKit::WebPageVisibilityStatePrerender;
666 return true; 670 return true;
667 } 671 }
668 672
669 void ChromeContentRendererClient::SetExtensionDispatcher( 673 void ChromeContentRendererClient::SetExtensionDispatcher(
670 ExtensionDispatcher* extension_dispatcher) { 674 ExtensionDispatcher* extension_dispatcher) {
671 extension_dispatcher_.reset(extension_dispatcher); 675 extension_dispatcher_.reset(extension_dispatcher);
672 } 676 }
673 677
674 bool ChromeContentRendererClient::CrossesExtensionExtents(WebFrame* frame, 678 bool ChromeContentRendererClient::CrossesExtensionExtents(
675 const GURL& new_url) { 679 WebFrame* frame,
680 const GURL& new_url,
681 bool is_initial_navigation) {
676 const ExtensionSet* extensions = extension_dispatcher_->extensions(); 682 const ExtensionSet* extensions = extension_dispatcher_->extensions();
677 // If the URL is still empty, this is a window.open navigation. Check the 683 bool is_extension_url = !!extensions->GetByURL(new_url);
678 // opener's URL. In all cases we use the top frame's URL (as opposed to our
679 // frame's) since that's what determines the type of process.
680 // TODO(abarth): This code is super sketchy! Are you sure looking at the
681 // opener is correct here? This appears to let me steal my opener's
682 // privileges if I can make my URL be "empty."
683 GURL old_url(frame->top()->document().url()); 684 GURL old_url(frame->top()->document().url());
684 if (old_url.is_empty() && frame->opener()) 685
686 // If old_url is still empty and this is an initial navigation, then this is
687 // a window.open operation. We should look at the opener URL.
688 if (is_initial_navigation && old_url.is_empty() && frame->opener()) {
689 // If we're about to open a normal web page from a same-origin opener stuck
690 // in an extension process, we want to keep it in process to allow the
691 // opener to script it.
692 GURL opener_url = frame->opener()->document().url();
693 bool opener_is_extension_url = !!extensions->GetByURL(opener_url);
694 WebSecurityOrigin opener = frame->opener()->document().securityOrigin();
695 if (!is_extension_url &&
696 !opener_is_extension_url &&
697 extension_dispatcher_->is_extension_process() &&
698 opener.canRequest(WebURL(new_url)))
699 return false;
700
701 // In all other cases, we want to compare against the top frame's URL (as
702 // opposed to the opener frame's), since that's what determines the type of
703 // process. This allows iframes outside an app to open a popup in the app.
685 old_url = frame->top()->opener()->top()->document().url(); 704 old_url = frame->top()->opener()->top()->document().url();
705 }
686 706
687 // If this is a reload, check whether it has the wrong process type. We 707 // If this is a reload, check whether it has the wrong process type. We
688 // should send it to the browser if it's an extension URL (e.g., hosted app) 708 // should send it to the browser if it's an extension URL (e.g., hosted app)
689 // in a normal process, or if it's a process for an extension that has been 709 // in a normal process, or if it's a process for an extension that has been
690 // uninstalled. 710 // uninstalled.
691 if (old_url == new_url) { 711 if (old_url == new_url) {
692 bool is_extension_url = !!extensions->GetByURL(new_url);
693 if (is_extension_url != extension_dispatcher_->is_extension_process()) 712 if (is_extension_url != extension_dispatcher_->is_extension_process())
694 return true; 713 return true;
695 } 714 }
696 715
697 return !extensions->InSameExtent(old_url, new_url); 716 return !extensions->InSameExtent(old_url, new_url);
698 } 717 }
699 718
700 void ChromeContentRendererClient::OnPurgeMemory() { 719 void ChromeContentRendererClient::OnPurgeMemory() {
701 DVLOG(1) << "Resetting spellcheck in renderer client"; 720 DVLOG(1) << "Resetting spellcheck in renderer client";
702 RenderThread* thread = RenderThread::current(); 721 RenderThread* thread = RenderThread::current();
703 if (spellcheck_.get()) 722 if (spellcheck_.get())
704 thread->RemoveObserver(spellcheck_.get()); 723 thread->RemoveObserver(spellcheck_.get());
705 SpellCheck* new_spellcheck = new SpellCheck(); 724 SpellCheck* new_spellcheck = new SpellCheck();
706 if (spellcheck_provider_) 725 if (spellcheck_provider_)
707 spellcheck_provider_->SetSpellCheck(new_spellcheck); 726 spellcheck_provider_->SetSpellCheck(new_spellcheck);
708 spellcheck_.reset(new_spellcheck); 727 spellcheck_.reset(new_spellcheck);
709 thread->AddObserver(new_spellcheck); 728 thread->AddObserver(new_spellcheck);
710 } 729 }
711 730
712 } // namespace chrome 731 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698