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/content_renderer_pepper_host_factory.h" | 5 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "content/public/common/content_client.h" |
| 10 #include "content/public/renderer/content_renderer_client.h" |
9 #include "content/renderer/pepper/pepper_audio_input_host.h" | 11 #include "content/renderer/pepper/pepper_audio_input_host.h" |
10 #include "content/renderer/pepper/pepper_file_chooser_host.h" | 12 #include "content/renderer/pepper/pepper_file_chooser_host.h" |
11 #include "content/renderer/pepper/pepper_file_io_host.h" | 13 #include "content/renderer/pepper/pepper_file_io_host.h" |
12 #include "content/renderer/pepper/pepper_file_system_host.h" | 14 #include "content/renderer/pepper/pepper_file_system_host.h" |
13 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 15 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
14 #include "content/renderer/pepper/pepper_truetype_font_host.h" | 16 #include "content/renderer/pepper/pepper_truetype_font_host.h" |
15 #include "content/renderer/pepper/pepper_url_loader_host.h" | 17 #include "content/renderer/pepper/pepper_url_loader_host.h" |
16 #include "content/renderer/pepper/pepper_video_capture_host.h" | 18 #include "content/renderer/pepper/pepper_video_capture_host.h" |
17 #include "content/renderer/pepper/pepper_video_destination_host.h" | 19 #include "content/renderer/pepper/pepper_video_destination_host.h" |
18 #include "content/renderer/pepper/pepper_video_source_host.h" | 20 #include "content/renderer/pepper/pepper_video_source_host.h" |
19 #include "content/renderer/pepper/pepper_websocket_host.h" | 21 #include "content/renderer/pepper/pepper_websocket_host.h" |
20 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 22 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
21 #include "ppapi/host/resource_host.h" | 23 #include "ppapi/host/resource_host.h" |
22 #include "ppapi/proxy/ppapi_message_utils.h" | 24 #include "ppapi/proxy/ppapi_message_utils.h" |
23 #include "ppapi/proxy/ppapi_messages.h" | 25 #include "ppapi/proxy/ppapi_messages.h" |
24 #include "ppapi/proxy/serialized_structs.h" | 26 #include "ppapi/proxy/serialized_structs.h" |
| 27 #include "third_party/WebKit/public/platform/WebURL.h" |
| 28 #include "third_party/WebKit/public/web/WebDocument.h" |
| 29 #include "third_party/WebKit/public/web/WebElement.h" |
| 30 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
25 | 31 |
26 using ppapi::host::ResourceHost; | 32 using ppapi::host::ResourceHost; |
27 using ppapi::proxy::SerializedTrueTypeFontDesc; | 33 using ppapi::proxy::SerializedTrueTypeFontDesc; |
28 using ppapi::UnpackMessage; | 34 using ppapi::UnpackMessage; |
29 | 35 |
| 36 namespace { |
| 37 |
| 38 bool CanUseMediaStreamAPI(const content::RendererPpapiHost* host, |
| 39 PP_Instance instance) { |
| 40 WebKit::WebPluginContainer* container = |
| 41 host->GetContainerForInstance(instance); |
| 42 if (!container) |
| 43 return false; |
| 44 |
| 45 GURL document_url = container->element().document().url(); |
| 46 content::ContentRendererClient* content_renderer_client = |
| 47 content::GetContentClient()->renderer(); |
| 48 return content_renderer_client->AllowPepperMediaStreamAPI(document_url); |
| 49 } |
| 50 |
| 51 } |
| 52 |
30 namespace content { | 53 namespace content { |
31 | 54 |
32 ContentRendererPepperHostFactory::ContentRendererPepperHostFactory( | 55 ContentRendererPepperHostFactory::ContentRendererPepperHostFactory( |
33 RendererPpapiHostImpl* host) | 56 RendererPpapiHostImpl* host) |
34 : host_(host) { | 57 : host_(host) { |
35 } | 58 } |
36 | 59 |
37 ContentRendererPepperHostFactory::~ContentRendererPepperHostFactory() { | 60 ContentRendererPepperHostFactory::~ContentRendererPepperHostFactory() { |
38 } | 61 } |
39 | 62 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return scoped_ptr<ResourceHost>( | 97 return scoped_ptr<ResourceHost>( |
75 PepperGraphics2DHost::Create(host_, instance, params.pp_resource(), | 98 PepperGraphics2DHost::Create(host_, instance, params.pp_resource(), |
76 size, is_always_opaque)); | 99 size, is_always_opaque)); |
77 } | 100 } |
78 case PpapiHostMsg_URLLoader_Create::ID: | 101 case PpapiHostMsg_URLLoader_Create::ID: |
79 return scoped_ptr<ResourceHost>(new PepperURLLoaderHost( | 102 return scoped_ptr<ResourceHost>(new PepperURLLoaderHost( |
80 host_, false, instance, params.pp_resource())); | 103 host_, false, instance, params.pp_resource())); |
81 case PpapiHostMsg_WebSocket_Create::ID: | 104 case PpapiHostMsg_WebSocket_Create::ID: |
82 return scoped_ptr<ResourceHost>(new PepperWebSocketHost( | 105 return scoped_ptr<ResourceHost>(new PepperWebSocketHost( |
83 host_, instance, params.pp_resource())); | 106 host_, instance, params.pp_resource())); |
| 107 #if defined(ENABLE_WEBRTC) |
| 108 // These private MediaStream interfaces are exposed as if they were public |
| 109 // so they can be used by NaCl plugins. However, they are available only |
| 110 // for whitelisted apps. |
| 111 case PpapiHostMsg_VideoDestination_Create::ID: |
| 112 if (CanUseMediaStreamAPI(host_, instance)) |
| 113 return scoped_ptr<ResourceHost>(new PepperVideoDestinationHost( |
| 114 host_, instance, params.pp_resource())); |
| 115 case PpapiHostMsg_VideoSource_Create::ID: |
| 116 if (CanUseMediaStreamAPI(host_, instance)) |
| 117 return scoped_ptr<ResourceHost>(new PepperVideoSourceHost( |
| 118 host_, instance, params.pp_resource())); |
| 119 #endif // defined(ENABLE_WEBRTC) |
84 } | 120 } |
85 | 121 |
86 // Dev interfaces. | 122 // Dev interfaces. |
87 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) { | 123 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) { |
88 switch (message.type()) { | 124 switch (message.type()) { |
89 case PpapiHostMsg_AudioInput_Create::ID: | 125 case PpapiHostMsg_AudioInput_Create::ID: |
90 return scoped_ptr<ResourceHost>(new PepperAudioInputHost( | 126 return scoped_ptr<ResourceHost>(new PepperAudioInputHost( |
91 host_, instance, params.pp_resource())); | 127 host_, instance, params.pp_resource())); |
92 case PpapiHostMsg_FileChooser_Create::ID: | 128 case PpapiHostMsg_FileChooser_Create::ID: |
93 return scoped_ptr<ResourceHost>(new PepperFileChooserHost( | 129 return scoped_ptr<ResourceHost>(new PepperFileChooserHost( |
(...skipping 18 matching lines...) Expand all Loading... |
112 host_, instance, params.pp_resource()); | 148 host_, instance, params.pp_resource()); |
113 if (!host->Init()) { | 149 if (!host->Init()) { |
114 delete host; | 150 delete host; |
115 return scoped_ptr<ResourceHost>(); | 151 return scoped_ptr<ResourceHost>(); |
116 } | 152 } |
117 return scoped_ptr<ResourceHost>(host); | 153 return scoped_ptr<ResourceHost>(host); |
118 } | 154 } |
119 } | 155 } |
120 } | 156 } |
121 | 157 |
122 #if defined(ENABLE_WEBRTC) | |
123 // Private interfaces. | |
124 if (GetPermissions().HasPermission(ppapi::PERMISSION_PRIVATE)) { | |
125 switch (message.type()) { | |
126 case PpapiHostMsg_VideoDestination_Create::ID: | |
127 return scoped_ptr<ResourceHost>(new PepperVideoDestinationHost( | |
128 host_, instance, params.pp_resource())); | |
129 case PpapiHostMsg_VideoSource_Create::ID: | |
130 return scoped_ptr<ResourceHost>(new PepperVideoSourceHost( | |
131 host_, instance, params.pp_resource())); | |
132 } | |
133 } | |
134 #endif | |
135 | |
136 return scoped_ptr<ResourceHost>(); | 158 return scoped_ptr<ResourceHost>(); |
137 } | 159 } |
138 | 160 |
139 const ppapi::PpapiPermissions& | 161 const ppapi::PpapiPermissions& |
140 ContentRendererPepperHostFactory::GetPermissions() const { | 162 ContentRendererPepperHostFactory::GetPermissions() const { |
141 return host_->GetPpapiHost()->permissions(); | 163 return host_->GetPpapiHost()->permissions(); |
142 } | 164 } |
143 | 165 |
144 } // namespace content | 166 } // namespace content |
OLD | NEW |