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

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 "build/build_config.h" 7 #include "build/build_config.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/pp_time.h" 9 #include "ppapi/c/pp_time.h"
10 #include "ppapi/c/pp_var.h" 10 #include "ppapi/c/pp_var.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize( 324 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize(
325 API_ID_PPB_INSTANCE, instance, &result, size)); 325 API_ID_PPB_INSTANCE, instance, &result, size));
326 return result; 326 return result;
327 } 327 }
328 328
329 thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { 329 thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() {
330 InterfaceProxy* ip = dispatcher()->GetInterfaceProxy(API_ID_PPB_FLASH); 330 InterfaceProxy* ip = dispatcher()->GetInterfaceProxy(API_ID_PPB_FLASH);
331 return static_cast<PPB_Flash_Proxy*>(ip); 331 return static_cast<PPB_Flash_Proxy*>(ip);
332 } 332 }
333 333
334 // TODO(raymes): We can most likely cut down this boilerplate for grabbing 334 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance,
335 // singleton resource APIs. 335 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())-> 336 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
340 GetInstanceData(instance); 337 GetInstanceData(instance);
341 if (!data) 338
339 InstanceData::SingletonResourceMap::iterator it =
340 data->singleton_resources.find(id);
341 if (it != data->singleton_resources.end())
342 return it->second.get();
343
344 Resource* new_singleton(NULL);
345 Connection connection(
346 PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(),
347 dispatcher());
348
349 switch (id) {
350 // Flash resources aren't needed for NaCl.
351 #if !defined(OS_NACL) && !defined(NACL_WIN64)
352 case FLASH_SINGLETON_ID:
353 new_singleton = new FlashResource(connection, instance);
354 break;
355 case FLASH_CLIPBOARD_SINGLETON_ID:
356 new_singleton = new FlashClipboardResource(connection, instance);
357 break;
358 #endif // !defined(OS_NACL) && !defined(NACL_WIN64)
359 case GAMEPAD_SINGLETON_ID:
360 new_singleton = new GamepadResource(connection, instance);
361 break;
362 default:
363 // Unfortunately the default case is needed because we ifdef out some of
364 // the cases.
365 break;
366 }
367
368 if (!new_singleton) {
369 // Getting here implies that a constructor is missing in the above switch.
370 NOTREACHED();
342 return NULL; 371 return NULL;
372 }
343 373
344 if (!data->flash_resource.get()) { 374 data->singleton_resources[id] = linked_ptr<Resource>(new_singleton);
345 Connection connection( 375 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 } 376 }
396 377
397 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, 378 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
398 uint32_t event_classes) { 379 uint32_t event_classes) {
399 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents( 380 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents(
400 API_ID_PPB_INSTANCE, instance, false, event_classes)); 381 API_ID_PPB_INSTANCE, instance, false, event_classes));
401 382
402 // We always register for the classes we can handle, this function validates 383 // 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 384 // the flags so we can notify it if anything was invalid, without requiring
404 // a sync reply. 385 // a sync reply.
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 PP_Instance instance) { 1173 PP_Instance instance) {
1193 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> 1174 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
1194 GetInstanceData(instance); 1175 GetInstanceData(instance);
1195 if (!data) 1176 if (!data)
1196 return; // Instance was probably deleted. 1177 return; // Instance was probably deleted.
1197 data->should_do_request_surrounding_text = false; 1178 data->should_do_request_surrounding_text = false;
1198 } 1179 }
1199 1180
1200 } // namespace proxy 1181 } // namespace proxy
1201 } // namespace ppapi 1182 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698