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

Side by Side Diff: content/renderer/pepper/content_renderer_pepper_host_factory.cc

Issue 225903006: PPAPI: Run clang_format.py on content/renderer/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 8 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 | Annotate | Revision Log
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 "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" 9 #include "content/public/common/content_client.h"
10 #include "content/public/renderer/content_renderer_client.h" 10 #include "content/public/renderer/content_renderer_client.h"
(...skipping 23 matching lines...) Expand all
34 34
35 using ppapi::host::ResourceHost; 35 using ppapi::host::ResourceHost;
36 using ppapi::proxy::SerializedTrueTypeFontDesc; 36 using ppapi::proxy::SerializedTrueTypeFontDesc;
37 using ppapi::UnpackMessage; 37 using ppapi::UnpackMessage;
38 38
39 namespace content { 39 namespace content {
40 40
41 #if defined(ENABLE_WEBRTC) 41 #if defined(ENABLE_WEBRTC)
42 namespace { 42 namespace {
43 43
44 bool CanUseMediaStreamAPI(const RendererPpapiHost* host, 44 bool CanUseMediaStreamAPI(const RendererPpapiHost* host, PP_Instance instance) {
45 PP_Instance instance) {
46 blink::WebPluginContainer* container = 45 blink::WebPluginContainer* container =
47 host->GetContainerForInstance(instance); 46 host->GetContainerForInstance(instance);
48 if (!container) 47 if (!container)
49 return false; 48 return false;
50 49
51 GURL document_url = container->element().document().url(); 50 GURL document_url = container->element().document().url();
52 ContentRendererClient* content_renderer_client = 51 ContentRendererClient* content_renderer_client =
53 GetContentClient()->renderer(); 52 GetContentClient()->renderer();
54 return content_renderer_client->AllowPepperMediaStreamAPI(document_url); 53 return content_renderer_client->AllowPepperMediaStreamAPI(document_url);
55 } 54 }
56 55
57 } // namespace 56 } // namespace
58 #endif // defined(ENABLE_WEBRTC) 57 #endif // defined(ENABLE_WEBRTC)
59 58
60 ContentRendererPepperHostFactory::ContentRendererPepperHostFactory( 59 ContentRendererPepperHostFactory::ContentRendererPepperHostFactory(
61 RendererPpapiHostImpl* host) 60 RendererPpapiHostImpl* host)
62 : host_(host) { 61 : host_(host) {}
63 }
64 62
65 ContentRendererPepperHostFactory::~ContentRendererPepperHostFactory() { 63 ContentRendererPepperHostFactory::~ContentRendererPepperHostFactory() {}
66 }
67 64
68 scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost( 65 scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost(
69 ppapi::host::PpapiHost* host, 66 ppapi::host::PpapiHost* host,
70 const ppapi::proxy::ResourceMessageCallParams& params, 67 const ppapi::proxy::ResourceMessageCallParams& params,
71 PP_Instance instance, 68 PP_Instance instance,
72 const IPC::Message& message) { 69 const IPC::Message& message) {
73 DCHECK(host == host_->GetPpapiHost()); 70 DCHECK(host == host_->GetPpapiHost());
74 71
75 // Make sure the plugin is giving us a valid instance for this resource. 72 // Make sure the plugin is giving us a valid instance for this resource.
76 if (!host_->IsValidInstance(instance)) 73 if (!host_->IsValidInstance(instance))
77 return scoped_ptr<ResourceHost>(); 74 return scoped_ptr<ResourceHost>();
78 75
79 PepperPluginInstanceImpl* instance_impl = 76 PepperPluginInstanceImpl* instance_impl =
80 host_->GetPluginInstanceImpl(instance); 77 host_->GetPluginInstanceImpl(instance);
81 if (!instance_impl->render_frame()) 78 if (!instance_impl->render_frame())
82 return scoped_ptr<ResourceHost>(); 79 return scoped_ptr<ResourceHost>();
83 80
84 // Public interfaces. 81 // Public interfaces.
85 switch (message.type()) { 82 switch (message.type()) {
86 case PpapiHostMsg_FileRef_CreateForFileAPI::ID: { 83 case PpapiHostMsg_FileRef_CreateForFileAPI::ID: {
87 PP_Resource file_system; 84 PP_Resource file_system;
88 std::string internal_path; 85 std::string internal_path;
89 if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>( 86 if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>(
90 message, &file_system, &internal_path)) { 87 message, &file_system, &internal_path)) {
91 NOTREACHED(); 88 NOTREACHED();
92 return scoped_ptr<ResourceHost>(); 89 return scoped_ptr<ResourceHost>();
93 } 90 }
94 return scoped_ptr<ResourceHost>(new PepperFileRefRendererHost( 91 return scoped_ptr<ResourceHost>(new PepperFileRefRendererHost(
95 host_, instance, params.pp_resource(), file_system, internal_path)); 92 host_, instance, params.pp_resource(), file_system, internal_path));
96 } 93 }
97 case PpapiHostMsg_FileSystem_Create::ID: { 94 case PpapiHostMsg_FileSystem_Create::ID: {
98 PP_FileSystemType file_system_type; 95 PP_FileSystemType file_system_type;
99 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message, 96 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message,
100 &file_system_type)) { 97 &file_system_type)) {
101 NOTREACHED(); 98 NOTREACHED();
102 return scoped_ptr<ResourceHost>(); 99 return scoped_ptr<ResourceHost>();
103 } 100 }
104 return scoped_ptr<ResourceHost>(new PepperFileSystemHost( 101 return scoped_ptr<ResourceHost>(new PepperFileSystemHost(
105 host_, instance, params.pp_resource(), file_system_type)); 102 host_, instance, params.pp_resource(), file_system_type));
106 } 103 }
107 case PpapiHostMsg_Graphics2D_Create::ID: { 104 case PpapiHostMsg_Graphics2D_Create::ID: {
108 PP_Size size; 105 PP_Size size;
109 PP_Bool is_always_opaque; 106 PP_Bool is_always_opaque;
110 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>(message, &size, 107 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>(
111 &is_always_opaque)) { 108 message, &size, &is_always_opaque)) {
112 NOTREACHED(); 109 NOTREACHED();
113 return scoped_ptr<ResourceHost>(); 110 return scoped_ptr<ResourceHost>();
114 } 111 }
115 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl( 112 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl(
116 instance, ppapi::PPB_ImageData_Shared::PLATFORM)); 113 instance, ppapi::PPB_ImageData_Shared::PLATFORM));
117 return scoped_ptr<ResourceHost>( 114 return scoped_ptr<ResourceHost>(
118 PepperGraphics2DHost::Create(host_, instance, params.pp_resource(), 115 PepperGraphics2DHost::Create(host_,
119 size, is_always_opaque, image_data)); 116 instance,
117 params.pp_resource(),
118 size,
119 is_always_opaque,
120 image_data));
120 } 121 }
121 case PpapiHostMsg_URLLoader_Create::ID: 122 case PpapiHostMsg_URLLoader_Create::ID:
122 return scoped_ptr<ResourceHost>(new PepperURLLoaderHost( 123 return scoped_ptr<ResourceHost>(new PepperURLLoaderHost(
123 host_, false, instance, params.pp_resource())); 124 host_, false, instance, params.pp_resource()));
124 case PpapiHostMsg_WebSocket_Create::ID: 125 case PpapiHostMsg_WebSocket_Create::ID:
125 return scoped_ptr<ResourceHost>(new PepperWebSocketHost( 126 return scoped_ptr<ResourceHost>(
126 host_, instance, params.pp_resource())); 127 new PepperWebSocketHost(host_, instance, params.pp_resource()));
127 #if defined(ENABLE_WEBRTC) 128 #if defined(ENABLE_WEBRTC)
128 // These private MediaStream interfaces are exposed as if they were public 129 // These private MediaStream interfaces are exposed as if they were public
129 // so they can be used by NaCl plugins. However, they are available only 130 // so they can be used by NaCl plugins. However, they are available only
130 // for whitelisted apps. 131 // for whitelisted apps.
131 case PpapiHostMsg_VideoDestination_Create::ID: 132 case PpapiHostMsg_VideoDestination_Create::ID:
132 if (CanUseMediaStreamAPI(host_, instance)) 133 if (CanUseMediaStreamAPI(host_, instance))
133 return scoped_ptr<ResourceHost>(new PepperVideoDestinationHost( 134 return scoped_ptr<ResourceHost>(new PepperVideoDestinationHost(
134 host_, instance, params.pp_resource())); 135 host_, instance, params.pp_resource()));
135 case PpapiHostMsg_VideoSource_Create::ID: 136 case PpapiHostMsg_VideoSource_Create::ID:
136 if (CanUseMediaStreamAPI(host_, instance)) 137 if (CanUseMediaStreamAPI(host_, instance))
137 return scoped_ptr<ResourceHost>(new PepperVideoSourceHost( 138 return scoped_ptr<ResourceHost>(
138 host_, instance, params.pp_resource())); 139 new PepperVideoSourceHost(host_, instance, params.pp_resource()));
139 #endif // defined(ENABLE_WEBRTC) 140 #endif // defined(ENABLE_WEBRTC)
140 } 141 }
141 142
142 // Dev interfaces. 143 // Dev interfaces.
143 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) { 144 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) {
144 switch (message.type()) { 145 switch (message.type()) {
145 case PpapiHostMsg_AudioInput_Create::ID: 146 case PpapiHostMsg_AudioInput_Create::ID:
146 return scoped_ptr<ResourceHost>(new PepperAudioInputHost( 147 return scoped_ptr<ResourceHost>(
147 host_, instance, params.pp_resource())); 148 new PepperAudioInputHost(host_, instance, params.pp_resource()));
148 case PpapiHostMsg_FileChooser_Create::ID: 149 case PpapiHostMsg_FileChooser_Create::ID:
149 return scoped_ptr<ResourceHost>(new PepperFileChooserHost( 150 return scoped_ptr<ResourceHost>(
150 host_, instance, params.pp_resource())); 151 new PepperFileChooserHost(host_, instance, params.pp_resource()));
151 case PpapiHostMsg_TrueTypeFont_Create::ID: { 152 case PpapiHostMsg_TrueTypeFont_Create::ID: {
152 SerializedTrueTypeFontDesc desc; 153 SerializedTrueTypeFontDesc desc;
153 if (!UnpackMessage<PpapiHostMsg_TrueTypeFont_Create>(message, 154 if (!UnpackMessage<PpapiHostMsg_TrueTypeFont_Create>(message, &desc)) {
154 &desc)) {
155 NOTREACHED(); 155 NOTREACHED();
156 return scoped_ptr<ResourceHost>(); 156 return scoped_ptr<ResourceHost>();
157 } 157 }
158 // Check that the family name is valid UTF-8 before passing it to the 158 // Check that the family name is valid UTF-8 before passing it to the
159 // host OS. 159 // host OS.
160 if (IsStringUTF8(desc.family)) { 160 if (IsStringUTF8(desc.family)) {
161 return scoped_ptr<ResourceHost>(new PepperTrueTypeFontHost( 161 return scoped_ptr<ResourceHost>(new PepperTrueTypeFontHost(
162 host_, instance, params.pp_resource(), desc)); 162 host_, instance, params.pp_resource(), desc));
163 } 163 }
164 break; // Drop through and return null host. 164 break; // Drop through and return null host.
165 } 165 }
166 case PpapiHostMsg_VideoCapture_Create::ID: { 166 case PpapiHostMsg_VideoCapture_Create::ID: {
167 PepperVideoCaptureHost* host = new PepperVideoCaptureHost( 167 PepperVideoCaptureHost* host =
168 host_, instance, params.pp_resource()); 168 new PepperVideoCaptureHost(host_, instance, params.pp_resource());
169 if (!host->Init()) { 169 if (!host->Init()) {
170 delete host; 170 delete host;
171 return scoped_ptr<ResourceHost>(); 171 return scoped_ptr<ResourceHost>();
172 } 172 }
173 return scoped_ptr<ResourceHost>(host); 173 return scoped_ptr<ResourceHost>(host);
174 } 174 }
175 } 175 }
176 } 176 }
177 177
178 return scoped_ptr<ResourceHost>(); 178 return scoped_ptr<ResourceHost>();
179 } 179 }
180 180
181 const ppapi::PpapiPermissions& 181 const ppapi::PpapiPermissions&
182 ContentRendererPepperHostFactory::GetPermissions() const { 182 ContentRendererPepperHostFactory::GetPermissions() const {
183 return host_->GetPpapiHost()->permissions(); 183 return host_->GetPpapiHost()->permissions();
184 } 184 }
185 185
186 } // namespace content 186 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/content_renderer_pepper_host_factory.h ('k') | content/renderer/pepper/event_conversion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698