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

Side by Side Diff: chrome_frame/chrome_frame_npapi_entrypoints.cc

Issue 521072: Attempt 2 at landing this.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome_frame/chrome_frame_npapi_entrypoints.h"
5 #include "chrome_frame/chrome_frame_npapi.h" 6 #include "chrome_frame/chrome_frame_npapi.h"
6 7
7 #define NPAPI WINAPI 8 #define NPAPI WINAPI
8 9
9 // Plugin entry points. 10 // Plugin entry points.
10 extern "C" { 11 extern "C" {
11 NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs); 12 NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs);
12 NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs); 13 NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs);
13 void NPAPI NP_Shutdown(); 14 void NPAPI NP_Shutdown();
14 } 15 }
15 16
16 NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs) { 17 NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs) {
17 DLOG(INFO) << __FUNCTION__; 18 DLOG(INFO) << __FUNCTION__;
18 _pAtlModule->Lock(); 19 _pAtlModule->Lock();
19 npapi::InitializeBrowserFunctions(browser_funcs); 20 npapi::InitializeBrowserFunctions(browser_funcs);
20 return NPERR_NO_ERROR; 21 return NPERR_NO_ERROR;
21 } 22 }
22 23
23 NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) { 24 NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) {
24 plugin_funcs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; 25 plugin_funcs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
25 plugin_funcs->size = sizeof(plugin_funcs); 26 plugin_funcs->size = sizeof(plugin_funcs);
26 plugin_funcs->newp = NPP_New; 27 plugin_funcs->newp = chrome_frame::NPP_New;
27 plugin_funcs->destroy = NPP_Destroy; 28 plugin_funcs->destroy = chrome_frame::NPP_Destroy;
28 plugin_funcs->setwindow = NPP_SetWindow; 29 plugin_funcs->setwindow = chrome_frame::NPP_SetWindow;
29 plugin_funcs->newstream = NPP_NewStream; 30 plugin_funcs->newstream = chrome_frame::NPP_NewStream;
30 plugin_funcs->destroystream = NPP_DestroyStream; 31 plugin_funcs->destroystream = chrome_frame::NPP_DestroyStream;
31 plugin_funcs->asfile = NULL; 32 plugin_funcs->asfile = NULL;
32 plugin_funcs->writeready = NPP_WriteReady; 33 plugin_funcs->writeready = chrome_frame::NPP_WriteReady;
33 plugin_funcs->write = NPP_Write; 34 plugin_funcs->write = chrome_frame::NPP_Write;
34 plugin_funcs->print = NPP_Print; 35 plugin_funcs->print = chrome_frame::NPP_Print;
35 plugin_funcs->event = NULL; 36 plugin_funcs->event = NULL;
36 plugin_funcs->urlnotify = NPP_URLNotify; 37 plugin_funcs->urlnotify = chrome_frame::NPP_URLNotify;
37 plugin_funcs->getvalue = NPP_GetValue; 38 plugin_funcs->getvalue = chrome_frame::NPP_GetValue;
38 plugin_funcs->setvalue = NPP_SetValue; 39 plugin_funcs->setvalue = chrome_frame::NPP_SetValue;
39 return NPERR_NO_ERROR; 40 return NPERR_NO_ERROR;
40 } 41 }
41 42
42 void NPAPI NP_Shutdown() { 43 void NPAPI NP_Shutdown() {
43 DLOG(INFO) << __FUNCTION__; 44 DLOG(INFO) << __FUNCTION__;
44 45
45 npapi::UninitializeBrowserFunctions(); 46 npapi::UninitializeBrowserFunctions();
46 47
47 _pAtlModule->Unlock(); // matches Lock() inside NP_Initialize 48 _pAtlModule->Unlock(); // matches Lock() inside NP_Initialize
48 49
49 DLOG_IF(ERROR, _pAtlModule->GetLockCount() != 0) 50 DLOG_IF(ERROR, _pAtlModule->GetLockCount() != 0)
50 << "Being shut down but still have " << _pAtlModule->GetLockCount() 51 << "Being shut down but still have " << _pAtlModule->GetLockCount()
51 << " living objects"; 52 << " living objects";
52 } 53 }
53 54
55
56 namespace chrome_frame {
57
58 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc,
59 char* argn[], char* argv[], NPSavedData* saved) {
60 if (instance == NULL)
61 return NPERR_INVALID_INSTANCE_ERROR;
62
63 ChromeFrameNPAPI::ChromeFrameNPObject* chrome_frame_npapi_obj =
64 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>(
65 npapi::CreateObject(instance, ChromeFrameNPAPI::PluginClass()));
66 DCHECK(chrome_frame_npapi_obj != NULL);
67
68 ChromeFrameNPAPI* plugin_instance =
69 chrome_frame_npapi_obj->chrome_frame_plugin_instance;
70 DCHECK(plugin_instance != NULL);
71
72 // Note that we MUST set instance->pdata BEFORE calling Initialize. This is
73 // because Initialize can call back into the NPAPI host which will need the
74 // pdata field to be set.
75 chrome_frame_npapi_obj->chrome_frame_plugin_instance =
76 plugin_instance;
77 instance->pdata = chrome_frame_npapi_obj;
78
79 bool init = plugin_instance->Initialize(plugin_type, instance,
80 mode, argc, argn, argv);
81 DCHECK(init);
82
83 return NPERR_NO_ERROR;
84 }
85
86 NPError NPP_Destroy(NPP instance, NPSavedData** save) {
87 // Takes ownership and releases the object at the end of scope.
88 ScopedNpObject<ChromeFrameNPAPI::ChromeFrameNPObject> chrome_frame_npapi_obj(
89 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>(
90 instance->pdata));
91
92 if (chrome_frame_npapi_obj.get()) {
93 ChromeFrameNPAPI* plugin_instance =
94 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance);
95
96 plugin_instance->Uninitialize();
97 instance->pdata = NULL;
98 }
99
100 return NPERR_NO_ERROR;
101 }
102
103 NPError NPP_SetWindow(NPP instance, NPWindow* window_info) {
104 if (window_info == NULL) {
105 NOTREACHED();
106 return NPERR_GENERIC_ERROR;
107 }
108
109 ChromeFrameNPAPI* plugin_instance =
110 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance);
111
112 if (plugin_instance == NULL) {
113 return NPERR_INVALID_INSTANCE_ERROR;
114 }
115
116 plugin_instance->SetWindow(window_info);
117 return NPERR_NO_ERROR;
118 }
119
120 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
121 NPBool seekable, uint16* stream_type) {
122 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest(
123 instance, stream->notifyData);
124 if (url_request) {
125 if (!url_request->OnStreamCreated(type, stream))
126 return NPERR_GENERIC_ERROR;
127 }
128
129 // We need to return the requested stream mode if we are returning a success
130 // code. If we don't do this it causes Opera to blow up.
131 *stream_type = NP_NORMAL;
132 return NPERR_NO_ERROR;
133 }
134
135 NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) {
136 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest(
137 instance, stream->notifyData);
138 if (url_request) {
139 url_request->OnStreamDestroyed(reason);
140 }
141
142 return NPERR_NO_ERROR;
143 }
144
145 NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) {
146 if (variable == NPPVpluginScriptableNPObject) {
147 void** plugin = reinterpret_cast<void**>(value);
148 ChromeFrameNPAPI::ChromeFrameNPObject* chrome_frame_npapi_obj =
149 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>(
150 instance->pdata);
151 // Return value is expected to be retained
152 npapi::RetainObject(reinterpret_cast<NPObject*>(chrome_frame_npapi_obj));
153 *plugin = chrome_frame_npapi_obj;
154 return NPERR_NO_ERROR;
155 }
156 return NPERR_GENERIC_ERROR;
157 }
158
159 NPError NPP_SetValue(NPP instance, NPNVariable variable, void* value) {
160 return NPERR_GENERIC_ERROR;
161 }
162
163 int32 NPP_WriteReady(NPP instance, NPStream* stream) {
164 static const int kMaxBytesForPluginConsumption = 0x7FFFFFFF;
165
166 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest(
167 instance, stream->notifyData);
168 if (url_request) {
169 return url_request->OnWriteReady();
170 }
171
172 return kMaxBytesForPluginConsumption;
173 }
174
175 int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
176 void* buffer) {
177 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest(
178 instance, stream->notifyData);
179 if (url_request) {
180 return url_request->OnWrite(buffer, len);
181 }
182
183 return len;
184 }
185
186 void NPP_URLNotify(NPP instance, const char* url, NPReason reason,
187 void* notifyData) {
188 ChromeFrameNPAPI* plugin_instance =
189 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance);
190 if (plugin_instance) {
191 plugin_instance->UrlNotify(url, reason, notifyData);
192 }
193 }
194
195 void NPP_Print(NPP instance, NPPrint* print_info) {
196 ChromeFrameNPAPI* plugin_instance =
197 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance);
198
199 if (plugin_instance == NULL) {
200 NOTREACHED();
201 return;
202 }
203
204 plugin_instance->Print(print_info);
205 }
206
207 } // namespace chrome_frame
OLDNEW
« no previous file with comments | « chrome_frame/chrome_frame_npapi_entrypoints.h ('k') | chrome_frame/test/chrome_frame_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698