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

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

Issue 6685012: Give prerendering RVH's RenderWidgetHostViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Sync to trunk Created 9 years, 8 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/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include "base/process_util.h" 7 #include "base/process_util.h"
8 #include "base/task.h" 8 #include "base/task.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/background_contents_service.h" 10 #include "chrome/browser/background_contents_service.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/prerender/prerender_final_status.h" 12 #include "chrome/browser/prerender/prerender_final_status.h"
13 #include "chrome/browser/prerender/prerender_manager.h" 13 #include "chrome/browser/prerender/prerender_manager.h"
14 #include "chrome/browser/prerender/prerender_render_widget_host_view.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/renderer_preferences_util.h" 16 #include "chrome/browser/renderer_preferences_util.h"
16 #include "chrome/browser/ui/login/login_prompt.h" 17 #include "chrome/browser/ui/login/login_prompt.h"
17 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/icon_messages.h" 19 #include "chrome/common/icon_messages.h"
19 #include "chrome/common/render_messages.h" 20 #include "chrome/common/render_messages.h"
20 #include "chrome/common/extensions/extension_messages.h" 21 #include "chrome/common/extensions/extension_messages.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "chrome/common/view_types.h" 23 #include "chrome/common/view_types.h"
23 #include "content/browser/browsing_instance.h" 24 #include "content/browser/browsing_instance.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (!AddAliasURL(*it)) 81 if (!AddAliasURL(*it))
81 LOG(DFATAL) << "PrerenderContents given invalid URL " << prerender_url_; 82 LOG(DFATAL) << "PrerenderContents given invalid URL " << prerender_url_;
82 } 83 }
83 } 84 }
84 85
85 // static 86 // static
86 PrerenderContents::Factory* PrerenderContents::CreateFactory() { 87 PrerenderContents::Factory* PrerenderContents::CreateFactory() {
87 return new PrerenderContentsFactoryImpl(); 88 return new PrerenderContentsFactoryImpl();
88 } 89 }
89 90
90 void PrerenderContents::StartPrerendering() { 91 void PrerenderContents::StartPrerendering(
92 const RenderViewHost* source_render_view_host) {
91 DCHECK(profile_ != NULL); 93 DCHECK(profile_ != NULL);
92 DCHECK(!prerendering_has_started_); 94 DCHECK(!prerendering_has_started_);
95 DCHECK(source_render_view_host != NULL);
96 DCHECK(source_render_view_host->view() != NULL);
93 prerendering_has_started_ = true; 97 prerendering_has_started_ = true;
94 SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile_); 98 SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile_);
95 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, 99 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE,
96 NULL); 100 NULL);
97 101
98 int process_id = render_view_host_->process()->id(); 102 int process_id = render_view_host_->process()->id();
99 int view_id = render_view_host_->routing_id(); 103 int view_id = render_view_host_->routing_id();
100 std::pair<int, int> process_view_pair = std::make_pair(process_id, view_id); 104 std::pair<int, int> process_view_pair = std::make_pair(process_id, view_id);
101 NotificationService::current()->Notify( 105 NotificationService::current()->Notify(
102 NotificationType::PRERENDER_CONTENTS_STARTED, 106 NotificationType::PRERENDER_CONTENTS_STARTED,
103 Source<std::pair<int, int> >(&process_view_pair), 107 Source<std::pair<int, int> >(&process_view_pair),
104 NotificationService::NoDetails()); 108 NotificationService::NoDetails());
105 109
106 // Create the RenderView, so it can receive messages. 110 // Create the RenderView, so it can receive messages.
107 render_view_host_->CreateRenderView(string16()); 111 render_view_host_->CreateRenderView(string16());
108 112
109 // Hide the RVH, so that we will run at a lower CPU priority. 113 // Give the RVH a PrerenderRenderWidgetHostView, both so its size can be set
110 // Once the RVH is being swapped into a tab, we will Restore it again. 114 // and so that the prerender can be cancelled under certain circumstances.
111 render_view_host_->WasHidden(); 115 PrerenderRenderWidgetHostView* view =
116 new PrerenderRenderWidgetHostView(render_view_host_, this);
117 view->Init(source_render_view_host->view());
118
112 119
113 // Register this with the ResourceDispatcherHost as a prerender 120 // Register this with the ResourceDispatcherHost as a prerender
114 // RenderViewHost. This must be done before the Navigate message to catch all 121 // RenderViewHost. This must be done before the Navigate message to catch all
115 // resource requests, but as it is on the same thread as the Navigate message 122 // resource requests, but as it is on the same thread as the Navigate message
116 // (IO) there is no race condition. 123 // (IO) there is no race condition.
117 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); 124 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host();
118 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 125 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
119 NewRunnableFunction(&AddChildRoutePair, rdh, 126 NewRunnableFunction(&AddChildRoutePair, rdh,
120 process_id, view_id)); 127 process_id, view_id));
121 128
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return; 556 return;
550 557
551 size_t private_bytes, shared_bytes; 558 size_t private_bytes, shared_bytes;
552 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { 559 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) {
553 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024) 560 if (private_bytes > kMaxPrerenderPrivateMB * 1024 * 1024)
554 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); 561 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
555 } 562 }
556 } 563 }
557 564
558 } // namespace prerender 565 } // 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