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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "content/public/common/web_preferences.h" | 10 #include "content/public/common/web_preferences.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 102 |
| 103 void WebViewPlugin::RestoreTitleText() { | 103 void WebViewPlugin::RestoreTitleText() { |
| 104 if (container_) | 104 if (container_) |
| 105 container_->element().setAttribute("title", old_title_); | 105 container_->element().setAttribute("title", old_title_); |
| 106 } | 106 } |
| 107 | 107 |
| 108 WebPluginContainer* WebViewPlugin::container() const { return container_; } | 108 WebPluginContainer* WebViewPlugin::container() const { return container_; } |
| 109 | 109 |
| 110 bool WebViewPlugin::initialize(WebPluginContainer* container) { | 110 bool WebViewPlugin::initialize(WebPluginContainer* container) { |
| 111 container_ = container; | 111 container_ = container; |
| 112 if (container_) | 112 if (container_) { |
| 113 old_title_ = container_->element().getAttribute("title"); | 113 old_title_ = container_->element().getAttribute("title"); |
| 114 | |
| 115 // Propagate device scale to inner webview to load the correct resource | |
| 116 // when images have a "srcset" attribute. | |
| 117 web_view_->setDeviceScaleFactor(container_->deviceScaleFactor()); | |
| 118 } | |
| 114 return true; | 119 return true; |
| 115 } | 120 } |
| 116 | 121 |
| 117 void WebViewPlugin::destroy() { | 122 void WebViewPlugin::destroy() { |
| 118 if (delegate_) { | 123 if (delegate_) { |
| 119 delegate_->PluginDestroyed(); | 124 delegate_->PluginDestroyed(); |
| 120 delegate_ = NULL; | 125 delegate_ = NULL; |
| 121 } | 126 } |
| 122 container_ = NULL; | 127 container_ = NULL; |
| 123 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 128 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 124 } | 129 } |
| 125 | 130 |
| 126 NPObject* WebViewPlugin::scriptableObject() { return NULL; } | 131 NPObject* WebViewPlugin::scriptableObject() { return NULL; } |
| 127 | 132 |
| 128 struct _NPP* WebViewPlugin::pluginNPP() { return NULL; } | 133 struct _NPP* WebViewPlugin::pluginNPP() { return NULL; } |
| 129 | 134 |
| 130 bool WebViewPlugin::getFormValue(WebString& value) { return false; } | 135 bool WebViewPlugin::getFormValue(WebString& value) { return false; } |
| 131 | 136 |
| 132 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 137 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
| 133 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); | 138 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); |
| 134 if (paint_rect.IsEmpty()) | 139 if (paint_rect.IsEmpty()) |
| 135 return; | 140 return; |
| 136 | 141 |
| 137 paint_rect.Offset(-rect_.x(), -rect_.y()); | 142 paint_rect.Offset(-rect_.x(), -rect_.y()); |
| 138 | 143 |
| 144 canvas->save(); | |
|
tommycli
2015/03/06 21:30:55
I also changed the order so 'save' is called befor
jbroman
2015/03/07 03:56:02
Yeah, looks good.
| |
| 139 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); | 145 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); |
| 140 canvas->save(); | 146 |
| 147 // Apply inverse device scale factor, as the outer webview has already | |
| 148 // applied it, and the inner webview will apply it again. | |
| 149 SkScalar inverse_scale = | |
| 150 SkFloatToScalar(1.0 / container_->deviceScaleFactor()); | |
| 151 canvas->scale(inverse_scale, inverse_scale); | |
| 141 | 152 |
| 142 web_view_->layout(); | 153 web_view_->layout(); |
| 143 web_view_->paint(canvas, paint_rect); | 154 web_view_->paint(canvas, paint_rect); |
| 144 | 155 |
| 145 canvas->restore(); | 156 canvas->restore(); |
| 146 } | 157 } |
| 147 | 158 |
| 148 // Coordinates are relative to the containing window. | 159 // Coordinates are relative to the containing window. |
| 149 void WebViewPlugin::updateGeometry(const WebRect& frame_rect, | 160 void WebViewPlugin::updateGeometry(const WebRect& frame_rect, |
| 150 const WebRect& clip_rect, | 161 const WebRect& clip_rect, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { | 253 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { |
| 243 if (delegate_) | 254 if (delegate_) |
| 244 delegate_->BindWebFrame(frame); | 255 delegate_->BindWebFrame(frame); |
| 245 } | 256 } |
| 246 | 257 |
| 247 void WebViewPlugin::didReceiveResponse(WebLocalFrame* frame, | 258 void WebViewPlugin::didReceiveResponse(WebLocalFrame* frame, |
| 248 unsigned identifier, | 259 unsigned identifier, |
| 249 const WebURLResponse& response) { | 260 const WebURLResponse& response) { |
| 250 WebFrameClient::didReceiveResponse(frame, identifier, response); | 261 WebFrameClient::didReceiveResponse(frame, identifier, response); |
| 251 } | 262 } |
| OLD | NEW |