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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "third_party/WebKit/public/web/WebNodeList.h" | 30 #include "third_party/WebKit/public/web/WebNodeList.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 bool AllowMixedContent(const WebKit::WebURL& url) { | 40 bool AllowMixedContent(const blink::WebURL& url) { |
41 // We treat non-standard schemes as "secure" in the WebView to allow them to | 41 // We treat non-standard schemes as "secure" in the WebView to allow them to |
42 // be used for request interception. | 42 // be used for request interception. |
43 // TODO(benm): Tighten this restriction by requiring embedders to register | 43 // TODO(benm): Tighten this restriction by requiring embedders to register |
44 // their custom schemes? See b/9420953. | 44 // their custom schemes? See b/9420953. |
45 GURL gurl(url); | 45 GURL gurl(url); |
46 return !gurl.IsStandard(); | 46 return !gurl.IsStandard(); |
47 } | 47 } |
48 | 48 |
49 GURL GetAbsoluteUrl(const WebKit::WebNode& node, const string16& url_fragment) { | 49 GURL GetAbsoluteUrl(const blink::WebNode& node, const string16& url_fragment) { |
50 return GURL(node.document().completeURL(url_fragment)); | 50 return GURL(node.document().completeURL(url_fragment)); |
51 } | 51 } |
52 | 52 |
53 string16 GetHref(const WebKit::WebElement& element) { | 53 string16 GetHref(const blink::WebElement& element) { |
54 // Get the actual 'href' attribute, which might relative if valid or can | 54 // Get the actual 'href' attribute, which might relative if valid or can |
55 // possibly contain garbage otherwise, so not using absoluteLinkURL here. | 55 // possibly contain garbage otherwise, so not using absoluteLinkURL here. |
56 return element.getAttribute("href"); | 56 return element.getAttribute("href"); |
57 } | 57 } |
58 | 58 |
59 GURL GetAbsoluteSrcUrl(const WebKit::WebElement& element) { | 59 GURL GetAbsoluteSrcUrl(const blink::WebElement& element) { |
60 if (element.isNull()) | 60 if (element.isNull()) |
61 return GURL(); | 61 return GURL(); |
62 return GetAbsoluteUrl(element, element.getAttribute("src")); | 62 return GetAbsoluteUrl(element, element.getAttribute("src")); |
63 } | 63 } |
64 | 64 |
65 WebKit::WebNode GetImgChild(const WebKit::WebNode& node) { | 65 blink::WebNode GetImgChild(const blink::WebNode& node) { |
66 // This implementation is incomplete (for example if is an area tag) but | 66 // This implementation is incomplete (for example if is an area tag) but |
67 // matches the original WebViewClassic implementation. | 67 // matches the original WebViewClassic implementation. |
68 | 68 |
69 WebKit::WebNodeList list = node.getElementsByTagName("img"); | 69 blink::WebNodeList list = node.getElementsByTagName("img"); |
70 if (list.length() > 0) | 70 if (list.length() > 0) |
71 return list.item(0); | 71 return list.item(0); |
72 return WebKit::WebNode(); | 72 return blink::WebNode(); |
73 } | 73 } |
74 | 74 |
75 bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix, | 75 bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix, |
76 const GURL& url, | 76 const GURL& url, |
77 std::string* dest) { | 77 std::string* dest) { |
78 const base::StringPiece spec(url.possibly_invalid_spec()); | 78 const base::StringPiece spec(url.possibly_invalid_spec()); |
79 | 79 |
80 if (spec.starts_with(prefix)) { | 80 if (spec.starts_with(prefix)) { |
81 url_canon::RawCanonOutputW<1024> output; | 81 url_canon::RawCanonOutputW<1024> output; |
82 url_util::DecodeURLEscapeSequences(spec.data() + prefix.length(), | 82 url_util::DecodeURLEscapeSequences(spec.data() + prefix.length(), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 IPC_MESSAGE_HANDLER(AwViewMsg_SetFixedLayoutSize, OnSetFixedLayoutSize) | 168 IPC_MESSAGE_HANDLER(AwViewMsg_SetFixedLayoutSize, OnSetFixedLayoutSize) |
169 IPC_MESSAGE_HANDLER(AwViewMsg_SetBackgroundColor, OnSetBackgroundColor) | 169 IPC_MESSAGE_HANDLER(AwViewMsg_SetBackgroundColor, OnSetBackgroundColor) |
170 IPC_MESSAGE_UNHANDLED(handled = false) | 170 IPC_MESSAGE_UNHANDLED(handled = false) |
171 IPC_END_MESSAGE_MAP() | 171 IPC_END_MESSAGE_MAP() |
172 return handled; | 172 return handled; |
173 } | 173 } |
174 | 174 |
175 void AwRenderViewExt::OnDocumentHasImagesRequest(int id) { | 175 void AwRenderViewExt::OnDocumentHasImagesRequest(int id) { |
176 bool hasImages = false; | 176 bool hasImages = false; |
177 if (render_view()) { | 177 if (render_view()) { |
178 WebKit::WebView* webview = render_view()->GetWebView(); | 178 blink::WebView* webview = render_view()->GetWebView(); |
179 if (webview) { | 179 if (webview) { |
180 WebKit::WebVector<WebKit::WebElement> images; | 180 blink::WebVector<blink::WebElement> images; |
181 webview->mainFrame()->document().images(images); | 181 webview->mainFrame()->document().images(images); |
182 hasImages = !images.isEmpty(); | 182 hasImages = !images.isEmpty(); |
183 } | 183 } |
184 } | 184 } |
185 Send(new AwViewHostMsg_DocumentHasImagesResponse(routing_id(), id, | 185 Send(new AwViewHostMsg_DocumentHasImagesResponse(routing_id(), id, |
186 hasImages)); | 186 hasImages)); |
187 } | 187 } |
188 | 188 |
189 bool AwRenderViewExt::allowDisplayingInsecureContent( | 189 bool AwRenderViewExt::allowDisplayingInsecureContent( |
190 WebKit::WebFrame* frame, | 190 blink::WebFrame* frame, |
191 bool enabled_per_settings, | 191 bool enabled_per_settings, |
192 const WebKit::WebSecurityOrigin& origin, | 192 const blink::WebSecurityOrigin& origin, |
193 const WebKit::WebURL& url) { | 193 const blink::WebURL& url) { |
194 return enabled_per_settings ? true : AllowMixedContent(url); | 194 return enabled_per_settings ? true : AllowMixedContent(url); |
195 } | 195 } |
196 | 196 |
197 bool AwRenderViewExt::allowRunningInsecureContent( | 197 bool AwRenderViewExt::allowRunningInsecureContent( |
198 WebKit::WebFrame* frame, | 198 blink::WebFrame* frame, |
199 bool enabled_per_settings, | 199 bool enabled_per_settings, |
200 const WebKit::WebSecurityOrigin& origin, | 200 const blink::WebSecurityOrigin& origin, |
201 const WebKit::WebURL& url) { | 201 const blink::WebURL& url) { |
202 return enabled_per_settings ? true : AllowMixedContent(url); | 202 return enabled_per_settings ? true : AllowMixedContent(url); |
203 } | 203 } |
204 | 204 |
205 void AwRenderViewExt::DidCommitProvisionalLoad(WebKit::WebFrame* frame, | 205 void AwRenderViewExt::DidCommitProvisionalLoad(blink::WebFrame* frame, |
206 bool is_new_navigation) { | 206 bool is_new_navigation) { |
207 content::DocumentState* document_state = | 207 content::DocumentState* document_state = |
208 content::DocumentState::FromDataSource(frame->dataSource()); | 208 content::DocumentState::FromDataSource(frame->dataSource()); |
209 if (document_state->can_load_local_resources()) { | 209 if (document_state->can_load_local_resources()) { |
210 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); | 210 blink::WebSecurityOrigin origin = frame->document().securityOrigin(); |
211 origin.grantLoadLocalResources(); | 211 origin.grantLoadLocalResources(); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 void AwRenderViewExt::DidCommitCompositorFrame() { | 215 void AwRenderViewExt::DidCommitCompositorFrame() { |
216 UpdatePageScaleFactor(); | 216 UpdatePageScaleFactor(); |
217 } | 217 } |
218 | 218 |
219 void AwRenderViewExt::DidUpdateLayout() { | 219 void AwRenderViewExt::DidUpdateLayout() { |
220 if (check_contents_size_timer_.IsRunning()) | 220 if (check_contents_size_timer_.IsRunning()) |
(...skipping 11 matching lines...) Expand all Loading... |
232 page_scale_factor_)); | 232 page_scale_factor_)); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 void AwRenderViewExt::CheckContentsSize() { | 236 void AwRenderViewExt::CheckContentsSize() { |
237 if (!render_view()->GetWebView()) | 237 if (!render_view()->GetWebView()) |
238 return; | 238 return; |
239 | 239 |
240 gfx::Size contents_size; | 240 gfx::Size contents_size; |
241 | 241 |
242 WebKit::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 242 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
243 if (main_frame) | 243 if (main_frame) |
244 contents_size = main_frame->contentsSize(); | 244 contents_size = main_frame->contentsSize(); |
245 | 245 |
246 // Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a | 246 // Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a |
247 // 0x0 size (this happens during initial load). | 247 // 0x0 size (this happens during initial load). |
248 if (contents_size.IsEmpty()) { | 248 if (contents_size.IsEmpty()) { |
249 contents_size = render_view()->GetWebView()->contentsPreferredMinimumSize(); | 249 contents_size = render_view()->GetWebView()->contentsPreferredMinimumSize(); |
250 } | 250 } |
251 | 251 |
252 if (contents_size == last_sent_contents_size_) | 252 if (contents_size == last_sent_contents_size_) |
253 return; | 253 return; |
254 | 254 |
255 last_sent_contents_size_ = contents_size; | 255 last_sent_contents_size_ = contents_size; |
256 Send(new AwViewHostMsg_OnContentsSizeChanged(routing_id(), contents_size)); | 256 Send(new AwViewHostMsg_OnContentsSizeChanged(routing_id(), contents_size)); |
257 } | 257 } |
258 | 258 |
259 void AwRenderViewExt::Navigate(const GURL& url) { | 259 void AwRenderViewExt::Navigate(const GURL& url) { |
260 // Navigate is called only on NEW navigations, so WebImageCache won't be freed | 260 // Navigate is called only on NEW navigations, so WebImageCache won't be freed |
261 // when the user just clicks on links, but only when a navigation is started, | 261 // when the user just clicks on links, but only when a navigation is started, |
262 // for instance via loadUrl. A better approach would be clearing the cache on | 262 // for instance via loadUrl. A better approach would be clearing the cache on |
263 // cross-site boundaries, however this would require too many changes both on | 263 // cross-site boundaries, however this would require too many changes both on |
264 // the browser side (in RenderViewHostManger), to the IPCmessages and to the | 264 // the browser side (in RenderViewHostManger), to the IPCmessages and to the |
265 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems | 265 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems |
266 // a more acceptable compromise. | 266 // a more acceptable compromise. |
267 WebKit::WebImageCache::clear(); | 267 blink::WebImageCache::clear(); |
268 } | 268 } |
269 | 269 |
270 void AwRenderViewExt::FocusedNodeChanged(const WebKit::WebNode& node) { | 270 void AwRenderViewExt::FocusedNodeChanged(const blink::WebNode& node) { |
271 if (node.isNull() || !node.isElementNode() || !render_view()) | 271 if (node.isNull() || !node.isElementNode() || !render_view()) |
272 return; | 272 return; |
273 | 273 |
274 // Note: element is not const due to innerText() is not const. | 274 // Note: element is not const due to innerText() is not const. |
275 WebKit::WebElement element = node.toConst<WebKit::WebElement>(); | 275 blink::WebElement element = node.toConst<blink::WebElement>(); |
276 AwHitTestData data; | 276 AwHitTestData data; |
277 | 277 |
278 data.href = GetHref(element); | 278 data.href = GetHref(element); |
279 data.anchor_text = element.innerText(); | 279 data.anchor_text = element.innerText(); |
280 | 280 |
281 GURL absolute_link_url; | 281 GURL absolute_link_url; |
282 if (node.isLink()) | 282 if (node.isLink()) |
283 absolute_link_url = GetAbsoluteUrl(node, data.href); | 283 absolute_link_url = GetAbsoluteUrl(node, data.href); |
284 | 284 |
285 GURL absolute_image_url; | 285 GURL absolute_image_url; |
286 const WebKit::WebNode child_img = GetImgChild(node); | 286 const blink::WebNode child_img = GetImgChild(node); |
287 if (!child_img.isNull() && child_img.isElementNode()) { | 287 if (!child_img.isNull() && child_img.isElementNode()) { |
288 absolute_image_url = | 288 absolute_image_url = |
289 GetAbsoluteSrcUrl(child_img.toConst<WebKit::WebElement>()); | 289 GetAbsoluteSrcUrl(child_img.toConst<blink::WebElement>()); |
290 } | 290 } |
291 | 291 |
292 PopulateHitTestData(absolute_link_url, | 292 PopulateHitTestData(absolute_link_url, |
293 absolute_image_url, | 293 absolute_image_url, |
294 render_view()->IsEditableNode(node), | 294 render_view()->IsEditableNode(node), |
295 &data); | 295 &data); |
296 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); | 296 Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); |
297 } | 297 } |
298 | 298 |
299 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { | 299 void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { |
300 if (!render_view() || !render_view()->GetWebView()) | 300 if (!render_view() || !render_view()->GetWebView()) |
301 return; | 301 return; |
302 | 302 |
303 const WebKit::WebHitTestResult result = | 303 const blink::WebHitTestResult result = |
304 render_view()->GetWebView()->hitTestResultAt( | 304 render_view()->GetWebView()->hitTestResultAt( |
305 WebKit::WebPoint(view_x, view_y)); | 305 blink::WebPoint(view_x, view_y)); |
306 AwHitTestData data; | 306 AwHitTestData data; |
307 | 307 |
308 if (!result.urlElement().isNull()) { | 308 if (!result.urlElement().isNull()) { |
309 data.anchor_text = result.urlElement().innerText(); | 309 data.anchor_text = result.urlElement().innerText(); |
310 data.href = GetHref(result.urlElement()); | 310 data.href = GetHref(result.urlElement()); |
311 } | 311 } |
312 | 312 |
313 PopulateHitTestData(result.absoluteLinkURL(), | 313 PopulateHitTestData(result.absoluteLinkURL(), |
314 result.absoluteImageURL(), | 314 result.absoluteImageURL(), |
315 result.isContentEditable(), | 315 result.isContentEditable(), |
(...skipping 28 matching lines...) Expand all Loading... |
344 render_view()->GetWebView()->setFixedLayoutSize(size); | 344 render_view()->GetWebView()->setFixedLayoutSize(size); |
345 } | 345 } |
346 | 346 |
347 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { | 347 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { |
348 if (!render_view() || !render_view()->GetWebView()) | 348 if (!render_view() || !render_view()->GetWebView()) |
349 return; | 349 return; |
350 render_view()->GetWebView()->setBaseBackgroundColor(c); | 350 render_view()->GetWebView()->setBaseBackgroundColor(c); |
351 } | 351 } |
352 | 352 |
353 } // namespace android_webview | 353 } // namespace android_webview |
OLD | NEW |