diff --git a/mozilla/layout/base/src/Makefile.in b/mozilla/layout/base/src/Makefile.in index a07f4bd1a35..f2d86317179 100644 --- a/mozilla/layout/base/src/Makefile.in +++ b/mozilla/layout/base/src/Makefile.in @@ -58,7 +58,6 @@ CPPSRCS = \ nsNameSpaceManager.cpp \ nsNodeInfo.cpp \ nsNodeInfoManager.cpp \ - nsPluginViewer.cpp \ nsPresContext.cpp \ nsPresState.cpp \ nsPrintContext.cpp \ diff --git a/mozilla/layout/base/src/makefile.win b/mozilla/layout/base/src/makefile.win index 250c7493897..70a95ef8985 100644 --- a/mozilla/layout/base/src/makefile.win +++ b/mozilla/layout/base/src/makefile.win @@ -52,7 +52,6 @@ CPPSRCS = \ nsNameSpaceManager.cpp \ nsNodeInfo.cpp \ nsNodeInfoManager.cpp \ - nsPluginViewer.cpp \ nsPresContext.cpp \ nsPresState.cpp \ nsPrintContext.cpp \ @@ -103,7 +102,6 @@ CPP_OBJS= \ .\$(OBJDIR)\nsNameSpaceManager.obj \ .\$(OBJDIR)\nsNodeInfo.obj \ .\$(OBJDIR)\nsNodeInfoManager.obj \ - .\$(OBJDIR)\nsPluginViewer.obj \ .\$(OBJDIR)\nsPresContext.obj \ .\$(OBJDIR)\nsPresState.obj \ .\$(OBJDIR)\nsPrintContext.obj \ diff --git a/mozilla/layout/base/src/nsPluginViewer.cpp b/mozilla/layout/base/src/nsPluginViewer.cpp deleted file mode 100644 index 16142f47b25..00000000000 --- a/mozilla/layout/base/src/nsPluginViewer.cpp +++ /dev/null @@ -1,900 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * 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/ - * - * 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. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#include "nsCOMPtr.h" -#include "nscore.h" -#include "nsCRT.h" -#include "nsIContentViewer.h" -#include "nsIPluginHost.h" -#include "nsIPluginInstance.h" -#include "nsIStreamListener.h" -#include "nsIURL.h" -#include "nsIChannel.h" -#include "nsNetUtil.h" -#include "nsIComponentManager.h" -#include "nsWidgetsCID.h" -#include "nsILinkHandler.h" -#include "nsIWebShell.h" -#include "nsIContentViewerEdit.h" -#include "nsIContentViewerFile.h" -#include "nsIContent.h" -#include "nsIDocument.h" -#include "nsIInterfaceRequestor.h" -#include "nsIDocShellTreeItem.h" -#include "nsIDocShellTreeOwner.h" -#include "nsIWebBrowserChrome.h" -#include "nsIDOMDocument.h" - -// Class IDs -static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); -static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); - -// Interface IDs -static NS_DEFINE_IID(kIContentViewerIID, NS_ICONTENT_VIEWER_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID); -static NS_DEFINE_IID(kIPluginInstanceOwnerIID, NS_IPLUGININSTANCEOWNER_IID); -static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); -static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID); -static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); -static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); - - -class PluginViewerImpl; - -class PluginListener : public nsIStreamListener { -public: - PluginListener(PluginViewerImpl* aViewer); - virtual ~PluginListener(); - - // nsISupports - NS_DECL_ISUPPORTS - - // nsIStreamObserver methods: - NS_DECL_NSISTREAMOBSERVER - - // nsIStreamListener methods: - NS_DECL_NSISTREAMLISTENER - - PluginViewerImpl* mViewer; - nsIStreamListener* mNextStream; -}; - -class pluginInstanceOwner : public nsIPluginInstanceOwner -{ -public: - pluginInstanceOwner(); - virtual ~pluginInstanceOwner(); - - NS_DECL_ISUPPORTS - - //nsIPluginInstanceOwner interface - - NS_IMETHOD SetInstance(nsIPluginInstance *aInstance); - - NS_IMETHOD GetInstance(nsIPluginInstance *&aInstance); - - NS_IMETHOD GetWindow(nsPluginWindow *&aWindow); - - NS_IMETHOD GetMode(nsPluginMode *aMode); - - NS_IMETHOD CreateWidget(void); - - NS_IMETHOD GetURL(const char *aURL, const char *aTarget, void *aPostData); - - NS_IMETHOD ShowStatus(const char *aStatusMsg); - - NS_IMETHOD GetDocument(nsIDocument* *aDocument); - - //locals - - NS_IMETHOD Init(PluginViewerImpl *aViewer, nsIWidget *aWindow); - -private: - nsPluginWindow mPluginWindow; - nsIPluginInstance *mInstance; - nsIWidget *mWindow; //we do not addref this... - PluginViewerImpl *mViewer; //we do not addref this... -}; - -class PluginViewerImpl : public nsIContentViewer, - public nsIContentViewerEdit, - public nsIContentViewerFile -{ -public: - PluginViewerImpl(const char* aCommand); - nsresult Init(nsIStreamListener** aDocListener); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - // nsISupports - NS_DECL_ISUPPORTS - - // nsIContentViewer - NS_IMETHOD Init(nsIWidget* aParentWidget, - nsIDeviceContext* aDeviceContext, - const nsRect& aBounds); - NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); - NS_IMETHOD SetContainer(nsISupports* aContainer); - NS_IMETHOD GetContainer(nsISupports** aContainerResult); - NS_IMETHOD LoadComplete(nsresult aStatus); - NS_IMETHOD Destroy(void); - NS_IMETHOD Stop(void); - NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); - NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); - NS_IMETHOD GetBounds(nsRect& aResult); - NS_IMETHOD SetBounds(const nsRect& aBounds); - NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); - NS_IMETHOD Show(); - NS_IMETHOD Hide(); - NS_IMETHOD SetEnableRendering(PRBool aOn); - NS_IMETHOD GetEnableRendering(PRBool* aResult); - - // nsIContentViewerEdit - NS_DECL_NSICONTENTVIEWEREDIT - - // nsIContentViewerFile - NS_DECL_NSICONTENTVIEWERFILE - - virtual ~PluginViewerImpl(); - - nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, - nsIStreamListener*& aResult); - - nsresult MakeWindow(nsNativeWidget aParent, - nsIDeviceContext* aDeviceContext, - const nsRect& aBounds); - - nsresult StartLoad(nsIChannel* channel, nsIStreamListener*& aResult); - - void ForceRefresh(void); - - nsresult GetURI(nsIURI* *aURI); - - nsresult GetDocument(nsIDocument* *aDocument); - - nsIWidget* mWindow; - nsIDocument* mDocument; - nsCOMPtr mContainer; - nsIChannel* mChannel; - pluginInstanceOwner *mOwner; - PRBool mEnableRendering; -}; - -//---------------------------------------------------------------------- - -nsresult -NS_NewPluginContentViewer(const char* aCommand, - nsIStreamListener** aDocListener, - nsIContentViewer** aDocViewer) -{ - PluginViewerImpl* it = new PluginViewerImpl(aCommand); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsresult rv = it->Init(aDocListener); - if (NS_FAILED(rv)) { - delete it; - return rv; - } - return it->QueryInterface(kIContentViewerIID, (void**) aDocViewer); -} - -// Note: operator new zeros our memory -PluginViewerImpl::PluginViewerImpl(const char* aCommand) -{ - NS_INIT_REFCNT(); - mEnableRendering = PR_TRUE; -} - -nsresult -PluginViewerImpl::Init(nsIStreamListener** aDocListener) -{ - nsIStreamListener* it = new PluginListener(this); - if (it == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(it); - *aDocListener = it; - return NS_OK; -} - -// ISupports implementation... -NS_IMPL_ADDREF(PluginViewerImpl) -NS_IMPL_RELEASE(PluginViewerImpl) - -nsresult -PluginViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - - if (aIID.Equals(kIContentViewerIID)) { - nsIContentViewer* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsIContentViewer* tmp1 = this; - nsISupports* tmp2 = tmp1; - *aInstancePtr = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -PluginViewerImpl::~PluginViewerImpl() -{ - NS_IF_RELEASE(mOwner); - if (nsnull != mWindow) { - mWindow->Destroy(); - NS_RELEASE(mWindow); - } - NS_IF_RELEASE(mDocument); - NS_IF_RELEASE(mChannel); -} - -/* - * This method is called by the Document Loader once a document has - * been created for a particular data stream... The content viewer - * must cache this document for later use when Init(...) is called. - */ -NS_IMETHODIMP -PluginViewerImpl::BindToDocument(nsISupports *aDoc, const char *aCommand) -{ -#ifdef NS_DEBUG - printf("PluginViewerImpl::BindToDocument\n"); -#endif - return aDoc->QueryInterface(kIDocumentIID, (void**)&mDocument); - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::SetContainer(nsISupports* aContainer) -{ - mContainer = aContainer; - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::GetContainer(nsISupports** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = mContainer; - NS_IF_ADDREF(*aResult); - - return NS_OK; -} - - -NS_IMETHODIMP -PluginViewerImpl::Init(nsIWidget* aParentWidget, - nsIDeviceContext* aDeviceContext, - const nsRect& aBounds) -{ - nsresult rv = MakeWindow(aParentWidget->GetNativeData(NS_NATIVE_WIDGET), - aDeviceContext, aBounds); - if (NS_OK == rv) { - mOwner = new pluginInstanceOwner(); - if (nsnull != mOwner) { - NS_ADDREF(mOwner); - rv = mOwner->Init(this, mWindow); - } - } - return rv; -} - -nsresult -PluginViewerImpl::StartLoad(nsIChannel* channel, nsIStreamListener*& aResult) -{ - NS_IF_RELEASE(mChannel); - mChannel = channel; - NS_ADDREF(mChannel); - -#ifdef DEBUG - char* contentType; - mChannel->GetContentType(&contentType); - printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType); - nsCRT::free(contentType); -#endif - - aResult = nsnull; - - // Only instantiate the plugin if our container can host it - nsCOMPtr host; - - host = do_GetService(kCPluginManagerCID); - nsresult rv = NS_ERROR_FAILURE; - if(host) - { - nsRect r; - mWindow->GetClientBounds(r); - rv = CreatePlugin(host, nsRect(0, 0, r.width, r.height), aResult); - } - - return rv; -} - -nsresult -PluginViewerImpl::CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, - nsIStreamListener*& aResult) -{ - nsresult rv = NS_OK; - - if (nsnull != mOwner) { - nsPluginWindow *win; - - mOwner->GetWindow(win); - - win->x = aBounds.x; - win->y = aBounds.y; - win->width = aBounds.width; - win->height = aBounds.height; - win->clipRect.top = aBounds.y; - win->clipRect.left = aBounds.x; - win->clipRect.bottom = aBounds.YMost(); - win->clipRect.right = aBounds.XMost(); - #ifdef XP_UNIX - win->ws_info = nsnull; //XXX need to figure out what this is. MMP - #endif - - nsIURI* uri; - rv = mChannel->GetURI(&uri); - if (NS_FAILED(rv)) return rv; - - char* spec; - rv = uri->GetSpec(&spec); - NS_RELEASE(uri); - if (NS_FAILED(rv)) return rv; - nsAutoString str; str.AssignWithConversion(spec); - nsCRT::free(spec); - - char* ct; - rv = mChannel->GetContentType(&ct); - if (NS_FAILED(rv)) return rv; - rv = aHost->InstantiateFullPagePlugin(ct, str, aResult, mOwner); - delete[] ct; - } - - return rv; -} - -NS_IMETHODIMP -PluginViewerImpl::Stop(void) -{ - // XXX write this - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::LoadComplete(nsresult aStatus) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -PluginViewerImpl::Destroy(void) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -PluginViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) -{ - return CallQueryInterface(mDocument, aResult); -} - -NS_IMETHODIMP -PluginViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) -{ - return NS_ERROR_FAILURE; -} - -static nsEventStatus PR_CALLBACK -HandlePluginEvent(nsGUIEvent *aEvent) -{ - return nsEventStatus_eIgnore; -} -nsresult -PluginViewerImpl::MakeWindow(nsNativeWidget aParent, - nsIDeviceContext* aDeviceContext, - const nsRect& aBounds) -{ - nsresult rv = - nsComponentManager::CreateInstance(kChildWindowCID, nsnull, kIWidgetIID, - (void**)&mWindow); - if (NS_OK != rv) { - return rv; - } - mWindow->Create(aParent, aBounds, HandlePluginEvent, aDeviceContext); - return rv; -} - -NS_IMETHODIMP -PluginViewerImpl::GetBounds(nsRect& aResult) -{ - NS_PRECONDITION(nsnull != mWindow, "null window"); - if (nsnull != mWindow) { - mWindow->GetBounds(aResult); - } - else { - aResult.SetRect(0, 0, 0, 0); - } - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::SetBounds(const nsRect& aBounds) -{ - NS_PRECONDITION(nsnull != mWindow, "null window"); - if (nsnull != mWindow) { - // Don't have the widget repaint. Layout will generate repaint requests - // during reflow - nsIPluginInstance *inst; - mWindow->Resize(aBounds.x, aBounds.y, aBounds.width, aBounds.height, PR_FALSE); - if ((nsnull != mOwner) && (NS_OK == mOwner->GetInstance(inst)) && (nsnull != inst)) { - nsPluginWindow *win; - if (NS_OK == mOwner->GetWindow(win)) { - win->x = aBounds.x; - win->y = aBounds.y; - win->width = aBounds.width; - win->height = aBounds.height; - win->clipRect.top = aBounds.y; - win->clipRect.left = aBounds.x; - win->clipRect.bottom = aBounds.YMost(); - win->clipRect.right = aBounds.XMost(); - - inst->SetWindow(win); - } - NS_RELEASE(inst); - } - } - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::Move(PRInt32 aX, PRInt32 aY) -{ - NS_PRECONDITION(nsnull != mWindow, "null window"); - if (nsnull != mWindow) { - nsIPluginInstance *inst; - mWindow->Move(aX, aY); - if ((nsnull != mOwner) && (NS_OK == mOwner->GetInstance(inst)) && (nsnull != inst)) { - nsPluginWindow *win; - if (NS_OK == mOwner->GetWindow(win)) { - win->x = aX; - win->y = aY; - win->clipRect.bottom = (win->clipRect.bottom - win->clipRect.top) + aY; - win->clipRect.right = (win->clipRect.right - win->clipRect.left) + aX; - win->clipRect.top = aY; - win->clipRect.left = aX; - - inst->SetWindow(win); - } - NS_RELEASE(inst); - } - } - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::Show() -{ - NS_PRECONDITION(nsnull != mWindow, "null window"); - if (nsnull != mWindow) { - mWindow->Show(PR_TRUE); - } - - // XXX should we call SetWindow here? - - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::Hide() -{ - NS_PRECONDITION(nsnull != mWindow, "null window"); - if (nsnull != mWindow) { - mWindow->Show(PR_FALSE); - } - - // should we call SetWindow(nsnull) here? - - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::SetEnableRendering(PRBool aOn) -{ - mEnableRendering = aOn; - return NS_OK; -} - -NS_IMETHODIMP -PluginViewerImpl::GetEnableRendering(PRBool* aResult) -{ - NS_PRECONDITION(nsnull != aResult, "null OUT ptr"); - if (aResult) { - *aResult = mEnableRendering; - } - return NS_OK; -} - -void -PluginViewerImpl::ForceRefresh() -{ - mWindow->Invalidate(PR_TRUE); -} - -nsresult PluginViewerImpl::GetURI(nsIURI* *aURI) -{ - return mChannel->GetURI(aURI); -} - -nsresult PluginViewerImpl::GetDocument(nsIDocument* *aDocument) -{ - NS_IF_ADDREF(mDocument); - *aDocument = mDocument; - return NS_OK; -} - -/* ======================================================================================== - * nsIContentViewerFile - * ======================================================================================== */ - -NS_IMETHODIMP PluginViewerImpl::Search() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::GetSearchable(PRBool *aSearchable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::ClearSelection() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::SelectAll() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::CopySelection() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::GetCopyable(PRBool *aCopyable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::CutSelection() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::GetCutable(PRBool *aCutable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::Paste() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* ======================================================================================== - * nsIContentViewerEdit - * ======================================================================================== */ -NS_IMETHODIMP -PluginViewerImpl::Save() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -PluginViewerImpl::GetSaveable(PRBool *aSaveable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -PluginViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) -{ - return NS_OK; // XXX: hey, plug in guys! implement me! -} - - -NS_IMETHODIMP -PluginViewerImpl::GetPrintable(PRBool *aPrintable) -{ - NS_ENSURE_ARG_POINTER(aPrintable); - - *aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me! - return NS_OK; -} - - -NS_IMETHODIMP -PluginViewerImpl::PrintContent(nsIWebShell *aParent, nsIDeviceContext *aDContext) -{ - NS_ENSURE_ARG_POINTER(aParent); - NS_ENSURE_ARG_POINTER(aDContext); - - return NS_OK; -} - - -//---------------------------------------------------------------------- - -PluginListener::PluginListener(PluginViewerImpl* aViewer) -{ - NS_INIT_REFCNT(); - mViewer = aViewer; - NS_ADDREF(aViewer); -} - -PluginListener::~PluginListener() -{ - NS_RELEASE(mViewer); - NS_IF_RELEASE(mNextStream); -} - -NS_IMPL_ISUPPORTS(PluginListener, kIStreamListenerIID) - -NS_IMETHODIMP -PluginListener::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) -{ - nsresult rv; - char* contentType = nsnull; - - rv = channel->GetContentType(&contentType); - if (NS_FAILED(rv)) { - return rv; - } - rv = mViewer->StartLoad(channel, mNextStream); - - if (NS_FAILED(rv)) { - return rv; - } - if (nsnull == mNextStream) - return NS_ERROR_FAILURE; - return mNextStream->OnStartRequest(channel, ctxt); -} - -NS_IMETHODIMP -PluginListener::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, - nsresult status, const PRUnichar *errorMsg) -{ - if (nsnull == mNextStream) { - return NS_ERROR_FAILURE; - } - return mNextStream->OnStopRequest(channel, ctxt, status, errorMsg); -} - -NS_IMETHODIMP -PluginListener::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, - nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count) -{ - if (nsnull == mNextStream) { - return NS_ERROR_FAILURE; - } - return mNextStream->OnDataAvailable(channel, ctxt, inStr, sourceOffset, count); -} - -//---------------------------------------------------------------------- - -pluginInstanceOwner :: pluginInstanceOwner() -{ - NS_INIT_REFCNT(); - - memset(&mPluginWindow, 0, sizeof(mPluginWindow)); - mInstance = nsnull; - mWindow = nsnull; - mViewer = nsnull; -} - -pluginInstanceOwner :: ~pluginInstanceOwner() -{ - if (nsnull != mInstance) - { - mInstance->Stop(); - mInstance->Destroy(); - NS_RELEASE(mInstance); - } - - mWindow = nsnull; - mViewer = nsnull; -} - -NS_IMPL_ISUPPORTS(pluginInstanceOwner, kIPluginInstanceOwnerIID); - -NS_IMETHODIMP pluginInstanceOwner :: SetInstance(nsIPluginInstance *aInstance) -{ - NS_IF_RELEASE(mInstance); - mInstance = aInstance; - NS_IF_ADDREF(mInstance); - - return NS_OK; -} - -NS_IMETHODIMP pluginInstanceOwner :: GetInstance(nsIPluginInstance *&aInstance) -{ - NS_IF_ADDREF(mInstance); - aInstance = mInstance; - - return NS_OK; -} - -NS_IMETHODIMP pluginInstanceOwner :: GetWindow(nsPluginWindow *&aWindow) -{ - aWindow = &mPluginWindow; - return NS_OK; -} - -NS_IMETHODIMP pluginInstanceOwner :: GetMode(nsPluginMode *aMode) -{ - *aMode = nsPluginMode_Full; - return NS_OK; -} - -NS_IMETHODIMP pluginInstanceOwner :: CreateWidget(void) -{ - PRBool windowless; - - if (nsnull != mInstance) - { - mInstance->GetValue(nsPluginInstanceVariable_WindowlessBool, (void *)&windowless); - - if (PR_TRUE == windowless) - { - mPluginWindow.window = nsnull; //XXX this needs to be a HDC - mPluginWindow.type = nsPluginWindowType_Drawable; - } - else if (nsnull != mWindow) - { - mPluginWindow.window = (nsPluginPort *)mWindow->GetNativeData(NS_NATIVE_PLUGIN_PORT); - mPluginWindow.type = nsPluginWindowType_Window; - } - else - return NS_ERROR_FAILURE; - } - else - return NS_ERROR_FAILURE; - - return NS_OK; -} - -NS_IMETHODIMP pluginInstanceOwner :: GetURL(const char *aURL, const char *aTarget, void *aPostData) -{ - nsresult rv; - - if (nsnull != mViewer) - { - nsCOMPtr cont; - - rv = mViewer->GetContainer(getter_AddRefs(cont)); - - if (NS_OK == rv) - { - nsCOMPtr lh(do_QueryInterface(cont)); - - if (lh) - { - nsCOMPtr uri; - rv = mViewer->GetURI(getter_AddRefs(uri)); - - if (NS_OK == rv) - { - // Create an absolute URL - char* absURIStr; - rv = NS_MakeAbsoluteURI(&absURIStr, aURL, uri); - nsAutoString fullurl; fullurl.AssignWithConversion(absURIStr); - nsCRT::free(absURIStr); - - if (NS_OK == rv) { - nsAutoString unitarget; unitarget.AssignWithConversion(aTarget); - rv = lh->OnLinkClick(nsnull, eLinkVerb_Replace, fullurl.GetUnicode(), unitarget.GetUnicode(), nsnull); - } - } - } - } - } - else - rv = NS_ERROR_FAILURE; - - return rv; -} - -NS_IMETHODIMP pluginInstanceOwner :: ShowStatus(const char *aStatusMsg) -{ - nsresult rv = NS_ERROR_FAILURE; - - if (nsnull != mViewer) - { - nsCOMPtr cont; - - rv = mViewer->GetContainer(getter_AddRefs(cont)); - - if ((NS_OK == rv) && (nsnull != cont)) - { - nsCOMPtr docShellItem(do_QueryInterface(cont)); - - if (docShellItem) - { - nsCOMPtr treeOwner; - docShellItem->GetTreeOwner(getter_AddRefs(treeOwner)); - - if(treeOwner) - { - nsCOMPtr browserChrome(do_GetInterface(treeOwner)); - - if(browserChrome) - { - nsAutoString msg; msg.AssignWithConversion(aStatusMsg); - browserChrome->SetJSStatus(msg.GetUnicode()); - } - } - } - } - } - - return rv; -} - -NS_IMETHODIMP pluginInstanceOwner :: GetDocument(nsIDocument* *aDocument) -{ - return mViewer->GetDocument(aDocument); -} - -NS_IMETHODIMP pluginInstanceOwner :: Init(PluginViewerImpl *aViewer, nsIWidget *aWindow) -{ - //do not addref - mWindow = aWindow; - mViewer = aViewer; - - return NS_OK; -} diff --git a/mozilla/layout/build/nsLayoutDLF.cpp b/mozilla/layout/build/nsLayoutDLF.cpp index 376ea5036f3..c5736b3533a 100644 --- a/mozilla/layout/build/nsLayoutDLF.cpp +++ b/mozilla/layout/build/nsLayoutDLF.cpp @@ -33,7 +33,6 @@ #include "prprf.h" #include "nsNetUtil.h" #include "nsICSSLoader.h" -#include "nsIPluginHost.h" #include "nsRDFCID.h" #include "nsIRDFResource.h" @@ -55,7 +54,6 @@ static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID); static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID); static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID); -static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult); @@ -92,11 +90,6 @@ static char* gImageTypes[] = { 0 }; -extern nsresult -NS_NewPluginContentViewer(const char* aCommand, - nsIStreamListener** aDocListener, - nsIContentViewer** aDocViewer); - class nsLayoutDLF : public nsIDocumentLoaderFactory, public nsIDocStreamLoaderFactory { @@ -305,17 +298,8 @@ nsLayoutDLF::CreateInstance(const char *aCommand, } } - // Try plugin types - nsCOMPtr pluginHost = do_GetService(kCPluginManagerCID); - if(pluginHost) - { - if(pluginHost->IsPluginEnabledForType(aContentType) == NS_OK) - return NS_NewPluginContentViewer(aCommand, aDocListener, aDocViewer); - else - return NS_ERROR_FAILURE; - } - - return rv; + // If we get here, then we weren't able to create anything. Sorry! + return NS_ERROR_FAILURE; } diff --git a/mozilla/modules/plugin/base/public/nsIPluginManager.h b/mozilla/modules/plugin/base/public/nsIPluginManager.h index 86874600bbb..b65328545bb 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginManager.h +++ b/mozilla/modules/plugin/base/public/nsIPluginManager.h @@ -181,6 +181,47 @@ public: PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; + + /** + * Persistently register a plugin with the plugin + * manager. aMimeTypes, aMimeDescriptions, and aFileExtensions are + * parallel arrays that contain information about the MIME types + * that the plugin supports. + * + * @param aCID - the plugin's CID + * @param aPluginName - the plugin's name + * @param aDescription - a description of the plugin + * @param aMimeTypes - an array of MIME types that the plugin + * is prepared to handle + * @param aMimeDescriptions - an array of descriptions for the + * MIME types that the plugin can handle. + * @param aFileExtensions - an array of file extensions for + * the MIME types that the plugin can handle. + * @param aCount - the number of elements in the aMimeTypes, + * aMimeDescriptions, and aFileExtensions arrays. + * @result - NS_OK if the operation was successful. + */ + + NS_IMETHOD + RegisterPlugin(REFNSIID aCID, + const char* aPluginName, + const char* aDescription, + const char** aMimeTypes, + const char** aMimeDescriptions, + const char** aFileExtensions, + PRInt32 aCount) = 0; + + + /** + * Unregister a plugin from the plugin manager + * + * @param aCID the CID of the plugin to unregister. + * @result - NS_OK if the operation was successful. + */ + + NS_IMETHOD + UnregisterPlugin(REFNSIID aCID) = 0; + }; //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/modules/plugin/base/src/Makefile.in b/mozilla/modules/plugin/base/src/Makefile.in index 5ccd9829596..59ed5d79f02 100644 --- a/mozilla/modules/plugin/base/src/Makefile.in +++ b/mozilla/modules/plugin/base/src/Makefile.in @@ -29,14 +29,17 @@ include $(DEPTH)/config/autoconf.mk MODULE = layout LIBRARY_NAME = gkplugin SHORT_LIBNAME = ngplugin +IS_COMPONENT = 1 CPPSRCS = \ - nsPluginHostImpl.cpp \ - nsPluginFactory.cpp \ ns4xPlugin.cpp \ ns4xPluginInstance.cpp \ + nsPluginDocLoaderFactory.cpp \ + nsPluginHostImpl.cpp \ + nsPluginModule.cpp \ nsPluginInstancePeer.cpp \ + nsPluginViewer.cpp \ $(NULL) ifeq ($(OS_ARCH), BeOS) @@ -57,6 +60,8 @@ EXPORTS = \ EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) +EXTRA_DSO_LIBS += gkgfx + EXTRA_DSO_LDOPTS = \ $(MOZ_NECKO_UTIL_LIBS) \ $(MOZ_COMPONENT_LIBS) \ diff --git a/mozilla/modules/plugin/base/src/makefile.win b/mozilla/modules/plugin/base/src/makefile.win index 14937db7ef0..4e2bacd9fad 100644 --- a/mozilla/modules/plugin/base/src/makefile.win +++ b/mozilla/modules/plugin/base/src/makefile.win @@ -24,8 +24,8 @@ include <$(DEPTH)/config/config.mak> EXPORTS = \ - nsPluginsCID.h \ - nsIPluginHost.h \ + nsPluginsCID.h \ + nsIPluginHost.h \ nsIPluginInstanceOwner.h MAKE_OBJ_TYPE = DLL @@ -33,16 +33,19 @@ DLLNAME = gkplugin DLL=.\$(OBJDIR)\$(DLLNAME).dll MODULE=raptor +IS_COMPONENT=1 DEFINES =-D_IMPL_NS_PLUGIN -DWIN32_LEAN_AND_MEAN -OBJS = \ - .\$(OBJDIR)\nsPluginHostImpl.obj \ - .\$(OBJDIR)\nsPluginFactory.obj \ - .\$(OBJDIR)\ns4xPlugin.obj \ - .\$(OBJDIR)\ns4xPluginInstance.obj \ - .\$(OBJDIR)\nsPluginInstancePeer.obj \ - .\$(OBJDIR)\nsPluginsDirWin.obj \ +OBJS = \ + .\$(OBJDIR)\ns4xPlugin.obj \ + .\$(OBJDIR)\ns4xPluginInstance.obj \ + .\$(OBJDIR)\nsPluginDocLoaderFactory.obj \ + .\$(OBJDIR)\nsPluginHostImpl.obj \ + .\$(OBJDIR)\nsPluginModule.obj \ + .\$(OBJDIR)\nsPluginInstancePeer.obj \ + .\$(OBJDIR)\nsPluginViewer.obj \ + .\$(OBJDIR)\nsPluginsDirWin.obj \ $(NULL) LINCS = \ @@ -76,6 +79,7 @@ CACHELIBNAME=netcache.lib !endif LLIBS = \ + $(DIST)\lib\gkgfxwin.lib \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\xppref32.lib \ $(LIBNSPR) @@ -89,7 +93,7 @@ it: echo $(LLIBS) install:: $(DLL) - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components clobber:: rm -f $(DIST)\bin\$(DLLNAME).dll diff --git a/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.cpp b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.cpp new file mode 100644 index 00000000000..7a8ebf993ae --- /dev/null +++ b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsCOMPtr.h" +#include "nsIDocumentLoaderFactory.h" +#include "nsIPluginHost.h" +#include "nsIPluginManager.h" +#include "nsIServiceManager.h" +#include "nsPluginDocLoaderFactory.h" +#include "nsPluginViewer.h" + +NS_METHOD +nsPluginDocLoaderFactory::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) +{ + NS_PRECONDITION(aOuter == nsnull, "no aggregation"); + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + + nsPluginDocLoaderFactory* factory = new nsPluginDocLoaderFactory(); + if (! factory) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv; + NS_ADDREF(factory); + rv = factory->QueryInterface(aIID, aResult); + NS_RELEASE(factory); + return rv; +} + +NS_IMPL_ISUPPORTS1(nsPluginDocLoaderFactory, nsIDocumentLoaderFactory); + +NS_IMETHODIMP +nsPluginDocLoaderFactory::CreateInstance(const char *aCommand, + nsIChannel* aChannel, + nsILoadGroup* aLoadGroup, + const char* aContentType, + nsISupports* aContainer, + nsISupports* aExtraInfo, + nsIStreamListener** aDocListener, + nsIContentViewer** aDocViewer) +{ + static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); + nsCOMPtr pluginHost = do_GetService(kPluginManagerCID); + if(! pluginHost) + return NS_ERROR_FAILURE; + + if (pluginHost->IsPluginEnabledForType(aContentType) != NS_OK) + return NS_ERROR_FAILURE; + + return NS_NewPluginContentViewer(aCommand, aDocListener, aDocViewer); +} + +NS_IMETHODIMP +nsPluginDocLoaderFactory::CreateInstanceForDocument(nsISupports* aContainer, + nsIDocument* aDocument, + const char *aCommand, + nsIContentViewer** aDocViewerResult) +{ + NS_NOTREACHED("how'd I get here?"); + return NS_ERROR_FAILURE; +} diff --git a/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.h b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.h new file mode 100644 index 00000000000..fbf57322fa0 --- /dev/null +++ b/mozilla/modules/plugin/base/src/nsPluginDocLoaderFactory.h @@ -0,0 +1,76 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/* + + An nsIDocumentLoaderFactory that is used to load plugins + +*/ + +#ifndef nsPluginDocLoaderFactory_h__ +#define nsPluginDocLoaderFactory_h__ + +#include "nsIDocumentLoaderFactory.h" + +class nsIChannel; +class nsIContentViewer; +class nsILoadGroup; +class nsIStreamListener; + +/** + * An nsIDocumentLoaderFactory that is used to load plugins + */ +class nsPluginDocLoaderFactory : public nsIDocumentLoaderFactory +{ +protected: + nsPluginDocLoaderFactory() { NS_INIT_ISUPPORTS(); } + virtual ~nsPluginDocLoaderFactory() {} + +public: + static NS_METHOD + Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); + + NS_DECL_ISUPPORTS + + // nsIDocumentLoaderFactory + NS_IMETHOD CreateInstance(const char* aCommand, + nsIChannel* aChannel, + nsILoadGroup* aLoadGroup, + const char* aContentType, + nsISupports* aContainer, + nsISupports* aExtraInfo, + nsIStreamListener** aDocListener, + nsIContentViewer** aDocViewer); + + NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer, + nsIDocument* aDocument, + const char *aCommand, + nsIContentViewer** aDocViewerResult); +}; + +/* dd1b8d10-1dd1-11b2-9852-e162b2c46000 */ +#define NS_PLUGINDOCLOADERFACTORY_CID \ +{ 0xdd1b8d10, 0x1dd1, 0x11b2, { 0x98, 0x52, 0xe1, 0x62, 0xb2, 0xc4, 0x60, 0x00 } } + +#endif // nsPluginDocLoaderFactory_h__ + + diff --git a/mozilla/modules/plugin/base/src/nsPluginFactory.cpp b/mozilla/modules/plugin/base/src/nsPluginFactory.cpp deleted file mode 100644 index 09ffdfcb8ec..00000000000 --- a/mozilla/modules/plugin/base/src/nsPluginFactory.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nscore.h" -#include "nsIFactory.h" -#include "nsCOMPtr.h" - -//#include "nsPluginsCID.h" -#include "nsPluginHostImpl.h" -#include "nsIServiceManager.h" -#include "nsIPluginManager.h" - -//static NS_DEFINE_IID(kCPluginHost, NS_PLUGIN_HOST_CID); -static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIServiceManagerIID, NS_ISERVICEMANAGER_IID); - -class nsPluginFactory : public nsIFactory -{ - public: - NS_DECL_ISUPPORTS - - NS_DECL_NSIFACTORY - - nsPluginFactory(const nsCID &aClass, nsIServiceManager* serviceMgr); - - protected: - virtual ~nsPluginFactory(); - - private: - nsCID mClassID; - nsIServiceManager *mserviceMgr; -}; - -nsPluginFactory :: nsPluginFactory(const nsCID &aClass, nsIServiceManager* serviceMgr) -{ - NS_INIT_ISUPPORTS(); - mClassID = aClass; - // XXX Are we sure about this weak reference. -dp - mserviceMgr = serviceMgr; -} - -nsPluginFactory :: ~nsPluginFactory() -{ -} - -NS_IMPL_ISUPPORTS(nsPluginFactory, NS_GET_IID(nsIFactory)) - -nsresult nsPluginFactory :: CreateInstance(nsISupports *aOuter, - const nsIID &aIID, - void **aResult) -{ - if (aResult == NULL) { - return NS_ERROR_NULL_POINTER; - } - - if (aOuter) { - *aResult = nsnull; - return NS_ERROR_NO_AGGREGATION; - } - - *aResult = NULL; - - nsPluginHostImpl *inst = nsnull; - - //if (mClassID.Equals(kCPluginHost) || mClassID.Equals(kCPluginManagerCID) ){ - if (mClassID.Equals(kCPluginManagerCID) ) { - inst = new nsPluginHostImpl(mserviceMgr); - } else { - return NS_ERROR_NO_INTERFACE; - } - - if (inst == NULL) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(inst); // Stabilize - - nsresult res = inst->QueryInterface(aIID, aResult); - - NS_RELEASE(inst); // Destabilize and avoid leaks. Avoid calling delete - - return res; -} - -nsresult nsPluginFactory :: LockFactory(PRBool aLock) -{ - // Not implemented in simplest case. - return NS_OK; -} - -// return the proper factory to the caller -extern "C" NS_PLUGIN nsresult -NSGetFactory(nsISupports* serviceMgr, - const nsCID &aClass, - const char *aClassName, - const char *aProgID, - nsIFactory **aFactory) -{ - if (nsnull == aFactory) { - return NS_ERROR_NULL_POINTER; - } - - nsresult rv; - nsCOMPtr servMgr = do_QueryInterface(serviceMgr, &rv); - if (NS_FAILED(rv)) return rv; - - *aFactory = new nsPluginFactory(aClass, servMgr); - - if (nsnull == aFactory) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory); -} - diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index ce6886c76b3..da2ae3a049e 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -44,6 +44,14 @@ #include "nsIProgressEventSink.h" #include "nsIDocument.h" +// Friggin' X11 has to "#define None". Lame! +#ifdef None +#undef None +#endif + +#include "nsIRegistry.h" +#include "nsEnumeratorUtils.h" + // for the dialog #include "nsIStringBundle.h" #include "nsINetSupportDialogService.h" @@ -73,25 +81,27 @@ #include "nsSpecialSystemDirectory.h" #include "nsFileSpec.h" +#include "nsPluginDocLoaderFactory.h" #include "nsIDocumentLoaderFactory.h" -#include "nsLayoutCID.h" #ifdef XP_UNIX #include // for GDK_DISPLAY() #endif +// We need this hackery so that we can dynamically register doc +// loaders for the 4.x plugins that we discover. #if defined(XP_PC) -#define LAYOUT_DLL "gkhtml.dll" +#define PLUGIN_DLL "gkplugin.dll" #elif defined(XP_UNIX) || defined(XP_BEOS) -#define LAYOUT_DLL "libgklayout"MOZ_DLL_SUFFIX +#define PLUGIN_DLL "libgkplugin" MOZ_DLL_SUFFIX #elif defined(XP_MAC) -#define LAYOUT_DLL "LAYOUT_DLL" +#define PLUGIN_DLL "PLUGIN_DLL" #endif #ifdef XP_MAC -#define REL_LAYOUT_DLL LAYOUT_DLL +#define REL_PLUGIN_DLL PLUGIN_DLL #else -#define REL_LAYOUT_DLL "rel:"LAYOUT_DLL +#define REL_PLUGIN_DLL "rel:" PLUGIN_DLL #endif //uncomment this to use netlib to determine what the @@ -118,12 +128,13 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID); static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID); +static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID); + // for the dialog static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID); static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); -static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); #define PLUGIN_PROPERTIES_URL "chrome://global/locale/downloadProgress.properties" void DisplayNoDefaultPluginDialog(const char *mimeType); @@ -434,9 +445,6 @@ nsPluginTag::nsPluginTag() mNext = nsnull; mName = nsnull; mDescription = nsnull; - mMimeType = nsnull; - mMimeDescription = nsnull; - mExtensions = nsnull; mVariants = 0; mMimeTypeArray = nsnull; mMimeDescriptionArray = nsnull; @@ -447,7 +455,7 @@ nsPluginTag::nsPluginTag() mFileName = nsnull; } -inline char* new_str(char* str) +inline char* new_str(const char* str) { if(str == nsnull) return nsnull; @@ -463,9 +471,6 @@ nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag) mNext = nsnull; mName = new_str(aPluginTag->mName); mDescription = new_str(aPluginTag->mDescription); - mMimeType = new_str(aPluginTag->mMimeType); - mMimeDescription = new_str(aPluginTag->mMimeDescription); - mExtensions = new_str(aPluginTag->mExtensions); mVariants = aPluginTag->mVariants; mMimeTypeArray = nsnull; @@ -504,9 +509,6 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) mNext = nsnull; mName = new_str(aPluginInfo->fName); mDescription = new_str(aPluginInfo->fDescription); - mMimeType = new_str(aPluginInfo->fMimeType); - mMimeDescription = new_str(aPluginInfo->fMimeDescription); - mExtensions = new_str(aPluginInfo->fExtensions); mVariants = aPluginInfo->fVariantCount; mMimeTypeArray = nsnull; @@ -541,6 +543,40 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) mFlags = NS_PLUGIN_FLAG_ENABLED; } + +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), + 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]); + } + } +} + nsPluginTag::~nsPluginTag() { NS_IF_RELEASE(mEntryPoint); @@ -555,21 +591,6 @@ nsPluginTag::~nsPluginTag() mDescription = nsnull; } - if (nsnull != mMimeType) { - delete[] (mMimeType); - mMimeType = nsnull; - } - - if (nsnull != mMimeDescription) { - delete[] (mMimeDescription); - mMimeDescription = nsnull; - } - - if (nsnull != mExtensions) { - delete[] (mExtensions); - mExtensions = nsnull; - } - if (nsnull != mMimeTypeArray) { for (int i = 0; i < mVariants; i++) delete[] mMimeTypeArray[i]; @@ -1313,11 +1334,10 @@ nsPluginStreamListenerPeer::GetLoadGroup() ///////////////////////////////////////////////////////////////////////// -nsPluginHostImpl::nsPluginHostImpl(nsIServiceManager *serviceMgr) +nsPluginHostImpl::nsPluginHostImpl() { NS_INIT_REFCNT(); mPluginsLoaded = PR_FALSE; - mServiceMgr = serviceMgr; } nsPluginHostImpl::~nsPluginHostImpl() @@ -1340,66 +1360,29 @@ printf("killing plugin host\n"); } } -NS_IMPL_ADDREF(nsPluginHostImpl) -NS_IMPL_RELEASE(nsPluginHostImpl) +NS_IMPL_ISUPPORTS5(nsPluginHostImpl, + nsIPluginManager, + nsIPluginManager2, + nsIPluginHost, + nsIFileUtilities, + nsICookieStorage); -nsresult nsPluginHostImpl::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) +NS_METHOD +nsPluginHostImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); + NS_PRECONDITION(aOuter == nsnull, "no aggregation"); + if (aOuter) + return NS_ERROR_NO_AGGREGATION; - if (nsnull == aInstancePtrResult) - return NS_ERROR_NULL_POINTER; + nsPluginHostImpl* host = new nsPluginHostImpl(); + if (! host) + return NS_ERROR_OUT_OF_MEMORY; - if (aIID.Equals(nsIPluginManager::GetIID())) - { - *aInstancePtrResult = (void *)((nsIPluginManager *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIPluginManager2::GetIID())) - { - *aInstancePtrResult = (void *)((nsIPluginManager2 *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIPluginHost::GetIID())) - { - *aInstancePtrResult = (void *)((nsIPluginHost *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIFactory::GetIID())) - { - *aInstancePtrResult = (void *)((nsIFactory *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIFileUtilities::GetIID())) - { - *aInstancePtrResult = (void*)(nsIFileUtilities*)this; - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsICookieStorage::GetIID())) { - *aInstancePtrResult = (void*)(nsICookieStorage*)this; - AddRef(); - return NS_OK; - } - - if (aIID.Equals(kISupportsIID)) - { - *aInstancePtrResult = (void *)((nsISupports *)((nsIPluginHost *)this)); - AddRef(); - return NS_OK; - } - - return NS_NOINTERFACE; + nsresult rv; + NS_ADDREF(host); + rv = host->QueryInterface(aIID, aResult); + NS_RELEASE(host); + return rv; } NS_IMETHODIMP nsPluginHostImpl::GetValue(nsPluginManagerVariable aVariable, void *aValue) @@ -1422,6 +1405,9 @@ NS_IMETHODIMP nsPluginHostImpl::GetValue(nsPluginManagerVariable aVariable, void nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages) { + // XXX don't we want to nuke the old mPlugins right now? + // XXX for new-style plugins, we should also call + // nsIComponentManager::AutoRegister() mPluginsLoaded = PR_FALSE; return LoadPlugins(); } @@ -1575,6 +1561,73 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, return rv; } +NS_IMETHODIMP nsPluginHostImpl::RegisterPlugin(REFNSIID aCID, + const char* aPluginName, + const char* aDescription, + const char** aMimeTypes, + const char** aMimeDescriptions, + const char** aFileExtensions, + PRInt32 aCount) +{ + nsCOMPtr registry = do_CreateInstance(kRegistryCID); + if (! registry) + return NS_ERROR_FAILURE; + + nsresult rv; + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(rv)) return rv; + + nsCAutoString path = "software/plugins/"; + 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 registry = do_CreateInstance(kRegistryCID); + if (! registry) + return NS_ERROR_FAILURE; + + nsresult rv; + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(rv)) return rv; + + nsCAutoString path = "software/plugins/"; + char* cid = aCID.ToString(); + if (! cid) + return NS_ERROR_OUT_OF_MEMORY; + + path += cid; + nsMemory::Free(cid); + + return registry->RemoveSubtree(nsIRegistry::Common, path); +} + NS_IMETHODIMP nsPluginHostImpl::BeginWaitCursor(void) { return NS_ERROR_NOT_IMPLEMENTED; @@ -1731,6 +1784,20 @@ NS_IMETHODIMP nsPluginHostImpl::ProcessNextEvent(PRBool *bEventHandled) return NS_ERROR_NOT_IMPLEMENTED; } +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; +} + NS_IMETHODIMP nsPluginHostImpl::Init(void) { return NS_OK; @@ -2057,7 +2124,7 @@ void nsPluginHostImpl::AddInstanceToActiveList(nsIPluginInstance* aInstance, nsresult nsPluginHostImpl::RegisterPluginMimeTypesWithLayout(nsPluginTag * pluginTag, nsIComponentManager * compManager, - nsIFile * layoutPath) + nsIFile * path) { NS_ENSURE_ARG_POINTER(pluginTag); NS_ENSURE_ARG_POINTER(pluginTag->mMimeTypeArray); @@ -2067,10 +2134,17 @@ nsresult nsPluginHostImpl::RegisterPluginMimeTypesWithLayout(nsPluginTag * plugi for(int i = 0; i < pluginTag->mVariants; i++) { - char progid[512]; - char * contentType = pluginTag->mMimeTypeArray[i]; - PR_snprintf(progid, sizeof(progid), NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX "%s/%s", "view", contentType); - rv = compManager->RegisterComponentSpec(kDocumentFactoryImplCID, "Layout", progid, layoutPath, PR_TRUE, PR_TRUE); + static NS_DEFINE_CID(kPluginDocLoaderFactoryCID, NS_PLUGINDOCLOADERFACTORY_CID); + + nsCAutoString progid = NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX "view/"; + progid += pluginTag->mMimeTypeArray[i]; + + rv = compManager->RegisterComponentSpec(kPluginDocLoaderFactoryCID, + "Plugin Loader Stub", + progid, + path, + PR_TRUE, + PR_FALSE); } return rv; @@ -2557,12 +2631,17 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi nsIPlugin* plugin = pluginTag->mEntryPoint; if(plugin == NULL) { + // No, this is not a leak. GetGlobalServiceManager() doesn't + // addref the pointer on the way out. It probably should. + nsIServiceManager* serviceManager; + nsServiceManager::GetGlobalServiceManager(&serviceManager); + // need to get the plugin factory from this plugin. nsFactoryProc nsGetFactory = nsnull; nsGetFactory = (nsFactoryProc) PR_FindSymbol(pluginTag->mLibrary, "NSGetFactory"); if(nsGetFactory != nsnull) { - rv = nsGetFactory(mServiceMgr, kPluginCID, nsnull, nsnull, // XXX fix ClassName/ProgID + rv = nsGetFactory(serviceManager, kPluginCID, nsnull, nsnull, // XXX fix ClassName/ProgID (nsIFactory**)&pluginTag->mEntryPoint); plugin = pluginTag->mEntryPoint; if (plugin != NULL) @@ -2570,10 +2649,10 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi } else { - rv = ns4xPlugin::CreatePlugin(mServiceMgr, - pluginTag->mFileName, - pluginTag->mLibrary, - &pluginTag->mEntryPoint); + rv = ns4xPlugin::CreatePlugin(serviceManager, + pluginTag->mFileName, + pluginTag->mLibrary, + &pluginTag->mEntryPoint); plugin = pluginTag->mEntryPoint; pluginTag->mFlags |= NS_PLUGIN_FLAG_OLDSCHOOL; @@ -2597,16 +2676,17 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() { - do { - // 1. scan the plugins directory (where is it?) for eligible plugin libraries. - nsPluginsDir pluginsDir; - if (! pluginsDir.Valid()) - break; - // retrieve a path for layout module. Needed for plugin mime types registration nsCOMPtr compManager = do_GetService(kComponentManagerCID); nsCOMPtr path; - nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_LAYOUT_DLL, getter_AddRefs(path)); + nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_PLUGIN_DLL, getter_AddRefs(path)); + + LoadXPCOMPlugins(compManager, path); + + // 1. scan the plugins directory (where is it?) for eligible plugin libraries. + nsPluginsDir pluginsDir; + if (! pluginsDir.Valid()) + return NS_ERROR_FAILURE; for (nsDirectoryIterator iter(pluginsDir, PR_TRUE); iter.Exists(); iter++) { const nsFileSpec& file = iter; @@ -2646,9 +2726,6 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() mPluginsLoaded = PR_TRUE; return NS_OK; - } while (0); - - return NS_ERROR_FAILURE; } #else // go for new plugin finding logic on Windows @@ -2714,6 +2791,13 @@ static PRBool isUnwantedPlugin(nsPluginTag * tag) NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() { + // retrieve a path for layout module. Needed for plugin mime types registration + nsCOMPtr compManager = do_GetService(kComponentManagerCID); + nsCOMPtr path; + nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_PLUGIN_DLL, getter_AddRefs(path)); + + LoadXPCOMPlugins(compManager, path); + // 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 @@ -2726,11 +2810,6 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() if(!pluginsDir4x.Valid() && !pluginsDirMoz.Valid()) return NS_ERROR_FAILURE; - // retrieve a path for layout module. Needed for plugin mime types registration - nsCOMPtr compManager = do_GetService(kComponentManagerCID); - nsCOMPtr path; - nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_LAYOUT_DLL, getter_AddRefs(path)); - // first, make a list from MOZ_LOCAL installation for (nsDirectoryIterator iter(pluginsDirMoz, PR_TRUE); iter.Exists(); iter++) { @@ -2838,6 +2917,220 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() } #endif // XP_WIN -- end new plugin finding logic + +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. + nsAutoString path = NS_LITERAL_STRING("software/mozilla/XPCOM/classID/"); + path += NS_ConvertASCIItoUCS2(aCID); + + 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 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 enumerator; + rv = aRegistry->EnumerateAllSubtrees(aPluginKey, getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr 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 isupports; + subtrees->GetNext(getter_AddRefs(isupports)); + + nsCOMPtr 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 + = new nsPluginTag(name, + description, + filename, + mimetypes, + mimedescriptions, + extensions, + 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 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 enumerator; + rv = registry->EnumerateSubtrees(pluginsKey, getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr plugins; + rv = NS_NewAdapterEnumerator(getter_AddRefs(plugins), enumerator); + if (NS_FAILED(rv)) return rv; + + for (;;) { + PRBool hasMore; + plugins->HasMoreElements(&hasMore); + if (! hasMore) + break; + + nsCOMPtr isupports; + plugins->GetNext(getter_AddRefs(isupports)); + + nsCOMPtr 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); + + nsPluginTag* tag; + rv = LoadXPCOMPlugin(aComponentManager, registry, cid, key, &tag); + if (NS_FAILED(rv)) + continue; + + tag->mNext = mPlugins; + mPlugins = tag; + + // Create an nsIDocumentLoaderFactory wrapper in case we ever see + // any naked streams. + RegisterPluginMimeTypesWithLayout(tag, aComponentManager, aPath); + } + + return NS_OK; +} + /* Called by GetURL and PostURL */ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, @@ -3002,37 +3295,6 @@ nsresult nsPluginHostImpl::NewFullPagePluginStream(nsIStreamListener *&aStreamLi return rv; } -// nsIFactory interface - -nsresult nsPluginHostImpl::CreateInstance(nsISupports *aOuter, - const nsIID &aIID, - void **aResult) -{ - if (aResult == NULL) - return NS_ERROR_NULL_POINTER; - - nsISupports *inst = nsnull; - - if (inst == NULL) - return NS_ERROR_OUT_OF_MEMORY; - - // XXX Doh, we never get here... what is going on??? - - NS_ADDREF(inst); // Stabilize - - nsresult res = inst->QueryInterface(aIID, aResult); - - NS_RELEASE(inst); // Destabilize and avoid leaks. Avoid calling delete - - return res; -} - -nsresult nsPluginHostImpl::LockFactory(PRBool aLock) -{ - // Not implemented in simplest case. - return NS_OK; -} - // nsIFileUtilities interface NS_IMETHODIMP nsPluginHostImpl::GetProgramPath(const char* *result) diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index abbff6c1881..85f2933b67a 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -35,22 +35,34 @@ class ns4xPlugin; class nsFileSpec; -class nsIServiceManager; +class nsIComponentManager; +class nsIFile; +/** + * A linked-list of plugin information that is used for + * instantiating plugins and reflecting plugin information + * into JavaScript. + */ class nsPluginTag { public: nsPluginTag(); nsPluginTag(nsPluginTag* aPluginTag); nsPluginTag(nsPluginInfo* aPluginInfo); + + nsPluginTag(const char* aName, + const char* aDescription, + const char* aFileName, + const char* const* aMimeTypes, + const char* const* aMimeDescriptions, + const char* const* aExtensions, + PRInt32 aVariants); + ~nsPluginTag(); nsPluginTag *mNext; char *mName; char *mDescription; - char *mMimeType; - char *mMimeDescription; - char *mExtensions; PRInt32 mVariants; char **mMimeTypeArray; char **mMimeDescriptionArray; @@ -106,9 +118,12 @@ class nsPluginHostImpl : public nsIPluginManager2, public nsICookieStorage { public: - nsPluginHostImpl(nsIServiceManager *serviceMgr); + nsPluginHostImpl(); virtual ~nsPluginHostImpl(); + static NS_METHOD + Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW NS_DECL_ISUPPORTS @@ -147,6 +162,18 @@ public: PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); + NS_IMETHOD + RegisterPlugin(REFNSIID aCID, + const char* aPluginName, + const char* aDescription, + const char** aMimeTypes, + const char** aMimeDescriptions, + const char** aFileExtensions, + PRInt32 aCount); + + NS_IMETHOD + UnregisterPlugin(REFNSIID aCID); + //nsIPluginHost interface - used to communicate to the nsPluginInstanceOwner NS_IMETHOD @@ -157,7 +184,7 @@ public: NS_IMETHOD LoadPlugins(void); - + NS_IMETHOD GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin); @@ -217,8 +244,8 @@ public: NS_IMETHOD ProcessNextEvent(PRBool *bEventHandled); - //nsIFactory interface - used to create new Plugin instances - + // nsIFactory interface, from nsIPlugin. + // XXX not currently used? NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult); @@ -264,6 +291,9 @@ public: private: + nsresult + LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFile* aPath); + /* Called by InstantiatePlugin */ nsresult @@ -289,7 +319,6 @@ private: char *mPluginPath; nsPluginTag *mPlugins; PRBool mPluginsLoaded; - nsIServiceManager *mServiceMgr; nsActivePluginList mActivePluginList; }; diff --git a/mozilla/modules/plugin/base/src/nsPluginModule.cpp b/mozilla/modules/plugin/base/src/nsPluginModule.cpp new file mode 100644 index 00000000000..ab7ab0d5125 --- /dev/null +++ b/mozilla/modules/plugin/base/src/nsPluginModule.cpp @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Pierre Phaneuf + */ + +#include "nsIGenericFactory.h" +#include "nsIPluginManager.h" +#include "nsPluginsCID.h" +#include "nsPluginHostImpl.h" +#include "nsPluginDocLoaderFactory.h" + +static nsModuleComponentInfo gComponentInfo[] = { + { "Plugin Host", + NS_PLUGIN_HOST_CID, + "component://netscape/plugin/host", + nsPluginHostImpl::Create }, + + { "Plugin Manager", + NS_PLUGINMANAGER_CID, + "component://netscape/plugin/manager", + nsPluginHostImpl::Create }, + + { "Plugin Doc Loader Factory", + NS_PLUGINDOCLOADERFACTORY_CID, + "component://netscape/plugin/doc-loader/factory", + nsPluginDocLoaderFactory::Create }, +}; + +NS_IMPL_NSGETMODULE("nsPluginModule", gComponentInfo); diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index 2710db97cf9..3e7c27b390e 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -42,6 +42,7 @@ #include "nsIDocShellTreeOwner.h" #include "nsIWebBrowserChrome.h" #include "nsIDOMDocument.h" +#include "nsPluginViewer.h" // Class IDs static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); @@ -796,7 +797,7 @@ NS_IMETHODIMP pluginInstanceOwner :: CreateWidget(void) } else if (nsnull != mWindow) { - mPluginWindow.window = (nsPluginPort *)mWindow->GetNativeData(NS_NATIVE_WINDOW); + mPluginWindow.window = (nsPluginPort *)mWindow->GetNativeData(NS_NATIVE_PLUGIN_PORT); mPluginWindow.type = nsPluginWindowType_Window; } else diff --git a/mozilla/modules/plugin/samples/simple/stubs2.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.h similarity index 51% rename from mozilla/modules/plugin/samples/simple/stubs2.cpp rename to mozilla/modules/plugin/base/src/nsPluginViewer.h index 6ffb0621b2e..b30f99f21cd 100644 --- a/mozilla/modules/plugin/samples/simple/stubs2.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -10,25 +10,27 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is mozilla.org code. + * The Original Code is Mozilla Communicator client code. * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): */ -// Include the backward adapter to make this plugin run in pre-5.0 browsers too: -#include "prtypes.h" -#include "../bad/badapter.cpp" +#ifndef nsPluginViewer_h__ +#define nsPluginViewer_h__ -#include "npapi.h" +class nsIStreamListener; +class nsIContentViewer; + +extern nsresult +NS_NewPluginContentViewer(const char* aCommand, + nsIStreamListener** aDocListener, + nsIContentViewer** aDocViewer); + + +#endif // nsPluginViewer_h__ -// Include the old API glue file. -#ifdef XP_WIN -# include "npwin.cpp" -#elif XP_MAC -# include "npmac.cpp" -#endif diff --git a/mozilla/modules/plugin/nglsrc/Makefile.in b/mozilla/modules/plugin/nglsrc/Makefile.in index 5ccd9829596..59ed5d79f02 100644 --- a/mozilla/modules/plugin/nglsrc/Makefile.in +++ b/mozilla/modules/plugin/nglsrc/Makefile.in @@ -29,14 +29,17 @@ include $(DEPTH)/config/autoconf.mk MODULE = layout LIBRARY_NAME = gkplugin SHORT_LIBNAME = ngplugin +IS_COMPONENT = 1 CPPSRCS = \ - nsPluginHostImpl.cpp \ - nsPluginFactory.cpp \ ns4xPlugin.cpp \ ns4xPluginInstance.cpp \ + nsPluginDocLoaderFactory.cpp \ + nsPluginHostImpl.cpp \ + nsPluginModule.cpp \ nsPluginInstancePeer.cpp \ + nsPluginViewer.cpp \ $(NULL) ifeq ($(OS_ARCH), BeOS) @@ -57,6 +60,8 @@ EXPORTS = \ EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) +EXTRA_DSO_LIBS += gkgfx + EXTRA_DSO_LDOPTS = \ $(MOZ_NECKO_UTIL_LIBS) \ $(MOZ_COMPONENT_LIBS) \ diff --git a/mozilla/modules/plugin/nglsrc/makefile.win b/mozilla/modules/plugin/nglsrc/makefile.win index 14937db7ef0..4e2bacd9fad 100644 --- a/mozilla/modules/plugin/nglsrc/makefile.win +++ b/mozilla/modules/plugin/nglsrc/makefile.win @@ -24,8 +24,8 @@ include <$(DEPTH)/config/config.mak> EXPORTS = \ - nsPluginsCID.h \ - nsIPluginHost.h \ + nsPluginsCID.h \ + nsIPluginHost.h \ nsIPluginInstanceOwner.h MAKE_OBJ_TYPE = DLL @@ -33,16 +33,19 @@ DLLNAME = gkplugin DLL=.\$(OBJDIR)\$(DLLNAME).dll MODULE=raptor +IS_COMPONENT=1 DEFINES =-D_IMPL_NS_PLUGIN -DWIN32_LEAN_AND_MEAN -OBJS = \ - .\$(OBJDIR)\nsPluginHostImpl.obj \ - .\$(OBJDIR)\nsPluginFactory.obj \ - .\$(OBJDIR)\ns4xPlugin.obj \ - .\$(OBJDIR)\ns4xPluginInstance.obj \ - .\$(OBJDIR)\nsPluginInstancePeer.obj \ - .\$(OBJDIR)\nsPluginsDirWin.obj \ +OBJS = \ + .\$(OBJDIR)\ns4xPlugin.obj \ + .\$(OBJDIR)\ns4xPluginInstance.obj \ + .\$(OBJDIR)\nsPluginDocLoaderFactory.obj \ + .\$(OBJDIR)\nsPluginHostImpl.obj \ + .\$(OBJDIR)\nsPluginModule.obj \ + .\$(OBJDIR)\nsPluginInstancePeer.obj \ + .\$(OBJDIR)\nsPluginViewer.obj \ + .\$(OBJDIR)\nsPluginsDirWin.obj \ $(NULL) LINCS = \ @@ -76,6 +79,7 @@ CACHELIBNAME=netcache.lib !endif LLIBS = \ + $(DIST)\lib\gkgfxwin.lib \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\xppref32.lib \ $(LIBNSPR) @@ -89,7 +93,7 @@ it: echo $(LLIBS) install:: $(DLL) - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components clobber:: rm -f $(DIST)\bin\$(DLLNAME).dll diff --git a/mozilla/modules/plugin/nglsrc/nsPluginDocLoaderFactory.cpp b/mozilla/modules/plugin/nglsrc/nsPluginDocLoaderFactory.cpp new file mode 100644 index 00000000000..7a8ebf993ae --- /dev/null +++ b/mozilla/modules/plugin/nglsrc/nsPluginDocLoaderFactory.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsCOMPtr.h" +#include "nsIDocumentLoaderFactory.h" +#include "nsIPluginHost.h" +#include "nsIPluginManager.h" +#include "nsIServiceManager.h" +#include "nsPluginDocLoaderFactory.h" +#include "nsPluginViewer.h" + +NS_METHOD +nsPluginDocLoaderFactory::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) +{ + NS_PRECONDITION(aOuter == nsnull, "no aggregation"); + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + + nsPluginDocLoaderFactory* factory = new nsPluginDocLoaderFactory(); + if (! factory) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv; + NS_ADDREF(factory); + rv = factory->QueryInterface(aIID, aResult); + NS_RELEASE(factory); + return rv; +} + +NS_IMPL_ISUPPORTS1(nsPluginDocLoaderFactory, nsIDocumentLoaderFactory); + +NS_IMETHODIMP +nsPluginDocLoaderFactory::CreateInstance(const char *aCommand, + nsIChannel* aChannel, + nsILoadGroup* aLoadGroup, + const char* aContentType, + nsISupports* aContainer, + nsISupports* aExtraInfo, + nsIStreamListener** aDocListener, + nsIContentViewer** aDocViewer) +{ + static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); + nsCOMPtr pluginHost = do_GetService(kPluginManagerCID); + if(! pluginHost) + return NS_ERROR_FAILURE; + + if (pluginHost->IsPluginEnabledForType(aContentType) != NS_OK) + return NS_ERROR_FAILURE; + + return NS_NewPluginContentViewer(aCommand, aDocListener, aDocViewer); +} + +NS_IMETHODIMP +nsPluginDocLoaderFactory::CreateInstanceForDocument(nsISupports* aContainer, + nsIDocument* aDocument, + const char *aCommand, + nsIContentViewer** aDocViewerResult) +{ + NS_NOTREACHED("how'd I get here?"); + return NS_ERROR_FAILURE; +} diff --git a/mozilla/modules/plugin/nglsrc/nsPluginDocLoaderFactory.h b/mozilla/modules/plugin/nglsrc/nsPluginDocLoaderFactory.h new file mode 100644 index 00000000000..fbf57322fa0 --- /dev/null +++ b/mozilla/modules/plugin/nglsrc/nsPluginDocLoaderFactory.h @@ -0,0 +1,76 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/* + + An nsIDocumentLoaderFactory that is used to load plugins + +*/ + +#ifndef nsPluginDocLoaderFactory_h__ +#define nsPluginDocLoaderFactory_h__ + +#include "nsIDocumentLoaderFactory.h" + +class nsIChannel; +class nsIContentViewer; +class nsILoadGroup; +class nsIStreamListener; + +/** + * An nsIDocumentLoaderFactory that is used to load plugins + */ +class nsPluginDocLoaderFactory : public nsIDocumentLoaderFactory +{ +protected: + nsPluginDocLoaderFactory() { NS_INIT_ISUPPORTS(); } + virtual ~nsPluginDocLoaderFactory() {} + +public: + static NS_METHOD + Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); + + NS_DECL_ISUPPORTS + + // nsIDocumentLoaderFactory + NS_IMETHOD CreateInstance(const char* aCommand, + nsIChannel* aChannel, + nsILoadGroup* aLoadGroup, + const char* aContentType, + nsISupports* aContainer, + nsISupports* aExtraInfo, + nsIStreamListener** aDocListener, + nsIContentViewer** aDocViewer); + + NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer, + nsIDocument* aDocument, + const char *aCommand, + nsIContentViewer** aDocViewerResult); +}; + +/* dd1b8d10-1dd1-11b2-9852-e162b2c46000 */ +#define NS_PLUGINDOCLOADERFACTORY_CID \ +{ 0xdd1b8d10, 0x1dd1, 0x11b2, { 0x98, 0x52, 0xe1, 0x62, 0xb2, 0xc4, 0x60, 0x00 } } + +#endif // nsPluginDocLoaderFactory_h__ + + diff --git a/mozilla/modules/plugin/nglsrc/nsPluginFactory.cpp b/mozilla/modules/plugin/nglsrc/nsPluginFactory.cpp deleted file mode 100644 index 09ffdfcb8ec..00000000000 --- a/mozilla/modules/plugin/nglsrc/nsPluginFactory.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nscore.h" -#include "nsIFactory.h" -#include "nsCOMPtr.h" - -//#include "nsPluginsCID.h" -#include "nsPluginHostImpl.h" -#include "nsIServiceManager.h" -#include "nsIPluginManager.h" - -//static NS_DEFINE_IID(kCPluginHost, NS_PLUGIN_HOST_CID); -static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIServiceManagerIID, NS_ISERVICEMANAGER_IID); - -class nsPluginFactory : public nsIFactory -{ - public: - NS_DECL_ISUPPORTS - - NS_DECL_NSIFACTORY - - nsPluginFactory(const nsCID &aClass, nsIServiceManager* serviceMgr); - - protected: - virtual ~nsPluginFactory(); - - private: - nsCID mClassID; - nsIServiceManager *mserviceMgr; -}; - -nsPluginFactory :: nsPluginFactory(const nsCID &aClass, nsIServiceManager* serviceMgr) -{ - NS_INIT_ISUPPORTS(); - mClassID = aClass; - // XXX Are we sure about this weak reference. -dp - mserviceMgr = serviceMgr; -} - -nsPluginFactory :: ~nsPluginFactory() -{ -} - -NS_IMPL_ISUPPORTS(nsPluginFactory, NS_GET_IID(nsIFactory)) - -nsresult nsPluginFactory :: CreateInstance(nsISupports *aOuter, - const nsIID &aIID, - void **aResult) -{ - if (aResult == NULL) { - return NS_ERROR_NULL_POINTER; - } - - if (aOuter) { - *aResult = nsnull; - return NS_ERROR_NO_AGGREGATION; - } - - *aResult = NULL; - - nsPluginHostImpl *inst = nsnull; - - //if (mClassID.Equals(kCPluginHost) || mClassID.Equals(kCPluginManagerCID) ){ - if (mClassID.Equals(kCPluginManagerCID) ) { - inst = new nsPluginHostImpl(mserviceMgr); - } else { - return NS_ERROR_NO_INTERFACE; - } - - if (inst == NULL) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(inst); // Stabilize - - nsresult res = inst->QueryInterface(aIID, aResult); - - NS_RELEASE(inst); // Destabilize and avoid leaks. Avoid calling delete - - return res; -} - -nsresult nsPluginFactory :: LockFactory(PRBool aLock) -{ - // Not implemented in simplest case. - return NS_OK; -} - -// return the proper factory to the caller -extern "C" NS_PLUGIN nsresult -NSGetFactory(nsISupports* serviceMgr, - const nsCID &aClass, - const char *aClassName, - const char *aProgID, - nsIFactory **aFactory) -{ - if (nsnull == aFactory) { - return NS_ERROR_NULL_POINTER; - } - - nsresult rv; - nsCOMPtr servMgr = do_QueryInterface(serviceMgr, &rv); - if (NS_FAILED(rv)) return rv; - - *aFactory = new nsPluginFactory(aClass, servMgr); - - if (nsnull == aFactory) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory); -} - diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index ce6886c76b3..da2ae3a049e 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -44,6 +44,14 @@ #include "nsIProgressEventSink.h" #include "nsIDocument.h" +// Friggin' X11 has to "#define None". Lame! +#ifdef None +#undef None +#endif + +#include "nsIRegistry.h" +#include "nsEnumeratorUtils.h" + // for the dialog #include "nsIStringBundle.h" #include "nsINetSupportDialogService.h" @@ -73,25 +81,27 @@ #include "nsSpecialSystemDirectory.h" #include "nsFileSpec.h" +#include "nsPluginDocLoaderFactory.h" #include "nsIDocumentLoaderFactory.h" -#include "nsLayoutCID.h" #ifdef XP_UNIX #include // for GDK_DISPLAY() #endif +// We need this hackery so that we can dynamically register doc +// loaders for the 4.x plugins that we discover. #if defined(XP_PC) -#define LAYOUT_DLL "gkhtml.dll" +#define PLUGIN_DLL "gkplugin.dll" #elif defined(XP_UNIX) || defined(XP_BEOS) -#define LAYOUT_DLL "libgklayout"MOZ_DLL_SUFFIX +#define PLUGIN_DLL "libgkplugin" MOZ_DLL_SUFFIX #elif defined(XP_MAC) -#define LAYOUT_DLL "LAYOUT_DLL" +#define PLUGIN_DLL "PLUGIN_DLL" #endif #ifdef XP_MAC -#define REL_LAYOUT_DLL LAYOUT_DLL +#define REL_PLUGIN_DLL PLUGIN_DLL #else -#define REL_LAYOUT_DLL "rel:"LAYOUT_DLL +#define REL_PLUGIN_DLL "rel:" PLUGIN_DLL #endif //uncomment this to use netlib to determine what the @@ -118,12 +128,13 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID); static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID); +static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID); + // for the dialog static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID); static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); -static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); #define PLUGIN_PROPERTIES_URL "chrome://global/locale/downloadProgress.properties" void DisplayNoDefaultPluginDialog(const char *mimeType); @@ -434,9 +445,6 @@ nsPluginTag::nsPluginTag() mNext = nsnull; mName = nsnull; mDescription = nsnull; - mMimeType = nsnull; - mMimeDescription = nsnull; - mExtensions = nsnull; mVariants = 0; mMimeTypeArray = nsnull; mMimeDescriptionArray = nsnull; @@ -447,7 +455,7 @@ nsPluginTag::nsPluginTag() mFileName = nsnull; } -inline char* new_str(char* str) +inline char* new_str(const char* str) { if(str == nsnull) return nsnull; @@ -463,9 +471,6 @@ nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag) mNext = nsnull; mName = new_str(aPluginTag->mName); mDescription = new_str(aPluginTag->mDescription); - mMimeType = new_str(aPluginTag->mMimeType); - mMimeDescription = new_str(aPluginTag->mMimeDescription); - mExtensions = new_str(aPluginTag->mExtensions); mVariants = aPluginTag->mVariants; mMimeTypeArray = nsnull; @@ -504,9 +509,6 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) mNext = nsnull; mName = new_str(aPluginInfo->fName); mDescription = new_str(aPluginInfo->fDescription); - mMimeType = new_str(aPluginInfo->fMimeType); - mMimeDescription = new_str(aPluginInfo->fMimeDescription); - mExtensions = new_str(aPluginInfo->fExtensions); mVariants = aPluginInfo->fVariantCount; mMimeTypeArray = nsnull; @@ -541,6 +543,40 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) mFlags = NS_PLUGIN_FLAG_ENABLED; } + +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), + 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]); + } + } +} + nsPluginTag::~nsPluginTag() { NS_IF_RELEASE(mEntryPoint); @@ -555,21 +591,6 @@ nsPluginTag::~nsPluginTag() mDescription = nsnull; } - if (nsnull != mMimeType) { - delete[] (mMimeType); - mMimeType = nsnull; - } - - if (nsnull != mMimeDescription) { - delete[] (mMimeDescription); - mMimeDescription = nsnull; - } - - if (nsnull != mExtensions) { - delete[] (mExtensions); - mExtensions = nsnull; - } - if (nsnull != mMimeTypeArray) { for (int i = 0; i < mVariants; i++) delete[] mMimeTypeArray[i]; @@ -1313,11 +1334,10 @@ nsPluginStreamListenerPeer::GetLoadGroup() ///////////////////////////////////////////////////////////////////////// -nsPluginHostImpl::nsPluginHostImpl(nsIServiceManager *serviceMgr) +nsPluginHostImpl::nsPluginHostImpl() { NS_INIT_REFCNT(); mPluginsLoaded = PR_FALSE; - mServiceMgr = serviceMgr; } nsPluginHostImpl::~nsPluginHostImpl() @@ -1340,66 +1360,29 @@ printf("killing plugin host\n"); } } -NS_IMPL_ADDREF(nsPluginHostImpl) -NS_IMPL_RELEASE(nsPluginHostImpl) +NS_IMPL_ISUPPORTS5(nsPluginHostImpl, + nsIPluginManager, + nsIPluginManager2, + nsIPluginHost, + nsIFileUtilities, + nsICookieStorage); -nsresult nsPluginHostImpl::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) +NS_METHOD +nsPluginHostImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); + NS_PRECONDITION(aOuter == nsnull, "no aggregation"); + if (aOuter) + return NS_ERROR_NO_AGGREGATION; - if (nsnull == aInstancePtrResult) - return NS_ERROR_NULL_POINTER; + nsPluginHostImpl* host = new nsPluginHostImpl(); + if (! host) + return NS_ERROR_OUT_OF_MEMORY; - if (aIID.Equals(nsIPluginManager::GetIID())) - { - *aInstancePtrResult = (void *)((nsIPluginManager *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIPluginManager2::GetIID())) - { - *aInstancePtrResult = (void *)((nsIPluginManager2 *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIPluginHost::GetIID())) - { - *aInstancePtrResult = (void *)((nsIPluginHost *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIFactory::GetIID())) - { - *aInstancePtrResult = (void *)((nsIFactory *)this); - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIFileUtilities::GetIID())) - { - *aInstancePtrResult = (void*)(nsIFileUtilities*)this; - AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsICookieStorage::GetIID())) { - *aInstancePtrResult = (void*)(nsICookieStorage*)this; - AddRef(); - return NS_OK; - } - - if (aIID.Equals(kISupportsIID)) - { - *aInstancePtrResult = (void *)((nsISupports *)((nsIPluginHost *)this)); - AddRef(); - return NS_OK; - } - - return NS_NOINTERFACE; + nsresult rv; + NS_ADDREF(host); + rv = host->QueryInterface(aIID, aResult); + NS_RELEASE(host); + return rv; } NS_IMETHODIMP nsPluginHostImpl::GetValue(nsPluginManagerVariable aVariable, void *aValue) @@ -1422,6 +1405,9 @@ NS_IMETHODIMP nsPluginHostImpl::GetValue(nsPluginManagerVariable aVariable, void nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages) { + // XXX don't we want to nuke the old mPlugins right now? + // XXX for new-style plugins, we should also call + // nsIComponentManager::AutoRegister() mPluginsLoaded = PR_FALSE; return LoadPlugins(); } @@ -1575,6 +1561,73 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, return rv; } +NS_IMETHODIMP nsPluginHostImpl::RegisterPlugin(REFNSIID aCID, + const char* aPluginName, + const char* aDescription, + const char** aMimeTypes, + const char** aMimeDescriptions, + const char** aFileExtensions, + PRInt32 aCount) +{ + nsCOMPtr registry = do_CreateInstance(kRegistryCID); + if (! registry) + return NS_ERROR_FAILURE; + + nsresult rv; + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(rv)) return rv; + + nsCAutoString path = "software/plugins/"; + 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 registry = do_CreateInstance(kRegistryCID); + if (! registry) + return NS_ERROR_FAILURE; + + nsresult rv; + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(rv)) return rv; + + nsCAutoString path = "software/plugins/"; + char* cid = aCID.ToString(); + if (! cid) + return NS_ERROR_OUT_OF_MEMORY; + + path += cid; + nsMemory::Free(cid); + + return registry->RemoveSubtree(nsIRegistry::Common, path); +} + NS_IMETHODIMP nsPluginHostImpl::BeginWaitCursor(void) { return NS_ERROR_NOT_IMPLEMENTED; @@ -1731,6 +1784,20 @@ NS_IMETHODIMP nsPluginHostImpl::ProcessNextEvent(PRBool *bEventHandled) return NS_ERROR_NOT_IMPLEMENTED; } +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; +} + NS_IMETHODIMP nsPluginHostImpl::Init(void) { return NS_OK; @@ -2057,7 +2124,7 @@ void nsPluginHostImpl::AddInstanceToActiveList(nsIPluginInstance* aInstance, nsresult nsPluginHostImpl::RegisterPluginMimeTypesWithLayout(nsPluginTag * pluginTag, nsIComponentManager * compManager, - nsIFile * layoutPath) + nsIFile * path) { NS_ENSURE_ARG_POINTER(pluginTag); NS_ENSURE_ARG_POINTER(pluginTag->mMimeTypeArray); @@ -2067,10 +2134,17 @@ nsresult nsPluginHostImpl::RegisterPluginMimeTypesWithLayout(nsPluginTag * plugi for(int i = 0; i < pluginTag->mVariants; i++) { - char progid[512]; - char * contentType = pluginTag->mMimeTypeArray[i]; - PR_snprintf(progid, sizeof(progid), NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX "%s/%s", "view", contentType); - rv = compManager->RegisterComponentSpec(kDocumentFactoryImplCID, "Layout", progid, layoutPath, PR_TRUE, PR_TRUE); + static NS_DEFINE_CID(kPluginDocLoaderFactoryCID, NS_PLUGINDOCLOADERFACTORY_CID); + + nsCAutoString progid = NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX "view/"; + progid += pluginTag->mMimeTypeArray[i]; + + rv = compManager->RegisterComponentSpec(kPluginDocLoaderFactoryCID, + "Plugin Loader Stub", + progid, + path, + PR_TRUE, + PR_FALSE); } return rv; @@ -2557,12 +2631,17 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi nsIPlugin* plugin = pluginTag->mEntryPoint; if(plugin == NULL) { + // No, this is not a leak. GetGlobalServiceManager() doesn't + // addref the pointer on the way out. It probably should. + nsIServiceManager* serviceManager; + nsServiceManager::GetGlobalServiceManager(&serviceManager); + // need to get the plugin factory from this plugin. nsFactoryProc nsGetFactory = nsnull; nsGetFactory = (nsFactoryProc) PR_FindSymbol(pluginTag->mLibrary, "NSGetFactory"); if(nsGetFactory != nsnull) { - rv = nsGetFactory(mServiceMgr, kPluginCID, nsnull, nsnull, // XXX fix ClassName/ProgID + rv = nsGetFactory(serviceManager, kPluginCID, nsnull, nsnull, // XXX fix ClassName/ProgID (nsIFactory**)&pluginTag->mEntryPoint); plugin = pluginTag->mEntryPoint; if (plugin != NULL) @@ -2570,10 +2649,10 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi } else { - rv = ns4xPlugin::CreatePlugin(mServiceMgr, - pluginTag->mFileName, - pluginTag->mLibrary, - &pluginTag->mEntryPoint); + rv = ns4xPlugin::CreatePlugin(serviceManager, + pluginTag->mFileName, + pluginTag->mLibrary, + &pluginTag->mEntryPoint); plugin = pluginTag->mEntryPoint; pluginTag->mFlags |= NS_PLUGIN_FLAG_OLDSCHOOL; @@ -2597,16 +2676,17 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() { - do { - // 1. scan the plugins directory (where is it?) for eligible plugin libraries. - nsPluginsDir pluginsDir; - if (! pluginsDir.Valid()) - break; - // retrieve a path for layout module. Needed for plugin mime types registration nsCOMPtr compManager = do_GetService(kComponentManagerCID); nsCOMPtr path; - nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_LAYOUT_DLL, getter_AddRefs(path)); + nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_PLUGIN_DLL, getter_AddRefs(path)); + + LoadXPCOMPlugins(compManager, path); + + // 1. scan the plugins directory (where is it?) for eligible plugin libraries. + nsPluginsDir pluginsDir; + if (! pluginsDir.Valid()) + return NS_ERROR_FAILURE; for (nsDirectoryIterator iter(pluginsDir, PR_TRUE); iter.Exists(); iter++) { const nsFileSpec& file = iter; @@ -2646,9 +2726,6 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() mPluginsLoaded = PR_TRUE; return NS_OK; - } while (0); - - return NS_ERROR_FAILURE; } #else // go for new plugin finding logic on Windows @@ -2714,6 +2791,13 @@ static PRBool isUnwantedPlugin(nsPluginTag * tag) NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() { + // retrieve a path for layout module. Needed for plugin mime types registration + nsCOMPtr compManager = do_GetService(kComponentManagerCID); + nsCOMPtr path; + nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_PLUGIN_DLL, getter_AddRefs(path)); + + LoadXPCOMPlugins(compManager, path); + // 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 @@ -2726,11 +2810,6 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() if(!pluginsDir4x.Valid() && !pluginsDirMoz.Valid()) return NS_ERROR_FAILURE; - // retrieve a path for layout module. Needed for plugin mime types registration - nsCOMPtr compManager = do_GetService(kComponentManagerCID); - nsCOMPtr path; - nsresult rvIsLayoutPath = compManager->SpecForRegistryLocation(REL_LAYOUT_DLL, getter_AddRefs(path)); - // first, make a list from MOZ_LOCAL installation for (nsDirectoryIterator iter(pluginsDirMoz, PR_TRUE); iter.Exists(); iter++) { @@ -2838,6 +2917,220 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() } #endif // XP_WIN -- end new plugin finding logic + +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. + nsAutoString path = NS_LITERAL_STRING("software/mozilla/XPCOM/classID/"); + path += NS_ConvertASCIItoUCS2(aCID); + + 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 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 enumerator; + rv = aRegistry->EnumerateAllSubtrees(aPluginKey, getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr 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 isupports; + subtrees->GetNext(getter_AddRefs(isupports)); + + nsCOMPtr 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 + = new nsPluginTag(name, + description, + filename, + mimetypes, + mimedescriptions, + extensions, + 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 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 enumerator; + rv = registry->EnumerateSubtrees(pluginsKey, getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr plugins; + rv = NS_NewAdapterEnumerator(getter_AddRefs(plugins), enumerator); + if (NS_FAILED(rv)) return rv; + + for (;;) { + PRBool hasMore; + plugins->HasMoreElements(&hasMore); + if (! hasMore) + break; + + nsCOMPtr isupports; + plugins->GetNext(getter_AddRefs(isupports)); + + nsCOMPtr 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); + + nsPluginTag* tag; + rv = LoadXPCOMPlugin(aComponentManager, registry, cid, key, &tag); + if (NS_FAILED(rv)) + continue; + + tag->mNext = mPlugins; + mPlugins = tag; + + // Create an nsIDocumentLoaderFactory wrapper in case we ever see + // any naked streams. + RegisterPluginMimeTypesWithLayout(tag, aComponentManager, aPath); + } + + return NS_OK; +} + /* Called by GetURL and PostURL */ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, @@ -3002,37 +3295,6 @@ nsresult nsPluginHostImpl::NewFullPagePluginStream(nsIStreamListener *&aStreamLi return rv; } -// nsIFactory interface - -nsresult nsPluginHostImpl::CreateInstance(nsISupports *aOuter, - const nsIID &aIID, - void **aResult) -{ - if (aResult == NULL) - return NS_ERROR_NULL_POINTER; - - nsISupports *inst = nsnull; - - if (inst == NULL) - return NS_ERROR_OUT_OF_MEMORY; - - // XXX Doh, we never get here... what is going on??? - - NS_ADDREF(inst); // Stabilize - - nsresult res = inst->QueryInterface(aIID, aResult); - - NS_RELEASE(inst); // Destabilize and avoid leaks. Avoid calling delete - - return res; -} - -nsresult nsPluginHostImpl::LockFactory(PRBool aLock) -{ - // Not implemented in simplest case. - return NS_OK; -} - // nsIFileUtilities interface NS_IMETHODIMP nsPluginHostImpl::GetProgramPath(const char* *result) diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h index abbff6c1881..85f2933b67a 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -35,22 +35,34 @@ class ns4xPlugin; class nsFileSpec; -class nsIServiceManager; +class nsIComponentManager; +class nsIFile; +/** + * A linked-list of plugin information that is used for + * instantiating plugins and reflecting plugin information + * into JavaScript. + */ class nsPluginTag { public: nsPluginTag(); nsPluginTag(nsPluginTag* aPluginTag); nsPluginTag(nsPluginInfo* aPluginInfo); + + nsPluginTag(const char* aName, + const char* aDescription, + const char* aFileName, + const char* const* aMimeTypes, + const char* const* aMimeDescriptions, + const char* const* aExtensions, + PRInt32 aVariants); + ~nsPluginTag(); nsPluginTag *mNext; char *mName; char *mDescription; - char *mMimeType; - char *mMimeDescription; - char *mExtensions; PRInt32 mVariants; char **mMimeTypeArray; char **mMimeDescriptionArray; @@ -106,9 +118,12 @@ class nsPluginHostImpl : public nsIPluginManager2, public nsICookieStorage { public: - nsPluginHostImpl(nsIServiceManager *serviceMgr); + nsPluginHostImpl(); virtual ~nsPluginHostImpl(); + static NS_METHOD + Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW NS_DECL_ISUPPORTS @@ -147,6 +162,18 @@ public: PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); + NS_IMETHOD + RegisterPlugin(REFNSIID aCID, + const char* aPluginName, + const char* aDescription, + const char** aMimeTypes, + const char** aMimeDescriptions, + const char** aFileExtensions, + PRInt32 aCount); + + NS_IMETHOD + UnregisterPlugin(REFNSIID aCID); + //nsIPluginHost interface - used to communicate to the nsPluginInstanceOwner NS_IMETHOD @@ -157,7 +184,7 @@ public: NS_IMETHOD LoadPlugins(void); - + NS_IMETHOD GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin); @@ -217,8 +244,8 @@ public: NS_IMETHOD ProcessNextEvent(PRBool *bEventHandled); - //nsIFactory interface - used to create new Plugin instances - + // nsIFactory interface, from nsIPlugin. + // XXX not currently used? NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult); @@ -264,6 +291,9 @@ public: private: + nsresult + LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFile* aPath); + /* Called by InstantiatePlugin */ nsresult @@ -289,7 +319,6 @@ private: char *mPluginPath; nsPluginTag *mPlugins; PRBool mPluginsLoaded; - nsIServiceManager *mServiceMgr; nsActivePluginList mActivePluginList; }; diff --git a/mozilla/modules/plugin/nglsrc/nsPluginModule.cpp b/mozilla/modules/plugin/nglsrc/nsPluginModule.cpp new file mode 100644 index 00000000000..ab7ab0d5125 --- /dev/null +++ b/mozilla/modules/plugin/nglsrc/nsPluginModule.cpp @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Pierre Phaneuf + */ + +#include "nsIGenericFactory.h" +#include "nsIPluginManager.h" +#include "nsPluginsCID.h" +#include "nsPluginHostImpl.h" +#include "nsPluginDocLoaderFactory.h" + +static nsModuleComponentInfo gComponentInfo[] = { + { "Plugin Host", + NS_PLUGIN_HOST_CID, + "component://netscape/plugin/host", + nsPluginHostImpl::Create }, + + { "Plugin Manager", + NS_PLUGINMANAGER_CID, + "component://netscape/plugin/manager", + nsPluginHostImpl::Create }, + + { "Plugin Doc Loader Factory", + NS_PLUGINDOCLOADERFACTORY_CID, + "component://netscape/plugin/doc-loader/factory", + nsPluginDocLoaderFactory::Create }, +}; + +NS_IMPL_NSGETMODULE("nsPluginModule", gComponentInfo); diff --git a/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp index 2710db97cf9..3e7c27b390e 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp @@ -42,6 +42,7 @@ #include "nsIDocShellTreeOwner.h" #include "nsIWebBrowserChrome.h" #include "nsIDOMDocument.h" +#include "nsPluginViewer.h" // Class IDs static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); @@ -796,7 +797,7 @@ NS_IMETHODIMP pluginInstanceOwner :: CreateWidget(void) } else if (nsnull != mWindow) { - mPluginWindow.window = (nsPluginPort *)mWindow->GetNativeData(NS_NATIVE_WINDOW); + mPluginWindow.window = (nsPluginPort *)mWindow->GetNativeData(NS_NATIVE_PLUGIN_PORT); mPluginWindow.type = nsPluginWindowType_Window; } else diff --git a/mozilla/modules/plugin/test/stubs2.cpp b/mozilla/modules/plugin/nglsrc/nsPluginViewer.h similarity index 51% rename from mozilla/modules/plugin/test/stubs2.cpp rename to mozilla/modules/plugin/nglsrc/nsPluginViewer.h index 6ffb0621b2e..b30f99f21cd 100644 --- a/mozilla/modules/plugin/test/stubs2.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginViewer.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -10,25 +10,27 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is mozilla.org code. + * The Original Code is Mozilla Communicator client code. * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): */ -// Include the backward adapter to make this plugin run in pre-5.0 browsers too: -#include "prtypes.h" -#include "../bad/badapter.cpp" +#ifndef nsPluginViewer_h__ +#define nsPluginViewer_h__ -#include "npapi.h" +class nsIStreamListener; +class nsIContentViewer; + +extern nsresult +NS_NewPluginContentViewer(const char* aCommand, + nsIStreamListener** aDocListener, + nsIContentViewer** aDocViewer); + + +#endif // nsPluginViewer_h__ -// Include the old API glue file. -#ifdef XP_WIN -# include "npwin.cpp" -#elif XP_MAC -# include "npmac.cpp" -#endif diff --git a/mozilla/modules/plugin/public/nsIPluginManager.h b/mozilla/modules/plugin/public/nsIPluginManager.h index 86874600bbb..b65328545bb 100644 --- a/mozilla/modules/plugin/public/nsIPluginManager.h +++ b/mozilla/modules/plugin/public/nsIPluginManager.h @@ -181,6 +181,47 @@ public: PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; + + /** + * Persistently register a plugin with the plugin + * manager. aMimeTypes, aMimeDescriptions, and aFileExtensions are + * parallel arrays that contain information about the MIME types + * that the plugin supports. + * + * @param aCID - the plugin's CID + * @param aPluginName - the plugin's name + * @param aDescription - a description of the plugin + * @param aMimeTypes - an array of MIME types that the plugin + * is prepared to handle + * @param aMimeDescriptions - an array of descriptions for the + * MIME types that the plugin can handle. + * @param aFileExtensions - an array of file extensions for + * the MIME types that the plugin can handle. + * @param aCount - the number of elements in the aMimeTypes, + * aMimeDescriptions, and aFileExtensions arrays. + * @result - NS_OK if the operation was successful. + */ + + NS_IMETHOD + RegisterPlugin(REFNSIID aCID, + const char* aPluginName, + const char* aDescription, + const char** aMimeTypes, + const char** aMimeDescriptions, + const char** aFileExtensions, + PRInt32 aCount) = 0; + + + /** + * Unregister a plugin from the plugin manager + * + * @param aCID the CID of the plugin to unregister. + * @result - NS_OK if the operation was successful. + */ + + NS_IMETHOD + UnregisterPlugin(REFNSIID aCID) = 0; + }; //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/modules/plugin/samples/simple/Simple.java b/mozilla/modules/plugin/samples/simple/Simple.java deleted file mode 100644 index 22f28c37385..00000000000 --- a/mozilla/modules/plugin/samples/simple/Simple.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -import netscape.plugin.Plugin; - -class Simple extends Plugin { - - /* - ** A plug-in can consist of code written in java as well as - ** natively. Here's a dummy method. - */ - public static int fact(int n) { - if (n == 1) - return 1; - else - return n * fact(n-1); - } - - /* - ** This instance variable is used to keep track of the number of - ** times we've called into this plug-in. - */ - int count; - - /* - ** This native method will give us a way to print to stdout from java - ** instead of just the java console. - */ - native void printToStdout(String msg); - - /* - ** This is a publically callable new feature that our plug-in is - ** providing. We can call it from JavaScript, Java, or from native - ** code. - */ - public void doit(String text) { - /* construct a message */ - String msg = "" + (++count) + ". " + text + "\n"; - /* write it to the console */ - System.out.print(msg); - /* and also write it to stdout */ - printToStdout(msg); - } -} diff --git a/mozilla/modules/plugin/samples/simple/Simple32.def b/mozilla/modules/plugin/samples/simple/Simple32.def deleted file mode 100644 index c33fe338638..00000000000 --- a/mozilla/modules/plugin/samples/simple/Simple32.def +++ /dev/null @@ -1,28 +0,0 @@ -; -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -; -; 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/ -; -; 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. -; -; The Original Code is mozilla.org code. -; -; The Initial Developer of the Original Code is Netscape -; Communications Corporation. Portions created by Netscape are -; Copyright (C) 1998 Netscape Communications Corporation. All -; Rights Reserved. -; -; Contributor(s): - -LIBRARY NPSimp32 - -CODE PRELOAD MOVEABLE DISCARDABLE -DATA PRELOAD SINGLE - -EXPORTS - NSGetFactory @1 diff --git a/mozilla/modules/plugin/samples/simple/Simple32.rc b/mozilla/modules/plugin/samples/simple/Simple32.rc deleted file mode 100644 index 5fc7246a307..00000000000 --- a/mozilla/modules/plugin/samples/simple/Simple32.rc +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "#define _AFX_NO_SPLITTER_RESOURCES\r\n" - "#define _AFX_NO_OLE_RESOURCES\r\n" - "#define _AFX_NO_TRACKER_RESOURCES\r\n" - "#define _AFX_NO_PROPERTY_RESOURCES\r\n" - "\r\n" - "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" - "#ifdef _WIN32\r\n" - "LANGUAGE 9, 1\r\n" - "#pragma code_page(1252)\r\n" - "#endif\r\n" - "#include ""res\\CharFlipper.rc2"" // non-Microsoft Visual C++ edited resources\r\n" - "#include ""afxres.rc"" // Standard components\r\n" - "#endif\0" -END - -#endif // APSTUDIO_INVOKED - - -#ifndef _MAC -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,1 - PRODUCTVERSION 1,0,0,1 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "CompanyName", "\0" - VALUE "FileDescription", "Simple Example Plugin\0" - VALUE "FileExtents", "smp\0" - VALUE "FileOpenName", "Simple Plugin File (*.smp)\0" - VALUE "FileVersion", "1, 0, 0, 1\0" - VALUE "InternalName", "CHARFLIPPER\0" - VALUE "LegalCopyright", "Copyright © 1996\0" - VALUE "MIMEType", "application/x-simple\0" - VALUE "OriginalFilename", "NPSimp32.dll\0" - VALUE "ProductName", "HelloWorld Example Plugin\0" - VALUE "ProductVersion", "1, 0, 0, 1\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END - -#endif // !_MAC - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// -#define _AFX_NO_SPLITTER_RESOURCES -#define _AFX_NO_OLE_RESOURCES -#define _AFX_NO_TRACKER_RESOURCES -#define _AFX_NO_PROPERTY_RESOURCES - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE 9, 1 -#pragma code_page(1252) -#endif -#include "afxres.rc" // Standard components -#endif -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/mozilla/modules/plugin/samples/simple/makefile.win b/mozilla/modules/plugin/samples/simple/makefile.win index 3e7dc8899bb..344a9134298 100644 --- a/mozilla/modules/plugin/samples/simple/makefile.win +++ b/mozilla/modules/plugin/samples/simple/makefile.win @@ -51,8 +51,6 @@ MAKE_OBJ_TYPE=DLL DLLNAME=npsimple.dll PDBFILE=npsimple.pdb MAPFILE=npsimple.map -#DEFFILE=Simple32.def -RESFILE=Simple32.res #//------------------------------------------------------------------------ #// @@ -91,4 +89,4 @@ LCFLAGS = $(LCFLAGS) -DNEW_PLUGIN_STREAM_API install:: $(DLL) # $(MAKE_INSTALL) $(XPDIST)\classes11\Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple # $(MAKE_INSTALL) Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple - $(MAKE_INSTALL) $(OBJDIR)\npsimple.dll $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple + $(MAKE_INSTALL) $(OBJDIR)\npsimple.dll $(DIST)\bin\components diff --git a/mozilla/modules/plugin/samples/simple/npsimple.cpp b/mozilla/modules/plugin/samples/simple/npsimple.cpp index 8e746aaa05d..f7c2e7b55f9 100644 --- a/mozilla/modules/plugin/samples/simple/npsimple.cpp +++ b/mozilla/modules/plugin/samples/simple/npsimple.cpp @@ -24,7 +24,7 @@ /******************************************************************************* * npsimple.cpp ****************************************************************************** - * Simple LiveConnect Sample Plugin + * Simple Sample Plugin * Copyright (c) 1996 Netscape Communications. All rights reserved. ****************************************************************************** * OVERVIEW @@ -32,8 +32,7 @@ * Section 1 - Includes * Section 2 - Instance Structs * Section 3 - API Plugin Implementations - * Section 4 - Java Native Method Implementations - * Section 5 - Utility Method Implementations + * Section 4 - Utility Method Implementations *******************************************************************************/ /******************************************************************************* @@ -45,6 +44,8 @@ #include "nsIServiceManager.h" #include "nsISupports.h" #include "nsIFactory.h" +#include "nsIGenericFactory.h" +#include "nsMemory.h" #include "nsString.h" #include "simpleCID.h" @@ -137,25 +138,28 @@ typedef struct _PlatformInstance // Define constants for easy use -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID); -static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); -static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); -static NS_DEFINE_IID(kIServiceManagerIID, NS_ISERVICEMANAGER_IID); -static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID); - -static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID); -static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); -static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); static NS_DEFINE_CID(kSimplePluginCID, NS_SIMPLEPLUGIN_CID); +static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); -#define PLUGIN_NAME "Simple Sample Plug-in" -#define PLUGIN_DESCRIPTION "Demonstrates a simple plug-in." -#define PLUGIN_MIME_DESCRIPTION "application/x-simple:smp:Simple Sample Plug-in" #define PLUGIN_MIME_TYPE "application/x-simple" -static const char* g_desc = "Sample XPCOM Plugin"; +static const char kPluginName[] = "Simple Sample Plug-in"; +static const char kPluginDescription[] = "Demonstrates a simple plug-in."; + +static const char* kMimeTypes[] = { + PLUGIN_MIME_TYPE +}; + +static const char* kMimeDescriptions[] = { + "Simple Sample Plug-in" +}; + +static const char* kFileExtensions[] = { + "smp" +}; + +static const PRInt32 kNumMimeTypes = sizeof(kMimeTypes) / sizeof(*kMimeTypes); + //////////////////////////////////////////////////////////////////////////////// @@ -163,84 +167,28 @@ static const char* g_desc = "Sample XPCOM Plugin"; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -// SimplePlugin represents the class of all simple plugins. One -// instance of this class is kept around for as long as there are -// plugin instances outstanding. - -class SimplePlugin : public nsIPlugin { -public: - - //////////////////////////////////////////////////////////////////////////// - // from nsIFactory: - - NS_IMETHOD CreateInstance(nsISupports *aOuter, - REFNSIID aIID, - void **aResult); - - NS_IMETHOD LockFactory(PRBool aLock); - - //////////////////////////////////////////////////////////////////////////// - // from nsIPlugin: - - // This call initializes the plugin and will be called before any new - // instances are created. It is passed browserInterfaces on which QueryInterface - // may be used to obtain an nsIPluginManager, and other interfaces. - NS_IMETHOD - Initialize(void); - - // (Corresponds to NPP_Shutdown.) - // Called when the browser is done with the plugin factory, or when - // the plugin is disabled by the user. - NS_IMETHOD - Shutdown(void); - - // (Corresponds to NPP_GetMIMEDescription.) - NS_IMETHOD - GetMIMEDescription(const char* *result); - - // (Corresponds to NPP_GetValue.) - NS_IMETHOD - GetValue(nsPluginVariable variable, void *value); - - NS_IMETHOD - CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID, - const char* aPluginMIMEType, - void **aResult); - - // The old NPP_New call has been factored into two plugin instance methods: - // - // CreateInstance -- called once, after the plugin instance is created. This - // method is used to initialize the new plugin instance (although the actual - // plugin instance object will be created by the plugin manager). - // - // nsIPluginInstance::Start -- called when the plugin instance is to be - // started. This happens in two circumstances: (1) after the plugin instance - // is first initialized, and (2) after a plugin instance is returned to - // (e.g. by going back in the window history) after previously being stopped - // by the Stop method. - - // SimplePlugin specific methods: - - SimplePlugin(); - virtual ~SimplePlugin(void); - - NS_DECL_ISUPPORTS - - nsIPluginManager* GetPluginManager(void) { return mPluginManager; } - -protected: - nsIPluginManager* mPluginManager; - nsIServiceManager* mServiceManager; - -}; - -//////////////////////////////////////////////////////////////////////////////// -// SimplePluginInstance represents an instance of the SimplePlugin class. +// SimplePluginInstance represents an instance of the simple plugin class. class SimplePluginInstance : public nsIPluginInstance, public nsISimplePluginInstance { public: + //////////////////////////////////////////////////////////////////////////// + // for implementing a generic module + static NS_METHOD + Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); + + static NS_METHOD + RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation, + const char* aComponentType); + + static NS_METHOD + UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation); + NS_DECL_ISUPPORTS NS_DECL_NSISIMPLEPLUGININSTANCE @@ -401,323 +349,96 @@ public: protected: const char* fMessageName; - }; /******************************************************************************* * SECTION 3 - API Plugin Implementations ******************************************************************************/ -// This counter is used to keep track of the number of outstanding objects. -// It is used to determine whether the plugin's DLL can be unloaded. -static PRUint32 gPluginObjectCount = 0; - -// This flag is used to keep track of whether the plugin's DLL is explicitly -// being retained by some client. -static PRBool gPluginLocked = PR_FALSE; - -//////////////////////////////////////////////////////////////////////////////// -// SimplePlugin Methods -//////////////////////////////////////////////////////////////////////////////// - -SimplePlugin::SimplePlugin() - : mPluginManager(NULL), - mServiceManager(NULL) -{ - NS_INIT_REFCNT(); - - if(nsComponentManager::CreateInstance(kCPluginManagerCID, - NULL, kIPluginManagerIID, (void**)&mPluginManager) != NS_OK) - return; - - gPluginObjectCount++; -} - -SimplePlugin::~SimplePlugin(void) -{ - if(mPluginManager) - mPluginManager->Release(); - - if(mServiceManager) - mServiceManager->Release(); - - gPluginObjectCount--; -} - -// These macros produce simple version of QueryInterface and AddRef. -// See the nsISupports.h header file for details. - -NS_METHOD -SimplePlugin::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ - if (!aInstancePtr) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = NS_STATIC_CAST(nsISupports*,this); - } else if (aIID.Equals(kIFactoryIID)) { - *aInstancePtr = NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(nsIFactory*,this)); - } else if (aIID.Equals(kIPluginIID)) { - *aInstancePtr = NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(nsIPlugin*,this)); - } else { - *aInstancePtr = nsnull; - return NS_ERROR_NO_INTERFACE; - } - - NS_ADDREF(NS_REINTERPRET_CAST(nsISupports*,*aInstancePtr)); - - return NS_OK; -} - -NS_IMPL_ADDREF(SimplePlugin); -NS_IMPL_RELEASE(SimplePlugin); - -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * NSGetFactory: - * Provides global initialization for a plug-in, and returns an error value. - * - * This function is called once when a plug-in is loaded, before the first instance - * is created. You should allocate any memory or resources shared by all - * instances of your plug-in at this time. After the last instance has been deleted, - * NPP_Shutdown will be called, where you can release any memory or - * resources allocated by NPP_Initialize. - +++++++++++++++++++++++++++++++++++++++++++++++++*/ - -SimplePlugin* gPlugin = NULL; - -extern "C" NS_EXPORT nsresult -NSGetFactory(nsISupports* serviceMgr, - const nsCID &aCID, - const char *aClassName, - const char *aProgID, - nsIFactory **aResult) -{ - if (!aResult) - return NS_ERROR_NULL_POINTER; - - *aResult = nsnull; - - nsISupports *inst; - - if (aCID.Equals(kSimplePluginCID)) { - // Ok, we know this CID and here is the factory - // that can manufacture the objects - inst = new SimplePlugin(); - } else if (aCID.Equals(kPluginCID)) { - inst = new SimplePlugin(); - } else { - return NS_ERROR_NO_INTERFACE; - } - - if (!inst) - return NS_ERROR_OUT_OF_MEMORY; - - nsresult rv = inst->QueryInterface(kIFactoryIID, - (void **) aResult); - - if (NS_FAILED(rv)) { - delete inst; - } - - return rv; -} - -extern "C" NS_EXPORT PRBool -NSCanUnload(nsISupports* serviceMgr) -{ - return gPluginObjectCount == 1 && !gPluginLocked; -} - -extern "C" NS_EXPORT nsresult -NSRegisterSelf(nsISupports *aServMgr, const char *path) -{ - nsresult rv = NS_OK; - - char buf[255]; // todo: use a const - - nsCString progID(NS_INLINE_PLUGIN_PROGID_PREFIX); - - // We will use the service manager to obtain the component - // manager, which will enable us to register a component - // with a ProgID (text string) instead of just the CID. - - nsIServiceManager *sm; - - // We can get the IID of an interface with the static GetIID() method as - // well. - - rv = aServMgr->QueryInterface(NS_GET_IID(nsIServiceManager), (void **)&sm); - - if (NS_FAILED(rv)) - return rv; - - nsIComponentManager *cm; - - rv = sm->GetService(kComponentManagerCID, NS_GET_IID(nsIComponentManager), (nsISupports **)&cm); - - if (NS_FAILED(rv)) { - NS_RELEASE(sm); - - return rv; - } - - // Note the text string, we can access the hello component with just this - // string without knowing the CID - - progID += PLUGIN_MIME_TYPE; - progID.ToCString(buf, 255); // todo: need to use a const - - rv = cm->RegisterComponent(kSimplePluginCID, g_desc, buf, - path, PR_TRUE, PR_TRUE); - - sm->ReleaseService(kComponentManagerCID, cm); - - NS_RELEASE(sm); - -#ifdef NS_DEBUG - printf("*** %s registered\n",g_desc); -#endif - - return rv; -} - -extern "C" NS_EXPORT nsresult -NSUnregisterSelf(nsISupports* aServMgr, const char *path) -{ - nsresult rv = NS_OK; - - nsIServiceManager *sm; - - rv = aServMgr->QueryInterface(NS_GET_IID(nsIServiceManager), (void **)&sm); - - if (NS_FAILED(rv)) - return rv; - - nsIComponentManager *cm; - - rv = sm->GetService(kComponentManagerCID, NS_GET_IID(nsIComponentManager), (nsISupports **)&cm); - - if (NS_FAILED(rv)) { - NS_RELEASE(sm); - - return rv; - } - - rv = cm->UnregisterComponent(kSimplePluginCID, path); - - sm->ReleaseService(kComponentManagerCID, cm); - - NS_RELEASE(sm); - - return rv; -} - - -NS_METHOD -SimplePlugin::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - SimplePluginInstance* inst = new SimplePluginInstance(); - if (inst == NULL) - return NS_ERROR_OUT_OF_MEMORY; - inst->AddRef(); - *aResult = inst; - return NS_OK; -} - -NS_METHOD -SimplePlugin::LockFactory(PRBool aLock) -{ - gPluginLocked = aLock; - return NS_OK; -} - -NS_METHOD -SimplePlugin::Initialize() -{ -#ifdef NS_DEBUG - printf("SimplePlugin::Initialize\n"); -#endif - - return NS_OK; -} - -NS_METHOD -SimplePlugin::Shutdown(void) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::Shutdown\n"); -#endif - - return NS_OK; -} - -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * GetMIMEDescription: - +++++++++++++++++++++++++++++++++++++++++++++++++*/ - -NS_METHOD -SimplePlugin::GetMIMEDescription(const char* *result) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::GetMIMEDescription\n"); -#endif - - *result = PLUGIN_MIME_DESCRIPTION; - return NS_OK; -} - -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * NPP_GetValue: - +++++++++++++++++++++++++++++++++++++++++++++++++*/ - -NS_METHOD -SimplePlugin::GetValue(nsPluginVariable variable, void *value) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::GetValue\n"); -#endif - - nsresult err = NS_OK; - if (variable == nsPluginVariable_NameString) - *((char **)value) = PLUGIN_NAME; - else if (variable == nsPluginVariable_DescriptionString) - *((char **)value) = PLUGIN_DESCRIPTION; - else - err = NS_ERROR_FAILURE; - - return err; -} - -NS_IMETHODIMP -SimplePlugin::CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID, - const char* aPluginMIMEType, - void **aResult) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::CreatePluginInstance\n"); -#endif - - SimplePluginInstance* inst = new SimplePluginInstance(); - if(!inst) - { - *aResult = NULL; - return NS_ERROR_UNEXPECTED; - - } - inst->AddRef(); - *aResult = inst; - return NS_OK; -} +// XXXwaterson document! +static nsModuleComponentInfo gComponentInfo[] = { + { "Simple Plugin", + NS_SIMPLEPLUGIN_CID, + NS_INLINE_PLUGIN_PROGID_PREFIX PLUGIN_MIME_TYPE, + SimplePluginInstance::Create, + SimplePluginInstance::RegisterSelf, + SimplePluginInstance::UnregisterSelf }, +}; + +NS_IMPL_NSGETMODULE("SimplePlugin", gComponentInfo); //////////////////////////////////////////////////////////////////////////////// // SimplePluginInstance Methods //////////////////////////////////////////////////////////////////////////////// +NS_METHOD +SimplePluginInstance::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) +{ + NS_PRECONDITION(aOuter == nsnull, "no aggregation"); + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + + SimplePluginInstance* plugin = new SimplePluginInstance(); + if (! plugin) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv; + NS_ADDREF(plugin); + rv = plugin->QueryInterface(aIID, aResult); + NS_RELEASE(plugin); + return rv; +} + +NS_METHOD +SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation, + const char* aComponentType) +{ + nsresult rv; + + nsIPluginManager* pm; + rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(nsISupports**, &pm)); + if (NS_SUCCEEDED(rv)) { + rv = pm->RegisterPlugin(kSimplePluginCID, + kPluginName, + kPluginDescription, + kMimeTypes, + kMimeDescriptions, + kFileExtensions, + kNumMimeTypes); + + NS_RELEASE(pm); + } + + return rv; +} + + +NS_METHOD +SimplePluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation) +{ + nsresult rv; + + nsIPluginManager* pm; + rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(nsISupports**, &pm)); + if (NS_SUCCEEDED(rv)) { + rv = pm->UnregisterPlugin(kSimplePluginCID); + NS_RELEASE(pm); + } + + return rv; +} + + SimplePluginInstance::SimplePluginInstance(void) - : fPeer(NULL), fWindow(NULL), fMode(nsPluginMode_Embedded), fText(NULL) + : fText(NULL), fPeer(NULL), fWindow(NULL), fMode(nsPluginMode_Embedded) { NS_INIT_REFCNT(); - gPluginObjectCount++; static const char text[] = "Hello World!"; fText = (char*) nsMemory::Clone(text, sizeof(text)); @@ -732,7 +453,6 @@ SimplePluginInstance::SimplePluginInstance(void) SimplePluginInstance::~SimplePluginInstance(void) { - gPluginObjectCount--; if(fText) nsMemory::Free(fText); PlatformDestroy(); // Perform platform specific cleanup @@ -1033,7 +753,6 @@ SimplePluginStreamListener::SimplePluginStreamListener(SimplePluginInstance* ins const char* msgName) : fMessageName(msgName) { - gPluginObjectCount++; NS_INIT_REFCNT(); char msg[256]; sprintf(msg, "### Creating SimplePluginStreamListener for %s\n", fMessageName); @@ -1041,7 +760,6 @@ SimplePluginStreamListener::SimplePluginStreamListener(SimplePluginInstance* ins SimplePluginStreamListener::~SimplePluginStreamListener(void) { - gPluginObjectCount--; char msg[256]; sprintf(msg, "### Destroying SimplePluginStreamListener for %s\n", fMessageName); } @@ -1049,7 +767,7 @@ SimplePluginStreamListener::~SimplePluginStreamListener(void) // This macro produces a simple version of QueryInterface, AddRef and Release. // See the nsISupports.h header file for details. -NS_IMPL_ISUPPORTS(SimplePluginStreamListener, kIPluginStreamListenerIID); +NS_IMPL_ISUPPORTS1(SimplePluginStreamListener, nsIPluginStreamListener); NS_METHOD SimplePluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo) @@ -1132,7 +850,7 @@ SimplePluginStreamListener::GetStreamType(nsPluginStreamType *result) } /******************************************************************************* - * SECTION 5 - Utility Method Implementations + * SECTION 4 - Utility Method Implementations *******************************************************************************/ /*------------------------------------------------------------------------------ diff --git a/mozilla/modules/plugin/samples/simple/resource.h b/mozilla/modules/plugin/samples/simple/resource.h deleted file mode 100644 index 7152f7bd7fe..00000000000 --- a/mozilla/modules/plugin/samples/simple/resource.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by Simple32.rc -// - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 129 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/mozilla/modules/plugin/samples/simple/stubs.c b/mozilla/modules/plugin/samples/simple/stubs.c deleted file mode 100644 index 82cdab12e9d..00000000000 --- a/mozilla/modules/plugin/samples/simple/stubs.c +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "_jri/netscape_plugin_Plugin.c" - -/* -** Define IMPLEMENT_Simple in order to pull the stub code in when -** compiling the Simple.c file. Without doing this, we'd get a -** UnsatisfiedLinkError whenever we tried to call one of the native -** methods: -*/ -#define IMPLEMENT_Simple - -/* -** Include the native stubs, initialization routines and -** debugging code. You should be building with DEBUG defined in order to -** take advantage of the diagnostic code that javah creates for -** you. Otherwise your life will be hell. -*/ -#include "_jri/Simple.c" - -#include "prtypes.h" -#include "npapi.h" - -// Include the old API glue file. -#ifdef XP_UNIX -# include "npunix.c" -#endif - diff --git a/mozilla/modules/plugin/test/Simple.java b/mozilla/modules/plugin/test/Simple.java deleted file mode 100644 index 22f28c37385..00000000000 --- a/mozilla/modules/plugin/test/Simple.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -import netscape.plugin.Plugin; - -class Simple extends Plugin { - - /* - ** A plug-in can consist of code written in java as well as - ** natively. Here's a dummy method. - */ - public static int fact(int n) { - if (n == 1) - return 1; - else - return n * fact(n-1); - } - - /* - ** This instance variable is used to keep track of the number of - ** times we've called into this plug-in. - */ - int count; - - /* - ** This native method will give us a way to print to stdout from java - ** instead of just the java console. - */ - native void printToStdout(String msg); - - /* - ** This is a publically callable new feature that our plug-in is - ** providing. We can call it from JavaScript, Java, or from native - ** code. - */ - public void doit(String text) { - /* construct a message */ - String msg = "" + (++count) + ". " + text + "\n"; - /* write it to the console */ - System.out.print(msg); - /* and also write it to stdout */ - printToStdout(msg); - } -} diff --git a/mozilla/modules/plugin/test/Simple32.def b/mozilla/modules/plugin/test/Simple32.def deleted file mode 100644 index c33fe338638..00000000000 --- a/mozilla/modules/plugin/test/Simple32.def +++ /dev/null @@ -1,28 +0,0 @@ -; -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -; -; 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/ -; -; 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. -; -; The Original Code is mozilla.org code. -; -; The Initial Developer of the Original Code is Netscape -; Communications Corporation. Portions created by Netscape are -; Copyright (C) 1998 Netscape Communications Corporation. All -; Rights Reserved. -; -; Contributor(s): - -LIBRARY NPSimp32 - -CODE PRELOAD MOVEABLE DISCARDABLE -DATA PRELOAD SINGLE - -EXPORTS - NSGetFactory @1 diff --git a/mozilla/modules/plugin/test/Simple32.rc b/mozilla/modules/plugin/test/Simple32.rc deleted file mode 100644 index 5fc7246a307..00000000000 --- a/mozilla/modules/plugin/test/Simple32.rc +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "#define _AFX_NO_SPLITTER_RESOURCES\r\n" - "#define _AFX_NO_OLE_RESOURCES\r\n" - "#define _AFX_NO_TRACKER_RESOURCES\r\n" - "#define _AFX_NO_PROPERTY_RESOURCES\r\n" - "\r\n" - "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" - "#ifdef _WIN32\r\n" - "LANGUAGE 9, 1\r\n" - "#pragma code_page(1252)\r\n" - "#endif\r\n" - "#include ""res\\CharFlipper.rc2"" // non-Microsoft Visual C++ edited resources\r\n" - "#include ""afxres.rc"" // Standard components\r\n" - "#endif\0" -END - -#endif // APSTUDIO_INVOKED - - -#ifndef _MAC -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,1 - PRODUCTVERSION 1,0,0,1 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "CompanyName", "\0" - VALUE "FileDescription", "Simple Example Plugin\0" - VALUE "FileExtents", "smp\0" - VALUE "FileOpenName", "Simple Plugin File (*.smp)\0" - VALUE "FileVersion", "1, 0, 0, 1\0" - VALUE "InternalName", "CHARFLIPPER\0" - VALUE "LegalCopyright", "Copyright © 1996\0" - VALUE "MIMEType", "application/x-simple\0" - VALUE "OriginalFilename", "NPSimp32.dll\0" - VALUE "ProductName", "HelloWorld Example Plugin\0" - VALUE "ProductVersion", "1, 0, 0, 1\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END - -#endif // !_MAC - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// -#define _AFX_NO_SPLITTER_RESOURCES -#define _AFX_NO_OLE_RESOURCES -#define _AFX_NO_TRACKER_RESOURCES -#define _AFX_NO_PROPERTY_RESOURCES - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE 9, 1 -#pragma code_page(1252) -#endif -#include "afxres.rc" // Standard components -#endif -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/mozilla/modules/plugin/test/makefile.win b/mozilla/modules/plugin/test/makefile.win index 3e7dc8899bb..344a9134298 100644 --- a/mozilla/modules/plugin/test/makefile.win +++ b/mozilla/modules/plugin/test/makefile.win @@ -51,8 +51,6 @@ MAKE_OBJ_TYPE=DLL DLLNAME=npsimple.dll PDBFILE=npsimple.pdb MAPFILE=npsimple.map -#DEFFILE=Simple32.def -RESFILE=Simple32.res #//------------------------------------------------------------------------ #// @@ -91,4 +89,4 @@ LCFLAGS = $(LCFLAGS) -DNEW_PLUGIN_STREAM_API install:: $(DLL) # $(MAKE_INSTALL) $(XPDIST)\classes11\Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple # $(MAKE_INSTALL) Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple - $(MAKE_INSTALL) $(OBJDIR)\npsimple.dll $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple + $(MAKE_INSTALL) $(OBJDIR)\npsimple.dll $(DIST)\bin\components diff --git a/mozilla/modules/plugin/test/npsimple.cpp b/mozilla/modules/plugin/test/npsimple.cpp index 8e746aaa05d..f7c2e7b55f9 100644 --- a/mozilla/modules/plugin/test/npsimple.cpp +++ b/mozilla/modules/plugin/test/npsimple.cpp @@ -24,7 +24,7 @@ /******************************************************************************* * npsimple.cpp ****************************************************************************** - * Simple LiveConnect Sample Plugin + * Simple Sample Plugin * Copyright (c) 1996 Netscape Communications. All rights reserved. ****************************************************************************** * OVERVIEW @@ -32,8 +32,7 @@ * Section 1 - Includes * Section 2 - Instance Structs * Section 3 - API Plugin Implementations - * Section 4 - Java Native Method Implementations - * Section 5 - Utility Method Implementations + * Section 4 - Utility Method Implementations *******************************************************************************/ /******************************************************************************* @@ -45,6 +44,8 @@ #include "nsIServiceManager.h" #include "nsISupports.h" #include "nsIFactory.h" +#include "nsIGenericFactory.h" +#include "nsMemory.h" #include "nsString.h" #include "simpleCID.h" @@ -137,25 +138,28 @@ typedef struct _PlatformInstance // Define constants for easy use -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID); -static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); -static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); -static NS_DEFINE_IID(kIServiceManagerIID, NS_ISERVICEMANAGER_IID); -static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID); - -static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID); -static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); -static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); static NS_DEFINE_CID(kSimplePluginCID, NS_SIMPLEPLUGIN_CID); +static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); -#define PLUGIN_NAME "Simple Sample Plug-in" -#define PLUGIN_DESCRIPTION "Demonstrates a simple plug-in." -#define PLUGIN_MIME_DESCRIPTION "application/x-simple:smp:Simple Sample Plug-in" #define PLUGIN_MIME_TYPE "application/x-simple" -static const char* g_desc = "Sample XPCOM Plugin"; +static const char kPluginName[] = "Simple Sample Plug-in"; +static const char kPluginDescription[] = "Demonstrates a simple plug-in."; + +static const char* kMimeTypes[] = { + PLUGIN_MIME_TYPE +}; + +static const char* kMimeDescriptions[] = { + "Simple Sample Plug-in" +}; + +static const char* kFileExtensions[] = { + "smp" +}; + +static const PRInt32 kNumMimeTypes = sizeof(kMimeTypes) / sizeof(*kMimeTypes); + //////////////////////////////////////////////////////////////////////////////// @@ -163,84 +167,28 @@ static const char* g_desc = "Sample XPCOM Plugin"; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -// SimplePlugin represents the class of all simple plugins. One -// instance of this class is kept around for as long as there are -// plugin instances outstanding. - -class SimplePlugin : public nsIPlugin { -public: - - //////////////////////////////////////////////////////////////////////////// - // from nsIFactory: - - NS_IMETHOD CreateInstance(nsISupports *aOuter, - REFNSIID aIID, - void **aResult); - - NS_IMETHOD LockFactory(PRBool aLock); - - //////////////////////////////////////////////////////////////////////////// - // from nsIPlugin: - - // This call initializes the plugin and will be called before any new - // instances are created. It is passed browserInterfaces on which QueryInterface - // may be used to obtain an nsIPluginManager, and other interfaces. - NS_IMETHOD - Initialize(void); - - // (Corresponds to NPP_Shutdown.) - // Called when the browser is done with the plugin factory, or when - // the plugin is disabled by the user. - NS_IMETHOD - Shutdown(void); - - // (Corresponds to NPP_GetMIMEDescription.) - NS_IMETHOD - GetMIMEDescription(const char* *result); - - // (Corresponds to NPP_GetValue.) - NS_IMETHOD - GetValue(nsPluginVariable variable, void *value); - - NS_IMETHOD - CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID, - const char* aPluginMIMEType, - void **aResult); - - // The old NPP_New call has been factored into two plugin instance methods: - // - // CreateInstance -- called once, after the plugin instance is created. This - // method is used to initialize the new plugin instance (although the actual - // plugin instance object will be created by the plugin manager). - // - // nsIPluginInstance::Start -- called when the plugin instance is to be - // started. This happens in two circumstances: (1) after the plugin instance - // is first initialized, and (2) after a plugin instance is returned to - // (e.g. by going back in the window history) after previously being stopped - // by the Stop method. - - // SimplePlugin specific methods: - - SimplePlugin(); - virtual ~SimplePlugin(void); - - NS_DECL_ISUPPORTS - - nsIPluginManager* GetPluginManager(void) { return mPluginManager; } - -protected: - nsIPluginManager* mPluginManager; - nsIServiceManager* mServiceManager; - -}; - -//////////////////////////////////////////////////////////////////////////////// -// SimplePluginInstance represents an instance of the SimplePlugin class. +// SimplePluginInstance represents an instance of the simple plugin class. class SimplePluginInstance : public nsIPluginInstance, public nsISimplePluginInstance { public: + //////////////////////////////////////////////////////////////////////////// + // for implementing a generic module + static NS_METHOD + Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); + + static NS_METHOD + RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation, + const char* aComponentType); + + static NS_METHOD + UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation); + NS_DECL_ISUPPORTS NS_DECL_NSISIMPLEPLUGININSTANCE @@ -401,323 +349,96 @@ public: protected: const char* fMessageName; - }; /******************************************************************************* * SECTION 3 - API Plugin Implementations ******************************************************************************/ -// This counter is used to keep track of the number of outstanding objects. -// It is used to determine whether the plugin's DLL can be unloaded. -static PRUint32 gPluginObjectCount = 0; - -// This flag is used to keep track of whether the plugin's DLL is explicitly -// being retained by some client. -static PRBool gPluginLocked = PR_FALSE; - -//////////////////////////////////////////////////////////////////////////////// -// SimplePlugin Methods -//////////////////////////////////////////////////////////////////////////////// - -SimplePlugin::SimplePlugin() - : mPluginManager(NULL), - mServiceManager(NULL) -{ - NS_INIT_REFCNT(); - - if(nsComponentManager::CreateInstance(kCPluginManagerCID, - NULL, kIPluginManagerIID, (void**)&mPluginManager) != NS_OK) - return; - - gPluginObjectCount++; -} - -SimplePlugin::~SimplePlugin(void) -{ - if(mPluginManager) - mPluginManager->Release(); - - if(mServiceManager) - mServiceManager->Release(); - - gPluginObjectCount--; -} - -// These macros produce simple version of QueryInterface and AddRef. -// See the nsISupports.h header file for details. - -NS_METHOD -SimplePlugin::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ - if (!aInstancePtr) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = NS_STATIC_CAST(nsISupports*,this); - } else if (aIID.Equals(kIFactoryIID)) { - *aInstancePtr = NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(nsIFactory*,this)); - } else if (aIID.Equals(kIPluginIID)) { - *aInstancePtr = NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(nsIPlugin*,this)); - } else { - *aInstancePtr = nsnull; - return NS_ERROR_NO_INTERFACE; - } - - NS_ADDREF(NS_REINTERPRET_CAST(nsISupports*,*aInstancePtr)); - - return NS_OK; -} - -NS_IMPL_ADDREF(SimplePlugin); -NS_IMPL_RELEASE(SimplePlugin); - -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * NSGetFactory: - * Provides global initialization for a plug-in, and returns an error value. - * - * This function is called once when a plug-in is loaded, before the first instance - * is created. You should allocate any memory or resources shared by all - * instances of your plug-in at this time. After the last instance has been deleted, - * NPP_Shutdown will be called, where you can release any memory or - * resources allocated by NPP_Initialize. - +++++++++++++++++++++++++++++++++++++++++++++++++*/ - -SimplePlugin* gPlugin = NULL; - -extern "C" NS_EXPORT nsresult -NSGetFactory(nsISupports* serviceMgr, - const nsCID &aCID, - const char *aClassName, - const char *aProgID, - nsIFactory **aResult) -{ - if (!aResult) - return NS_ERROR_NULL_POINTER; - - *aResult = nsnull; - - nsISupports *inst; - - if (aCID.Equals(kSimplePluginCID)) { - // Ok, we know this CID and here is the factory - // that can manufacture the objects - inst = new SimplePlugin(); - } else if (aCID.Equals(kPluginCID)) { - inst = new SimplePlugin(); - } else { - return NS_ERROR_NO_INTERFACE; - } - - if (!inst) - return NS_ERROR_OUT_OF_MEMORY; - - nsresult rv = inst->QueryInterface(kIFactoryIID, - (void **) aResult); - - if (NS_FAILED(rv)) { - delete inst; - } - - return rv; -} - -extern "C" NS_EXPORT PRBool -NSCanUnload(nsISupports* serviceMgr) -{ - return gPluginObjectCount == 1 && !gPluginLocked; -} - -extern "C" NS_EXPORT nsresult -NSRegisterSelf(nsISupports *aServMgr, const char *path) -{ - nsresult rv = NS_OK; - - char buf[255]; // todo: use a const - - nsCString progID(NS_INLINE_PLUGIN_PROGID_PREFIX); - - // We will use the service manager to obtain the component - // manager, which will enable us to register a component - // with a ProgID (text string) instead of just the CID. - - nsIServiceManager *sm; - - // We can get the IID of an interface with the static GetIID() method as - // well. - - rv = aServMgr->QueryInterface(NS_GET_IID(nsIServiceManager), (void **)&sm); - - if (NS_FAILED(rv)) - return rv; - - nsIComponentManager *cm; - - rv = sm->GetService(kComponentManagerCID, NS_GET_IID(nsIComponentManager), (nsISupports **)&cm); - - if (NS_FAILED(rv)) { - NS_RELEASE(sm); - - return rv; - } - - // Note the text string, we can access the hello component with just this - // string without knowing the CID - - progID += PLUGIN_MIME_TYPE; - progID.ToCString(buf, 255); // todo: need to use a const - - rv = cm->RegisterComponent(kSimplePluginCID, g_desc, buf, - path, PR_TRUE, PR_TRUE); - - sm->ReleaseService(kComponentManagerCID, cm); - - NS_RELEASE(sm); - -#ifdef NS_DEBUG - printf("*** %s registered\n",g_desc); -#endif - - return rv; -} - -extern "C" NS_EXPORT nsresult -NSUnregisterSelf(nsISupports* aServMgr, const char *path) -{ - nsresult rv = NS_OK; - - nsIServiceManager *sm; - - rv = aServMgr->QueryInterface(NS_GET_IID(nsIServiceManager), (void **)&sm); - - if (NS_FAILED(rv)) - return rv; - - nsIComponentManager *cm; - - rv = sm->GetService(kComponentManagerCID, NS_GET_IID(nsIComponentManager), (nsISupports **)&cm); - - if (NS_FAILED(rv)) { - NS_RELEASE(sm); - - return rv; - } - - rv = cm->UnregisterComponent(kSimplePluginCID, path); - - sm->ReleaseService(kComponentManagerCID, cm); - - NS_RELEASE(sm); - - return rv; -} - - -NS_METHOD -SimplePlugin::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - SimplePluginInstance* inst = new SimplePluginInstance(); - if (inst == NULL) - return NS_ERROR_OUT_OF_MEMORY; - inst->AddRef(); - *aResult = inst; - return NS_OK; -} - -NS_METHOD -SimplePlugin::LockFactory(PRBool aLock) -{ - gPluginLocked = aLock; - return NS_OK; -} - -NS_METHOD -SimplePlugin::Initialize() -{ -#ifdef NS_DEBUG - printf("SimplePlugin::Initialize\n"); -#endif - - return NS_OK; -} - -NS_METHOD -SimplePlugin::Shutdown(void) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::Shutdown\n"); -#endif - - return NS_OK; -} - -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * GetMIMEDescription: - +++++++++++++++++++++++++++++++++++++++++++++++++*/ - -NS_METHOD -SimplePlugin::GetMIMEDescription(const char* *result) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::GetMIMEDescription\n"); -#endif - - *result = PLUGIN_MIME_DESCRIPTION; - return NS_OK; -} - -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * NPP_GetValue: - +++++++++++++++++++++++++++++++++++++++++++++++++*/ - -NS_METHOD -SimplePlugin::GetValue(nsPluginVariable variable, void *value) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::GetValue\n"); -#endif - - nsresult err = NS_OK; - if (variable == nsPluginVariable_NameString) - *((char **)value) = PLUGIN_NAME; - else if (variable == nsPluginVariable_DescriptionString) - *((char **)value) = PLUGIN_DESCRIPTION; - else - err = NS_ERROR_FAILURE; - - return err; -} - -NS_IMETHODIMP -SimplePlugin::CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID, - const char* aPluginMIMEType, - void **aResult) -{ -#ifdef NS_DEBUG - printf("SimplePlugin::CreatePluginInstance\n"); -#endif - - SimplePluginInstance* inst = new SimplePluginInstance(); - if(!inst) - { - *aResult = NULL; - return NS_ERROR_UNEXPECTED; - - } - inst->AddRef(); - *aResult = inst; - return NS_OK; -} +// XXXwaterson document! +static nsModuleComponentInfo gComponentInfo[] = { + { "Simple Plugin", + NS_SIMPLEPLUGIN_CID, + NS_INLINE_PLUGIN_PROGID_PREFIX PLUGIN_MIME_TYPE, + SimplePluginInstance::Create, + SimplePluginInstance::RegisterSelf, + SimplePluginInstance::UnregisterSelf }, +}; + +NS_IMPL_NSGETMODULE("SimplePlugin", gComponentInfo); //////////////////////////////////////////////////////////////////////////////// // SimplePluginInstance Methods //////////////////////////////////////////////////////////////////////////////// +NS_METHOD +SimplePluginInstance::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) +{ + NS_PRECONDITION(aOuter == nsnull, "no aggregation"); + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + + SimplePluginInstance* plugin = new SimplePluginInstance(); + if (! plugin) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv; + NS_ADDREF(plugin); + rv = plugin->QueryInterface(aIID, aResult); + NS_RELEASE(plugin); + return rv; +} + +NS_METHOD +SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation, + const char* aComponentType) +{ + nsresult rv; + + nsIPluginManager* pm; + rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(nsISupports**, &pm)); + if (NS_SUCCEEDED(rv)) { + rv = pm->RegisterPlugin(kSimplePluginCID, + kPluginName, + kPluginDescription, + kMimeTypes, + kMimeDescriptions, + kFileExtensions, + kNumMimeTypes); + + NS_RELEASE(pm); + } + + return rv; +} + + +NS_METHOD +SimplePluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFile* aPath, + const char* aRegistryLocation) +{ + nsresult rv; + + nsIPluginManager* pm; + rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(nsISupports**, &pm)); + if (NS_SUCCEEDED(rv)) { + rv = pm->UnregisterPlugin(kSimplePluginCID); + NS_RELEASE(pm); + } + + return rv; +} + + SimplePluginInstance::SimplePluginInstance(void) - : fPeer(NULL), fWindow(NULL), fMode(nsPluginMode_Embedded), fText(NULL) + : fText(NULL), fPeer(NULL), fWindow(NULL), fMode(nsPluginMode_Embedded) { NS_INIT_REFCNT(); - gPluginObjectCount++; static const char text[] = "Hello World!"; fText = (char*) nsMemory::Clone(text, sizeof(text)); @@ -732,7 +453,6 @@ SimplePluginInstance::SimplePluginInstance(void) SimplePluginInstance::~SimplePluginInstance(void) { - gPluginObjectCount--; if(fText) nsMemory::Free(fText); PlatformDestroy(); // Perform platform specific cleanup @@ -1033,7 +753,6 @@ SimplePluginStreamListener::SimplePluginStreamListener(SimplePluginInstance* ins const char* msgName) : fMessageName(msgName) { - gPluginObjectCount++; NS_INIT_REFCNT(); char msg[256]; sprintf(msg, "### Creating SimplePluginStreamListener for %s\n", fMessageName); @@ -1041,7 +760,6 @@ SimplePluginStreamListener::SimplePluginStreamListener(SimplePluginInstance* ins SimplePluginStreamListener::~SimplePluginStreamListener(void) { - gPluginObjectCount--; char msg[256]; sprintf(msg, "### Destroying SimplePluginStreamListener for %s\n", fMessageName); } @@ -1049,7 +767,7 @@ SimplePluginStreamListener::~SimplePluginStreamListener(void) // This macro produces a simple version of QueryInterface, AddRef and Release. // See the nsISupports.h header file for details. -NS_IMPL_ISUPPORTS(SimplePluginStreamListener, kIPluginStreamListenerIID); +NS_IMPL_ISUPPORTS1(SimplePluginStreamListener, nsIPluginStreamListener); NS_METHOD SimplePluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo) @@ -1132,7 +850,7 @@ SimplePluginStreamListener::GetStreamType(nsPluginStreamType *result) } /******************************************************************************* - * SECTION 5 - Utility Method Implementations + * SECTION 4 - Utility Method Implementations *******************************************************************************/ /*------------------------------------------------------------------------------ diff --git a/mozilla/modules/plugin/test/resource.h b/mozilla/modules/plugin/test/resource.h deleted file mode 100644 index 7152f7bd7fe..00000000000 --- a/mozilla/modules/plugin/test/resource.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by Simple32.rc -// - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 129 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/mozilla/modules/plugin/test/stubs.c b/mozilla/modules/plugin/test/stubs.c deleted file mode 100644 index 82cdab12e9d..00000000000 --- a/mozilla/modules/plugin/test/stubs.c +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "_jri/netscape_plugin_Plugin.c" - -/* -** Define IMPLEMENT_Simple in order to pull the stub code in when -** compiling the Simple.c file. Without doing this, we'd get a -** UnsatisfiedLinkError whenever we tried to call one of the native -** methods: -*/ -#define IMPLEMENT_Simple - -/* -** Include the native stubs, initialization routines and -** debugging code. You should be building with DEBUG defined in order to -** take advantage of the diagnostic code that javah creates for -** you. Otherwise your life will be hell. -*/ -#include "_jri/Simple.c" - -#include "prtypes.h" -#include "npapi.h" - -// Include the old API glue file. -#ifdef XP_UNIX -# include "npunix.c" -#endif - diff --git a/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp b/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp index 2094159c60d..1f6eea4ee38 100644 --- a/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp +++ b/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp @@ -25,7 +25,6 @@ #include "nsIComponentManager.h" #include "nsWidgetsCID.h" #include "nsViewsCID.h" -#include "nsPluginsCID.h" #include "nsIDocumentLoader.h" @@ -34,7 +33,6 @@ #include "nsILiveconnect.h" #include "nsIJVMManager.h" #endif -#include "nsIPluginManager.h" #include "nsIProperties.h" #include "nsIObserverService.h" @@ -61,7 +59,6 @@ #define VIEW_DLL "NGVIEW" #define WEB_DLL "WEBSHELL" #define DOM_DLL "JSDOM" - #define PLUGIN_DLL "NGPLUGIN" #define CAPS_DLL "CAPS" #define LIVECONNECT_DLL "JSJ" #define OJI_DLL "OJI" @@ -70,7 +67,6 @@ #define GFXWIN_DLL "gkgfxwin.dll" #define VIEW_DLL "gkview.dll" #define DOM_DLL "jsdom.dll" - #define PLUGIN_DLL "gkplugin.dll" #define CAPS_DLL "caps.dll" #define LIVECONNECT_DLL "jsj3250.dll" #define OJI_DLL "oji.dll" @@ -80,14 +76,12 @@ #define VIEW_DLL "VIEW_DLL" #define WEB_DLL "WEB_DLL" #define DOM_DLL "DOM_DLL" - #define PLUGIN_DLL "PLUGIN_DLL" #define CAPS_DLL "CAPS_DLL" #define LIVECONNECT_DLL "LIVECONNECT_DLL" #define OJI_DLL "OJI_DLL" #else #define VIEW_DLL "libgkview"MOZ_DLL_SUFFIX #define DOM_DLL "libjsdom"MOZ_DLL_SUFFIX - #define PLUGIN_DLL "libgkplugin"MOZ_DLL_SUFFIX #define CAPS_DLL "libcaps"MOZ_DLL_SUFFIX #define LIVECONNECT_DLL "libliveconnect"MOZ_DLL_SUFFIX #define OJI_DLL "liboji"MOZ_DLL_SUFFIX @@ -160,10 +154,6 @@ static NS_DEFINE_IID(kCScrollPortViewCID, NS_SCROLL_PORT_VIEW_CID); static NS_DEFINE_IID(kCDOMScriptObjectFactory, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); static NS_DEFINE_IID(kCScriptNameSetRegistry, NS_SCRIPT_NAMESET_REGISTRY_CID); -// PLUGIN -static NS_DEFINE_IID(kCPluginHostCID, NS_PLUGIN_HOST_CID); -static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); - // for prefs static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID); @@ -267,10 +257,6 @@ NS_SetupRegistry() nsComponentManager::RegisterComponentLib(kCDOMScriptObjectFactory, NULL, NULL, DOM_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCScriptNameSetRegistry, NULL, NULL, DOM_DLL, PR_FALSE, PR_FALSE); - // PLUGIN - nsComponentManager::RegisterComponentLib(kCPluginHostCID, NULL, NULL, PLUGIN_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCPluginManagerCID, NULL, NULL, PLUGIN_DLL, PR_FALSE, PR_FALSE); - #ifdef OJI nsComponentManager::RegisterComponentLib(kCLiveconnectCID, "LiveConnect", "component://netscape/javascript/liveconnect", LIVECONNECT_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCJVMManagerCID, "JVMManager", "component://netscape/oji/jvmmanager", OJI_DLL, PR_FALSE, PR_FALSE);