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

Side by Side Diff: ppapi/proxy/ppb_instance_proxy.cc

Issue 11359063: Refactor the way singleton-style resources are exposed via PPB_Instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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 "ppapi/proxy/ppb_instance_proxy.h" 5 #include "ppapi/proxy/ppb_instance_proxy.h"
6 6
7 #include "base/memory/ref_counted.h"
7 #include "build/build_config.h" 8 #include "build/build_config.h"
8 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/pp_time.h" 10 #include "ppapi/c/pp_time.h"
10 #include "ppapi/c/pp_var.h" 11 #include "ppapi/c/pp_var.h"
11 #include "ppapi/c/ppb_audio_config.h" 12 #include "ppapi/c/ppb_audio_config.h"
12 #include "ppapi/c/ppb_instance.h" 13 #include "ppapi/c/ppb_instance.h"
13 #include "ppapi/c/ppb_messaging.h" 14 #include "ppapi/c/ppb_messaging.h"
14 #include "ppapi/c/ppb_mouse_lock.h" 15 #include "ppapi/c/ppb_mouse_lock.h"
15 #include "ppapi/c/private/pp_content_decryptor.h" 16 #include "ppapi/c/private/pp_content_decryptor.h"
16 #include "ppapi/proxy/content_decryptor_private_serializer.h" 17 #include "ppapi/proxy/content_decryptor_private_serializer.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize( 325 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
325 API_ID_PPB_INSTANCE, instance, &result, size)); 326 API_ID_PPB_INSTANCE, instance, &result, size));
326 return result; 327 return result;
327 } 328 }
328 329
329 thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { 330 thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() {
330 InterfaceProxy* ip = dispatcher()->GetInterfaceProxy(API_ID_PPB_FLASH); 331 InterfaceProxy* ip = dispatcher()->GetInterfaceProxy(API_ID_PPB_FLASH);
331 return static_cast<PPB_Flash_Proxy*>(ip); 332 return static_cast<PPB_Flash_Proxy*>(ip);
332 } 333 }
333 334
334 // TODO(raymes): We can most likely cut down this boilerplate for grabbing 335 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance,
335 // singleton resource APIs. 336 SingletonResourceID id) {
336 thunk::PPB_Flash_Functions_API* PPB_Instance_Proxy::GetFlashFunctionsAPI(
337 PP_Instance instance) {
338 #if !defined(OS_NACL) && !defined(NACL_WIN64)
339 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> 337 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
340 GetInstanceData(instance); 338 GetInstanceData(instance);
341 if (!data) 339
340 InstanceData::SingletonResourceMap::iterator it =
341 data->singleton_resources.find(id);
342 if (it != data->singleton_resources.end())
343 return it->second.get();
344
345 Resource* new_singleton(NULL);
346 Connection connection(
347 PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(),
348 dispatcher());
349
350 switch (id) {
351 // Flash resources aren't needed for NaCl.
352 #if !defined(OS_NACL) && !defined(NACL_WIN64)
353 case FLASH_SINGLETON_ID:
354 new_singleton = new FlashResource(connection, instance);
355 break;
356 case FLASH_CLIPBOARD_SINGLETON_ID:
357 new_singleton = new FlashClipboardResource(connection, instance);
358 break;
359 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
360 case GAMEPAD_SINGLETON_ID:
361 new_singleton = new GamepadResource(connection, instance);
362 break;
363 default:
364 // Unfortunately the default case is needed because we ifdef out some of
365 // the cases.
366 break;
367 }
368
369 if (!new_singleton) {
370 // Getting here implies that a constructor is missing in the above switch.
371 NOTREACHED();
342 return NULL; 372 return NULL;
373 }
343 374
344 if (!data->flash_resource.get()) { 375 data->singleton_resources[id] = scoped_refptr<Resource>(new_singleton);
345 Connection connection( 376 return new_singleton;
346 PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(),
347 dispatcher());
348 data->flash_resource = new FlashResource(connection, instance);
349 }
350 return data->flash_resource.get();
351 #else
352 // Flash functions aren't implemented for nacl.
353 NOTIMPLEMENTED();
354 return NULL;
355 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
356 }
357
358 thunk::PPB_Flash_Clipboard_API* PPB_Instance_Proxy::GetFlashClipboardAPI(
359 PP_Instance instance) {
360 #if !defined(OS_NACL) && !defined(NACL_WIN64)
361 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
362 GetInstanceData(instance);
363 if (!data)
364 return NULL;
365
366 if (!data->flash_clipboard_resource.get()) {
367 Connection connection(
368 PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(),
369 dispatcher());
370 data->flash_clipboard_resource =
371 new FlashClipboardResource(connection, instance);
372 }
373 return data->flash_clipboard_resource.get();
374 #else
375 // Flash functions aren't implemented for nacl.
376 NOTIMPLEMENTED();
377 return NULL;
378 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
379 }
380
381 thunk::PPB_Gamepad_API* PPB_Instance_Proxy::GetGamepadAPI(
382 PP_Instance instance) {
383 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
384 GetInstanceData(instance);
385 if (!data)
386 return NULL;
387
388 if (!data->gamepad_resource.get()) {
389 Connection connection(
390 PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(),
391 dispatcher());
392 data->gamepad_resource = new GamepadResource(connection, instance);
393 }
394 return data->gamepad_resource.get();
395 } 377 }
396 378
397 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, 379 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
398 uint32_t event_classes) { 380 uint32_t event_classes) {
399 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents( 381 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
400 API_ID_PPB_INSTANCE, instance, false, event_classes)); 382 API_ID_PPB_INSTANCE, instance, false, event_classes));
401 383
402 // We always register for the classes we can handle, this function validates 384 // We always register for the classes we can handle, this function validates
403 // the flags so we can notify it if anything was invalid, without requiring 385 // the flags so we can notify it if anything was invalid, without requiring
404 // a sync reply. 386 // a sync reply.
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 PP_Instance instance) { 1174 PP_Instance instance) {
1193 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> 1175 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1194 GetInstanceData(instance); 1176 GetInstanceData(instance);
1195 if (!data) 1177 if (!data)
1196 return; // Instance was probably deleted. 1178 return; // Instance was probably deleted.
1197 data->should_do_request_surrounding_text = false; 1179 data->should_do_request_surrounding_text = false;
1198 } 1180 }
1199 1181
1200 } // namespace proxy 1182 } // namespace proxy
1201 } // namespace ppapi 1183 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698