| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "android_webview/browser/renderer_host/view_renderer_host.h" | 5 #include "android_webview/browser/renderer_host/view_renderer_host.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | 7 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
| 8 #include "android_webview/common/aw_switches.h" | 8 #include "android_webview/common/aw_switches.h" |
| 9 #include "android_webview/common/render_view_messages.h" | 9 #include "android_webview/common/render_view_messages.h" |
| 10 #include "android_webview/common/renderer_picture_map.h" | 10 #include "android_webview/common/renderer_picture_map.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "content/public/browser/android/content_view_core.h" | 12 #include "content/public/browser/android/content_view_core.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dler.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dler.h" |
| 17 | 17 |
| 18 namespace android_webview { | 18 namespace android_webview { |
| 19 | 19 |
| 20 ViewRendererHost::ViewRendererHost(content::WebContents* contents, | 20 ViewRendererHost::ViewRendererHost(content::WebContents* contents, |
| 21 Client* client) | 21 Client* client) |
| 22 : content::WebContentsObserver(contents), | 22 : content::WebContentsObserver(contents), |
| 23 client_(client) { | 23 client_(client) { |
| 24 DCHECK(client); |
| 24 } | 25 } |
| 25 | 26 |
| 26 ViewRendererHost::~ViewRendererHost() { | 27 ViewRendererHost::~ViewRendererHost() { |
| 27 } | 28 } |
| 28 | 29 |
| 29 void ViewRendererHost::CapturePictureSync() { | 30 void ViewRendererHost::CapturePictureSync() { |
| 30 if (!IsRenderViewReady()) | 31 if (!IsRenderViewReady()) |
| 31 return; | 32 return; |
| 32 | 33 |
| 33 ScopedAllowWaitForLegacyWebViewApi wait; | 34 ScopedAllowWaitForLegacyWebViewApi wait; |
| 34 Send(new AwViewMsg_CapturePictureSync(web_contents()->GetRoutingID())); | 35 Send(new AwViewMsg_CapturePictureSync(web_contents()->GetRoutingID())); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void ViewRendererHost::EnableCapturePictureCallback(bool enabled) { | 38 void ViewRendererHost::EnableCapturePictureCallback(bool enabled) { |
| 38 Send(new AwViewMsg_EnableCapturePictureCallback( | 39 Send(new AwViewMsg_EnableCapturePictureCallback( |
| 39 web_contents()->GetRoutingID(), enabled)); | 40 web_contents()->GetRoutingID(), enabled)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void ViewRendererHost::OnPictureUpdated() { | 43 void ViewRendererHost::OnPictureUpdated() { |
| 43 if (client_) { | 44 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), |
| 44 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), | 45 routing_id()); |
| 45 routing_id()); | |
| 46 } | |
| 47 } | 46 } |
| 48 | 47 |
| 49 void ViewRendererHost::OnDidActivateAcceleratedCompositing( | 48 void ViewRendererHost::OnDidActivateAcceleratedCompositing( |
| 50 int input_handler_id) { | 49 int input_handler_id) { |
| 51 | 50 |
| 52 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 51 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 53 switches::kMergeUIAndRendererCompositorThreads)) { | 52 switches::kMergeUIAndRendererCompositorThreads)) { |
| 54 return; | 53 return; |
| 55 } | 54 } |
| 56 | 55 |
| 57 // This call is only meaningful and thread-safe when the UI and renderer | 56 // This call is only meaningful and thread-safe when the UI and renderer |
| 58 // compositor share the same thread. Any other case will likely yield | 57 // compositor share the same thread. Any other case will likely yield |
| 59 // terrible, terrible damage. | 58 // terrible, terrible damage. |
| 60 WebKit::WebCompositorInputHandler* input_handler = | 59 WebKit::WebCompositorInputHandler* input_handler = |
| 61 WebKit::WebCompositorInputHandler::fromIdentifier(input_handler_id); | 60 WebKit::WebCompositorInputHandler::fromIdentifier(input_handler_id); |
| 62 if (!input_handler) | 61 if (!input_handler) |
| 63 return; | 62 return; |
| 64 | 63 |
| 65 content::ContentViewCore* content_view_core | 64 content::ContentViewCore* content_view_core |
| 66 = content::ContentViewCore::FromWebContents(web_contents()); | 65 = content::ContentViewCore::FromWebContents(web_contents()); |
| 67 if (content_view_core) | 66 if (content_view_core) |
| 68 content_view_core->SetInputHandler(input_handler); | 67 content_view_core->SetInputHandler(input_handler); |
| 69 } | 68 } |
| 70 | 69 |
| 70 void ViewRendererHost::OnPageScaleFactorChanged(float page_scale_factor) { |
| 71 client_->OnPageScaleFactorChanged( |
| 72 web_contents()->GetRenderProcessHost()->GetID(), |
| 73 routing_id(), |
| 74 page_scale_factor); |
| 75 } |
| 76 |
| 71 void ViewRendererHost::RenderViewGone(base::TerminationStatus status) { | 77 void ViewRendererHost::RenderViewGone(base::TerminationStatus status) { |
| 72 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
| 73 RendererPictureMap::GetInstance()->ClearRendererPicture( | 79 RendererPictureMap::GetInstance()->ClearRendererPicture( |
| 74 web_contents()->GetRoutingID()); | 80 web_contents()->GetRoutingID()); |
| 75 } | 81 } |
| 76 | 82 |
| 77 bool ViewRendererHost::OnMessageReceived(const IPC::Message& message) { | 83 bool ViewRendererHost::OnMessageReceived(const IPC::Message& message) { |
| 78 bool handled = true; | 84 bool handled = true; |
| 79 IPC_BEGIN_MESSAGE_MAP(ViewRendererHost, message) | 85 IPC_BEGIN_MESSAGE_MAP(ViewRendererHost, message) |
| 80 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, | 86 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, |
| 81 OnPictureUpdated) | 87 OnPictureUpdated) |
| 82 IPC_MESSAGE_HANDLER(AwViewHostMsg_DidActivateAcceleratedCompositing, | 88 IPC_MESSAGE_HANDLER(AwViewHostMsg_DidActivateAcceleratedCompositing, |
| 83 OnDidActivateAcceleratedCompositing) | 89 OnDidActivateAcceleratedCompositing) |
| 90 IPC_MESSAGE_HANDLER(AwViewHostMsg_PageScaleFactorChanged, |
| 91 OnPageScaleFactorChanged) |
| 84 IPC_MESSAGE_UNHANDLED(handled = false) | 92 IPC_MESSAGE_UNHANDLED(handled = false) |
| 85 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
| 86 | 94 |
| 87 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 95 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
| 88 } | 96 } |
| 89 | 97 |
| 90 bool ViewRendererHost::IsRenderViewReady() const { | 98 bool ViewRendererHost::IsRenderViewReady() const { |
| 91 return web_contents()->GetRenderProcessHost()->HasConnection() && | 99 return web_contents()->GetRenderProcessHost()->HasConnection() && |
| 92 web_contents()->GetRenderViewHost() && | 100 web_contents()->GetRenderViewHost() && |
| 93 web_contents()->GetRenderViewHost()->IsRenderViewLive(); | 101 web_contents()->GetRenderViewHost()->IsRenderViewLive(); |
| 94 } | 102 } |
| 95 | 103 |
| 96 } // namespace android_webview | 104 } // namespace android_webview |
| OLD | NEW |