Index: chrome/browser/prerender/prerender_contents.cc |
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc |
index d81dfcfd9fbbc3ea9b4d87e5a2a5857203bedb32..a6c4773b9178c99e4a4a49c50f8bfbed60c78d22 100644 |
--- a/chrome/browser/prerender/prerender_contents.cc |
+++ b/chrome/browser/prerender/prerender_contents.cc |
@@ -21,7 +21,7 @@ |
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/icon_messages.h" |
-#include "chrome/common/render_messages.h" |
+#include "chrome/common/prerender_messages.h" |
#include "chrome/common/url_constants.h" |
#include "content/browser/renderer_host/render_view_host.h" |
#include "content/browser/renderer_host/resource_request_details.h" |
@@ -61,6 +61,29 @@ struct PrerenderURLPredicate { |
GURL url_; |
}; |
+// Tells the render process at |child_id| whether |url| is a new prerendered |
+// page, or whether |url| is being removed as a prerendered page. Currently |
+// this will only inform the render process that created the prerendered page |
+// with <link rel="prerender"> tags about it. This means that if the user |
+// clicks on a link for a prerendered URL in a different page, the prerender |
+// will not be swapped in. |
Charlie Reis
2012/03/01 19:06:03
I think this is the right call. For reference, we
|
+void InformRenderProcessAboutPrerender(const GURL& url, |
+ bool is_add, |
+ int child_id) { |
+ if (child_id < 0) |
+ return; |
+ content::RenderProcessHost* render_process_host = |
+ content::RenderProcessHost::FromID(child_id); |
+ if (!render_process_host) |
+ return; |
+ IPC::Message* message = NULL; |
+ if (is_add) |
+ message = new PrerenderMsg_AddPrerenderURL(url); |
+ else |
+ message = new PrerenderMsg_RemovePrerenderURL(url); |
Charlie Reis
2012/03/01 19:06:03
Just as a sanity check, we don't need to be concer
cbentzel
2012/03/01 22:18:53
You are correct - there is not a race here.
I com
Charlie Reis
2012/03/01 22:24:38
That comment is sufficient, thanks. This file jus
|
+ render_process_host->Send(message); |
+} |
+ |
} // end namespace |
class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { |
@@ -227,7 +250,8 @@ PrerenderContents::PrerenderContents( |
child_id_(-1), |
route_id_(-1), |
origin_(origin), |
- experiment_id_(experiment_id) { |
+ experiment_id_(experiment_id), |
+ creator_child_id_(-1) { |
DCHECK(prerender_manager != NULL); |
} |
@@ -248,6 +272,12 @@ void PrerenderContents::StartPrerendering( |
DCHECK(prerender_contents_.get() == NULL); |
prerendering_has_started_ = true; |
+ DCHECK(creator_child_id_ == -1); |
+ if (source_render_view_host) |
+ creator_child_id_ = source_render_view_host->process()->GetID(); |
+ InformRenderProcessAboutPrerender(prerender_url_, true, |
+ creator_child_id_); |
+ |
WebContents* new_contents = WebContents::Create( |
profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); |
prerender_contents_.reset(new TabContentsWrapper(new_contents)); |
@@ -363,8 +393,10 @@ PrerenderContents::~PrerenderContents() { |
match_complete_status_, |
final_status_); |
- if (child_id_ != -1 && route_id_ != -1) |
+ if (child_id_ != -1 && route_id_ != -1) { |
prerender_tracker_->OnPrerenderingFinished(child_id_, route_id_); |
+ InformRenderProcessAboutPrerender(prerender_url_, false, creator_child_id_); |
+ } |
// If we still have a TabContents, clean up anything we need to and then |
// destroy it. |
@@ -419,7 +451,7 @@ void PrerenderContents::Observe(int type, |
// first navigation, so there's no need to send the message just after |
// the TabContents is created. |
new_render_view_host->Send( |
- new ChromeViewMsg_SetIsPrerendering( |
+ new PrerenderMsg_SetIsPrerendering( |
new_render_view_host->routing_id(), |
true)); |