2000-07-22 01:34:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
1998-07-28 02:07:25 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-07-28 02:07:25 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-07-28 02:07:25 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-07-28 02:07:25 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-07-28 02:07:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsPluginHostImpl.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "prio.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "ns4xPlugin.h"
|
1998-08-01 05:46:47 +00:00
|
|
|
#include "nsPluginInstancePeer.h"
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
#include "nsIPluginStreamListener.h"
|
a=brendan,av
r=av
bug=50811
This bug fix was suggested by Stanley Ho <stanley.ho@eng.sun.com>.
Stanley proposed we overload the meaning of the nsIPluginStreamListener
argument to nsIPluginManager::{GetURL,PostURL}() so that it also may
implement an interface for reading headers. Thus, the browser could QI
the plugin's nsIPluginStreamListener instance to this headers reading
interface and send the plugin the headers from the response.
I have implemented Stanley's above proposal. I have defined a new
interface, nsIHTTPHeaderListener.idl with one method:
/**
* Called for each HTTP Response header.
* NOTE: You must copy the values of the params.
*/
void newResponseHeader(in string headerName, in string headerValue);
To affect this fix, I have added a new private method
nsPluginStreamListenerPeer::
ReadHeadersFromChannelAndPostToListener(nsIHTTPChannel *httpChannel,
nsIHTTPHeaderListener *listener)
Then, modified nsPluginStreamListenerPeer::OnDataAvailable() to call
this method BEFORE reading the content data. However, this fix makes
two important assumptions I would like to check out:
* Assumption
* By the time nsPluginStreamListenerPeer::OnDataAvailable() gets
* called, all the headers have been read.
* Assumption:
* The return value from nsIHTTPHeader->{GetFieldName,GetValue}()
* must be freed.
The following files are included in this fix:
A modules/plugin/public/nsIHTTPHeaderListener.idl
A modules/plugin/public/makefile.win
A modules/plugin/public/Makefile.in
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
2000-09-13 07:09:38 +00:00
|
|
|
#include "nsIHTTPHeaderListener.h"
|
|
|
|
#include "nsIHTTPHeader.h"
|
2000-10-31 20:25:19 +00:00
|
|
|
#include "nsIHTTPProtocolHandler.h"
|
1998-08-05 04:21:36 +00:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIInputStream.h"
|
1999-03-11 22:48:58 +00:00
|
|
|
#include "nsIOutputStream.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIURL.h"
|
1999-10-09 01:18:02 +00:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsIPref.h"
|
2000-10-05 07:58:51 +00:00
|
|
|
#include "nsIProxyAutoConfig.h"
|
2000-08-19 05:44:34 +00:00
|
|
|
#include "nsIFile.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
|
2000-08-22 07:03:33 +00:00
|
|
|
#include "nsIInputStream.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-25 01:41:26 +00:00
|
|
|
#include "nsIChannel.h"
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
#include "nsIHTTPChannel.h"
|
|
|
|
#include "nsIFileStream.h" // for nsIRandomAccessStore
|
1999-06-25 00:03:22 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1999-07-07 08:08:40 +00:00
|
|
|
#include "nsIProgressEventSink.h"
|
1999-07-09 21:18:47 +00:00
|
|
|
#include "nsIDocument.h"
|
2000-10-27 22:43:51 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
// Friggin' X11 has to "#define None". Lame!
|
|
|
|
#ifdef None
|
|
|
|
#undef None
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nsIRegistry.h"
|
|
|
|
#include "nsEnumeratorUtils.h"
|
|
|
|
|
2000-06-20 21:04:52 +00:00
|
|
|
// for the dialog
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsINetSupportDialogService.h"
|
|
|
|
#include "nsIPrompt.h"
|
2000-07-20 22:53:32 +00:00
|
|
|
#include "nsHashtable.h"
|
|
|
|
|
2000-06-20 21:04:52 +00:00
|
|
|
#include "nsILocale.h"
|
2000-07-13 02:44:14 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2000-06-20 21:04:52 +00:00
|
|
|
|
1998-10-28 21:16:00 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-03-20 23:11:25 +00:00
|
|
|
#include "nsICookieStorage.h"
|
1999-10-21 21:09:21 +00:00
|
|
|
#include "nsICookieService.h"
|
1999-04-20 19:29:28 +00:00
|
|
|
#include "nsIDOMPlugin.h"
|
|
|
|
#include "nsIDOMMimeType.h"
|
1998-09-15 03:48:58 +00:00
|
|
|
#include "prprf.h"
|
1998-12-11 05:17:50 +00:00
|
|
|
|
2000-02-28 15:00:30 +00:00
|
|
|
#if defined(XP_PC) && !defined(XP_OS2)
|
1998-07-28 02:07:25 +00:00
|
|
|
#include "windows.h"
|
1998-09-15 03:48:58 +00:00
|
|
|
#include "winbase.h"
|
1998-07-28 02:07:25 +00:00
|
|
|
#endif
|
|
|
|
|
1999-03-20 23:11:25 +00:00
|
|
|
#include "nsSpecialSystemDirectory.h"
|
1999-02-20 02:24:15 +00:00
|
|
|
#include "nsFileSpec.h"
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
#include "nsPluginDocLoaderFactory.h"
|
2000-07-07 00:10:54 +00:00
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
|
|
|
|
2000-09-22 06:31:29 +00:00
|
|
|
#include "nsIMIMEService.h"
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
|
2000-07-20 01:16:52 +00:00
|
|
|
#ifdef XP_UNIX
|
2000-11-30 22:01:45 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2000-07-20 01:16:52 +00:00
|
|
|
#include <gdk/gdkx.h> // for GDK_DISPLAY()
|
2000-11-30 22:01:45 +00:00
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
#include <qwindowdefs.h> // for qt_xdisplay()
|
|
|
|
#endif
|
2000-07-20 01:16:52 +00:00
|
|
|
#endif
|
|
|
|
|
2001-02-13 21:48:26 +00:00
|
|
|
#if defined(XP_MAC) && TARGET_CARBON
|
|
|
|
#include "nsIClassicPluginFactory.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_MAC) && TARGET_CARBON
|
|
|
|
#include "nsIClassicPluginFactory.h"
|
|
|
|
#endif
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
// We need this hackery so that we can dynamically register doc
|
|
|
|
// loaders for the 4.x plugins that we discover.
|
2000-07-09 22:26:44 +00:00
|
|
|
#if defined(XP_PC)
|
2000-07-22 01:34:13 +00:00
|
|
|
#define PLUGIN_DLL "gkplugin.dll"
|
2000-07-09 22:26:44 +00:00
|
|
|
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
2000-07-22 01:34:13 +00:00
|
|
|
#define PLUGIN_DLL "libgkplugin" MOZ_DLL_SUFFIX
|
2000-07-09 22:26:44 +00:00
|
|
|
#elif defined(XP_MAC)
|
2000-07-22 01:34:13 +00:00
|
|
|
#define PLUGIN_DLL "PLUGIN_DLL"
|
2000-07-09 22:26:44 +00:00
|
|
|
#endif
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
#define REL_PLUGIN_DLL "rel:" PLUGIN_DLL
|
2000-07-09 22:26:44 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
|
1998-08-05 04:21:36 +00:00
|
|
|
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
|
1999-01-25 08:05:00 +00:00
|
|
|
static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
|
1999-03-03 04:10:54 +00:00
|
|
|
static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);
|
2000-05-26 22:14:39 +00:00
|
|
|
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
|
1999-10-09 01:18:02 +00:00
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
1999-10-21 21:09:21 +00:00
|
|
|
static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
1998-08-05 04:21:36 +00:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
1999-06-18 17:34:08 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
2000-10-31 20:25:19 +00:00
|
|
|
static NS_DEFINE_CID(kHTTPHandlerCID, NS_IHTTPHANDLER_CID);
|
1999-06-18 17:34:08 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID);
|
1999-03-11 22:48:58 +00:00
|
|
|
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
1998-08-01 05:46:47 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
|
|
|
|
|
2000-06-20 21:04:52 +00:00
|
|
|
// for the dialog
|
|
|
|
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
|
|
|
static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
|
|
|
|
2000-07-07 00:10:54 +00:00
|
|
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
|
|
|
|
2000-06-20 21:04:52 +00:00
|
|
|
#define PLUGIN_PROPERTIES_URL "chrome://global/locale/downloadProgress.properties"
|
2001-02-07 01:13:01 +00:00
|
|
|
|
|
|
|
// #defines for reading prefs and extra search plugin paths from windows registry
|
|
|
|
#define _MAXKEYVALUE_ 8196
|
|
|
|
#define _NS_PREF_COMMON_PLUGIN_REG_KEY_ "browser.plugins.registry_plugins_folder_key_location"
|
|
|
|
#define _NS_COMMON_PLUGIN_KEY_NAME_ "Plugins Folders"
|
|
|
|
|
2001-02-14 23:03:47 +00:00
|
|
|
// #defines for plugin cache and prefs
|
|
|
|
#define NS_PREF_MAX_NUM_CACHED_PLUGINS "browser.plugins.max_num_cached_plugins"
|
|
|
|
#define DEFAULT_NUMBER_OF_STOPPED_PLUGINS 10
|
|
|
|
|
2000-07-20 22:53:32 +00:00
|
|
|
void DisplayNoDefaultPluginDialog(const char *mimeType);
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Used in DisplayNoDefaultPlugindialog to prevent showing the dialog twice
|
|
|
|
* for the same mimetype.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static nsHashtable *mimeTypesSeen = nsnull;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* placeholder value for mimeTypesSeen hashtable
|
2000-06-20 21:04:52 +00:00
|
|
|
|
2000-07-20 22:53:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const char *hashValue = "value";
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Default number of entries in the mimeTypesSeen hashtable
|
|
|
|
|
|
|
|
*/
|
|
|
|
#define NS_MIME_TYPES_HASH_NUM (20)
|
|
|
|
|
|
|
|
|
|
|
|
void DisplayNoDefaultPluginDialog(const char *mimeType)
|
2000-06-20 21:04:52 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-07-20 22:53:32 +00:00
|
|
|
|
|
|
|
if (nsnull == mimeTypesSeen) {
|
|
|
|
mimeTypesSeen = new nsHashtable(NS_MIME_TYPES_HASH_NUM);
|
|
|
|
}
|
2000-08-18 21:53:03 +00:00
|
|
|
if ((mimeTypesSeen != nsnull) && (mimeType != nsnull)) {
|
2000-08-10 06:19:37 +00:00
|
|
|
nsCStringKey key(mimeType);
|
2000-07-20 22:53:32 +00:00
|
|
|
// if we've seen this mimetype before
|
|
|
|
if (mimeTypesSeen->Get(&key)) {
|
|
|
|
// don't display the dialog
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mimeTypesSeen->Put(&key, (void *) hashValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
|
2000-06-20 21:04:52 +00:00
|
|
|
nsCOMPtr<nsIPrompt> prompt(do_GetService(kNetSupportDialogCID));
|
|
|
|
nsCOMPtr<nsIIOService> io(do_GetService(kIOServiceCID));
|
|
|
|
nsCOMPtr<nsIStringBundleService> strings(do_GetService(kStringBundleServiceCID));
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
char *spec = nsnull;
|
|
|
|
nsILocale* locale = nsnull;
|
|
|
|
PRInt32 buttonPressed;
|
2000-07-20 22:53:32 +00:00
|
|
|
PRBool displayDialogPrefValue = PR_FALSE, checkboxState = PR_FALSE;
|
2000-06-20 21:04:52 +00:00
|
|
|
|
2000-07-20 22:53:32 +00:00
|
|
|
if (!prefs || !prompt || !io || !strings) {
|
2000-06-20 21:04:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-20 22:53:32 +00:00
|
|
|
rv = prefs->GetBoolPref("plugin.display_plugin_downloader_dialog",
|
|
|
|
&displayDialogPrefValue);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// if the pref is false, don't display the dialog
|
|
|
|
if (!displayDialogPrefValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-20 21:04:52 +00:00
|
|
|
// Taken from mozilla\extensions\wallet\src\wallet.cpp
|
|
|
|
// WalletLocalize().
|
|
|
|
|
|
|
|
rv = io->NewURI(PLUGIN_PROPERTIES_URL, nsnull, getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = uri->GetSpec(&spec);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCRT::free(spec);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = strings->CreateBundle(spec, locale, getter_AddRefs(bundle));
|
|
|
|
nsCRT::free(spec);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar *titleUni = nsnull;
|
|
|
|
PRUnichar *messageUni = nsnull;
|
2000-07-20 22:53:32 +00:00
|
|
|
PRUnichar *checkboxMessageUni = nsnull;
|
2000-09-13 02:48:08 +00:00
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("noDefaultPluginTitle").get(),
|
2000-06-20 21:04:52 +00:00
|
|
|
&titleUni);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto EXIT_DNDPD;
|
|
|
|
}
|
2000-09-13 02:48:08 +00:00
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("noDefaultPluginMessage").get(),
|
2000-06-20 21:04:52 +00:00
|
|
|
&messageUni);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto EXIT_DNDPD;
|
|
|
|
}
|
2000-09-13 02:48:08 +00:00
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("noDefaultPluginCheckboxMessage").get(),
|
2000-07-20 22:53:32 +00:00
|
|
|
&checkboxMessageUni);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto EXIT_DNDPD;
|
|
|
|
}
|
2000-06-20 21:04:52 +00:00
|
|
|
|
|
|
|
rv = prompt->UniversalDialog(
|
|
|
|
nsnull, /* title message */
|
|
|
|
titleUni, /* title text in top line of window */
|
|
|
|
messageUni, /* this is the main message */
|
2000-07-20 22:53:32 +00:00
|
|
|
checkboxMessageUni, /* This is the checkbox message */
|
2000-06-20 21:04:52 +00:00
|
|
|
nsnull, /* first button text, becomes OK by default */
|
|
|
|
nsnull, /* second button text, becomes CANCEL by default */
|
|
|
|
nsnull, /* third button text */
|
|
|
|
nsnull, /* fourth button text */
|
|
|
|
nsnull, /* first edit field label */
|
|
|
|
nsnull, /* second edit field label */
|
|
|
|
nsnull, /* first edit field initial and final value */
|
|
|
|
nsnull, /* second edit field initial and final value */
|
|
|
|
nsnull, /* icon: question mark by default */
|
2000-07-20 22:53:32 +00:00
|
|
|
&checkboxState, /* initial and final value of checkbox */
|
2000-06-20 21:04:52 +00:00
|
|
|
1, /* number of buttons */
|
|
|
|
0, /* number of edit fields */
|
|
|
|
0, /* is first edit field a password field */
|
|
|
|
|
|
|
|
&buttonPressed);
|
2000-07-20 22:53:32 +00:00
|
|
|
|
|
|
|
// if the user checked the checkbox, make it so the dialog doesn't
|
|
|
|
// display again.
|
|
|
|
if (checkboxState) {
|
|
|
|
prefs->SetBoolPref("plugin.display_plugin_downloader_dialog",
|
|
|
|
!checkboxState);
|
|
|
|
}
|
2000-06-20 21:04:52 +00:00
|
|
|
EXIT_DNDPD:
|
|
|
|
nsMemory::Free((void *)titleUni);
|
|
|
|
nsMemory::Free((void *)messageUni);
|
2000-07-20 22:53:32 +00:00
|
|
|
nsMemory::Free((void *)checkboxMessageUni);
|
2000-06-20 21:04:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
nsActivePlugin::nsActivePlugin(nsIPluginInstance* aInstance, char * url, PRBool aDefaultPlugin)
|
2000-06-13 23:23:13 +00:00
|
|
|
{
|
|
|
|
mNext = nsnull;
|
|
|
|
mPeer = nsnull;
|
|
|
|
|
|
|
|
mURL = PL_strdup(url);
|
|
|
|
mInstance = aInstance;
|
|
|
|
if(aInstance != nsnull)
|
|
|
|
{
|
|
|
|
aInstance->GetPeer(&mPeer);
|
|
|
|
NS_ADDREF(aInstance);
|
|
|
|
}
|
2001-02-02 23:48:17 +00:00
|
|
|
mDefaultPlugin = aDefaultPlugin;
|
2000-06-13 23:23:13 +00:00
|
|
|
mStopped = PR_FALSE;
|
2000-06-15 01:07:27 +00:00
|
|
|
mllStopTime = LL_ZERO;
|
2000-06-13 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsActivePlugin::~nsActivePlugin()
|
|
|
|
{
|
|
|
|
if(mInstance != nsnull)
|
|
|
|
{
|
|
|
|
mInstance->Destroy();
|
|
|
|
NS_RELEASE(mInstance);
|
|
|
|
NS_RELEASE(mPeer);
|
|
|
|
}
|
|
|
|
PL_strfree(mURL);
|
|
|
|
}
|
|
|
|
|
2000-06-15 01:07:27 +00:00
|
|
|
void nsActivePlugin::setStopped(PRBool stopped)
|
|
|
|
{
|
|
|
|
mStopped = stopped;
|
|
|
|
if(mStopped)
|
|
|
|
mllStopTime = PR_Now();
|
|
|
|
else
|
|
|
|
mllStopTime = LL_ZERO;
|
|
|
|
}
|
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
nsActivePluginList::nsActivePluginList()
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
mFirst = nsnull;
|
|
|
|
mLast = nsnull;
|
|
|
|
mCount = 0;
|
2000-06-13 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsActivePluginList::~nsActivePluginList()
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
if(mFirst == nsnull)
|
2000-06-13 23:23:13 +00:00
|
|
|
return;
|
|
|
|
shut();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsActivePluginList::shut()
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
if(mFirst == nsnull)
|
2000-06-13 23:23:13 +00:00
|
|
|
return;
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
for(nsActivePlugin * plugin = mFirst; plugin != nsnull;)
|
2000-06-13 23:23:13 +00:00
|
|
|
{
|
|
|
|
nsActivePlugin * next = plugin->mNext;
|
|
|
|
remove(plugin);
|
|
|
|
plugin = next;
|
|
|
|
}
|
2001-02-02 23:48:17 +00:00
|
|
|
mFirst = nsnull;
|
|
|
|
mLast = nsnull;
|
2000-06-13 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsActivePluginList::add(nsActivePlugin * plugin)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
if (mFirst == nsnull)
|
2000-06-13 23:23:13 +00:00
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
mFirst = plugin;
|
|
|
|
mLast = plugin;
|
|
|
|
mFirst->mNext = nsnull;
|
2000-06-13 23:23:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
mLast->mNext = plugin;
|
|
|
|
mLast = plugin;
|
2000-06-13 23:23:13 +00:00
|
|
|
}
|
2001-02-02 23:48:17 +00:00
|
|
|
mLast->mNext = nsnull;
|
|
|
|
mCount++;
|
|
|
|
return mCount;
|
2000-06-13 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsActivePluginList::remove(nsActivePlugin * plugin)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
if(mFirst == nsnull)
|
2000-06-13 23:23:13 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsActivePlugin * prev = nsnull;
|
2001-02-02 23:48:17 +00:00
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull; p = p->mNext)
|
2000-06-13 23:23:13 +00:00
|
|
|
{
|
|
|
|
if(p == plugin)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
if(p == mFirst)
|
|
|
|
mFirst = p->mNext;
|
2000-06-13 23:23:13 +00:00
|
|
|
else
|
|
|
|
prev->mNext = p->mNext;
|
|
|
|
|
|
|
|
if((prev != nsnull) && (prev->mNext == nsnull))
|
2001-02-02 23:48:17 +00:00
|
|
|
mLast = prev;
|
2000-06-13 23:23:13 +00:00
|
|
|
|
|
|
|
delete p;
|
2001-02-02 23:48:17 +00:00
|
|
|
mCount--;
|
2000-06-13 23:23:13 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
prev = p;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
void nsActivePluginList::stopRunning()
|
|
|
|
{
|
|
|
|
if(mFirst == nsnull)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull; p = p->mNext)
|
|
|
|
{
|
|
|
|
if(!p->mStopped && p->mInstance)
|
|
|
|
{
|
|
|
|
p->mInstance->SetWindow(nsnull);
|
|
|
|
p->mInstance->Stop();
|
|
|
|
p->setStopped(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsActivePluginList::removeAllStopped()
|
|
|
|
{
|
|
|
|
if(mFirst == nsnull)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsActivePlugin * prev = nsnull;
|
|
|
|
nsActivePlugin * next = nsnull;
|
|
|
|
|
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull;)
|
|
|
|
{
|
|
|
|
next = p->mNext;
|
|
|
|
|
|
|
|
if(p->mStopped)
|
|
|
|
{
|
|
|
|
if(p == mFirst)
|
|
|
|
mFirst = next;
|
|
|
|
else
|
|
|
|
prev->mNext = next;
|
|
|
|
|
|
|
|
if(p == mLast)
|
|
|
|
mLast = prev;
|
|
|
|
|
|
|
|
delete p;
|
|
|
|
mCount--;
|
|
|
|
p = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prev = p;
|
|
|
|
p = next;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
nsActivePlugin * nsActivePluginList::find(nsIPluginInstance* instance)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull; p = p->mNext)
|
2000-06-13 23:23:13 +00:00
|
|
|
{
|
|
|
|
if(p->mInstance == instance)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
nsActivePlugin * nsActivePluginList::find(char * mimetype)
|
|
|
|
{
|
|
|
|
PRBool defaultplugin = (PL_strcmp(mimetype, "*") == 0);
|
|
|
|
|
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull; p = p->mNext)
|
|
|
|
{
|
|
|
|
// give it some special treatment for the default plugin first
|
|
|
|
// because we cannot tell the default plugin by asking peer for a mime type
|
|
|
|
if(defaultplugin && p->mDefaultPlugin)
|
|
|
|
return p;
|
|
|
|
|
|
|
|
if(!p->mPeer)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsMIMEType mt;
|
|
|
|
|
|
|
|
nsresult res = p->mPeer->GetMIMEType(&mt);
|
|
|
|
|
|
|
|
if(NS_FAILED(res))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(PL_strcasecmp(mt, mimetype) == 0)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
nsActivePlugin * nsActivePluginList::findStopped(char * url)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull; p = p->mNext)
|
2000-06-13 23:23:13 +00:00
|
|
|
{
|
|
|
|
if(!PL_strcmp(url, p->mURL) && p->mStopped)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 nsActivePluginList::getStoppedCount()
|
|
|
|
{
|
|
|
|
PRUint32 stoppedCount = 0;
|
2001-02-02 23:48:17 +00:00
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull; p = p->mNext)
|
2000-06-13 23:23:13 +00:00
|
|
|
{
|
|
|
|
if(p->mStopped)
|
|
|
|
stoppedCount++;
|
|
|
|
}
|
|
|
|
return stoppedCount;
|
|
|
|
}
|
|
|
|
|
2000-06-15 01:07:27 +00:00
|
|
|
nsActivePlugin * nsActivePluginList::findOldestStopped()
|
|
|
|
{
|
|
|
|
nsActivePlugin * res = nsnull;
|
|
|
|
PRInt64 llTime = LL_MAXINT;
|
2001-02-02 23:48:17 +00:00
|
|
|
for(nsActivePlugin * p = mFirst; p != nsnull; p = p->mNext)
|
2000-06-15 01:07:27 +00:00
|
|
|
{
|
|
|
|
if(!p->mStopped)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(LL_CMP(p->mllStopTime, <, llTime))
|
|
|
|
{
|
|
|
|
llTime = p->mllStopTime;
|
|
|
|
res = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
nsUnloadedLibrary::nsUnloadedLibrary(PRLibrary * aLibrary)
|
|
|
|
{
|
|
|
|
mLibrary = aLibrary;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsUnloadedLibrary::~nsUnloadedLibrary()
|
|
|
|
{
|
|
|
|
if(mLibrary)
|
|
|
|
PR_UnloadLibrary(mLibrary);
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsPluginTag::nsPluginTag()
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
mNext = nsnull;
|
|
|
|
mName = nsnull;
|
|
|
|
mDescription = nsnull;
|
|
|
|
mVariants = 0;
|
|
|
|
mMimeTypeArray = nsnull;
|
|
|
|
mMimeDescriptionArray = nsnull;
|
|
|
|
mExtensionsArray = nsnull;
|
|
|
|
mLibrary = nsnull;
|
|
|
|
mCanUnloadLibrary = PR_TRUE;
|
|
|
|
mEntryPoint = nsnull;
|
|
|
|
mFlags = NS_PLUGIN_FLAG_ENABLED;
|
2000-06-13 23:23:13 +00:00
|
|
|
mFileName = nsnull;
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
inline char* new_str(const char* str)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
1999-10-02 00:41:03 +00:00
|
|
|
if(str == nsnull)
|
|
|
|
return nsnull;
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
char* result = new char[strlen(str) + 1];
|
|
|
|
if (result != nsnull)
|
|
|
|
return strcpy(result, str);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
mNext = nsnull;
|
|
|
|
mName = new_str(aPluginTag->mName);
|
|
|
|
mDescription = new_str(aPluginTag->mDescription);
|
|
|
|
mVariants = aPluginTag->mVariants;
|
2000-04-13 22:34:49 +00:00
|
|
|
|
|
|
|
mMimeTypeArray = nsnull;
|
|
|
|
mMimeDescriptionArray = nsnull;
|
|
|
|
mExtensionsArray = nsnull;
|
|
|
|
|
|
|
|
if(aPluginTag->mMimeTypeArray != nsnull)
|
|
|
|
{
|
|
|
|
mMimeTypeArray = new char*[mVariants];
|
2001-02-02 23:48:17 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
mMimeTypeArray[i] = new_str(aPluginTag->mMimeTypeArray[i]);
|
2000-04-13 22:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(aPluginTag->mMimeDescriptionArray != nsnull)
|
|
|
|
{
|
|
|
|
mMimeDescriptionArray = new char*[mVariants];
|
2001-02-02 23:48:17 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
mMimeDescriptionArray[i] = new_str(aPluginTag->mMimeDescriptionArray[i]);
|
2000-04-13 22:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(aPluginTag->mExtensionsArray != nsnull)
|
|
|
|
{
|
|
|
|
mExtensionsArray = new char*[mVariants];
|
2001-02-02 23:48:17 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
mExtensionsArray[i] = new_str(aPluginTag->mExtensionsArray[i]);
|
1999-04-20 19:29:28 +00:00
|
|
|
}
|
2000-04-13 22:34:49 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
mLibrary = nsnull;
|
|
|
|
mCanUnloadLibrary = PR_TRUE;
|
|
|
|
mEntryPoint = nsnull;
|
|
|
|
mFlags = NS_PLUGIN_FLAG_ENABLED;
|
2000-03-23 00:45:49 +00:00
|
|
|
mFileName = new_str(aPluginTag->mFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
mNext = nsnull;
|
2000-03-23 00:45:49 +00:00
|
|
|
mName = new_str(aPluginInfo->fName);
|
2001-02-02 23:48:17 +00:00
|
|
|
mDescription = new_str(aPluginInfo->fDescription);
|
|
|
|
mVariants = aPluginInfo->fVariantCount;
|
2000-03-23 00:45:49 +00:00
|
|
|
|
2000-04-13 22:34:49 +00:00
|
|
|
mMimeTypeArray = nsnull;
|
|
|
|
mMimeDescriptionArray = nsnull;
|
|
|
|
mExtensionsArray = nsnull;
|
|
|
|
|
2000-03-29 23:58:42 +00:00
|
|
|
if(aPluginInfo->fMimeTypeArray != nsnull)
|
2000-03-23 00:45:49 +00:00
|
|
|
{
|
2000-04-13 22:34:49 +00:00
|
|
|
mMimeTypeArray = new char*[mVariants];
|
2001-02-02 23:48:17 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
mMimeTypeArray[i] = new_str(aPluginInfo->fMimeTypeArray[i]);
|
2000-03-29 23:58:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(aPluginInfo->fMimeDescriptionArray != nsnull)
|
|
|
|
{
|
2000-04-13 22:34:49 +00:00
|
|
|
mMimeDescriptionArray = new char*[mVariants];
|
2001-02-02 23:48:17 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
mMimeDescriptionArray[i] = new_str(aPluginInfo->fMimeDescriptionArray[i]);
|
2000-03-29 23:58:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(aPluginInfo->fExtensionArray != nsnull)
|
|
|
|
{
|
2000-04-13 22:34:49 +00:00
|
|
|
mExtensionsArray = new char*[mVariants];
|
2001-02-02 23:48:17 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
mExtensionsArray[i] = new_str(aPluginInfo->fExtensionArray[i]);
|
2000-03-23 00:45:49 +00:00
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
mFileName = new_str(aPluginInfo->fFileName);
|
2000-03-23 00:45:49 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
mLibrary = nsnull;
|
|
|
|
mCanUnloadLibrary = PR_TRUE;
|
|
|
|
mEntryPoint = nsnull;
|
|
|
|
mFlags = NS_PLUGIN_FLAG_ENABLED;
|
1999-04-20 19:29:28 +00:00
|
|
|
}
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
|
|
|
|
nsPluginTag::nsPluginTag(const char* aName,
|
|
|
|
const char* aDescription,
|
|
|
|
const char* aFileName,
|
|
|
|
const char* const* aMimeTypes,
|
|
|
|
const char* const* aMimeDescriptions,
|
|
|
|
const char* const* aExtensions,
|
|
|
|
PRInt32 aVariants)
|
|
|
|
: mNext(nsnull),
|
|
|
|
mVariants(aVariants),
|
|
|
|
mMimeTypeArray(nsnull),
|
|
|
|
mMimeDescriptionArray(nsnull),
|
|
|
|
mExtensionsArray(nsnull),
|
|
|
|
mLibrary(nsnull),
|
2001-02-02 23:48:17 +00:00
|
|
|
mCanUnloadLibrary(PR_TRUE),
|
2000-07-22 01:34:13 +00:00
|
|
|
mEntryPoint(nsnull),
|
|
|
|
mFlags(0)
|
|
|
|
{
|
|
|
|
mName = new_str(aName);
|
|
|
|
mDescription = new_str(aDescription);
|
|
|
|
mFileName = new_str(aFileName);
|
|
|
|
|
|
|
|
if (mVariants) {
|
|
|
|
mMimeTypeArray = new char*[mVariants];
|
|
|
|
mMimeDescriptionArray = new char*[mVariants];
|
|
|
|
mExtensionsArray = new char*[mVariants];
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aVariants; ++i) {
|
|
|
|
mMimeTypeArray[i] = new_str(aMimeTypes[i]);
|
|
|
|
mMimeDescriptionArray[i] = new_str(aMimeDescriptions[i]);
|
|
|
|
mExtensionsArray[i] = new_str(aExtensions[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsPluginTag::~nsPluginTag()
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
1998-09-15 03:48:58 +00:00
|
|
|
NS_IF_RELEASE(mEntryPoint);
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
if (nsnull != mName) {
|
|
|
|
delete[] (mName);
|
1998-07-28 02:07:25 +00:00
|
|
|
mName = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
if (nsnull != mDescription) {
|
|
|
|
delete[] (mDescription);
|
1998-07-28 02:07:25 +00:00
|
|
|
mDescription = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
if (nsnull != mMimeTypeArray) {
|
2000-05-14 09:18:43 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
delete[] mMimeTypeArray[i];
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
delete[] (mMimeTypeArray);
|
1998-07-28 02:07:25 +00:00
|
|
|
mMimeTypeArray = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
if (nsnull != mMimeDescriptionArray) {
|
2000-05-14 09:18:43 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
delete[] mMimeDescriptionArray[i];
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
delete[] (mMimeDescriptionArray);
|
1998-07-28 02:07:25 +00:00
|
|
|
mMimeDescriptionArray = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
if (nsnull != mExtensionsArray) {
|
2000-05-14 09:18:43 +00:00
|
|
|
for (int i = 0; i < mVariants; i++)
|
|
|
|
delete[] mExtensionsArray[i];
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
delete[] (mExtensionsArray);
|
1998-07-28 02:07:25 +00:00
|
|
|
mExtensionsArray = nsnull;
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
if ((nsnull != mLibrary) && mCanUnloadLibrary)
|
|
|
|
{
|
|
|
|
// before we unload check if we are allowed to, see bug #61388
|
1998-07-28 02:07:25 +00:00
|
|
|
PR_UnloadLibrary(mLibrary);
|
|
|
|
mLibrary = nsnull;
|
|
|
|
}
|
1999-06-04 22:32:27 +00:00
|
|
|
|
|
|
|
if(nsnull != mFileName)
|
|
|
|
{
|
|
|
|
delete [] mFileName;
|
|
|
|
mFileName = nsnull;
|
|
|
|
}
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
class nsPluginStreamInfo : public nsIPluginStreamInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsPluginStreamInfo();
|
1999-03-23 03:18:12 +00:00
|
|
|
virtual ~nsPluginStreamInfo();
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIPluginStreamInfo interface
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetContentType(nsMIMEType* result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
IsSeekable(PRBool* result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetLength(PRUint32* result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
GetLastModified(PRUint32* result);
|
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
NS_IMETHOD
|
|
|
|
GetURL(const char** result);
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
NS_IMETHOD
|
|
|
|
RequestRead(nsByteRange* rangeList);
|
|
|
|
|
|
|
|
// local methods
|
|
|
|
|
|
|
|
void
|
1999-03-11 22:48:58 +00:00
|
|
|
SetContentType(const nsMIMEType contentType);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
void
|
1999-03-11 22:48:58 +00:00
|
|
|
SetSeekable(const PRBool seekable);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
void
|
1999-03-11 22:48:58 +00:00
|
|
|
SetLength(const PRUint32 length);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
void
|
1999-03-11 22:48:58 +00:00
|
|
|
SetLastModified(const PRUint32 modified);
|
|
|
|
|
|
|
|
void
|
|
|
|
SetURL(const char* url);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
char* mContentType;
|
1999-03-11 22:48:58 +00:00
|
|
|
char* mURL;
|
1999-01-25 08:05:00 +00:00
|
|
|
PRBool mSeekable;
|
|
|
|
PRUint32 mLength;
|
|
|
|
PRUint32 mModified;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsPluginStreamInfo::nsPluginStreamInfo()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
mContentType = nsnull;
|
1999-03-11 22:48:58 +00:00
|
|
|
mURL = nsnull;
|
1999-01-25 08:05:00 +00:00
|
|
|
mSeekable = PR_FALSE;
|
|
|
|
mLength = 0;
|
|
|
|
mModified = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginStreamInfo::~nsPluginStreamInfo()
|
|
|
|
{
|
|
|
|
if(mContentType != nsnull)
|
|
|
|
PL_strfree(mContentType);
|
1999-03-11 22:48:58 +00:00
|
|
|
if(mURL != nsnull)
|
|
|
|
PL_strfree(mURL);
|
1999-01-25 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsPluginStreamInfo)
|
|
|
|
NS_IMPL_RELEASE(nsPluginStreamInfo)
|
|
|
|
|
|
|
|
nsresult nsPluginStreamInfo::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
|
|
|
|
if (nsnull == aInstancePtrResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (aIID.Equals(kIPluginStreamInfoIID))
|
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsIPluginStreamInfo *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID.Equals(kISupportsIID))
|
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsISupports *)((nsIStreamListener *)this));
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginStreamInfo::GetContentType(nsMIMEType* result)
|
|
|
|
{
|
|
|
|
*result = mContentType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginStreamInfo::IsSeekable(PRBool* result)
|
|
|
|
{
|
|
|
|
*result = mSeekable;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginStreamInfo::GetLength(PRUint32* result)
|
|
|
|
{
|
|
|
|
*result = mLength;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginStreamInfo::GetLastModified(PRUint32* result)
|
|
|
|
{
|
|
|
|
*result = mModified;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginStreamInfo::GetURL(const char** result)
|
|
|
|
{
|
|
|
|
*result = mURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginStreamInfo::RequestRead(nsByteRange* rangeList)
|
|
|
|
{
|
2000-06-21 22:57:17 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-25 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// local methods
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPluginStreamInfo::SetContentType(const nsMIMEType contentType)
|
|
|
|
{
|
|
|
|
if(mContentType != nsnull)
|
|
|
|
PL_strfree(mContentType);
|
|
|
|
|
|
|
|
mContentType = PL_strdup(contentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPluginStreamInfo::SetSeekable(const PRBool seekable)
|
|
|
|
{
|
|
|
|
mSeekable = seekable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPluginStreamInfo::SetLength(const PRUint32 length)
|
|
|
|
{
|
|
|
|
mLength = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPluginStreamInfo::SetLastModified(const PRUint32 modified)
|
|
|
|
{
|
|
|
|
mModified = modified;
|
|
|
|
}
|
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
void
|
|
|
|
nsPluginStreamInfo::SetURL(const char* url)
|
|
|
|
{
|
|
|
|
if(mURL != nsnull)
|
|
|
|
PL_strfree(mURL);
|
|
|
|
|
|
|
|
mURL = PL_strdup(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
class nsPluginStreamListenerPeer : public nsIStreamListener
|
1999-07-07 08:08:40 +00:00
|
|
|
, public nsIProgressEventSink
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-01-25 08:05:00 +00:00
|
|
|
nsPluginStreamListenerPeer();
|
1999-03-23 03:18:12 +00:00
|
|
|
virtual ~nsPluginStreamListenerPeer();
|
1998-08-05 04:21:36 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-07-09 21:18:47 +00:00
|
|
|
// nsIProgressEventSink methods:
|
1999-08-22 23:52:07 +00:00
|
|
|
NS_DECL_NSIPROGRESSEVENTSINK
|
|
|
|
|
1999-07-09 21:18:47 +00:00
|
|
|
// nsIStreamObserver methods:
|
1999-08-22 23:52:07 +00:00
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
|
|
|
|
1999-07-09 21:18:47 +00:00
|
|
|
// nsIStreamListener methods:
|
1999-08-22 23:52:07 +00:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-06-25 00:03:22 +00:00
|
|
|
|
1998-08-05 04:21:36 +00:00
|
|
|
//locals
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
// Called by GetURL and PostURL (via NewStream)
|
2000-04-22 20:50:22 +00:00
|
|
|
nsresult Initialize(nsIURI *aURL, nsIPluginInstance *aInstance,
|
|
|
|
nsIPluginStreamListener *aListener);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
nsresult InitializeEmbeded(nsIURI *aURL, nsIPluginInstance* aInstance,
|
|
|
|
nsIPluginInstanceOwner *aOwner = nsnull,
|
|
|
|
nsIPluginHost *aHost = nsnull);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
nsresult InitializeFullPage(nsIPluginInstance *aInstance);
|
1998-08-05 04:21:36 +00:00
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
nsresult OnFileAvailable(const char* aFilename);
|
|
|
|
|
1999-07-09 21:18:47 +00:00
|
|
|
nsILoadGroup* GetLoadGroup();
|
|
|
|
|
a=brendan,av
r=av
bug=50811
This bug fix was suggested by Stanley Ho <stanley.ho@eng.sun.com>.
Stanley proposed we overload the meaning of the nsIPluginStreamListener
argument to nsIPluginManager::{GetURL,PostURL}() so that it also may
implement an interface for reading headers. Thus, the browser could QI
the plugin's nsIPluginStreamListener instance to this headers reading
interface and send the plugin the headers from the response.
I have implemented Stanley's above proposal. I have defined a new
interface, nsIHTTPHeaderListener.idl with one method:
/**
* Called for each HTTP Response header.
* NOTE: You must copy the values of the params.
*/
void newResponseHeader(in string headerName, in string headerValue);
To affect this fix, I have added a new private method
nsPluginStreamListenerPeer::
ReadHeadersFromChannelAndPostToListener(nsIHTTPChannel *httpChannel,
nsIHTTPHeaderListener *listener)
Then, modified nsPluginStreamListenerPeer::OnDataAvailable() to call
this method BEFORE reading the content data. However, this fix makes
two important assumptions I would like to check out:
* Assumption
* By the time nsPluginStreamListenerPeer::OnDataAvailable() gets
* called, all the headers have been read.
* Assumption:
* The return value from nsIHTTPHeader->{GetFieldName,GetValue}()
* must be freed.
The following files are included in this fix:
A modules/plugin/public/nsIHTTPHeaderListener.idl
A modules/plugin/public/makefile.win
A modules/plugin/public/Makefile.in
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
2000-09-13 07:09:38 +00:00
|
|
|
NS_IMETHOD
|
|
|
|
ReadHeadersFromChannelAndPostToListener(nsIHTTPChannel *httpChannel,
|
|
|
|
nsIHTTPHeaderListener *list);
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-08-05 04:21:36 +00:00
|
|
|
private:
|
1998-12-11 04:50:57 +00:00
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsresult SetUpCache(nsIURI* aURL);
|
2001-02-21 20:38:08 +00:00
|
|
|
nsresult SetUpStreamListener(nsIRequest* request, nsIURI* aURL);
|
1998-12-11 04:50:57 +00:00
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI *mURL;
|
1998-09-15 03:48:58 +00:00
|
|
|
nsIPluginInstanceOwner *mOwner;
|
|
|
|
nsIPluginInstance *mInstance;
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
nsIPluginStreamListener *mPStreamListener;
|
|
|
|
nsPluginStreamInfo *mPluginStreamInfo;
|
2000-09-20 09:27:54 +00:00
|
|
|
PRBool mSetUpListener;
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Set to PR_TRUE after nsIPluginInstancePeer::OnStartBinding() has
|
|
|
|
* been called. Checked in ::OnStopRequest so we can call the
|
|
|
|
* plugin's OnStartBinding if, for some reason, it has not already
|
|
|
|
* been called.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
PRBool mStartBinding;
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
// these get passed to the plugin stream listener
|
1998-09-15 03:48:58 +00:00
|
|
|
char *mMIMEType;
|
1999-01-25 08:05:00 +00:00
|
|
|
PRUint32 mLength;
|
|
|
|
nsPluginStreamType mStreamType;
|
1998-09-15 03:48:58 +00:00
|
|
|
nsIPluginHost *mHost;
|
1999-03-11 22:48:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class nsPluginCacheListener : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPluginCacheListener(nsPluginStreamListenerPeer* aListener);
|
1999-03-23 03:18:12 +00:00
|
|
|
virtual ~nsPluginCacheListener();
|
1999-03-11 22:48:58 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-06-25 00:03:22 +00:00
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
private:
|
2000-06-21 22:57:17 +00:00
|
|
|
nsPluginStreamListenerPeer* mListener;
|
1998-08-05 04:21:36 +00:00
|
|
|
};
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsPluginCacheListener::nsPluginCacheListener(nsPluginStreamListenerPeer* aListener)
|
1999-03-11 22:48:58 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
mListener = aListener;
|
|
|
|
NS_ADDREF(mListener);
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsPluginCacheListener::~nsPluginCacheListener()
|
1999-03-11 22:48:58 +00:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsPluginCacheListener, kIStreamListenerIID);
|
|
|
|
|
1999-06-25 00:03:22 +00:00
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
nsPluginCacheListener::OnStartRequest(nsIRequest *request, nsISupports* ctxt)
|
1999-06-25 00:03:22 +00:00
|
|
|
{
|
2000-06-21 22:57:17 +00:00
|
|
|
return NS_OK;
|
1999-06-25 00:03:22 +00:00
|
|
|
}
|
1999-03-11 22:48:58 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
nsPluginCacheListener::OnDataAvailable(nsIRequest *request, nsISupports* ctxt,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsIInputStream* aIStream,
|
|
|
|
PRUint32 sourceOffset,
|
|
|
|
PRUint32 aLength)
|
1999-03-11 22:48:58 +00:00
|
|
|
{
|
1999-06-25 00:03:22 +00:00
|
|
|
|
2000-06-21 22:57:17 +00:00
|
|
|
PRUint32 readlen;
|
|
|
|
char* buffer = (char*) PR_Malloc(aLength);
|
1999-03-11 22:48:58 +00:00
|
|
|
|
2000-06-21 22:57:17 +00:00
|
|
|
// if we don't read from the stream, OnStopRequest will never be called
|
|
|
|
if(!buffer)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv = aIStream->Read(buffer, aLength, &readlen);
|
|
|
|
|
|
|
|
NS_ASSERTION(aLength == readlen, "nsCacheListener->OnDataAvailable: "
|
|
|
|
"readlen != aLength");
|
|
|
|
|
|
|
|
PR_Free(buffer);
|
|
|
|
return rv;
|
1999-03-11 22:48:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
nsPluginCacheListener::OnStopRequest(nsIRequest *request,
|
2000-04-22 20:50:22 +00:00
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aMsg)
|
1999-03-11 22:48:58 +00:00
|
|
|
{
|
2000-06-21 22:57:17 +00:00
|
|
|
return NS_OK;
|
1999-03-11 22:48:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsPluginStreamListenerPeer::nsPluginStreamListenerPeer()
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
1998-09-15 03:48:58 +00:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
1998-08-05 04:21:36 +00:00
|
|
|
mURL = nsnull;
|
1998-09-15 03:48:58 +00:00
|
|
|
mOwner = nsnull;
|
1998-08-05 04:21:36 +00:00
|
|
|
mInstance = nsnull;
|
1999-01-25 08:05:00 +00:00
|
|
|
mPStreamListener = nsnull;
|
|
|
|
mPluginStreamInfo = nsnull;
|
1999-02-04 23:37:20 +00:00
|
|
|
mSetUpListener = PR_FALSE;
|
1998-08-05 04:21:36 +00:00
|
|
|
mHost = nsnull;
|
1998-09-27 22:21:39 +00:00
|
|
|
mStreamType = nsPluginStreamType_Normal;
|
2000-09-20 09:27:54 +00:00
|
|
|
mStartBinding = PR_FALSE;
|
1998-08-05 04:21:36 +00:00
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsPluginStreamListenerPeer::~nsPluginStreamListenerPeer()
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
1998-09-15 03:48:58 +00:00
|
|
|
#ifdef NS_DEBUG
|
1999-01-04 23:43:41 +00:00
|
|
|
if(mURL != nsnull)
|
|
|
|
{
|
1999-06-28 10:35:57 +00:00
|
|
|
char* spec;
|
1999-01-04 23:43:41 +00:00
|
|
|
(void)mURL->GetSpec(&spec);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("killing stream for %s\n", mURL ? spec : "(unknown URL)");
|
1999-06-25 01:41:26 +00:00
|
|
|
nsCRT::free(spec);
|
1999-01-04 23:43:41 +00:00
|
|
|
}
|
1998-09-15 03:48:58 +00:00
|
|
|
#endif
|
1999-01-25 08:05:00 +00:00
|
|
|
|
1998-08-05 04:21:36 +00:00
|
|
|
NS_IF_RELEASE(mURL);
|
1998-09-15 03:48:58 +00:00
|
|
|
NS_IF_RELEASE(mOwner);
|
1998-08-05 04:21:36 +00:00
|
|
|
NS_IF_RELEASE(mInstance);
|
1999-01-25 08:05:00 +00:00
|
|
|
NS_IF_RELEASE(mPStreamListener);
|
1998-08-05 04:21:36 +00:00
|
|
|
NS_IF_RELEASE(mHost);
|
|
|
|
}
|
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
NS_IMPL_ADDREF(nsPluginStreamListenerPeer);
|
|
|
|
NS_IMPL_RELEASE(nsPluginStreamListenerPeer);
|
1998-08-05 04:21:36 +00:00
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsresult nsPluginStreamListenerPeer::QueryInterface(const nsIID& aIID,
|
2000-04-22 20:50:22 +00:00
|
|
|
void** aInstancePtrResult)
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
|
|
|
|
if (nsnull == aInstancePtrResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (aIID.Equals(kIStreamListenerIID))
|
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsIStreamListener *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID.Equals(kIStreamObserverIID))
|
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsIStreamObserver *)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID.Equals(kISupportsIID))
|
|
|
|
{
|
|
|
|
*aInstancePtrResult = (void *)((nsISupports *)((nsIStreamListener *)this));
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/* Called as a result of GetURL and PostURL */
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
nsresult nsPluginStreamListenerPeer::Initialize(nsIURI *aURL,
|
|
|
|
nsIPluginInstance *aInstance,
|
|
|
|
nsIPluginStreamListener* aListener)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
1999-06-28 10:35:57 +00:00
|
|
|
char* spec;
|
1999-01-25 08:05:00 +00:00
|
|
|
(void)aURL->GetSpec(&spec);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("created stream for %s\n", spec);
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(spec);
|
1999-01-25 08:05:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
|
|
|
|
|
|
|
mInstance = aInstance;
|
|
|
|
NS_ADDREF(mInstance);
|
|
|
|
|
|
|
|
mPStreamListener = aListener;
|
|
|
|
NS_ADDREF(mPStreamListener);
|
|
|
|
|
|
|
|
mPluginStreamInfo = new nsPluginStreamInfo();
|
1998-08-05 04:21:36 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/*
|
2000-04-22 20:50:22 +00:00
|
|
|
Called by NewEmbededPluginStream() - if this is called, we weren't
|
|
|
|
able to load the plugin, so we need to load it later once we figure
|
|
|
|
out the mimetype. In order to load it later, we need the plugin
|
|
|
|
host and instance owner.
|
1999-01-25 08:05:00 +00:00
|
|
|
*/
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
nsresult nsPluginStreamListenerPeer::InitializeEmbeded(nsIURI *aURL,
|
|
|
|
nsIPluginInstance* aInstance,
|
|
|
|
nsIPluginInstanceOwner *aOwner,
|
|
|
|
nsIPluginHost *aHost)
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
1998-09-15 03:48:58 +00:00
|
|
|
#ifdef NS_DEBUG
|
1999-06-28 10:35:57 +00:00
|
|
|
char* spec;
|
1998-12-16 05:40:20 +00:00
|
|
|
(void)aURL->GetSpec(&spec);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("created stream for %s\n", spec);
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(spec);
|
1998-09-15 03:48:58 +00:00
|
|
|
#endif
|
1999-01-25 08:05:00 +00:00
|
|
|
|
1998-08-05 04:21:36 +00:00
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
if(aInstance != nsnull)
|
|
|
|
{
|
2000-06-21 22:57:17 +00:00
|
|
|
NS_ASSERTION(mInstance == nsnull, "nsPluginStreamListenerPeer::InitializeEmbeded mInstance != nsnull");
|
1999-01-25 08:05:00 +00:00
|
|
|
mInstance = aInstance;
|
|
|
|
NS_ADDREF(mInstance);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mOwner = aOwner;
|
|
|
|
NS_IF_ADDREF(mOwner);
|
|
|
|
|
|
|
|
mHost = aHost;
|
|
|
|
NS_IF_ADDREF(mHost);
|
|
|
|
}
|
1998-08-05 04:21:36 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
mPluginStreamInfo = new nsPluginStreamInfo();
|
1998-08-05 04:21:36 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/* Called by NewFullPagePluginStream() */
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsresult nsPluginStreamListenerPeer::InitializeFullPage(nsIPluginInstance *aInstance)
|
1998-09-15 03:48:58 +00:00
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("created stream for (unknown URL)\n");
|
|
|
|
printf("Inside nsPluginStreamListenerPeer::InitializeFullPage...\n");
|
2000-06-16 22:27:16 +00:00
|
|
|
#endif
|
2000-04-22 20:50:22 +00:00
|
|
|
|
2000-06-21 22:57:17 +00:00
|
|
|
NS_ASSERTION(mInstance == nsnull, "nsPluginStreamListenerPeer::InitializeFullPage mInstance != nsnull");
|
1998-09-15 03:48:58 +00:00
|
|
|
mInstance = aInstance;
|
|
|
|
NS_ADDREF(mInstance);
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
mPluginStreamInfo = new nsPluginStreamInfo();
|
1998-09-15 03:48:58 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
|
1999-07-07 08:08:40 +00:00
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aContext)
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
char* aContentType = nsnull;
|
|
|
|
rv = channel->GetContentType(&aContentType);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-25 00:03:22 +00:00
|
|
|
|
1998-08-05 04:21:36 +00:00
|
|
|
if (nsnull != aContentType)
|
1999-03-11 22:48:58 +00:00
|
|
|
mPluginStreamInfo->SetContentType(aContentType);
|
1998-08-05 04:21:36 +00:00
|
|
|
|
1998-09-15 03:48:58 +00:00
|
|
|
nsPluginWindow *window = nsnull;
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
// if we don't have an nsIPluginInstance (mInstance), it means
|
|
|
|
// we weren't able to load a plugin previously because we
|
|
|
|
// didn't have the mimetype. Now that we do (aContentType),
|
2001-01-10 23:49:19 +00:00
|
|
|
// we'll try again with SetUpPluginInstance()
|
|
|
|
// which is called by InstantiateEmbededPlugin()
|
|
|
|
// NOTE: we don't want to try again if we didn't get the MIME type this time
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2001-01-10 23:49:19 +00:00
|
|
|
if ((nsnull == mInstance) && (nsnull != mOwner) && (nsnull != aContentType))
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
1999-01-25 08:05:00 +00:00
|
|
|
mOwner->GetInstance(mInstance);
|
1998-09-15 03:48:58 +00:00
|
|
|
mOwner->GetWindow(window);
|
1998-08-05 04:21:36 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
if ((nsnull == mInstance) && (nsnull != mHost) && (nsnull != window))
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
2001-01-10 23:49:19 +00:00
|
|
|
// determine if we need to try embedded again. FullPage takes a different code path
|
2001-01-12 23:45:03 +00:00
|
|
|
nsPluginMode mode;
|
|
|
|
mOwner->GetMode(&mode);
|
|
|
|
if (mode == nsPluginMode_Embedded)
|
2001-01-10 23:49:19 +00:00
|
|
|
rv = mHost->InstantiateEmbededPlugin(aContentType, aURL, mOwner);
|
|
|
|
else
|
|
|
|
rv = mHost->SetUpPluginInstance(aContentType, aURL, mOwner);
|
1998-09-15 03:48:58 +00:00
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
1999-01-25 08:05:00 +00:00
|
|
|
// GetInstance() adds a ref
|
|
|
|
mOwner->GetInstance(mInstance);
|
1998-08-05 04:21:36 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
if (nsnull != mInstance)
|
1998-09-15 03:48:58 +00:00
|
|
|
{
|
1999-01-25 08:05:00 +00:00
|
|
|
mInstance->Start();
|
1998-09-15 03:48:58 +00:00
|
|
|
mOwner->CreateWidget();
|
2000-07-20 01:40:54 +00:00
|
|
|
|
|
|
|
// If we've got a native window, the let the plugin know
|
|
|
|
// about it.
|
|
|
|
if (window->window)
|
|
|
|
mInstance->SetWindow(window);
|
1998-09-15 03:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
1998-08-05 04:21:36 +00:00
|
|
|
}
|
|
|
|
}
|
1998-09-15 03:48:58 +00:00
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(aContentType);
|
1999-09-09 05:13:31 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Set up the stream listener...
|
|
|
|
//
|
|
|
|
PRInt32 length;
|
|
|
|
|
|
|
|
rv = channel->GetContentLength(&length);
|
|
|
|
|
2000-09-20 09:27:54 +00:00
|
|
|
// it's possible for the server to not send a Content-Length. We should
|
|
|
|
// still work in this case.
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mPluginStreamInfo->SetLength(-1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mPluginStreamInfo->SetLength(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
rv = SetUpStreamListener(request, aURL);
|
1999-09-09 05:13:31 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1998-08-05 04:21:36 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIRequest *request,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsISupports* aContext,
|
|
|
|
PRUint32 aProgress,
|
|
|
|
PRUint32 aProgressMax)
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
1998-12-11 04:50:57 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
return rv;
|
1998-08-05 04:21:36 +00:00
|
|
|
}
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIRequest *request,
|
2000-07-25 05:45:56 +00:00
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aStatusArg)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-25 00:03:22 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream *aIStream,
|
|
|
|
PRUint32 sourceOffset,
|
|
|
|
PRUint32 aLength)
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
1999-03-11 22:48:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
if (!channel) return NS_ERROR_FAILURE;
|
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
if(!mPStreamListener)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-01-25 08:05:00 +00:00
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
char* urlString;
|
1999-03-11 22:48:58 +00:00
|
|
|
aURL->GetSpec(&urlString);
|
|
|
|
mPluginStreamInfo->SetURL(urlString);
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(urlString);
|
1999-03-11 22:48:58 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
// if the plugin has requested an AsFileOnly stream, then don't
|
|
|
|
// call OnDataAvailable
|
1999-03-11 22:48:58 +00:00
|
|
|
if(mStreamType != nsPluginStreamType_AsFileOnly)
|
|
|
|
{
|
2000-06-21 22:57:17 +00:00
|
|
|
// It's up to the plugin to read from the stream
|
|
|
|
// If it doesn't, OnStopRequest will never be called
|
1999-04-06 01:53:37 +00:00
|
|
|
rv = mPStreamListener->OnDataAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aIStream, aLength);
|
2000-06-21 22:57:17 +00:00
|
|
|
// if a plugin returns an error, the peer must kill the stream
|
|
|
|
// else the stream and PluginStreamListener leak
|
|
|
|
if (NS_FAILED(rv))
|
2001-02-21 20:38:08 +00:00
|
|
|
request->Cancel(rv);
|
1999-04-06 01:53:37 +00:00
|
|
|
}
|
|
|
|
else
|
2000-06-21 22:57:17 +00:00
|
|
|
{
|
1999-07-01 19:30:20 +00:00
|
|
|
// if we don't read from the stream, OnStopRequest will never be called
|
1999-04-06 01:53:37 +00:00
|
|
|
char* buffer = new char[aLength];
|
|
|
|
PRUint32 amountRead;
|
|
|
|
rv = aIStream->Read(buffer, aLength, &amountRead);
|
|
|
|
delete [] buffer;
|
|
|
|
}
|
1999-03-11 22:48:58 +00:00
|
|
|
return rv;
|
1998-08-05 04:21:36 +00:00
|
|
|
}
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aMsg)
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-07-07 08:08:40 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
if (!channel) return NS_ERROR_FAILURE;
|
1999-07-07 08:08:40 +00:00
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-09-15 03:48:58 +00:00
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
if(nsnull != mPStreamListener)
|
1998-09-15 03:48:58 +00:00
|
|
|
{
|
1999-06-28 10:35:57 +00:00
|
|
|
char* urlString;
|
2000-06-21 22:57:17 +00:00
|
|
|
nsCOMPtr<nsIFile> localFile;
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel);
|
|
|
|
|
|
|
|
if (fileChannel)
|
|
|
|
rv = fileChannel->GetFile(getter_AddRefs(localFile));
|
|
|
|
|
2000-06-22 22:36:37 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && localFile)
|
2000-06-21 22:57:17 +00:00
|
|
|
{
|
|
|
|
char* pathAndFilename;
|
|
|
|
rv = localFile->GetPath(&pathAndFilename);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
OnFileAvailable(pathAndFilename);
|
|
|
|
nsMemory::Free(pathAndFilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aURL->GetSpec(&urlString);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
mPluginStreamInfo->SetURL(urlString);
|
|
|
|
nsCRT::free(urlString);
|
|
|
|
}
|
1998-09-15 03:48:58 +00:00
|
|
|
|
2000-10-17 20:57:36 +00:00
|
|
|
// Set the content type to ensure we don't pass null to the plugin
|
|
|
|
char* aContentType = nsnull;
|
|
|
|
rv = channel->GetContentType(&aContentType);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (nsnull != aContentType)
|
|
|
|
mPluginStreamInfo->SetContentType(aContentType);
|
|
|
|
|
2000-09-20 09:27:54 +00:00
|
|
|
if (mStartBinding)
|
|
|
|
{
|
|
|
|
// On start binding has been called
|
|
|
|
mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// OnStartBinding hasn't been called, so complete the action.
|
|
|
|
mPStreamListener->OnStartBinding((nsIPluginStreamInfo*)mPluginStreamInfo);
|
|
|
|
mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus);
|
|
|
|
}
|
2000-10-17 20:57:36 +00:00
|
|
|
if (aContentType)
|
|
|
|
nsCRT::free(aContentType);
|
1998-09-27 22:21:39 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 03:48:58 +00:00
|
|
|
return rv;
|
1998-08-05 04:21:36 +00:00
|
|
|
}
|
|
|
|
|
1999-06-25 00:03:22 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
// private methods for nsPluginStreamListenerPeer
|
1998-08-05 04:21:36 +00:00
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURI* aURL)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
1999-03-11 22:48:58 +00:00
|
|
|
nsPluginCacheListener* cacheListener = new nsPluginCacheListener(this);
|
1999-08-26 22:45:55 +00:00
|
|
|
// XXX: Null LoadGroup?
|
|
|
|
return NS_OpenURI(cacheListener, nsnull, aURL, nsnull);
|
1999-01-25 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
|
2000-09-20 09:27:54 +00:00
|
|
|
nsIURI* aURL)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
1999-02-04 23:37:20 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
// If we don't yet have a stream listener, we need to get
|
|
|
|
// one from the plugin.
|
|
|
|
// NOTE: this should only happen when a stream was NOT created
|
|
|
|
// with GetURL or PostURL (i.e. it's the initial stream we
|
|
|
|
// send to the plugin as determined by the SRC or DATA attribute)
|
1999-01-25 08:05:00 +00:00
|
|
|
if(mPStreamListener == nsnull && mInstance != nsnull)
|
|
|
|
rv = mInstance->NewStream(&mPStreamListener);
|
|
|
|
|
|
|
|
if(rv != NS_OK)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if(mPStreamListener == nsnull)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-04 23:37:20 +00:00
|
|
|
|
2000-09-20 09:27:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Assumption
|
|
|
|
|
|
|
|
* By the time nsPluginStreamListenerPeer::OnDataAvailable() gets
|
|
|
|
* called, all the headers have been read.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHTTPHeaderListener> headerListener =
|
|
|
|
do_QueryInterface(mPStreamListener);
|
|
|
|
if (headerListener) {
|
2001-02-21 20:38:08 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
2000-09-20 09:27:54 +00:00
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel);
|
|
|
|
if (httpChannel) {
|
|
|
|
ReadHeadersFromChannelAndPostToListener(httpChannel, headerListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-04 23:37:20 +00:00
|
|
|
mSetUpListener = PR_TRUE;
|
2000-04-22 20:50:22 +00:00
|
|
|
mPluginStreamInfo->SetSeekable(PR_FALSE);
|
2000-12-12 01:00:28 +00:00
|
|
|
|
|
|
|
// get Last-Modified header for plugin info
|
2001-02-21 20:38:08 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
2000-12-12 01:00:28 +00:00
|
|
|
nsCOMPtr<nsIHTTPChannel> theHTTPChannel = do_QueryInterface(channel);
|
|
|
|
if (theHTTPChannel) {
|
|
|
|
char * lastModified;
|
|
|
|
nsCOMPtr<nsIAtom> header = NS_NewAtom("last-modified");
|
|
|
|
|
|
|
|
theHTTPChannel->GetResponseHeader(header, &lastModified);
|
|
|
|
if (lastModified) {
|
|
|
|
PRTime time64;
|
|
|
|
PR_ParseTimeString(lastModified, PR_TRUE, &time64); //convert string time to interger time
|
|
|
|
|
|
|
|
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
|
|
|
|
double fpTime;
|
|
|
|
LL_L2D(fpTime, time64);
|
|
|
|
mPluginStreamInfo->SetLastModified((PRUint32)(fpTime * 1e-6 + 0.5));
|
|
|
|
nsCRT::free(lastModified);
|
|
|
|
}
|
|
|
|
}
|
1999-01-25 08:05:00 +00:00
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
char* urlString;
|
|
|
|
aURL->GetSpec(&urlString);
|
|
|
|
mPluginStreamInfo->SetURL(urlString);
|
|
|
|
nsCRT::free(urlString);
|
1998-07-28 02:07:25 +00:00
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
rv = mPStreamListener->OnStartBinding((nsIPluginStreamInfo*)mPluginStreamInfo);
|
1998-12-11 04:50:57 +00:00
|
|
|
|
2000-09-20 09:27:54 +00:00
|
|
|
mStartBinding = PR_TRUE;
|
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
if(rv == NS_OK)
|
2000-06-21 22:57:17 +00:00
|
|
|
{
|
|
|
|
mPStreamListener->GetStreamType(&mStreamType);
|
|
|
|
// check to see if we need to cache the file as well
|
|
|
|
if ((mStreamType == nsPluginStreamType_AsFile) ||
|
2000-04-22 20:50:22 +00:00
|
|
|
(mStreamType == nsPluginStreamType_AsFileOnly))
|
2000-06-21 22:57:17 +00:00
|
|
|
rv = SetUpCache(aURL);
|
|
|
|
}
|
1998-12-11 04:50:57 +00:00
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-12-11 04:50:57 +00:00
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
nsresult
|
|
|
|
nsPluginStreamListenerPeer::OnFileAvailable(const char* aFilename)
|
|
|
|
{
|
2000-06-21 22:57:17 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (!mPStreamListener)
|
|
|
|
return NS_ERROR_FAILURE;
|
1998-12-11 04:50:57 +00:00
|
|
|
|
2000-06-21 22:57:17 +00:00
|
|
|
rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename);
|
|
|
|
return rv;
|
1998-12-11 04:50:57 +00:00
|
|
|
}
|
|
|
|
|
1999-07-09 21:18:47 +00:00
|
|
|
nsILoadGroup*
|
|
|
|
nsPluginStreamListenerPeer::GetLoadGroup()
|
|
|
|
{
|
|
|
|
nsILoadGroup* loadGroup = nsnull;
|
|
|
|
nsIDocument* doc;
|
|
|
|
nsresult rv = mOwner->GetDocument(&doc);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-09-18 06:55:13 +00:00
|
|
|
doc->GetDocumentLoadGroup(&loadGroup);
|
1999-07-09 21:18:47 +00:00
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
return loadGroup;
|
|
|
|
}
|
|
|
|
|
a=brendan,av
r=av
bug=50811
This bug fix was suggested by Stanley Ho <stanley.ho@eng.sun.com>.
Stanley proposed we overload the meaning of the nsIPluginStreamListener
argument to nsIPluginManager::{GetURL,PostURL}() so that it also may
implement an interface for reading headers. Thus, the browser could QI
the plugin's nsIPluginStreamListener instance to this headers reading
interface and send the plugin the headers from the response.
I have implemented Stanley's above proposal. I have defined a new
interface, nsIHTTPHeaderListener.idl with one method:
/**
* Called for each HTTP Response header.
* NOTE: You must copy the values of the params.
*/
void newResponseHeader(in string headerName, in string headerValue);
To affect this fix, I have added a new private method
nsPluginStreamListenerPeer::
ReadHeadersFromChannelAndPostToListener(nsIHTTPChannel *httpChannel,
nsIHTTPHeaderListener *listener)
Then, modified nsPluginStreamListenerPeer::OnDataAvailable() to call
this method BEFORE reading the content data. However, this fix makes
two important assumptions I would like to check out:
* Assumption
* By the time nsPluginStreamListenerPeer::OnDataAvailable() gets
* called, all the headers have been read.
* Assumption:
* The return value from nsIHTTPHeader->{GetFieldName,GetValue}()
* must be freed.
The following files are included in this fix:
A modules/plugin/public/nsIHTTPHeaderListener.idl
A modules/plugin/public/makefile.win
A modules/plugin/public/Makefile.in
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
2000-09-13 07:09:38 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginStreamListenerPeer::
|
|
|
|
ReadHeadersFromChannelAndPostToListener(nsIHTTPChannel *httpChannel,
|
|
|
|
nsIHTTPHeaderListener *listener)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
|
|
|
if (NS_FAILED(rv = httpChannel->
|
|
|
|
GetResponseHeaderEnumerator(getter_AddRefs(enumerator)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
PRBool bMoreHeaders;
|
|
|
|
nsCOMPtr<nsISupports> item;
|
|
|
|
nsCOMPtr<nsIHTTPHeader> header;
|
|
|
|
char *name = nsnull;
|
|
|
|
char *val = nsnull;
|
|
|
|
|
|
|
|
while (NS_SUCCEEDED(rv = enumerator->HasMoreElements(&bMoreHeaders))
|
|
|
|
&& (bMoreHeaders == PR_TRUE)) {
|
|
|
|
enumerator->GetNext(getter_AddRefs(item));
|
|
|
|
header = do_QueryInterface(item);
|
|
|
|
NS_ASSERTION(header, "nsPluginHostImpl::ReadHeadersFromChannelAndPostToListener - Bad HTTP header.");
|
|
|
|
if (header) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Assumption:
|
|
|
|
|
|
|
|
* The return value from nsIHTTPHeader->{GetFieldName,GetValue}()
|
|
|
|
* must be freed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
header->GetFieldName(&name);
|
|
|
|
header->GetValue(&val);
|
|
|
|
if (NS_FAILED(rv = listener->NewResponseHeader(name, val))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCRT::free(name);
|
|
|
|
name = nsnull;
|
|
|
|
nsCRT::free(val);
|
|
|
|
val = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
nsPluginHostImpl::nsPluginHostImpl()
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
1998-09-15 03:48:58 +00:00
|
|
|
NS_INIT_REFCNT();
|
1999-01-25 08:05:00 +00:00
|
|
|
mPluginsLoaded = PR_FALSE;
|
2000-09-14 23:58:17 +00:00
|
|
|
mDontShowBadPluginMessage = PR_FALSE;
|
2001-02-02 23:48:17 +00:00
|
|
|
mUnloadedLibraries = nsnull;
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsPluginHostImpl::~nsPluginHostImpl()
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
1998-09-15 03:48:58 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("killing plugin host\n");
|
1998-09-15 03:48:58 +00:00
|
|
|
#endif
|
2000-04-13 02:52:34 +00:00
|
|
|
Destroy();
|
1998-07-28 02:07:25 +00:00
|
|
|
if (nsnull != mPluginPath)
|
|
|
|
{
|
|
|
|
PR_Free(mPluginPath);
|
|
|
|
mPluginPath = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (nsnull != mPlugins)
|
|
|
|
{
|
|
|
|
nsPluginTag *temp = mPlugins->mNext;
|
|
|
|
delete mPlugins;
|
|
|
|
mPlugins = temp;
|
|
|
|
}
|
2001-02-02 23:48:17 +00:00
|
|
|
|
|
|
|
CleanUnloadedLibraries();
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_IMPL_ISUPPORTS5(nsPluginHostImpl,
|
|
|
|
nsIPluginManager,
|
|
|
|
nsIPluginManager2,
|
|
|
|
nsIPluginHost,
|
|
|
|
nsIFileUtilities,
|
|
|
|
nsICookieStorage);
|
1998-07-28 02:07:25 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_METHOD
|
|
|
|
nsPluginHostImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_PRECONDITION(aOuter == nsnull, "no aggregation");
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
1998-07-28 02:07:25 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
nsPluginHostImpl* host = new nsPluginHostImpl();
|
|
|
|
if (! host)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-28 02:07:25 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
nsresult rv;
|
|
|
|
NS_ADDREF(host);
|
|
|
|
rv = host->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(host);
|
|
|
|
return rv;
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2000-07-20 01:16:52 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::GetValue(nsPluginManagerVariable aVariable, void *aValue)
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
2000-07-20 01:16:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aValue);
|
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
if (nsPluginManagerVariable_XDisplay == aVariable) {
|
|
|
|
Display** value = NS_REINTERPRET_CAST(Display**, aValue);
|
2000-11-30 22:01:45 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
|
|
|
*value = GDK_DISPLAY();
|
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
*value = qt_xdisplay();
|
|
|
|
#endif
|
|
|
|
if (!(*value)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-07-20 01:16:52 +00:00
|
|
|
}
|
2000-11-30 22:01:45 +00:00
|
|
|
}
|
2000-07-20 01:16:52 +00:00
|
|
|
#endif
|
|
|
|
return rv;
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
PRBool nsPluginHostImpl::IsRunningPlugin(nsPluginTag * plugin)
|
|
|
|
{
|
|
|
|
if(!plugin)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// we can check for mLibrary to be non-zero and then querry nsIPluginInstancePeer
|
|
|
|
// in nsActivePluginList to see if plugin with matching mime type is not stopped
|
|
|
|
if(!plugin->mLibrary)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
for(int i = 0; i < plugin->mVariants; i++)
|
|
|
|
{
|
|
|
|
nsActivePlugin * p = mActivePluginList.find(plugin->mMimeTypeArray[i]);
|
|
|
|
if(p && !p->mStopped)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this will unload loaded but no longer needed libs which are
|
|
|
|
// gathered in mUnloadedLibraries list, see bug #61388
|
|
|
|
void nsPluginHostImpl::CleanUnloadedLibraries()
|
|
|
|
{
|
|
|
|
if(!mUnloadedLibraries)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (nsnull != mUnloadedLibraries)
|
|
|
|
{
|
|
|
|
nsUnloadedLibrary *temp = mUnloadedLibraries->mNext;
|
|
|
|
delete mUnloadedLibraries;
|
|
|
|
mUnloadedLibraries = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages)
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
2000-07-22 01:34:13 +00:00
|
|
|
// XXX don't we want to nuke the old mPlugins right now?
|
2000-08-17 19:26:15 +00:00
|
|
|
// we should. Otherwise LoadPlugins will add the same plugins to the list
|
|
|
|
// XXX for new-style plugins, we should also call nsIComponentManager::AutoRegister()
|
2001-02-02 23:48:17 +00:00
|
|
|
|
|
|
|
// we are re-scanning plugins. New plugins may have been added, also some
|
|
|
|
// plugins may have been removed, so we should probably shut everything down
|
|
|
|
// but don't touch running (active and not stopped) plugins
|
|
|
|
|
|
|
|
if(reloadPages)
|
|
|
|
{
|
|
|
|
// if we have currently running plugins we should set a flag not to
|
|
|
|
// unload them from memory, see bug #61388
|
|
|
|
// and form a list of libs to be unloaded later
|
|
|
|
for(nsPluginTag * p = mPlugins; p != nsnull; p = p->mNext)
|
|
|
|
{
|
|
|
|
if(IsRunningPlugin(p))
|
|
|
|
{
|
|
|
|
p->mCanUnloadLibrary = PR_FALSE;
|
|
|
|
nsUnloadedLibrary * unloadedLibrary = new nsUnloadedLibrary(p->mLibrary);
|
|
|
|
if(unloadedLibrary)
|
|
|
|
{
|
|
|
|
unloadedLibrary->mNext = mUnloadedLibraries;
|
|
|
|
mUnloadedLibraries = unloadedLibrary;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// then stop any running plugins
|
|
|
|
mActivePluginList.stopRunning();
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean active plugin list
|
|
|
|
mActivePluginList.removeAllStopped();
|
|
|
|
|
|
|
|
// shutdown plugins and kill the list if there are no running plugins
|
|
|
|
nsPluginTag * prev = nsnull;
|
|
|
|
nsPluginTag * next = nsnull;
|
|
|
|
|
|
|
|
for(nsPluginTag * p = mPlugins; p != nsnull;)
|
|
|
|
{
|
|
|
|
next = p->mNext;
|
|
|
|
|
|
|
|
if(!IsRunningPlugin(p))
|
|
|
|
{
|
|
|
|
if(p == mPlugins)
|
|
|
|
mPlugins = next;
|
|
|
|
else
|
|
|
|
prev->mNext = next;
|
|
|
|
|
|
|
|
if(p->mEntryPoint)
|
|
|
|
p->mEntryPoint->Shutdown();
|
|
|
|
|
|
|
|
delete p;
|
|
|
|
p = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = p;
|
|
|
|
p = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set flags
|
1998-09-30 18:57:27 +00:00
|
|
|
mPluginsLoaded = PR_FALSE;
|
2000-11-30 22:01:45 +00:00
|
|
|
|
|
|
|
// load them again
|
2001-02-02 23:48:17 +00:00
|
|
|
nsresult rv = LoadPlugins();
|
|
|
|
|
|
|
|
return rv;
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
2000-10-31 20:25:19 +00:00
|
|
|
#define NS_RETURN_UASTRING_SIZE 128
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
nsresult nsPluginHostImpl::UserAgent(const char **retstring)
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
2000-10-31 20:25:19 +00:00
|
|
|
static char resultString[NS_RETURN_UASTRING_SIZE];
|
1998-11-22 00:22:35 +00:00
|
|
|
nsresult res;
|
|
|
|
|
2000-10-31 20:25:19 +00:00
|
|
|
nsCOMPtr<nsIHTTPProtocolHandler> http = do_GetService(kHTTPHandlerCID, &res);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
1998-10-28 21:16:00 +00:00
|
|
|
|
2000-10-31 20:25:19 +00:00
|
|
|
PRUnichar *UAString = nsnull;
|
|
|
|
res = http->GetUserAgent(&UAString);
|
1999-06-18 17:34:08 +00:00
|
|
|
|
2000-10-31 20:25:19 +00:00
|
|
|
if (NS_SUCCEEDED(res))
|
1998-11-22 00:22:35 +00:00
|
|
|
{
|
2000-10-31 20:25:19 +00:00
|
|
|
nsAutoString ua(UAString);
|
|
|
|
char * newString = ua.ToNewCString();
|
|
|
|
if (!newString)
|
|
|
|
{
|
|
|
|
*retstring = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(NS_RETURN_UASTRING_SIZE > PL_strlen(newString))
|
|
|
|
{
|
|
|
|
PL_strcpy(resultString, newString);
|
|
|
|
*retstring = resultString;
|
|
|
|
}
|
1998-11-22 00:22:35 +00:00
|
|
|
else
|
2000-10-31 20:25:19 +00:00
|
|
|
{
|
1998-11-22 00:22:35 +00:00
|
|
|
*retstring = nsnull;
|
2000-10-31 20:25:19 +00:00
|
|
|
res = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-11-22 00:22:35 +00:00
|
|
|
|
2000-10-31 20:25:19 +00:00
|
|
|
nsCRT::free(newString);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*retstring = nsnull;
|
1998-11-22 00:22:35 +00:00
|
|
|
|
1998-10-28 21:16:00 +00:00
|
|
|
return res;
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::GetURL(nsISupports* pluginInst,
|
|
|
|
const char* url,
|
|
|
|
const char* target,
|
|
|
|
nsIPluginStreamListener* streamListener,
|
|
|
|
const char* altHost,
|
|
|
|
const char* referrer,
|
|
|
|
PRBool forceJSEnabled)
|
r=vidur, av
a=brendan
bug=49525
This simple fix just adds parameters to an existing method in an XPCOM
safe way, by defining a new method at the end of the interface
definition with the additional parameters.
Original method:
NS_IMETHOD
GetURL(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE) = 0;
New method:
NS_IMETHOD
GetURLWithHeaders(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
PRUint32 getHeadersLength = 0,
const char* getHeaders = NULL) = 0;
I have modified nsPluginHostImpl.h to include this new method, and
modified nsPluginHostImpl.cpp so that its GetURL calls GetURLWithHeaders
with null values for the last two params.
M modules/plugin/public/nsIPluginManager.h
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-14 22:57:56 +00:00
|
|
|
{
|
|
|
|
return GetURLWithHeaders(pluginInst, url, target, streamListener,
|
|
|
|
altHost, referrer, forceJSEnabled, nsnull, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst,
|
|
|
|
const char* url,
|
|
|
|
const char* target,
|
|
|
|
nsIPluginStreamListener* streamListener,
|
|
|
|
const char* altHost,
|
|
|
|
const char* referrer,
|
|
|
|
PRBool forceJSEnabled,
|
|
|
|
PRUint32 getHeadersLength,
|
|
|
|
const char* getHeaders)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
2000-04-03 09:20:26 +00:00
|
|
|
nsAutoString string; string.AssignWithConversion(url);
|
1999-01-25 08:05:00 +00:00
|
|
|
nsIPluginInstance *instance;
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
// we can only send a stream back to the plugin (as specified by a
|
|
|
|
// null target) if we also have a nsIPluginStreamListener to talk to also
|
1999-01-25 08:05:00 +00:00
|
|
|
if(target == nsnull && streamListener == nsnull)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
rv = pluginInst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
|
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
if (nsnull != target)
|
|
|
|
{
|
|
|
|
nsPluginInstancePeerImpl *peer;
|
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
rv = instance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
2000-06-16 22:27:16 +00:00
|
|
|
nsCOMPtr<nsIPluginInstanceOwner> owner;
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
rv = peer->GetOwner(*getter_AddRefs(owner));
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
if ((0 == PL_strcmp(target, "newwindow")) ||
|
|
|
|
(0 == PL_strcmp(target, "_new")))
|
|
|
|
target = "_blank";
|
|
|
|
else if (0 == PL_strcmp(target, "_current"))
|
|
|
|
target = "_self";
|
|
|
|
|
r=vidur, av
a=brendan
bug=49525
This simple fix just adds parameters to an existing method in an XPCOM
safe way, by defining a new method at the end of the interface
definition with the additional parameters.
Original method:
NS_IMETHOD
GetURL(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE) = 0;
New method:
NS_IMETHOD
GetURLWithHeaders(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
PRUint32 getHeadersLength = 0,
const char* getHeaders = NULL) = 0;
I have modified nsPluginHostImpl.h to include this new method, and
modified nsPluginHostImpl.cpp so that its GetURL calls GetURLWithHeaders
with null values for the last two params.
M modules/plugin/public/nsIPluginManager.h
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-14 22:57:56 +00:00
|
|
|
rv = owner->GetURL(url, target, nsnull, 0, (void *) getHeaders,
|
|
|
|
getHeadersLength);
|
1999-01-25 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != streamListener)
|
r=vidur, av
a=brendan
bug=49525
This simple fix just adds parameters to an existing method in an XPCOM
safe way, by defining a new method at the end of the interface
definition with the additional parameters.
Original method:
NS_IMETHOD
GetURL(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE) = 0;
New method:
NS_IMETHOD
GetURLWithHeaders(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
const char* altHost = NULL,
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
PRUint32 getHeadersLength = 0,
const char* getHeaders = NULL) = 0;
I have modified nsPluginHostImpl.h to include this new method, and
modified nsPluginHostImpl.cpp so that its GetURL calls GetURLWithHeaders
with null values for the last two params.
M modules/plugin/public/nsIPluginManager.h
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-14 22:57:56 +00:00
|
|
|
rv = NewPluginURLStream(string, instance, streamListener,
|
|
|
|
nsnull, nsnull, getHeaders, getHeadersLength);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
NS_RELEASE(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
|
|
|
|
const char* url,
|
|
|
|
PRUint32 postDataLen,
|
|
|
|
const char* postData,
|
|
|
|
PRBool isFile,
|
|
|
|
const char* target,
|
|
|
|
nsIPluginStreamListener* streamListener,
|
|
|
|
const char* altHost,
|
|
|
|
const char* referrer,
|
|
|
|
PRBool forceJSEnabled,
|
|
|
|
PRUint32 postHeadersLength,
|
|
|
|
const char* postHeaders)
|
|
|
|
{
|
2000-04-03 09:20:26 +00:00
|
|
|
nsAutoString string; string.AssignWithConversion(url);
|
1999-01-25 08:05:00 +00:00
|
|
|
nsIPluginInstance *instance;
|
|
|
|
nsresult rv;
|
2000-08-24 19:49:08 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
// we can only send a stream back to the plugin (as specified
|
|
|
|
// by a null target) if we also have a nsIPluginStreamListener
|
|
|
|
// to talk to also
|
1999-01-25 08:05:00 +00:00
|
|
|
if(target == nsnull && streamListener == nsnull)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2000-08-24 19:49:08 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
rv = pluginInst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
|
2000-08-24 19:49:08 +00:00
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
nsPluginInstancePeerImpl *peer;
|
|
|
|
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
if (nsnull != target)
|
|
|
|
{
|
|
|
|
|
|
|
|
rv = instance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPluginInstanceOwner> owner;
|
|
|
|
|
|
|
|
rv = peer->GetOwner(*getter_AddRefs(owner));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
if (!target) {
|
|
|
|
target = "_self";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((0 == PL_strcmp(target, "newwindow")) ||
|
|
|
|
(0 == PL_strcmp(target, "_new")))
|
|
|
|
target = "_blank";
|
|
|
|
else if (0 == PL_strcmp(target, "_current"))
|
|
|
|
target = "_self";
|
|
|
|
}
|
|
|
|
rv = owner->GetURL(url, target, (void*)postData, postDataLen,
|
|
|
|
(void*) postHeaders, postHeadersLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(peer);
|
2000-08-24 19:49:08 +00:00
|
|
|
}
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
}
|
2000-08-24 19:49:08 +00:00
|
|
|
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
// if we don't have a target, just create a stream. This does
|
|
|
|
// NS_OpenURI()!
|
|
|
|
if (streamListener != nsnull)
|
|
|
|
rv = NewPluginURLStream(string, instance, streamListener,
|
|
|
|
(void*)postData, postDataLen,
|
|
|
|
postHeaders, postHeadersLength);
|
|
|
|
|
|
|
|
NS_RELEASE(instance);
|
1999-01-25 08:05:00 +00:00
|
|
|
}
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::RegisterPlugin(REFNSIID aCID,
|
|
|
|
const char* aPluginName,
|
|
|
|
const char* aDescription,
|
|
|
|
const char** aMimeTypes,
|
|
|
|
const char** aMimeDescriptions,
|
|
|
|
const char** aFileExtensions,
|
|
|
|
PRInt32 aCount)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRegistry> registry = do_CreateInstance(kRegistryCID);
|
|
|
|
if (! registry)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-08-19 21:44:26 +00:00
|
|
|
nsCAutoString path("software/plugins/");
|
2000-07-22 01:34:13 +00:00
|
|
|
char* cid = aCID.ToString();
|
|
|
|
if (! cid)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
path += cid;
|
|
|
|
nsMemory::Free(cid);
|
|
|
|
|
|
|
|
nsRegistryKey pluginKey;
|
|
|
|
rv = registry->AddSubtree(nsIRegistry::Common, path, &pluginKey);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
registry->SetStringUTF8(pluginKey, "name", aPluginName);
|
|
|
|
registry->SetStringUTF8(pluginKey, "description", aDescription);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aCount; ++i) {
|
|
|
|
nsCAutoString mimepath;
|
|
|
|
mimepath.AppendInt(i);
|
|
|
|
|
|
|
|
nsRegistryKey key;
|
|
|
|
registry->AddSubtree(pluginKey, mimepath, &key);
|
|
|
|
|
|
|
|
registry->SetStringUTF8(key, "mimetype", aMimeTypes[i]);
|
|
|
|
registry->SetStringUTF8(key, "description", aMimeDescriptions[i]);
|
|
|
|
registry->SetStringUTF8(key, "extension", aFileExtensions[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::UnregisterPlugin(REFNSIID aCID)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRegistry> registry = do_CreateInstance(kRegistryCID);
|
|
|
|
if (! registry)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-08-19 21:44:26 +00:00
|
|
|
nsCAutoString path("software/plugins/");
|
2000-07-22 01:34:13 +00:00
|
|
|
char* cid = aCID.ToString();
|
|
|
|
if (! cid)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
path += cid;
|
|
|
|
nsMemory::Free(cid);
|
|
|
|
|
|
|
|
return registry->RemoveSubtree(nsIRegistry::Common, path);
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::BeginWaitCursor(void)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::EndWaitCursor(void)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::SupportsURLProtocol(const char* protocol, PRBool *result)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::NotifyStatusChange(nsIPlugin* plugin, nsresult errorStatus)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
1998-09-01 00:17:25 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-10-09 01:18:02 +00:00
|
|
|
/**
|
|
|
|
* This method queries the prefs for proxy information.
|
|
|
|
* It has been tested and is known to work in the following three cases
|
|
|
|
* when no proxy host or port is specified
|
|
|
|
* when only the proxy host is specified
|
|
|
|
* when only the proxy port is specified
|
|
|
|
* This method conforms to the return code specified in
|
|
|
|
* http://developer.netscape.com/docs/manuals/proxy/adminnt/autoconf.htm#1020923
|
|
|
|
* with the exception that multiple values are not implemented.
|
|
|
|
*/
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::FindProxyForURL(const char* url, char* *result)
|
1998-09-01 00:17:25 +00:00
|
|
|
{
|
2000-10-05 07:58:51 +00:00
|
|
|
if (!url || !result) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsresult res;
|
1999-10-09 01:18:02 +00:00
|
|
|
const PRInt32 bufLen = 80;
|
|
|
|
char buf[bufLen];
|
2000-10-05 07:58:51 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uriIn;
|
|
|
|
nsCOMPtr<nsIProxyAutoConfig> pacService;
|
|
|
|
nsXPIDLCString protocol;
|
|
|
|
nsXPIDLCString type;
|
1999-10-09 01:18:02 +00:00
|
|
|
nsXPIDLCString proxyHost;
|
2000-07-20 19:09:50 +00:00
|
|
|
nsXPIDLCString noProxyList;
|
1999-10-09 01:18:02 +00:00
|
|
|
PRInt32 proxyPort = -1;
|
|
|
|
PRBool useDirect = PR_FALSE;
|
2000-10-05 07:58:51 +00:00
|
|
|
PRBool usePrefs = PR_TRUE;
|
2001-02-03 02:56:28 +00:00
|
|
|
PRInt32 proxyType = -1;
|
1999-10-09 01:18:02 +00:00
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &res);
|
|
|
|
|
2000-10-05 07:58:51 +00:00
|
|
|
if (NS_FAILED(res) || !prefs) {
|
1999-10-09 01:18:02 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIIOService, theService, kIOServiceCID, &res);
|
|
|
|
|
2000-10-05 07:58:51 +00:00
|
|
|
if (NS_FAILED(res) || !theService) {
|
|
|
|
return res;
|
1999-10-09 01:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make an nsURI from the argument url
|
2000-10-05 07:58:51 +00:00
|
|
|
res = theService->NewURI(url, nsnull, getter_AddRefs(uriIn));
|
1999-10-09 01:18:02 +00:00
|
|
|
if (NS_FAILED(res)) {
|
2000-10-05 07:58:51 +00:00
|
|
|
return res;
|
1999-10-09 01:18:02 +00:00
|
|
|
}
|
|
|
|
|
2000-10-05 07:58:51 +00:00
|
|
|
// FIRST, see if the ProxyAutoConfig service is activated and enabled
|
|
|
|
pacService = do_GetService("@mozilla.org/network/proxy_autoconfig;1");
|
|
|
|
if (pacService) {
|
|
|
|
|
|
|
|
// ASSUMPTION: the only time where it's appropriate to NOT look at
|
|
|
|
// the prefs is a successful return from PAC.
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(res = pacService->ProxyForURL(uriIn,
|
|
|
|
getter_Copies(proxyHost),
|
|
|
|
&proxyPort,
|
|
|
|
getter_Copies(type)))) {
|
|
|
|
if (PL_strstr(type, "direct")) {
|
|
|
|
usePrefs = PR_FALSE;
|
2000-07-20 19:09:50 +00:00
|
|
|
useDirect = PR_TRUE;
|
|
|
|
}
|
2000-10-05 07:58:51 +00:00
|
|
|
else {
|
|
|
|
if (proxyHost) {
|
|
|
|
usePrefs = PR_FALSE;
|
|
|
|
*result = PR_smprintf("PROXY %s:%d", (const char *) proxyHost,
|
|
|
|
proxyPort);
|
|
|
|
if (nsnull == *result) {
|
|
|
|
res = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-20 19:09:50 +00:00
|
|
|
}
|
1999-10-09 01:18:02 +00:00
|
|
|
}
|
2000-10-05 07:58:51 +00:00
|
|
|
if (usePrefs) {
|
2001-02-03 02:56:28 +00:00
|
|
|
// first, see if the prefs say, use "direct connection to the
|
|
|
|
// internet".
|
|
|
|
// see bug http://bugzilla.mozilla.org/show_bug.cgi?id=48336
|
|
|
|
res = prefs->GetIntPref("network.proxy.type", &proxyType);
|
|
|
|
if (NS_FAILED(res) || 0 == proxyType) {
|
|
|
|
useDirect = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (usePrefs && !useDirect) {
|
2000-10-05 07:58:51 +00:00
|
|
|
// If ProxyAutoConfig is not enabled, look to the prefs.
|
1999-10-09 01:18:02 +00:00
|
|
|
|
2000-10-05 07:58:51 +00:00
|
|
|
// If the host for this url is in the "no proxy for" list, just go
|
|
|
|
// direct.
|
|
|
|
res = prefs->CopyCharPref("network.proxy.no_proxies_on",
|
|
|
|
getter_Copies(noProxyList));
|
|
|
|
if (NS_SUCCEEDED(res) && nsCRT::strlen((const char *) noProxyList) > 0) {
|
|
|
|
res = uriIn->GetHost(getter_Copies(proxyHost));
|
|
|
|
if (NS_SUCCEEDED(res) && nsCRT::strlen(proxyHost) > 0) {
|
|
|
|
// tokenize the noProxyList, and scan each token for
|
|
|
|
// the proxyHost.
|
|
|
|
// if only one host in noProxyList
|
|
|
|
const char *comma = ",";
|
|
|
|
char *newStr;
|
|
|
|
char *token;
|
|
|
|
char *noProxyCopy = nsXPIDLCString::Copy(noProxyList);
|
|
|
|
if (!noProxyCopy) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
token = nsCRT::strtok( noProxyCopy, comma, &newStr );
|
|
|
|
while( token != NULL ) {
|
|
|
|
if (PL_strstr((const char *) token, (const char *) proxyHost)) {
|
|
|
|
useDirect = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
token = nsCRT::strtok( newStr, comma, &newStr );
|
|
|
|
}
|
|
|
|
nsCRT::free(noProxyCopy);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!useDirect) {
|
|
|
|
// get the scheme from this nsURI
|
|
|
|
res = uriIn->GetScheme(getter_Copies(protocol));
|
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2000-07-20 19:09:50 +00:00
|
|
|
|
2000-10-05 07:58:51 +00:00
|
|
|
PR_snprintf(buf, bufLen, "network.proxy.%s", (const char *) protocol);
|
|
|
|
res = prefs->CopyCharPref(buf, getter_Copies(proxyHost));
|
|
|
|
if (NS_SUCCEEDED(res) && nsCRT::strlen((const char *) proxyHost) > 0) {
|
|
|
|
PR_snprintf(buf, bufLen, "network.proxy.%s_port",
|
|
|
|
(const char *) protocol);
|
|
|
|
res = prefs->GetIntPref(buf, &proxyPort);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(res) && (proxyPort>0)) { // currently a bug in IntPref
|
|
|
|
// construct the return value
|
|
|
|
*result = PR_smprintf("PROXY %s:%d", (const char *) proxyHost,
|
|
|
|
proxyPort);
|
|
|
|
if (nsnull == *result) {
|
|
|
|
res = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
useDirect = PR_TRUE;
|
2000-07-20 19:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-05 07:58:51 +00:00
|
|
|
else {
|
2000-07-20 19:09:50 +00:00
|
|
|
useDirect = PR_TRUE;
|
1999-10-09 01:18:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-20 19:09:50 +00:00
|
|
|
|
1999-10-09 01:18:02 +00:00
|
|
|
if (useDirect) {
|
|
|
|
// construct the return value
|
|
|
|
*result = PR_smprintf("DIRECT");
|
|
|
|
if (nsnull == *result) {
|
|
|
|
res = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
1998-09-27 22:21:39 +00:00
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::RegisterWindow(nsIEventHandler* handler, nsPluginPlatformWindowRef window)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::UnregisterWindow(nsIEventHandler* handler, nsPluginPlatformWindowRef window)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::AllocateMenuID(nsIEventHandler* handler, PRBool isSubmenu, PRInt16 *result)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::DeallocateMenuID(nsIEventHandler* handler, PRInt16 menuID)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::HasAllocatedMenuID(nsIEventHandler* handler, PRInt16 menuID, PRBool *result)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::ProcessNextEvent(PRBool *bEventHandled)
|
1998-09-27 22:21:39 +00:00
|
|
|
{
|
1998-09-01 00:17:25 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1998-08-01 05:46:47 +00:00
|
|
|
}
|
1998-07-28 02:07:25 +00:00
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::CreateInstance(nsISupports *aOuter,
|
|
|
|
REFNSIID aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("how'd I get here?");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::LockFactory(PRBool aLock)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("how'd I get here?");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::Init(void)
|
1998-07-28 02:07:25 +00:00
|
|
|
{
|
1999-03-02 22:33:32 +00:00
|
|
|
return NS_OK;
|
1998-07-28 02:07:25 +00:00
|
|
|
}
|
|
|
|
|
1999-03-03 04:10:54 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::Destroy(void)
|
1998-09-15 03:48:58 +00:00
|
|
|
{
|
|
|
|
nsPluginTag *plug = mPlugins;
|
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
mActivePluginList.shut();
|
1999-05-17 21:26:48 +00:00
|
|
|
|
1998-09-15 03:48:58 +00:00
|
|
|
while (nsnull != plug)
|
|
|
|
{
|
|
|
|
if (nsnull != plug->mEntryPoint)
|
|
|
|
plug->mEntryPoint->Shutdown();
|
|
|
|
|
|
|
|
plug = plug->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/* Called by nsPluginInstanceOwner (nsObjectFrame.cpp - embeded case) */
|
1998-08-21 01:12:53 +00:00
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType,
|
|
|
|
nsIURI* aURL,
|
|
|
|
nsIPluginInstanceOwner *aOwner)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-03-11 22:48:58 +00:00
|
|
|
nsIPluginInstance *instance = nsnull;
|
2000-06-20 21:04:52 +00:00
|
|
|
nsCOMPtr<nsIPluginTagInfo2> pti2 = nsnull;
|
|
|
|
nsPluginTagType tagType;
|
|
|
|
PRBool isJavaEnabled = PR_TRUE;
|
|
|
|
|
|
|
|
rv = aOwner->QueryInterface(kIPluginTagInfo2IID, getter_AddRefs(pti2));
|
|
|
|
|
|
|
|
if(rv != NS_OK) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = pti2->GetTagType(&tagType);
|
|
|
|
|
2000-06-21 22:57:17 +00:00
|
|
|
if((rv != NS_OK) || !((tagType == nsPluginTagType_Embed)
|
2000-06-22 23:17:50 +00:00
|
|
|
|| (tagType == nsPluginTagType_Applet)
|
|
|
|
|| (tagType == nsPluginTagType_Object)))
|
|
|
|
{
|
2000-06-20 21:04:52 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-08-21 01:12:53 +00:00
|
|
|
|
2000-06-30 17:31:02 +00:00
|
|
|
if (tagType == nsPluginTagType_Applet) {
|
|
|
|
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
|
|
|
|
// see if java is enabled
|
|
|
|
if (prefs) {
|
|
|
|
rv = prefs->GetBoolPref("security.enable_java", &isJavaEnabled);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// if not, don't show this plugin
|
|
|
|
if (!isJavaEnabled) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if we were unable to get the pref, assume java is enabled
|
|
|
|
// and rely on the "find the plugin or not" logic.
|
|
|
|
|
|
|
|
// make sure the value wasn't modified in GetBoolPref
|
|
|
|
isJavaEnabled = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-07 00:28:34 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-08-17 19:26:15 +00:00
|
|
|
if(aMimeType)
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("InstantiateEmbededPlugin for %s\n",aMimeType);
|
1999-07-07 00:28:34 +00:00
|
|
|
#endif
|
|
|
|
|
1999-05-07 22:06:47 +00:00
|
|
|
if(FindStoppedPluginForURL(aURL, aOwner) == NS_OK)
|
|
|
|
{
|
1999-07-07 00:28:34 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("InstantiateEmbededPlugin find stopped\n");
|
1999-07-07 00:28:34 +00:00
|
|
|
#endif
|
|
|
|
|
1999-05-07 22:06:47 +00:00
|
|
|
aOwner->GetInstance(instance);
|
|
|
|
if(!aMimeType || PL_strcasecmp(aMimeType, "application/x-java-vm"))
|
|
|
|
rv = NewEmbededPluginStream(aURL, nsnull, instance);
|
2000-05-16 00:22:30 +00:00
|
|
|
|
|
|
|
// notify Java DOM component
|
|
|
|
nsresult res;
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIPluginInstanceOwner, javaDOM, "@mozilla.org/blackwood/java-dom;1", &res);
|
2000-05-16 00:22:30 +00:00
|
|
|
if (NS_SUCCEEDED(res) && javaDOM)
|
|
|
|
javaDOM->SetInstance(instance);
|
|
|
|
|
2000-05-02 22:27:58 +00:00
|
|
|
NS_IF_RELEASE(instance);
|
1999-05-07 22:06:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-10 23:49:19 +00:00
|
|
|
// if we don't have a MIME type at this point, we still have one more chance by
|
|
|
|
// opening the stream and seeing if the server hands one back
|
|
|
|
if (!aMimeType)
|
|
|
|
if (aURL)
|
|
|
|
{
|
|
|
|
rv = NewEmbededPluginStream(aURL, aOwner, nsnull);
|
|
|
|
return rv;
|
|
|
|
} else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
rv = SetUpPluginInstance(aMimeType, aURL, aOwner);
|
1999-05-07 22:06:47 +00:00
|
|
|
|
1999-03-11 22:48:58 +00:00
|
|
|
if(rv == NS_OK)
|
1999-05-07 22:06:47 +00:00
|
|
|
rv = aOwner->GetInstance(instance);
|
2000-06-20 21:04:52 +00:00
|
|
|
else
|
2000-05-26 22:14:39 +00:00
|
|
|
{
|
2001-01-10 23:49:19 +00:00
|
|
|
// We have the mime type either supplied in source or from the header.
|
|
|
|
// Let's try to render the default plugin. See bug 41197
|
|
|
|
|
2000-05-06 06:00:48 +00:00
|
|
|
// We were unable to find a plug-in yet we
|
|
|
|
// really do have mime type. Return the error
|
|
|
|
// so that the nsObjectFrame can render any
|
|
|
|
// alternate content.
|
2000-05-26 22:14:39 +00:00
|
|
|
|
|
|
|
// but try to load the default plugin first. We need to do this
|
|
|
|
// for <embed> tag leaving <object> to play with its alt content.
|
|
|
|
// but before we return an error let's see if this is an <embed>
|
|
|
|
// tag and try to launch the default plugin
|
2000-06-21 22:57:17 +00:00
|
|
|
|
2000-06-22 23:17:50 +00:00
|
|
|
// but to comply with the spec don't do it for <object> tag
|
|
|
|
if(tagType == nsPluginTagType_Object)
|
|
|
|
return rv;
|
|
|
|
|
2000-06-20 21:04:52 +00:00
|
|
|
nsresult result;
|
2000-05-26 22:14:39 +00:00
|
|
|
|
|
|
|
result = SetUpDefaultPluginInstance(aMimeType, aURL, aOwner);
|
|
|
|
|
|
|
|
if(result == NS_OK)
|
|
|
|
result = aOwner->GetInstance(instance);
|
|
|
|
|
2000-06-20 21:04:52 +00:00
|
|
|
if(result != NS_OK) {
|
2000-07-20 22:53:32 +00:00
|
|
|
DisplayNoDefaultPluginDialog(aMimeType);
|
2000-06-20 21:04:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-05-26 22:14:39 +00:00
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
1998-08-21 01:12:53 +00:00
|
|
|
|
1999-03-23 03:18:12 +00:00
|
|
|
// if we have a failure error, it means we found a plugin for the mimetype,
|
|
|
|
// but we had a problem with the entry point
|
|
|
|
if(rv == NS_ERROR_FAILURE)
|
|
|
|
return rv;
|
|
|
|
|
2001-01-10 23:49:19 +00:00
|
|
|
// if we are here then we have loaded a plugin for this mimetype
|
|
|
|
// and it could be the Default plugin
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
nsPluginWindow *window = nsnull;
|
1998-08-21 01:12:53 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
//we got a plugin built, now stream
|
|
|
|
aOwner->GetWindow(window);
|
1998-08-21 01:12:53 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
if (nsnull != instance)
|
|
|
|
{
|
|
|
|
instance->Start();
|
|
|
|
aOwner->CreateWidget();
|
2000-07-20 01:40:54 +00:00
|
|
|
|
|
|
|
// If we've got a native window, the let the plugin know about it.
|
|
|
|
if (window->window)
|
|
|
|
instance->SetWindow(window);
|
1998-08-21 01:12:53 +00:00
|
|
|
|
1999-04-06 01:53:37 +00:00
|
|
|
// don't make an initial steam if it's a java applet
|
2000-04-22 20:50:22 +00:00
|
|
|
if(!aMimeType ||
|
|
|
|
(PL_strcasecmp(aMimeType, "application/x-java-vm") != 0 &&
|
|
|
|
PL_strcasecmp(aMimeType, "application/x-java-applet") != 0))
|
1999-05-08 15:19:06 +00:00
|
|
|
rv = NewEmbededPluginStream(aURL, nsnull, instance);
|
1998-08-21 01:12:53 +00:00
|
|
|
|
2000-05-16 00:22:30 +00:00
|
|
|
// notify Java DOM component
|
|
|
|
nsresult res;
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIPluginInstanceOwner, javaDOM, "@mozilla.org/blackwood/java-dom;1", &res);
|
2000-05-16 00:22:30 +00:00
|
|
|
if (NS_SUCCEEDED(res) && javaDOM)
|
|
|
|
javaDOM->SetInstance(instance);
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
NS_RELEASE(instance);
|
|
|
|
}
|
1998-08-21 01:12:53 +00:00
|
|
|
|
1999-07-07 00:28:34 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("InstantiateEmbededPlugin.. returning\n");
|
1999-07-07 00:28:34 +00:00
|
|
|
#endif
|
1999-01-25 08:05:00 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-08-21 01:12:53 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/* Called by nsPluginViewer.cpp (full-page case) */
|
1998-07-28 02:07:25 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::InstantiateFullPagePlugin(const char *aMimeType,
|
|
|
|
nsString& aURLSpec,
|
|
|
|
nsIStreamListener *&aStreamListener,
|
|
|
|
nsIPluginInstanceOwner *aOwner)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI *url;
|
2000-06-20 21:04:52 +00:00
|
|
|
PRBool isJavaEnabled = PR_TRUE;
|
1998-07-28 02:07:25 +00:00
|
|
|
|
1999-07-07 00:28:34 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("InstantiateFullPagePlugin for %s\n",aMimeType);
|
1999-07-07 00:28:34 +00:00
|
|
|
#endif
|
2000-06-30 17:31:02 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
//create a URL so that the instantiator can do file ext.
|
|
|
|
//based plugin lookups...
|
1999-06-28 10:35:57 +00:00
|
|
|
rv = NS_NewURI(&url, aURLSpec);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
if (rv != NS_OK)
|
|
|
|
url = nsnull;
|
1999-05-07 22:06:47 +00:00
|
|
|
|
|
|
|
if(FindStoppedPluginForURL(url, aOwner) == NS_OK)
|
|
|
|
{
|
1999-07-07 00:28:34 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("InstantiateFullPagePlugin, got a stopped plugin\n");
|
1999-07-07 00:28:34 +00:00
|
|
|
#endif
|
|
|
|
|
1999-05-07 22:06:47 +00:00
|
|
|
nsIPluginInstance* instance;
|
|
|
|
aOwner->GetInstance(instance);
|
|
|
|
if(!aMimeType || PL_strcasecmp(aMimeType, "application/x-java-vm"))
|
|
|
|
rv = NewFullPagePluginStream(aStreamListener, instance);
|
2000-05-02 22:27:58 +00:00
|
|
|
NS_IF_RELEASE(instance);
|
1999-05-07 22:06:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
rv = SetUpPluginInstance(aMimeType, url, aOwner);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(url);
|
|
|
|
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
nsIPluginInstance *instance = nsnull;
|
|
|
|
nsPluginWindow *window = nsnull;
|
|
|
|
|
1999-07-07 00:28:34 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("InstantiateFullPagePlugin, got it... now stream\n");
|
1999-07-07 00:28:34 +00:00
|
|
|
#endif
|
1999-01-25 08:05:00 +00:00
|
|
|
//we got a plugin built, now stream
|
|
|
|
|
|
|
|
aOwner->GetInstance(instance);
|
|
|
|
aOwner->GetWindow(window);
|
|
|
|
|
|
|
|
if (nsnull != instance)
|
|
|
|
{
|
|
|
|
instance->Start();
|
|
|
|
aOwner->CreateWidget();
|
2000-07-20 01:40:54 +00:00
|
|
|
|
|
|
|
// If we've got a native window, the let the plugin know about it.
|
|
|
|
if (window->window)
|
|
|
|
instance->SetWindow(window);
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
rv = NewFullPagePluginStream(aStreamListener, instance);
|
|
|
|
|
|
|
|
NS_RELEASE(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Falling out of InstantiateFullPagePlugin...\n");
|
2000-04-22 20:50:22 +00:00
|
|
|
#endif
|
1999-01-25 08:05:00 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURI* aURL,
|
|
|
|
nsIPluginInstanceOwner *aOwner)
|
1999-05-07 22:06:47 +00:00
|
|
|
{
|
1999-06-28 10:35:57 +00:00
|
|
|
char* url;
|
1999-05-17 21:26:48 +00:00
|
|
|
if(!aURL)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
#ifdef NS_DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Inside nsPluginHostImpl::FindStoppedPluginForURL...\n");
|
2000-04-22 20:50:22 +00:00
|
|
|
#endif
|
|
|
|
|
1999-05-07 22:06:47 +00:00
|
|
|
(void)aURL->GetSpec(&url);
|
2000-06-13 23:23:13 +00:00
|
|
|
|
|
|
|
nsActivePlugin * plugin = mActivePluginList.findStopped(url);
|
1999-05-07 22:06:47 +00:00
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
if((plugin != nsnull) && (plugin->mStopped))
|
1999-05-07 22:06:47 +00:00
|
|
|
{
|
2000-06-13 23:23:13 +00:00
|
|
|
nsIPluginInstance* instance = plugin->mInstance;
|
|
|
|
nsPluginWindow *window = nsnull;
|
|
|
|
aOwner->GetWindow(window);
|
1999-05-07 22:06:47 +00:00
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
aOwner->SetInstance(instance);
|
1999-05-07 22:06:47 +00:00
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
// we have to reset the owner and instance in the plugin instance peer
|
|
|
|
//instance->GetPeer(&peer);
|
|
|
|
((nsPluginInstancePeerImpl*)plugin->mPeer)->SetOwner(aOwner);
|
1999-05-07 22:06:47 +00:00
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
instance->Start();
|
|
|
|
aOwner->CreateWidget();
|
2000-07-20 01:40:54 +00:00
|
|
|
|
|
|
|
// If we've got a native window, the let the plugin know about it.
|
|
|
|
if (window->window)
|
|
|
|
instance->SetWindow(window);
|
1999-05-07 22:06:47 +00:00
|
|
|
|
2000-06-15 01:07:27 +00:00
|
|
|
plugin->setStopped(PR_FALSE);
|
2000-06-13 23:23:13 +00:00
|
|
|
nsCRT::free(url);
|
|
|
|
return NS_OK;
|
1999-05-07 22:06:47 +00:00
|
|
|
}
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(url);
|
1999-05-07 22:06:47 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
void nsPluginHostImpl::AddInstanceToActiveList(nsIPluginInstance* aInstance,
|
2001-02-02 23:48:17 +00:00
|
|
|
nsIURI* aURL,
|
|
|
|
PRBool aDefaultPlugin)
|
2000-09-14 08:22:31 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
{
|
2000-09-14 08:22:31 +00:00
|
|
|
// first, determine if the plugin wants to be cached
|
2001-02-02 23:48:17 +00:00
|
|
|
// Code moved to StopPluginInstance as we still need running
|
|
|
|
// plugins to be present in the 'active' list
|
2000-09-14 08:22:31 +00:00
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
char* url;
|
1999-11-02 23:34:03 +00:00
|
|
|
|
1999-05-17 21:26:48 +00:00
|
|
|
if(!aURL)
|
|
|
|
return;
|
|
|
|
|
1999-05-07 22:06:47 +00:00
|
|
|
(void)aURL->GetSpec(&url);
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
nsActivePlugin * plugin = new nsActivePlugin(aInstance, url, aDefaultPlugin);
|
1999-05-07 22:06:47 +00:00
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
if(plugin == nsnull)
|
|
|
|
return;
|
2000-04-26 06:19:26 +00:00
|
|
|
|
2000-06-13 23:23:13 +00:00
|
|
|
mActivePluginList.add(plugin);
|
2000-04-26 06:19:26 +00:00
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(url);
|
1999-05-07 22:06:47 +00:00
|
|
|
}
|
|
|
|
|
2000-07-07 00:10:54 +00:00
|
|
|
nsresult nsPluginHostImpl::RegisterPluginMimeTypesWithLayout(nsPluginTag * pluginTag,
|
|
|
|
nsIComponentManager * compManager,
|
2000-07-22 01:34:13 +00:00
|
|
|
nsIFile * path)
|
2000-07-07 00:10:54 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(pluginTag);
|
|
|
|
NS_ENSURE_ARG_POINTER(pluginTag->mMimeTypeArray);
|
|
|
|
NS_ENSURE_ARG_POINTER(compManager);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
for(int i = 0; i < pluginTag->mVariants; i++)
|
|
|
|
{
|
2000-07-22 01:34:13 +00:00
|
|
|
static NS_DEFINE_CID(kPluginDocLoaderFactoryCID, NS_PLUGINDOCLOADERFACTORY_CID);
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
nsCAutoString contractid(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=");
|
|
|
|
contractid += pluginTag->mMimeTypeArray[i];
|
2000-07-22 01:34:13 +00:00
|
|
|
|
|
|
|
rv = compManager->RegisterComponentSpec(kPluginDocLoaderFactoryCID,
|
|
|
|
"Plugin Loader Stub",
|
2000-09-13 23:57:52 +00:00
|
|
|
contractid,
|
2000-07-22 01:34:13 +00:00
|
|
|
path,
|
|
|
|
PR_TRUE,
|
|
|
|
PR_FALSE);
|
2000-07-07 00:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-03-03 04:10:54 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI *aURL,
|
1999-03-03 04:10:54 +00:00
|
|
|
nsIPluginInstanceOwner *aOwner)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
1999-07-25 23:20:03 +00:00
|
|
|
nsIPluginInstance* instance = NULL;
|
1999-03-03 04:10:54 +00:00
|
|
|
nsIPlugin* plugin = NULL;
|
1999-03-29 22:18:05 +00:00
|
|
|
const char* mimetype;
|
2000-09-13 23:57:52 +00:00
|
|
|
nsString strContractID; strContractID.AssignWithConversion (NS_INLINE_PLUGIN_CONTRACTID_PREFIX);
|
1999-07-25 23:20:03 +00:00
|
|
|
char buf[255]; // todo: need to use a const
|
1999-05-17 21:26:48 +00:00
|
|
|
|
|
|
|
if(!aURL)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
// if don't have a mimetype, check by file extension
|
|
|
|
if(!aMimeType)
|
|
|
|
{
|
|
|
|
char* extension;
|
1999-05-17 21:26:48 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
char* filename;
|
1999-06-25 01:41:26 +00:00
|
|
|
aURL->GetPath(&filename);
|
1999-03-29 22:18:05 +00:00
|
|
|
extension = PL_strrchr(filename, '.');
|
|
|
|
if(extension)
|
|
|
|
++extension;
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if(IsPluginEnabledForExtension(extension, mimetype) != NS_OK)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-06-28 10:35:57 +00:00
|
|
|
nsCRT::free(filename);
|
1999-03-29 22:18:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
mimetype = aMimeType;
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
strContractID.AppendWithConversion(mimetype);
|
|
|
|
strContractID.ToCString(buf, 255); // todo: need to use a const
|
1999-07-25 23:20:03 +00:00
|
|
|
|
|
|
|
result = nsComponentManager::CreateInstance(buf,
|
|
|
|
nsnull,
|
2000-04-22 20:50:22 +00:00
|
|
|
nsIPluginInstance::GetIID(),
|
1999-07-25 23:20:03 +00:00
|
|
|
(void**)&instance);
|
|
|
|
|
1999-08-03 00:17:55 +00:00
|
|
|
|
1999-07-25 23:20:03 +00:00
|
|
|
// couldn't create an XPCOM plugin, try to create wrapper for a legacy plugin
|
|
|
|
if (NS_FAILED(result)) {
|
1999-08-03 00:17:55 +00:00
|
|
|
result = GetPluginFactory(mimetype, &plugin);
|
2000-04-22 20:50:22 +00:00
|
|
|
if(!NS_FAILED(result)){
|
|
|
|
result = plugin->CreateInstance(NULL, kIPluginInstanceIID, (void **)&instance);
|
1999-07-25 23:20:03 +00:00
|
|
|
NS_RELEASE(plugin);
|
|
|
|
}
|
1999-11-16 04:18:59 +00:00
|
|
|
if (NS_FAILED(result)) {
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIPlugin, plugin, "@mozilla.org/blackwood/pluglet-engine;1",&result);
|
1999-11-16 04:18:59 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = plugin->CreatePluginInstance(NULL, kIPluginInstanceIID, aMimeType,(void **)&instance);
|
|
|
|
}
|
|
|
|
}
|
1999-07-25 23:20:03 +00:00
|
|
|
}
|
1999-03-29 22:18:05 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
// neither an XPCOM or legacy plugin could be instantiated,
|
|
|
|
// so return the failure
|
1999-08-03 00:17:55 +00:00
|
|
|
if (NS_FAILED(result)){
|
1999-07-25 23:20:03 +00:00
|
|
|
return result;
|
|
|
|
}
|
1999-03-03 04:10:54 +00:00
|
|
|
|
2000-04-26 06:19:26 +00:00
|
|
|
// it is adreffed here
|
1999-07-25 23:20:03 +00:00
|
|
|
aOwner->SetInstance(instance);
|
1999-03-03 04:10:54 +00:00
|
|
|
|
1999-07-25 23:20:03 +00:00
|
|
|
nsPluginInstancePeerImpl *peer = new nsPluginInstancePeerImpl();
|
1999-07-30 23:51:53 +00:00
|
|
|
if(peer == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-03 04:10:54 +00:00
|
|
|
|
1999-07-25 23:20:03 +00:00
|
|
|
// set up the peer for the instance
|
2000-04-22 00:04:24 +00:00
|
|
|
peer->Initialize(aOwner, mimetype);
|
|
|
|
|
|
|
|
nsIPluginInstancePeer *pi;
|
|
|
|
|
|
|
|
result = peer->QueryInterface(kIPluginInstancePeerIID, (void **)&pi);
|
|
|
|
|
|
|
|
if(result != NS_OK)
|
|
|
|
return result;
|
1999-05-07 22:06:47 +00:00
|
|
|
|
1999-07-25 23:20:03 +00:00
|
|
|
// tell the plugin instance to initialize itself and pass in the peer.
|
2000-04-22 00:04:24 +00:00
|
|
|
instance->Initialize(pi); // this will not add a ref to the instance (or owner). MMP
|
|
|
|
|
|
|
|
NS_RELEASE(pi);
|
1999-07-25 23:20:03 +00:00
|
|
|
|
2000-04-26 06:19:26 +00:00
|
|
|
// we should addref here
|
1999-07-25 23:20:03 +00:00
|
|
|
AddInstanceToActiveList(instance, aURL);
|
|
|
|
|
2000-04-26 06:19:26 +00:00
|
|
|
//release what was addreffed in Create(Plugin)Instance
|
|
|
|
NS_RELEASE(instance);
|
1999-07-25 23:20:03 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-03-03 04:10:54 +00:00
|
|
|
}
|
|
|
|
|
2000-05-26 22:14:39 +00:00
|
|
|
nsresult nsPluginHostImpl::SetUpDefaultPluginInstance(const char *aMimeType, nsIURI *aURL,
|
|
|
|
nsIPluginInstanceOwner *aOwner)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
|
|
|
nsIPluginInstance* instance = NULL;
|
|
|
|
nsIPlugin* plugin = NULL;
|
|
|
|
const char* mimetype;
|
2000-09-13 23:57:52 +00:00
|
|
|
nsString strContractID; strContractID.AssignWithConversion (NS_INLINE_PLUGIN_CONTRACTID_PREFIX);
|
2000-05-26 22:14:39 +00:00
|
|
|
char buf[255]; // todo: need to use a const
|
|
|
|
|
|
|
|
if(!aURL)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mimetype = aMimeType;
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
strContractID.AppendWithConversion("*");
|
|
|
|
strContractID.ToCString(buf, 255); // todo: need to use a const
|
2000-05-26 22:14:39 +00:00
|
|
|
|
|
|
|
result = nsComponentManager::CreateInstance(buf, nsnull, nsIPluginInstance::GetIID(), (void**)&instance);
|
|
|
|
|
|
|
|
// couldn't create an XPCOM plugin, try to create wrapper for a legacy plugin
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
{
|
|
|
|
result = GetPluginFactory("*", &plugin);
|
|
|
|
if(!NS_FAILED(result))
|
|
|
|
{
|
|
|
|
result = plugin->CreateInstance(NULL, kIPluginInstanceIID, (void **)&instance);
|
|
|
|
NS_RELEASE(plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// neither an XPCOM or legacy plugin could be instantiated, so return the failure
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// it is adreffed here
|
|
|
|
aOwner->SetInstance(instance);
|
|
|
|
|
|
|
|
nsPluginInstancePeerImpl *peer = new nsPluginInstancePeerImpl();
|
|
|
|
if(peer == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2000-09-22 06:31:29 +00:00
|
|
|
// if we don't have a mimetype, check by file extension
|
|
|
|
nsXPIDLCString mt;
|
|
|
|
if(mimetype == nsnull)
|
|
|
|
{
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(aURL);
|
|
|
|
if(url)
|
|
|
|
{
|
|
|
|
nsXPIDLCString extension;
|
|
|
|
url->GetFileExtension(getter_Copies(extension));
|
|
|
|
|
|
|
|
if(extension)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMIMEService> ms (do_GetService(NS_MIMESERVICE_CONTRACTID, &res));
|
|
|
|
if(NS_SUCCEEDED(res) && ms)
|
|
|
|
{
|
|
|
|
res = ms->GetTypeFromExtension(extension, getter_Copies(mt));
|
|
|
|
if(NS_SUCCEEDED(res))
|
|
|
|
mimetype = mt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-26 22:14:39 +00:00
|
|
|
// set up the peer for the instance
|
|
|
|
peer->Initialize(aOwner, mimetype);
|
|
|
|
|
|
|
|
nsIPluginInstancePeer *pi;
|
|
|
|
|
|
|
|
result = peer->QueryInterface(kIPluginInstancePeerIID, (void **)&pi);
|
|
|
|
|
|
|
|
if(result != NS_OK)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// tell the plugin instance to initialize itself and pass in the peer.
|
|
|
|
instance->Initialize(pi); // this will not add a ref to the instance (or owner). MMP
|
|
|
|
|
|
|
|
NS_RELEASE(pi);
|
|
|
|
|
|
|
|
// we should addref here
|
2001-02-02 23:48:17 +00:00
|
|
|
AddInstanceToActiveList(instance, aURL, PR_TRUE);
|
2000-05-26 22:14:39 +00:00
|
|
|
|
|
|
|
//release what was addreffed in Create(Plugin)Instance
|
|
|
|
NS_RELEASE(instance);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginHostImpl::IsPluginEnabledForType(const char* aMimeType)
|
1999-01-25 08:05:00 +00:00
|
|
|
{
|
|
|
|
nsPluginTag *plugins = nsnull;
|
|
|
|
PRInt32 variants, cnt;
|
|
|
|
|
2000-08-17 19:26:15 +00:00
|
|
|
LoadPlugins();
|
1999-01-25 08:05:00 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
// if we have a mimetype passed in, search the mPlugins linked
|
|
|
|
// list for a match
|
1999-01-25 08:05:00 +00:00
|
|
|
if (nsnull != aMimeType)
|
|
|
|
{
|
|
|
|
plugins = mPlugins;
|
|
|
|
|
|
|
|
while (nsnull != plugins)
|
|
|
|
{
|
|
|
|
variants = plugins->mVariants;
|
|
|
|
|
|
|
|
for (cnt = 0; cnt < variants; cnt++)
|
2000-07-11 21:44:39 +00:00
|
|
|
if (plugins->mMimeTypeArray[cnt] && (0 == strcmp(plugins->mMimeTypeArray[cnt], aMimeType)))
|
1999-03-29 22:18:05 +00:00
|
|
|
return NS_OK;
|
1999-01-25 08:05:00 +00:00
|
|
|
|
|
|
|
if (cnt < variants)
|
|
|
|
break;
|
|
|
|
|
|
|
|
plugins = plugins->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-01-25 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
1999-09-01 19:58:22 +00:00
|
|
|
// check comma delimetered extensions
|
|
|
|
static int CompareExtensions(const char *aExtensionList, const char *aExtension)
|
|
|
|
{
|
|
|
|
if((aExtensionList == nsnull) || (aExtension == nsnull))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
const char *pExt = aExtensionList;
|
1999-11-12 23:55:01 +00:00
|
|
|
const char *pComma = strchr(pExt, ',');
|
1999-09-01 19:58:22 +00:00
|
|
|
|
|
|
|
if(pComma == nsnull)
|
|
|
|
return strcmp(pExt, aExtension);
|
|
|
|
|
|
|
|
while(pComma != nsnull)
|
|
|
|
{
|
|
|
|
int length = pComma - pExt;
|
|
|
|
if(0 == strncmp(pExt, aExtension, length))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pComma++;
|
|
|
|
pExt = pComma;
|
|
|
|
pComma = strchr(pExt, ',');
|
|
|
|
}
|
|
|
|
|
|
|
|
// the last one
|
|
|
|
return strcmp(pExt, aExtension);
|
|
|
|
}
|
|
|
|
|
1999-03-23 03:18:12 +00:00
|
|
|
NS_IMETHODIMP
|
2000-04-22 20:50:22 +00:00
|
|
|
nsPluginHostImpl::IsPluginEnabledForExtension(const char* aExtension,
|
|
|
|
const char* &aMimeType)
|
1999-03-23 03:18:12 +00:00
|
|
|
{
|
|
|
|
nsPluginTag *plugins = nsnull;
|
|
|
|
PRInt32 variants, cnt;
|
|
|
|
|
2000-08-17 19:26:15 +00:00
|
|
|
LoadPlugins();
|
1999-03-23 03:18:12 +00:00
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
// if we have a mimetype passed in, search the mPlugins linked
|
|
|
|
// list for a match
|
1999-03-29 22:18:05 +00:00
|
|
|
if (nsnull != aExtension)
|
1999-03-23 03:18:12 +00:00
|
|
|
{
|
|
|
|
plugins = mPlugins;
|
|
|
|
|
|
|
|
while (nsnull != plugins)
|
|
|
|
{
|
|
|
|
variants = plugins->mVariants;
|
|
|
|
|
|
|
|
for (cnt = 0; cnt < variants; cnt++)
|
|
|
|
{
|
1999-09-01 19:58:22 +00:00
|
|
|
//if (0 == strcmp(plugins->mExtensionsArray[cnt], aExtension))
|
2000-04-22 20:50:22 +00:00
|
|
|
// mExtensionsArray[cnt] could be not a single extension but
|
|
|
|
// rather a list separated by commas
|
1999-09-01 19:58:22 +00:00
|
|
|
if (0 == CompareExtensions(plugins->mExtensionsArray[cnt], aExtension))
|
|
|
|
{
|
|
|
|
aMimeType = plugins->mMimeTypeArray[cnt];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
1999-03-23 03:18:12 +00:00
|
|
|
|
|
|
|
if (cnt < variants)
|
|
|
|
break;
|
|
|
|
|
|
|
|
plugins = plugins->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
class DOMMimeTypeImpl : public nsIDOMMimeType {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
DOMMimeTypeImpl(nsPluginTag* aPluginTag, PRUint32 aMimeTypeIndex)
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
2000-04-03 09:20:26 +00:00
|
|
|
mDescription.AssignWithConversion(aPluginTag->mMimeDescriptionArray[aMimeTypeIndex]);
|
|
|
|
mSuffixes.AssignWithConversion(aPluginTag->mExtensionsArray[aMimeTypeIndex]);
|
|
|
|
mType.AssignWithConversion(aPluginTag->mMimeTypeArray[aMimeTypeIndex]);
|
1999-04-20 19:29:28 +00:00
|
|
|
}
|
|
|
|
|
1999-05-13 02:17:09 +00:00
|
|
|
virtual ~DOMMimeTypeImpl() {
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_METHOD GetDescription(nsAWritableString& aDescription)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aDescription.Assign(mDescription);
|
1999-04-20 19:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin)
|
|
|
|
{
|
|
|
|
// this has to be implemented by the DOM version.
|
|
|
|
*aEnabledPlugin = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_METHOD GetSuffixes(nsAWritableString& aSuffixes)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aSuffixes.Assign(mSuffixes);
|
1999-04-20 19:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_METHOD GetType(nsAWritableString& aType)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aType.Assign(mType);
|
1999-04-20 19:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsString mDescription;
|
|
|
|
nsString mSuffixes;
|
|
|
|
nsString mType;
|
|
|
|
};
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
NS_IMPL_ISUPPORTS(DOMMimeTypeImpl, nsIDOMMimeType::GetIID());
|
1999-04-20 19:29:28 +00:00
|
|
|
|
|
|
|
class DOMPluginImpl : public nsIDOMPlugin {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
DOMPluginImpl(nsPluginTag* aPluginTag) : mPluginTag(aPluginTag)
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
1999-05-13 02:17:09 +00:00
|
|
|
virtual ~DOMPluginImpl() {
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_METHOD GetDescription(nsAWritableString& aDescription)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aDescription.Assign(NS_ConvertASCIItoUCS2(mPluginTag.mDescription));
|
1999-04-20 19:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_METHOD GetFilename(nsAWritableString& aFilename)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aFilename.Assign(NS_ConvertASCIItoUCS2(mPluginTag.mFileName));
|
1999-04-20 19:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_METHOD GetName(nsAWritableString& aName)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aName.Assign(NS_ConvertASCIItoUCS2(mPluginTag.mName));
|
1999-04-20 19:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
*aLength = mPluginTag.mVariants;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD Item(PRUint32 aIndex, nsIDOMMimeType** aReturn)
|
|
|
|
{
|
|
|
|
nsIDOMMimeType* mimeType = new DOMMimeTypeImpl(&mPluginTag, aIndex);
|
|
|
|
NS_IF_ADDREF(mimeType);
|
|
|
|
*aReturn = mimeType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
NS_METHOD NamedItem(const nsAReadableString& aName, nsIDOMMimeType** aReturn)
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
|
|
|
for (int index = mPluginTag.mVariants - 1; index >= 0; --index) {
|
2000-08-23 17:27:06 +00:00
|
|
|
if (aName.Equals(NS_ConvertASCIItoUCS2(mPluginTag.mMimeTypeArray[index])))
|
1999-04-20 19:29:28 +00:00
|
|
|
return Item(index, aReturn);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsPluginTag mPluginTag;
|
|
|
|
};
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
NS_IMPL_ISUPPORTS(DOMPluginImpl, nsIDOMPlugin::GetIID());
|
1999-04-20 19:29:28 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginHostImpl::GetPluginCount(PRUint32* aPluginCount)
|
|
|
|
{
|
2000-08-17 19:26:15 +00:00
|
|
|
LoadPlugins();
|
|
|
|
|
|
|
|
PRUint32 count = 0;
|
|
|
|
|
|
|
|
nsPluginTag* plugin = mPlugins;
|
|
|
|
while (plugin != nsnull) {
|
|
|
|
++count;
|
|
|
|
plugin = plugin->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aPluginCount = count;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-04-20 19:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-22 20:50:22 +00:00
|
|
|
nsPluginHostImpl::GetPlugins(PRUint32 aPluginCount,
|
|
|
|
nsIDOMPlugin* aPluginArray[])
|
1999-04-20 19:29:28 +00:00
|
|
|
{
|
2000-08-17 19:26:15 +00:00
|
|
|
LoadPlugins();
|
2000-04-22 20:50:22 +00:00
|
|
|
|
|
|
|
nsPluginTag* plugin = mPlugins;
|
|
|
|
for (PRUint32 i = 0; i < aPluginCount && plugin != nsnull;
|
|
|
|
i++, plugin = plugin->mNext) {
|
|
|
|
nsIDOMPlugin* domPlugin = new DOMPluginImpl(plugin);
|
|
|
|
NS_IF_ADDREF(domPlugin);
|
|
|
|
aPluginArray[i] = domPlugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-04-20 19:29:28 +00:00
|
|
|
}
|
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
nsresult
|
2000-04-22 20:50:22 +00:00
|
|
|
nsPluginHostImpl::FindPluginEnabledForType(const char* aMimeType,
|
|
|
|
nsPluginTag* &aPlugin)
|
1999-03-23 03:18:12 +00:00
|
|
|
{
|
|
|
|
nsPluginTag *plugins = nsnull;
|
|
|
|
PRInt32 variants, cnt;
|
2000-04-22 20:50:22 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
aPlugin = nsnull;
|
2000-04-22 20:50:22 +00:00
|
|
|
|
2000-08-17 19:26:15 +00:00
|
|
|
LoadPlugins();
|
2000-04-22 20:50:22 +00:00
|
|
|
|
|
|
|
// if we have a mimetype passed in, search the mPlugins
|
|
|
|
// linked list for a match
|
|
|
|
if (nsnull != aMimeType) {
|
1999-03-23 03:18:12 +00:00
|
|
|
plugins = mPlugins;
|
2000-04-22 20:50:22 +00:00
|
|
|
|
|
|
|
while (nsnull != plugins) {
|
1999-03-23 03:18:12 +00:00
|
|
|
variants = plugins->mVariants;
|
2000-04-22 20:50:22 +00:00
|
|
|
|
|
|
|
for (cnt = 0; cnt < variants; cnt++) {
|
2000-07-11 21:44:39 +00:00
|
|
|
if (plugins->mMimeTypeArray[cnt] && (0 == strcmp(plugins->mMimeTypeArray[cnt], aMimeType))) {
|
1999-07-06 04:14:54 +00:00
|
|
|
aPlugin = plugins;
|
2000-04-22 20:50:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
1999-03-23 03:18:12 +00:00
|
|
|
|
|
|
|
if (cnt < variants)
|
|
|
|
break;
|
2000-04-22 20:50:22 +00:00
|
|
|
|
1999-03-23 03:18:12 +00:00
|
|
|
plugins = plugins->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-02-25 04:15:39 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin)
|
1999-02-20 02:24:15 +00:00
|
|
|
{
|
1999-03-29 22:18:05 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
1999-02-20 02:24:15 +00:00
|
|
|
*aPlugin = NULL;
|
1999-02-25 04:15:39 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
if(!aMimeType)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
// unload any libs that can remain after plugins.refresh(1), see #61388
|
|
|
|
CleanUnloadedLibraries();
|
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
// If plugins haven't been scanned yet, do so now
|
2000-08-17 19:26:15 +00:00
|
|
|
LoadPlugins();
|
1999-02-25 04:15:39 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
nsPluginTag* pluginTag;
|
|
|
|
if((rv = FindPluginEnabledForType(aMimeType, pluginTag)) == NS_OK)
|
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if(aMimeType && pluginTag->mFileName)
|
|
|
|
printf("For %s found plugin %s\n", aMimeType, pluginTag->mFileName);
|
|
|
|
#endif
|
1999-07-06 04:14:54 +00:00
|
|
|
|
2000-11-13 18:42:43 +00:00
|
|
|
if (nsnull == pluginTag->mLibrary) // if we haven't done this yet
|
|
|
|
{
|
|
|
|
nsFileSpec file(pluginTag->mFileName);
|
1999-07-07 00:37:41 +00:00
|
|
|
|
2000-11-13 18:42:43 +00:00
|
|
|
nsPluginFile pluginFile(file);
|
|
|
|
PRLibrary* pluginLibrary = NULL;
|
1999-07-06 04:14:54 +00:00
|
|
|
|
2000-11-13 18:42:43 +00:00
|
|
|
if (pluginFile.LoadPlugin(pluginLibrary) != NS_OK || pluginLibrary == NULL)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-07-06 04:14:54 +00:00
|
|
|
|
2000-11-13 18:42:43 +00:00
|
|
|
pluginTag->mLibrary = pluginLibrary;
|
1999-07-06 04:14:54 +00:00
|
|
|
|
2000-11-13 18:42:43 +00:00
|
|
|
}
|
1999-07-06 04:14:54 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
nsIPlugin* plugin = pluginTag->mEntryPoint;
|
|
|
|
if(plugin == NULL)
|
|
|
|
{
|
2001-02-13 21:48:26 +00:00
|
|
|
// No, this is not a leak. GetGlobalServiceManager() doesn't
|
|
|
|
// addref the pointer on the way out. It probably should.
|
|
|
|
nsIServiceManager* serviceManager;
|
|
|
|
nsServiceManager::GetGlobalServiceManager(&serviceManager);
|
2000-07-22 01:34:13 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
// need to get the plugin factory from this plugin.
|
|
|
|
nsFactoryProc nsGetFactory = nsnull;
|
|
|
|
nsGetFactory = (nsFactoryProc) PR_FindSymbol(pluginTag->mLibrary, "NSGetFactory");
|
1999-05-07 22:06:47 +00:00
|
|
|
if(nsGetFactory != nsnull)
|
1999-03-29 22:18:05 +00:00
|
|
|
{
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = nsGetFactory(serviceManager, kPluginCID, nsnull, nsnull, // XXX fix ClassName/ContractID
|
1999-05-07 22:06:47 +00:00
|
|
|
(nsIFactory**)&pluginTag->mEntryPoint);
|
|
|
|
plugin = pluginTag->mEntryPoint;
|
|
|
|
if (plugin != NULL)
|
|
|
|
plugin->Initialize();
|
1999-03-29 22:18:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-13 21:48:26 +00:00
|
|
|
#if defined(XP_MAC) && TARGET_CARBON
|
|
|
|
// should we also look for a 'carb' resource?
|
|
|
|
if (PR_FindSymbol(pluginTag->mLibrary, "mainRD") != NULL) {
|
|
|
|
NS_WITH_SERVICE(nsIClassicPluginFactory, factory, NS_CLASSIC_PLUGIN_FACTORY_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) rv = factory->CreatePlugin(serviceManager, pluginTag->mFileName,
|
|
|
|
pluginTag->mLibrary, &pluginTag->mEntryPoint);
|
|
|
|
} else
|
|
|
|
#endif
|
2000-07-22 01:34:13 +00:00
|
|
|
rv = ns4xPlugin::CreatePlugin(serviceManager,
|
|
|
|
pluginTag->mFileName,
|
|
|
|
pluginTag->mLibrary,
|
|
|
|
&pluginTag->mEntryPoint);
|
2001-02-13 21:48:26 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
plugin = pluginTag->mEntryPoint;
|
1999-05-17 21:26:48 +00:00
|
|
|
pluginTag->mFlags |= NS_PLUGIN_FLAG_OLDSCHOOL;
|
1999-05-07 22:06:47 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
// no need to initialize, already done by CreatePlugin()
|
1999-02-25 04:15:39 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-20 02:24:15 +00:00
|
|
|
|
2001-02-13 21:48:26 +00:00
|
|
|
if (plugin != nsnull)
|
1999-03-29 22:18:05 +00:00
|
|
|
{
|
|
|
|
*aPlugin = plugin;
|
|
|
|
plugin->AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
1999-02-20 02:24:15 +00:00
|
|
|
|
1999-03-29 22:18:05 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-02-20 02:24:15 +00:00
|
|
|
|
2000-02-01 00:42:52 +00:00
|
|
|
static PRBool areTheSameFileNames(char * name1, char * name2)
|
|
|
|
{
|
|
|
|
if((name1 == nsnull) || (name2 == nsnull))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
char * filename1 = PL_strrchr(name1, '\\');
|
|
|
|
if(filename1 != nsnull)
|
|
|
|
filename1++;
|
|
|
|
else
|
|
|
|
filename1 = name1;
|
|
|
|
|
|
|
|
char * filename2 = PL_strrchr(name2, '\\');
|
|
|
|
if(filename2 != nsnull)
|
|
|
|
filename2++;
|
|
|
|
else
|
|
|
|
filename2 = name2;
|
|
|
|
|
|
|
|
if(PL_strlen(filename1) != PL_strlen(filename2))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2000-03-15 01:27:30 +00:00
|
|
|
// this one MUST be case insensitive for Windows and MUST be case sensitive
|
|
|
|
// for Unix. How about Win2000?
|
2000-03-03 00:53:45 +00:00
|
|
|
return (nsnull == PL_strncasecmp(filename1, filename2, PL_strlen(filename1)));
|
2000-02-01 00:42:52 +00:00
|
|
|
}
|
|
|
|
|
2000-03-15 01:27:30 +00:00
|
|
|
static PRBool isJavaPlugin(nsPluginTag * tag)
|
|
|
|
{
|
|
|
|
if(tag->mFileName == nsnull)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
char * filename = PL_strrchr(tag->mFileName, '\\');
|
|
|
|
|
|
|
|
if(filename != nsnull)
|
|
|
|
filename++;
|
|
|
|
else
|
|
|
|
filename = tag->mFileName;
|
|
|
|
|
|
|
|
return (nsnull == PL_strncasecmp(filename, "npjava", 6));
|
|
|
|
}
|
|
|
|
|
2000-06-21 01:44:55 +00:00
|
|
|
// currently 'unwanted' plugins are Java, and all other plugins except
|
|
|
|
// RealPlayer, Acrobat, Flash
|
|
|
|
static PRBool isUnwantedPlugin(nsPluginTag * tag)
|
|
|
|
{
|
|
|
|
if(tag->mFileName == nsnull)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2000-07-22 01:58:55 +00:00
|
|
|
for (PRInt32 i = 0; i < tag->mVariants; ++i) {
|
|
|
|
if(nsnull == PL_strcasecmp(tag->mMimeTypeArray[i], "audio/x-pn-realaudio-plugin"))
|
|
|
|
return PR_FALSE;
|
2000-06-21 01:44:55 +00:00
|
|
|
|
2000-07-22 01:58:55 +00:00
|
|
|
if(nsnull == PL_strcasecmp(tag->mMimeTypeArray[i], "application/pdf"))
|
|
|
|
return PR_FALSE;
|
2000-06-21 01:44:55 +00:00
|
|
|
|
2000-07-22 01:58:55 +00:00
|
|
|
if(nsnull == PL_strcasecmp(tag->mMimeTypeArray[i], "application/x-shockwave-flash"))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-06-21 01:44:55 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
nsresult nsPluginHostImpl::ScanPluginsDirectory(nsPluginsDir& pluginsDir,
|
|
|
|
nsIComponentManager * compManager,
|
|
|
|
nsIFile * layoutPath,
|
2001-02-02 23:48:17 +00:00
|
|
|
PRBool checkForUnwantedPlugins)
|
2000-02-01 00:42:52 +00:00
|
|
|
{
|
2000-09-22 00:58:46 +00:00
|
|
|
for (nsDirectoryIterator iter(pluginsDir, PR_TRUE); iter.Exists(); iter++)
|
2000-02-01 00:42:52 +00:00
|
|
|
{
|
|
|
|
const nsFileSpec& file = iter;
|
2000-09-22 00:58:46 +00:00
|
|
|
if (pluginsDir.IsPluginFile(file))
|
|
|
|
{
|
2000-02-01 00:42:52 +00:00
|
|
|
nsPluginFile pluginFile(file);
|
2000-09-22 00:58:46 +00:00
|
|
|
PRLibrary* pluginLibrary = nsnull;
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
// load the plugin's library so we can ask it some questions, but not for Windows
|
2000-02-01 00:42:52 +00:00
|
|
|
#ifndef XP_WIN
|
2000-09-22 00:58:46 +00:00
|
|
|
if (pluginFile.LoadPlugin(pluginLibrary) != NS_OK || pluginLibrary == nsnull)
|
|
|
|
continue;
|
2000-02-01 00:42:52 +00:00
|
|
|
#endif
|
2000-03-23 00:45:49 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
// create a tag describing this plugin.
|
|
|
|
nsPluginInfo info = { sizeof(info) };
|
|
|
|
nsresult res = pluginFile.GetPluginInfo(info);
|
|
|
|
if(NS_FAILED(res))
|
|
|
|
continue;
|
2000-04-22 00:04:24 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
nsPluginTag* pluginTag = new nsPluginTag(&info);
|
|
|
|
pluginFile.FreePluginInfo(info);
|
2000-04-22 00:04:24 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
if(pluginTag == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
pluginTag->mLibrary = pluginLibrary;
|
2000-07-07 00:10:54 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
PRBool bAddIt = PR_TRUE;
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
// check if there are specific plugins we don't want
|
2000-09-22 00:58:46 +00:00
|
|
|
if(checkForUnwantedPlugins)
|
|
|
|
{
|
|
|
|
if(isUnwantedPlugin(pluginTag))
|
|
|
|
bAddIt = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
// check if we already have this plugin in the list which
|
|
|
|
// is possible if we do refresh
|
|
|
|
if(bAddIt)
|
2000-09-22 00:58:46 +00:00
|
|
|
{
|
|
|
|
for(nsPluginTag* tag = mPlugins; tag != nsnull; tag = tag->mNext)
|
|
|
|
{
|
|
|
|
if(areTheSameFileNames(tag->mFileName, pluginTag->mFileName))
|
|
|
|
{
|
|
|
|
bAddIt = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
// so if we still want it -- do it
|
2000-09-22 00:58:46 +00:00
|
|
|
if(bAddIt)
|
|
|
|
{
|
|
|
|
pluginTag->mNext = mPlugins;
|
|
|
|
mPlugins = pluginTag;
|
|
|
|
|
|
|
|
if(layoutPath)
|
|
|
|
RegisterPluginMimeTypesWithLayout(pluginTag, compManager, layoutPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete pluginTag;
|
2000-02-01 00:42:52 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-22 00:58:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::LoadPlugins()
|
|
|
|
{
|
|
|
|
// do not do anything if it is already done
|
|
|
|
// use nsPluginHostImpl::ReloadPlugins to enforce loading
|
|
|
|
if(mPluginsLoaded)
|
|
|
|
return NS_OK;
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
// retrieve a path for layout module. Needed for plugin mime types registration
|
|
|
|
nsCOMPtr<nsIFile> path;
|
|
|
|
PRBool isLayoutPath = PR_FALSE;
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIComponentManager> compManager = do_GetService(kComponentManagerCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && compManager)
|
|
|
|
{
|
|
|
|
isLayoutPath = NS_SUCCEEDED(compManager->SpecForRegistryLocation(REL_PLUGIN_DLL, getter_AddRefs(path)));
|
|
|
|
rv = LoadXPCOMPlugins(compManager, path);
|
|
|
|
}
|
2000-03-23 00:45:49 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
// scan the 4x plugins directory for eligible legacy plugin libraries
|
2000-04-22 00:04:24 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
#ifndef XP_WIN // old plugin finding logic
|
2000-04-22 00:04:24 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
// scan Mozilla plugins dir
|
|
|
|
nsPluginsDir pluginsDir;
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
if (pluginsDir.Valid())
|
2000-09-22 01:48:05 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> lpath = nsnull;
|
|
|
|
if(isLayoutPath)
|
|
|
|
lpath = path;
|
|
|
|
|
|
|
|
ScanPluginsDirectory(pluginsDir, compManager, lpath);
|
|
|
|
}
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
#ifdef XP_MAC
|
|
|
|
// try to scan old-spelled plugins dir ("Plug-ins") for Mac
|
|
|
|
// should we check for duplicate plugins here? We probably should.
|
|
|
|
nsPluginsDir pluginsDirMacOld(PLUGINS_DIR_LOCATION_MAC_OLD);
|
|
|
|
|
|
|
|
if (pluginsDirMacOld.Valid())
|
2000-09-22 01:48:05 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> lpath = nsnull;
|
|
|
|
if(isLayoutPath)
|
|
|
|
lpath = path;
|
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
ScanPluginsDirectory(pluginsDirMacOld,
|
|
|
|
compManager,
|
2000-09-22 01:48:05 +00:00
|
|
|
lpath,
|
2001-02-02 23:48:17 +00:00
|
|
|
PR_FALSE); // don't check for specific plugins
|
2000-09-22 01:48:05 +00:00
|
|
|
}
|
2000-09-22 00:58:46 +00:00
|
|
|
#endif // XP_MAC
|
|
|
|
|
|
|
|
#else // XP_WIN go for new plugin finding logic on Windows
|
|
|
|
|
|
|
|
// currently we decided to look in both local plugins dir and
|
|
|
|
// that of the previous 4.x installation combining plugins from both places.
|
|
|
|
// See bug #21938
|
|
|
|
// As of 1.27.00 this selective mechanism is natively supported in Windows
|
|
|
|
// native implementation of nsPluginsDir.
|
2000-03-15 01:27:30 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
// first, make a list from MOZ_LOCAL installation
|
|
|
|
nsPluginsDir pluginsDirMoz(PLUGINS_DIR_LOCATION_MOZ_LOCAL);
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
if (pluginsDirMoz.Valid())
|
2000-09-22 01:48:05 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> lpath = nsnull;
|
|
|
|
if(isLayoutPath)
|
|
|
|
lpath = path;
|
|
|
|
|
|
|
|
ScanPluginsDirectory(pluginsDirMoz, compManager, lpath);
|
|
|
|
}
|
2000-02-01 00:42:52 +00:00
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
// now check the 4.x plugins dir and add new files
|
|
|
|
// Specifying the last two params as PR_TRUE we make sure that:
|
|
|
|
// 1. we search for a match in the list of MOZ_LOCAL plugins, ignore if found,
|
|
|
|
// add if not found (check for dups)
|
|
|
|
// 2. we ignore 4.x Java plugins no matter what and other
|
|
|
|
// unwanted plugins as per temporary decision described in bug #23856
|
|
|
|
nsPluginsDir pluginsDir4x(PLUGINS_DIR_LOCATION_4DOTX);
|
|
|
|
if (pluginsDir4x.Valid())
|
2000-09-22 01:48:05 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> lpath = nsnull;
|
|
|
|
if(isLayoutPath)
|
|
|
|
lpath = path;
|
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
ScanPluginsDirectory(pluginsDir4x,
|
|
|
|
compManager,
|
2000-09-22 01:48:05 +00:00
|
|
|
lpath,
|
2001-02-02 23:48:17 +00:00
|
|
|
PR_TRUE); // check for specific plugins
|
2000-09-22 01:48:05 +00:00
|
|
|
}
|
2001-02-07 01:13:01 +00:00
|
|
|
|
|
|
|
mPluginsLoaded = PR_TRUE; // at this point 'some' plugins have been loaded,
|
|
|
|
// the rest is optional
|
|
|
|
|
|
|
|
// Check the windows registry for extra paths to scan for plugins
|
|
|
|
//
|
|
|
|
// We are going to get this registry key location from the pref:
|
|
|
|
// browser.plugins.registry_plugins_folder_key_location
|
|
|
|
// The key name is "Plugins Folders"
|
|
|
|
//
|
|
|
|
// So, for example, in winprefs.js put in this line:
|
|
|
|
// pref ("browser.plugins.registry_plugins_folder_key_location","Software\\Mozilla\\Common");
|
|
|
|
// Then, in HKEY_LOCAL_MACHINE\Software\Mozilla\Common
|
|
|
|
// Make a string key "Plugins Folder" who's value is a list of paths sperated by semi-colons
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
|
|
|
if (!prefs) return NS_OK; // if we can't get to the prefs, bail
|
|
|
|
|
|
|
|
char * regkey;
|
|
|
|
rv = prefs->CopyCharPref(_NS_PREF_COMMON_PLUGIN_REG_KEY_,®key);
|
|
|
|
if (!NS_SUCCEEDED(rv) || regkey == nsnull) return NS_OK; //if pref isn't set, bail
|
|
|
|
|
|
|
|
unsigned char valbuf[_MAXKEYVALUE_];
|
|
|
|
char* pluginPath;
|
|
|
|
HKEY newkey;
|
|
|
|
LONG result;
|
|
|
|
DWORD type = REG_SZ;
|
|
|
|
DWORD length = _MAXKEYVALUE_;
|
|
|
|
|
|
|
|
// set up layout path (if not done above)
|
|
|
|
nsCOMPtr<nsIFile> lpath = nsnull;
|
|
|
|
if(isLayoutPath)
|
|
|
|
lpath = path;
|
|
|
|
|
|
|
|
result = RegOpenKeyEx( HKEY_LOCAL_MACHINE, regkey, NULL, KEY_QUERY_VALUE, &newkey );
|
|
|
|
|
|
|
|
if ( ERROR_SUCCESS == result ) {
|
|
|
|
result = RegQueryValueEx( newkey, _NS_COMMON_PLUGIN_KEY_NAME_, nsnull, &type, valbuf, &length );
|
|
|
|
RegCloseKey( newkey );
|
|
|
|
if ( ERROR_SUCCESS == result ) {
|
|
|
|
// tokenize reg key value by semi-colons
|
|
|
|
for ( pluginPath = strtok((char *)&valbuf, ";"); pluginPath; pluginPath = strtok(NULL, ";") ) {
|
|
|
|
nsFileSpec winRegPluginPath (pluginPath);
|
|
|
|
if (winRegPluginPath.Exists()) { // check for validity of path first
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("found some more plugins at: %s\n", pluginPath);
|
|
|
|
#endif
|
|
|
|
ScanPluginsDirectory( (nsPluginsDir)winRegPluginPath,
|
|
|
|
compManager,
|
|
|
|
lpath,
|
|
|
|
PR_FALSE); // check for even unwanted plugins
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (regkey); // clean up
|
|
|
|
|
2000-09-22 00:58:46 +00:00
|
|
|
#endif // !XP_WIN
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-01 00:42:52 +00:00
|
|
|
}
|
2000-07-22 01:34:13 +00:00
|
|
|
|
|
|
|
static nsresult
|
|
|
|
LoadXPCOMPlugin(nsIComponentManager* aComponentManager,
|
|
|
|
nsIRegistry* aRegistry,
|
|
|
|
const char* aCID,
|
|
|
|
nsRegistryKey aPluginKey,
|
|
|
|
nsPluginTag** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// The name, description, MIME types, MIME descriptions, and
|
|
|
|
// supported file extensions will all hang off of the plugin's key
|
|
|
|
// in the registry. Pull these out now.
|
|
|
|
nsXPIDLCString name;
|
|
|
|
aRegistry->GetStringUTF8(aPluginKey, "name", getter_Copies(name));
|
|
|
|
|
|
|
|
nsXPIDLCString description;
|
|
|
|
aRegistry->GetStringUTF8(aPluginKey, "description", getter_Copies(description));
|
|
|
|
|
|
|
|
nsXPIDLCString filename;
|
|
|
|
|
|
|
|
// To figure out the filename of the plugin, we'll need to get the
|
|
|
|
// plugin's CID, and then navigate through the XPCOM registry to
|
|
|
|
// pull out the DLL name to which the CID is registered.
|
2000-09-04 01:19:36 +00:00
|
|
|
nsAutoString path(NS_LITERAL_STRING("software/mozilla/XPCOM/classID/") + NS_ConvertASCIItoUCS2(aCID));
|
2000-07-22 01:34:13 +00:00
|
|
|
|
|
|
|
nsRegistryKey cidKey;
|
|
|
|
rv = aRegistry->GetKey(nsIRegistry::Common, path.GetUnicode(), &cidKey);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRUint8* library;
|
|
|
|
PRUint32 count;
|
|
|
|
// XXX Good grief, what does "GetBytesUTF8()" mean? They're bytes!
|
|
|
|
rv = aRegistry->GetBytesUTF8(cidKey, "InprocServer", &count, &library);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = aComponentManager->SpecForRegistryLocation(NS_REINTERPRET_CAST(const char*, library),
|
|
|
|
getter_AddRefs(file));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
file->GetPath(getter_Copies(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCRT::free(NS_REINTERPRET_CAST(char*, library));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEnumerator> enumerator;
|
|
|
|
rv = aRegistry->EnumerateAllSubtrees(aPluginKey, getter_AddRefs(enumerator));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> subtrees;
|
|
|
|
rv = NS_NewAdapterEnumerator(getter_AddRefs(subtrees), enumerator);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
char** mimetypes = nsnull;
|
|
|
|
char** mimedescriptions = nsnull;
|
|
|
|
char** extensions = nsnull;
|
|
|
|
PRInt32 count = 0;
|
|
|
|
PRInt32 capacity = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
PRBool hasmore;
|
|
|
|
subtrees->HasMoreElements(&hasmore);
|
|
|
|
if (! hasmore)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> isupports;
|
|
|
|
subtrees->GetNext(getter_AddRefs(isupports));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRegistryNode> node = do_QueryInterface(isupports);
|
|
|
|
NS_ASSERTION(node != nsnull, "not an nsIRegistryNode");
|
|
|
|
if (! node)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsRegistryKey key;
|
|
|
|
node->GetKey(&key);
|
|
|
|
|
|
|
|
if (count >= capacity) {
|
|
|
|
capacity += capacity ? capacity : 4;
|
|
|
|
|
|
|
|
char** newmimetypes = new char*[capacity];
|
|
|
|
char** newmimedescriptions = new char*[capacity];
|
|
|
|
char** newextensions = new char*[capacity];
|
|
|
|
|
|
|
|
if (!newmimetypes || !newmimedescriptions || !newextensions) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
delete[] newmimetypes;
|
|
|
|
delete[] newmimedescriptions;
|
|
|
|
delete[] newextensions;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < count; ++i) {
|
|
|
|
newmimetypes[i] = mimetypes[i];
|
|
|
|
newmimedescriptions[i] = mimedescriptions[i];
|
|
|
|
newextensions[i] = extensions[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] mimetypes;
|
|
|
|
delete[] mimedescriptions;
|
|
|
|
delete[] extensions;
|
|
|
|
|
|
|
|
mimetypes = newmimetypes;
|
|
|
|
mimedescriptions = newmimedescriptions;
|
|
|
|
extensions = newextensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRegistry->GetStringUTF8(key, "mimetype", &mimetypes[count]);
|
|
|
|
aRegistry->GetStringUTF8(key, "description", &mimedescriptions[count]);
|
|
|
|
aRegistry->GetStringUTF8(key, "extension", &extensions[count]);
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// All done! Create the new nsPluginTag info and send it back.
|
|
|
|
nsPluginTag* tag
|
2000-07-28 05:43:24 +00:00
|
|
|
= new nsPluginTag(name.get(),
|
|
|
|
description.get(),
|
|
|
|
filename.get(),
|
|
|
|
(const char* const*)mimetypes,
|
|
|
|
(const char* const*)mimedescriptions,
|
|
|
|
(const char* const*)extensions,
|
2000-07-22 01:34:13 +00:00
|
|
|
count);
|
|
|
|
|
|
|
|
if (! tag)
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aResult = tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < count; ++i) {
|
|
|
|
CRTFREEIF(mimetypes[i]);
|
|
|
|
CRTFREEIF(mimedescriptions[i]);
|
|
|
|
CRTFREEIF(extensions[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] mimetypes;
|
|
|
|
delete[] mimedescriptions;
|
|
|
|
delete[] extensions;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginHostImpl::LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFile* aPath)
|
|
|
|
{
|
|
|
|
// The "new style" XPCOM plugins have their information stored in
|
|
|
|
// the component registry, under the key
|
|
|
|
//
|
|
|
|
// nsIRegistry::Common/software/plugins
|
|
|
|
//
|
|
|
|
// Enumerate through that list now, creating an nsPluginTag for
|
|
|
|
// each.
|
|
|
|
nsCOMPtr<nsIRegistry> registry = do_CreateInstance(kRegistryCID);
|
|
|
|
if (! registry)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsRegistryKey pluginsKey;
|
|
|
|
rv = registry->GetSubtree(nsIRegistry::Common, "software/plugins", &pluginsKey);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// XXX get rid nsIEnumerator someday!
|
|
|
|
nsCOMPtr<nsIEnumerator> enumerator;
|
|
|
|
rv = registry->EnumerateSubtrees(pluginsKey, getter_AddRefs(enumerator));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> plugins;
|
|
|
|
rv = NS_NewAdapterEnumerator(getter_AddRefs(plugins), enumerator);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
PRBool hasMore;
|
|
|
|
plugins->HasMoreElements(&hasMore);
|
|
|
|
if (! hasMore)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> isupports;
|
|
|
|
plugins->GetNext(getter_AddRefs(isupports));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRegistryNode> node = do_QueryInterface(isupports);
|
|
|
|
NS_ASSERTION(node != nsnull, "not an nsIRegistryNode");
|
|
|
|
if (! node)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Pull out the information for an individual plugin, and link it
|
|
|
|
// in to the mPlugins list.
|
|
|
|
nsXPIDLCString cid;
|
|
|
|
node->GetNameUTF8(getter_Copies(cid));
|
|
|
|
|
|
|
|
nsRegistryKey key;
|
|
|
|
node->GetKey(&key);
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
nsPluginTag* tag = nsnull;
|
2000-07-22 01:34:13 +00:00
|
|
|
rv = LoadXPCOMPlugin(aComponentManager, registry, cid, key, &tag);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
// skip it if we already have it
|
|
|
|
PRBool bAddIt = PR_TRUE;
|
|
|
|
for(nsPluginTag* existingtag = mPlugins; existingtag != nsnull; existingtag = existingtag->mNext)
|
|
|
|
{
|
|
|
|
if(areTheSameFileNames(tag->mFileName, existingtag->mFileName))
|
|
|
|
{
|
|
|
|
bAddIt = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!bAddIt)
|
|
|
|
{
|
|
|
|
if(tag)
|
|
|
|
delete tag;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-07-22 01:34:13 +00:00
|
|
|
tag->mNext = mPlugins;
|
|
|
|
mPlugins = tag;
|
|
|
|
|
|
|
|
// Create an nsIDocumentLoaderFactory wrapper in case we ever see
|
|
|
|
// any naked streams.
|
|
|
|
RegisterPluginMimeTypesWithLayout(tag, aComponentManager, aPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/* Called by GetURL and PostURL */
|
1998-09-15 03:48:58 +00:00
|
|
|
|
1999-04-20 19:29:28 +00:00
|
|
|
NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
nsIPluginInstance *aInstance,
|
|
|
|
nsIPluginStreamListener* aListener,
|
|
|
|
void *aPostData,
|
|
|
|
PRUint32 aPostDataLen,
|
|
|
|
const char *aHeadersData,
|
|
|
|
PRUint32 aHeadersDataLen)
|
1998-09-15 03:48:58 +00:00
|
|
|
{
|
2000-06-16 22:27:16 +00:00
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
nsAutoString absUrl;
|
2000-04-22 20:50:22 +00:00
|
|
|
nsresult rv;
|
2001-01-16 22:53:39 +00:00
|
|
|
void *newPostData = nsnull;
|
|
|
|
PRUint32 newPostDataLen = 0;
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
if (aURL.Length() <= 0)
|
|
|
|
return NS_OK;
|
1998-09-15 03:48:58 +00:00
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
// get the full URL of the document that the plugin is embedded
|
|
|
|
// in to create an absolute url in case aURL is relative
|
2000-07-13 02:44:14 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2000-06-16 22:27:16 +00:00
|
|
|
nsPluginInstancePeerImpl *peer;
|
|
|
|
rv = aInstance->GetPeer(NS_REINTERPRET_CAST(nsIPluginInstancePeer **, &peer));
|
2000-09-22 06:17:28 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && peer)
|
2000-06-16 22:27:16 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPluginInstanceOwner> owner;
|
|
|
|
rv = peer->GetOwner(*getter_AddRefs(owner));
|
2000-09-22 06:17:28 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && owner)
|
2000-06-16 22:27:16 +00:00
|
|
|
{
|
|
|
|
rv = owner->GetDocument(getter_AddRefs(doc));
|
2000-09-22 06:17:28 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && doc)
|
2000-06-16 22:27:16 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> docURL( getter_AddRefs(doc->GetDocumentURL()) );
|
|
|
|
|
|
|
|
// Create an absolute URL
|
|
|
|
rv = NS_MakeAbsoluteURI(absUrl, aURL, docURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(peer);
|
|
|
|
}
|
1998-09-15 03:48:58 +00:00
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
if (absUrl.IsEmpty())
|
|
|
|
absUrl.Assign(aURL);
|
|
|
|
|
|
|
|
rv = NS_NewURI(getter_AddRefs(url), absUrl);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
1998-09-15 03:48:58 +00:00
|
|
|
{
|
2000-06-16 22:27:16 +00:00
|
|
|
nsPluginStreamListenerPeer *listenerPeer = new nsPluginStreamListenerPeer;
|
|
|
|
if (listenerPeer == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(listenerPeer);
|
1999-01-25 08:05:00 +00:00
|
|
|
rv = listenerPeer->Initialize(url, aInstance, aListener);
|
1998-09-15 03:48:58 +00:00
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-07-13 02:44:14 +00:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> callbacks;
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
// Get the script global object owner and use that as the notification callback
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> global;
|
|
|
|
doc->GetScriptGlobalObject(getter_AddRefs(global));
|
|
|
|
|
|
|
|
if (global) {
|
|
|
|
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
|
|
|
|
global->GetGlobalObjectOwner(getter_AddRefs(owner));
|
|
|
|
|
|
|
|
callbacks = do_QueryInterface(owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
|
1999-08-26 22:45:55 +00:00
|
|
|
// XXX: Null LoadGroup?
|
2000-07-13 02:44:14 +00:00
|
|
|
rv = NS_OpenURI(getter_AddRefs(channel), url, nsnull,
|
|
|
|
nsnull, callbacks);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
// Set the owner of channel to the document principal...
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
doc->GetPrincipal(getter_AddRefs(principal));
|
|
|
|
|
|
|
|
channel->SetOwner(principal);
|
|
|
|
}
|
|
|
|
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
// deal with headers and post data
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if(httpChannel)
|
|
|
|
{
|
|
|
|
|
|
|
|
// figure out if we need to set the post data stream on the
|
|
|
|
// channel... right now, this is only done for http
|
|
|
|
// channels.....
|
|
|
|
if(aPostData)
|
|
|
|
{
|
2001-01-16 22:53:39 +00:00
|
|
|
//Make sure there is "r\n\r\n" before the post data
|
|
|
|
if (!PL_strstr((const char *) aPostData, "\r\n\r\n")) {
|
|
|
|
if (NS_SUCCEEDED(FixPostData(aPostData, aPostDataLen,
|
|
|
|
&newPostData, &newPostDataLen))) {
|
|
|
|
aPostData = newPostData;
|
|
|
|
aPostDataLen = newPostDataLen;
|
|
|
|
}
|
|
|
|
}
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
nsCOMPtr<nsIInputStream> postDataStream = nsnull;
|
|
|
|
if (aPostData) {
|
2001-01-16 22:53:39 +00:00
|
|
|
NS_NewPostDataStream(getter_AddRefs(postDataStream),
|
|
|
|
PR_FALSE,
|
|
|
|
(const char *) aPostData, 0);
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX it's a bit of a hack to rewind the postdata stream
|
|
|
|
// here but it has to be done in case the post data is
|
|
|
|
// being reused multiple times.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRandomAccessStore>
|
|
|
|
postDataRandomAccess(do_QueryInterface(postDataStream));
|
|
|
|
if (postDataRandomAccess)
|
|
|
|
{
|
|
|
|
postDataRandomAccess->Seek(PR_SEEK_SET, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> method = NS_NewAtom ("POST");
|
|
|
|
httpChannel->SetRequestMethod(method);
|
|
|
|
httpChannel->SetUploadStream(postDataStream);
|
2001-01-16 22:53:39 +00:00
|
|
|
|
|
|
|
if (newPostData)
|
|
|
|
{
|
2001-01-19 01:52:33 +00:00
|
|
|
delete [] (char *)newPostData;
|
2001-01-16 22:53:39 +00:00
|
|
|
newPostData = nsnull;
|
|
|
|
}
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
}
|
2000-09-20 09:27:54 +00:00
|
|
|
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
if (aHeadersData)
|
|
|
|
{
|
|
|
|
rv = AddHeadersToChannel(aHeadersData, aHeadersDataLen,
|
|
|
|
httpChannel);
|
2000-09-20 09:27:54 +00:00
|
|
|
}
|
|
|
|
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
}
|
2001-02-21 20:38:08 +00:00
|
|
|
rv = channel->AsyncOpen(listenerPeer, nsnull);
|
2000-09-20 09:27:54 +00:00
|
|
|
}
|
|
|
|
|
2000-06-16 22:27:16 +00:00
|
|
|
NS_RELEASE(listenerPeer);
|
1998-08-05 04:21:36 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-01-16 22:53:39 +00:00
|
|
|
nsresult
|
|
|
|
nsPluginHostImpl::FixPostData(void *inPostData, PRUint32 inPostDataLen,
|
|
|
|
void **outPostData, PRUint32 *outPostDataLen)
|
|
|
|
{
|
|
|
|
if ((!inPostData) || (inPostDataLen <= 0) ||
|
|
|
|
(!outPostData) || (!outPostDataLen)) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *postData = (const char *)inPostData;
|
|
|
|
const char *crlf = nsnull;
|
|
|
|
const char *crlfcrlf = "\r\n\r\n";
|
|
|
|
const char *t;
|
|
|
|
char *newBuf;
|
|
|
|
PRInt32 headersLen = 0, dataLen = 0;
|
|
|
|
|
|
|
|
if (!(newBuf = new char[inPostDataLen + 4])) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsCRT::memset(newBuf, 0, inPostDataLen + 4);
|
|
|
|
|
|
|
|
if (!(crlf = PL_strstr(postData, "\r\n\n"))) {
|
|
|
|
delete [] newBuf;
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
headersLen = crlf - postData;
|
|
|
|
|
|
|
|
// find the next non-whitespace char
|
|
|
|
t = crlf + 3;
|
|
|
|
while (*t == '\r' || *t == '\n' || *t == '\t' || *t == ' ' && *t) {
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
if (*t) {
|
|
|
|
// copy the headers
|
|
|
|
nsCRT::memcpy(newBuf, postData, headersLen);
|
|
|
|
// copy the correct crlfcrlf
|
|
|
|
nsCRT::memcpy(newBuf + headersLen, crlfcrlf, 4);
|
|
|
|
// copy the rest of the postData
|
|
|
|
dataLen = inPostDataLen - (t - postData);
|
|
|
|
nsCRT::memcpy(newBuf + headersLen + 4, t, dataLen);
|
|
|
|
*outPostDataLen = headersLen + 4 + dataLen;
|
|
|
|
*outPostData = newBuf;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete [] newBuf;
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData,
|
|
|
|
PRUint32 aHeadersDataLen,
|
|
|
|
nsIChannel *aGenericChannel)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHTTPChannel> aChannel = do_QueryInterface(aGenericChannel);
|
|
|
|
if (!aChannel) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// used during the manipulation of the String from the aHeadersData
|
|
|
|
nsCAutoString headersString;
|
|
|
|
nsCAutoString oneHeader;
|
|
|
|
nsCAutoString headerName;
|
|
|
|
nsCAutoString headerValue;
|
2001-01-30 20:39:55 +00:00
|
|
|
PRInt32 crlf = 0;
|
|
|
|
PRInt32 colon = 0;
|
r=av
a=waterson
bug=51919
This fix makes it so nsIPluginManager::PostURL() works correctly in the
case of a null target and non-null streamListener.
The fix was to add parameters to NewPluginURLStream() for headers and
post data:
NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
+ NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance,
+ nsIPluginStreamListener *aListener,
+ void *aPostData = nsnull, PRUint32 aPostDataLen = 0,
+ const char *aHeadersData = nsnull,
+ PRUint32 aHeadersDataLen = 0);
And to add a new method to correctly send the headers to the channel:
+ NS_IMETHOD
+ AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen,
+ nsIChannel *aGenericChannel);
Files in this fix:
M modules/plugin/nglsrc/nsPluginHostImpl.cpp
M modules/plugin/nglsrc/nsPluginHostImpl.h
2000-09-08 23:58:36 +00:00
|
|
|
nsIAtom *headerAtom;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Turn the char * buffer into an nsString.
|
|
|
|
//
|
|
|
|
headersString = aHeadersData;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Iterate over the nsString: for each "\r\n" delimeted chunk,
|
|
|
|
// add the value as a header to the nsIHTTPChannel
|
|
|
|
//
|
|
|
|
|
|
|
|
while (PR_TRUE) {
|
|
|
|
crlf = headersString.Find("\r\n", PR_TRUE);
|
|
|
|
if (-1 == crlf) {
|
|
|
|
rv = NS_OK;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
headersString.Mid(oneHeader, 0, crlf);
|
|
|
|
headersString.Cut(0, crlf + 2);
|
|
|
|
oneHeader.StripWhitespace();
|
|
|
|
colon = oneHeader.Find(":");
|
|
|
|
if (-1 == colon) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
oneHeader.Left(headerName, colon);
|
|
|
|
colon++;
|
|
|
|
oneHeader.Mid(headerValue, colon, oneHeader.Length() - colon);
|
|
|
|
headerAtom = NS_NewAtom((const char *) headerName);
|
|
|
|
if (!headerAtom) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FINALLY: we can set the header!
|
|
|
|
//
|
|
|
|
|
|
|
|
rv =aChannel->SetRequestHeader(headerAtom, (const char *) headerValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1999-06-04 22:32:27 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance)
|
|
|
|
{
|
2000-06-13 23:23:13 +00:00
|
|
|
nsActivePlugin * plugin = mActivePluginList.find(aInstance);
|
|
|
|
|
|
|
|
if(plugin != nsnull)
|
2000-06-15 01:07:27 +00:00
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
// if the plugin does not want to be 'cached' just remove it
|
|
|
|
PRBool doCache = PR_TRUE;
|
|
|
|
aInstance->GetValue(nsPluginInstanceVariable_DoCacheBool, (void *) &doCache);
|
|
|
|
if (!doCache)
|
2000-06-15 01:07:27 +00:00
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
mActivePluginList.remove(plugin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-14 23:03:47 +00:00
|
|
|
// try to get the max cached plugins from a pref or use default
|
|
|
|
PRUint32 max_num;
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
|
|
|
if (prefs) rv = prefs->GetIntPref(NS_PREF_MAX_NUM_CACHED_PLUGINS,(int *)&max_num);
|
|
|
|
if (!NS_SUCCEEDED(rv)) max_num = DEFAULT_NUMBER_OF_STOPPED_PLUGINS;
|
|
|
|
|
|
|
|
if(mActivePluginList.getStoppedCount() >= max_num)
|
2001-02-02 23:48:17 +00:00
|
|
|
{
|
|
|
|
nsActivePlugin * oldest = mActivePluginList.findOldestStopped();
|
|
|
|
if(oldest != nsnull)
|
|
|
|
mActivePluginList.remove(oldest);
|
|
|
|
}
|
|
|
|
plugin->setStopped(PR_TRUE);
|
2000-06-15 01:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-04 22:32:27 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/* Called by InstantiateEmbededPlugin() */
|
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsresult nsPluginHostImpl::NewEmbededPluginStream(nsIURI* aURL,
|
1998-09-15 03:48:58 +00:00
|
|
|
nsIPluginInstanceOwner *aOwner,
|
2001-02-02 23:48:17 +00:00
|
|
|
nsIPluginInstance* aInstance)
|
1998-08-05 04:21:36 +00:00
|
|
|
{
|
2001-02-02 23:48:17 +00:00
|
|
|
nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
|
1999-07-30 23:51:53 +00:00
|
|
|
if (listener == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv;
|
1998-09-15 03:48:58 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
if (!aURL)
|
|
|
|
return NS_OK;
|
1998-08-05 04:21:36 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
// if we have an instance, everything has been set up
|
|
|
|
// if we only have an owner, then we need to pass it in
|
|
|
|
// so the listener can set up the instance later after
|
|
|
|
// we've determined the mimetype of the stream
|
|
|
|
if(aInstance != nsnull)
|
|
|
|
rv = listener->InitializeEmbeded(aURL, aInstance);
|
|
|
|
else if(aOwner != nsnull)
|
|
|
|
rv = listener->InitializeEmbeded(aURL, nsnull, aOwner, (nsIPluginHost *)this);
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE;
|
1998-09-15 03:48:58 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
// XXX: Null LoadGroup?
|
|
|
|
rv = NS_OpenURI(listener, nsnull, aURL, nsnull);
|
|
|
|
}
|
1998-09-15 03:48:58 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
//NS_RELEASE(aURL);
|
1998-08-05 04:21:36 +00:00
|
|
|
|
2001-02-02 23:48:17 +00:00
|
|
|
return rv;
|
1998-09-15 03:48:58 +00:00
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
/* Called by InstantiateFullPagePlugin() */
|
|
|
|
|
2000-04-22 20:50:22 +00:00
|
|
|
nsresult nsPluginHostImpl::NewFullPagePluginStream(nsIStreamListener *&aStreamListener,
|
|
|
|
nsIPluginInstance *aInstance)
|
1998-09-15 03:48:58 +00:00
|
|
|
{
|
1999-01-25 08:05:00 +00:00
|
|
|
nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
|
1999-07-30 23:51:53 +00:00
|
|
|
if (listener == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv;
|
1998-09-15 03:48:58 +00:00
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
rv = listener->InitializeFullPage(aInstance);
|
1998-09-15 03:48:58 +00:00
|
|
|
|
|
|
|
aStreamListener = (nsIStreamListener *)listener;
|
|
|
|
NS_IF_ADDREF(listener);
|
|
|
|
|
|
|
|
return rv;
|
1998-08-05 04:21:36 +00:00
|
|
|
}
|
|
|
|
|
1999-01-25 08:05:00 +00:00
|
|
|
// nsIFileUtilities interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::GetProgramPath(const char* *result)
|
|
|
|
{
|
1999-03-20 23:11:25 +00:00
|
|
|
static nsSpecialSystemDirectory programDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
|
|
|
*result = programDir;
|
1999-01-25 08:05:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::GetTempDirPath(const char* *result)
|
|
|
|
{
|
1999-03-20 23:11:25 +00:00
|
|
|
static nsSpecialSystemDirectory tempDir(nsSpecialSystemDirectory::OS_TemporaryDirectory);
|
|
|
|
*result = tempDir;
|
1999-01-25 08:05:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::NewTempFileName(const char* prefix, PRUint32 bufLen, char* resultBuf)
|
|
|
|
{
|
1999-03-20 23:11:25 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsICookieStorage interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCookieBuffer, PRUint32& inOutCookieSize)
|
|
|
|
{
|
1999-10-21 21:09:21 +00:00
|
|
|
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
nsString cookieString;
|
|
|
|
nsCOMPtr<nsIURI> uriIn;
|
|
|
|
char *bufPtr;
|
|
|
|
|
|
|
|
if ((nsnull == inCookieURL) || (0 >= inOutCookieSize)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIIOService, ioService, kIOServiceCID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || (nsnull == ioService)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICookieService, cookieService, kCookieServiceCID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || (nsnull == cookieService)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make an nsURI from the argument url
|
|
|
|
rv = ioService->NewURI(inCookieURL, nsnull, getter_AddRefs(uriIn));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = cookieService->GetCookieString(uriIn, cookieString);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) ||
|
2000-11-17 22:22:47 +00:00
|
|
|
(inOutCookieSize < cookieString.Length())) {
|
1999-10-21 21:09:21 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
bufPtr = cookieString.ToCString((char *) inOutCookieBuffer,
|
|
|
|
inOutCookieSize);
|
|
|
|
if (nsnull == bufPtr) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
inOutCookieSize = cookieString.Length();
|
|
|
|
rv = NS_OK;
|
|
|
|
|
|
|
|
return rv;
|
1999-03-20 23:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::SetCookie(const char* inCookieURL, const void* inCookieBuffer, PRUint32 inCookieSize)
|
|
|
|
{
|
1999-10-21 21:09:21 +00:00
|
|
|
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
nsString cookieString;
|
|
|
|
nsCOMPtr<nsIURI> uriIn;
|
|
|
|
|
|
|
|
if ((nsnull == inCookieURL) || (nsnull == inCookieBuffer) ||
|
|
|
|
(0 >= inCookieSize)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIIOService, ioService, kIOServiceCID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || (nsnull == ioService)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICookieService, cookieService, kCookieServiceCID, &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || (nsnull == cookieService)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make an nsURI from the argument url
|
|
|
|
rv = ioService->NewURI(inCookieURL, nsnull, getter_AddRefs(uriIn));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-04-03 09:20:26 +00:00
|
|
|
cookieString.AssignWithConversion((const char *) inCookieBuffer,(PRInt32) inCookieSize);
|
1999-10-21 21:09:21 +00:00
|
|
|
|
2000-09-07 07:00:36 +00:00
|
|
|
rv = cookieService->SetCookieString(uriIn, nsnull, cookieString); // needs an nsHTMLDocument parameter
|
1999-10-21 21:09:21 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-01-25 08:05:00 +00:00
|
|
|
}
|
2000-09-14 06:03:37 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-09-14 23:58:17 +00:00
|
|
|
|
|
|
|
if(mDontShowBadPluginMessage)
|
|
|
|
return rv;
|
2000-09-14 06:03:37 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrompt> prompt(do_GetService(kNetSupportDialogCID));
|
|
|
|
nsCOMPtr<nsIIOService> io(do_GetService(kIOServiceCID));
|
|
|
|
nsCOMPtr<nsIStringBundleService> strings(do_GetService(kStringBundleServiceCID));
|
|
|
|
|
|
|
|
if (!prompt || !io || !strings)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
char *spec = nsnull;
|
|
|
|
nsILocale* locale = nsnull;
|
|
|
|
|
|
|
|
PRInt32 buttonPressed;
|
|
|
|
PRBool checkboxState = PR_FALSE;
|
|
|
|
|
|
|
|
rv = io->NewURI(PLUGIN_PROPERTIES_URL, nsnull, getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = uri->GetSpec(&spec);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
nsCRT::free(spec);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = strings->CreateBundle(spec, locale, getter_AddRefs(bundle));
|
|
|
|
nsCRT::free(spec);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRUnichar *title = nsnull;
|
|
|
|
PRUnichar *message = nsnull;
|
|
|
|
PRUnichar *checkboxMessage = nsnull;
|
|
|
|
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginTitle"),
|
|
|
|
&title);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginMessage"),
|
|
|
|
&message);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
nsMemory::Free((void *)title);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginCheckboxMessage"),
|
|
|
|
&checkboxMessage);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
nsMemory::Free((void *)title);
|
|
|
|
nsMemory::Free((void *)message);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = prompt->UniversalDialog(nsnull, /* title message */
|
|
|
|
title, /* title text in top line of window */
|
|
|
|
message, /* this is the main message */
|
|
|
|
checkboxMessage, /* This is the checkbox message */
|
|
|
|
nsnull, /* first button text, becomes OK by default */
|
|
|
|
nsnull, /* second button text, becomes CANCEL by default */
|
|
|
|
nsnull, /* third button text */
|
|
|
|
nsnull, /* fourth button text */
|
|
|
|
nsnull, /* first edit field label */
|
|
|
|
nsnull, /* second edit field label */
|
|
|
|
nsnull, /* first edit field initial and final value */
|
|
|
|
nsnull, /* second edit field initial and final value */
|
|
|
|
nsnull, /* icon: question mark by default */
|
|
|
|
&checkboxState, /* initial and final value of checkbox */
|
|
|
|
1, /* number of buttons */
|
|
|
|
0, /* number of edit fields */
|
|
|
|
0, /* is first edit field a password field */
|
|
|
|
&buttonPressed);
|
|
|
|
|
2000-09-14 23:58:17 +00:00
|
|
|
if (checkboxState)
|
|
|
|
mDontShowBadPluginMessage = PR_TRUE;
|
|
|
|
|
2000-09-14 06:03:37 +00:00
|
|
|
nsMemory::Free((void *)title);
|
|
|
|
nsMemory::Free((void *)message);
|
|
|
|
nsMemory::Free((void *)checkboxMessage);
|
|
|
|
return rv;
|
|
|
|
}
|