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