| 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/renderer/pepper/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "content/renderer/pepper/common.h" | 24 #include "content/renderer/pepper/common.h" |
| 25 #include "content/renderer/pepper/content_decryptor_delegate.h" | 25 #include "content/renderer/pepper/content_decryptor_delegate.h" |
| 26 #include "content/renderer/pepper/event_conversion.h" | 26 #include "content/renderer/pepper/event_conversion.h" |
| 27 #include "content/renderer/pepper/fullscreen_container.h" | 27 #include "content/renderer/pepper/fullscreen_container.h" |
| 28 #include "content/renderer/pepper/gfx_conversion.h" | 28 #include "content/renderer/pepper/gfx_conversion.h" |
| 29 #include "content/renderer/pepper/host_dispatcher_wrapper.h" | 29 #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
| 30 #include "content/renderer/pepper/host_globals.h" | 30 #include "content/renderer/pepper/host_globals.h" |
| 31 #include "content/renderer/pepper/message_channel.h" | 31 #include "content/renderer/pepper/message_channel.h" |
| 32 #include "content/renderer/pepper/npapi_glue.h" | 32 #include "content/renderer/pepper/npapi_glue.h" |
| 33 #include "content/renderer/pepper/pepper_browser_connection.h" | 33 #include "content/renderer/pepper/pepper_browser_connection.h" |
| 34 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
| 34 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 35 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
| 35 #include "content/renderer/pepper/pepper_in_process_router.h" | 36 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 36 #include "content/renderer/pepper/pepper_platform_context_3d.h" | 37 #include "content/renderer/pepper/pepper_platform_context_3d.h" |
| 37 #include "content/renderer/pepper/pepper_url_loader_host.h" | 38 #include "content/renderer/pepper/pepper_url_loader_host.h" |
| 38 #include "content/renderer/pepper/plugin_module.h" | 39 #include "content/renderer/pepper/plugin_module.h" |
| 39 #include "content/renderer/pepper/plugin_object.h" | 40 #include "content/renderer/pepper/plugin_object.h" |
| 40 #include "content/renderer/pepper/ppb_buffer_impl.h" | 41 #include "content/renderer/pepper/ppb_buffer_impl.h" |
| 41 #include "content/renderer/pepper/ppb_file_ref_impl.h" | |
| 42 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 42 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
| 43 #include "content/renderer/pepper/ppb_image_data_impl.h" | 43 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 44 #include "content/renderer/pepper/ppp_pdf.h" | 44 #include "content/renderer/pepper/ppp_pdf.h" |
| 45 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 45 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| 46 #include "content/renderer/pepper/url_request_info_util.h" | 46 #include "content/renderer/pepper/url_request_info_util.h" |
| 47 #include "content/renderer/pepper/url_response_info_util.h" | 47 #include "content/renderer/pepper/url_response_info_util.h" |
| 48 #include "content/renderer/render_thread_impl.h" | 48 #include "content/renderer/render_thread_impl.h" |
| 49 #include "content/renderer/render_view_impl.h" | 49 #include "content/renderer/render_view_impl.h" |
| 50 #include "content/renderer/render_widget_fullscreen_pepper.h" | 50 #include "content/renderer/render_widget_fullscreen_pepper.h" |
| 51 #include "content/renderer/sad_plugin.h" | 51 #include "content/renderer/sad_plugin.h" |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 771 |
| 772 // This host will be pending until the resource object attaches to it. | 772 // This host will be pending until the resource object attaches to it. |
| 773 // | 773 // |
| 774 // PpapiHost now owns the pointer to loader_host, so we don't have to worry | 774 // PpapiHost now owns the pointer to loader_host, so we don't have to worry |
| 775 // about managing it. | 775 // about managing it. |
| 776 int pending_host_id = host_impl->GetPpapiHost()->AddPendingResourceHost( | 776 int pending_host_id = host_impl->GetPpapiHost()->AddPendingResourceHost( |
| 777 scoped_ptr<ppapi::host::ResourceHost>(loader_host)); | 777 scoped_ptr<ppapi::host::ResourceHost>(loader_host)); |
| 778 DCHECK(pending_host_id); | 778 DCHECK(pending_host_id); |
| 779 | 779 |
| 780 DataFromWebURLResponse( | 780 DataFromWebURLResponse( |
| 781 host_impl, |
| 781 pp_instance(), | 782 pp_instance(), |
| 782 response, | 783 response, |
| 783 base::Bind(&PepperPluginInstanceImpl::DidDataFromWebURLResponse, | 784 base::Bind(&PepperPluginInstanceImpl::DidDataFromWebURLResponse, |
| 784 AsWeakPtr(), | 785 AsWeakPtr(), |
| 785 response, | 786 response, |
| 786 pending_host_id)); | 787 pending_host_id)); |
| 787 | 788 |
| 788 // If the load was not abandoned, document_loader_ will now be set. It's | 789 // If the load was not abandoned, document_loader_ will now be set. It's |
| 789 // possible that the load was canceled by now and document_loader_ was | 790 // possible that the load was canceled by now and document_loader_ was |
| 790 // already nulled out. | 791 // already nulled out. |
| (...skipping 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2667 } | 2668 } |
| 2668 | 2669 |
| 2669 const GURL& PepperPluginInstanceImpl::GetPluginURL() { | 2670 const GURL& PepperPluginInstanceImpl::GetPluginURL() { |
| 2670 return plugin_url_; | 2671 return plugin_url_; |
| 2671 } | 2672 } |
| 2672 | 2673 |
| 2673 base::FilePath PepperPluginInstanceImpl::GetModulePath() { | 2674 base::FilePath PepperPluginInstanceImpl::GetModulePath() { |
| 2674 return module_->path(); | 2675 return module_->path(); |
| 2675 } | 2676 } |
| 2676 | 2677 |
| 2677 PP_Resource PepperPluginInstanceImpl::CreateExternalFileReference( | |
| 2678 const base::FilePath& external_file_path) { | |
| 2679 PPB_FileRef_Impl* ref = PPB_FileRef_Impl::CreateExternal( | |
| 2680 pp_instance(), external_file_path, ""); | |
| 2681 return ref->GetReference(); | |
| 2682 } | |
| 2683 | |
| 2684 PP_Resource PepperPluginInstanceImpl::CreateImage(gfx::ImageSkia* source_image, | 2678 PP_Resource PepperPluginInstanceImpl::CreateImage(gfx::ImageSkia* source_image, |
| 2685 float scale) { | 2679 float scale) { |
| 2686 ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale); | 2680 ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale); |
| 2687 gfx::ImageSkiaRep image_skia_rep = source_image->GetRepresentation( | 2681 gfx::ImageSkiaRep image_skia_rep = source_image->GetRepresentation( |
| 2688 scale_factor); | 2682 scale_factor); |
| 2689 | 2683 |
| 2690 if (image_skia_rep.is_null() || image_skia_rep.scale_factor() != scale_factor) | 2684 if (image_skia_rep.is_null() || image_skia_rep.scale_factor() != scale_factor) |
| 2691 return 0; | 2685 return 0; |
| 2692 | 2686 |
| 2693 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl( | 2687 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2810 return PP_ERROR_FAILED; | 2804 return PP_ERROR_FAILED; |
| 2811 | 2805 |
| 2812 WebDocument document = container_->element().document(); | 2806 WebDocument document = container_->element().document(); |
| 2813 WebFrame* frame = document.frame(); | 2807 WebFrame* frame = document.frame(); |
| 2814 if (!frame) | 2808 if (!frame) |
| 2815 return PP_ERROR_FAILED; | 2809 return PP_ERROR_FAILED; |
| 2816 | 2810 |
| 2817 ppapi::URLRequestInfoData completed_request = request; | 2811 ppapi::URLRequestInfoData completed_request = request; |
| 2818 | 2812 |
| 2819 WebURLRequest web_request; | 2813 WebURLRequest web_request; |
| 2820 if (!CreateWebURLRequest(&completed_request, frame, &web_request)) | 2814 if (!CreateWebURLRequest(pp_instance_, |
| 2815 &completed_request, |
| 2816 frame, |
| 2817 &web_request)) { |
| 2821 return PP_ERROR_FAILED; | 2818 return PP_ERROR_FAILED; |
| 2819 } |
| 2822 web_request.setFirstPartyForCookies(document.firstPartyForCookies()); | 2820 web_request.setFirstPartyForCookies(document.firstPartyForCookies()); |
| 2823 web_request.setHasUserGesture(from_user_action); | 2821 web_request.setHasUserGesture(from_user_action); |
| 2824 | 2822 |
| 2825 GURL gurl(web_request.url()); | 2823 GURL gurl(web_request.url()); |
| 2826 if (gurl.SchemeIs("javascript")) { | 2824 if (gurl.SchemeIs("javascript")) { |
| 2827 // In imitation of the NPAPI implementation, only |target_frame == frame| is | 2825 // In imitation of the NPAPI implementation, only |target_frame == frame| is |
| 2828 // allowed for security reasons. | 2826 // allowed for security reasons. |
| 2829 WebFrame* target_frame = | 2827 WebFrame* target_frame = |
| 2830 frame->view()->findFrameByName(WebString::fromUTF8(target), frame); | 2828 frame->view()->findFrameByName(WebString::fromUTF8(target), frame); |
| 2831 if (target_frame != frame) | 2829 if (target_frame != frame) |
| 2832 return PP_ERROR_NOACCESS; | 2830 return PP_ERROR_NOACCESS; |
| 2833 | 2831 |
| 2834 // TODO(viettrungluu): NPAPI sends the result back to the plugin -- do we | 2832 // TODO(viettrungluu): NPAPI sends the result back to the plugin -- do we |
| 2835 // need that? | 2833 // need that? |
| 2836 WebString result = container_->executeScriptURL(gurl, from_user_action); | 2834 WebString result = container_->executeScriptURL(gurl, from_user_action); |
| 2837 return result.isNull() ? PP_ERROR_FAILED : PP_OK; | 2835 return result.isNull() ? PP_ERROR_FAILED : PP_OK; |
| 2838 } | 2836 } |
| 2839 | 2837 |
| 2840 // Only GETs and POSTs are supported. | 2838 // Only GETs and POSTs are supported. |
| 2841 if (web_request.httpMethod() != "GET" && | 2839 if (web_request.httpMethod() != "GET" && |
| 2842 web_request.httpMethod() != "POST") | 2840 web_request.httpMethod() != "POST") |
| 2843 return PP_ERROR_BADARGUMENT; | 2841 return PP_ERROR_BADARGUMENT; |
| 2844 | 2842 |
| 2845 WebString target_str = WebString::fromUTF8(target); | 2843 WebString target_str = WebString::fromUTF8(target); |
| 2846 container_->loadFrameRequest(web_request, target_str, false, NULL); | 2844 container_->loadFrameRequest(web_request, target_str, false, NULL); |
| 2847 return PP_OK; | 2845 return PP_OK; |
| 2848 } | 2846 } |
| 2849 | 2847 |
| 2848 int PepperPluginInstanceImpl::MakePendingFileRefRendererHost( |
| 2849 const base::FilePath& path) { |
| 2850 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
| 2851 PepperFileRefRendererHost* file_ref_host( |
| 2852 new PepperFileRefRendererHost(host_impl, pp_instance(), 0, path)); |
| 2853 return host_impl->GetPpapiHost()->AddPendingResourceHost( |
| 2854 scoped_ptr<ppapi::host::ResourceHost>(file_ref_host)); |
| 2855 } |
| 2856 |
| 2850 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { | 2857 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { |
| 2851 if (!container_) | 2858 if (!container_) |
| 2852 return false; | 2859 return false; |
| 2853 WebKit::WebDocument containing_document = container_->element().document(); | 2860 WebKit::WebDocument containing_document = container_->element().document(); |
| 2854 | 2861 |
| 2855 if (!containing_document.frame() || | 2862 if (!containing_document.frame() || |
| 2856 !containing_document.frame()->view() || | 2863 !containing_document.frame()->view() || |
| 2857 !containing_document.frame()->view()->mainFrame()) { | 2864 !containing_document.frame()->view()->mainFrame()) { |
| 2858 return false; | 2865 return false; |
| 2859 } | 2866 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2967 // Running out-of-process. Initiate an IPC call to notify the plugin | 2974 // Running out-of-process. Initiate an IPC call to notify the plugin |
| 2968 // process. | 2975 // process. |
| 2969 ppapi::proxy::HostDispatcher* dispatcher = | 2976 ppapi::proxy::HostDispatcher* dispatcher = |
| 2970 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 2977 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
| 2971 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 2978 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
| 2972 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 2979 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
| 2973 } | 2980 } |
| 2974 } | 2981 } |
| 2975 | 2982 |
| 2976 } // namespace content | 2983 } // namespace content |
| OLD | NEW |