| OLD | NEW |
| 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/cpp/instance.h" | 5 #include "ppapi/cpp/instance.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/ppb_console.h" |
| 8 #include "ppapi/c/ppb_input_event.h" | 9 #include "ppapi/c/ppb_input_event.h" |
| 9 #include "ppapi/c/ppb_instance.h" | 10 #include "ppapi/c/ppb_instance.h" |
| 10 #include "ppapi/c/ppb_messaging.h" | 11 #include "ppapi/c/ppb_messaging.h" |
| 11 #include "ppapi/cpp/graphics_2d.h" | 12 #include "ppapi/cpp/graphics_2d.h" |
| 12 #include "ppapi/cpp/graphics_3d.h" | 13 #include "ppapi/cpp/graphics_3d.h" |
| 13 #include "ppapi/cpp/image_data.h" | 14 #include "ppapi/cpp/image_data.h" |
| 14 #include "ppapi/cpp/instance_handle.h" | 15 #include "ppapi/cpp/instance_handle.h" |
| 15 #include "ppapi/cpp/logging.h" | 16 #include "ppapi/cpp/logging.h" |
| 16 #include "ppapi/cpp/module.h" | 17 #include "ppapi/cpp/module.h" |
| 17 #include "ppapi/cpp/module_impl.h" | 18 #include "ppapi/cpp/module_impl.h" |
| 18 #include "ppapi/cpp/point.h" | 19 #include "ppapi/cpp/point.h" |
| 19 #include "ppapi/cpp/resource.h" | 20 #include "ppapi/cpp/resource.h" |
| 20 #include "ppapi/cpp/var.h" | 21 #include "ppapi/cpp/var.h" |
| 21 #include "ppapi/cpp/view.h" | 22 #include "ppapi/cpp/view.h" |
| 22 | 23 |
| 23 namespace pp { | 24 namespace pp { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 28 template <> const char* interface_name<PPB_Console_1_0>() { |
| 29 return PPB_CONSOLE_INTERFACE_1_0; |
| 30 } |
| 31 |
| 27 template <> const char* interface_name<PPB_InputEvent_1_0>() { | 32 template <> const char* interface_name<PPB_InputEvent_1_0>() { |
| 28 return PPB_INPUT_EVENT_INTERFACE_1_0; | 33 return PPB_INPUT_EVENT_INTERFACE_1_0; |
| 29 } | 34 } |
| 30 | 35 |
| 31 template <> const char* interface_name<PPB_Instance_1_0>() { | 36 template <> const char* interface_name<PPB_Instance_1_0>() { |
| 32 return PPB_INSTANCE_INTERFACE_1_0; | 37 return PPB_INSTANCE_INTERFACE_1_0; |
| 33 } | 38 } |
| 34 | 39 |
| 35 template <> const char* interface_name<PPB_Messaging_1_0>() { | 40 template <> const char* interface_name<PPB_Messaging_1_0>() { |
| 36 return PPB_MESSAGING_INTERFACE_1_0; | 41 return PPB_MESSAGING_INTERFACE_1_0; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 event_classes); | 121 event_classes); |
| 117 } | 122 } |
| 118 | 123 |
| 119 void Instance::PostMessage(const Var& message) { | 124 void Instance::PostMessage(const Var& message) { |
| 120 if (!has_interface<PPB_Messaging_1_0>()) | 125 if (!has_interface<PPB_Messaging_1_0>()) |
| 121 return; | 126 return; |
| 122 get_interface<PPB_Messaging_1_0>()->PostMessage(pp_instance(), | 127 get_interface<PPB_Messaging_1_0>()->PostMessage(pp_instance(), |
| 123 message.pp_var()); | 128 message.pp_var()); |
| 124 } | 129 } |
| 125 | 130 |
| 131 void Instance::LogToConsole(PP_LogLevel level, const Var& value) { |
| 132 if (!has_interface<PPB_Console_1_0>()) |
| 133 return; |
| 134 get_interface<PPB_Console_1_0>()->Log( |
| 135 pp_instance(), level, value.pp_var()); |
| 136 } |
| 137 |
| 138 void Instance::LogToConsoleWithSource(PP_LogLevel level, |
| 139 const Var& source, |
| 140 const Var& value) { |
| 141 if (!has_interface<PPB_Console_1_0>()) |
| 142 return; |
| 143 get_interface<PPB_Console_1_0>()->LogWithSource( |
| 144 pp_instance(), level, source.pp_var(), value.pp_var()); |
| 145 } |
| 146 |
| 126 void Instance::AddPerInstanceObject(const std::string& interface_name, | 147 void Instance::AddPerInstanceObject(const std::string& interface_name, |
| 127 void* object) { | 148 void* object) { |
| 128 // Ensure we're not trying to register more than one object per interface | 149 // Ensure we're not trying to register more than one object per interface |
| 129 // type. Otherwise, we'll get confused in GetPerInstanceObject. | 150 // type. Otherwise, we'll get confused in GetPerInstanceObject. |
| 130 PP_DCHECK(interface_name_to_objects_.find(interface_name) == | 151 PP_DCHECK(interface_name_to_objects_.find(interface_name) == |
| 131 interface_name_to_objects_.end()); | 152 interface_name_to_objects_.end()); |
| 132 interface_name_to_objects_[interface_name] = object; | 153 interface_name_to_objects_[interface_name] = object; |
| 133 } | 154 } |
| 134 | 155 |
| 135 void Instance::RemovePerInstanceObject(const std::string& interface_name, | 156 void Instance::RemovePerInstanceObject(const std::string& interface_name, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (!that) | 189 if (!that) |
| 169 return NULL; | 190 return NULL; |
| 170 InterfaceNameToObjectMap::iterator found = | 191 InterfaceNameToObjectMap::iterator found = |
| 171 that->interface_name_to_objects_.find(interface_name); | 192 that->interface_name_to_objects_.find(interface_name); |
| 172 if (found == that->interface_name_to_objects_.end()) | 193 if (found == that->interface_name_to_objects_.end()) |
| 173 return NULL; | 194 return NULL; |
| 174 return found->second; | 195 return found->second; |
| 175 } | 196 } |
| 176 | 197 |
| 177 } // namespace pp | 198 } // namespace pp |
| OLD | NEW |