| 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 "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 "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
| 15 #include "content/public/renderer/android_content_detection_prefixes.h" | 16 #include "content/public/renderer/android_content_detection_prefixes.h" |
| 16 #include "content/public/renderer/document_state.h" | 17 #include "content/public/renderer/document_state.h" |
| 17 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
| 18 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
| 19 #include "third_party/WebKit/public/platform/WebSize.h" | 20 #include "third_party/WebKit/public/platform/WebSize.h" |
| 20 #include "third_party/WebKit/public/platform/WebURL.h" | 21 #include "third_party/WebKit/public/platform/WebURL.h" |
| 21 #include "third_party/WebKit/public/platform/WebVector.h" | 22 #include "third_party/WebKit/public/platform/WebVector.h" |
| 22 #include "third_party/WebKit/public/web/WebDataSource.h" | 23 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 23 #include "third_party/WebKit/public/web/WebDocument.h" | 24 #include "third_party/WebKit/public/web/WebDocument.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (document_state->can_load_local_resources()) { | 208 if (document_state->can_load_local_resources()) { |
| 208 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); | 209 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 209 origin.grantLoadLocalResources(); | 210 origin.grantLoadLocalResources(); |
| 210 } | 211 } |
| 211 } | 212 } |
| 212 | 213 |
| 213 void AwRenderViewExt::DidCommitCompositorFrame() { | 214 void AwRenderViewExt::DidCommitCompositorFrame() { |
| 214 UpdatePageScaleFactor(); | 215 UpdatePageScaleFactor(); |
| 215 } | 216 } |
| 216 | 217 |
| 218 void AwRenderViewExt::DidUpdateLayout() { |
| 219 if (check_contents_size_timer_.IsRunning()) |
| 220 return; |
| 221 |
| 222 check_contents_size_timer_.Start(FROM_HERE, |
| 223 base::TimeDelta::FromMilliseconds(0), this, |
| 224 &AwRenderViewExt::CheckContentsSize); |
| 225 } |
| 226 |
| 217 void AwRenderViewExt::UpdatePageScaleFactor() { | 227 void AwRenderViewExt::UpdatePageScaleFactor() { |
| 218 if (page_scale_factor_ != render_view()->GetWebView()->pageScaleFactor()) { | 228 if (page_scale_factor_ != render_view()->GetWebView()->pageScaleFactor()) { |
| 219 page_scale_factor_ = render_view()->GetWebView()->pageScaleFactor(); | 229 page_scale_factor_ = render_view()->GetWebView()->pageScaleFactor(); |
| 220 Send(new AwViewHostMsg_PageScaleFactorChanged(routing_id(), | 230 Send(new AwViewHostMsg_PageScaleFactorChanged(routing_id(), |
| 221 page_scale_factor_)); | 231 page_scale_factor_)); |
| 222 } | 232 } |
| 223 } | 233 } |
| 224 | 234 |
| 235 void AwRenderViewExt::CheckContentsSize() { |
| 236 if (!render_view()->GetWebView()) |
| 237 return; |
| 238 |
| 239 gfx::Size contents_size; |
| 240 |
| 241 WebKit::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 242 if (main_frame) |
| 243 contents_size = main_frame->contentsSize(); |
| 244 |
| 245 // Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a |
| 246 // 0x0 size (this happens during initial load). |
| 247 if (contents_size.IsEmpty()) { |
| 248 contents_size = render_view()->GetWebView()->contentsPreferredMinimumSize(); |
| 249 } |
| 250 |
| 251 if (contents_size == last_sent_contents_size_) |
| 252 return; |
| 253 |
| 254 last_sent_contents_size_ = contents_size; |
| 255 Send(new AwViewHostMsg_OnContentsSizeChanged(routing_id(), contents_size)); |
| 256 } |
| 257 |
| 225 void AwRenderViewExt::Navigate(const GURL& url) { | 258 void AwRenderViewExt::Navigate(const GURL& url) { |
| 226 // Navigate is called only on NEW navigations, so WebImageCache won't be freed | 259 // Navigate is called only on NEW navigations, so WebImageCache won't be freed |
| 227 // when the user just clicks on links, but only when a navigation is started, | 260 // when the user just clicks on links, but only when a navigation is started, |
| 228 // for instance via loadUrl. A better approach would be clearing the cache on | 261 // for instance via loadUrl. A better approach would be clearing the cache on |
| 229 // cross-site boundaries, however this would require too many changes both on | 262 // cross-site boundaries, however this would require too many changes both on |
| 230 // the browser side (in RenderViewHostManger), to the IPCmessages and to the | 263 // the browser side (in RenderViewHostManger), to the IPCmessages and to the |
| 231 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems | 264 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems |
| 232 // a more acceptable compromise. | 265 // a more acceptable compromise. |
| 233 WebKit::WebImageCache::clear(); | 266 WebKit::WebImageCache::clear(); |
| 234 } | 267 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 page_scale_factor); | 337 page_scale_factor); |
| 305 } | 338 } |
| 306 | 339 |
| 307 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { | 340 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { |
| 308 if (!render_view() || !render_view()->GetWebView()) | 341 if (!render_view() || !render_view()->GetWebView()) |
| 309 return; | 342 return; |
| 310 render_view()->GetWebView()->setBaseBackgroundColor(c); | 343 render_view()->GetWebView()->setBaseBackgroundColor(c); |
| 311 } | 344 } |
| 312 | 345 |
| 313 } // namespace android_webview | 346 } // namespace android_webview |
| OLD | NEW |