| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 data->extra_data_for_type = data->img_src.possibly_invalid_spec(); | 137 data->extra_data_for_type = data->img_src.possibly_invalid_spec(); |
| 137 } else if (is_editable) { | 138 } else if (is_editable) { |
| 138 data->type = AwHitTestData::EDIT_TEXT_TYPE; | 139 data->type = AwHitTestData::EDIT_TEXT_TYPE; |
| 139 DCHECK(data->extra_data_for_type.length() == 0); | 140 DCHECK(data->extra_data_for_type.length() == 0); |
| 140 } | 141 } |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace | 144 } // namespace |
| 144 | 145 |
| 145 AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) | 146 AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) |
| 146 : content::RenderViewObserver(render_view), page_scale_factor_(0.0f) { | 147 : content::RenderViewObserver(render_view), |
| 148 page_scale_factor_(0.0f), |
| 149 send_contents_size_updates_(false) { |
| 147 render_view->GetWebView()->setPermissionClient(this); | 150 render_view->GetWebView()->setPermissionClient(this); |
| 148 } | 151 } |
| 149 | 152 |
| 150 AwRenderViewExt::~AwRenderViewExt() { | 153 AwRenderViewExt::~AwRenderViewExt() { |
| 151 } | 154 } |
| 152 | 155 |
| 153 // static | 156 // static |
| 154 void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { | 157 void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { |
| 155 new AwRenderViewExt(render_view); // |render_view| takes ownership. | 158 new AwRenderViewExt(render_view); // |render_view| takes ownership. |
| 156 } | 159 } |
| 157 | 160 |
| 158 bool AwRenderViewExt::OnMessageReceived(const IPC::Message& message) { | 161 bool AwRenderViewExt::OnMessageReceived(const IPC::Message& message) { |
| 159 bool handled = true; | 162 bool handled = true; |
| 160 IPC_BEGIN_MESSAGE_MAP(AwRenderViewExt, message) | 163 IPC_BEGIN_MESSAGE_MAP(AwRenderViewExt, message) |
| 161 IPC_MESSAGE_HANDLER(AwViewMsg_DocumentHasImages, OnDocumentHasImagesRequest) | 164 IPC_MESSAGE_HANDLER(AwViewMsg_DocumentHasImages, OnDocumentHasImagesRequest) |
| 162 IPC_MESSAGE_HANDLER(AwViewMsg_DoHitTest, OnDoHitTest) | 165 IPC_MESSAGE_HANDLER(AwViewMsg_DoHitTest, OnDoHitTest) |
| 163 IPC_MESSAGE_HANDLER(AwViewMsg_SetTextZoomLevel, OnSetTextZoomLevel) | 166 IPC_MESSAGE_HANDLER(AwViewMsg_SetTextZoomLevel, OnSetTextZoomLevel) |
| 164 IPC_MESSAGE_HANDLER(AwViewMsg_ResetScrollAndScaleState, | 167 IPC_MESSAGE_HANDLER(AwViewMsg_ResetScrollAndScaleState, |
| 165 OnResetScrollAndScaleState) | 168 OnResetScrollAndScaleState) |
| 166 IPC_MESSAGE_HANDLER(AwViewMsg_SetInitialPageScale, OnSetInitialPageScale) | 169 IPC_MESSAGE_HANDLER(AwViewMsg_SetInitialPageScale, OnSetInitialPageScale) |
| 167 IPC_MESSAGE_HANDLER(AwViewMsg_SetBackgroundColor, OnSetBackgroundColor) | 170 IPC_MESSAGE_HANDLER(AwViewMsg_SetBackgroundColor, OnSetBackgroundColor) |
| 171 IPC_MESSAGE_HANDLER(AwViewMsg_EnableContentsSizeNotifications, |
| 172 OnEnableContentsSizeNotifications) |
| 168 IPC_MESSAGE_UNHANDLED(handled = false) | 173 IPC_MESSAGE_UNHANDLED(handled = false) |
| 169 IPC_END_MESSAGE_MAP() | 174 IPC_END_MESSAGE_MAP() |
| 170 return handled; | 175 return handled; |
| 171 } | 176 } |
| 172 | 177 |
| 173 void AwRenderViewExt::OnDocumentHasImagesRequest(int id) { | 178 void AwRenderViewExt::OnDocumentHasImagesRequest(int id) { |
| 174 bool hasImages = false; | 179 bool hasImages = false; |
| 175 if (render_view()) { | 180 if (render_view()) { |
| 176 WebKit::WebView* webview = render_view()->GetWebView(); | 181 WebKit::WebView* webview = render_view()->GetWebView(); |
| 177 if (webview) { | 182 if (webview) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 207 if (document_state->can_load_local_resources()) { | 212 if (document_state->can_load_local_resources()) { |
| 208 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); | 213 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 209 origin.grantLoadLocalResources(); | 214 origin.grantLoadLocalResources(); |
| 210 } | 215 } |
| 211 } | 216 } |
| 212 | 217 |
| 213 void AwRenderViewExt::DidCommitCompositorFrame() { | 218 void AwRenderViewExt::DidCommitCompositorFrame() { |
| 214 UpdatePageScaleFactor(); | 219 UpdatePageScaleFactor(); |
| 215 } | 220 } |
| 216 | 221 |
| 222 void AwRenderViewExt::DidUpdateLayout() { |
| 223 if (!send_contents_size_updates_) |
| 224 return; |
| 225 |
| 226 if (check_contents_size_timer_.IsRunning()) |
| 227 return; |
| 228 |
| 229 check_contents_size_timer_.Start(FROM_HERE, |
| 230 base::TimeDelta::FromMilliseconds(0), this, |
| 231 &AwRenderViewExt::CheckContentsSize); |
| 232 } |
| 233 |
| 217 void AwRenderViewExt::UpdatePageScaleFactor() { | 234 void AwRenderViewExt::UpdatePageScaleFactor() { |
| 218 if (page_scale_factor_ != render_view()->GetWebView()->pageScaleFactor()) { | 235 if (page_scale_factor_ != render_view()->GetWebView()->pageScaleFactor()) { |
| 219 page_scale_factor_ = render_view()->GetWebView()->pageScaleFactor(); | 236 page_scale_factor_ = render_view()->GetWebView()->pageScaleFactor(); |
| 220 Send(new AwViewHostMsg_PageScaleFactorChanged(routing_id(), | 237 Send(new AwViewHostMsg_PageScaleFactorChanged(routing_id(), |
| 221 page_scale_factor_)); | 238 page_scale_factor_)); |
| 222 } | 239 } |
| 223 } | 240 } |
| 224 | 241 |
| 242 void AwRenderViewExt::OnEnableContentsSizeNotifications() { |
| 243 send_contents_size_updates_ = true; |
| 244 last_sent_contents_size_ = gfx::Size(); |
| 245 CheckContentsSize(); |
| 246 } |
| 247 |
| 248 void AwRenderViewExt::CheckContentsSize() { |
| 249 if (!send_contents_size_updates_) |
| 250 return; |
| 251 |
| 252 if (!render_view()->GetWebView() || |
| 253 !render_view()->GetWebView()->mainFrame()) |
| 254 return; |
| 255 |
| 256 gfx::Size contents_size = |
| 257 render_view()->GetWebView()->mainFrame()->contentsSize(); |
| 258 |
| 259 if (contents_size == last_sent_contents_size_) |
| 260 return; |
| 261 |
| 262 last_sent_contents_size_ = contents_size; |
| 263 Send(new AwViewHostMsg_OnContentsSizeChanged(routing_id(), contents_size)); |
| 264 } |
| 265 |
| 225 void AwRenderViewExt::Navigate(const GURL& url) { | 266 void AwRenderViewExt::Navigate(const GURL& url) { |
| 226 // Navigate is called only on NEW navigations, so WebImageCache won't be freed | 267 // 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, | 268 // 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 | 269 // 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 | 270 // cross-site boundaries, however this would require too many changes both on |
| 230 // the browser side (in RenderViewHostManger), to the IPCmessages and to the | 271 // the browser side (in RenderViewHostManger), to the IPCmessages and to the |
| 231 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems | 272 // RenderViewObserver. Thus, clearing decoding image cache on Navigate, seems |
| 232 // a more acceptable compromise. | 273 // a more acceptable compromise. |
| 233 WebKit::WebImageCache::clear(); | 274 WebKit::WebImageCache::clear(); |
| 234 } | 275 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 page_scale_factor); | 345 page_scale_factor); |
| 305 } | 346 } |
| 306 | 347 |
| 307 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { | 348 void AwRenderViewExt::OnSetBackgroundColor(SkColor c) { |
| 308 if (!render_view() || !render_view()->GetWebView()) | 349 if (!render_view() || !render_view()->GetWebView()) |
| 309 return; | 350 return; |
| 310 render_view()->GetWebView()->setBaseBackgroundColor(c); | 351 render_view()->GetWebView()->setBaseBackgroundColor(c); |
| 311 } | 352 } |
| 312 | 353 |
| 313 } // namespace android_webview | 354 } // namespace android_webview |
| OLD | NEW |