| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dev/ppb_messaging_dev.h" |
| 7 #include "ppapi/c/dev/ppp_printing_dev.h" | 8 #include "ppapi/c/dev/ppp_printing_dev.h" |
| 8 #include "ppapi/c/ppb_instance.h" | 9 #include "ppapi/c/ppb_instance.h" |
| 9 #include "ppapi/cpp/common.h" | 10 #include "ppapi/cpp/common.h" |
| 10 #include "ppapi/cpp/dev/surface_3d_dev.h" | 11 #include "ppapi/cpp/dev/surface_3d_dev.h" |
| 11 #include "ppapi/cpp/graphics_2d.h" | 12 #include "ppapi/cpp/graphics_2d.h" |
| 12 #include "ppapi/cpp/image_data.h" | 13 #include "ppapi/cpp/image_data.h" |
| 13 #include "ppapi/cpp/logging.h" | 14 #include "ppapi/cpp/logging.h" |
| 14 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 15 #include "ppapi/cpp/module_impl.h" | 16 #include "ppapi/cpp/module_impl.h" |
| 16 #include "ppapi/cpp/point.h" | 17 #include "ppapi/cpp/point.h" |
| 17 #include "ppapi/cpp/resource.h" | 18 #include "ppapi/cpp/resource.h" |
| 18 #include "ppapi/cpp/var.h" | 19 #include "ppapi/cpp/var.h" |
| 19 | 20 |
| 20 namespace pp { | 21 namespace pp { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 template <> const char* interface_name<PPB_Instance>() { | 25 template <> const char* interface_name<PPB_Instance>() { |
| 25 return PPB_INSTANCE_INTERFACE; | 26 return PPB_INSTANCE_INTERFACE; |
| 26 } | 27 } |
| 27 | 28 |
| 29 template <> const char* interface_name<PPB_Messaging_Dev>() { |
| 30 return PPB_MESSAGING_DEV_INTERFACE; |
| 31 } |
| 32 |
| 28 } // namespace | 33 } // namespace |
| 29 | 34 |
| 30 Instance::Instance(PP_Instance instance) : pp_instance_(instance) { | 35 Instance::Instance(PP_Instance instance) : pp_instance_(instance) { |
| 31 } | 36 } |
| 32 | 37 |
| 33 Instance::~Instance() { | 38 Instance::~Instance() { |
| 34 // Ensure that all per-instance objects have been removed. Generally, these | 39 // Ensure that all per-instance objects have been removed. Generally, these |
| 35 // objects should have their lifetime scoped to the instance, such as being | 40 // objects should have their lifetime scoped to the instance, such as being |
| 36 // instance members or even implemented by your instance sub-class directly. | 41 // instance members or even implemented by your instance sub-class directly. |
| 37 // | 42 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 54 | 59 |
| 55 | 60 |
| 56 bool Instance::HandleDocumentLoad(const URLLoader& /*url_loader*/) { | 61 bool Instance::HandleDocumentLoad(const URLLoader& /*url_loader*/) { |
| 57 return false; | 62 return false; |
| 58 } | 63 } |
| 59 | 64 |
| 60 bool Instance::HandleInputEvent(const PP_InputEvent& /*event*/) { | 65 bool Instance::HandleInputEvent(const PP_InputEvent& /*event*/) { |
| 61 return false; | 66 return false; |
| 62 } | 67 } |
| 63 | 68 |
| 69 void Instance::HandleMessage(const Var& /*message_data*/) { |
| 70 return; |
| 71 } |
| 72 |
| 64 Var Instance::GetInstanceObject() { | 73 Var Instance::GetInstanceObject() { |
| 65 return Var(); | 74 return Var(); |
| 66 } | 75 } |
| 67 | 76 |
| 68 Var Instance::GetSelectedText(bool /* html */) { | 77 Var Instance::GetSelectedText(bool /* html */) { |
| 69 return Var(); | 78 return Var(); |
| 70 } | 79 } |
| 71 | 80 |
| 72 Var Instance::GetWindowObject() { | 81 Var Instance::GetWindowObject() { |
| 73 if (!has_interface<PPB_Instance>()) | 82 if (!has_interface<PPB_Instance>()) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Var Instance::ExecuteScript(const Var& script, Var* exception) { | 117 Var Instance::ExecuteScript(const Var& script, Var* exception) { |
| 109 if (!has_interface<PPB_Instance>()) | 118 if (!has_interface<PPB_Instance>()) |
| 110 return Var(); | 119 return Var(); |
| 111 return Var(Var::PassRef(), | 120 return Var(Var::PassRef(), |
| 112 get_interface<PPB_Instance>()->ExecuteScript( | 121 get_interface<PPB_Instance>()->ExecuteScript( |
| 113 pp_instance(), | 122 pp_instance(), |
| 114 script.pp_var(), | 123 script.pp_var(), |
| 115 Var::OutException(exception).get())); | 124 Var::OutException(exception).get())); |
| 116 } | 125 } |
| 117 | 126 |
| 127 void Instance::PostMessage(const Var& message) { |
| 128 if (!has_interface<PPB_Messaging_Dev>()) |
| 129 return; |
| 130 get_interface<PPB_Messaging_Dev>()->PostMessage(pp_instance(), |
| 131 message.pp_var()); |
| 132 } |
| 133 |
| 118 void Instance::AddPerInstanceObject(const std::string& interface_name, | 134 void Instance::AddPerInstanceObject(const std::string& interface_name, |
| 119 void* object) { | 135 void* object) { |
| 120 // Ensure we're not trying to register more than one object per interface | 136 // Ensure we're not trying to register more than one object per interface |
| 121 // type. Otherwise, we'll get confused in GetPerInstanceObject. | 137 // type. Otherwise, we'll get confused in GetPerInstanceObject. |
| 122 PP_DCHECK(interface_name_to_objects_.find(interface_name) == | 138 PP_DCHECK(interface_name_to_objects_.find(interface_name) == |
| 123 interface_name_to_objects_.end()); | 139 interface_name_to_objects_.end()); |
| 124 interface_name_to_objects_[interface_name] = object; | 140 interface_name_to_objects_[interface_name] = object; |
| 125 } | 141 } |
| 126 | 142 |
| 127 void Instance::RemovePerInstanceObject(const std::string& interface_name, | 143 void Instance::RemovePerInstanceObject(const std::string& interface_name, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 if (!that) | 165 if (!that) |
| 150 return NULL; | 166 return NULL; |
| 151 InterfaceNameToObjectMap::iterator found = | 167 InterfaceNameToObjectMap::iterator found = |
| 152 that->interface_name_to_objects_.find(interface_name); | 168 that->interface_name_to_objects_.find(interface_name); |
| 153 if (found == that->interface_name_to_objects_.end()) | 169 if (found == that->interface_name_to_objects_.end()) |
| 154 return NULL; | 170 return NULL; |
| 155 return found->second; | 171 return found->second; |
| 156 } | 172 } |
| 157 | 173 |
| 158 } // namespace pp | 174 } // namespace pp |
| OLD | NEW |