| 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/render_view_messages.h" | 9 #include "android_webview/common/render_view_messages.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.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/user_metrics.h" | 15 #include "content/public/browser/user_metrics.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/frame_navigate_params.h" | 17 #include "content/public/common/frame_navigate_params.h" |
| 18 | 18 |
| 19 namespace android_webview { | 19 namespace android_webview { |
| 20 | 20 |
| 21 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents, | 21 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents) |
| 22 Client* client) | |
| 23 : content::WebContentsObserver(contents), | 22 : content::WebContentsObserver(contents), |
| 24 has_new_hit_test_data_(false), | 23 has_new_hit_test_data_(false) { |
| 25 client_(client) { | |
| 26 } | 24 } |
| 27 | 25 |
| 28 AwRenderViewHostExt::~AwRenderViewHostExt() {} | 26 AwRenderViewHostExt::~AwRenderViewHostExt() {} |
| 29 | 27 |
| 30 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { | 28 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { |
| 31 DCHECK(CalledOnValidThread()); | 29 DCHECK(CalledOnValidThread()); |
| 32 if (!web_contents()->GetRenderViewHost()) { | 30 if (!web_contents()->GetRenderViewHost()) { |
| 33 result.Run(false); | 31 result.Run(false); |
| 34 return; | 32 return; |
| 35 } | 33 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 58 Send(new AwViewMsg_DoHitTest(web_contents()->GetRoutingID(), | 56 Send(new AwViewMsg_DoHitTest(web_contents()->GetRoutingID(), |
| 59 view_x, | 57 view_x, |
| 60 view_y)); | 58 view_y)); |
| 61 } | 59 } |
| 62 | 60 |
| 63 const AwHitTestData& AwRenderViewHostExt::GetLastHitTestData() const { | 61 const AwHitTestData& AwRenderViewHostExt::GetLastHitTestData() const { |
| 64 DCHECK(CalledOnValidThread()); | 62 DCHECK(CalledOnValidThread()); |
| 65 return last_hit_test_data_; | 63 return last_hit_test_data_; |
| 66 } | 64 } |
| 67 | 65 |
| 68 void AwRenderViewHostExt::EnableCapturePictureCallback(bool enabled) { | |
| 69 Send(new AwViewMsg_EnableCapturePictureCallback( | |
| 70 web_contents()->GetRoutingID(), enabled)); | |
| 71 } | |
| 72 | |
| 73 void AwRenderViewHostExt::SetTextZoomLevel(double level) { | 66 void AwRenderViewHostExt::SetTextZoomLevel(double level) { |
| 74 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
| 75 Send(new AwViewMsg_SetTextZoomLevel(web_contents()->GetRoutingID(), level)); | 68 Send(new AwViewMsg_SetTextZoomLevel(web_contents()->GetRoutingID(), level)); |
| 76 } | 69 } |
| 77 | 70 |
| 78 void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { | 71 void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { |
| 79 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 80 for (std::map<int, DocumentHasImagesResult>::iterator pending_req = | 73 for (std::map<int, DocumentHasImagesResult>::iterator pending_req = |
| 81 pending_document_has_images_requests_.begin(); | 74 pending_document_has_images_requests_.begin(); |
| 82 pending_req != pending_document_has_images_requests_.end(); | 75 pending_req != pending_document_has_images_requests_.end(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 ->AddVisitedURLs(params.redirects); | 87 ->AddVisitedURLs(params.redirects); |
| 95 } | 88 } |
| 96 | 89 |
| 97 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { | 90 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { |
| 98 bool handled = true; | 91 bool handled = true; |
| 99 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) | 92 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) |
| 100 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, | 93 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, |
| 101 OnDocumentHasImagesResponse) | 94 OnDocumentHasImagesResponse) |
| 102 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, | 95 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, |
| 103 OnUpdateHitTestData) | 96 OnUpdateHitTestData) |
| 104 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, | |
| 105 OnPictureUpdated) | |
| 106 IPC_MESSAGE_UNHANDLED(handled = false) | 97 IPC_MESSAGE_UNHANDLED(handled = false) |
| 107 IPC_END_MESSAGE_MAP() | 98 IPC_END_MESSAGE_MAP() |
| 108 | 99 |
| 109 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 100 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
| 110 } | 101 } |
| 111 | 102 |
| 112 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, | 103 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, |
| 113 bool has_images) { | 104 bool has_images) { |
| 114 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
| 115 std::map<int, DocumentHasImagesResult>::iterator pending_req = | 106 std::map<int, DocumentHasImagesResult>::iterator pending_req = |
| 116 pending_document_has_images_requests_.find(msg_id); | 107 pending_document_has_images_requests_.find(msg_id); |
| 117 if (pending_req == pending_document_has_images_requests_.end()) { | 108 if (pending_req == pending_document_has_images_requests_.end()) { |
| 118 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; | 109 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; |
| 119 } else { | 110 } else { |
| 120 pending_req->second.Run(has_images); | 111 pending_req->second.Run(has_images); |
| 121 pending_document_has_images_requests_.erase(pending_req); | 112 pending_document_has_images_requests_.erase(pending_req); |
| 122 } | 113 } |
| 123 } | 114 } |
| 124 | 115 |
| 125 void AwRenderViewHostExt::OnUpdateHitTestData( | 116 void AwRenderViewHostExt::OnUpdateHitTestData( |
| 126 const AwHitTestData& hit_test_data) { | 117 const AwHitTestData& hit_test_data) { |
| 127 DCHECK(CalledOnValidThread()); | 118 DCHECK(CalledOnValidThread()); |
| 128 last_hit_test_data_ = hit_test_data; | 119 last_hit_test_data_ = hit_test_data; |
| 129 has_new_hit_test_data_ = true; | 120 has_new_hit_test_data_ = true; |
| 130 } | 121 } |
| 131 | 122 |
| 132 void AwRenderViewHostExt::OnPictureUpdated() { | |
| 133 if (client_) | |
| 134 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), | |
| 135 routing_id()); | |
| 136 } | |
| 137 | |
| 138 bool AwRenderViewHostExt::IsRenderViewReady() const { | |
| 139 return web_contents()->GetRenderProcessHost()->HasConnection() && | |
| 140 web_contents()->GetRenderViewHost() && | |
| 141 web_contents()->GetRenderViewHost()->IsRenderViewLive(); | |
| 142 } | |
| 143 | |
| 144 void AwRenderViewHostExt::CapturePictureSync() { | |
| 145 if (!IsRenderViewReady()) | |
| 146 return; | |
| 147 | |
| 148 ScopedAllowWaitForLegacyWebViewApi wait; | |
| 149 Send(new AwViewMsg_CapturePictureSync(web_contents()->GetRoutingID())); | |
| 150 } | |
| 151 | |
| 152 } // namespace android_webview | 123 } // namespace android_webview |
| OLD | NEW |