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_macros.h" | 8 #include "base/metrics/histogram_macros.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" |
11 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
12 #include "gin/converter.h" | 12 #include "gin/converter.h" |
13 #include "skia/ext/platform_canvas.h" | 13 #include "skia/ext/platform_canvas.h" |
14 #include "third_party/WebKit/public/platform/WebSize.h" | 14 #include "third_party/WebKit/public/platform/WebSize.h" |
15 #include "third_party/WebKit/public/platform/WebURL.h" | 15 #include "third_party/WebKit/public/platform/WebURL.h" |
16 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 16 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
17 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 17 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
18 #include "third_party/WebKit/public/web/WebDocument.h" | 18 #include "third_party/WebKit/public/web/WebDocument.h" |
19 #include "third_party/WebKit/public/web/WebElement.h" | 19 #include "third_party/WebKit/public/web/WebElement.h" |
| 20 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
20 #include "third_party/WebKit/public/web/WebInputEvent.h" | 21 #include "third_party/WebKit/public/web/WebInputEvent.h" |
21 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
22 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 23 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
23 #include "third_party/WebKit/public/web/WebView.h" | 24 #include "third_party/WebKit/public/web/WebView.h" |
24 | 25 |
25 using blink::WebCanvas; | 26 using blink::WebCanvas; |
26 using blink::WebCursorInfo; | 27 using blink::WebCursorInfo; |
27 using blink::WebDragData; | 28 using blink::WebDragData; |
28 using blink::WebDragOperationsMask; | 29 using blink::WebDragOperationsMask; |
| 30 using blink::WebFrameWidget; |
29 using blink::WebImage; | 31 using blink::WebImage; |
30 using blink::WebInputEvent; | 32 using blink::WebInputEvent; |
31 using blink::WebLocalFrame; | 33 using blink::WebLocalFrame; |
32 using blink::WebMouseEvent; | 34 using blink::WebMouseEvent; |
33 using blink::WebPlugin; | 35 using blink::WebPlugin; |
34 using blink::WebPluginContainer; | 36 using blink::WebPluginContainer; |
35 using blink::WebPoint; | 37 using blink::WebPoint; |
36 using blink::WebRect; | 38 using blink::WebRect; |
37 using blink::WebSize; | 39 using blink::WebSize; |
38 using blink::WebString; | 40 using blink::WebString; |
39 using blink::WebURLError; | 41 using blink::WebURLError; |
40 using blink::WebURLRequest; | 42 using blink::WebURLRequest; |
41 using blink::WebURLResponse; | 43 using blink::WebURLResponse; |
42 using blink::WebVector; | 44 using blink::WebVector; |
43 using blink::WebView; | 45 using blink::WebView; |
44 using content::WebPreferences; | 46 using content::WebPreferences; |
45 | 47 |
46 WebViewPlugin::WebViewPlugin(content::RenderView* render_view, | 48 WebViewPlugin::WebViewPlugin(content::RenderView* render_view, |
47 WebViewPlugin::Delegate* delegate, | 49 WebViewPlugin::Delegate* delegate, |
48 const WebPreferences& preferences) | 50 const WebPreferences& preferences) |
49 : content::RenderViewObserver(render_view), | 51 : content::RenderViewObserver(render_view), |
50 delegate_(delegate), | 52 delegate_(delegate), |
51 container_(nullptr), | 53 container_(nullptr), |
52 web_view_(WebView::create(this)), | 54 web_view_(WebView::create(this)), |
53 finished_loading_(false), | 55 finished_loading_(false), |
54 focused_(false) { | 56 focused_(false) { |
55 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a | 57 // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a |
56 // consistent view of our preferences. | 58 // consistent view of our preferences. |
57 content::RenderView::ApplyWebPreferences(preferences, web_view_); | 59 content::RenderView::ApplyWebPreferences(preferences, web_view_); |
58 web_frame_ = WebLocalFrame::create(blink::WebTreeScopeType::Document, this); | 60 WebLocalFrame* web_local_frame = |
| 61 WebLocalFrame::create(blink::WebTreeScopeType::Document, this); |
| 62 web_frame_ = web_local_frame; |
59 web_view_->setMainFrame(web_frame_); | 63 web_view_->setMainFrame(web_frame_); |
| 64 // TODO(dcheng): The main frame widget currently has a special case. |
| 65 // Eliminate this once WebView is no longer a WebWidget. |
| 66 web_frame_widget_ = WebFrameWidget::create(this, web_view_, web_local_frame); |
60 } | 67 } |
61 | 68 |
62 // static | 69 // static |
63 WebViewPlugin* WebViewPlugin::Create(content::RenderView* render_view, | 70 WebViewPlugin* WebViewPlugin::Create(content::RenderView* render_view, |
64 WebViewPlugin::Delegate* delegate, | 71 WebViewPlugin::Delegate* delegate, |
65 const WebPreferences& preferences, | 72 const WebPreferences& preferences, |
66 const std::string& html_data, | 73 const std::string& html_data, |
67 const GURL& url) { | 74 const GURL& url) { |
68 DCHECK(url.is_valid()) << "Blink requires the WebView to have a valid URL."; | 75 DCHECK(url.is_valid()) << "Blink requires the WebView to have a valid URL."; |
69 WebViewPlugin* plugin = new WebViewPlugin(render_view, delegate, preferences); | 76 WebViewPlugin* plugin = new WebViewPlugin(render_view, delegate, preferences); |
70 plugin->web_view()->mainFrame()->loadHTMLString(html_data, url); | 77 plugin->web_view()->mainFrame()->loadHTMLString(html_data, url); |
71 return plugin; | 78 return plugin; |
72 } | 79 } |
73 | 80 |
74 WebViewPlugin::~WebViewPlugin() { | 81 WebViewPlugin::~WebViewPlugin() { |
| 82 web_frame_widget_->close(); |
75 web_view_->close(); | 83 web_view_->close(); |
76 web_frame_->close(); | 84 web_frame_->close(); |
77 } | 85 } |
78 | 86 |
79 void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) { | 87 void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) { |
80 if (!response_.isNull()) { | 88 if (!response_.isNull()) { |
81 plugin->didReceiveResponse(response_); | 89 plugin->didReceiveResponse(response_); |
82 size_t total_bytes = 0; | 90 size_t total_bytes = 0; |
83 for (std::list<std::string>::iterator it = data_.begin(); it != data_.end(); | 91 for (std::list<std::string>::iterator it = data_.begin(); it != data_.end(); |
84 ++it) { | 92 ++it) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // By default RenderViewObservers are destroyed along with the RenderView. | 321 // By default RenderViewObservers are destroyed along with the RenderView. |
314 // WebViewPlugin has a custom destruction mechanism, so we disable this. | 322 // WebViewPlugin has a custom destruction mechanism, so we disable this. |
315 } | 323 } |
316 | 324 |
317 void WebViewPlugin::OnZoomLevelChanged() { | 325 void WebViewPlugin::OnZoomLevelChanged() { |
318 if (container_) { | 326 if (container_) { |
319 web_view_->setZoomLevel( | 327 web_view_->setZoomLevel( |
320 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); | 328 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); |
321 } | 329 } |
322 } | 330 } |
OLD | NEW |