| 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/auto_reset.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 bool WebViewPlugin::initialize(WebPluginContainer* container) { | 128 bool WebViewPlugin::initialize(WebPluginContainer* container) { |
| 129 container_ = container; | 129 container_ = container; |
| 130 if (container_) { | 130 if (container_) { |
| 131 // We must call layout again here to ensure that the container is laid | 131 // We must call layout again here to ensure that the container is laid |
| 132 // out before we next try to paint it, which is a requirement of the | 132 // out before we next try to paint it, which is a requirement of the |
| 133 // document life cycle in Blink. In most cases, needsLayout is set by | 133 // document life cycle in Blink. In most cases, needsLayout is set by |
| 134 // scheduleAnimation, but due to timers controlling widget update, | 134 // scheduleAnimation, but due to timers controlling widget update, |
| 135 // scheduleAnimation may be invoked before this initialize call (which | 135 // scheduleAnimation may be invoked before this initialize call (which |
| 136 // comes through the widget update process). It doesn't hurt to mark | 136 // comes through the widget update process). It doesn't hurt to mark |
| 137 // for layout again, and it does help us in the race-condition situation. | 137 // for animation again, and it does help us in the race-condition situation. |
| 138 container_->setNeedsLayout(); | 138 container_->scheduleAnimation(); |
| 139 | 139 |
| 140 old_title_ = container_->element().getAttribute("title"); | 140 old_title_ = container_->element().getAttribute("title"); |
| 141 | 141 |
| 142 // Propagate device scale and zoom level to inner webview. | 142 // Propagate device scale and zoom level to inner webview. |
| 143 web_view_->setDeviceScaleFactor(container_->deviceScaleFactor()); | 143 web_view_->setDeviceScaleFactor(container_->deviceScaleFactor()); |
| 144 web_view_->setZoomLevel( | 144 web_view_->setZoomLevel( |
| 145 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); | 145 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); |
| 146 } | 146 } |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 void WebViewPlugin::destroy() { | 150 void WebViewPlugin::destroy() { |
| 151 if (delegate_) { | 151 if (delegate_) { |
| 152 delegate_->PluginDestroyed(); | 152 delegate_->PluginDestroyed(); |
| 153 delegate_ = nullptr; | 153 delegate_ = nullptr; |
| 154 } | 154 } |
| 155 container_ = nullptr; | 155 container_ = nullptr; |
| 156 content::RenderViewObserver::Observe(nullptr); | 156 content::RenderViewObserver::Observe(nullptr); |
| 157 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 157 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 158 } | 158 } |
| 159 | 159 |
| 160 v8::Local<v8::Object> WebViewPlugin::v8ScriptableObject(v8::Isolate* isolate) { | 160 v8::Local<v8::Object> WebViewPlugin::v8ScriptableObject(v8::Isolate* isolate) { |
| 161 if (!delegate_) | 161 if (!delegate_) |
| 162 return v8::Local<v8::Object>(); | 162 return v8::Local<v8::Object>(); |
| 163 | 163 |
| 164 return delegate_->GetV8ScriptableObject(isolate); | 164 return delegate_->GetV8ScriptableObject(isolate); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // TODO(wkorman): Look into renaming this to something more in line with | 167 void WebViewPlugin::updateAllLifecyclePhases() { |
| 168 // either the Blink lifecycle or Compositor layer tree host nomenclature. | |
| 169 void WebViewPlugin::layoutIfNeeded() { | |
| 170 web_view_->updateAllLifecyclePhases(); | 168 web_view_->updateAllLifecyclePhases(); |
| 171 } | 169 } |
| 172 | 170 |
| 173 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 171 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
| 174 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); | 172 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); |
| 175 if (paint_rect.IsEmpty()) | 173 if (paint_rect.IsEmpty()) |
| 176 return; | 174 return; |
| 177 | 175 |
| 178 base::AutoReset<bool> is_painting( | 176 base::AutoReset<bool> is_painting( |
| 179 &is_painting_, true); | 177 &is_painting_, true); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // be triggerd from within the WebView or this WebViewPlugin. | 304 // be triggerd from within the WebView or this WebViewPlugin. |
| 307 // This is because this WebViewPlugin is contained in another | 305 // This is because this WebViewPlugin is contained in another |
| 308 // Web View which may be in the middle of updating its lifecycle, | 306 // Web View which may be in the middle of updating its lifecycle, |
| 309 // but after layout is done, and it is illegal to dirty earlier | 307 // but after layout is done, and it is illegal to dirty earlier |
| 310 // lifecycle stages during later ones. | 308 // lifecycle stages during later ones. |
| 311 if (is_resizing_) | 309 if (is_resizing_) |
| 312 return; | 310 return; |
| 313 if (container_) { | 311 if (container_) { |
| 314 // This should never happen; see also crbug.com/545039 for context. | 312 // This should never happen; see also crbug.com/545039 for context. |
| 315 CHECK(!is_painting_); | 313 CHECK(!is_painting_); |
| 316 container_->setNeedsLayout(); | 314 container_->scheduleAnimation(); |
| 317 } | 315 } |
| 318 } | 316 } |
| 319 | 317 |
| 320 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { | 318 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { |
| 321 if (!delegate_) | 319 if (!delegate_) |
| 322 return; | 320 return; |
| 323 | 321 |
| 324 v8::Isolate* isolate = blink::mainThreadIsolate(); | 322 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 325 v8::HandleScope handle_scope(isolate); | 323 v8::HandleScope handle_scope(isolate); |
| 326 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 324 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 342 // By default RenderViewObservers are destroyed along with the RenderView. | 340 // By default RenderViewObservers are destroyed along with the RenderView. |
| 343 // WebViewPlugin has a custom destruction mechanism, so we disable this. | 341 // WebViewPlugin has a custom destruction mechanism, so we disable this. |
| 344 } | 342 } |
| 345 | 343 |
| 346 void WebViewPlugin::OnZoomLevelChanged() { | 344 void WebViewPlugin::OnZoomLevelChanged() { |
| 347 if (container_) { | 345 if (container_) { |
| 348 web_view_->setZoomLevel( | 346 web_view_->setZoomLevel( |
| 349 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); | 347 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); |
| 350 } | 348 } |
| 351 } | 349 } |
| OLD | NEW |