| 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/common/render_view_messages.h" | 8 #include "android_webview/common/render_view_messages.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 AwRenderViewHostExt::AwRenderViewHostExt( | 25 AwRenderViewHostExt::AwRenderViewHostExt( |
| 26 AwRenderViewHostExtClient* client, content::WebContents* contents) | 26 AwRenderViewHostExtClient* client, content::WebContents* contents) |
| 27 : content::WebContentsObserver(contents), | 27 : content::WebContentsObserver(contents), |
| 28 client_(client), | 28 client_(client), |
| 29 background_color_(SK_ColorWHITE), | 29 background_color_(SK_ColorWHITE), |
| 30 has_new_hit_test_data_(false) { | 30 has_new_hit_test_data_(false) { |
| 31 DCHECK(client_); | 31 DCHECK(client_); |
| 32 } | 32 } |
| 33 | 33 |
| 34 AwRenderViewHostExt::~AwRenderViewHostExt() { | 34 AwRenderViewHostExt::~AwRenderViewHostExt() { |
| 35 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 35 ClearImageRequests(); | 36 ClearImageRequests(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { | 39 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { |
| 39 DCHECK(CalledOnValidThread()); | 40 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 40 if (!web_contents()->GetRenderViewHost()) { | 41 if (!web_contents()->GetRenderViewHost()) { |
| 41 result.Run(false); | 42 result.Run(false); |
| 42 return; | 43 return; |
| 43 } | 44 } |
| 44 static uint32_t next_id = 1; | 45 static uint32_t next_id = 1; |
| 45 uint32_t this_id = next_id++; | 46 uint32_t this_id = next_id++; |
| 46 // Send the message to the main frame, instead of the whole frame tree, | 47 // Send the message to the main frame, instead of the whole frame tree, |
| 47 // because it only makes sense on the main frame. | 48 // because it only makes sense on the main frame. |
| 48 if (Send(new AwViewMsg_DocumentHasImages( | 49 if (Send(new AwViewMsg_DocumentHasImages( |
| 49 web_contents()->GetMainFrame()->GetRoutingID(), this_id))) { | 50 web_contents()->GetMainFrame()->GetRoutingID(), this_id))) { |
| 50 image_requests_callback_map_[this_id] = result; | 51 image_requests_callback_map_[this_id] = result; |
| 51 } else { | 52 } else { |
| 52 // Still have to respond to the API call WebView#docuemntHasImages. | 53 // Still have to respond to the API call WebView#docuemntHasImages. |
| 53 // Otherwise the listener of the response may be starved. | 54 // Otherwise the listener of the response may be starved. |
| 54 result.Run(false); | 55 result.Run(false); |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 | 58 |
| 58 void AwRenderViewHostExt::ClearCache() { | 59 void AwRenderViewHostExt::ClearCache() { |
| 59 DCHECK(CalledOnValidThread()); | 60 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 60 Send(new AwViewMsg_ClearCache); | 61 Send(new AwViewMsg_ClearCache); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void AwRenderViewHostExt::KillRenderProcess() { | 64 void AwRenderViewHostExt::KillRenderProcess() { |
| 64 DCHECK(CalledOnValidThread()); | 65 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 65 Send(new AwViewMsg_KillProcess); | 66 Send(new AwViewMsg_KillProcess); |
| 66 } | 67 } |
| 67 | 68 |
| 68 bool AwRenderViewHostExt::HasNewHitTestData() const { | 69 bool AwRenderViewHostExt::HasNewHitTestData() const { |
| 69 return has_new_hit_test_data_; | 70 return has_new_hit_test_data_; |
| 70 } | 71 } |
| 71 | 72 |
| 72 void AwRenderViewHostExt::MarkHitTestDataRead() { | 73 void AwRenderViewHostExt::MarkHitTestDataRead() { |
| 73 has_new_hit_test_data_ = false; | 74 has_new_hit_test_data_ = false; |
| 74 } | 75 } |
| 75 | 76 |
| 76 void AwRenderViewHostExt::RequestNewHitTestDataAt( | 77 void AwRenderViewHostExt::RequestNewHitTestDataAt( |
| 77 const gfx::PointF& touch_center, | 78 const gfx::PointF& touch_center, |
| 78 const gfx::SizeF& touch_area) { | 79 const gfx::SizeF& touch_area) { |
| 79 DCHECK(CalledOnValidThread()); | 80 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 80 // We only need to get blink::WebView on the renderer side to invoke the | 81 // We only need to get blink::WebView on the renderer side to invoke the |
| 81 // blink hit test API, so sending this IPC to main frame is enough. | 82 // blink hit test API, so sending this IPC to main frame is enough. |
| 82 Send(new AwViewMsg_DoHitTest(web_contents()->GetMainFrame()->GetRoutingID(), | 83 Send(new AwViewMsg_DoHitTest(web_contents()->GetMainFrame()->GetRoutingID(), |
| 83 touch_center, touch_area)); | 84 touch_center, touch_area)); |
| 84 } | 85 } |
| 85 | 86 |
| 86 const AwHitTestData& AwRenderViewHostExt::GetLastHitTestData() const { | 87 const AwHitTestData& AwRenderViewHostExt::GetLastHitTestData() const { |
| 87 DCHECK(CalledOnValidThread()); | 88 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 88 return last_hit_test_data_; | 89 return last_hit_test_data_; |
| 89 } | 90 } |
| 90 | 91 |
| 91 void AwRenderViewHostExt::SetTextZoomFactor(float factor) { | 92 void AwRenderViewHostExt::SetTextZoomFactor(float factor) { |
| 92 DCHECK(CalledOnValidThread()); | 93 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 93 Send(new AwViewMsg_SetTextZoomFactor( | 94 Send(new AwViewMsg_SetTextZoomFactor( |
| 94 web_contents()->GetMainFrame()->GetRoutingID(), factor)); | 95 web_contents()->GetMainFrame()->GetRoutingID(), factor)); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void AwRenderViewHostExt::ResetScrollAndScaleState() { | 98 void AwRenderViewHostExt::ResetScrollAndScaleState() { |
| 98 DCHECK(CalledOnValidThread()); | 99 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 99 Send(new AwViewMsg_ResetScrollAndScaleState( | 100 Send(new AwViewMsg_ResetScrollAndScaleState( |
| 100 web_contents()->GetMainFrame()->GetRoutingID())); | 101 web_contents()->GetMainFrame()->GetRoutingID())); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void AwRenderViewHostExt::SetInitialPageScale(double page_scale_factor) { | 104 void AwRenderViewHostExt::SetInitialPageScale(double page_scale_factor) { |
| 104 DCHECK(CalledOnValidThread()); | 105 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 105 Send(new AwViewMsg_SetInitialPageScale( | 106 Send(new AwViewMsg_SetInitialPageScale( |
| 106 web_contents()->GetMainFrame()->GetRoutingID(), page_scale_factor)); | 107 web_contents()->GetMainFrame()->GetRoutingID(), page_scale_factor)); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void AwRenderViewHostExt::SetBackgroundColor(SkColor c) { | 110 void AwRenderViewHostExt::SetBackgroundColor(SkColor c) { |
| 110 if (background_color_ == c) | 111 if (background_color_ == c) |
| 111 return; | 112 return; |
| 112 background_color_ = c; | 113 background_color_ = c; |
| 113 if (web_contents()->GetRenderViewHost()) { | 114 if (web_contents()->GetRenderViewHost()) { |
| 114 Send(new AwViewMsg_SetBackgroundColor( | 115 Send(new AwViewMsg_SetBackgroundColor( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 152 |
| 152 void AwRenderViewHostExt::RenderFrameCreated( | 153 void AwRenderViewHostExt::RenderFrameCreated( |
| 153 content::RenderFrameHost* frame_host) { | 154 content::RenderFrameHost* frame_host) { |
| 154 frame_host->GetInterfaceRegistry()->AddInterface( | 155 frame_host->GetInterfaceRegistry()->AddInterface( |
| 155 base::Bind(&web_restrictions::WebRestrictionsMojoImplementation::Create, | 156 base::Bind(&web_restrictions::WebRestrictionsMojoImplementation::Create, |
| 156 AwBrowserContext::GetDefault()->GetWebRestrictionProvider())); | 157 AwBrowserContext::GetDefault()->GetWebRestrictionProvider())); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void AwRenderViewHostExt::DidFinishNavigation( | 160 void AwRenderViewHostExt::DidFinishNavigation( |
| 160 content::NavigationHandle* navigation_handle) { | 161 content::NavigationHandle* navigation_handle) { |
| 161 DCHECK(CalledOnValidThread()); | 162 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 162 if (!navigation_handle->HasCommitted() || | 163 if (!navigation_handle->HasCommitted() || |
| 163 (!navigation_handle->IsInMainFrame() && | 164 (!navigation_handle->IsInMainFrame() && |
| 164 !navigation_handle->HasSubframeNavigationEntryCommitted())) | 165 !navigation_handle->HasSubframeNavigationEntryCommitted())) |
| 165 return; | 166 return; |
| 166 | 167 |
| 167 AwBrowserContext::FromWebContents(web_contents()) | 168 AwBrowserContext::FromWebContents(web_contents()) |
| 168 ->AddVisitedURLs(navigation_handle->GetRedirectChain()); | 169 ->AddVisitedURLs(navigation_handle->GetRedirectChain()); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void AwRenderViewHostExt::OnPageScaleFactorChanged(float page_scale_factor) { | 172 void AwRenderViewHostExt::OnPageScaleFactorChanged(float page_scale_factor) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 194 content::RenderFrameHost* render_frame_host, | 195 content::RenderFrameHost* render_frame_host, |
| 195 int msg_id, | 196 int msg_id, |
| 196 bool has_images) { | 197 bool has_images) { |
| 197 // Only makes sense coming from the main frame of the current frame tree. | 198 // Only makes sense coming from the main frame of the current frame tree. |
| 198 // This matches the current implementation that only cares about if there is | 199 // This matches the current implementation that only cares about if there is |
| 199 // an img child node in the main document, and essentially invokes JS: | 200 // an img child node in the main document, and essentially invokes JS: |
| 200 // node.getElementsByTagName("img"). | 201 // node.getElementsByTagName("img"). |
| 201 if (render_frame_host != web_contents()->GetMainFrame()) | 202 if (render_frame_host != web_contents()->GetMainFrame()) |
| 202 return; | 203 return; |
| 203 | 204 |
| 204 DCHECK(CalledOnValidThread()); | 205 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 205 std::map<int, DocumentHasImagesResult>::iterator pending_req = | 206 std::map<int, DocumentHasImagesResult>::iterator pending_req = |
| 206 image_requests_callback_map_.find(msg_id); | 207 image_requests_callback_map_.find(msg_id); |
| 207 if (pending_req == image_requests_callback_map_.end()) { | 208 if (pending_req == image_requests_callback_map_.end()) { |
| 208 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; | 209 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; |
| 209 } else { | 210 } else { |
| 210 pending_req->second.Run(has_images); | 211 pending_req->second.Run(has_images); |
| 211 image_requests_callback_map_.erase(pending_req); | 212 image_requests_callback_map_.erase(pending_req); |
| 212 } | 213 } |
| 213 } | 214 } |
| 214 | 215 |
| 215 void AwRenderViewHostExt::OnUpdateHitTestData( | 216 void AwRenderViewHostExt::OnUpdateHitTestData( |
| 216 content::RenderFrameHost* render_frame_host, | 217 content::RenderFrameHost* render_frame_host, |
| 217 const AwHitTestData& hit_test_data) { | 218 const AwHitTestData& hit_test_data) { |
| 218 content::RenderFrameHost* main_frame_host = render_frame_host; | 219 content::RenderFrameHost* main_frame_host = render_frame_host; |
| 219 while (main_frame_host->GetParent()) | 220 while (main_frame_host->GetParent()) |
| 220 main_frame_host = main_frame_host->GetParent(); | 221 main_frame_host = main_frame_host->GetParent(); |
| 221 | 222 |
| 222 // Make sense from any frame of the current frame tree, because a focused | 223 // Make sense from any frame of the current frame tree, because a focused |
| 223 // node could be in either the mainframe or a subframe. | 224 // node could be in either the mainframe or a subframe. |
| 224 if (main_frame_host != web_contents()->GetMainFrame()) | 225 if (main_frame_host != web_contents()->GetMainFrame()) |
| 225 return; | 226 return; |
| 226 | 227 |
| 227 DCHECK(CalledOnValidThread()); | 228 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 228 last_hit_test_data_ = hit_test_data; | 229 last_hit_test_data_ = hit_test_data; |
| 229 has_new_hit_test_data_ = true; | 230 has_new_hit_test_data_ = true; |
| 230 } | 231 } |
| 231 | 232 |
| 232 void AwRenderViewHostExt::OnContentsSizeChanged( | 233 void AwRenderViewHostExt::OnContentsSizeChanged( |
| 233 content::RenderFrameHost* render_frame_host, | 234 content::RenderFrameHost* render_frame_host, |
| 234 const gfx::Size& contents_size) { | 235 const gfx::Size& contents_size) { |
| 235 // Only makes sense coming from the main frame of the current frame tree. | 236 // Only makes sense coming from the main frame of the current frame tree. |
| 236 if (render_frame_host != web_contents()->GetMainFrame()) | 237 if (render_frame_host != web_contents()->GetMainFrame()) |
| 237 return; | 238 return; |
| 238 | 239 |
| 239 client_->OnWebLayoutContentsSizeChanged(contents_size); | 240 client_->OnWebLayoutContentsSizeChanged(contents_size); |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace android_webview | 243 } // namespace android_webview |
| OLD | NEW |