Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Side by Side Diff: android_webview/renderer/aw_render_view_ext.cc

Issue 149313005: Update android WebView to use WebElementCollection instead of WebNodeCollection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 11 #include "base/bind.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
16 #include "content/public/renderer/android_content_detection_prefixes.h" 16 #include "content/public/renderer/android_content_detection_prefixes.h"
17 #include "content/public/renderer/document_state.h" 17 #include "content/public/renderer/document_state.h"
18 #include "content/public/renderer/render_view.h" 18 #include "content/public/renderer/render_view.h"
19 #include "skia/ext/refptr.h" 19 #include "skia/ext/refptr.h"
20 #include "third_party/WebKit/public/platform/WebSize.h" 20 #include "third_party/WebKit/public/platform/WebSize.h"
21 #include "third_party/WebKit/public/platform/WebURL.h" 21 #include "third_party/WebKit/public/platform/WebURL.h"
22 #include "third_party/WebKit/public/platform/WebVector.h" 22 #include "third_party/WebKit/public/platform/WebVector.h"
23 #include "third_party/WebKit/public/web/WebDataSource.h" 23 #include "third_party/WebKit/public/web/WebDataSource.h"
24 #include "third_party/WebKit/public/web/WebDocument.h" 24 #include "third_party/WebKit/public/web/WebDocument.h"
25 #include "third_party/WebKit/public/web/WebElement.h" 25 #include "third_party/WebKit/public/web/WebElement.h"
26 #include "third_party/WebKit/public/web/WebElementCollection.h"
26 #include "third_party/WebKit/public/web/WebFrame.h" 27 #include "third_party/WebKit/public/web/WebFrame.h"
27 #include "third_party/WebKit/public/web/WebHitTestResult.h" 28 #include "third_party/WebKit/public/web/WebHitTestResult.h"
28 #include "third_party/WebKit/public/web/WebImageCache.h" 29 #include "third_party/WebKit/public/web/WebImageCache.h"
29 #include "third_party/WebKit/public/web/WebNode.h" 30 #include "third_party/WebKit/public/web/WebNode.h"
30 #include "third_party/WebKit/public/web/WebNodeCollection.h"
31 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 31 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
32 #include "third_party/WebKit/public/web/WebView.h" 32 #include "third_party/WebKit/public/web/WebView.h"
33 #include "url/url_canon.h" 33 #include "url/url_canon.h"
34 #include "url/url_util.h" 34 #include "url/url_util.h"
35 35
36 namespace android_webview { 36 namespace android_webview {
37 37
38 namespace { 38 namespace {
39 39
40 GURL GetAbsoluteUrl(const blink::WebNode& node, 40 GURL GetAbsoluteUrl(const blink::WebNode& node,
41 const base::string16& url_fragment) { 41 const base::string16& url_fragment) {
42 return GURL(node.document().completeURL(url_fragment)); 42 return GURL(node.document().completeURL(url_fragment));
43 } 43 }
44 44
45 base::string16 GetHref(const blink::WebElement& element) { 45 base::string16 GetHref(const blink::WebElement& element) {
46 // Get the actual 'href' attribute, which might relative if valid or can 46 // Get the actual 'href' attribute, which might relative if valid or can
47 // possibly contain garbage otherwise, so not using absoluteLinkURL here. 47 // possibly contain garbage otherwise, so not using absoluteLinkURL here.
48 return element.getAttribute("href"); 48 return element.getAttribute("href");
49 } 49 }
50 50
51 GURL GetAbsoluteSrcUrl(const blink::WebElement& element) { 51 GURL GetAbsoluteSrcUrl(const blink::WebElement& element) {
52 if (element.isNull()) 52 if (element.isNull())
53 return GURL(); 53 return GURL();
54 return GetAbsoluteUrl(element, element.getAttribute("src")); 54 return GetAbsoluteUrl(element, element.getAttribute("src"));
55 } 55 }
56 56
57 blink::WebNode GetImgChild(const blink::WebNode& node) { 57 blink::WebElement GetImgChild(const blink::WebElement& element) {
58 // This implementation is incomplete (for example if is an area tag) but 58 // This implementation is incomplete (for example if is an area tag) but
59 // matches the original WebViewClassic implementation. 59 // matches the original WebViewClassic implementation.
60 60
61 blink::WebNodeCollection collection = node.getElementsByTagName("img"); 61 blink::WebElementCollection collection = element.getElementsByTagName("img");
62 DCHECK(!collection.isNull()); 62 DCHECK(!collection.isNull());
63 return collection.firstItem(); 63 return collection.firstItem();
64 } 64 }
65 65
66 bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix, 66 bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix,
67 const GURL& url, 67 const GURL& url,
68 std::string* dest) { 68 std::string* dest) {
69 const base::StringPiece spec(url.possibly_invalid_spec()); 69 const base::StringPiece spec(url.possibly_invalid_spec());
70 70
71 if (spec.starts_with(prefix)) { 71 if (spec.starts_with(prefix)) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 AwHitTestData data; 254 AwHitTestData data;
255 255
256 data.href = GetHref(element); 256 data.href = GetHref(element);
257 data.anchor_text = element.innerText(); 257 data.anchor_text = element.innerText();
258 258
259 GURL absolute_link_url; 259 GURL absolute_link_url;
260 if (node.isLink()) 260 if (node.isLink())
261 absolute_link_url = GetAbsoluteUrl(node, data.href); 261 absolute_link_url = GetAbsoluteUrl(node, data.href);
262 262
263 GURL absolute_image_url; 263 GURL absolute_image_url;
264 const blink::WebNode child_img = GetImgChild(node); 264 const blink::WebElement child_img = GetImgChild(element);
265 if (!child_img.isNull() && child_img.isElementNode()) { 265 if (!child_img.isNull()) {
266 absolute_image_url = 266 absolute_image_url =
267 GetAbsoluteSrcUrl(child_img.toConst<blink::WebElement>()); 267 GetAbsoluteSrcUrl(child_img);
268 } 268 }
269 269
270 PopulateHitTestData(absolute_link_url, 270 PopulateHitTestData(absolute_link_url,
271 absolute_image_url, 271 absolute_image_url,
272 render_view()->IsEditableNode(node), 272 render_view()->IsEditableNode(node),
273 &data); 273 &data);
274 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); 274 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data));
275 } 275 }
276 276
277 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { 277 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 render_view()->GetWebView()->setFixedLayoutSize(size); 322 render_view()->GetWebView()->setFixedLayoutSize(size);
323 } 323 }
324 324
325 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { 325 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) {
326 if (!render_view() || !render_view()->GetWebView()) 326 if (!render_view() || !render_view()->GetWebView())
327 return; 327 return;
328 render_view()->GetWebView()->setBaseBackgroundColor(c); 328 render_view()->GetWebView()->setBaseBackgroundColor(c);
329 } 329 }
330 330
331 } // namespace android_webview 331 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698