OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/glue/plugins/pepper_webplugin_impl.h" | |
6 | |
7 #include <cmath> | |
8 | |
9 #include "base/message_loop.h" | |
10 #include "ppapi/c/pp_var.h" | |
11 #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" | |
12 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | |
13 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | |
14 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | |
15 #include "webkit/glue/plugins/pepper_plugin_instance.h" | |
16 #include "webkit/glue/plugins/pepper_plugin_module.h" | |
17 #include "webkit/glue/plugins/pepper_url_loader.h" | |
18 #include "webkit/glue/plugins/pepper_var.h" | |
19 | |
20 using WebKit::WebCanvas; | |
21 using WebKit::WebPluginContainer; | |
22 using WebKit::WebPluginParams; | |
23 using WebKit::WebPoint; | |
24 using WebKit::WebRect; | |
25 using WebKit::WebString; | |
26 using WebKit::WebURL; | |
27 using WebKit::WebVector; | |
28 using WebKit::WebView; | |
29 | |
30 namespace pepper { | |
31 | |
32 struct WebPluginImpl::InitData { | |
33 scoped_refptr<PluginModule> module; | |
34 base::WeakPtr<PluginDelegate> delegate; | |
35 std::vector<std::string> arg_names; | |
36 std::vector<std::string> arg_values; | |
37 }; | |
38 | |
39 WebPluginImpl::WebPluginImpl( | |
40 PluginModule* plugin_module, | |
41 const WebPluginParams& params, | |
42 const base::WeakPtr<PluginDelegate>& plugin_delegate) | |
43 : init_data_(new InitData()), | |
44 full_frame_(params.loadManually) { | |
45 DCHECK(plugin_module); | |
46 init_data_->module = plugin_module; | |
47 init_data_->delegate = plugin_delegate; | |
48 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | |
49 init_data_->arg_names.push_back(params.attributeNames[i].utf8()); | |
50 init_data_->arg_values.push_back(params.attributeValues[i].utf8()); | |
51 } | |
52 } | |
53 | |
54 WebPluginImpl::~WebPluginImpl() { | |
55 } | |
56 | |
57 bool WebPluginImpl::initialize(WebPluginContainer* container) { | |
58 // The plugin delegate may have gone away. | |
59 if (!init_data_->delegate) | |
60 return false; | |
61 | |
62 instance_ = init_data_->module->CreateInstance(init_data_->delegate); | |
63 if (!instance_) | |
64 return false; | |
65 | |
66 bool success = instance_->Initialize(container, | |
67 init_data_->arg_names, | |
68 init_data_->arg_values, | |
69 full_frame_); | |
70 if (!success) { | |
71 instance_->Delete(); | |
72 instance_ = NULL; | |
73 return false; | |
74 } | |
75 | |
76 init_data_.reset(); | |
77 return true; | |
78 } | |
79 | |
80 void WebPluginImpl::destroy() { | |
81 if (instance_) { | |
82 instance_->Delete(); | |
83 instance_ = NULL; | |
84 } | |
85 | |
86 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
87 } | |
88 | |
89 NPObject* WebPluginImpl::scriptableObject() { | |
90 scoped_refptr<ObjectVar> object( | |
91 ObjectVar::FromPPVar(instance_->GetInstanceObject())); | |
92 if (object) | |
93 return object->np_object(); | |
94 return NULL; | |
95 } | |
96 | |
97 void WebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { | |
98 if (!instance_->IsFullscreen()) | |
99 instance_->Paint(canvas, plugin_rect_, rect); | |
100 } | |
101 | |
102 void WebPluginImpl::updateGeometry( | |
103 const WebRect& window_rect, | |
104 const WebRect& clip_rect, | |
105 const WebVector<WebRect>& cut_outs_rects, | |
106 bool is_visible) { | |
107 plugin_rect_ = window_rect; | |
108 if (!instance_->IsFullscreen()) | |
109 instance_->ViewChanged(plugin_rect_, clip_rect); | |
110 } | |
111 | |
112 unsigned WebPluginImpl::getBackingTextureId() { | |
113 return instance_->GetBackingTextureId(); | |
114 } | |
115 | |
116 void WebPluginImpl::updateFocus(bool focused) { | |
117 instance_->SetWebKitFocus(focused); | |
118 } | |
119 | |
120 void WebPluginImpl::updateVisibility(bool visible) { | |
121 } | |
122 | |
123 bool WebPluginImpl::acceptsInputEvents() { | |
124 return true; | |
125 } | |
126 | |
127 bool WebPluginImpl::handleInputEvent(const WebKit::WebInputEvent& event, | |
128 WebKit::WebCursorInfo& cursor_info) { | |
129 if (instance_->IsFullscreen()) | |
130 return false; | |
131 return instance_->HandleInputEvent(event, &cursor_info); | |
132 } | |
133 | |
134 void WebPluginImpl::didReceiveResponse( | |
135 const WebKit::WebURLResponse& response) { | |
136 DCHECK(!document_loader_); | |
137 | |
138 document_loader_ = new URLLoader(instance_, true); | |
139 document_loader_->didReceiveResponse(NULL, response); | |
140 | |
141 if (!instance_->HandleDocumentLoad(document_loader_)) | |
142 document_loader_ = NULL; | |
143 } | |
144 | |
145 void WebPluginImpl::didReceiveData(const char* data, int data_length) { | |
146 if (document_loader_) | |
147 document_loader_->didReceiveData(NULL, data, data_length); | |
148 } | |
149 | |
150 void WebPluginImpl::didFinishLoading() { | |
151 if (document_loader_) { | |
152 document_loader_->didFinishLoading(NULL, 0); | |
153 document_loader_ = NULL; | |
154 } | |
155 } | |
156 | |
157 void WebPluginImpl::didFailLoading(const WebKit::WebURLError& error) { | |
158 if (document_loader_) { | |
159 document_loader_->didFail(NULL, error); | |
160 document_loader_ = NULL; | |
161 } | |
162 } | |
163 | |
164 void WebPluginImpl::didFinishLoadingFrameRequest(const WebKit::WebURL& url, | |
165 void* notify_data) { | |
166 } | |
167 | |
168 void WebPluginImpl::didFailLoadingFrameRequest( | |
169 const WebKit::WebURL& url, | |
170 void* notify_data, | |
171 const WebKit::WebURLError& error) { | |
172 } | |
173 | |
174 bool WebPluginImpl::hasSelection() const { | |
175 return !selectionAsText().isEmpty(); | |
176 } | |
177 | |
178 WebString WebPluginImpl::selectionAsText() const { | |
179 return instance_->GetSelectedText(false); | |
180 } | |
181 | |
182 WebString WebPluginImpl::selectionAsMarkup() const { | |
183 return instance_->GetSelectedText(true); | |
184 } | |
185 | |
186 WebURL WebPluginImpl::linkAtPosition(const WebPoint& position) const { | |
187 return GURL(instance_->GetLinkAtPosition(position)); | |
188 } | |
189 | |
190 void WebPluginImpl::setZoomLevel(double level, bool text_only) { | |
191 instance_->Zoom(WebView::zoomLevelToZoomFactor(level), text_only); | |
192 } | |
193 | |
194 bool WebPluginImpl::startFind(const WebKit::WebString& search_text, | |
195 bool case_sensitive, | |
196 int identifier) { | |
197 return instance_->StartFind(search_text, case_sensitive, identifier); | |
198 } | |
199 | |
200 void WebPluginImpl::selectFindResult(bool forward) { | |
201 instance_->SelectFindResult(forward); | |
202 } | |
203 | |
204 void WebPluginImpl::stopFind() { | |
205 instance_->StopFind(); | |
206 } | |
207 | |
208 bool WebPluginImpl::supportsPaginatedPrint() { | |
209 return instance_->SupportsPrintInterface(); | |
210 } | |
211 | |
212 int WebPluginImpl::printBegin(const WebKit::WebRect& printable_area, | |
213 int printer_dpi) { | |
214 return instance_->PrintBegin(printable_area, printer_dpi); | |
215 } | |
216 | |
217 bool WebPluginImpl::printPage(int page_number, | |
218 WebKit::WebCanvas* canvas) { | |
219 return instance_->PrintPage(page_number, canvas); | |
220 } | |
221 | |
222 void WebPluginImpl::printEnd() { | |
223 return instance_->PrintEnd(); | |
224 } | |
225 | |
226 } // namespace pepper | |
OLD | NEW |