summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prerender/prerender_render_view_host_observer.cc
blob: 7a5d168725f2a604354daec4069f48e25a30f04e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/prerender/prerender_render_view_host_observer.h"

#include "chrome/browser/prerender/prerender_contents.h"
#include "chrome/common/icon_messages.h"
#include "chrome/common/render_messages.h"

namespace prerender {

PrerenderRenderViewHostObserver::PrerenderRenderViewHostObserver(
    PrerenderContents* prerender_contents,
    RenderViewHost* render_view_host)
    : content::RenderViewHostObserver(render_view_host),
      prerender_contents_(prerender_contents) {
}

void PrerenderRenderViewHostObserver::RenderViewHostDestroyed(
    RenderViewHost* rvh) {
  // The base class deletes |this| on RenderViewHost destruction but we want the
  // lifetime to be tied to the PrerenderContents instead, so we'll do nothing
  // here.
}

bool PrerenderRenderViewHostObserver::OnMessageReceived(
    const IPC::Message& message) {
  if (!prerender_contents_)
    return content::RenderViewHostObserver::OnMessageReceived(message);

  bool handled = true;
  // The following messages we do want to consume.
  IPC_BEGIN_MESSAGE_MAP(PrerenderRenderViewHostObserver, message)
    IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_MaybeCancelPrerenderForHTML5Media,
                        OnMaybeCancelPrerenderForHTML5Media)
    IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CancelPrerenderForPrinting,
                        OnCancelPrerenderForPrinting)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()

  // Pass the message through.
  if (!handled)
    handled = content::RenderViewHostObserver::OnMessageReceived(message);

  return handled;
}

// The base class declares this as protected so this is just here to make it
// public so it is visible to the caller.
bool PrerenderRenderViewHostObserver::Send(IPC::Message* message) {
  return content::RenderViewHostObserver::Send(message);
}

void PrerenderRenderViewHostObserver::OnUpdateFaviconURL(
    int32 page_id,
    const std::vector<FaviconURL>& urls) {
  prerender_contents_->OnUpdateFaviconURL(page_id, urls);
}

void PrerenderRenderViewHostObserver::OnMaybeCancelPrerenderForHTML5Media() {
  prerender_contents_->Destroy(FINAL_STATUS_HTML5_MEDIA);
}

void PrerenderRenderViewHostObserver::OnCancelPrerenderForPrinting() {
  prerender_contents_->Destroy(FINAL_STATUS_WINDOW_PRINT);
}

}