Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 14371021: Implementation of URLLoader using PluginResource/ResourceHost. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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) {
brettw 2013/05/15 17:14:29 Indent 1 more space.
bbudge 2013/05/15 19:05:27 Done.
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
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(&current_print_settings_, 0, sizeof(current_print_settings_)); 443 memset(&current_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;
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 scoped_ptr<const char*[]> argv_array(StringVectorToArgArray(argv_)); 647 scoped_ptr<const char*[]> argv_array(StringVectorToArgArray(argv_));
590 bool success = PP_ToBool(instance_interface_->DidCreate(pp_instance(), 648 bool success = PP_ToBool(instance_interface_->DidCreate(pp_instance(),
591 argn_.size(), 649 argn_.size(),
592 argn_array.get(), 650 argn_array.get(),
593 argv_array.get())); 651 argv_array.get()));
594 if (success) 652 if (success)
595 message_channel_->StopQueueingJavaScriptMessages(); 653 message_channel_->StopQueueingJavaScriptMessages();
596 return success; 654 return success;
597 } 655 }
598 656
599 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { 657 bool PluginInstance::HandleDocumentLoad(
600 if (!document_loader_) 658 const WebKit::WebURLResponse& response) {
601 document_loader_ = loader; 659 DCHECK(!document_loader_);
602 DCHECK(loader == document_loader_.get()); 660 if (!nacl_document_load_) {
603 661 if (module()->is_crashed()) {
604 return PP_ToBool(instance_interface_->HandleDocumentLoad( 662 // Don't create a resource for a crashed plugin.
605 pp_instance(), loader->pp_resource())); 663 container()->element().document().frame()->stopLoading();
664 return false;
665 }
666 delegate()->HandleDocumentLoad(this, response);
667 // If the load was not abandoned, document_loader_ will now be set. It's
668 // possible that the load was canceled by now and document_loader_ was
669 // already nulled out.
670 } else {
671 // The NaCl proxy isn't available, so save the response and record document
672 // load notifications for later replay.
673 nacl_document_response_ = response;
674 nacl_document_loader_.reset(new NaClDocumentLoader());
675 document_loader_ = nacl_document_loader_.get();
676 }
677 return true;
606 } 678 }
607 679
608 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type, 680 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type,
609 const base::string16& text) { 681 const base::string16& text) {
610 std::vector<WebKit::WebCompositionUnderline> empty; 682 std::vector<WebKit::WebCompositionUnderline> empty;
611 return SendCompositionEventWithUnderlineInformationToPlugin( 683 return SendCompositionEventWithUnderlineInformationToPlugin(
612 type, text, empty, static_cast<int>(text.size()), 684 type, text, empty, static_cast<int>(text.size()),
613 static_cast<int>(text.size())); 685 static_cast<int>(text.size()));
614 } 686 }
615 687
(...skipping 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 return PP_NACL_ERROR_INSTANCE; 2516 return PP_NACL_ERROR_INSTANCE;
2445 message_channel_->StopQueueingJavaScriptMessages(); 2517 message_channel_->StopQueueingJavaScriptMessages();
2446 2518
2447 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView 2519 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView
2448 // event. This way, SendDidChangeView will send the "current" view 2520 // event. This way, SendDidChangeView will send the "current" view
2449 // immediately (before other events like HandleDocumentLoad). 2521 // immediately (before other events like HandleDocumentLoad).
2450 sent_initial_did_change_view_ = false; 2522 sent_initial_did_change_view_ = false;
2451 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); 2523 view_change_weak_ptr_factory_.InvalidateWeakPtrs();
2452 SendDidChangeView(); 2524 SendDidChangeView();
2453 2525
2454 // If we received HandleDocumentLoad, re-send it now via the proxy. 2526 DCHECK(nacl_document_load_);
2455 if (document_loader_) 2527 nacl_document_load_ = false;
2456 HandleDocumentLoad(document_loader_.get()); 2528 if (!nacl_document_response_.isNull()) {
2529 document_loader_ = NULL;
2530 // Pass the response to the nwe proxy.
brettw 2013/05/15 17:14:29 "nwe"
bbudge 2013/05/15 19:05:27 Done.
2531 HandleDocumentLoad(nacl_document_response_);
2532 nacl_document_response_ = WebKit::WebURLResponse();
2533 // Replay any document load events we've received through the real loader.
2534 nacl_document_loader_->ReplayReceivedData(document_loader_);
2535 nacl_document_loader_.reset(NULL);
2536 }
2537
2457 return PP_NACL_OK; 2538 return PP_NACL_OK;
2458 } 2539 }
2459 2540
2460 bool PluginInstance::IsValidInstanceOf(PluginModule* module) { 2541 bool PluginInstance::IsValidInstanceOf(PluginModule* module) {
2461 DCHECK(module); 2542 DCHECK(module);
2462 return module == module_.get() || 2543 return module == module_.get() ||
2463 module == original_module_.get(); 2544 module == original_module_.get();
2464 } 2545 }
2465 2546
2466 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { 2547 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 screen_size_for_fullscreen_ = gfx::Size(); 2607 screen_size_for_fullscreen_ = gfx::Size();
2527 WebElement element = container_->element(); 2608 WebElement element = container_->element();
2528 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2609 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2529 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2610 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2530 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2611 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2531 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2612 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2532 } 2613 }
2533 2614
2534 } // namespace ppapi 2615 } // namespace ppapi
2535 } // namespace webkit 2616 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | webkit/plugins/ppapi/ppapi_webplugin_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698