Chromium Code Reviews| 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 <cstring> | 7 #include <cstring> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 DebugPrintf("PPB_GetInterface: value=%p\n", ppb); | 71 DebugPrintf("PPB_GetInterface: value=%p\n", ppb); |
| 72 return ppb; | 72 return ppb; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Module ids are needed for some call APIs, but the fake browser does | 75 // Module ids are needed for some call APIs, but the fake browser does |
| 76 // not implement the storage tracking APIs that would use a real value. | 76 // not implement the storage tracking APIs that would use a real value. |
| 77 // TODO(sehr): implement storage tracking. | 77 // TODO(sehr): implement storage tracking. |
| 78 // The storage allocated by the browser for the window object, etc., are | 78 // The storage allocated by the browser for the window object, etc., are |
| 79 // attributed to the browser's module id. | 79 // attributed to the browser's module id. |
| 80 PP_Module BrowserModuleId() { | 80 PP_Module BrowserModuleId() { |
| 81 static void* id; | 81 static PP_Module id = 100; |
|
sehr (please use chromium)
2011/01/12 00:55:10
I presume this number has some significance? Plea
neb
2011/01/13 00:00:43
Done.
| |
| 82 return reinterpret_cast<PP_Module>(&id); | 82 return id; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // The storage allocated by the plugin for its scriptable objects are | 85 // The storage allocated by the plugin for its scriptable objects are |
| 86 // attributed to the its module id. | 86 // attributed to the its module id. |
| 87 PP_Module PluginModuleId() { | 87 PP_Module PluginModuleId() { |
| 88 static void* id; | 88 static PP_Module id = 1; |
| 89 return reinterpret_cast<PP_Module>(&id); | 89 return id; |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool ParseArgs(const char* str, | 92 bool ParseArgs(const char* str, |
| 93 uint32_t* argc, | 93 uint32_t* argc, |
| 94 const char*** argn, | 94 const char*** argn, |
| 95 const char*** argv) { | 95 const char*** argv) { |
| 96 std::vector<std::string> argn_vector; | 96 std::vector<std::string> argn_vector; |
| 97 std::vector<std::string> argv_vector; | 97 std::vector<std::string> argv_vector; |
| 98 *argc = 0; | 98 *argc = 0; |
| 99 char* embed_arg = std::strtok(strdup(str), ";"); | 99 char* embed_arg = std::strtok(strdup(str), ";"); |
| 100 while (embed_arg != NULL) { | 100 while (embed_arg != NULL) { |
| 101 char* equal_loc = std::strchr(embed_arg, '='); | 101 char* equal_loc = std::strchr(embed_arg, '='); |
| 102 if (equal_loc == NULL) { | 102 if (equal_loc == NULL) { |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 size_t name_length = static_cast<size_t>(equal_loc - embed_arg); | 105 size_t name_length = static_cast<size_t>(equal_loc - embed_arg); |
| 106 argn_vector.push_back(std::string(embed_arg, name_length)); | 106 argn_vector.push_back(std::string(embed_arg, name_length)); |
| 107 argv_vector.push_back(equal_loc + 1); | 107 argv_vector.push_back(equal_loc + 1); |
| 108 ++*argc; | 108 ++*argc; |
| 109 embed_arg = std::strtok(NULL, ";"); | 109 embed_arg = std::strtok(NULL, ";"); |
| 110 } | 110 } |
| 111 | 111 |
| 112 *argn = reinterpret_cast<const char**>(malloc(*argc * sizeof(*argn))); | 112 *argn = reinterpret_cast<const char**>(malloc(*argc * sizeof(*argn))); |
| 113 *argv = reinterpret_cast<const char**>(malloc(*argc * sizeof(*argv))); | 113 *argv = reinterpret_cast<const char**>(malloc(*argc * sizeof(*argv))); |
| 114 for (uint32_t i = 0; i < *argc; ++i) { | 114 for (uint32_t i = 0; i < *argc; ++i) { |
| 115 (*argn)[i] = strdup(argn_vector[i].c_str()); | 115 (*argn)[i] = strdup(argn_vector[i].c_str()); |
| 116 (*argv)[i] = strdup(argv_vector[i].c_str()); | 116 (*argv)[i] = strdup(argv_vector[i].c_str()); |
| 117 printf("ParseArgs(): arg[%u]: '%s' = '%s'\n", i, (*argn)[i], (*argv)[i]); | 117 DebugPrintf("ParseArgs(): arg[%u]: '%s' = '%s'\n", |
| 118 i, (*argn)[i], (*argv)[i]); | |
| 118 } | 119 } |
| 119 return true; | 120 return true; |
| 120 } | 121 } |
| 121 | 122 |
| 123 } // namespace | |
| 124 | |
| 125 namespace fake_browser_ppapi { | |
| 126 | |
| 127 PP_Resource TrackResource(Resource* resource) { | |
| 128 PP_Resource resource_id = host->TrackResource(resource); | |
| 129 DebugPrintf("TrackResource: resource_id=%"NACL_PRId32"\n", resource_id); | |
| 130 return resource_id; | |
| 131 } | |
| 132 | |
| 133 Resource* GetResource(PP_Resource resource_id) { | |
| 134 return host->GetResource(resource_id); | |
| 135 } | |
| 136 | |
| 137 PP_Instance TrackInstance(Instance* instance) { | |
| 138 PP_Instance instance_id = host->TrackInstance(instance); | |
| 139 DebugPrintf("TrackInstance: instance_id=%"NACL_PRId32"\n", instance_id); | |
| 140 return instance_id; | |
| 141 } | |
| 142 | |
| 143 Instance* GetInstance(PP_Instance instance_id) { | |
| 144 return host->GetInstance(instance_id); | |
| 145 } | |
| 146 | |
| 147 } // namespace fake_browser_ppapi | |
| 148 | |
| 149 namespace { | |
| 150 | |
| 122 // Test instance execution. | 151 // Test instance execution. |
| 123 void TestInstance(PP_Module browser_module_id, | 152 void TestInstance(PP_Module browser_module_id, |
| 124 const PPP_Instance* instance_interface, | 153 const PPP_Instance* instance_interface, |
| 125 const char* page_url, | 154 const char* page_url, |
| 126 uint32_t argc, | 155 uint32_t argc, |
| 127 const char** argn, | 156 const char** argn, |
| 128 const char** argv) { | 157 const char** argv) { |
| 129 printf("TestInstance(): page url %s\n", page_url); | 158 DebugPrintf("TestInstance(): page url %s\n", page_url); |
| 130 // Create an instance and the corresponding id. | 159 // Create an instance and the corresponding id. |
| 131 fake_browser_ppapi::Instance browser_instance; | 160 fake_browser_ppapi::Instance* instance = new fake_browser_ppapi::Instance; |
| 132 PP_Instance instance_id = reinterpret_cast<PP_Instance>(&browser_instance); | 161 PP_Instance instance_id = TrackInstance(instance); |
| 133 | |
| 134 // Create a fake window object. | 162 // Create a fake window object. |
| 135 FakeWindow window(browser_module_id, instance_id, host, page_url); | 163 FakeWindow window(browser_module_id, instance_id, host, page_url); |
| 136 browser_instance.set_window(&window); | 164 instance->set_window(&window); |
| 137 | |
| 138 // Create and initialize plugin instance. | 165 // Create and initialize plugin instance. |
| 139 CHECK(instance_interface->DidCreate(instance_id, argc, argn, argv)); | 166 CHECK(instance_interface->DidCreate(instance_id, argc, argn, argv)); |
| 167 DebugPrintf("TestInstance(): instance initialized\n"); | |
|
sehr (please use chromium)
2011/01/12 00:55:10
Do we need these prints? I think not.
neb
2011/01/13 00:00:43
They sneaked in. Done.
| |
| 140 // Test the scriptable object for the instance. | 168 // Test the scriptable object for the instance. |
| 141 PP_Var instance_object = instance_interface->GetInstanceObject(instance_id); | 169 PP_Var instance_object = instance_interface->GetInstanceObject(instance_id); |
| 170 DebugPrintf("TestInstance(): instance object obtained\n"); | |
| 142 const PPB_Var_Deprecated* var_interface = | 171 const PPB_Var_Deprecated* var_interface = |
| 143 reinterpret_cast<const PPB_Var_Deprecated*>( | 172 reinterpret_cast<const PPB_Var_Deprecated*>( |
| 144 FakeGetBrowserInterface(PPB_VAR_DEPRECATED_INTERFACE)); | 173 FakeGetBrowserInterface(PPB_VAR_DEPRECATED_INTERFACE)); |
| 174 DebugPrintf("TestInstance(): PPB_Var_Deprecated interface obtained\n"); | |
| 145 TestScriptableObject(instance_object, | 175 TestScriptableObject(instance_object, |
| 146 browser_instance.GetInterface(), | 176 fake_browser_ppapi::Instance::GetInterface(), |
| 147 var_interface, | 177 var_interface, |
| 148 instance_id, | 178 instance_id, |
| 149 browser_module_id); | 179 browser_module_id); |
| 150 } | 180 } |
| 151 | 181 |
| 152 } // namespace | 182 } // namespace |
| 153 | 183 |
| 154 namespace fake_browser_ppapi { | |
| 155 | |
| 156 PP_Resource TrackResource(Resource* resource) { | |
| 157 PP_Resource resource_id = host->TrackResource(resource); | |
| 158 DebugPrintf("TrackResource: resource_id=%"NACL_PRId64"\n", resource_id); | |
| 159 resource->set_resource_id(resource_id); | |
| 160 return resource_id; | |
| 161 } | |
| 162 | |
| 163 Resource* GetResource(PP_Resource resource_id) { | |
| 164 return host->GetResource(resource_id); | |
| 165 } | |
| 166 | |
| 167 } // namespace fake_browser_ppapi | |
| 168 | |
| 169 int main(int argc, char** argv) { | 184 int main(int argc, char** argv) { |
| 170 // Turn off stdout buffering to aid debugging in case of a crash. | 185 // Turn off stdout buffering to aid debugging in case of a crash. |
| 171 setvbuf(stdout, NULL, _IONBF, 0); | 186 setvbuf(stdout, NULL, _IONBF, 0); |
| 172 | 187 |
| 173 NaClLogModuleInit(); | 188 NaClLogModuleInit(); |
| 174 | 189 |
| 175 if (argc < 5) { | 190 if (argc < 5) { |
| 176 fprintf(stderr, | 191 fprintf(stderr, |
| 177 "Usage: fake_browser_ppapi plugin page_url \"embed args\"" | 192 "Usage: fake_browser_ppapi plugin page_url \"embed args\"" |
| 178 " root_path\n"); | 193 " root_path\n"); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 | 236 |
| 222 // Shutdown. | 237 // Shutdown. |
| 223 host->ShutdownModule(); | 238 host->ShutdownModule(); |
| 224 | 239 |
| 225 // Close the plugin .so. | 240 // Close the plugin .so. |
| 226 delete host; | 241 delete host; |
| 227 | 242 |
| 228 printf("PASS\n"); | 243 printf("PASS\n"); |
| 229 return 0; | 244 return 0; |
| 230 } | 245 } |
| OLD | NEW |