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

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

Issue 2600253003: Fix plugin placeholders not loading (Closed)
Patch Set: Created 4 years 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 8d45c4201aed4e7b9429fc053c946a038c98455f..aa8bdcb60787874e46b7cbbb12f3dad864ee4ddb 100644
--- a/components/plugins/renderer/webview_plugin.cc
+++ b/components/plugins/renderer/webview_plugin.cc
@@ -53,21 +53,12 @@ WebViewPlugin::WebViewPlugin(content::RenderView* render_view,
: content::RenderViewObserver(render_view),
delegate_(delegate),
container_(nullptr),
- web_view_(WebView::create(this, blink::WebPageVisibilityStateVisible)),
+ finished_loading_(false),
focused_(false),
is_painting_(false),
is_resizing_(false),
- web_frame_client_(this),
+ web_view_helper_(this, preferences),
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_);
- WebLocalFrame* web_frame = WebLocalFrame::create(
- blink::WebTreeScopeType::Document, &web_frame_client_);
- web_view_->setMainFrame(web_frame);
- // TODO(dcheng): The main frame widget currently has a special case.
- // Eliminate this once WebView is no longer a WebWidget.
- WebFrameWidget::create(this, web_view_, web_frame);
}
// static
@@ -84,7 +75,29 @@ WebViewPlugin* WebViewPlugin::Create(content::RenderView* render_view,
WebViewPlugin::~WebViewPlugin() {
DCHECK(!weak_factory_.HasWeakPtrs());
- web_view_->close();
+}
+
+void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) {
+ if (!response_.isNull()) {
+ plugin->didReceiveResponse(response_);
+ size_t total_bytes = 0;
+ for (std::list<std::string>::iterator it = data_.begin(); it != data_.end();
+ ++it) {
+ plugin->didReceiveData(
+ it->c_str(), base::checked_cast<int>(it->length()));
+ total_bytes += it->length();
+ }
+ }
+ // We need to transfer the |focused_| to new plugin after it loaded.
+ if (focused_) {
Bernhard Bauer 2017/01/03 17:01:33 Nit: It looks like the style for single-line bodie
Nate Chapin 2017/01/03 20:04:26 Done. I had just reverted to what I had deleted, b
+ plugin->updateFocus(true, blink::WebFocusTypeNone);
+ }
+ if (finished_loading_) {
+ plugin->didFinishLoading();
+ }
+ if (error_) {
+ plugin->didFailLoading(*error_);
+ }
}
WebPluginContainer* WebViewPlugin::container() const { return container_; }
@@ -106,8 +119,8 @@ bool WebViewPlugin::initialize(WebPluginContainer* container) {
old_title_ = container_->element().getAttribute("title");
// Propagate device scale and zoom level to inner webview.
- web_view_->setDeviceScaleFactor(container_->deviceScaleFactor());
- web_view_->setZoomLevel(
+ web_view()->setDeviceScaleFactor(container_->deviceScaleFactor());
+ web_view()->setZoomLevel(
blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor()));
return true;
@@ -133,7 +146,7 @@ v8::Local<v8::Object> WebViewPlugin::v8ScriptableObject(v8::Isolate* isolate) {
}
void WebViewPlugin::updateAllLifecyclePhases() {
- web_view_->updateAllLifecyclePhases();
+ web_view()->updateAllLifecyclePhases();
}
void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) {
@@ -155,7 +168,7 @@ void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) {
SkFloatToScalar(1.0 / container_->deviceScaleFactor());
canvas->scale(inverse_scale, inverse_scale);
- web_view_->paint(canvas, paint_rect);
+ web_view()->paint(canvas, paint_rect);
canvas->restore();
}
@@ -172,7 +185,7 @@ void WebViewPlugin::updateGeometry(const WebRect& window_rect,
if (static_cast<gfx::Rect>(window_rect) != rect_) {
rect_ = window_rect;
- web_view_->resize(rect_.size());
+ web_view()->resize(rect_.size());
}
// Plugin updates are forbidden during Blink layout. Therefore,
@@ -209,77 +222,102 @@ blink::WebInputEventResult WebViewPlugin::handleInputEvent(
return blink::WebInputEventResult::HandledSuppressed;
}
current_cursor_ = cursor;
- blink::WebInputEventResult handled = web_view_->handleInputEvent(event);
+ blink::WebInputEventResult handled = web_view()->handleInputEvent(event);
cursor = current_cursor_;
return handled;
}
void WebViewPlugin::didReceiveResponse(const WebURLResponse& response) {
- NOTREACHED();
+ DCHECK(response_.isNull());
+ response_ = response;
}
void WebViewPlugin::didReceiveData(const char* data, int data_length) {
- NOTREACHED();
+ data_.push_back(std::string(data, data_length));
}
void WebViewPlugin::didFinishLoading() {
- NOTREACHED();
+ DCHECK(!finished_loading_);
+ finished_loading_ = true;
}
void WebViewPlugin::didFailLoading(const WebURLError& error) {
- NOTREACHED();
+ DCHECK(!error_.get());
+ error_.reset(new WebURLError(error));
}
-bool WebViewPlugin::acceptsLoadDrops() { return false; }
+WebViewPlugin::WebViewHelper::WebViewHelper(
+ WebViewPlugin* plugin,
+ const WebPreferences& preferences) : plugin_(plugin) {
+ // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a
Bernhard Bauer 2017/01/03 17:01:33 Nit: Move this comment right before the call to Ap
Nate Chapin 2017/01/03 20:04:26 Done.
+ // consistent view of our preferences.
+ web_view_ =
+ WebView::create(this, blink::WebPageVisibilityStateVisible);
+ content::RenderView::ApplyWebPreferences(preferences, web_view_);
+ WebLocalFrame* web_frame = WebLocalFrame::create(
+ blink::WebTreeScopeType::Document, this);
+ web_view_->setMainFrame(web_frame);
+ // TODO(dcheng): The main frame widget currently has a special case.
+ // Eliminate this once WebView is no longer a WebWidget.
+ WebFrameWidget::create(this, web_view_, web_frame);
+}
+
+WebViewPlugin::WebViewHelper::~WebViewHelper() {
+ web_view_->close();
+}
-void WebViewPlugin::setToolTipText(const WebString& text,
- blink::WebTextDirection hint) {
- if (container_)
- container_->element().setAttribute("title", text);
+bool WebViewPlugin::WebViewHelper::acceptsLoadDrops() { return false; }
+
+void WebViewPlugin::WebViewHelper::setToolTipText(
+ const WebString& text,
+ blink::WebTextDirection hint) {
+ if (plugin_->container_)
+ plugin_->container_->element().setAttribute("title", text);
}
-void WebViewPlugin::startDragging(blink::WebReferrerPolicy,
- const WebDragData&,
- WebDragOperationsMask,
- const WebImage&,
- const WebPoint&) {
+void WebViewPlugin::WebViewHelper::startDragging(blink::WebReferrerPolicy,
+ const WebDragData&,
+ WebDragOperationsMask,
+ const WebImage&,
+ const WebPoint&) {
// Immediately stop dragging.
DCHECK(web_view_->mainFrame()->isWebLocalFrame());
web_view_->mainFrame()->toWebLocalFrame()->frameWidget()->
dragSourceSystemDragEnded();
}
-bool WebViewPlugin::allowsBrokenNullLayerTreeView() const {
+bool WebViewPlugin::WebViewHelper::allowsBrokenNullLayerTreeView() const {
return true;
}
-void WebViewPlugin::didInvalidateRect(const WebRect& rect) {
- if (container_)
- container_->invalidateRect(rect);
+void WebViewPlugin::WebViewHelper::didInvalidateRect(const WebRect& rect) {
+ if (plugin_->container_)
+ plugin_->container_->invalidateRect(rect);
}
-void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) {
- current_cursor_ = cursor;
+void WebViewPlugin::WebViewHelper::didChangeCursor(
+ const WebCursorInfo& cursor) {
+ plugin_->current_cursor_ = cursor;
}
-void WebViewPlugin::scheduleAnimation() {
+void WebViewPlugin::WebViewHelper::scheduleAnimation() {
// Resizes must be self-contained: any lifecycle updating must
// be triggerd from within the WebView or this WebViewPlugin.
// This is because this WebViewPlugin is contained in another
// Web View which may be in the middle of updating its lifecycle,
// but after layout is done, and it is illegal to dirty earlier
// lifecycle stages during later ones.
- if (is_resizing_)
+ if (plugin_->is_resizing_)
return;
- if (container_) {
+ if (plugin_->container_) {
// This should never happen; see also crbug.com/545039 for context.
Bernhard Bauer 2017/01/03 17:01:33 https://crbug.com/545039 has been marked fixed; ca
Nate Chapin 2017/01/03 20:04:26 Double-checked with chrishtr, who added the commen
- CHECK(!is_painting_);
- container_->scheduleAnimation();
+ CHECK(!plugin_->is_painting_);
+ plugin_->container_->scheduleAnimation();
}
}
-void WebViewPlugin::PluginWebFrameClient::didClearWindowObject(
+void WebViewPlugin::WebViewHelper::didClearWindowObject(
WebLocalFrame* frame) {
if (!plugin_->delegate_)
return;
@@ -296,11 +334,9 @@ void WebViewPlugin::PluginWebFrameClient::didClearWindowObject(
plugin_->delegate_->GetV8Handle(isolate));
}
-void WebViewPlugin::OnDestruct() {}
-
void WebViewPlugin::OnZoomLevelChanged() {
if (container_) {
- web_view_->setZoomLevel(
+ web_view()->setZoomLevel(
blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor()));
}
}
@@ -317,5 +353,5 @@ void WebViewPlugin::UpdatePluginForNewGeometry(
// 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();
+ 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