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

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: 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_CreateInternal::ID: { 83 case PpapiHostMsg_FileRef_CreateInternal::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_CreateInternal>(message, 86 if (!UnpackMessage<PpapiHostMsg_FileRef_CreateInternal>(
90 &file_system, 87 message, &file_system, &internal_path)) {
91 &internal_path)) {
92 NOTREACHED(); 88 NOTREACHED();
93 return scoped_ptr<ResourceHost>(); 89 return scoped_ptr<ResourceHost>();
94 } 90 }
95 return scoped_ptr<ResourceHost>(new PepperFileRefRendererHost( 91 return scoped_ptr<ResourceHost>(new PepperFileRefRendererHost(
96 host_, instance, params.pp_resource(), file_system, internal_path)); 92 host_, instance, params.pp_resource(), file_system, internal_path));
97 } 93 }
98 case PpapiHostMsg_FileSystem_Create::ID: { 94 case PpapiHostMsg_FileSystem_Create::ID: {
99 PP_FileSystemType file_system_type; 95 PP_FileSystemType file_system_type;
100 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message, 96 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message,
101 &file_system_type)) { 97 &file_system_type)) {
102 NOTREACHED(); 98 NOTREACHED();
103 return scoped_ptr<ResourceHost>(); 99 return scoped_ptr<ResourceHost>();
104 } 100 }
105 return scoped_ptr<ResourceHost>(new PepperFileSystemHost( 101 return scoped_ptr<ResourceHost>(new PepperFileSystemHost(
106 host_, instance, params.pp_resource(), file_system_type)); 102 host_, instance, params.pp_resource(), file_system_type));
107 } 103 }
108 case PpapiHostMsg_Graphics2D_Create::ID: { 104 case PpapiHostMsg_Graphics2D_Create::ID: {
109 PP_Size size; 105 PP_Size size;
110 PP_Bool is_always_opaque; 106 PP_Bool is_always_opaque;
111 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>(message, &size, 107 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>(
112 &is_always_opaque)) { 108 message, &size, &is_always_opaque)) {
113 NOTREACHED(); 109 NOTREACHED();
114 return scoped_ptr<ResourceHost>(); 110 return scoped_ptr<ResourceHost>();
115 } 111 }
116 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl( 112 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl(
117 instance, ppapi::PPB_ImageData_Shared::PLATFORM)); 113 instance, ppapi::PPB_ImageData_Shared::PLATFORM));
118 return scoped_ptr<ResourceHost>( 114 return scoped_ptr<ResourceHost>(
119 PepperGraphics2DHost::Create(host_, instance, params.pp_resource(), 115 PepperGraphics2DHost::Create(host_,
120 size, is_always_opaque, image_data)); 116 instance,
117 params.pp_resource(),
118 size,
119 is_always_opaque,
120 image_data));
121 } 121 }
122 case PpapiHostMsg_URLLoader_Create::ID: 122 case PpapiHostMsg_URLLoader_Create::ID:
123 return scoped_ptr<ResourceHost>(new PepperURLLoaderHost( 123 return scoped_ptr<ResourceHost>(new PepperURLLoaderHost(
124 host_, false, instance, params.pp_resource())); 124 host_, false, instance, params.pp_resource()));
125 case PpapiHostMsg_WebSocket_Create::ID: 125 case PpapiHostMsg_WebSocket_Create::ID:
126 return scoped_ptr<ResourceHost>(new PepperWebSocketHost( 126 return scoped_ptr<ResourceHost>(
127 host_, instance, params.pp_resource())); 127 new PepperWebSocketHost(host_, instance, params.pp_resource()));
128 #if defined(ENABLE_WEBRTC) 128 #if defined(ENABLE_WEBRTC)
129 // These private MediaStream interfaces are exposed as if they were public 129 // These private MediaStream interfaces are exposed as if they were public
130 // 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
131 // for whitelisted apps. 131 // for whitelisted apps.
132 case PpapiHostMsg_VideoDestination_Create::ID: 132 case PpapiHostMsg_VideoDestination_Create::ID:
133 if (CanUseMediaStreamAPI(host_, instance)) 133 if (CanUseMediaStreamAPI(host_, instance))
134 return scoped_ptr<ResourceHost>(new PepperVideoDestinationHost( 134 return scoped_ptr<ResourceHost>(new PepperVideoDestinationHost(
135 host_, instance, params.pp_resource())); 135 host_, instance, params.pp_resource()));
136 case PpapiHostMsg_VideoSource_Create::ID: 136 case PpapiHostMsg_VideoSource_Create::ID:
137 if (CanUseMediaStreamAPI(host_, instance)) 137 if (CanUseMediaStreamAPI(host_, instance))
138 return scoped_ptr<ResourceHost>(new PepperVideoSourceHost( 138 return scoped_ptr<ResourceHost>(
139 host_, instance, params.pp_resource())); 139 new PepperVideoSourceHost(host_, instance, params.pp_resource()));
140 #endif // defined(ENABLE_WEBRTC) 140 #endif // defined(ENABLE_WEBRTC)
141 } 141 }
142 142
143 // Dev interfaces. 143 // Dev interfaces.
144 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) { 144 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) {
145 switch (message.type()) { 145 switch (message.type()) {
146 case PpapiHostMsg_AudioInput_Create::ID: 146 case PpapiHostMsg_AudioInput_Create::ID:
147 return scoped_ptr<ResourceHost>(new PepperAudioInputHost( 147 return scoped_ptr<ResourceHost>(
148 host_, instance, params.pp_resource())); 148 new PepperAudioInputHost(host_, instance, params.pp_resource()));
149 case PpapiHostMsg_FileChooser_Create::ID: 149 case PpapiHostMsg_FileChooser_Create::ID:
150 return scoped_ptr<ResourceHost>(new PepperFileChooserHost( 150 return scoped_ptr<ResourceHost>(
151 host_, instance, params.pp_resource())); 151 new PepperFileChooserHost(host_, instance, params.pp_resource()));
152 case PpapiHostMsg_TrueTypeFont_Create::ID: { 152 case PpapiHostMsg_TrueTypeFont_Create::ID: {
153 SerializedTrueTypeFontDesc desc; 153 SerializedTrueTypeFontDesc desc;
154 if (!UnpackMessage<PpapiHostMsg_TrueTypeFont_Create>(message, 154 if (!UnpackMessage<PpapiHostMsg_TrueTypeFont_Create>(message, &desc)) {
155 &desc)) {
156 NOTREACHED(); 155 NOTREACHED();
157 return scoped_ptr<ResourceHost>(); 156 return scoped_ptr<ResourceHost>();
158 } 157 }
159 // 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
160 // host OS. 159 // host OS.
161 if (IsStringUTF8(desc.family)) { 160 if (IsStringUTF8(desc.family)) {
162 return scoped_ptr<ResourceHost>(new PepperTrueTypeFontHost( 161 return scoped_ptr<ResourceHost>(new PepperTrueTypeFontHost(
163 host_, instance, params.pp_resource(), desc)); 162 host_, instance, params.pp_resource(), desc));
164 } 163 }
165 break; // Drop through and return null host. 164 break; // Drop through and return null host.
166 } 165 }
167 case PpapiHostMsg_VideoCapture_Create::ID: { 166 case PpapiHostMsg_VideoCapture_Create::ID: {
168 PepperVideoCaptureHost* host = new PepperVideoCaptureHost( 167 PepperVideoCaptureHost* host =
169 host_, instance, params.pp_resource()); 168 new PepperVideoCaptureHost(host_, instance, params.pp_resource());
170 if (!host->Init()) { 169 if (!host->Init()) {
171 delete host; 170 delete host;
172 return scoped_ptr<ResourceHost>(); 171 return scoped_ptr<ResourceHost>();
173 } 172 }
174 return scoped_ptr<ResourceHost>(host); 173 return scoped_ptr<ResourceHost>(host);
175 } 174 }
176 } 175 }
177 } 176 }
178 177
179 return scoped_ptr<ResourceHost>(); 178 return scoped_ptr<ResourceHost>();
180 } 179 }
181 180
182 const ppapi::PpapiPermissions& 181 const ppapi::PpapiPermissions&
183 ContentRendererPepperHostFactory::GetPermissions() const { 182 ContentRendererPepperHostFactory::GetPermissions() const {
184 return host_->GetPpapiHost()->permissions(); 183 return host_->GetPpapiHost()->permissions();
185 } 184 }
186 185
187 } // namespace content 186 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698