| 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/common/render_view_messages.h" | 7 #include "android_webview/common/render_view_messages.h" |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/user_metrics.h" | 12 #include "content/public/browser/user_metrics.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 | 14 |
| 15 namespace android_webview { | 15 namespace android_webview { |
| 16 | 16 |
| 17 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents, | 17 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents) |
| 18 Client* client) | |
| 19 : content::WebContentsObserver(contents), | 18 : content::WebContentsObserver(contents), |
| 20 has_new_hit_test_data_(false), | 19 has_new_hit_test_data_(false) { |
| 21 client_(client) { | |
| 22 } | 20 } |
| 23 | 21 |
| 24 AwRenderViewHostExt::~AwRenderViewHostExt() {} | 22 AwRenderViewHostExt::~AwRenderViewHostExt() {} |
| 25 | 23 |
| 26 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { | 24 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { |
| 27 DCHECK(CalledOnValidThread()); | 25 DCHECK(CalledOnValidThread()); |
| 28 if (!web_contents()->GetRenderViewHost()) { | 26 if (!web_contents()->GetRenderViewHost()) { |
| 29 result.Run(false); | 27 result.Run(false); |
| 30 return; | 28 return; |
| 31 } | 29 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 69 } |
| 72 } | 70 } |
| 73 | 71 |
| 74 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { | 72 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { |
| 75 bool handled = true; | 73 bool handled = true; |
| 76 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) | 74 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) |
| 77 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, | 75 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, |
| 78 OnDocumentHasImagesResponse) | 76 OnDocumentHasImagesResponse) |
| 79 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, | 77 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, |
| 80 OnUpdateHitTestData) | 78 OnUpdateHitTestData) |
| 81 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, | |
| 82 OnPictureUpdated) | |
| 83 IPC_MESSAGE_UNHANDLED(handled = false) | 79 IPC_MESSAGE_UNHANDLED(handled = false) |
| 84 IPC_END_MESSAGE_MAP() | 80 IPC_END_MESSAGE_MAP() |
| 85 | 81 |
| 86 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 82 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
| 87 } | 83 } |
| 88 | 84 |
| 89 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, | 85 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, |
| 90 bool has_images) { | 86 bool has_images) { |
| 91 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
| 92 std::map<int, DocumentHasImagesResult>::iterator pending_req = | 88 std::map<int, DocumentHasImagesResult>::iterator pending_req = |
| 93 pending_document_has_images_requests_.find(msg_id); | 89 pending_document_has_images_requests_.find(msg_id); |
| 94 if (pending_req == pending_document_has_images_requests_.end()) { | 90 if (pending_req == pending_document_has_images_requests_.end()) { |
| 95 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; | 91 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; |
| 96 } else { | 92 } else { |
| 97 pending_req->second.Run(has_images); | 93 pending_req->second.Run(has_images); |
| 98 pending_document_has_images_requests_.erase(pending_req); | 94 pending_document_has_images_requests_.erase(pending_req); |
| 99 } | 95 } |
| 100 } | 96 } |
| 101 | 97 |
| 102 void AwRenderViewHostExt::OnUpdateHitTestData( | 98 void AwRenderViewHostExt::OnUpdateHitTestData( |
| 103 const AwHitTestData& hit_test_data) { | 99 const AwHitTestData& hit_test_data) { |
| 104 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
| 105 last_hit_test_data_ = hit_test_data; | 101 last_hit_test_data_ = hit_test_data; |
| 106 has_new_hit_test_data_ = true; | 102 has_new_hit_test_data_ = true; |
| 107 } | 103 } |
| 108 | 104 |
| 109 void AwRenderViewHostExt::OnPictureUpdated() { | |
| 110 if (client_) | |
| 111 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), | |
| 112 routing_id()); | |
| 113 } | |
| 114 | |
| 115 } // namespace android_webview | 105 } // namespace android_webview |
| OLD | NEW |