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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "ppapi/c/private/ppp_instance_private.h" | 33 #include "ppapi/c/private/ppp_instance_private.h" |
34 #include "ppapi/shared_impl/ppapi_preferences.h" | 34 #include "ppapi/shared_impl/ppapi_preferences.h" |
35 #include "ppapi/shared_impl/ppb_gamepad_shared.h" | 35 #include "ppapi/shared_impl/ppb_gamepad_shared.h" |
36 #include "ppapi/shared_impl/ppb_input_event_shared.h" | 36 #include "ppapi/shared_impl/ppb_input_event_shared.h" |
37 #include "ppapi/shared_impl/ppb_url_util_shared.h" | 37 #include "ppapi/shared_impl/ppb_url_util_shared.h" |
38 #include "ppapi/shared_impl/ppb_view_shared.h" | 38 #include "ppapi/shared_impl/ppb_view_shared.h" |
39 #include "ppapi/shared_impl/ppp_instance_combined.h" | 39 #include "ppapi/shared_impl/ppp_instance_combined.h" |
40 #include "ppapi/shared_impl/resource.h" | 40 #include "ppapi/shared_impl/resource.h" |
41 #include "ppapi/shared_impl/scoped_pp_resource.h" | 41 #include "ppapi/shared_impl/scoped_pp_resource.h" |
42 #include "ppapi/shared_impl/time_conversion.h" | 42 #include "ppapi/shared_impl/time_conversion.h" |
43 #include "ppapi/shared_impl/url_request_info_data.h" | |
43 #include "ppapi/shared_impl/var.h" | 44 #include "ppapi/shared_impl/var.h" |
44 #include "ppapi/thunk/enter.h" | 45 #include "ppapi/thunk/enter.h" |
45 #include "ppapi/thunk/ppb_buffer_api.h" | 46 #include "ppapi/thunk/ppb_buffer_api.h" |
46 #include "printing/metafile.h" | 47 #include "printing/metafile.h" |
47 #include "printing/metafile_skia_wrapper.h" | 48 #include "printing/metafile_skia_wrapper.h" |
48 #include "printing/units.h" | 49 #include "printing/units.h" |
49 #include "skia/ext/platform_device.h" | 50 #include "skia/ext/platform_device.h" |
50 #include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h" | 51 #include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h" |
51 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 52 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
52 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 53 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
54 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" | |
53 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" | 55 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" | 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" |
56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintParams.h" | 64 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintParams.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
78 #include "webkit/plugins/ppapi/fullscreen_container.h" | 80 #include "webkit/plugins/ppapi/fullscreen_container.h" |
79 #include "webkit/plugins/ppapi/gfx_conversion.h" | 81 #include "webkit/plugins/ppapi/gfx_conversion.h" |
80 #include "webkit/plugins/ppapi/host_globals.h" | 82 #include "webkit/plugins/ppapi/host_globals.h" |
81 #include "webkit/plugins/ppapi/message_channel.h" | 83 #include "webkit/plugins/ppapi/message_channel.h" |
82 #include "webkit/plugins/ppapi/npapi_glue.h" | 84 #include "webkit/plugins/ppapi/npapi_glue.h" |
83 #include "webkit/plugins/ppapi/plugin_module.h" | 85 #include "webkit/plugins/ppapi/plugin_module.h" |
84 #include "webkit/plugins/ppapi/plugin_object.h" | 86 #include "webkit/plugins/ppapi/plugin_object.h" |
85 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 87 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
86 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 88 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
87 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 89 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
88 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | |
89 #include "webkit/plugins/ppapi/ppp_pdf.h" | 90 #include "webkit/plugins/ppapi/ppp_pdf.h" |
90 #include "webkit/plugins/ppapi/url_request_info_util.h" | 91 #include "webkit/plugins/ppapi/url_request_info_util.h" |
91 #include "webkit/plugins/sad_plugin.h" | 92 #include "webkit/plugins/sad_plugin.h" |
92 | 93 |
93 #if defined(OS_MACOSX) | 94 #if defined(OS_MACOSX) |
94 #include "printing/metafile_impl.h" | 95 #include "printing/metafile_impl.h" |
95 #endif // defined(OS_MACOSX) | 96 #endif // defined(OS_MACOSX) |
96 | 97 |
97 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
98 #include "base/metrics/histogram.h" | 99 #include "base/metrics/histogram.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
127 using WebKit::WebDocument; | 128 using WebKit::WebDocument; |
128 using WebKit::WebElement; | 129 using WebKit::WebElement; |
129 using WebKit::WebFrame; | 130 using WebKit::WebFrame; |
130 using WebKit::WebInputEvent; | 131 using WebKit::WebInputEvent; |
131 using WebKit::WebPlugin; | 132 using WebKit::WebPlugin; |
132 using WebKit::WebPluginContainer; | 133 using WebKit::WebPluginContainer; |
133 using WebKit::WebPrintParams; | 134 using WebKit::WebPrintParams; |
134 using WebKit::WebPrintScalingOption; | 135 using WebKit::WebPrintScalingOption; |
135 using WebKit::WebScopedUserGesture; | 136 using WebKit::WebScopedUserGesture; |
136 using WebKit::WebString; | 137 using WebKit::WebString; |
138 using WebKit::WebURLError; | |
139 using WebKit::WebURLLoader; | |
140 using WebKit::WebURLLoaderClient; | |
137 using WebKit::WebURLRequest; | 141 using WebKit::WebURLRequest; |
142 using WebKit::WebURLResponse; | |
138 using WebKit::WebUserGestureIndicator; | 143 using WebKit::WebUserGestureIndicator; |
139 using WebKit::WebUserGestureToken; | 144 using WebKit::WebUserGestureToken; |
140 using WebKit::WebView; | 145 using WebKit::WebView; |
141 | 146 |
142 namespace webkit { | 147 namespace webkit { |
143 namespace ppapi { | 148 namespace ppapi { |
144 | 149 |
145 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
146 // Exported by pdf.dll | 151 // Exported by pdf.dll |
147 typedef bool (*RenderPDFPageToDCProc)( | 152 typedef bool (*RenderPDFPageToDCProc)( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 base::Callback<const void*(const char*)> get_plugin_interface_func = | 317 base::Callback<const void*(const char*)> get_plugin_interface_func = |
313 base::Bind(&PluginModule::GetPluginInterface, module); | 318 base::Bind(&PluginModule::GetPluginInterface, module); |
314 PPP_Instance_Combined* ppp_instance_combined = | 319 PPP_Instance_Combined* ppp_instance_combined = |
315 PPP_Instance_Combined::Create(get_plugin_interface_func); | 320 PPP_Instance_Combined::Create(get_plugin_interface_func); |
316 if (!ppp_instance_combined) | 321 if (!ppp_instance_combined) |
317 return NULL; | 322 return NULL; |
318 return new PluginInstance(delegate, module, ppp_instance_combined, container, | 323 return new PluginInstance(delegate, module, ppp_instance_combined, container, |
319 plugin_url); | 324 plugin_url); |
320 } | 325 } |
321 | 326 |
327 PluginInstance::NaClDocumentLoader::NaClDocumentLoader() | |
328 : finished_loading_(false) { | |
329 } | |
330 | |
331 PluginInstance::NaClDocumentLoader::~NaClDocumentLoader(){ | |
332 } | |
333 | |
334 void PluginInstance::NaClDocumentLoader::ReplayReceivedData( | |
335 WebURLLoaderClient* document_loader) { | |
336 for (std::list<std::string>::iterator it = data_.begin(); | |
337 it != data_.end(); ++it) { | |
338 document_loader->didReceiveData(NULL, it->c_str(), it->length(), | |
339 0 /* encoded_data_length */); | |
340 } | |
341 if (finished_loading_) { | |
342 document_loader->didFinishLoading(NULL, | |
343 0 /* finish_time */); | |
344 } | |
345 if (error_.get()) { | |
346 document_loader->didFail(NULL, *error_); | |
347 } | |
348 } | |
349 | |
350 void PluginInstance::NaClDocumentLoader::didReceiveData( | |
351 WebURLLoader* loader, | |
352 const char* data, | |
353 int data_length, | |
354 int encoded_data_length) { | |
355 data_.push_back(std::string(data, data_length)); | |
356 } | |
357 | |
358 void PluginInstance::NaClDocumentLoader::didFinishLoading( | |
359 WebURLLoader* loader, | |
360 double finish_time) { | |
361 DCHECK(!finished_loading_); | |
362 finished_loading_ = true; | |
363 } | |
364 | |
365 void PluginInstance::NaClDocumentLoader::didFail( | |
366 WebURLLoader* loader, | |
367 const WebURLError& error) { | |
368 DCHECK(!error_.get()); | |
369 error_.reset(new WebURLError(error)); | |
370 } | |
371 | |
322 PluginInstance::GamepadImpl::GamepadImpl(PluginDelegate* delegate) | 372 PluginInstance::GamepadImpl::GamepadImpl(PluginDelegate* delegate) |
323 : Resource(::ppapi::Resource::Untracked()), | 373 : Resource(::ppapi::Resource::Untracked()), |
324 delegate_(delegate) { | 374 delegate_(delegate) { |
325 } | 375 } |
326 | 376 |
327 PPB_Gamepad_API* PluginInstance::GamepadImpl::AsPPB_Gamepad_API() { | 377 PPB_Gamepad_API* PluginInstance::GamepadImpl::AsPPB_Gamepad_API() { |
328 return this; | 378 return this; |
329 } | 379 } |
330 | 380 |
331 void PluginInstance::GamepadImpl::Sample(PP_Instance /* instance */, | 381 void PluginInstance::GamepadImpl::Sample(PP_Instance /* instance */, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 message_channel_(NULL), | 428 message_channel_(NULL), |
379 sad_plugin_(NULL), | 429 sad_plugin_(NULL), |
380 input_event_mask_(0), | 430 input_event_mask_(0), |
381 filtered_input_event_mask_(0), | 431 filtered_input_event_mask_(0), |
382 text_input_type_(kPluginDefaultTextInputType), | 432 text_input_type_(kPluginDefaultTextInputType), |
383 text_input_caret_(0, 0, 0, 0), | 433 text_input_caret_(0, 0, 0, 0), |
384 text_input_caret_bounds_(0, 0, 0, 0), | 434 text_input_caret_bounds_(0, 0, 0, 0), |
385 text_input_caret_set_(false), | 435 text_input_caret_set_(false), |
386 selection_caret_(0), | 436 selection_caret_(0), |
387 selection_anchor_(0), | 437 selection_anchor_(0), |
388 pending_user_gesture_(0.0) { | 438 pending_user_gesture_(0.0), |
439 document_loader_(NULL), | |
440 nacl_document_load_(false) { | |
389 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 441 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
390 | 442 |
391 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 443 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
392 DCHECK(delegate); | 444 DCHECK(delegate); |
393 module_->InstanceCreated(this); | 445 module_->InstanceCreated(this); |
394 delegate_->InstanceCreated(this); | 446 delegate_->InstanceCreated(this); |
395 message_channel_.reset(new MessageChannel(this)); | 447 message_channel_.reset(new MessageChannel(this)); |
396 | 448 |
397 view_data_.is_page_visible = delegate->IsPageVisible(); | 449 view_data_.is_page_visible = delegate->IsPageVisible(); |
398 | 450 |
399 resource_creation_ = delegate_->CreateResourceCreationAPI(this); | 451 resource_creation_ = delegate_->CreateResourceCreationAPI(this); |
452 | |
453 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed. | |
454 // We must defer certain plugin events for NaCl instances since we switch | |
455 // from the in-process to the out-of-process proxy after instantiating them. | |
456 if (module->name() == "Native Client") | |
457 nacl_document_load_ = true; | |
bbudge
2013/05/08 14:29:49
If you can think of a better way to detect that th
bbudge
2013/05/10 00:07:27
The problem is that this is fragile. We could make
| |
400 } | 458 } |
401 | 459 |
402 PluginInstance::~PluginInstance() { | 460 PluginInstance::~PluginInstance() { |
403 DCHECK(!fullscreen_container_); | 461 DCHECK(!fullscreen_container_); |
404 | 462 |
405 // Force-unbind any Graphics. In the case of Graphics2D, if the plugin | 463 // Force-unbind any Graphics. In the case of Graphics2D, if the plugin |
406 // leaks the graphics 2D, it may actually get cleaned up after our | 464 // leaks the graphics 2D, it may actually get cleaned up after our |
407 // destruction, so we need its pointers to be up-to-date. | 465 // destruction, so we need its pointers to be up-to-date. |
408 BindGraphics(pp_instance(), 0); | 466 BindGraphics(pp_instance(), 0); |
409 | 467 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 scoped_ptr<const char*[]> argv_array(StringVectorToArgArray(argv_)); | 644 scoped_ptr<const char*[]> argv_array(StringVectorToArgArray(argv_)); |
587 bool success = PP_ToBool(instance_interface_->DidCreate(pp_instance(), | 645 bool success = PP_ToBool(instance_interface_->DidCreate(pp_instance(), |
588 argn_.size(), | 646 argn_.size(), |
589 argn_array.get(), | 647 argn_array.get(), |
590 argv_array.get())); | 648 argv_array.get())); |
591 if (success) | 649 if (success) |
592 message_channel_->StopQueueingJavaScriptMessages(); | 650 message_channel_->StopQueueingJavaScriptMessages(); |
593 return success; | 651 return success; |
594 } | 652 } |
595 | 653 |
596 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { | 654 bool PluginInstance::HandleDocumentLoad( |
597 if (!document_loader_) | 655 const WebKit::WebURLResponse& response) { |
598 document_loader_ = loader; | 656 DCHECK(!document_loader_); |
599 DCHECK(loader == document_loader_.get()); | 657 if (!nacl_document_load_) { |
600 | 658 if (module()->is_crashed()) { |
601 return PP_ToBool(instance_interface_->HandleDocumentLoad( | 659 // Don't create a resource for a crashed plugin. |
602 pp_instance(), loader->pp_resource())); | 660 container()->element().document().frame()->stopLoading(); |
661 return false; | |
662 } | |
663 delegate()->HandleDocumentLoad(this, response); | |
664 // If the load was not abandoned, document_loader_ will now be set. It's | |
665 // possible that the load was canceled by now and document_loader_ was | |
666 // already nulled out. | |
667 } else { | |
668 // The NaCl proxy isn't available, so save the response and record document | |
669 // load notifications for later replay. | |
670 nacl_document_response_ = response; | |
671 nacl_document_loader_.reset(new NaClDocumentLoader()); | |
672 document_loader_ = nacl_document_loader_.get(); | |
673 } | |
674 return true; | |
603 } | 675 } |
604 | 676 |
605 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type, | 677 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type, |
606 const base::string16& text) { | 678 const base::string16& text) { |
607 std::vector<WebKit::WebCompositionUnderline> empty; | 679 std::vector<WebKit::WebCompositionUnderline> empty; |
608 return SendCompositionEventWithUnderlineInformationToPlugin( | 680 return SendCompositionEventWithUnderlineInformationToPlugin( |
609 type, text, empty, static_cast<int>(text.size()), | 681 type, text, empty, static_cast<int>(text.size()), |
610 static_cast<int>(text.size())); | 682 static_cast<int>(text.size())); |
611 } | 683 } |
612 | 684 |
(...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2435 return PP_NACL_ERROR_INSTANCE; | 2507 return PP_NACL_ERROR_INSTANCE; |
2436 message_channel_->StopQueueingJavaScriptMessages(); | 2508 message_channel_->StopQueueingJavaScriptMessages(); |
2437 | 2509 |
2438 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView | 2510 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView |
2439 // event. This way, SendDidChangeView will send the "current" view | 2511 // event. This way, SendDidChangeView will send the "current" view |
2440 // immediately (before other events like HandleDocumentLoad). | 2512 // immediately (before other events like HandleDocumentLoad). |
2441 sent_initial_did_change_view_ = false; | 2513 sent_initial_did_change_view_ = false; |
2442 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | 2514 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); |
2443 SendDidChangeView(); | 2515 SendDidChangeView(); |
2444 | 2516 |
2445 // If we received HandleDocumentLoad, re-send it now via the proxy. | 2517 DCHECK(nacl_document_load_); |
2446 if (document_loader_) | 2518 nacl_document_load_ = false; |
2447 HandleDocumentLoad(document_loader_.get()); | 2519 if (!nacl_document_response_.isNull()) { |
2520 document_loader_ = NULL; | |
2521 // Pass the response to the nwe proxy. | |
2522 HandleDocumentLoad(nacl_document_response_); | |
2523 nacl_document_response_ = WebKit::WebURLResponse(); | |
2524 // Replay any document load events we've received through the real loader. | |
2525 nacl_document_loader_->ReplayReceivedData(document_loader_); | |
2526 nacl_document_loader_.reset(NULL); | |
2527 } | |
2528 | |
2448 return PP_NACL_OK; | 2529 return PP_NACL_OK; |
2449 } | 2530 } |
2450 | 2531 |
2451 bool PluginInstance::IsValidInstanceOf(PluginModule* module) { | 2532 bool PluginInstance::IsValidInstanceOf(PluginModule* module) { |
2452 DCHECK(module); | 2533 DCHECK(module); |
2453 return module == module_.get() || | 2534 return module == module_.get() || |
2454 module == original_module_.get(); | 2535 module == original_module_.get(); |
2455 } | 2536 } |
2456 | 2537 |
2457 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { | 2538 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2517 screen_size_for_fullscreen_ = gfx::Size(); | 2598 screen_size_for_fullscreen_ = gfx::Size(); |
2518 WebElement element = container_->element(); | 2599 WebElement element = container_->element(); |
2519 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2600 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2520 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2601 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2521 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2602 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2522 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2603 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2523 } | 2604 } |
2524 | 2605 |
2525 } // namespace ppapi | 2606 } // namespace ppapi |
2526 } // namespace webkit | 2607 } // namespace webkit |
OLD | NEW |