OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/src/trusted/plugin/ppapi/plugin_ppapi.h" | 7 #include "native_client/src/trusted/plugin/ppapi/plugin_ppapi.h" |
8 | 8 |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "ppapi/cpp/module.h" | 31 #include "ppapi/cpp/module.h" |
32 #include "ppapi/cpp/rect.h" | 32 #include "ppapi/cpp/rect.h" |
33 | 33 |
34 namespace plugin { | 34 namespace plugin { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // The "src" attribute of the <embed> tag. The value is expected to be a URL | 38 // The "src" attribute of the <embed> tag. The value is expected to be a URL |
39 // pointing to the nexe (aka nacl module) file. | 39 // pointing to the nexe (aka nacl module) file. |
40 const char* const kSrcAttribute = "src"; | 40 const char* const kSrcAttribute = "src"; |
| 41 const char* const kTypeAttribute = "type"; |
41 // The "nacl" attribute of the <embed> tag. The value is expected to be either | 42 // The "nacl" attribute of the <embed> tag. The value is expected to be either |
42 // a URL or URI pointing to the manifest file (which is expected to contain | 43 // a URL or URI pointing to the manifest file (which is expected to contain |
43 // JSON matching ISAs with .nexe URLs). | 44 // JSON matching ISAs with .nexe URLs). |
44 const char* const kNaclManifestAttribute = "nacl"; | 45 const char* const kNaclManifestAttribute = "nacl"; |
45 // This is a pretty arbitrary limit on the byte size of the NaCl manfest file. | 46 // This is a pretty arbitrary limit on the byte size of the NaCl manfest file. |
46 // Note that the resulting string object has to have at least one byte extra | 47 // Note that the resulting string object has to have at least one byte extra |
47 // for the null termination character. | 48 // for the null termination character. |
48 const ssize_t kNaclManifestMaxFileBytesPlusNull = 1024; | 49 const ssize_t kNaclManifestMaxFileBytesPlusNull = 1024; |
49 const ssize_t kNaclManifestMaxFileBytesNoNull = | 50 const ssize_t kNaclManifestMaxFileBytesNoNull = |
50 kNaclManifestMaxFileBytesPlusNull - 1; | 51 kNaclManifestMaxFileBytesPlusNull - 1; |
(...skipping 10 matching lines...) Expand all Loading... |
61 PluginPpapi* plugin = | 62 PluginPpapi* plugin = |
62 static_cast<PluginPpapi*>(reinterpret_cast<Plugin*>(obj)); | 63 static_cast<PluginPpapi*>(reinterpret_cast<Plugin*>(obj)); |
63 const char* url = ins[0]->arrays.str; | 64 const char* url = ins[0]->arrays.str; |
64 // TODO(sehr,polina): Ensure that origin checks are performed here. | 65 // TODO(sehr,polina): Ensure that origin checks are performed here. |
65 return plugin->UrlAsNaClDesc( | 66 return plugin->UrlAsNaClDesc( |
66 url, *reinterpret_cast<pp::Var*>(ins[1]->arrays.oval)); | 67 url, *reinterpret_cast<pp::Var*>(ins[1]->arrays.oval)); |
67 } | 68 } |
68 | 69 |
69 } // namespace | 70 } // namespace |
70 | 71 |
| 72 const char* const PluginPpapi::kNaClMIMEType = "application/x-nacl"; |
| 73 |
71 bool PluginPpapi::SetAsyncCallback(void* obj, SrpcParams* params) { | 74 bool PluginPpapi::SetAsyncCallback(void* obj, SrpcParams* params) { |
72 PluginPpapi* plugin = | 75 PluginPpapi* plugin = |
73 static_cast<PluginPpapi*>(reinterpret_cast<Plugin*>(obj)); | 76 static_cast<PluginPpapi*>(reinterpret_cast<Plugin*>(obj)); |
74 if (plugin->service_runtime_ == NULL) { | 77 if (plugin->service_runtime_ == NULL) { |
75 params->set_exception_string("No subprocess running"); | 78 params->set_exception_string("No subprocess running"); |
76 return false; | 79 return false; |
77 } | 80 } |
78 if (plugin->receive_thread_running_) { | 81 if (plugin->receive_thread_running_) { |
79 params->set_exception_string("A callback has already been registered"); | 82 params->set_exception_string("A callback has already been registered"); |
80 return false; | 83 return false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 static_cast<void*>(scriptable_handle()))); | 140 static_cast<void*>(scriptable_handle()))); |
138 bool status = Plugin::Init( | 141 bool status = Plugin::Init( |
139 browser_interface, | 142 browser_interface, |
140 PPInstanceToInstanceIdentifier(static_cast<pp::Instance*>(this)), | 143 PPInstanceToInstanceIdentifier(static_cast<pp::Instance*>(this)), |
141 static_cast<int>(argc), | 144 static_cast<int>(argc), |
142 // TODO(polina): Can we change the args on our end to be const to | 145 // TODO(polina): Can we change the args on our end to be const to |
143 // avoid these ugly casts? This will also require changes to npapi code. | 146 // avoid these ugly casts? This will also require changes to npapi code. |
144 const_cast<char**>(argn), | 147 const_cast<char**>(argn), |
145 const_cast<char**>(argv)); | 148 const_cast<char**>(argv)); |
146 if (status) { | 149 if (status) { |
| 150 const char* type_attr = LookupArgument(kTypeAttribute); |
| 151 if (type_attr != NULL) { |
| 152 mime_type_ = nacl::string(type_attr); |
| 153 std::transform(mime_type_.begin(), mime_type_.end(), mime_type_.begin(), |
| 154 tolower); |
| 155 } |
147 // Note: The order of attribute lookup is important. This pattern looks | 156 // Note: The order of attribute lookup is important. This pattern looks |
148 // for a "nacl" attribute first, then a "src" attribute. | 157 // for a "nacl" attribute first, then a "src" attribute. |
149 const char* nacl_attr = LookupArgument(kNaclManifestAttribute); | 158 const char* nacl_attr = LookupArgument(kNaclManifestAttribute); |
150 PLUGIN_PRINTF(("PluginPpapi::Init (nacl_attr=%s)\n", nacl_attr)); | 159 PLUGIN_PRINTF(("PluginPpapi::Init (nacl_attr=%s)\n", nacl_attr)); |
151 if (nacl_attr != NULL) { | 160 if (nacl_attr != NULL) { |
152 // Issue a GET for the "nacl" attribute. The value of the attribute | 161 // Issue a GET for the "nacl" attribute. The value of the attribute |
153 // can be a URI or a URL pointing to the manifest file. The manifest | 162 // can be a URI or a URL pointing to the manifest file. The manifest |
154 // file will be parsed to determine the nexe URL. Then, just like for | 163 // file will be parsed to determine the nexe URL. Then, just like for |
155 // the "src" attribute below, SetSrcPropertyImpl() will be called. | 164 // the "src" attribute below, SetSrcPropertyImpl() will be called. |
156 // | 165 // |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 | 588 |
580 | 589 |
581 bool PluginPpapi::Failure(const nacl::string& error) { | 590 bool PluginPpapi::Failure(const nacl::string& error) { |
582 PLUGIN_PRINTF(("PluginPpapi::Failure (error='%s')\n", error.c_str())); | 591 PLUGIN_PRINTF(("PluginPpapi::Failure (error='%s')\n", error.c_str())); |
583 browser_interface()->AddToConsole(instance_id(), error); | 592 browser_interface()->AddToConsole(instance_id(), error); |
584 ShutdownProxy(); | 593 ShutdownProxy(); |
585 return false; | 594 return false; |
586 } | 595 } |
587 | 596 |
588 } // namespace plugin | 597 } // namespace plugin |
OLD | NEW |