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/auto_reset.h" | |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
11 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
12 #include "content/public/common/web_preferences.h" | 13 #include "content/public/common/web_preferences.h" |
13 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
14 #include "gin/converter.h" | 15 #include "gin/converter.h" |
15 #include "skia/ext/platform_canvas.h" | 16 #include "skia/ext/platform_canvas.h" |
16 #include "third_party/WebKit/public/platform/WebSize.h" | 17 #include "third_party/WebKit/public/platform/WebSize.h" |
17 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
18 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 19 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
48 using content::WebPreferences; | 49 using content::WebPreferences; |
49 | 50 |
50 WebViewPlugin::WebViewPlugin(content::RenderView* render_view, | 51 WebViewPlugin::WebViewPlugin(content::RenderView* render_view, |
51 WebViewPlugin::Delegate* delegate, | 52 WebViewPlugin::Delegate* delegate, |
52 const WebPreferences& preferences) | 53 const WebPreferences& preferences) |
53 : content::RenderViewObserver(render_view), | 54 : content::RenderViewObserver(render_view), |
54 delegate_(delegate), | 55 delegate_(delegate), |
55 container_(nullptr), | 56 container_(nullptr), |
56 web_view_(WebView::create(this)), | 57 web_view_(WebView::create(this)), |
57 finished_loading_(false), | 58 finished_loading_(false), |
58 focused_(false) { | 59 focused_(false), |
60 is_painting_(false) { | |
59 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a | 61 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a |
60 // consistent view of our preferences. | 62 // consistent view of our preferences. |
61 content::RenderView::ApplyWebPreferences(preferences, web_view_); | 63 content::RenderView::ApplyWebPreferences(preferences, web_view_); |
62 WebLocalFrame* web_local_frame = | 64 WebLocalFrame* web_local_frame = |
63 WebLocalFrame::create(blink::WebTreeScopeType::Document, this); | 65 WebLocalFrame::create(blink::WebTreeScopeType::Document, this); |
64 web_frame_ = web_local_frame; | 66 web_frame_ = web_local_frame; |
65 web_view_->setMainFrame(web_frame_); | 67 web_view_->setMainFrame(web_frame_); |
66 // TODO(dcheng): The main frame widget currently has a special case. | 68 // TODO(dcheng): The main frame widget currently has a special case. |
67 // Eliminate this once WebView is no longer a WebWidget. | 69 // Eliminate this once WebView is no longer a WebWidget. |
68 web_frame_widget_ = WebFrameWidget::create(this, web_view_, web_local_frame); | 70 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. | 167 // either the Blink lifecycle or Compositor layer tree host nomenclature. |
166 void WebViewPlugin::layoutIfNeeded() { | 168 void WebViewPlugin::layoutIfNeeded() { |
167 web_view_->updateAllLifecyclePhases(); | 169 web_view_->updateAllLifecyclePhases(); |
168 } | 170 } |
169 | 171 |
170 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 172 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
171 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); | 173 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); |
172 if (paint_rect.IsEmpty()) | 174 if (paint_rect.IsEmpty()) |
173 return; | 175 return; |
174 | 176 |
177 base::AutoReset<bool> is_painting( | |
178 &is_painting_, true); | |
179 | |
175 paint_rect.Offset(-rect_.x(), -rect_.y()); | 180 paint_rect.Offset(-rect_.x(), -rect_.y()); |
176 | 181 |
177 canvas->save(); | 182 canvas->save(); |
178 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); | 183 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); |
179 | 184 |
180 // Apply inverse device scale factor, as the outer webview has already | 185 // Apply inverse device scale factor, as the outer webview has already |
181 // applied it, and the inner webview will apply it again. | 186 // applied it, and the inner webview will apply it again. |
182 SkScalar inverse_scale = | 187 SkScalar inverse_scale = |
183 SkFloatToScalar(1.0 / container_->deviceScaleFactor()); | 188 SkFloatToScalar(1.0 / container_->deviceScaleFactor()); |
184 canvas->scale(inverse_scale, inverse_scale); | 189 canvas->scale(inverse_scale, inverse_scale); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 void WebViewPlugin::didInvalidateRect(const WebRect& rect) { | 286 void WebViewPlugin::didInvalidateRect(const WebRect& rect) { |
282 if (container_) | 287 if (container_) |
283 container_->invalidateRect(rect); | 288 container_->invalidateRect(rect); |
284 } | 289 } |
285 | 290 |
286 void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) { | 291 void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) { |
287 current_cursor_ = cursor; | 292 current_cursor_ = cursor; |
288 } | 293 } |
289 | 294 |
290 void WebViewPlugin::scheduleAnimation() { | 295 void WebViewPlugin::scheduleAnimation() { |
291 if (container_) | 296 if (container_) { |
297 DCHECK(!is_painting_); | |
tommycli
2016/02/08 23:09:04
Don't only CHECKs show up in crashes? Not sure, ju
chrishtr
2016/02/08 23:13:56
CHECK will crash in production, DCHECK in debug bu
| |
298 // This should never happen, but adding this code to see if it affects | |
299 /// crashes observed in crbug.com/545039. | |
300 if (is_painting_) | |
301 return; | |
292 container_->setNeedsLayout(); | 302 container_->setNeedsLayout(); |
303 } | |
293 } | 304 } |
294 | 305 |
295 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { | 306 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { |
296 if (!delegate_) | 307 if (!delegate_) |
297 return; | 308 return; |
298 | 309 |
299 v8::Isolate* isolate = blink::mainThreadIsolate(); | 310 v8::Isolate* isolate = blink::mainThreadIsolate(); |
300 v8::HandleScope handle_scope(isolate); | 311 v8::HandleScope handle_scope(isolate); |
301 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 312 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
302 DCHECK(!context.IsEmpty()); | 313 DCHECK(!context.IsEmpty()); |
(...skipping 15 matching lines...) Expand all Loading... | |
318 // By default RenderViewObservers are destroyed along with the RenderView. | 329 // By default RenderViewObservers are destroyed along with the RenderView. |
319 // WebViewPlugin has a custom destruction mechanism, so we disable this. | 330 // WebViewPlugin has a custom destruction mechanism, so we disable this. |
320 } | 331 } |
321 | 332 |
322 void WebViewPlugin::OnZoomLevelChanged() { | 333 void WebViewPlugin::OnZoomLevelChanged() { |
323 if (container_) { | 334 if (container_) { |
324 web_view_->setZoomLevel( | 335 web_view_->setZoomLevel( |
325 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); | 336 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); |
326 } | 337 } |
327 } | 338 } |
OLD | NEW |