1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
22 * Adam Lock <adamlock@eircom.net>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
41 #include "Pluginhostctrl.h"
43 #include "nsPluginHostWnd.h"
46 _OpenURL(NPP npp
, const char *szURL
, const char *szTarget
, void *pNotifyData
, const char *pData
, uint32 len
, NPBool isFile
)
50 return NPERR_INVALID_INSTANCE_ERROR
;
53 void *postData
= NULL
;
54 uint32 postDataLen
= 0;
59 postData
= (void *) pData
;
64 // TODO read the file specified in the postdata param into memory
68 nsPluginHostWnd
*pWnd
= (nsPluginHostWnd
*) npp
->ndata
;
71 // Other window targets
74 CComPtr
<IWebBrowserApp
> cpBrowser
;
75 pWnd
->GetWebBrowserApp(&cpBrowser
);
78 return NPERR_GENERIC_ERROR
;
85 // Test if the input URL has a schema which means it's relative,
86 // otherwise consider it to be relative to the current URL
89 const DWORD cbSchema
= sizeof(szSchema
) / sizeof(szSchema
[0]);
90 DWORD cbSchemaUsed
= 0;
92 memset(szSchema
, 0, cbSchema
);
93 hr
= CoInternetParseUrl(url
.m_str
, PARSE_SCHEMA
, 0,
94 szSchema
, cbSchema
, &cbSchemaUsed
, 0);
96 if (hr
!= S_OK
|| cbSchemaUsed
== 0)
98 // Convert relative URLs to absolute, so that they can be loaded
101 CComBSTR bstrCurrentURL
;
102 cpBrowser
->get_LocationURL(&bstrCurrentURL
);
104 if (bstrCurrentURL
.Length())
107 DWORD cbNewURL
= (url
.Length() + bstrCurrentURL
.Length() + 1) * sizeof(WCHAR
);
108 DWORD cbNewURLUsed
= 0;
109 WCHAR
*pszNewURL
= (WCHAR
*) calloc(cbNewURL
, 1);
110 ATLASSERT(pszNewURL
);
112 CoInternetCombineUrl(
113 bstrCurrentURL
.m_str
,
121 ATLASSERT(cbNewURLUsed
< cbNewURL
);
129 CComVariant
vTarget(szTarget
);
130 CComVariant vPostData
;
131 CComVariant vHeaders
;
133 // Initialise postdata
136 // According to the documentation.
137 // The post data specified by PostData is passed as a SAFEARRAY
138 // structure. The variant should be of type VT_ARRAY and point to
139 // a SAFEARRAY. The SAFEARRAY should be of element type VT_UI1,
140 // dimension one, and have an element count equal to the number of
141 // bytes of post data.
143 SAFEARRAYBOUND saBound
[1];
144 saBound
[0].lLbound
= 0;
145 saBound
[0].cElements
= len
;
146 vPostData
.vt
= VT_ARRAY
| VT_UI1
;
147 vPostData
.parray
= SafeArrayCreate(VT_UI1
, 1, saBound
);
148 SafeArrayLock(vPostData
.parray
);
149 memcpy(vPostData
.parray
->pvData
, postData
, postDataLen
);
150 SafeArrayUnlock(vPostData
.parray
);
153 cpBrowser
->Navigate(url
, &vFlags
, &vTarget
, &vPostData
, &vHeaders
);
154 // TODO listen to navigation & send a URL notify to plugin when completed
155 return NPERR_NO_ERROR
;
159 HRESULT hr
= pWnd
->OpenURLStream(A2CT(szURL
), pNotifyData
, postData
, postDataLen
);
160 return SUCCEEDED(hr
) ? NPERR_NO_ERROR
: NPERR_GENERIC_ERROR
;
165 NPN_GetURL(NPP npp
, const char* relativeURL
, const char* target
)
167 return _OpenURL(npp
, relativeURL
, target
, NULL
, NULL
, 0, FALSE
);
170 ////////////////////////////////////////////////////////////////////////
172 NPN_GetURLNotify(NPP npp
,
173 const char* relativeURL
,
177 if (strncmp("javascript:", relativeURL
, 11) == 0)
178 return NPERR_INVALID_URL
;
180 return _OpenURL(npp
, relativeURL
, target
, notifyData
, NULL
, 0, FALSE
);
184 ////////////////////////////////////////////////////////////////////////
186 NPN_PostURLNotify(NPP npp
,
187 const char *relativeURL
,
194 return _OpenURL(npp
, relativeURL
, target
, notifyData
, buf
, len
, file
);
198 ////////////////////////////////////////////////////////////////////////
201 const char *relativeURL
,
207 return _OpenURL(npp
, relativeURL
, target
, NULL
, buf
, len
, file
);
211 ////////////////////////////////////////////////////////////////////////
213 NPN_NewStream(NPP npp
, NPMIMEType type
, const char* window
, NPStream
* *result
)
217 return NPERR_INVALID_INSTANCE_ERROR
;
220 return NPERR_GENERIC_ERROR
;
224 ////////////////////////////////////////////////////////////////////////
226 NPN_Write(NPP npp
, NPStream
*pstream
, int32 len
, void *buffer
)
230 return NPERR_INVALID_INSTANCE_ERROR
;
233 return NPERR_GENERIC_ERROR
;
237 ////////////////////////////////////////////////////////////////////////
239 NPN_DestroyStream(NPP npp
, NPStream
*pstream
, NPError reason
)
243 return NPERR_INVALID_INSTANCE_ERROR
;
246 return NPERR_GENERIC_ERROR
;
250 ////////////////////////////////////////////////////////////////////////
252 NPN_Status(NPP npp
, const char *message
)
259 nsPluginHostWnd
*pWnd
= (nsPluginHostWnd
*) npp
->ndata
;
262 // Update the status bar in the browser
263 CComPtr
<IWebBrowserApp
> cpBrowser
;
264 pWnd
->GetWebBrowserApp(&cpBrowser
);
268 cpBrowser
->put_StatusText(A2OLE(message
));
273 ////////////////////////////////////////////////////////////////////////
275 NPN_MemAlloc (uint32 size
)
281 ////////////////////////////////////////////////////////////////////////
283 NPN_MemFree (void *ptr
)
292 ////////////////////////////////////////////////////////////////////////
294 NPN_MemFlush(uint32 size
)
300 ////////////////////////////////////////////////////////////////////////
302 NPN_ReloadPlugins(NPBool reloadPages
)
307 ////////////////////////////////////////////////////////////////////////
309 NPN_InvalidateRect(NPP npp
, NPRect
*invalidRect
)
316 nsPluginHostWnd
*pWnd
= (nsPluginHostWnd
*) npp
->ndata
;
324 prc
->left
= invalidRect
->left
;
325 prc
->bottom
= invalidRect
->bottom
;
326 prc
->top
= invalidRect
->top
;
327 prc
->right
= invalidRect
->right
;
329 pWnd
->InvalidateRect(prc
, FALSE
);
333 ////////////////////////////////////////////////////////////////////////
335 NPN_InvalidateRegion(NPP npp
, NPRegion invalidRegion
)
341 nsPluginHostWnd
*pWnd
= (nsPluginHostWnd
*) npp
->ndata
;
344 pWnd
->InvalidateRgn(invalidRegion
, FALSE
);
348 ////////////////////////////////////////////////////////////////////////
350 NPN_ForceRedraw(NPP npp
)
356 nsPluginHostWnd
*pWnd
= (nsPluginHostWnd
*) npp
->ndata
;
358 pWnd
->InvalidateRect(NULL
, FALSE
);
361 ////////////////////////////////////////////////////////////////////////
363 NPN_GetValue(NPP npp
, NPNVariable variable
, void *result
)
367 return NPERR_INVALID_INSTANCE_ERROR
;
372 return NPERR_INVALID_PARAM
;
375 nsPluginHostWnd
*pWnd
= (nsPluginHostWnd
*) npp
->ndata
;
378 CComPtr
<IWebBrowserApp
> cpBrowser
;
379 pWnd
->GetWebBrowserApp(&cpBrowser
);
384 case NPNVnetscapeWindow
:
385 *((HWND
*) result
) = pWnd
->m_hWnd
;
387 case NPNVjavascriptEnabledBool
:
389 *((NPBool
*) result
) = FALSE
;
391 case NPNVasdEnabledBool
:
392 *((NPBool
*) result
) = FALSE
;
394 case NPNVisOfflineBool
:
395 *((NPBool
*) result
) = FALSE
;
398 CComQIPtr
<IWebBrowser2
> cpBrowser2
= cpBrowser
;
401 VARIANT_BOOL bOffline
= VARIANT_FALSE
;
402 cpBrowser2
->get_Offline(&bOffline
);
403 *((NPBool
*) result
) = (bOffline
== VARIANT_TRUE
) ? TRUE
: FALSE
;
408 return NPERR_GENERIC_ERROR
;
410 return NPERR_NO_ERROR
;
414 ////////////////////////////////////////////////////////////////////////
416 NPN_SetValue(NPP npp
, NPPVariable variable
, void *result
)
420 return NPERR_INVALID_INSTANCE_ERROR
;
423 nsPluginHostWnd
*pWnd
= (nsPluginHostWnd
*) npp
->ndata
;
428 case NPPVpluginWindowBool
:
430 pWnd
->SetPluginWindowless((result
== NULL
) ? true : false);
432 return NPERR_NO_ERROR
;
433 case NPPVpluginTransparentBool
:
435 pWnd
->SetPluginTransparent((result
!= NULL
) ? true : false);
437 return NPERR_NO_ERROR
;
440 return NPERR_GENERIC_ERROR
;
444 ////////////////////////////////////////////////////////////////////////
446 NPN_RequestRead(NPStream
*pstream
, NPByteRange
*rangeList
)
448 if (!pstream
|| !rangeList
|| !pstream
->ndata
)
450 return NPERR_INVALID_PARAM
;
453 return NPERR_GENERIC_ERROR
;
456 ////////////////////////////////////////////////////////////////////////
464 ////////////////////////////////////////////////////////////////////////
465 const char * NP_EXPORT
466 NPN_UserAgent(NPP npp
)
468 return "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6";
472 ////////////////////////////////////////////////////////////////////////
473 java_lang_Class
* NP_EXPORT
474 NPN_GetJavaClass(void* handle
)
480 ////////////////////////////////////////////////////////////////////////
482 NPN_GetJavaPeer(NPP npp
)