| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 #include "native_client/src/trusted/plugin/ppapi/browser_interface_ppapi.h" | 9 #include "native_client/src/trusted/plugin/ppapi/browser_interface_ppapi.h" |
| 10 | 10 |
| 11 #include "native_client/src/include/checked_cast.h" | 11 #include "native_client/src/include/checked_cast.h" |
| 12 #include "native_client/src/include/nacl_elf.h" | 12 #include "native_client/src/include/nacl_elf.h" |
| 13 #include "native_client/src/include/nacl_macros.h" | 13 #include "native_client/src/include/nacl_macros.h" |
| 14 #include "native_client/src/include/portability.h" | 14 #include "native_client/src/include/portability.h" |
| 15 #include "native_client/src/trusted/plugin/api_defines.h" | 15 #include "native_client/src/trusted/plugin/api_defines.h" |
| 16 #include "native_client/src/trusted/plugin/ppapi/scriptable_handle_ppapi.h" | 16 #include "native_client/src/trusted/plugin/ppapi/scriptable_handle_ppapi.h" |
| 17 #include "native_client/src/trusted/plugin/ppapi/var_utils.h" | 17 #include "native_client/src/trusted/plugin/ppapi/var_utils.h" |
| 18 | 18 |
| 19 #include "ppapi/cpp/instance.h" | 19 #include "ppapi/cpp/instance.h" |
| 20 #include "ppapi/cpp/var.h" | 20 #include "ppapi/cpp/var.h" |
| 21 | 21 |
| 22 using nacl::assert_cast; | 22 using nacl::assert_cast; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // TODO(polina): this function should return pp::Var |
| 26 bool GetWindow(plugin::InstanceIdentifier instance_id, pp::Var* window) { | 27 bool GetWindow(plugin::InstanceIdentifier instance_id, pp::Var* window) { |
| 27 pp::Instance* instance = plugin::InstanceIdentifierToPPInstance(instance_id); | 28 pp::Instance* instance = plugin::InstanceIdentifierToPPInstance(instance_id); |
| 28 *window = instance->GetWindowObject(); | 29 *window = instance->GetWindowObject(); |
| 29 return !window->is_void(); | 30 return !window->is_void(); |
| 30 } | 31 } |
| 31 | 32 |
| 32 } // namespace | 33 } // namespace |
| 33 | 34 |
| 34 namespace plugin { | 35 namespace plugin { |
| 35 | 36 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 56 const nacl::string& text) { | 57 const nacl::string& text) { |
| 57 pp::Var window; | 58 pp::Var window; |
| 58 if (!GetWindow(instance_id, &window)) { | 59 if (!GetWindow(instance_id, &window)) { |
| 59 return false; | 60 return false; |
| 60 } | 61 } |
| 61 pp::Var exception; | 62 pp::Var exception; |
| 62 window.Call("alert", text, &exception); | 63 window.Call("alert", text, &exception); |
| 63 return exception.is_void(); | 64 return exception.is_void(); |
| 64 } | 65 } |
| 65 | 66 |
| 67 bool BrowserInterfacePpapi::AddToConsole(InstanceIdentifier instance_id, |
| 68 const nacl::string& text) { |
| 69 pp::Var window; |
| 70 if (!GetWindow(instance_id, &window)) { |
| 71 return false; |
| 72 } |
| 73 pp::Var exception; |
| 74 window.GetProperty("console", &exception).Call("log", text, &exception); |
| 75 return exception.is_void(); |
| 76 } |
| 66 | 77 |
| 67 bool BrowserInterfacePpapi::EvalString(InstanceIdentifier instance_id, | 78 bool BrowserInterfacePpapi::EvalString(InstanceIdentifier instance_id, |
| 68 const nacl::string& expression) { | 79 const nacl::string& expression) { |
| 69 pp::Var window; | 80 pp::Var window; |
| 70 if (!GetWindow(instance_id, &window)) { | 81 if (!GetWindow(instance_id, &window)) { |
| 71 return false; | 82 return false; |
| 72 } | 83 } |
| 73 pp::Var exception; | 84 pp::Var exception; |
| 74 window.Call("eval", expression, &exception); | 85 window.Call("eval", expression, &exception); |
| 75 return exception.is_void(); | 86 return exception.is_void(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 pp::Instance* InstanceIdentifierToPPInstance(InstanceIdentifier instance_id) { | 121 pp::Instance* InstanceIdentifierToPPInstance(InstanceIdentifier instance_id) { |
| 111 return reinterpret_cast<pp::Instance*>(assert_cast<intptr_t>(instance_id)); | 122 return reinterpret_cast<pp::Instance*>(assert_cast<intptr_t>(instance_id)); |
| 112 } | 123 } |
| 113 | 124 |
| 114 | 125 |
| 115 InstanceIdentifier PPInstanceToInstanceIdentifier(pp::Instance* instance) { | 126 InstanceIdentifier PPInstanceToInstanceIdentifier(pp::Instance* instance) { |
| 116 return assert_cast<InstanceIdentifier>(reinterpret_cast<intptr_t>(instance)); | 127 return assert_cast<InstanceIdentifier>(reinterpret_cast<intptr_t>(instance)); |
| 117 } | 128 } |
| 118 | 129 |
| 119 } // namespace plugin | 130 } // namespace plugin |
| OLD | NEW |