OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/child/npapi/webplugin_delegate_impl.h" | 5 #include "content/child/npapi/webplugin_delegate_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "content/child/npapi/plugin_instance.h" | 15 #include "content/child/npapi/plugin_instance.h" |
16 #include "content/child/npapi/plugin_lib.h" | 16 #include "content/child/npapi/plugin_lib.h" |
17 #include "content/child/npapi/plugin_stream_url.h" | |
18 #include "content/child/npapi/plugin_url_fetcher.h" | |
19 #include "third_party/WebKit/public/web/WebInputEvent.h" | 17 #include "third_party/WebKit/public/web/WebInputEvent.h" |
20 | 18 |
21 using blink::WebCursorInfo; | 19 using blink::WebCursorInfo; |
22 using blink::WebInputEvent; | 20 using blink::WebInputEvent; |
23 | 21 |
24 namespace content { | 22 namespace content { |
25 | 23 |
26 WebPluginDelegateImpl* WebPluginDelegateImpl::Create( | 24 WebPluginDelegateImpl* WebPluginDelegateImpl::Create( |
27 WebPlugin* plugin, | 25 WebPlugin* plugin, |
28 const base::FilePath& filename, | 26 const base::FilePath& filename, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 93 |
96 bool should_load = PlatformInitialize(); | 94 bool should_load = PlatformInitialize(); |
97 | 95 |
98 plugin_url_ = url.spec(); | 96 plugin_url_ = url.spec(); |
99 | 97 |
100 return should_load; | 98 return should_load; |
101 } | 99 } |
102 | 100 |
103 void WebPluginDelegateImpl::DestroyInstance() { | 101 void WebPluginDelegateImpl::DestroyInstance() { |
104 if (instance_.get() && (instance_->npp()->ndata != NULL)) { | 102 if (instance_.get() && (instance_->npp()->ndata != NULL)) { |
105 // Shutdown all streams before destroying so that | |
106 // no streams are left "in progress". Need to do | |
107 // this before calling set_web_plugin(NULL) because the | |
108 // instance uses the helper to do the download. | |
109 instance_->CloseStreams(); | |
110 | |
111 window_.window = NULL; | 103 window_.window = NULL; |
112 if (creation_succeeded_ && | 104 if (creation_succeeded_ && |
113 !(quirks_ & PLUGIN_QUIRK_DONT_SET_NULL_WINDOW_HANDLE_ON_DESTROY)) { | 105 !(quirks_ & PLUGIN_QUIRK_DONT_SET_NULL_WINDOW_HANDLE_ON_DESTROY)) { |
114 instance_->NPP_SetWindow(&window_); | 106 instance_->NPP_SetWindow(&window_); |
115 } | 107 } |
116 | 108 |
117 instance_->NPP_Destroy(); | 109 instance_->NPP_Destroy(); |
118 | 110 |
119 instance_->set_web_plugin(NULL); | 111 instance_->set_web_plugin(NULL); |
120 | 112 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 178 } |
187 | 179 |
188 NPP WebPluginDelegateImpl::GetPluginNPP() { | 180 NPP WebPluginDelegateImpl::GetPluginNPP() { |
189 return instance_->npp(); | 181 return instance_->npp(); |
190 } | 182 } |
191 | 183 |
192 bool WebPluginDelegateImpl::GetFormValue(base::string16* value) { | 184 bool WebPluginDelegateImpl::GetFormValue(base::string16* value) { |
193 return instance_->GetFormValue(value); | 185 return instance_->GetFormValue(value); |
194 } | 186 } |
195 | 187 |
196 void WebPluginDelegateImpl::DidFinishLoadWithReason(const GURL& url, | |
197 NPReason reason, | |
198 int notify_id) { | |
199 if (quirks_ & PLUGIN_QUIRK_ALWAYS_NOTIFY_SUCCESS && | |
200 reason == NPRES_NETWORK_ERR) { | |
201 // Flash needs this or otherwise it unloads the launching swf object. | |
202 reason = NPRES_DONE; | |
203 } | |
204 | |
205 instance()->DidFinishLoadWithReason(url, reason, notify_id); | |
206 } | |
207 | |
208 int WebPluginDelegateImpl::GetProcessId() { | 188 int WebPluginDelegateImpl::GetProcessId() { |
209 // We are in process, so the plugin pid is this current process pid. | 189 // We are in process, so the plugin pid is this current process pid. |
210 return base::GetCurrentProcId(); | 190 return base::GetCurrentProcId(); |
211 } | 191 } |
212 | 192 |
213 void WebPluginDelegateImpl::SendJavaScriptStream(const GURL& url, | |
214 const std::string& result, | |
215 bool success, | |
216 int notify_id) { | |
217 instance()->SendJavaScriptStream(url, result, success, notify_id); | |
218 } | |
219 | |
220 void WebPluginDelegateImpl::DidReceiveManualResponse( | |
221 const GURL& url, const std::string& mime_type, | |
222 const std::string& headers, uint32 expected_length, uint32 last_modified) { | |
223 if (!windowless_) { | |
224 // Calling NPP_WriteReady before NPP_SetWindow causes movies to not load in | |
225 // Flash. See http://b/issue?id=892174. | |
226 DCHECK(windowed_did_set_window_); | |
227 } | |
228 | |
229 instance()->DidReceiveManualResponse(url, mime_type, headers, | |
230 expected_length, last_modified); | |
231 } | |
232 | |
233 void WebPluginDelegateImpl::DidReceiveManualData(const char* buffer, | |
234 int length) { | |
235 instance()->DidReceiveManualData(buffer, length); | |
236 } | |
237 | |
238 void WebPluginDelegateImpl::DidFinishManualLoading() { | |
239 instance()->DidFinishManualLoading(); | |
240 } | |
241 | |
242 void WebPluginDelegateImpl::DidManualLoadFail() { | |
243 instance()->DidManualLoadFail(); | |
244 } | |
245 | |
246 base::FilePath WebPluginDelegateImpl::GetPluginPath() { | 193 base::FilePath WebPluginDelegateImpl::GetPluginPath() { |
247 return instance()->plugin_lib()->plugin_info().path; | 194 return instance()->plugin_lib()->plugin_info().path; |
248 } | 195 } |
249 | 196 |
250 void WebPluginDelegateImpl::WindowedUpdateGeometry( | 197 void WebPluginDelegateImpl::WindowedUpdateGeometry( |
251 const gfx::Rect& window_rect, | 198 const gfx::Rect& window_rect, |
252 const gfx::Rect& clip_rect) { | 199 const gfx::Rect& clip_rect) { |
253 if (WindowedReposition(window_rect, clip_rect) || | 200 if (WindowedReposition(window_rect, clip_rect) || |
254 !windowed_did_set_window_) { | 201 !windowed_did_set_window_) { |
255 // Let the plugin know that it has been moved | 202 // Let the plugin know that it has been moved |
(...skipping 26 matching lines...) Expand all Loading... |
282 case WebInputEvent::MouseDown: | 229 case WebInputEvent::MouseDown: |
283 case WebInputEvent::MouseUp: | 230 case WebInputEvent::MouseUp: |
284 case WebInputEvent::KeyDown: | 231 case WebInputEvent::KeyDown: |
285 case WebInputEvent::KeyUp: | 232 case WebInputEvent::KeyUp: |
286 return true; | 233 return true; |
287 default: | 234 default: |
288 return false; | 235 return false; |
289 } | 236 } |
290 } | 237 } |
291 | 238 |
292 WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( | |
293 unsigned long resource_id, const GURL& url, int notify_id) { | |
294 return instance()->CreateStream( | |
295 resource_id, url, std::string(), notify_id); | |
296 } | |
297 | |
298 WebPluginResourceClient* WebPluginDelegateImpl::CreateSeekableResourceClient( | |
299 unsigned long resource_id, int range_request_id) { | |
300 WebPluginResourceClient* resource_client = instance()->GetRangeRequest( | |
301 range_request_id); | |
302 if (resource_client) | |
303 resource_client->AddRangeRequestResourceId(resource_id); | |
304 return resource_client; | |
305 } | |
306 | |
307 void WebPluginDelegateImpl::FetchURL(unsigned long resource_id, | |
308 int notify_id, | |
309 const GURL& url, | |
310 const GURL& first_party_for_cookies, | |
311 const std::string& method, | |
312 const char* buf, | |
313 unsigned int len, | |
314 const Referrer& referrer, | |
315 bool notify_redirects, | |
316 bool is_plugin_src_load, | |
317 int origin_pid, | |
318 int render_frame_id, | |
319 int render_view_id) { | |
320 // TODO(jam): once we switch over to resource loading always happening in this | |
321 // code path, remove WebPluginResourceClient abstraction. | |
322 PluginStreamUrl* plugin_stream = instance()->CreateStream( | |
323 resource_id, url, std::string(), notify_id); | |
324 | |
325 bool copy_stream_data = !!(quirks_ & PLUGIN_QUIRK_COPY_STREAM_DATA); | |
326 plugin_stream->SetPluginURLFetcher(new PluginURLFetcher( | |
327 plugin_stream, url, first_party_for_cookies, method, buf, len, | |
328 referrer, std::string(), notify_redirects, is_plugin_src_load, origin_pid, | |
329 render_frame_id, render_view_id, resource_id, copy_stream_data)); | |
330 } | |
331 | |
332 } // namespace content | 239 } // namespace content |
OLD | NEW |