OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. |
| 5 */ |
| 6 |
| 7 #include "native_client/src/shared/ppapi_proxy/plugin_instance_data.h" |
| 8 |
| 9 #include <tr1/unordered_map> |
| 10 |
| 11 namespace ppapi_proxy { |
| 12 |
| 13 namespace { |
| 14 |
| 15 typedef std::tr1::unordered_map<PP_Instance, PluginInstanceData*> InstanceMap; |
| 16 |
| 17 InstanceMap& GetInstanceMap() { |
| 18 static InstanceMap map; |
| 19 return map; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 // static |
| 25 PluginInstanceData* PluginInstanceData::FromPP(PP_Instance id) { |
| 26 InstanceMap& map = GetInstanceMap(); |
| 27 InstanceMap::iterator i = map.find(id); |
| 28 |
| 29 return map.end() == i ? NULL : i->second; |
| 30 } |
| 31 |
| 32 // static |
| 33 void PluginInstanceData::DidCreate(PP_Instance id) { |
| 34 InstanceMap& map = GetInstanceMap(); |
| 35 // TODO(neb): figure out how to use CHECK in NaCl land. |
| 36 // CHECK(map.end() == map.find(id)); |
| 37 map[id] = new PluginInstanceData(id); |
| 38 } |
| 39 |
| 40 // static |
| 41 void PluginInstanceData::DidDestroy(PP_Instance id) { |
| 42 GetInstanceMap().erase(id); |
| 43 } |
| 44 |
| 45 // static |
| 46 void PluginInstanceData::DidChangeView(PP_Instance id, |
| 47 PP_Rect position, |
| 48 PP_Rect clip) { |
| 49 PluginInstanceData* instance = FromPP(id); |
| 50 if (instance) { |
| 51 instance->set_position(position); |
| 52 } |
| 53 } |
| 54 |
| 55 } // namespace ppapi_proxy |
OLD | NEW |