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

Side by Side Diff: ceee/common/np_browser_functions.cc

Issue 4563001: Adding a privileged callback used in IE CF to check whether to show... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | « ceee/common/np_browser_functions.h ('k') | ceee/ie/common/chrome_frame_host.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) 2010 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 #include "ceee/common/np_browser_functions.h"
5
6 #include "base/logging.h"
7
8 namespace npapi {
9
10 // global function pointers (within this namespace) for the NPN functions.
11 NPN_GetURLProcPtr g_geturl = NULL;
12 NPN_PostURLProcPtr g_posturl = NULL;
13 NPN_RequestReadProcPtr g_requestread = NULL;
14 NPN_NewStreamProcPtr g_newstream = NULL;
15 NPN_WriteProcPtr g_write = NULL;
16 NPN_DestroyStreamProcPtr g_destroystream = NULL;
17 NPN_StatusProcPtr g_status = NULL;
18 NPN_UserAgentProcPtr g_useragent = NULL;
19 NPN_MemAllocProcPtr g_memalloc = NULL;
20 NPN_MemFreeProcPtr g_memfree = NULL;
21 NPN_MemFlushProcPtr g_memflush = NULL;
22 NPN_ReloadPluginsProcPtr g_reloadplugins = NULL;
23 NPN_GetJavaEnvProcPtr g_getJavaEnv = NULL;
24 NPN_GetJavaPeerProcPtr g_getJavaPeer = NULL;
25 NPN_GetURLNotifyProcPtr g_geturlnotify = NULL;
26 NPN_PostURLNotifyProcPtr g_posturlnotify = NULL;
27 NPN_GetValueProcPtr g_getvalue = NULL;
28 NPN_SetValueProcPtr g_setvalue = NULL;
29 NPN_InvalidateRectProcPtr g_invalidaterect = NULL;
30 NPN_InvalidateRegionProcPtr g_invalidateregion = NULL;
31 NPN_ForceRedrawProcPtr g_forceredraw = NULL;
32 NPN_GetStringIdentifierProcPtr g_getstringidentifier = NULL;
33 NPN_GetStringIdentifiersProcPtr g_getstringidentifiers = NULL;
34 NPN_GetIntIdentifierProcPtr g_getintidentifier = NULL;
35 NPN_IdentifierIsStringProcPtr g_identifierisstring = NULL;
36 NPN_UTF8FromIdentifierProcPtr g_utf8fromidentifier = NULL;
37 NPN_IntFromIdentifierProcPtr g_intfromidentifier = NULL;
38 NPN_CreateObjectProcPtr g_createobject = NULL;
39 NPN_RetainObjectProcPtr g_retainobject = NULL;
40 NPN_ReleaseObjectProcPtr g_releaseobject = NULL;
41 NPN_InvokeProcPtr g_invoke = NULL;
42 NPN_InvokeDefaultProcPtr g_invoke_default = NULL;
43 NPN_EvaluateProcPtr g_evaluate = NULL;
44 NPN_GetPropertyProcPtr g_getproperty = NULL;
45 NPN_SetPropertyProcPtr g_setproperty = NULL;
46 NPN_RemovePropertyProcPtr g_removeproperty = NULL;
47 NPN_HasPropertyProcPtr g_hasproperty = NULL;
48 NPN_HasMethodProcPtr g_hasmethod = NULL;
49 NPN_ReleaseVariantValueProcPtr g_releasevariantvalue = NULL;
50 NPN_SetExceptionProcPtr g_setexception = NULL;
51 NPN_PushPopupsEnabledStateProcPtr g_pushpopupsenabledstate = NULL;
52 NPN_PopPopupsEnabledStateProcPtr g_poppopupsenabledstate = NULL;
53 NPN_EnumerateProcPtr g_enumerate = NULL;
54 NPN_PluginThreadAsyncCallProcPtr g_pluginthreadasynccall = NULL;
55 NPN_ConstructProcPtr g_construct = NULL;
56
57 // Must be called prior to calling any of the browser functions below.
58 void InitializeBrowserFunctions(NPNetscapeFuncs* functions) {
59 CHECK(functions);
60 DCHECK(g_geturl == NULL || g_geturl == functions->geturl);
61
62 g_geturl = functions->geturl;
63 g_posturl = functions->posturl;
64 g_requestread = functions->requestread;
65 g_newstream = functions->newstream;
66 g_write = functions->write;
67 g_destroystream = functions->destroystream;
68 g_status = functions->status;
69 g_useragent = functions->uagent;
70 g_memalloc = functions->memalloc;
71 g_memfree = functions->memfree;
72 g_memflush = functions->memflush;
73 g_reloadplugins = functions->reloadplugins;
74 g_getJavaEnv = functions->getJavaEnv;
75 g_getJavaPeer = functions->getJavaPeer;
76 g_geturlnotify = functions->geturlnotify;
77 g_posturlnotify = functions->posturlnotify;
78 g_getvalue = functions->getvalue;
79 g_setvalue = functions->setvalue;
80 g_invalidaterect = functions->invalidaterect;
81 g_invalidateregion = functions->invalidateregion;
82 g_forceredraw = functions->forceredraw;
83 g_getstringidentifier = functions->getstringidentifier;
84 g_getstringidentifiers = functions->getstringidentifiers;
85 g_getintidentifier = functions->getintidentifier;
86 g_identifierisstring = functions->identifierisstring;
87 g_utf8fromidentifier = functions->utf8fromidentifier;
88 g_intfromidentifier = functions->intfromidentifier;
89 g_createobject = functions->createobject;
90 g_retainobject = functions->retainobject;
91 g_releaseobject = functions->releaseobject;
92 g_invoke = functions->invoke;
93 g_invoke_default = functions->invokeDefault;
94 g_evaluate = functions->evaluate;
95 g_getproperty = functions->getproperty;
96 g_setproperty = functions->setproperty;
97 g_removeproperty = functions->removeproperty;
98 g_hasproperty = functions->hasproperty;
99 g_hasmethod = functions->hasmethod;
100 g_releasevariantvalue = functions->releasevariantvalue;
101 g_setexception = functions->setexception;
102 g_pushpopupsenabledstate = functions->pushpopupsenabledstate;
103 g_poppopupsenabledstate = functions->poppopupsenabledstate;
104 g_enumerate = functions->enumerate;
105 g_pluginthreadasynccall = functions->pluginthreadasynccall;
106 g_construct = functions->construct;
107 }
108
109 void UninitializeBrowserFunctions() {
110 // We skip doing this in the official build as it doesn't serve much purpose
111 // during shutdown. The reason for it being here in the other types of builds
112 // is to spot potential browser bugs whereby the browser leaves living objects
113 // in our DLL after shutdown has been called. In theory those objects could
114 // trigger a call to the browser functions after shutdown has been called
115 // and for non official builds we want that to simply crash.
116 // For official builds we leave the function pointers around since they
117 // continue to valid.
118 g_geturl = NULL;
119 g_posturl = NULL;
120 g_requestread = NULL;
121 g_newstream = NULL;
122 g_write = NULL;
123 g_destroystream = NULL;
124 g_status = NULL;
125 g_useragent = NULL;
126 g_memalloc = NULL;
127 g_memfree = NULL;
128 g_memflush = NULL;
129 g_reloadplugins = NULL;
130 g_getJavaEnv = NULL;
131 g_getJavaPeer = NULL;
132 g_geturlnotify = NULL;
133 g_posturlnotify = NULL;
134 g_getvalue = NULL;
135 g_setvalue = NULL;
136 g_invalidaterect = NULL;
137 g_invalidateregion = NULL;
138 g_forceredraw = NULL;
139 g_getstringidentifier = NULL;
140 g_getstringidentifiers = NULL;
141 g_getintidentifier = NULL;
142 g_identifierisstring = NULL;
143 g_utf8fromidentifier = NULL;
144 g_intfromidentifier = NULL;
145 g_createobject = NULL;
146 g_retainobject = NULL;
147 g_releaseobject = NULL;
148 g_invoke = NULL;
149 g_invoke_default = NULL;
150 g_evaluate = NULL;
151 g_getproperty = NULL;
152 g_setproperty = NULL;
153 g_removeproperty = NULL;
154 g_hasproperty = NULL;
155 g_hasmethod = NULL;
156 g_releasevariantvalue = NULL;
157 g_setexception = NULL;
158 g_pushpopupsenabledstate = NULL;
159 g_poppopupsenabledstate = NULL;
160 g_enumerate = NULL;
161 g_pluginthreadasynccall = NULL;
162 g_construct = NULL;
163 }
164
165 bool IsInitialized() {
166 // We only check one function for convenience.
167 return g_getvalue != NULL;
168 }
169
170 // Function stubs for functions that the host browser implements.
171
172 NPError GetURL(NPP instance, const char* URL, const char* window) {
173 DCHECK(IsInitialized()) << __FUNCTION__;
174 return g_geturl(instance, URL, window);
175 }
176
177 NPError PostURL(NPP instance, const char* URL, const char* window, uint32 len,
178 const char* buf, NPBool file) {
179 DCHECK(IsInitialized()) << __FUNCTION__;
180 return g_posturl(instance, URL, window, len, buf, file);
181 }
182
183 NPError RequestRead(NPStream* stream, NPByteRange* rangeList) {
184 DCHECK(IsInitialized()) << __FUNCTION__;
185 return g_requestread(stream, rangeList);
186 }
187
188 NPError NewStream(NPP instance, NPMIMEType type, const char* window,
189 NPStream** stream) {
190 DCHECK(IsInitialized()) << __FUNCTION__;
191 return g_newstream(instance, type, window, stream);
192 }
193
194 int32 Write(NPP instance, NPStream* stream, int32 len, void* buffer) {
195 DCHECK(IsInitialized()) << __FUNCTION__;
196 return g_write(instance, stream, len, buffer);
197 }
198
199 NPError DestroyStream(NPP instance, NPStream* stream, NPReason reason) {
200 DCHECK(IsInitialized()) << __FUNCTION__;
201 return g_destroystream(instance, stream, reason);
202 }
203
204 void Status(NPP instance, const char* message) {
205 DCHECK(IsInitialized()) << __FUNCTION__;
206 return g_status(instance, message);
207 }
208
209 const char* UserAgent(NPP instance) {
210 DCHECK(IsInitialized()) << __FUNCTION__;
211 return g_useragent(instance);
212 }
213
214 void* MemAlloc(uint32 size) {
215 DCHECK(IsInitialized()) << __FUNCTION__;
216 return g_memalloc(size);
217 }
218
219 void MemFree(void* ptr) {
220 DCHECK(IsInitialized()) << __FUNCTION__;
221 return g_memfree(ptr);
222 }
223
224 uint32 MemFlush(uint32 size) {
225 DCHECK(IsInitialized()) << __FUNCTION__;
226 return g_memflush(size);
227 }
228
229 void ReloadPlugins(NPBool reloadPages) {
230 DCHECK(IsInitialized()) << __FUNCTION__;
231 return g_reloadplugins(reloadPages);
232 }
233
234 void* GetJavaEnv() {
235 DCHECK(IsInitialized()) << __FUNCTION__;
236 return g_getJavaEnv();
237 }
238
239 void* GetJavaPeer(NPP instance) {
240 DCHECK(IsInitialized()) << __FUNCTION__;
241 return g_getJavaPeer(instance);
242 }
243
244 NPError GetURLNotify(NPP instance, const char* URL, const char* window,
245 void* notifyData) {
246 DCHECK(IsInitialized()) << __FUNCTION__;
247 return g_geturlnotify(instance, URL, window, notifyData);
248 }
249
250 NPError PostURLNotify(NPP instance, const char* URL, const char* window,
251 uint32 len, const char* buf, NPBool file,
252 void* notifyData) {
253 DCHECK(IsInitialized()) << __FUNCTION__;
254 return g_posturlnotify(instance, URL, window, len, buf, file, notifyData);
255 }
256
257 NPError GetValue(NPP instance, NPNVariable variable, void* ret_value) {
258 DCHECK(IsInitialized()) << __FUNCTION__;
259 return g_getvalue(instance, variable, ret_value);
260 }
261
262 NPError SetValue(NPP instance, NPPVariable variable, void* value) {
263 DCHECK(IsInitialized()) << __FUNCTION__;
264 return g_setvalue(instance, variable, value);
265 }
266
267 void InvalidateRect(NPP instance, NPRect* rect) {
268 DCHECK(IsInitialized()) << __FUNCTION__;
269 return g_invalidaterect(instance, rect);
270 }
271
272 void InvalidateRegion(NPP instance, NPRegion region) {
273 DCHECK(IsInitialized()) << __FUNCTION__;
274 return g_invalidateregion(instance, region);
275 }
276
277 void ForceRedraw(NPP instance) {
278 DCHECK(IsInitialized()) << __FUNCTION__;
279 return g_forceredraw(instance);
280 }
281
282 void ReleaseVariantValue(NPVariant* variant) {
283 DCHECK(IsInitialized()) << __FUNCTION__;
284 return g_releasevariantvalue(variant);
285 }
286
287 NPIdentifier GetStringIdentifier(const NPUTF8* name) {
288 DCHECK(IsInitialized()) << __FUNCTION__;
289 return g_getstringidentifier(name);
290 }
291
292 void GetStringIdentifiers(const NPUTF8** names, int32_t nameCount,
293 NPIdentifier* identifiers) {
294 DCHECK(IsInitialized()) << __FUNCTION__;
295 return g_getstringidentifiers(names, nameCount, identifiers);
296 }
297
298 NPIdentifier GetIntIdentifier(int32_t intid) {
299 DCHECK(IsInitialized()) << __FUNCTION__;
300 return g_getintidentifier(intid);
301 }
302
303 int32_t IntFromIdentifier(NPIdentifier identifier) {
304 DCHECK(IsInitialized()) << __FUNCTION__;
305 return g_intfromidentifier(identifier);
306 }
307
308 bool IdentifierIsString(NPIdentifier identifier) {
309 DCHECK(IsInitialized()) << __FUNCTION__;
310 return g_identifierisstring(identifier);
311 }
312
313 NPUTF8* UTF8FromIdentifier(NPIdentifier identifier) {
314 DCHECK(IsInitialized()) << __FUNCTION__;
315 return g_utf8fromidentifier(identifier);
316 }
317
318 NPObject* CreateObject(NPP instance, NPClass* aClass) {
319 DCHECK(IsInitialized()) << __FUNCTION__;
320 return g_createobject(instance, aClass);
321 }
322
323 NPObject* RetainObject(NPObject* obj) {
324 DCHECK(IsInitialized()) << __FUNCTION__;
325 return g_retainobject(obj);
326 }
327
328 void ReleaseObject(NPObject* obj) {
329 DCHECK(IsInitialized()) << __FUNCTION__;
330 return g_releaseobject(obj);
331 }
332
333 bool Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
334 const NPVariant* args, unsigned argCount, NPVariant* result) {
335 DCHECK(IsInitialized()) << __FUNCTION__;
336 return g_invoke(npp, obj, methodName, args, argCount, result);
337 }
338
339 bool InvokeDefault(NPP npp, NPObject* obj, const NPVariant* args,
340 unsigned argCount, NPVariant* result) {
341 DCHECK(IsInitialized()) << __FUNCTION__;
342 return g_invoke_default(npp, obj, args, argCount, result);
343 }
344
345 bool Evaluate(NPP npp, NPObject* obj, NPString* script, NPVariant* result) {
346 DCHECK(IsInitialized()) << __FUNCTION__;
347 return g_evaluate(npp, obj, script, result);
348 }
349
350 bool GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
351 NPVariant* result) {
352 DCHECK(IsInitialized()) << __FUNCTION__;
353 return g_getproperty(npp, obj, propertyName, result);
354 }
355
356 bool SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
357 const NPVariant* value) {
358 DCHECK(IsInitialized()) << __FUNCTION__;
359 return g_setproperty(npp, obj, propertyName, value);
360 }
361
362 bool HasProperty(NPP npp, NPObject* npobj, NPIdentifier propertyName) {
363 DCHECK(IsInitialized()) << __FUNCTION__;
364 return g_hasproperty(npp, npobj, propertyName);
365 }
366
367 bool HasMethod(NPP npp, NPObject* npobj, NPIdentifier methodName) {
368 DCHECK(IsInitialized()) << __FUNCTION__;
369 return g_hasmethod(npp, npobj, methodName);
370 }
371
372 bool RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName) {
373 DCHECK(IsInitialized()) << __FUNCTION__;
374 return g_removeproperty(npp, obj, propertyName);
375 }
376
377 void SetException(NPObject* obj, const NPUTF8* message) {
378 DCHECK(IsInitialized()) << __FUNCTION__;
379 return g_setexception(obj, message);
380 }
381
382 void PushPopupsEnabledState(NPP npp, NPBool enabled) {
383 DCHECK(IsInitialized()) << __FUNCTION__;
384 return g_pushpopupsenabledstate(npp, enabled);
385 }
386
387 void PopPopupsEnabledState(NPP npp) {
388 DCHECK(IsInitialized()) << __FUNCTION__;
389 return g_poppopupsenabledstate(npp);
390 }
391
392 bool Enumerate(NPP npp, NPObject* obj, NPIdentifier** identifier,
393 uint32_t* count) {
394 DCHECK(IsInitialized()) << __FUNCTION__;
395 return g_enumerate(npp, obj, identifier, count);
396 }
397
398 void PluginThreadAsyncCall(NPP instance,
399 void (*func)(void*), // NOLINT
400 void* userData) {
401 DCHECK(IsInitialized()) << __FUNCTION__;
402 return g_pluginthreadasynccall(instance, func, userData);
403 }
404
405 bool Construct(NPP npp, NPObject* obj, const NPVariant* args, uint32_t argCount,
406 NPVariant* result) {
407 DCHECK(IsInitialized()) << __FUNCTION__;
408 return g_construct(npp, obj, args, argCount, result);
409 }
410
411 std::string StringFromIdentifier(NPIdentifier identifier) {
412 std::string ret;
413 NPUTF8* utf8 = UTF8FromIdentifier(identifier);
414 if (utf8) {
415 ret = utf8;
416 MemFree(utf8);
417 }
418 return ret;
419 }
420
421 } // namespace npapi
422
423 void AllocateStringVariant(const std::string& str, NPVariant* var) {
424 DCHECK(var);
425
426 int len = str.length();
427 NPUTF8* buffer = reinterpret_cast<NPUTF8*>(npapi::MemAlloc(len + 1));
428 if (buffer) {
429 buffer[len] = '\0';
430 memcpy(buffer, str.c_str(), len);
431 STRINGN_TO_NPVARIANT(buffer, len, *var);
432 } else {
433 NULL_TO_NPVARIANT(*var);
434 }
435 }
OLDNEW
« no previous file with comments | « ceee/common/np_browser_functions.h ('k') | ceee/ie/common/chrome_frame_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698