| 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 |
| 7 #include "base/string_util.h" |
| 6 #include "webkit/glue/plugins/test/npapi_constants.h" | 8 #include "webkit/glue/plugins/test/npapi_constants.h" |
| 7 | 9 |
| 8 namespace NPAPIClient { | 10 namespace NPAPIClient { |
| 9 | 11 |
| 10 PluginTest::PluginTest(NPP id, NPNetscapeFuncs *host_functions) { | 12 PluginTest::PluginTest(NPP id, NPNetscapeFuncs *host_functions) { |
| 11 id_ = id; | 13 id_ = id; |
| 12 id_->pdata = this; | 14 id_->pdata = this; |
| 13 host_functions_ = host_functions; | 15 host_functions_ = host_functions; |
| 14 } | 16 } |
| 15 | 17 |
| 16 NPError PluginTest::New(uint16 mode, int16 argc, const char* argn[], | 18 NPError PluginTest::New(uint16 mode, int16 argc, const char* argn[], |
| 17 const char* argv[], NPSavedData* saved) { | 19 const char* argv[], NPSavedData* saved) { |
| 18 test_name_ = this->GetArgValue("name", argc, argn, argv); | 20 test_name_ = this->GetArgValue("name", argc, argn, argv); |
| 19 test_id_ = this->GetArgValue("id", argc, argn, argv); | 21 test_id_ = this->GetArgValue("id", argc, argn, argv); |
| 20 return NPERR_NO_ERROR; | 22 return NPERR_NO_ERROR; |
| 21 } | 23 } |
| 22 | 24 |
| 23 NPError PluginTest::SetWindow(NPWindow* pNPWindow) { | 25 NPError PluginTest::SetWindow(NPWindow* pNPWindow) { |
| 24 return NPERR_NO_ERROR; | 26 return NPERR_NO_ERROR; |
| 25 } | 27 } |
| 26 | 28 |
| 27 // It's a shame I have to implement URLEncode. But, using webkit's | 29 // It's a shame I have to implement URLEncode. But, using webkit's |
| 28 // or using chrome's means a ball of string of dlls and dependencies that | 30 // or using chrome's means a ball of string of dlls and dependencies that |
| 29 // is very very long. After spending far too much time on it, | 31 // is very very long. After spending far too much time on it, |
| 30 // I'll just encode it myself. Too bad Microsoft doesn't implement | 32 // I'll just encode it myself. Too bad Microsoft doesn't implement |
| 31 // this in a reusable way either. Both webkit and chrome will | 33 // this in a reusable way either. Both webkit and chrome will |
| 32 // end up using libicu, which is a string of dependencies we don't | 34 // end up using libicu, which is a string of dependencies we don't |
| 33 // want. | 35 // want. |
| 34 | 36 |
| 35 inline BYTE toHex(const BYTE &x) { | 37 inline unsigned char toHex(const unsigned char x) { |
| 36 return x > 9 ? x + 55: x + 48; | 38 return x > 9 ? (x + 'A' - 10) : (x + '0'); |
| 37 } | 39 } |
| 38 | 40 |
| 39 std::string URLEncode(const std::string &sIn) { | 41 std::string URLEncode(const std::string &sIn) { |
| 40 std::string sOut; | 42 std::string sOut; |
| 41 | 43 |
| 42 const size_t length = sIn.length(); | 44 const size_t length = sIn.length(); |
| 43 for (size_t idx = 0; idx < length;) { | 45 for (size_t idx = 0; idx < length;) { |
| 44 const char ch = sIn.at(idx); | 46 const char ch = sIn.at(idx); |
| 45 if (isalnum(ch)) { | 47 if (isalnum(ch)) { |
| 46 sOut.append(1, ch); | 48 sOut.append(1, ch); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 83 } |
| 82 script_url = URLEncode(script_url); | 84 script_url = URLEncode(script_url); |
| 83 script_result.append("javascript:"); | 85 script_result.append("javascript:"); |
| 84 script_result.append(script_url); | 86 script_result.append(script_url); |
| 85 host_functions_->geturl(id_, script_result.c_str(), "_self"); | 87 host_functions_->geturl(id_, script_result.c_str(), "_self"); |
| 86 } | 88 } |
| 87 | 89 |
| 88 const char *PluginTest::GetArgValue(const char *name, const int16 argc, | 90 const char *PluginTest::GetArgValue(const char *name, const int16 argc, |
| 89 const char *argn[], const char *argv[]) { | 91 const char *argn[], const char *argv[]) { |
| 90 for (int idx = 0; idx < argc; idx++) | 92 for (int idx = 0; idx < argc; idx++) |
| 91 if (_stricmp(argn[idx], name) == 0) | 93 if (base::strcasecmp(argn[idx], name) == 0) |
| 92 return argv[idx]; | 94 return argv[idx]; |
| 93 return NULL; | 95 return NULL; |
| 94 } | 96 } |
| 95 | 97 |
| 96 void PluginTest::SetError(const std::string &msg) { | 98 void PluginTest::SetError(const std::string &msg) { |
| 97 test_status_.append(msg); | 99 test_status_.append(msg); |
| 98 } | 100 } |
| 99 | 101 |
| 100 NPError PluginTest::NewStream(NPMIMEType type, NPStream* stream, | 102 NPError PluginTest::NewStream(NPMIMEType type, NPStream* stream, |
| 101 NPBool seekable, uint16* stype) { | 103 NPBool seekable, uint16* stype) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 127 // There is no default action | 129 // There is no default action |
| 128 } | 130 } |
| 129 | 131 |
| 130 int16 PluginTest::HandleEvent(void* event) { | 132 int16 PluginTest::HandleEvent(void* event) { |
| 131 // There is no default action | 133 // There is no default action |
| 132 return 0; | 134 return 0; |
| 133 } | 135 } |
| 134 | 136 |
| 135 } // namespace NPAPIClient | 137 } // namespace NPAPIClient |
| 136 | 138 |
| OLD | NEW |