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::RenderViewGone(base::TerminationStatus status) { | 66 void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { |
74 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
75 for (std::map<int, DocumentHasImagesResult>::iterator pending_req = | 68 for (std::map<int, DocumentHasImagesResult>::iterator pending_req = |
76 pending_document_has_images_requests_.begin(); | 69 pending_document_has_images_requests_.begin(); |
77 pending_req != pending_document_has_images_requests_.end(); | 70 pending_req != pending_document_has_images_requests_.end(); |
78 ++pending_req) { | 71 ++pending_req) { |
79 pending_req->second.Run(false); | 72 pending_req->second.Run(false); |
80 } | 73 } |
81 } | 74 } |
82 | 75 |
83 void AwRenderViewHostExt::DidNavigateAnyFrame( | 76 void AwRenderViewHostExt::DidNavigateAnyFrame( |
84 const content::LoadCommittedDetails& details, | 77 const content::LoadCommittedDetails& details, |
85 const content::FrameNavigateParams& params) { | 78 const content::FrameNavigateParams& params) { |
86 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
87 | 80 |
88 AwBrowserContext::FromWebContents(web_contents()) | 81 AwBrowserContext::FromWebContents(web_contents()) |
89 ->AddVisitedURLs(params.redirects); | 82 ->AddVisitedURLs(params.redirects); |
90 } | 83 } |
91 | 84 |
92 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { | 85 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { |
93 bool handled = true; | 86 bool handled = true; |
94 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) | 87 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) |
95 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, | 88 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, |
96 OnDocumentHasImagesResponse) | 89 OnDocumentHasImagesResponse) |
97 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, | 90 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, |
98 OnUpdateHitTestData) | 91 OnUpdateHitTestData) |
99 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, | |
100 OnPictureUpdated) | |
101 IPC_MESSAGE_UNHANDLED(handled = false) | 92 IPC_MESSAGE_UNHANDLED(handled = false) |
102 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
103 | 94 |
104 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 95 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
105 } | 96 } |
106 | 97 |
107 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, | 98 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, |
108 bool has_images) { | 99 bool has_images) { |
109 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
110 std::map<int, DocumentHasImagesResult>::iterator pending_req = | 101 std::map<int, DocumentHasImagesResult>::iterator pending_req = |
111 pending_document_has_images_requests_.find(msg_id); | 102 pending_document_has_images_requests_.find(msg_id); |
112 if (pending_req == pending_document_has_images_requests_.end()) { | 103 if (pending_req == pending_document_has_images_requests_.end()) { |
113 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; | 104 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; |
114 } else { | 105 } else { |
115 pending_req->second.Run(has_images); | 106 pending_req->second.Run(has_images); |
116 pending_document_has_images_requests_.erase(pending_req); | 107 pending_document_has_images_requests_.erase(pending_req); |
117 } | 108 } |
118 } | 109 } |
119 | 110 |
120 void AwRenderViewHostExt::OnUpdateHitTestData( | 111 void AwRenderViewHostExt::OnUpdateHitTestData( |
121 const AwHitTestData& hit_test_data) { | 112 const AwHitTestData& hit_test_data) { |
122 DCHECK(CalledOnValidThread()); | 113 DCHECK(CalledOnValidThread()); |
123 last_hit_test_data_ = hit_test_data; | 114 last_hit_test_data_ = hit_test_data; |
124 has_new_hit_test_data_ = true; | 115 has_new_hit_test_data_ = true; |
125 } | 116 } |
126 | 117 |
127 void AwRenderViewHostExt::OnPictureUpdated() { | |
128 if (client_) | |
129 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), | |
130 routing_id()); | |
131 } | |
132 | |
133 bool AwRenderViewHostExt::IsRenderViewReady() const { | |
134 return web_contents()->GetRenderProcessHost()->HasConnection() && | |
135 web_contents()->GetRenderViewHost() && | |
136 web_contents()->GetRenderViewHost()->IsRenderViewLive(); | |
137 } | |
138 | |
139 void AwRenderViewHostExt::CapturePictureSync() { | |
140 if (!IsRenderViewReady()) | |
141 return; | |
142 | |
143 ScopedAllowWaitForLegacyWebViewApi wait; | |
144 Send(new AwViewMsg_CapturePictureSync(web_contents()->GetRoutingID())); | |
145 } | |
146 | |
147 } // namespace android_webview | 118 } // namespace android_webview |
OLD | NEW |