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 |
| 139 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); | 144 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); |
| 140 canvas->save(); | 145 canvas->save(); |
| 141 | 146 |
| 147 // Before actually painting, remove device scaling, as it would otherwise | |
| 148 // be applied twice. | |
| 149 web_view_->setDeviceScaleFactor(1); | |
|
jbroman
2015/03/06 20:25:49
Changing the device scale factor of the page like
tommycli
2015/03/06 21:30:55
Done. Okay cool. That's the same thing as bauerb s
| |
| 150 | |
| 142 web_view_->layout(); | 151 web_view_->layout(); |
| 143 web_view_->paint(canvas, paint_rect); | 152 web_view_->paint(canvas, paint_rect); |
| 144 | 153 |
| 154 // Reapply the container's device scale factor for resource loading. | |
|
tommycli
2015/03/06 00:19:23
Not sure if this is actually needed. It doesn't se
jbroman
2015/03/06 20:25:49
See above.
tommycli
2015/03/06 21:30:55
Done.
| |
| 155 if (container_) | |
| 156 web_view_->setDeviceScaleFactor(container_->deviceScaleFactor()); | |
| 157 | |
| 145 canvas->restore(); | 158 canvas->restore(); |
| 146 } | 159 } |
| 147 | 160 |
| 148 // Coordinates are relative to the containing window. | 161 // Coordinates are relative to the containing window. |
| 149 void WebViewPlugin::updateGeometry(const WebRect& frame_rect, | 162 void WebViewPlugin::updateGeometry(const WebRect& frame_rect, |
| 150 const WebRect& clip_rect, | 163 const WebRect& clip_rect, |
| 151 const WebVector<WebRect>& cut_out_rects, | 164 const WebVector<WebRect>& cut_out_rects, |
| 152 bool is_visible) { | 165 bool is_visible) { |
| 153 if (static_cast<gfx::Rect>(frame_rect) != rect_) { | 166 if (static_cast<gfx::Rect>(frame_rect) != rect_) { |
| 154 rect_ = frame_rect; | 167 rect_ = frame_rect; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { | 255 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { |
| 243 if (delegate_) | 256 if (delegate_) |
| 244 delegate_->BindWebFrame(frame); | 257 delegate_->BindWebFrame(frame); |
| 245 } | 258 } |
| 246 | 259 |
| 247 void WebViewPlugin::didReceiveResponse(WebLocalFrame* frame, | 260 void WebViewPlugin::didReceiveResponse(WebLocalFrame* frame, |
| 248 unsigned identifier, | 261 unsigned identifier, |
| 249 const WebURLResponse& response) { | 262 const WebURLResponse& response) { |
| 250 WebFrameClient::didReceiveResponse(frame, identifier, response); | 263 WebFrameClient::didReceiveResponse(frame, identifier, response); |
| 251 } | 264 } |
| OLD | NEW |