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

Side by Side Diff: chrome/browser/prerender/prerender_contents.cc

Issue 10636034: Cancel prerender when a site tries to register a protocol handler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Change strings Created 8 years, 6 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) 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/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 // TabContentsDelegateImpl ----------------------------------------------------- 117 // TabContentsDelegateImpl -----------------------------------------------------
118 118
119 class PrerenderContents::TabContentsDelegateImpl 119 class PrerenderContents::TabContentsDelegateImpl
120 : public content::WebContentsDelegate { 120 : public content::WebContentsDelegate {
121 public: 121 public:
122 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) : 122 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) :
123 prerender_contents_(prerender_contents) { 123 prerender_contents_(prerender_contents) {
124 } 124 }
125 125
126 virtual WebContents* OpenURLFromTab(WebContents* source, 126 // content::WebContentsDelegate implementation:
127 virtual WebContents* OpenURLFromTab(WebContents* source,
127 const OpenURLParams& params) OVERRIDE { 128 const OpenURLParams& params) OVERRIDE {
128 // |OpenURLFromTab| is typically called when a frame performs a navigation 129 // |OpenURLFromTab| is typically called when a frame performs a navigation
129 // that requires the browser to perform the transition instead of WebKit. 130 // that requires the browser to perform the transition instead of WebKit.
130 // Examples include prerendering a site that redirects to an app URL, 131 // Examples include prerendering a site that redirects to an app URL,
131 // or if --enable-strict-site-isolation is specified and the prerendered 132 // or if --enable-strict-site-isolation is specified and the prerendered
132 // frame redirects to a different origin. 133 // frame redirects to a different origin.
133 // TODO(cbentzel): Consider supporting this is if it is a common case 134 // TODO(cbentzel): Consider supporting this if it is a common case during
134 // during prerenders. 135 // prerenders.
135 prerender_contents_->Destroy(FINAL_STATUS_OPEN_URL); 136 prerender_contents_->Destroy(FINAL_STATUS_OPEN_URL);
136 return NULL; 137 return NULL;
137 } 138 }
138 139
139 // content::WebContentsDelegate implementation:
140 virtual bool ShouldAddNavigationToHistory( 140 virtual bool ShouldAddNavigationToHistory(
141 const history::HistoryAddPageArgs& add_page_args, 141 const history::HistoryAddPageArgs& add_page_args,
142 content::NavigationType navigation_type) OVERRIDE { 142 content::NavigationType navigation_type) OVERRIDE {
143 add_page_vector_.push_back( 143 add_page_vector_.push_back(
144 scoped_refptr<history::HistoryAddPageArgs>(add_page_args.Clone())); 144 scoped_refptr<history::HistoryAddPageArgs>(add_page_args.Clone()));
145 return false; 145 return false;
146 } 146 }
147 147
148 virtual bool CanDownload(RenderViewHost* render_view_host, 148 virtual bool CanDownload(RenderViewHost* render_view_host,
149 int request_id, 149 int request_id,
(...skipping 24 matching lines...) Expand all
174 174
175 virtual bool OnGoToEntryOffset(int offset) OVERRIDE { 175 virtual bool OnGoToEntryOffset(int offset) OVERRIDE {
176 // This isn't allowed because the history merge operation 176 // This isn't allowed because the history merge operation
177 // does not work if there are renderer issued challenges. 177 // does not work if there are renderer issued challenges.
178 // TODO(cbentzel): Cancel in this case? May not need to do 178 // TODO(cbentzel): Cancel in this case? May not need to do
179 // since render-issued offset navigations are not guaranteed, 179 // since render-issued offset navigations are not guaranteed,
180 // but indicates that the page cares about the history. 180 // but indicates that the page cares about the history.
181 return false; 181 return false;
182 } 182 }
183 183
184 virtual void JSOutOfMemory(WebContents* tab) OVERRIDE { 184 virtual void JSOutOfMemory(WebContents* tab) OVERRIDE {
mmenke 2012/06/25 19:53:39 We should be consistent about whether we call dest
dominich 2012/06/25 19:59:27 I like this better.
185 prerender_contents_->OnJSOutOfMemory(); 185 prerender_contents_->Destroy(FINAL_STATUS_JS_OUT_OF_MEMORY);
186 } 186 }
187 187
188 virtual bool ShouldSuppressDialogs() OVERRIDE { 188 virtual bool ShouldSuppressDialogs() OVERRIDE {
189 return prerender_contents_->ShouldSuppressDialogs(); 189 // Always suppress JavaScript messages if they're triggered by a page being
190 // prerendered.
191 // We still want to show the user the message when they navigate to this
192 // page, so cancel this prerender.
193 prerender_contents_->Destroy(FINAL_STATUS_JAVASCRIPT_ALERT);
194 return true;
195 }
196
197 virtual void RegisterProtocolHandler(WebContents* web_contents,
198 const std::string& protocol,
199 const GURL& url,
200 const string16& title,
201 bool user_gesture) OVERRIDE {
202 // TODO(mmenke): Consider supporting this if it is a common case during
203 // prerenders.
204 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER);
190 } 205 }
191 206
192 // Commits the History of Pages to the given TabContents. 207 // Commits the History of Pages to the given TabContents.
193 void CommitHistory(TabContents* tab) { 208 void CommitHistory(TabContents* tab) {
194 for (size_t i = 0; i < add_page_vector_.size(); ++i) 209 for (size_t i = 0; i < add_page_vector_.size(); ++i)
195 tab->history_tab_helper()->UpdateHistoryForNavigation( 210 tab->history_tab_helper()->UpdateHistoryForNavigation(
196 add_page_vector_[i].get()); 211 add_page_vector_[i].get());
197 } 212 }
198 213
199 private: 214 private:
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 alias_urls_.end(), 575 alias_urls_.end(),
561 PrerenderURLPredicate(url)); 576 PrerenderURLPredicate(url));
562 if (matching_url_iterator != alias_urls_.end()) { 577 if (matching_url_iterator != alias_urls_.end()) {
563 if (matching_url) 578 if (matching_url)
564 *matching_url = *matching_url_iterator; 579 *matching_url = *matching_url_iterator;
565 return true; 580 return true;
566 } 581 }
567 return false; 582 return false;
568 } 583 }
569 584
570 void PrerenderContents::OnJSOutOfMemory() {
571 Destroy(FINAL_STATUS_JS_OUT_OF_MEMORY);
572 }
573
574 void PrerenderContents::RenderViewGone(base::TerminationStatus status) { 585 void PrerenderContents::RenderViewGone(base::TerminationStatus status) {
575 Destroy(FINAL_STATUS_RENDERER_CRASHED); 586 Destroy(FINAL_STATUS_RENDERER_CRASHED);
576 } 587 }
577 588
578 void PrerenderContents::DidStopLoading() { 589 void PrerenderContents::DidStopLoading() {
579 has_stopped_loading_ = true; 590 has_stopped_loading_ = true;
580 } 591 }
581 592
582 void PrerenderContents::DidStartProvisionalLoadForFrame( 593 void PrerenderContents::DidStartProvisionalLoadForFrame(
583 int64 frame_id, 594 int64 frame_id,
(...skipping 15 matching lines...) Expand all
599 } 610 }
600 } 611 }
601 612
602 void PrerenderContents::DidFinishLoad(int64 frame_id, 613 void PrerenderContents::DidFinishLoad(int64 frame_id,
603 const GURL& validated_url, 614 const GURL& validated_url,
604 bool is_main_frame) { 615 bool is_main_frame) {
605 if (is_main_frame) 616 if (is_main_frame)
606 has_finished_loading_ = true; 617 has_finished_loading_ = true;
607 } 618 }
608 619
609 bool PrerenderContents::ShouldSuppressDialogs() {
610 // Always suppress JavaScript messages if they're triggered by a page being
611 // prerendered.
612 // We still want to show the user the message when they navigate to this
613 // page, so cancel this prerender.
614 Destroy(FINAL_STATUS_JAVASCRIPT_ALERT);
615 return true;
616 }
617
618 void PrerenderContents::Destroy(FinalStatus final_status) { 620 void PrerenderContents::Destroy(FinalStatus final_status) {
619 if (prerendering_has_been_cancelled_) 621 if (prerendering_has_been_cancelled_)
620 return; 622 return;
621 623
622 if (child_id_ != -1 && route_id_ != -1) { 624 if (child_id_ != -1 && route_id_ != -1) {
623 // Cancel the prerender in the PrerenderTracker. This is needed 625 // Cancel the prerender in the PrerenderTracker. This is needed
624 // because destroy may be called directly from the UI thread without calling 626 // because destroy may be called directly from the UI thread without calling
625 // TryCancel(). This is difficult to completely avoid, since prerendering 627 // TryCancel(). This is difficult to completely avoid, since prerendering
626 // can be cancelled before a RenderView is created. 628 // can be cancelled before a RenderView is created.
627 bool is_cancelled = prerender_tracker_->TryCancel( 629 bool is_cancelled = prerender_tracker_->TryCancel(
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 bool PrerenderContents::IsCrossSiteNavigationPending() const { 725 bool PrerenderContents::IsCrossSiteNavigationPending() const {
724 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) 726 if (!prerender_contents_.get() || !prerender_contents_->web_contents())
725 return false; 727 return false;
726 const WebContents* web_contents = prerender_contents_->web_contents(); 728 const WebContents* web_contents = prerender_contents_->web_contents();
727 return (web_contents->GetSiteInstance() != 729 return (web_contents->GetSiteInstance() !=
728 web_contents->GetPendingSiteInstance()); 730 web_contents->GetPendingSiteInstance());
729 } 731 }
730 732
731 733
732 } // namespace prerender 734 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_contents.h ('k') | chrome/browser/prerender/prerender_final_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698