Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "webkit/glue/plugins/test/plugin_test.h" | 5 #include "webkit/glue/plugins/test/plugin_test.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "webkit/glue/plugins/test/npapi_constants.h" | 8 #include "webkit/glue/plugins/test/npapi_constants.h" |
| 9 | 9 |
| 10 namespace NPAPIClient { | 10 namespace NPAPIClient { |
| 11 | 11 |
| 12 PluginTest::PluginTest(NPP id, NPNetscapeFuncs *host_functions) { | 12 PluginTest::PluginTest(NPP id, NPNetscapeFuncs *host_functions) { |
| 13 id_ = id; | 13 id_ = id; |
| 14 id_->pdata = this; | 14 id_->pdata = this; |
| 15 host_functions_ = host_functions; | 15 host_functions_ = host_functions; |
| 16 test_completed_ = false; | 16 test_completed_ = false; |
| 17 } | 17 } |
| 18 | 18 |
| 19 NPError PluginTest::New(uint16 mode, int16 argc, const char* argn[], | 19 NPError PluginTest::New(uint16 mode, int16 argc, const char* argn[], |
| 20 const char* argv[], NPSavedData* saved) { | 20 const char* argv[], NPSavedData* saved) { |
| 21 test_name_ = this->GetArgValue("name", argc, argn, argv); | 21 test_name_ = this->GetArgValue("name", argc, argn, argv); |
| 22 test_id_ = this->GetArgValue("id", argc, argn, argv); | 22 test_id_ = this->GetArgValue("id", argc, argn, argv); |
| 23 return NPERR_NO_ERROR; | 23 return NPERR_NO_ERROR; |
| 24 } | 24 } |
| 25 | 25 |
| 26 NPError PluginTest::Destroy() { | |
| 27 return NPERR_NO_ERROR; | |
| 28 } | |
| 29 | |
| 26 NPError PluginTest::SetWindow(NPWindow* pNPWindow) { | 30 NPError PluginTest::SetWindow(NPWindow* pNPWindow) { |
| 27 return NPERR_NO_ERROR; | 31 return NPERR_NO_ERROR; |
| 28 } | 32 } |
| 29 | 33 |
| 30 // It's a shame I have to implement URLEncode. But, using webkit's | 34 // It's a shame I have to implement URLEncode. But, using webkit's |
| 31 // or using chrome's means a ball of string of dlls and dependencies that | 35 // or using chrome's means a ball of string of dlls and dependencies that |
| 32 // is very very long. After spending far too much time on it, | 36 // is very very long. After spending far too much time on it, |
| 33 // I'll just encode it myself. Too bad Microsoft doesn't implement | 37 // I'll just encode it myself. Too bad Microsoft doesn't implement |
| 34 // this in a reusable way either. Both webkit and chrome will | 38 // this in a reusable way either. Both webkit and chrome will |
| 35 // end up using libicu, which is a string of dependencies we don't | 39 // end up using libicu, which is a string of dependencies we don't |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 59 return sOut; | 63 return sOut; |
| 60 } | 64 } |
| 61 | 65 |
| 62 void PluginTest::SignalTestCompleted() { | 66 void PluginTest::SignalTestCompleted() { |
| 63 test_completed_ = true; | 67 test_completed_ = true; |
| 64 // To signal test completion, we expect a couple of | 68 // To signal test completion, we expect a couple of |
| 65 // javascript functions to be defined in the webpage | 69 // javascript functions to be defined in the webpage |
| 66 // which hosts this plugin: | 70 // which hosts this plugin: |
| 67 // onSuccess(test_name, test_id) | 71 // onSuccess(test_name, test_id) |
| 68 // onFailure(test_name, test_id, error_message) | 72 // onFailure(test_name, test_id, error_message) |
| 69 std::string script_result; | 73 std::string script("javascript:"); |
| 70 std::string script_url; | |
| 71 if (Succeeded()) { | 74 if (Succeeded()) { |
| 72 script_url.append("onSuccess(\""); | 75 script.append("onSuccess(\""); |
| 73 script_url.append(test_name_); | 76 script.append(test_name_); |
| 74 script_url.append("\",\""); | 77 script.append("\",\""); |
| 75 script_url.append(test_id_); | 78 script.append(test_id_); |
| 76 script_url.append("\");"); | 79 script.append("\");"); |
| 77 } else { | 80 } else { |
| 78 script_url.append("onFailure(\""); | 81 script.append("onFailure(\""); |
| 79 script_url.append(test_name_); | 82 script.append(test_name_); |
| 80 script_url.append("\",\""); | 83 script.append("\",\""); |
| 81 script_url.append(test_id_); | 84 script.append(test_id_); |
| 82 script_url.append("\",\""); | 85 script.append("\",\""); |
| 83 script_url.append(test_status_); | 86 script.append(test_status_); |
| 84 script_url.append("\");"); | 87 script.append("\");"); |
| 85 } | 88 } |
| 86 script_url = URLEncode(script_url); | 89 |
| 87 script_result.append("javascript:"); | 90 NPObject *window_obj = NULL; |
| 88 script_result.append(script_url); | 91 host_functions_->getvalue(id_, NPNVWindowNPObject,&window_obj); |
| 89 host_functions_->geturl(id_, script_result.c_str(), "_self"); | 92 if (!window_obj) |
|
ananta
2009/10/06 18:18:24
Nit: maybe we should do this at the top of this fu
jam
2009/10/06 19:12:40
Done.
| |
| 93 return; | |
| 94 | |
| 95 NPString script_string; | |
| 96 script_string.UTF8Characters = script.c_str(); | |
| 97 script_string.UTF8Length = static_cast<unsigned int>(script.length()); | |
| 98 | |
| 99 NPVariant result_var; | |
| 100 host_functions_->evaluate(id_, window_obj, &script_string, &result_var); | |
| 90 } | 101 } |
| 91 | 102 |
| 92 const char *PluginTest::GetArgValue(const char *name, const int16 argc, | 103 const char *PluginTest::GetArgValue(const char *name, const int16 argc, |
| 93 const char *argn[], const char *argv[]) { | 104 const char *argn[], const char *argv[]) { |
| 94 for (int idx = 0; idx < argc; idx++) | 105 for (int idx = 0; idx < argc; idx++) |
| 95 if (base::strcasecmp(argn[idx], name) == 0) | 106 if (base::strcasecmp(argn[idx], name) == 0) |
| 96 return argv[idx]; | 107 return argv[idx]; |
| 97 return NULL; | 108 return NULL; |
| 98 } | 109 } |
| 99 | 110 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 130 void PluginTest::URLNotify(const char* url, NPReason reason, void* data) { | 141 void PluginTest::URLNotify(const char* url, NPReason reason, void* data) { |
| 131 // There is no default action | 142 // There is no default action |
| 132 } | 143 } |
| 133 | 144 |
| 134 int16 PluginTest::HandleEvent(void* event) { | 145 int16 PluginTest::HandleEvent(void* event) { |
| 135 // There is no default action | 146 // There is no default action |
| 136 return 0; | 147 return 0; |
| 137 } | 148 } |
| 138 | 149 |
| 139 } // namespace NPAPIClient | 150 } // namespace NPAPIClient |
| OLD | NEW |