| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/aw_render_view_host_ext.h" | 5 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
| 8 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | 8 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
| 9 #include "android_webview/common/aw_switches.h" |
| 9 #include "android_webview/common/render_view_messages.h" | 10 #include "android_webview/common/render_view_messages.h" |
| 10 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "content/public/browser/android/content_view_core.h" |
| 13 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/user_metrics.h" | 18 #include "content/public/browser/user_metrics.h" |
| 16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/frame_navigate_params.h" | 20 #include "content/public/common/frame_navigate_params.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan
dler.h" |
| 18 | 22 |
| 19 namespace android_webview { | 23 namespace android_webview { |
| 20 | 24 |
| 21 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents) | 25 AwRenderViewHostExt::AwRenderViewHostExt( |
| 26 AwRenderViewHostExtClient* client, content::WebContents* contents) |
| 22 : content::WebContentsObserver(contents), | 27 : content::WebContentsObserver(contents), |
| 28 client_(client), |
| 23 has_new_hit_test_data_(false) { | 29 has_new_hit_test_data_(false) { |
| 30 DCHECK(client_); |
| 24 } | 31 } |
| 25 | 32 |
| 26 AwRenderViewHostExt::~AwRenderViewHostExt() {} | 33 AwRenderViewHostExt::~AwRenderViewHostExt() {} |
| 27 | 34 |
| 28 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { | 35 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { |
| 29 DCHECK(CalledOnValidThread()); | 36 DCHECK(CalledOnValidThread()); |
| 30 if (!web_contents()->GetRenderViewHost()) { | 37 if (!web_contents()->GetRenderViewHost()) { |
| 31 result.Run(false); | 38 result.Run(false); |
| 32 return; | 39 return; |
| 33 } | 40 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 ->AddVisitedURLs(params.redirects); | 105 ->AddVisitedURLs(params.redirects); |
| 99 } | 106 } |
| 100 | 107 |
| 101 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { | 108 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { |
| 102 bool handled = true; | 109 bool handled = true; |
| 103 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) | 110 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) |
| 104 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, | 111 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, |
| 105 OnDocumentHasImagesResponse) | 112 OnDocumentHasImagesResponse) |
| 106 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, | 113 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, |
| 107 OnUpdateHitTestData) | 114 OnUpdateHitTestData) |
| 115 IPC_MESSAGE_HANDLER(AwViewHostMsg_DidActivateAcceleratedCompositing, |
| 116 OnDidActivateAcceleratedCompositing) |
| 117 IPC_MESSAGE_HANDLER(AwViewHostMsg_PageScaleFactorChanged, |
| 118 OnPageScaleFactorChanged) |
| 108 IPC_MESSAGE_UNHANDLED(handled = false) | 119 IPC_MESSAGE_UNHANDLED(handled = false) |
| 109 IPC_END_MESSAGE_MAP() | 120 IPC_END_MESSAGE_MAP() |
| 110 | 121 |
| 111 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 122 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
| 112 } | 123 } |
| 113 | 124 |
| 114 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, | 125 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, |
| 115 bool has_images) { | 126 bool has_images) { |
| 116 DCHECK(CalledOnValidThread()); | 127 DCHECK(CalledOnValidThread()); |
| 117 std::map<int, DocumentHasImagesResult>::iterator pending_req = | 128 std::map<int, DocumentHasImagesResult>::iterator pending_req = |
| 118 pending_document_has_images_requests_.find(msg_id); | 129 pending_document_has_images_requests_.find(msg_id); |
| 119 if (pending_req == pending_document_has_images_requests_.end()) { | 130 if (pending_req == pending_document_has_images_requests_.end()) { |
| 120 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; | 131 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; |
| 121 } else { | 132 } else { |
| 122 pending_req->second.Run(has_images); | 133 pending_req->second.Run(has_images); |
| 123 pending_document_has_images_requests_.erase(pending_req); | 134 pending_document_has_images_requests_.erase(pending_req); |
| 124 } | 135 } |
| 125 } | 136 } |
| 126 | 137 |
| 127 void AwRenderViewHostExt::OnUpdateHitTestData( | 138 void AwRenderViewHostExt::OnUpdateHitTestData( |
| 128 const AwHitTestData& hit_test_data) { | 139 const AwHitTestData& hit_test_data) { |
| 129 DCHECK(CalledOnValidThread()); | 140 DCHECK(CalledOnValidThread()); |
| 130 last_hit_test_data_ = hit_test_data; | 141 last_hit_test_data_ = hit_test_data; |
| 131 has_new_hit_test_data_ = true; | 142 has_new_hit_test_data_ = true; |
| 132 } | 143 } |
| 133 | 144 |
| 145 void AwRenderViewHostExt::OnDidActivateAcceleratedCompositing( |
| 146 int input_handler_id) { |
| 147 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 148 switches::kNoMergeUIAndRendererCompositorThreads)) { |
| 149 return; |
| 150 } |
| 151 |
| 152 // This call is only meaningful and thread-safe when the UI and renderer |
| 153 // compositor share the same thread. Any other case will likely yield |
| 154 // terrible, terrible damage. |
| 155 WebKit::WebCompositorInputHandler* input_handler = |
| 156 WebKit::WebCompositorInputHandler::fromIdentifier(input_handler_id); |
| 157 if (!input_handler) |
| 158 return; |
| 159 |
| 160 content::ContentViewCore* content_view_core |
| 161 = content::ContentViewCore::FromWebContents(web_contents()); |
| 162 if (content_view_core) |
| 163 content_view_core->SetInputHandler(input_handler); |
| 164 } |
| 165 |
| 166 void AwRenderViewHostExt::OnPageScaleFactorChanged(float page_scale_factor) { |
| 167 client_->OnPageScaleFactorChanged(page_scale_factor); |
| 168 } |
| 169 |
| 134 } // namespace android_webview | 170 } // namespace android_webview |
| OLD | NEW |