| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
| 6 |
| 7 #include "android_webview/common/render_view_messages.h" |
| 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/callback.h" |
| 10 #include "content/public/browser/user_metrics.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 |
| 13 namespace android_webview { |
| 14 |
| 15 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents) |
| 16 : content::WebContentsObserver(contents) { |
| 17 } |
| 18 |
| 19 AwRenderViewHostExt::~AwRenderViewHostExt() {} |
| 20 |
| 21 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { |
| 22 if (!web_contents()->GetRenderViewHost()) { |
| 23 result.Run(false); |
| 24 return; |
| 25 } |
| 26 static int next_id = 1; |
| 27 int this_id = next_id++; |
| 28 pending_document_has_images_requests_[this_id] = result; |
| 29 Send(new AwViewMsg_DocumentHasImages(web_contents()->GetRoutingID(), |
| 30 this_id)); |
| 31 } |
| 32 |
| 33 void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { |
| 34 for (std::map<int, DocumentHasImagesResult>::iterator pending_req = |
| 35 pending_document_has_images_requests_.begin(); |
| 36 pending_req != pending_document_has_images_requests_.end(); |
| 37 ++pending_req) { |
| 38 pending_req->second.Run(false); |
| 39 } |
| 40 } |
| 41 |
| 42 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { |
| 43 bool handled = true; |
| 44 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) |
| 45 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, |
| 46 OnDocumentHasImagesResponse) |
| 47 IPC_MESSAGE_UNHANDLED(handled = false) |
| 48 IPC_END_MESSAGE_MAP() |
| 49 |
| 50 if (!handled) handled = WebContentsObserver::OnMessageReceived(message); |
| 51 |
| 52 return handled; |
| 53 } |
| 54 |
| 55 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, |
| 56 bool has_images) { |
| 57 std::map<int, DocumentHasImagesResult>::iterator pending_req = |
| 58 pending_document_has_images_requests_.find(msg_id); |
| 59 if (pending_req != pending_document_has_images_requests_.end()) { |
| 60 pending_req->second.Run(has_images); |
| 61 pending_document_has_images_requests_.erase(pending_req); |
| 62 } |
| 63 } |
| 64 |
| 65 } // namespace android_webview |
| OLD | NEW |