| 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 27 matching lines...) Expand all Loading... |
| 38 using blink::WebURLError; | 38 using blink::WebURLError; |
| 39 using blink::WebURLRequest; | 39 using blink::WebURLRequest; |
| 40 using blink::WebURLResponse; | 40 using blink::WebURLResponse; |
| 41 using blink::WebVector; | 41 using blink::WebVector; |
| 42 using blink::WebView; | 42 using blink::WebView; |
| 43 using content::WebPreferences; | 43 using content::WebPreferences; |
| 44 | 44 |
| 45 WebViewPlugin::WebViewPlugin(WebViewPlugin::Delegate* delegate, | 45 WebViewPlugin::WebViewPlugin(WebViewPlugin::Delegate* delegate, |
| 46 const WebPreferences& preferences) | 46 const WebPreferences& preferences) |
| 47 : delegate_(delegate), | 47 : delegate_(delegate), |
| 48 container_(NULL), | 48 container_(nullptr), |
| 49 web_view_(WebView::create(this)), | 49 web_view_(WebView::create(this)), |
| 50 finished_loading_(false), | 50 finished_loading_(false), |
| 51 focused_(false) { | 51 focused_(false) { |
| 52 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a | 52 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a |
| 53 // consistent view of our preferences. | 53 // consistent view of our preferences. |
| 54 content::RenderView::ApplyWebPreferences(preferences, web_view_); | 54 content::RenderView::ApplyWebPreferences(preferences, web_view_); |
| 55 web_frame_ = WebLocalFrame::create(blink::WebTreeScopeType::Document, this); | 55 web_frame_ = WebLocalFrame::create(blink::WebTreeScopeType::Document, this); |
| 56 web_view_->setMainFrame(web_frame_); | 56 web_view_->setMainFrame(web_frame_); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // static | 59 // static |
| 60 WebViewPlugin* WebViewPlugin::Create(WebViewPlugin::Delegate* delegate, | 60 WebViewPlugin* WebViewPlugin::Create(WebViewPlugin::Delegate* delegate, |
| 61 const WebPreferences& preferences, | 61 const WebPreferences& preferences, |
| 62 const std::string& html_data, | 62 const std::string& html_data, |
| 63 const GURL& url) { | 63 const GURL& url) { |
| 64 DCHECK(url.is_valid()) << "Blink requires the WebView to have a valid URL."; |
| 64 WebViewPlugin* plugin = new WebViewPlugin(delegate, preferences); | 65 WebViewPlugin* plugin = new WebViewPlugin(delegate, preferences); |
| 65 plugin->web_view()->mainFrame()->loadHTMLString(html_data, url); | 66 plugin->web_view()->mainFrame()->loadHTMLString(html_data, url); |
| 66 return plugin; | 67 return plugin; |
| 67 } | 68 } |
| 68 | 69 |
| 69 WebViewPlugin::~WebViewPlugin() { | 70 WebViewPlugin::~WebViewPlugin() { |
| 70 web_view_->close(); | 71 web_view_->close(); |
| 71 web_frame_->close(); | 72 web_frame_->close(); |
| 72 } | 73 } |
| 73 | 74 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // Propagate device scale to inner webview to load the correct resource | 116 // Propagate device scale to inner webview to load the correct resource |
| 116 // when images have a "srcset" attribute. | 117 // when images have a "srcset" attribute. |
| 117 web_view_->setDeviceScaleFactor(container_->deviceScaleFactor()); | 118 web_view_->setDeviceScaleFactor(container_->deviceScaleFactor()); |
| 118 } | 119 } |
| 119 return true; | 120 return true; |
| 120 } | 121 } |
| 121 | 122 |
| 122 void WebViewPlugin::destroy() { | 123 void WebViewPlugin::destroy() { |
| 123 if (delegate_) { | 124 if (delegate_) { |
| 124 delegate_->PluginDestroyed(); | 125 delegate_->PluginDestroyed(); |
| 125 delegate_ = NULL; | 126 delegate_ = nullptr; |
| 126 } | 127 } |
| 127 container_ = NULL; | 128 container_ = nullptr; |
| 128 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 129 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 129 } | 130 } |
| 130 | 131 |
| 131 v8::Local<v8::Object> WebViewPlugin::v8ScriptableObject(v8::Isolate* isolate) { | 132 v8::Local<v8::Object> WebViewPlugin::v8ScriptableObject(v8::Isolate* isolate) { |
| 132 if (!delegate_) | 133 if (!delegate_) |
| 133 return v8::Local<v8::Object>(); | 134 return v8::Local<v8::Object>(); |
| 134 | 135 |
| 135 return delegate_->GetV8ScriptableObject(isolate); | 136 return delegate_->GetV8ScriptableObject(isolate); |
| 136 } | 137 } |
| 137 | 138 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) { | 255 void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) { |
| 255 current_cursor_ = cursor; | 256 current_cursor_ = cursor; |
| 256 } | 257 } |
| 257 | 258 |
| 258 void WebViewPlugin::scheduleAnimation() { | 259 void WebViewPlugin::scheduleAnimation() { |
| 259 if (container_) | 260 if (container_) |
| 260 container_->invalidate(); | 261 container_->invalidate(); |
| 261 } | 262 } |
| 262 | 263 |
| 263 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { | 264 void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) { |
| 265 DCHECK_EQ(web_frame_, frame); |
| 264 if (delegate_) | 266 if (delegate_) |
| 265 delegate_->BindWebFrame(frame); | 267 delegate_->BindWebFrame(frame); |
| 266 } | 268 } |
| 267 | 269 |
| 268 void WebViewPlugin::didReceiveResponse(WebLocalFrame* frame, | 270 void WebViewPlugin::didReceiveResponse(WebLocalFrame* frame, |
| 269 unsigned identifier, | 271 unsigned identifier, |
| 270 const WebURLResponse& response) { | 272 const WebURLResponse& response) { |
| 271 WebFrameClient::didReceiveResponse(frame, identifier, response); | 273 WebFrameClient::didReceiveResponse(frame, identifier, response); |
| 272 } | 274 } |
| OLD | NEW |