Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/plugins/renderer/webview_plugin.h" | 5 #include "components/plugins/renderer/webview_plugin.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 using content::WebPreferences; | 48 using content::WebPreferences; |
| 49 | 49 |
| 50 WebViewPlugin::WebViewPlugin(content::RenderView* render_view, | 50 WebViewPlugin::WebViewPlugin(content::RenderView* render_view, |
| 51 WebViewPlugin::Delegate* delegate, | 51 WebViewPlugin::Delegate* delegate, |
| 52 const WebPreferences& preferences) | 52 const WebPreferences& preferences) |
| 53 : content::RenderViewObserver(render_view), | 53 : content::RenderViewObserver(render_view), |
| 54 delegate_(delegate), | 54 delegate_(delegate), |
| 55 container_(nullptr), | 55 container_(nullptr), |
| 56 web_view_(WebView::create(this)), | 56 web_view_(WebView::create(this)), |
| 57 finished_loading_(false), | 57 finished_loading_(false), |
| 58 focused_(false) { | 58 focused_(false), |
| 59 is_painting_(false) { | |
| 59 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a | 60 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a |
| 60 // consistent view of our preferences. | 61 // consistent view of our preferences. |
| 61 content::RenderView::ApplyWebPreferences(preferences, web_view_); | 62 content::RenderView::ApplyWebPreferences(preferences, web_view_); |
| 62 WebLocalFrame* web_local_frame = | 63 WebLocalFrame* web_local_frame = |
| 63 WebLocalFrame::create(blink::WebTreeScopeType::Document, this); | 64 WebLocalFrame::create(blink::WebTreeScopeType::Document, this); |
| 64 web_frame_ = web_local_frame; | 65 web_frame_ = web_local_frame; |
| 65 web_view_->setMainFrame(web_frame_); | 66 web_view_->setMainFrame(web_frame_); |
| 66 // TODO(dcheng): The main frame widget currently has a special case. | 67 // TODO(dcheng): The main frame widget currently has a special case. |
| 67 // Eliminate this once WebView is no longer a WebWidget. | 68 // Eliminate this once WebView is no longer a WebWidget. |
| 68 web_frame_widget_ = WebFrameWidget::create(this, web_view_, web_local_frame); | 69 web_frame_widget_ = WebFrameWidget::create(this, web_view_, web_local_frame); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 // either the Blink lifecycle or Compositor layer tree host nomenclature. | 166 // either the Blink lifecycle or Compositor layer tree host nomenclature. |
| 166 void WebViewPlugin::layoutIfNeeded() { | 167 void WebViewPlugin::layoutIfNeeded() { |
| 167 web_view_->updateAllLifecyclePhases(); | 168 web_view_->updateAllLifecyclePhases(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 171 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
| 171 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); | 172 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); |
| 172 if (paint_rect.IsEmpty()) | 173 if (paint_rect.IsEmpty()) |
| 173 return; | 174 return; |
| 174 | 175 |
| 176 is_painting_ = true; | |
|
tommycli
2016/02/08 22:20:43
Seems like this should use base::AutoReset
chrishtr
2016/02/08 22:43:38
Done.
| |
| 177 | |
| 175 paint_rect.Offset(-rect_.x(), -rect_.y()); | 178 paint_rect.Offset(-rect_.x(), -rect_.y()); |
| 176 | 179 |
| 177 canvas->save(); | 180 canvas->save(); |
| 178 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); | 181 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); |
| 179 | 182 |
| 180 // Apply inverse device scale factor, as the outer webview has already | 183 // Apply inverse device scale factor, as the outer webview has already |
| 181 // applied it, and the inner webview will apply it again. | 184 // applied it, and the inner webview will apply it again. |
| 182 SkScalar inverse_scale = | 185 SkScalar inverse_scale = |
| 183 SkFloatToScalar(1.0 / container_->deviceScaleFactor()); | 186 SkFloatToScalar(1.0 / container_->deviceScaleFactor()); |
| 184 canvas->scale(inverse_scale, inverse_scale); | 187 canvas->scale(inverse_scale, inverse_scale); |
| 185 | 188 |
| 186 web_view_->paint(canvas, paint_rect); | 189 web_view_->paint(canvas, paint_rect); |
| 187 | 190 |
| 188 canvas->restore(); | 191 canvas->restore(); |
| 192 is_painting_ = false; | |
| 189 } | 193 } |
| 190 | 194 |
| 191 // Coordinates are relative to the containing window. | 195 // Coordinates are relative to the containing window. |
| 192 void WebViewPlugin::updateGeometry(const WebRect& window_rect, | 196 void WebViewPlugin::updateGeometry(const WebRect& window_rect, |
| 193 const WebRect& clip_rect, | 197 const WebRect& clip_rect, |
| 194 const WebRect& unobscured_rect, | 198 const WebRect& unobscured_rect, |
| 195 const WebVector<WebRect>& cut_outs_rects, | 199 const WebVector<WebRect>& cut_outs_rects, |
| 196 bool is_visible) { | 200 bool is_visible) { |
| 197 if (static_cast<gfx::Rect>(window_rect) != rect_) { | 201 if (static_cast<gfx::Rect>(window_rect) != rect_) { |
| 198 rect_ = window_rect; | 202 rect_ = window_rect; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 void WebViewPlugin::didInvalidateRect(const WebRect& rect) { | 285 void WebViewPlugin::didInvalidateRect(const WebRect& rect) { |
| 282 if (container_) | 286 if (container_) |
| 283 container_->invalidateRect(rect); | 287 container_->invalidateRect(rect); |
| 284 } | 288 } |
| 285 | 289 |
| 286 void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) { | 290 void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) { |
| 287 current_cursor_ = cursor; | 291 current_cursor_ = cursor; |
| 288 } | 292 } |
| 289 | 293 |
| 290 void WebViewPlugin::scheduleAnimation() { | 294 void WebViewPlugin::scheduleAnimation() { |
| 291 if (container_) | 295 if (container_ && !is_painting_) |
|
tommycli
2016/02/08 22:20:43
If this should not happen anyways, shouldn't this
chrishtr
2016/02/08 22:43:39
Added DCHECK plus defensive logic.
| |
| 292 container_->setNeedsLayout(); | 296 container_->setNeedsLayout(); |
| 293 } | 297 } |
| 294 | 298 |
| 295 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { | 299 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { |
| 296 if (!delegate_) | 300 if (!delegate_) |
| 297 return; | 301 return; |
| 298 | 302 |
| 299 v8::Isolate* isolate = blink::mainThreadIsolate(); | 303 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 300 v8::HandleScope handle_scope(isolate); | 304 v8::HandleScope handle_scope(isolate); |
| 301 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 305 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 318 // By default RenderViewObservers are destroyed along with the RenderView. | 322 // By default RenderViewObservers are destroyed along with the RenderView. |
| 319 // WebViewPlugin has a custom destruction mechanism, so we disable this. | 323 // WebViewPlugin has a custom destruction mechanism, so we disable this. |
| 320 } | 324 } |
| 321 | 325 |
| 322 void WebViewPlugin::OnZoomLevelChanged() { | 326 void WebViewPlugin::OnZoomLevelChanged() { |
| 323 if (container_) { | 327 if (container_) { |
| 324 web_view_->setZoomLevel( | 328 web_view_->setZoomLevel( |
| 325 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); | 329 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); |
| 326 } | 330 } |
| 327 } | 331 } |
| OLD | NEW |