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