| 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/renderer/aw_render_view_ext.h" | 5 #include "android_webview/renderer/aw_render_view_ext.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "android_webview/common/aw_hit_test_data.h" | 9 #include "android_webview/common/aw_hit_test_data.h" |
| 10 #include "android_webview/common/render_view_messages.h" | 10 #include "android_webview/common/render_view_messages.h" |
| 11 #include "android_webview/common/renderer_picture_map.h" | 11 #include "android_webview/common/renderer_picture_map.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
| 14 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 15 #include "content/public/renderer/android_content_detection_prefixes.h" | 15 #include "content/public/renderer/android_content_detection_prefixes.h" |
| 16 #include "content/public/renderer/document_state.h" | 16 #include "content/public/renderer/document_state.h" |
| 17 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
| 18 #include "skia/ext/refptr.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
| 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 31 #include "third_party/skia/include/core/SkPicture.h" |
| 30 | 32 |
| 31 namespace android_webview { | 33 namespace android_webview { |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 GURL GetAbsoluteUrl(const WebKit::WebNode& node, const string16& url_fragment) { | 37 GURL GetAbsoluteUrl(const WebKit::WebNode& node, const string16& url_fragment) { |
| 36 return GURL(node.document().completeURL(url_fragment)); | 38 return GURL(node.document().completeURL(url_fragment)); |
| 37 } | 39 } |
| 38 | 40 |
| 39 string16 GetHref(const WebKit::WebElement& element) { | 41 string16 GetHref(const WebKit::WebElement& element) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 data->type = AwHitTestData::EDIT_TEXT_TYPE; | 122 data->type = AwHitTestData::EDIT_TEXT_TYPE; |
| 121 DCHECK(data->extra_data_for_type.length() == 0); | 123 DCHECK(data->extra_data_for_type.length() == 0); |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 | 126 |
| 125 } // namespace | 127 } // namespace |
| 126 | 128 |
| 127 AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) | 129 AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) |
| 128 : content::RenderViewObserver(render_view) { | 130 : content::RenderViewObserver(render_view) { |
| 129 render_view->GetWebView()->setPermissionClient(this); | 131 render_view->GetWebView()->setPermissionClient(this); |
| 130 // TODO(leandrogracia): enable once the feature is available in RenderView. | |
| 131 // TODO(leandrogracia): remove when SW rendering uses Ubercompositor. | 132 // TODO(leandrogracia): remove when SW rendering uses Ubercompositor. |
| 132 // Until then we need the callback enabled for SW mode invalidation. | 133 // Until then we need the callback enabled for SW mode invalidation. |
| 133 // http://crbug.com/170086. | 134 // http://crbug.com/170086. |
| 134 //render_view->SetCapturePictureCallback( | 135 capture_picture_enabled_ = true; |
| 135 // base::Bind(&AwRenderViewExt::OnPictureUpdate, AsWeakPtr())); | |
| 136 } | 136 } |
| 137 | 137 |
| 138 AwRenderViewExt::~AwRenderViewExt() { | 138 AwRenderViewExt::~AwRenderViewExt() { |
| 139 // TODO(leandrogracia): enable once the feature is available in RenderView. | |
| 140 //render_view()->SetCapturePictureCallback( | |
| 141 // content::RenderView::CapturePictureCallback()); | |
| 142 RendererPictureMap::GetInstance()->ClearRendererPicture(routing_id()); | 139 RendererPictureMap::GetInstance()->ClearRendererPicture(routing_id()); |
| 143 } | 140 } |
| 144 | 141 |
| 145 // static | 142 // static |
| 146 void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { | 143 void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { |
| 147 new AwRenderViewExt(render_view); // |render_view| takes ownership. | 144 new AwRenderViewExt(render_view); // |render_view| takes ownership. |
| 148 } | 145 } |
| 149 | 146 |
| 150 bool AwRenderViewExt::OnMessageReceived(const IPC::Message& message) { | 147 bool AwRenderViewExt::OnMessageReceived(const IPC::Message& message) { |
| 151 bool handled = true; | 148 bool handled = true; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 GetAbsoluteSrcUrl(child_img.toConst<WebKit::WebElement>()); | 219 GetAbsoluteSrcUrl(child_img.toConst<WebKit::WebElement>()); |
| 223 } | 220 } |
| 224 | 221 |
| 225 PopulateHitTestData(absolute_link_url, | 222 PopulateHitTestData(absolute_link_url, |
| 226 absolute_image_url, | 223 absolute_image_url, |
| 227 render_view()->IsEditableNode(node), | 224 render_view()->IsEditableNode(node), |
| 228 &data); | 225 &data); |
| 229 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); | 226 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); |
| 230 } | 227 } |
| 231 | 228 |
| 229 void AwRenderViewExt::DidCommitCompositorFrame() { |
| 230 if (!capture_picture_enabled_) |
| 231 return; |
| 232 |
| 233 skia::RefPtr<SkPicture> picture = render_view()->CapturePicture(); |
| 234 RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture); |
| 235 Send(new AwViewHostMsg_PictureUpdated(routing_id())); |
| 236 } |
| 237 |
| 232 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { | 238 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { |
| 233 if (!render_view() || !render_view()->GetWebView()) | 239 if (!render_view() || !render_view()->GetWebView()) |
| 234 return; | 240 return; |
| 235 | 241 |
| 236 const WebKit::WebHitTestResult result = | 242 const WebKit::WebHitTestResult result = |
| 237 render_view()->GetWebView()->hitTestResultAt( | 243 render_view()->GetWebView()->hitTestResultAt( |
| 238 WebKit::WebPoint(view_x, view_y)); | 244 WebKit::WebPoint(view_x, view_y)); |
| 239 AwHitTestData data; | 245 AwHitTestData data; |
| 240 | 246 |
| 241 if (!result.urlElement().isNull()) { | 247 if (!result.urlElement().isNull()) { |
| 242 data.anchor_text = result.urlElement().innerText(); | 248 data.anchor_text = result.urlElement().innerText(); |
| 243 data.href = GetHref(result.urlElement()); | 249 data.href = GetHref(result.urlElement()); |
| 244 } | 250 } |
| 245 | 251 |
| 246 PopulateHitTestData(result.absoluteLinkURL(), | 252 PopulateHitTestData(result.absoluteLinkURL(), |
| 247 result.absoluteImageURL(), | 253 result.absoluteImageURL(), |
| 248 result.isContentEditable(), | 254 result.isContentEditable(), |
| 249 &data); | 255 &data); |
| 250 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); | 256 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); |
| 251 } | 257 } |
| 252 | 258 |
| 253 void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) { | 259 void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) { |
| 254 // TODO(leandrogracia): enable once the feature is available in RenderView. | 260 capture_picture_enabled_ = enable; |
| 255 //render_view()->SetCapturePictureCallback(enable ? | |
| 256 // base::Bind(&AwRenderViewExt::OnPictureUpdate, AsWeakPtr()) : | |
| 257 // content::RenderView::CapturePictureCallback()); | |
| 258 } | |
| 259 | |
| 260 void AwRenderViewExt::OnPictureUpdate(skia::RefPtr<SkPicture> picture) { | |
| 261 RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture); | |
| 262 Send(new AwViewHostMsg_PictureUpdated(routing_id())); | |
| 263 } | 261 } |
| 264 | 262 |
| 265 void AwRenderViewExt::OnCapturePictureSync() { | 263 void AwRenderViewExt::OnCapturePictureSync() { |
| 266 // TODO(leandrogracia): enable once the feature is available in RenderView. | 264 RendererPictureMap::GetInstance()->SetRendererPicture( |
| 267 //RendererPictureMap::GetInstance()->SetRendererPicture( | 265 routing_id(), render_view()->CapturePicture()); |
| 268 // routing_id(), render_view()->CapturePicture()); | |
| 269 } | 266 } |
| 270 | 267 |
| 271 } // namespace android_webview | 268 } // namespace android_webview |
| OLD | NEW |