| 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/WebSecurityOrigin.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 30 #include "third_party/skia/include/core/SkPicture.h" |
| 29 | 31 |
| 30 namespace android_webview { | 32 namespace android_webview { |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix, | 36 bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix, |
| 35 const GURL& url, | 37 const GURL& url, |
| 36 std::string* dest) { | 38 std::string* dest) { |
| 37 const base::StringPiece spec(url.spec()); | 39 const base::StringPiece spec(url.spec()); |
| 38 | 40 |
| 39 if (spec.starts_with(prefix)) { | 41 if (spec.starts_with(prefix)) { |
| 40 dest->assign(spec.begin() + prefix.length(), spec.end()); | 42 dest->assign(spec.begin() + prefix.length(), spec.end()); |
| 41 return true; | 43 return true; |
| 42 } | 44 } |
| 43 return false; | 45 return false; |
| 44 } | 46 } |
| 45 | 47 |
| 46 } | 48 } |
| 47 | 49 |
| 48 AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) | 50 AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) |
| 49 : content::RenderViewObserver(render_view) { | 51 : content::RenderViewObserver(render_view) { |
| 50 render_view->GetWebView()->setPermissionClient(this); | 52 render_view->GetWebView()->setPermissionClient(this); |
| 51 // TODO(leandrogracia): enable once the feature is available in RenderView. | |
| 52 // TODO(leandrogracia): remove when SW rendering uses Ubercompositor. | 53 // TODO(leandrogracia): remove when SW rendering uses Ubercompositor. |
| 53 // Until then we need the callback enabled for SW mode invalidation. | 54 // Until then we need the callback enabled for SW mode invalidation. |
| 54 // http://crbug.com/170086. | 55 // http://crbug.com/170086. |
| 55 //render_view->SetCapturePictureCallback( | 56 capture_picture_enabled_ = true; |
| 56 // base::Bind(&AwRenderViewExt::OnPictureUpdate, AsWeakPtr())); | |
| 57 } | 57 } |
| 58 | 58 |
| 59 AwRenderViewExt::~AwRenderViewExt() { | 59 AwRenderViewExt::~AwRenderViewExt() { |
| 60 // TODO(leandrogracia): enable once the feature is available in RenderView. | |
| 61 //render_view()->SetCapturePictureCallback( | |
| 62 // content::RenderView::CapturePictureCallback()); | |
| 63 RendererPictureMap::GetInstance()->ClearRendererPicture(routing_id()); | 60 RendererPictureMap::GetInstance()->ClearRendererPicture(routing_id()); |
| 64 } | 61 } |
| 65 | 62 |
| 66 // static | 63 // static |
| 67 void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { | 64 void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { |
| 68 new AwRenderViewExt(render_view); // |render_view| takes ownership. | 65 new AwRenderViewExt(render_view); // |render_view| takes ownership. |
| 69 } | 66 } |
| 70 | 67 |
| 71 bool AwRenderViewExt::OnMessageReceived(const IPC::Message& message) { | 68 bool AwRenderViewExt::OnMessageReceived(const IPC::Message& message) { |
| 72 bool handled = true; | 69 bool handled = true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 data.type = AwHitTestData::EDIT_TEXT_TYPE; | 125 data.type = AwHitTestData::EDIT_TEXT_TYPE; |
| 129 Send(new AwViewHostMsg_UpdateHitTestData( | 126 Send(new AwViewHostMsg_UpdateHitTestData( |
| 130 routing_id(), data)); | 127 routing_id(), data)); |
| 131 } else { | 128 } else { |
| 132 // TODO(boliu): Implement this path. | 129 // TODO(boliu): Implement this path. |
| 133 NOTIMPLEMENTED() << "Tab focused links not implemented"; | 130 NOTIMPLEMENTED() << "Tab focused links not implemented"; |
| 134 } | 131 } |
| 135 } | 132 } |
| 136 } | 133 } |
| 137 | 134 |
| 135 void AwRenderViewExt::DidCommitCompositorFrame() { |
| 136 if (!capture_picture_enabled_) |
| 137 return; |
| 138 |
| 139 skia::RefPtr<SkPicture> picture = render_view()->CapturePicture(); |
| 140 RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture); |
| 141 Send(new AwViewHostMsg_PictureUpdated(routing_id())); |
| 142 } |
| 143 |
| 138 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { | 144 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { |
| 139 if (!render_view() || !render_view()->GetWebView()) | 145 if (!render_view() || !render_view()->GetWebView()) |
| 140 return; | 146 return; |
| 141 | 147 |
| 142 const WebKit::WebHitTestResult result = | 148 const WebKit::WebHitTestResult result = |
| 143 render_view()->GetWebView()->hitTestResultAt( | 149 render_view()->GetWebView()->hitTestResultAt( |
| 144 WebKit::WebPoint(view_x, view_y)); | 150 WebKit::WebPoint(view_x, view_y)); |
| 145 AwHitTestData data; | 151 AwHitTestData data; |
| 146 | 152 |
| 147 // Populate fixed AwHitTestData fields. | 153 // Populate fixed AwHitTestData fields. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 data.extra_data_for_type = data.img_src.spec(); | 198 data.extra_data_for_type = data.img_src.spec(); |
| 193 } else if (result.isContentEditable()) { | 199 } else if (result.isContentEditable()) { |
| 194 data.type = AwHitTestData::EDIT_TEXT_TYPE; | 200 data.type = AwHitTestData::EDIT_TEXT_TYPE; |
| 195 DCHECK(data.extra_data_for_type.length() == 0); | 201 DCHECK(data.extra_data_for_type.length() == 0); |
| 196 } | 202 } |
| 197 | 203 |
| 198 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); | 204 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); |
| 199 } | 205 } |
| 200 | 206 |
| 201 void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) { | 207 void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) { |
| 202 // TODO(leandrogracia): enable once the feature is available in RenderView. | 208 capture_picture_enabled_ = enable; |
| 203 //render_view()->SetCapturePictureCallback(enable ? | |
| 204 // base::Bind(&AwRenderViewExt::OnPictureUpdate, AsWeakPtr()) : | |
| 205 // content::RenderView::CapturePictureCallback()); | |
| 206 } | |
| 207 | |
| 208 void AwRenderViewExt::OnPictureUpdate(skia::RefPtr<SkPicture> picture) { | |
| 209 RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture); | |
| 210 Send(new AwViewHostMsg_PictureUpdated(routing_id())); | |
| 211 } | 209 } |
| 212 | 210 |
| 213 void AwRenderViewExt::OnCapturePictureSync() { | 211 void AwRenderViewExt::OnCapturePictureSync() { |
| 214 // TODO(leandrogracia): enable once the feature is available in RenderView. | 212 RendererPictureMap::GetInstance()->SetRendererPicture( |
| 215 //RendererPictureMap::GetInstance()->SetRendererPicture( | 213 routing_id(), render_view()->CapturePicture()); |
| 216 // routing_id(), render_view()->CapturePicture()); | |
| 217 } | 214 } |
| 218 | 215 |
| 219 } // namespace android_webview | 216 } // namespace android_webview |
| OLD | NEW |