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

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

Issue 280403002: Only commit cookie changes in prerenders after a prerender is shown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: fix sync related bug Created 6 years, 7 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 <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 21 matching lines...) Expand all
32 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/render_frame_host.h" 33 #include "content/public/browser/render_frame_host.h"
34 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
35 #include "content/public/browser/render_view_host.h" 35 #include "content/public/browser/render_view_host.h"
36 #include "content/public/browser/resource_request_details.h" 36 #include "content/public/browser/resource_request_details.h"
37 #include "content/public/browser/session_storage_namespace.h" 37 #include "content/public/browser/session_storage_namespace.h"
38 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
39 #include "content/public/browser/web_contents_delegate.h" 39 #include "content/public/browser/web_contents_delegate.h"
40 #include "content/public/common/frame_navigate_params.h" 40 #include "content/public/common/frame_navigate_params.h"
41 #include "content/public/common/page_transition_types.h" 41 #include "content/public/common/page_transition_types.h"
42 #include "net/url_request/url_request_context_getter.h"
42 #include "ui/gfx/rect.h" 43 #include "ui/gfx/rect.h"
43 44
45 using content::BrowserThread;
44 using content::DownloadItem; 46 using content::DownloadItem;
45 using content::OpenURLParams; 47 using content::OpenURLParams;
46 using content::RenderViewHost; 48 using content::RenderViewHost;
47 using content::ResourceRedirectDetails; 49 using content::ResourceRedirectDetails;
48 using content::SessionStorageNamespace; 50 using content::SessionStorageNamespace;
49 using content::WebContents; 51 using content::WebContents;
50 52
51 namespace prerender { 53 namespace prerender {
52 54
53 namespace { 55 namespace {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 PrerenderManager* prerender_manager = PrerenderManagerFactory::GetForProfile( 286 PrerenderManager* prerender_manager = PrerenderManagerFactory::GetForProfile(
285 Profile::FromBrowserContext(web_contents->GetBrowserContext())); 287 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
286 if (!prerender_manager) 288 if (!prerender_manager)
287 return NULL; 289 return NULL;
288 return prerender_manager->GetPrerenderContents(web_contents); 290 return prerender_manager->GetPrerenderContents(web_contents);
289 } 291 }
290 292
291 void PrerenderContents::StartPrerendering( 293 void PrerenderContents::StartPrerendering(
292 int creator_child_id, 294 int creator_child_id,
293 const gfx::Size& size, 295 const gfx::Size& size,
294 SessionStorageNamespace* session_storage_namespace) { 296 SessionStorageNamespace* session_storage_namespace,
297 net::URLRequestContextGetter* request_context) {
295 DCHECK(profile_ != NULL); 298 DCHECK(profile_ != NULL);
296 DCHECK(!size.IsEmpty()); 299 DCHECK(!size.IsEmpty());
297 DCHECK(!prerendering_has_started_); 300 DCHECK(!prerendering_has_started_);
298 DCHECK(prerender_contents_.get() == NULL); 301 DCHECK(prerender_contents_.get() == NULL);
299 DCHECK_EQ(-1, creator_child_id_); 302 DCHECK_EQ(-1, creator_child_id_);
300 DCHECK(size_.IsEmpty()); 303 DCHECK(size_.IsEmpty());
301 DCHECK_EQ(1U, alias_urls_.size()); 304 DCHECK_EQ(1U, alias_urls_.size());
302 305
303 creator_child_id_ = creator_child_id; 306 creator_child_id_ = creator_child_id;
304 session_storage_namespace_id_ = session_storage_namespace->id(); 307 session_storage_namespace_id_ = session_storage_namespace->id();
(...skipping 27 matching lines...) Expand all
332 // Set the size of the prerender WebContents. 335 // Set the size of the prerender WebContents.
333 apps::ResizeWebContents(prerender_contents_.get(), size_); 336 apps::ResizeWebContents(prerender_contents_.get(), size_);
334 337
335 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); 338 child_id_ = GetRenderViewHost()->GetProcess()->GetID();
336 route_id_ = GetRenderViewHost()->GetRoutingID(); 339 route_id_ = GetRenderViewHost()->GetRoutingID();
337 340
338 // Log transactions to see if we could merge session storage namespaces in 341 // Log transactions to see if we could merge session storage namespaces in
339 // the event of a mismatch. 342 // the event of a mismatch.
340 alias_session_storage_namespace->AddTransactionLogProcessId(child_id_); 343 alias_session_storage_namespace->AddTransactionLogProcessId(child_id_);
341 344
345 // Add the RenderProcessHost to the Prerender Manager.
346 prerender_manager()->AddPrerenderProcessHost(
347 GetRenderViewHost()->GetProcess());
348
349 // In the prerender tracker, create a Prerender Cookie Store to keep track of
350 // cookie changes performed by the prerender. Once the prerender is shown,
351 // the cookie changes will be committed to the actual cookie store,
352 // otherwise, they will be discarded.
353 BrowserThread::PostTask(
354 BrowserThread::IO, FROM_HERE,
355 base::Bind(&PrerenderTracker::AddPrerenderCookieStoreOnIOThread,
356 base::Unretained(prerender_manager()->prerender_tracker()),
357 GetRenderViewHost()->GetProcess()->GetID(),
358 make_scoped_refptr(request_context),
359 base::Bind(&PrerenderContents::Destroy,
360 AsWeakPtr(),
361 FINAL_STATUS_COOKIE_CONFLICT)));
362
342 NotifyPrerenderStart(); 363 NotifyPrerenderStart();
343 364
344 // Close ourselves when the application is shutting down. 365 // Close ourselves when the application is shutting down.
345 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, 366 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
346 content::NotificationService::AllSources()); 367 content::NotificationService::AllSources());
347 368
348 // Register to inform new RenderViews that we're prerendering. 369 // Register to inform new RenderViews that we're prerendering.
349 notification_registrar_.Add( 370 notification_registrar_.Add(
350 this, content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, 371 this, content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
351 content::Source<WebContents>(prerender_contents_.get())); 372 content::Source<WebContents>(prerender_contents_.get()));
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 void PrerenderContents::PrepareForUse() { 810 void PrerenderContents::PrepareForUse() {
790 SetFinalStatus(FINAL_STATUS_USED); 811 SetFinalStatus(FINAL_STATUS_USED);
791 812
792 if (prerender_contents_.get()) { 813 if (prerender_contents_.get()) {
793 prerender_contents_->SendToAllFrames( 814 prerender_contents_->SendToAllFrames(
794 new PrerenderMsg_SetIsPrerendering(MSG_ROUTING_NONE, false)); 815 new PrerenderMsg_SetIsPrerendering(MSG_ROUTING_NONE, false));
795 } 816 }
796 817
797 NotifyPrerenderStop(); 818 NotifyPrerenderStop();
798 819
799 content::BrowserThread::PostTask( 820 BrowserThread::PostTask(
800 content::BrowserThread::IO, 821 BrowserThread::IO,
801 FROM_HERE, 822 FROM_HERE,
802 base::Bind(&ResumeThrottles, resource_throttles_)); 823 base::Bind(&ResumeThrottles, resource_throttles_));
803 resource_throttles_.clear(); 824 resource_throttles_.clear();
804 } 825 }
805 826
806 SessionStorageNamespace* PrerenderContents::GetSessionStorageNamespace() const { 827 SessionStorageNamespace* PrerenderContents::GetSessionStorageNamespace() const {
807 if (!prerender_contents()) 828 if (!prerender_contents())
808 return NULL; 829 return NULL;
809 return prerender_contents()->GetController(). 830 return prerender_contents()->GetController().
810 GetDefaultSessionStorageNamespace(); 831 GetDefaultSessionStorageNamespace();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 void PrerenderContents::AddResourceThrottle( 899 void PrerenderContents::AddResourceThrottle(
879 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { 900 const base::WeakPtr<PrerenderResourceThrottle>& throttle) {
880 resource_throttles_.push_back(throttle); 901 resource_throttles_.push_back(throttle);
881 } 902 }
882 903
883 void PrerenderContents::AddNetworkBytes(int64 bytes) { 904 void PrerenderContents::AddNetworkBytes(int64 bytes) {
884 network_bytes_ += bytes; 905 network_bytes_ += bytes;
885 } 906 }
886 907
887 } // namespace prerender 908 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_contents.h ('k') | chrome/browser/prerender/prerender_cookie_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698