Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Unified Diff: components/plugins/renderer/webview_plugin.cc

Issue 2164753003: WebViewPlugin: Post geometry-update actions to a task to run async. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/plugins/renderer/webview_plugin.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/plugins/renderer/webview_plugin.cc
diff --git a/components/plugins/renderer/webview_plugin.cc b/components/plugins/renderer/webview_plugin.cc
index 099104df1b23e8408704ce1c28411d539346e453..ed0adbc0fe6950024154d026e3230004845dd7c3 100644
--- a/components/plugins/renderer/webview_plugin.cc
+++ b/components/plugins/renderer/webview_plugin.cc
@@ -7,6 +7,7 @@
#include <stddef.h>
#include "base/auto_reset.h"
+#include "base/bind.h"
#include "base/location.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
@@ -60,7 +61,8 @@ WebViewPlugin::WebViewPlugin(content::RenderView* render_view,
finished_loading_(false),
focused_(false),
is_painting_(false),
- is_resizing_(false) {
+ is_resizing_(false),
+ weak_factory_(this) {
// ApplyWebPreferences before making a WebLocalFrame so that the frame sees a
// consistent view of our preferences.
content::RenderView::ApplyWebPreferences(preferences, web_view_);
@@ -86,6 +88,7 @@ WebViewPlugin* WebViewPlugin::Create(content::RenderView* render_view,
}
WebViewPlugin::~WebViewPlugin() {
+ DCHECK(!weak_factory_.HasWeakPtrs());
web_frame_widget_->close();
web_view_->close();
web_frame_->close();
@@ -152,6 +155,8 @@ bool WebViewPlugin::initialize(WebPluginContainer* container) {
}
void WebViewPlugin::destroy() {
+ weak_factory_.InvalidateWeakPtrs();
+
if (delegate_) {
delegate_->PluginDestroyed();
delegate_ = nullptr;
@@ -202,22 +207,14 @@ void WebViewPlugin::updateGeometry(const WebRect& window_rect,
const WebRect& unobscured_rect,
const WebVector<WebRect>& cut_outs_rects,
bool is_visible) {
- base::AutoReset<bool> is_resizing(
- &is_resizing_, true);
-
- if (static_cast<gfx::Rect>(window_rect) != rect_) {
- rect_ = window_rect;
- WebSize newSize(window_rect.width, window_rect.height);
- web_view_->resize(newSize);
- }
-
- if (delegate_) {
- delegate_->OnUnobscuredRectUpdate(gfx::Rect(unobscured_rect));
- // The delegate may have dirtied style and layout of the WebView.
- // See for example the resizePoster function in plugin_poster.html.
- // Run the lifecycle now so that it is clean.
- web_view_->updateAllLifecyclePhases();
- }
+ DCHECK(container_);
+
+ // Plugin updates are forbidden during Blink layout. Therefore,
+ // UpdatePluginForNewGeometry must be posted to a task to run asynchronously.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&WebViewPlugin::UpdatePluginForNewGeometry,
+ weak_factory_.GetWeakPtr(), window_rect, unobscured_rect));
}
void WebViewPlugin::updateFocus(bool focused, blink::WebFocusType focus_type) {
@@ -346,3 +343,24 @@ void WebViewPlugin::OnZoomLevelChanged() {
blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor()));
}
}
+
+void WebViewPlugin::UpdatePluginForNewGeometry(
+ const blink::WebRect& window_rect,
+ const blink::WebRect& unobscured_rect) {
+ DCHECK(container_);
+
+ base::AutoReset<bool> is_resizing(&is_resizing_, true);
+
+ if (static_cast<gfx::Rect>(window_rect) != rect_) {
+ rect_ = window_rect;
+ web_view_->resize(rect_.size());
+ }
+
+ if (delegate_) {
+ delegate_->OnUnobscuredRectUpdate(gfx::Rect(unobscured_rect));
+ // The delegate may have dirtied style and layout of the WebView.
+ // See for example the resizePoster function in plugin_poster.html.
+ // Run the lifecycle now so that it is clean.
+ web_view_->updateAllLifecyclePhases();
+ }
+}
« no previous file with comments | « components/plugins/renderer/webview_plugin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698