Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: webkit/glue/plugins/test/plugin_test.cc

Issue 6012002: Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi and put... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/plugins/test/plugin_test.h ('k') | webkit/glue/plugins/test/plugin_test_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/glue/plugins/test/plugin_test.h"
6
7 #include "base/string_util.h"
8 #include "webkit/glue/plugins/test/npapi_constants.h"
9
10 namespace NPAPIClient {
11
12 PluginTest::PluginTest(NPP id, NPNetscapeFuncs *host_functions) {
13 id_ = id;
14 id_->pdata = this;
15 host_functions_ = host_functions;
16 test_completed_ = false;
17 }
18
19 NPError PluginTest::New(uint16 mode, int16 argc, const char* argn[],
20 const char* argv[], NPSavedData* saved) {
21 test_name_ = this->GetArgValue("name", argc, argn, argv);
22 test_id_ = this->GetArgValue("id", argc, argn, argv);
23 return NPERR_NO_ERROR;
24 }
25
26 NPError PluginTest::Destroy() {
27 return NPERR_NO_ERROR;
28 }
29
30 NPError PluginTest::SetWindow(NPWindow* pNPWindow) {
31 return NPERR_NO_ERROR;
32 }
33
34 // It's a shame I have to implement URLEncode. But, using webkit's
35 // or using chrome's means a ball of string of dlls and dependencies that
36 // is very very long. After spending far too much time on it,
37 // I'll just encode it myself. Too bad Microsoft doesn't implement
38 // this in a reusable way either. Both webkit and chrome will
39 // end up using libicu, which is a string of dependencies we don't
40 // want.
41
42 inline unsigned char toHex(const unsigned char x) {
43 return x > 9 ? (x + 'A' - 10) : (x + '0');
44 }
45
46 std::string URLEncode(const std::string &sIn) {
47 std::string sOut;
48
49 const size_t length = sIn.length();
50 for (size_t idx = 0; idx < length;) {
51 const char ch = sIn.at(idx);
52 if (isalnum(ch)) {
53 sOut.append(1, ch);
54 } else if (isspace(ch) && ((ch != '\n') && (ch != '\r'))) {
55 sOut.append(1, '+');
56 } else {
57 sOut.append(1, '%');
58 sOut.append(1, toHex(ch>>4));
59 sOut.append(1, toHex(ch%16));
60 }
61 idx++;
62 }
63 return sOut;
64 }
65
66 void PluginTest::SignalTestCompleted() {
67 NPObject *window_obj = NULL;
68 host_functions_->getvalue(id_, NPNVWindowNPObject, &window_obj);
69 if (!window_obj)
70 return;
71
72 test_completed_ = true;
73 // To signal test completion, we expect a couple of
74 // javascript functions to be defined in the webpage
75 // which hosts this plugin:
76 // onSuccess(test_name, test_id)
77 // onFailure(test_name, test_id, error_message)
78 std::string script("javascript:");
79 if (Succeeded()) {
80 script.append("onSuccess(\"");
81 script.append(test_name_);
82 script.append("\",\"");
83 script.append(test_id_);
84 script.append("\");");
85 } else {
86 script.append("onFailure(\"");
87 script.append(test_name_);
88 script.append("\",\"");
89 script.append(test_id_);
90 script.append("\",\"");
91 script.append(test_status_);
92 script.append("\");");
93 }
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);
101 }
102
103 const char *PluginTest::GetArgValue(const char *name, const int16 argc,
104 const char *argn[], const char *argv[]) {
105 for (int idx = 0; idx < argc; idx++)
106 if (base::strcasecmp(argn[idx], name) == 0)
107 return argv[idx];
108 return NULL;
109 }
110
111 void PluginTest::SetError(const std::string &msg) {
112 test_status_.append(msg);
113 }
114
115 NPError PluginTest::NewStream(NPMIMEType type, NPStream* stream,
116 NPBool seekable, uint16* stype) {
117 // There is no default action here.
118 return NPERR_NO_ERROR;
119 }
120
121 int32 PluginTest::WriteReady(NPStream *stream) {
122 // Take data in small chunks
123 return 4096;
124 }
125
126 int32 PluginTest::Write(NPStream *stream, int32 offset, int32 len,
127 void *buffer) {
128 // Pretend that we took all the data.
129 return len;
130 }
131
132 NPError PluginTest::DestroyStream(NPStream *stream, NPError reason) {
133 // There is no default action.
134 return NPERR_NO_ERROR;
135 }
136
137 void PluginTest::StreamAsFile(NPStream* stream, const char* fname) {
138 // There is no default action.
139 }
140
141 void PluginTest::URLNotify(const char* url, NPReason reason, void* data) {
142 // There is no default action
143 }
144
145 int16 PluginTest::HandleEvent(void* event) {
146 // There is no default action
147 return 0;
148 }
149
150 void PluginTest::URLRedirectNotify(const char* url, int32_t status,
151 void* notify_data) {
152 // There is no default action
153 }
154
155 } // namespace NPAPIClient
OLDNEW
« no previous file with comments | « webkit/glue/plugins/test/plugin_test.h ('k') | webkit/glue/plugins/test/plugin_test_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698