OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "android_webview/browser/renderer_host/view_renderer_host.h" | |
6 | |
7 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | |
8 #include "android_webview/common/aw_switches.h" | |
9 #include "android_webview/common/render_view_messages.h" | |
10 #include "android_webview/common/renderer_picture_map.h" | |
11 #include "content/public/browser/render_process_host.h" | |
12 #include "content/public/browser/render_view_host.h" | |
13 #include "content/public/browser/web_contents.h" | |
14 | |
15 namespace android_webview { | |
16 | |
17 ViewRendererHost::ViewRendererHost(content::WebContents* contents, | |
18 Client* client) | |
19 : content::WebContentsObserver(contents), | |
20 client_(client) { | |
21 DCHECK(client); | |
22 } | |
23 | |
24 ViewRendererHost::~ViewRendererHost() { | |
25 } | |
26 | |
27 void ViewRendererHost::CapturePictureSync() { | |
28 if (!IsRenderViewReady()) | |
29 return; | |
30 | |
31 ScopedAllowWaitForLegacyWebViewApi wait; | |
32 Send(new AwViewMsg_CapturePictureSync(web_contents()->GetRoutingID())); | |
33 } | |
34 | |
35 void ViewRendererHost::EnableCapturePictureCallback(bool enabled) { | |
36 Send(new AwViewMsg_EnableCapturePictureCallback( | |
37 web_contents()->GetRoutingID(), enabled)); | |
38 } | |
39 | |
40 void ViewRendererHost::OnPictureUpdated() { | |
41 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), | |
42 routing_id()); | |
43 } | |
44 | |
45 void ViewRendererHost::RenderViewGone(base::TerminationStatus status) { | |
46 DCHECK(CalledOnValidThread()); | |
47 RendererPictureMap::GetInstance()->ClearRendererPicture( | |
48 web_contents()->GetRoutingID()); | |
49 } | |
50 | |
51 bool ViewRendererHost::OnMessageReceived(const IPC::Message& message) { | |
52 bool handled = true; | |
53 IPC_BEGIN_MESSAGE_MAP(ViewRendererHost, message) | |
54 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, | |
55 OnPictureUpdated) | |
56 IPC_MESSAGE_UNHANDLED(handled = false) | |
57 IPC_END_MESSAGE_MAP() | |
58 | |
59 return handled ? true : WebContentsObserver::OnMessageReceived(message); | |
60 } | |
61 | |
62 bool ViewRendererHost::IsRenderViewReady() const { | |
63 return web_contents()->GetRenderProcessHost()->HasConnection() && | |
64 web_contents()->GetRenderViewHost() && | |
65 web_contents()->GetRenderViewHost()->IsRenderViewLive(); | |
66 } | |
67 | |
68 } // namespace android_webview | |
OLD | NEW |