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.
5 #include "chrome_frame/chrome_frame_npapi_entrypoints.h"
6 #include "chrome_frame/chrome_frame_npapi.h"
10 // Plugin entry points.
12 NPError NPAPI
NP_Initialize(NPNetscapeFuncs
* browser_funcs
);
13 NPError NPAPI
NP_GetEntryPoints(NPPluginFuncs
* plugin_funcs
);
14 void NPAPI
NP_Shutdown();
17 NPError NPAPI
NP_Initialize(NPNetscapeFuncs
* browser_funcs
) {
18 DVLOG(1) << __FUNCTION__
;
20 npapi::InitializeBrowserFunctions(browser_funcs
);
21 return NPERR_NO_ERROR
;
24 NPError NPAPI
NP_GetEntryPoints(NPPluginFuncs
* plugin_funcs
) {
25 plugin_funcs
->version
= (NP_VERSION_MAJOR
<< 8) | NP_VERSION_MINOR
;
26 plugin_funcs
->size
= sizeof(plugin_funcs
);
27 plugin_funcs
->newp
= chrome_frame::NPP_New
;
28 plugin_funcs
->destroy
= chrome_frame::NPP_Destroy
;
29 plugin_funcs
->setwindow
= chrome_frame::NPP_SetWindow
;
30 plugin_funcs
->newstream
= chrome_frame::NPP_NewStream
;
31 plugin_funcs
->destroystream
= chrome_frame::NPP_DestroyStream
;
32 plugin_funcs
->asfile
= NULL
;
33 plugin_funcs
->writeready
= chrome_frame::NPP_WriteReady
;
34 plugin_funcs
->write
= chrome_frame::NPP_Write
;
35 plugin_funcs
->print
= chrome_frame::NPP_Print
;
36 plugin_funcs
->event
= NULL
;
37 plugin_funcs
->urlnotify
= chrome_frame::NPP_URLNotify
;
38 plugin_funcs
->getvalue
= chrome_frame::NPP_GetValue
;
39 plugin_funcs
->setvalue
= chrome_frame::NPP_SetValue
;
40 plugin_funcs
->urlredirectnotify
= chrome_frame::NPP_URLRedirectNotify
;
41 return NPERR_NO_ERROR
;
44 void NPAPI
NP_Shutdown() {
45 DVLOG(1) << __FUNCTION__
;
47 npapi::UninitializeBrowserFunctions();
49 _pAtlModule
->Unlock(); // matches Lock() inside NP_Initialize
51 DLOG_IF(ERROR
, _pAtlModule
->GetLockCount() != 0)
52 << "Being shut down but still have " << _pAtlModule
->GetLockCount()
57 namespace chrome_frame
{
59 NPError
NPP_New(NPMIMEType plugin_type
, NPP instance
, uint16 mode
, int16 argc
,
60 char* argn
[], char* argv
[], NPSavedData
* saved
) {
62 return NPERR_INVALID_INSTANCE_ERROR
;
64 ChromeFrameNPAPI::ChromeFrameNPObject
* chrome_frame_npapi_obj
=
65 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject
*>(
66 npapi::CreateObject(instance
, ChromeFrameNPAPI::PluginClass()));
67 DCHECK(chrome_frame_npapi_obj
!= NULL
);
69 ChromeFrameNPAPI
* plugin_instance
=
70 chrome_frame_npapi_obj
->chrome_frame_plugin_instance
;
71 DCHECK(plugin_instance
!= NULL
);
73 // Note that we MUST set instance->pdata BEFORE calling Initialize. This is
74 // because Initialize can call back into the NPAPI host which will need the
75 // pdata field to be set.
76 chrome_frame_npapi_obj
->chrome_frame_plugin_instance
=
78 instance
->pdata
= chrome_frame_npapi_obj
;
80 bool init
= plugin_instance
->Initialize(plugin_type
, instance
,
81 mode
, argc
, argn
, argv
);
84 return NPERR_NO_ERROR
;
87 NPError
NPP_Destroy(NPP instance
, NPSavedData
** save
) {
88 // Takes ownership and releases the object at the end of scope.
89 ScopedNpObject
<ChromeFrameNPAPI::ChromeFrameNPObject
> chrome_frame_npapi_obj(
90 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject
*>(
93 if (chrome_frame_npapi_obj
.get()) {
94 ChromeFrameNPAPI
* plugin_instance
=
95 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
97 plugin_instance
->Uninitialize();
98 instance
->pdata
= NULL
;
101 return NPERR_NO_ERROR
;
104 NPError
NPP_SetWindow(NPP instance
, NPWindow
* window_info
) {
105 if (window_info
== NULL
) {
107 return NPERR_GENERIC_ERROR
;
110 ChromeFrameNPAPI
* plugin_instance
=
111 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
113 if (plugin_instance
== NULL
) {
114 return NPERR_INVALID_INSTANCE_ERROR
;
117 plugin_instance
->SetWindow(window_info
);
118 return NPERR_NO_ERROR
;
121 NPError
NPP_NewStream(NPP instance
, NPMIMEType type
, NPStream
* stream
,
122 NPBool seekable
, uint16
* stream_type
) {
123 ChromeFrameNPAPI
* plugin_instance
=
124 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
125 if (plugin_instance
== NULL
) {
126 return NPERR_INVALID_INSTANCE_ERROR
;
129 return plugin_instance
->NewStream(type
, stream
, seekable
, stream_type
);
132 NPError
NPP_DestroyStream(NPP instance
, NPStream
* stream
, NPReason reason
) {
133 ChromeFrameNPAPI
* plugin_instance
=
134 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
135 if (plugin_instance
== NULL
) {
136 return NPERR_INVALID_INSTANCE_ERROR
;
139 return plugin_instance
->DestroyStream(stream
, reason
);
142 NPError
NPP_GetValue(NPP instance
, NPPVariable variable
, void* value
) {
143 if (variable
== NPPVpluginScriptableNPObject
) {
144 void** plugin
= reinterpret_cast<void**>(value
);
145 ChromeFrameNPAPI::ChromeFrameNPObject
* chrome_frame_npapi_obj
=
146 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject
*>(
148 // Return value is expected to be retained
149 npapi::RetainObject(reinterpret_cast<NPObject
*>(chrome_frame_npapi_obj
));
150 *plugin
= chrome_frame_npapi_obj
;
151 return NPERR_NO_ERROR
;
153 return NPERR_GENERIC_ERROR
;
156 NPError
NPP_SetValue(NPP instance
, NPNVariable variable
, void* value
) {
157 return NPERR_GENERIC_ERROR
;
160 int32
NPP_WriteReady(NPP instance
, NPStream
* stream
) {
161 static const int kMaxBytesForPluginConsumption
= 0x7FFFFFFF;
163 ChromeFrameNPAPI
* plugin_instance
=
164 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
166 if (plugin_instance
== NULL
) {
167 return kMaxBytesForPluginConsumption
;
170 return plugin_instance
->WriteReady(stream
);
173 int32
NPP_Write(NPP instance
, NPStream
* stream
, int32 offset
, int32 len
,
175 ChromeFrameNPAPI
* plugin_instance
=
176 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
178 if (plugin_instance
== NULL
)
181 return plugin_instance
->Write(stream
, offset
, len
, buffer
);
184 void NPP_URLNotify(NPP instance
, const char* url
, NPReason reason
,
186 ChromeFrameNPAPI
* plugin_instance
=
187 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
188 if (plugin_instance
) {
189 plugin_instance
->UrlNotify(url
, reason
, notifyData
);
193 void NPP_Print(NPP instance
, NPPrint
* print_info
) {
194 ChromeFrameNPAPI
* plugin_instance
=
195 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
197 if (plugin_instance
== NULL
) {
198 NOTREACHED() << "Failed to find plugin instance";
202 plugin_instance
->Print(print_info
);
205 void NPP_URLRedirectNotify(NPP instance
, const char* url
, int status
,
207 ChromeFrameNPAPI
* plugin_instance
=
208 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance
);
210 if (plugin_instance
== NULL
) {
211 NOTREACHED() << "Failed to find plugin instance";
212 npapi::URLRedirectResponse(instance
, notify_data
, false);
215 plugin_instance
->URLRedirectNotify(url
, status
, notify_data
);
218 } // namespace chrome_frame