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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 if (document_state->can_load_local_resources()) { | 209 if (document_state->can_load_local_resources()) { |
209 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); | 210 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); |
210 origin.grantLoadLocalResources(); | 211 origin.grantLoadLocalResources(); |
211 } | 212 } |
212 } | 213 } |
213 | 214 |
214 void AwRenderViewExt::DidCommitCompositorFrame() { | 215 void AwRenderViewExt::DidCommitCompositorFrame() { |
215 UpdatePageScaleFactor(); | 216 UpdatePageScaleFactor(); |
216 } | 217 } |
217 | 218 |
| 219 void AwRenderViewExt::DidUpdateLayout() { |
| 220 if (check_contents_size_timer_.IsRunning()) |
| 221 return; |
| 222 |
| 223 check_contents_size_timer_.Start(FROM_HERE, |
| 224 base::TimeDelta::FromMilliseconds(0), this, |
| 225 &AwRenderViewExt::CheckContentsSize); |
| 226 } |
| 227 |
218 void AwRenderViewExt::UpdatePageScaleFactor() { | 228 void AwRenderViewExt::UpdatePageScaleFactor() { |
219 if (page_scale_factor_ != render_view()->GetWebView()->pageScaleFactor()) { | 229 if (page_scale_factor_ != render_view()->GetWebView()->pageScaleFactor()) { |
220 page_scale_factor_ = render_view()->GetWebView()->pageScaleFactor(); | 230 page_scale_factor_ = render_view()->GetWebView()->pageScaleFactor(); |
221 Send(new AwViewHostMsg_PageScaleFactorChanged(routing_id(), | 231 Send(new AwViewHostMsg_PageScaleFactorChanged(routing_id(), |
222 page_scale_factor_)); | 232 page_scale_factor_)); |
223 } | 233 } |
224 } | 234 } |
225 | 235 |
| 236 void AwRenderViewExt::CheckContentsSize() { |
| 237 if (!render_view()->GetWebView()) |
| 238 return; |
| 239 |
| 240 gfx::Size contents_size; |
| 241 |
| 242 WebKit::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 243 if (main_frame) |
| 244 contents_size = main_frame->contentsSize(); |
| 245 |
| 246 // Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a |
| 247 // 0x0 size (this happens during initial load). |
| 248 if (contents_size.IsEmpty()) { |
| 249 contents_size = render_view()->GetWebView()->contentsPreferredMinimumSize(); |
| 250 } |
| 251 |
| 252 if (contents_size == last_sent_contents_size_) |
| 253 return; |
| 254 |
| 255 last_sent_contents_size_ = contents_size; |
| 256 Send(new AwViewHostMsg_OnContentsSizeChanged(routing_id(), contents_size)); |
| 257 } |
| 258 |
226 void AwRenderViewExt::Navigate(const GURL& url) { | 259 void AwRenderViewExt::Navigate(const GURL& url) { |
227 // 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 |
228 // 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, |
229 // 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 |
230 // 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 |
231 // the browser side (in RenderViewHostManger), to the IPCmessages and to the | 264 // the browser side (in RenderViewHostManger), to the IPCmessages and to the |
232 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems | 265 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems |
233 // a more acceptable compromise. | 266 // a more acceptable compromise. |
234 WebKit::WebImageCache::clear(); | 267 WebKit::WebImageCache::clear(); |
235 } | 268 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 render_view()->GetWebView()->setFixedLayoutSize(size); | 345 render_view()->GetWebView()->setFixedLayoutSize(size); |
313 } | 346 } |
314 | 347 |
315 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { | 348 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { |
316 if (!render_view() || !render_view()->GetWebView()) | 349 if (!render_view() || !render_view()->GetWebView()) |
317 return; | 350 return; |
318 render_view()->GetWebView()->setBaseBackgroundColor(c); | 351 render_view()->GetWebView()->setBaseBackgroundColor(c); |
319 } | 352 } |
320 | 353 |
321 } // namespace android_webview | 354 } // namespace android_webview |
OLD | NEW |