Implement HasPermission() method in PermissionService.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_in_process_resource_creation.cc
blob627c1f8c84b3347949cb9d0b2442f4310599ced6
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
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/pepper_in_process_resource_creation.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "content/child/browser_font_resource_trusted.h"
12 #include "content/renderer/pepper/pepper_in_process_router.h"
13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
14 #include "content/renderer/pepper/ppapi_preferences_builder.h"
15 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
16 #include "content/renderer/render_view_impl.h"
17 #include "ipc/ipc_message.h"
18 #include "ipc/ipc_message_macros.h"
19 #include "ppapi/host/ppapi_host.h"
20 #include "ppapi/proxy/file_chooser_resource.h"
21 #include "ppapi/proxy/file_io_resource.h"
22 #include "ppapi/proxy/file_ref_resource.h"
23 #include "ppapi/proxy/file_system_resource.h"
24 #include "ppapi/proxy/graphics_2d_resource.h"
25 #include "ppapi/proxy/ppapi_messages.h"
26 #include "ppapi/proxy/printing_resource.h"
27 #include "ppapi/proxy/url_loader_resource.h"
28 #include "ppapi/proxy/url_request_info_resource.h"
29 #include "ppapi/proxy/url_response_info_resource.h"
30 #include "ppapi/proxy/websocket_resource.h"
31 #include "ppapi/shared_impl/ppapi_globals.h"
32 #include "ppapi/shared_impl/ppapi_permissions.h"
33 #include "ppapi/shared_impl/resource_tracker.h"
34 #include "ppapi/shared_impl/var.h"
36 // Note that the code in the creation functions in this file should generally
37 // be the same as that in ppapi/proxy/resource_creation_proxy.cc. See
38 // pepper_in_process_resource_creation.h for what this file is for.
40 namespace content {
42 // PepperInProcessResourceCreation --------------------------------------------
44 PepperInProcessResourceCreation::PepperInProcessResourceCreation(
45 RendererPpapiHostImpl* host_impl,
46 PepperPluginInstanceImpl* instance)
47 : ResourceCreationImpl(instance), host_impl_(host_impl) {}
49 PepperInProcessResourceCreation::~PepperInProcessResourceCreation() {}
51 PP_Resource PepperInProcessResourceCreation::CreateBrowserFont(
52 PP_Instance instance,
53 const PP_BrowserFont_Trusted_Description* description) {
54 if (!BrowserFontResource_Trusted::IsPPFontDescriptionValid(*description))
55 return 0;
56 ppapi::Preferences prefs(PpapiPreferencesBuilder::Build(
57 host_impl_->GetRenderViewForInstance(instance)->GetWebkitPreferences()));
58 return (new BrowserFontResource_Trusted(
59 host_impl_->in_process_router()->GetPluginConnection(instance),
60 instance,
61 *description,
62 prefs))->GetReference();
65 PP_Resource PepperInProcessResourceCreation::CreateFileChooser(
66 PP_Instance instance,
67 PP_FileChooserMode_Dev mode,
68 const PP_Var& accept_types) {
69 scoped_refptr<ppapi::StringVar> string_var =
70 ppapi::StringVar::FromPPVar(accept_types);
71 std::string str = string_var.get() ? string_var->value() : std::string();
72 return (new ppapi::proxy::FileChooserResource(
73 host_impl_->in_process_router()->GetPluginConnection(instance),
74 instance,
75 mode,
76 str.c_str()))->GetReference();
79 PP_Resource PepperInProcessResourceCreation::CreateFileIO(
80 PP_Instance instance) {
81 return (new ppapi::proxy::FileIOResource(
82 host_impl_->in_process_router()->GetPluginConnection(instance),
83 instance))->GetReference();
86 PP_Resource PepperInProcessResourceCreation::CreateFileRef(
87 PP_Instance instance,
88 const ppapi::FileRefCreateInfo& create_info) {
89 return ppapi::proxy::FileRefResource::CreateFileRef(
90 host_impl_->in_process_router()->GetPluginConnection(instance),
91 instance,
92 create_info);
95 PP_Resource PepperInProcessResourceCreation::CreateFileSystem(
96 PP_Instance instance,
97 PP_FileSystemType type) {
98 return (new ppapi::proxy::FileSystemResource(
99 host_impl_->in_process_router()->GetPluginConnection(instance),
100 instance,
101 type))->GetReference();
104 PP_Resource PepperInProcessResourceCreation::CreateGraphics2D(
105 PP_Instance instance,
106 const PP_Size* size,
107 PP_Bool is_always_opaque) {
108 return (new ppapi::proxy::Graphics2DResource(
109 host_impl_->in_process_router()->GetPluginConnection(instance),
110 instance,
111 *size,
112 is_always_opaque))->GetReference();
115 PP_Resource PepperInProcessResourceCreation::CreatePrinting(
116 PP_Instance instance) {
117 return (new ppapi::proxy::PrintingResource(
118 host_impl_->in_process_router()->GetPluginConnection(instance),
119 instance))->GetReference();
122 PP_Resource PepperInProcessResourceCreation::CreateTrueTypeFont(
123 PP_Instance instance,
124 const PP_TrueTypeFontDesc_Dev* desc) {
125 NOTIMPLEMENTED();
126 return 0;
129 PP_Resource PepperInProcessResourceCreation::CreateURLLoader(
130 PP_Instance instance) {
131 return (new ppapi::proxy::URLLoaderResource(
132 host_impl_->in_process_router()->GetPluginConnection(instance),
133 instance))->GetReference();
136 PP_Resource PepperInProcessResourceCreation::CreateURLRequestInfo(
137 PP_Instance instance) {
138 return (new ppapi::proxy::URLRequestInfoResource(
139 host_impl_->in_process_router()->GetPluginConnection(instance),
140 instance,
141 ppapi::URLRequestInfoData()))->GetReference();
144 PP_Resource PepperInProcessResourceCreation::CreateWebSocket(
145 PP_Instance instance) {
146 return (new ppapi::proxy::WebSocketResource(
147 host_impl_->in_process_router()->GetPluginConnection(instance),
148 instance))->GetReference();
151 } // namespace content