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
3 // found in the LICENSE file.
5 #include "chrome/renderer/prerender/prerender_helper.h"
7 #include "base/metrics/field_trial.h"
8 #include "base/metrics/histogram.h"
9 #include "chrome/common/prerender_messages.h"
10 #include "content/public/renderer/document_state.h"
11 #include "content/public/renderer/render_view.h"
12 #include "third_party/WebKit/public/web/WebFrame.h"
13 #include "third_party/WebKit/public/web/WebView.h"
15 using content::DocumentState
;
19 // Updates the visibility state of the RenderView. Must be called whenever
20 // prerendering starts or finishes and the page is about to be show. At both
21 // those times, the RenderView is hidden.
22 void UpdateVisibilityState(content::RenderView
* render_view
) {
23 if (render_view
->GetWebView()) {
24 render_view
->GetWebView()->setVisibilityState(
25 render_view
->GetVisibilityState(), false);
33 PrerenderHelper::PrerenderHelper(content::RenderView
* render_view
)
34 : content::RenderViewObserver(render_view
),
35 content::RenderViewObserverTracker
<PrerenderHelper
>(render_view
) {
36 UpdateVisibilityState(render_view
);
39 PrerenderHelper::~PrerenderHelper() {
43 bool PrerenderHelper::IsPrerendering(const content::RenderView
* render_view
) {
44 return PrerenderHelper::Get(render_view
) != NULL
;
47 bool PrerenderHelper::OnMessageReceived(
48 const IPC::Message
& message
) {
49 IPC_BEGIN_MESSAGE_MAP(PrerenderHelper
, message
)
50 IPC_MESSAGE_HANDLER(PrerenderMsg_SetIsPrerendering
, OnSetIsPrerendering
)
52 // Return false on ViewMsg_SetIsPrerendering so other observers can see the
57 void PrerenderHelper::OnSetIsPrerendering(bool is_prerendering
) {
58 // Immediately after construction, |this| may receive the message that
59 // triggered its creation. If so, ignore it.
63 content::RenderView
* view
= render_view();
64 // |this| must be deleted so PrerenderHelper::IsPrerendering returns false
65 // when the visibility state is updated, so the visibility state string will
66 // not be "prerendered".
69 UpdateVisibilityState(view
);
72 } // namespace prerender