OLD | NEW |
| (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 // | |
6 // npapitest | |
7 // | |
8 // This is a NPAPI Plugin Program which is used to test the Browser's NPAPI | |
9 // host implementation. It is used in conjunction with the npapi_unittest. | |
10 // | |
11 // As a NPAPI Plugin, you can invoke it by creating a web page of the following | |
12 // type: | |
13 // | |
14 // <embed src="content-to-load" type="application/vnd.npapi-test" | |
15 // name="test-name"> | |
16 // | |
17 // arguments: | |
18 // src: This is the initial content which will be sent to the plugin. | |
19 // type: Must be "application/vnd.npapi-test" | |
20 // name: The testcase to run when invoked | |
21 // id: The id of the test being run (for testing concurrent plugins) | |
22 // | |
23 // The Plugin drives the actual test, calling host functions and validating the | |
24 // Host callbacks which it receives. It is the duty of the plugin to record | |
25 // all errors. | |
26 // | |
27 // To indicate test completion, the plugin expects the containing HTML page to | |
28 // implement two javascript functions: | |
29 // onSuccess(string testname); | |
30 // onFailure(string testname, string results); | |
31 // The HTML host pages used in this test will then set a document cookie | |
32 // which the automated test framework can poll for and discover that the | |
33 // test has completed. | |
34 // | |
35 // | |
36 // TESTS | |
37 // When the PluginClient receives a NPP_New callback from the browser, | |
38 // it looks at the "name" argument which is passed in. It verifies that | |
39 // the name matches a known test, and instantiates that test. The test is | |
40 // a subclass of PluginTest. | |
41 // | |
42 // | |
43 | |
44 #include "base/basictypes.h" | |
45 | |
46 #if defined(OS_WIN) | |
47 #include <windows.h> | |
48 #endif | |
49 | |
50 #if defined(__GNUC__) && __GNUC__ >= 4 | |
51 #define EXPORT __attribute__((visibility ("default"))) | |
52 #else | |
53 #define EXPORT | |
54 #endif | |
55 | |
56 #include "webkit/glue/plugins/test/plugin_client.h" | |
57 | |
58 #if defined(OS_WIN) | |
59 BOOL API_CALL DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) { | |
60 return TRUE; | |
61 } | |
62 #endif | |
63 | |
64 extern "C" { | |
65 EXPORT NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* pFuncs) { | |
66 return NPAPIClient::PluginClient::GetEntryPoints(pFuncs); | |
67 } | |
68 | |
69 EXPORT NPError API_CALL NP_Shutdown() { | |
70 return NPAPIClient::PluginClient::Shutdown(); | |
71 } | |
72 | |
73 #if defined(OS_WIN) || defined(OS_MACOSX) | |
74 EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* npnFuncs) { | |
75 return NPAPIClient::PluginClient::Initialize(npnFuncs); | |
76 } | |
77 #elif defined(OS_POSIX) | |
78 EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* npnFuncs, | |
79 NPPluginFuncs* nppFuncs) { | |
80 NPError error = NPAPIClient::PluginClient::Initialize(npnFuncs); | |
81 if (error == NPERR_NO_ERROR) { | |
82 error = NP_GetEntryPoints(nppFuncs); | |
83 } | |
84 return error; | |
85 } | |
86 | |
87 EXPORT NPError API_CALL NP_GetValue(NPP instance, NPPVariable variable, | |
88 void* value) { | |
89 NPError err = NPERR_NO_ERROR; | |
90 | |
91 switch (variable) { | |
92 case NPPVpluginNameString: | |
93 *(static_cast<const char**>(value)) = "NPAPI Test Plugin"; | |
94 break; | |
95 case NPPVpluginDescriptionString: | |
96 *(static_cast<const char**>(value)) = | |
97 "Simple NPAPI plug-in for Chromium unit tests"; | |
98 break; | |
99 case NPPVpluginNeedsXEmbed: | |
100 *(static_cast<NPBool*>(value)) = true; | |
101 break; | |
102 default: | |
103 err = NPERR_GENERIC_ERROR; | |
104 break; | |
105 } | |
106 | |
107 return err; | |
108 } | |
109 | |
110 EXPORT const char* API_CALL NP_GetMIMEDescription(void) { | |
111 // The layout test LayoutTests/fast/js/navigator-mimeTypes-length.html | |
112 // asserts that the number of mimetypes handled by plugins should be | |
113 // greater than the number of plugins. We specify a mimetype here so | |
114 // this plugin has at least one. | |
115 return "application/vnd.npapi-test:npapitest:test npapi"; | |
116 } | |
117 #endif // OS_POSIX | |
118 } // extern "C" | |
119 | |
120 namespace WebCore { | |
121 const char* currentTextBreakLocaleID() { return "en_us"; } | |
122 } | |
OLD | NEW |