Back to index

lightning-sunbird  0.9+nobinonly
nsPluginInstancePeer.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nscore.h"
00040 #include "nsPluginInstancePeer.h"
00041 #include "nsIPluginInstance.h"
00042 #include <stdio.h>
00043 #include "prmem.h"
00044 #include "prthread.h"
00045 #include "plstr.h"
00046 #include "prprf.h"
00047 #include "nsIFile.h"
00048 #include "nsCOMPtr.h"
00049 #ifdef OJI
00050 #include "nsIJVMManager.h"
00051 #endif
00052 #include "nsIServiceManager.h"
00053 
00054 #include "nsIDocument.h"
00055 #include "nsPIDOMWindow.h"
00056 #include "nsIScriptGlobalObject.h"
00057 #include "nsIScriptContext.h"
00058 #include "nsIDirectoryService.h"
00059 #include "nsDirectoryServiceDefs.h"
00060 #include "nsIFileStreams.h"
00061 #include "nsNetUtil.h"
00062 
00063 #ifdef XP_WIN
00064 #include <windows.h>
00065 #include <winbase.h>
00066 #endif
00067 
00068 nsPluginInstancePeerImpl::nsPluginInstancePeerImpl()
00069 {
00070   mInstance = nsnull;
00071   mOwner = nsnull;
00072   mMIMEType = nsnull;
00073 }
00074 
00075 nsPluginInstancePeerImpl::~nsPluginInstancePeerImpl()
00076 {
00077   mInstance = nsnull;
00078   NS_IF_RELEASE(mOwner);
00079 
00080   if (nsnull != mMIMEType) {
00081     PR_Free((void *)mMIMEType);
00082     mMIMEType = nsnull;
00083   }
00084 }
00085 
00086 static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); 
00087 static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); 
00088 #ifdef OJI
00089 static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
00090 
00091 NS_IMPL_ISUPPORTS7(nsPluginInstancePeerImpl,
00092                    nsIPluginInstancePeer,
00093                    nsIPluginInstancePeer2,
00094                    nsIWindowlessPluginInstancePeer,
00095                    nsIPluginTagInfo,
00096                    nsIPluginTagInfo2,
00097                    nsIJVMPluginTagInfo,
00098                    nsPIPluginInstancePeer)
00099 #else
00100 NS_IMPL_ISUPPORTS6(nsPluginInstancePeerImpl,
00101                    nsIPluginInstancePeer,
00102                    nsIPluginInstancePeer2,
00103                    nsIWindowlessPluginInstancePeer,
00104                    nsIPluginTagInfo,
00105                    nsIPluginTagInfo2,
00106                    nsPIPluginInstancePeer)
00107 #endif
00108 
00109 NS_IMETHODIMP
00110 nsPluginInstancePeerImpl::GetValue(nsPluginInstancePeerVariable variable,
00111                                    void *value)
00112 {
00113   if(!mOwner)
00114     return NS_ERROR_FAILURE;
00115 
00116   return mOwner->GetValue(variable, value);
00117 }
00118 
00119 NS_IMETHODIMP
00120 nsPluginInstancePeerImpl::GetMIMEType(nsMIMEType *result)
00121 {
00122   if (nsnull == mMIMEType)
00123     *result = "";
00124   else
00125     *result = mMIMEType;
00126 
00127   return NS_OK;
00128 }
00129 
00130 NS_IMETHODIMP
00131 nsPluginInstancePeerImpl::GetMode(nsPluginMode *result)
00132 {
00133   if (nsnull != mOwner)
00134     return mOwner->GetMode(result);
00135   else
00136     return NS_ERROR_FAILURE;
00137 }
00138 
00139 // nsPluginStreamToFile
00140 // --------------------
00141 // Used to handle NPN_NewStream() - writes the stream as received by the plugin
00142 // to a file and at completion (NPN_DestroyStream), tells the browser to load it into
00143 // a plugin-specified target
00144 
00145 static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
00146 
00147 class nsPluginStreamToFile : public nsIOutputStream
00148 {
00149 public:
00150 
00151   nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner);
00152   virtual ~nsPluginStreamToFile();
00153 
00154   NS_DECL_ISUPPORTS
00155   NS_DECL_NSIOUTPUTSTREAM
00156 
00157 protected:
00158   char* mTarget;
00159   nsCString mFileURL;
00160   nsCOMPtr<nsILocalFile> mTempFile;
00161   nsCOMPtr<nsIOutputStream> mOutputStream;
00162   nsIPluginInstanceOwner* mOwner;
00163 };
00164 
00165 NS_IMPL_ADDREF(nsPluginStreamToFile)
00166 NS_IMPL_RELEASE(nsPluginStreamToFile)
00167 
00168 nsPluginStreamToFile::nsPluginStreamToFile(const char* target,
00169                                            nsIPluginInstanceOwner* owner)
00170   : mTarget(PL_strdup(target)),
00171     mOwner(owner)
00172 {
00173   nsresult rv;
00174   nsCOMPtr<nsIFile> pluginTmp;
00175   rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp));
00176   if (NS_FAILED(rv)) return;
00177 
00178   mTempFile = do_QueryInterface(pluginTmp, &rv);
00179   if (NS_FAILED(rv)) return;
00180     
00181   // need to create a file with a unique name - use target as the basis
00182   rv = mTempFile->AppendNative(nsDependentCString(target));
00183   if (NS_FAILED(rv)) return;
00184     
00185   // Yes, make it unique.
00186   rv = mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0700); 
00187   if (NS_FAILED(rv)) return;
00188 
00189   // create the file
00190   rv = NS_NewLocalFileOutputStream(getter_AddRefs(mOutputStream), mTempFile, -1, 00600);
00191   if (NS_FAILED(rv))
00192     return;
00193        
00194   mOutputStream->Close();
00195 
00196   // construct the URL we'll use later in calls to GetURL()
00197   NS_GetURLSpecFromFile(mTempFile, mFileURL);
00198 
00199 #ifdef NS_DEBUG
00200   printf("File URL = %s\n", mFileURL.get());
00201 #endif
00202 }
00203 
00204 nsPluginStreamToFile::~nsPluginStreamToFile()
00205 {
00206   // should we be deleting mTempFile here?
00207   if (nsnull != mTarget)
00208     PL_strfree(mTarget);
00209 }
00210 
00211 nsresult
00212 nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
00213                                      void** aInstancePtrResult)
00214 {
00215   NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
00216 
00217   if (nsnull == aInstancePtrResult)
00218     return NS_ERROR_NULL_POINTER;
00219 
00220   if (aIID.Equals(kIOutputStreamIID)) {
00221     *aInstancePtrResult = (void *)((nsIOutputStream *)this);
00222     AddRef();
00223     return NS_OK;
00224   }
00225 
00226   return NS_NOINTERFACE;
00227 }
00228 
00229 NS_IMETHODIMP
00230 nsPluginStreamToFile::Flush()
00231 {
00232   return NS_OK;
00233 }
00234 
00235 NS_IMETHODIMP
00236 nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount,
00237                             PRUint32 *aWriteCount)
00238 {
00239   PRUint32 actualCount;
00240   mOutputStream->Write(aBuf, aCount, &actualCount);
00241   mOutputStream->Flush();
00242   mOwner->GetURL(mFileURL.get(), mTarget, nsnull, 0, nsnull, 0);
00243 
00244   return NS_OK;
00245 }
00246     
00247 NS_IMETHODIMP
00248 nsPluginStreamToFile::WriteFrom(nsIInputStream *inStr, PRUint32 count,
00249                                 PRUint32 *_retval)
00250 {
00251   NS_NOTREACHED("WriteFrom");
00252   return NS_ERROR_NOT_IMPLEMENTED;
00253 }
00254 
00255 NS_IMETHODIMP
00256 nsPluginStreamToFile::WriteSegments(nsReadSegmentFun reader, void * closure,
00257                                     PRUint32 count, PRUint32 *_retval)
00258 {
00259   NS_NOTREACHED("WriteSegments");
00260   return NS_ERROR_NOT_IMPLEMENTED;
00261 }
00262 
00263 NS_IMETHODIMP
00264 nsPluginStreamToFile::IsNonBlocking(PRBool *aNonBlocking)
00265 {
00266   *aNonBlocking = PR_FALSE;
00267   return NS_OK;
00268 }
00269 
00270 NS_IMETHODIMP
00271 nsPluginStreamToFile::Close(void)
00272 {
00273   mOwner->GetURL(mFileURL.get(), mTarget, nsnull, 0, nsnull, 0);
00274   return NS_OK;
00275 }
00276 
00277 // end of nsPluginStreamToFile
00278 
00279 NS_IMETHODIMP
00280 nsPluginInstancePeerImpl::NewStream(nsMIMEType type, const char* target,
00281                                     nsIOutputStream* *result)
00282 {
00283   nsresult rv;
00284   nsPluginStreamToFile*  stream = new nsPluginStreamToFile(target, mOwner);
00285   if(stream == nsnull)
00286     return NS_ERROR_OUT_OF_MEMORY;
00287 
00288   rv = stream->QueryInterface(kIOutputStreamIID, (void **)result);
00289 
00290   return rv;
00291 }
00292 
00293 NS_IMETHODIMP
00294 nsPluginInstancePeerImpl::ShowStatus(const char* message)
00295 {
00296   if (nsnull != mOwner)
00297     return mOwner->ShowStatus(message);
00298   else
00299     return NS_ERROR_FAILURE;
00300 }
00301 
00302 NS_IMETHODIMP
00303 nsPluginInstancePeerImpl::GetAttributes(PRUint16& n, const char*const*& names,
00304                                         const char*const*& values)
00305 {
00306   if (nsnull != mOwner) {
00307     nsIPluginTagInfo  *tinfo;
00308     nsresult rv;
00309 
00310     rv = mOwner->QueryInterface(kIPluginTagInfoIID, (void **)&tinfo);
00311 
00312     if (NS_OK == rv)  {
00313       rv = tinfo->GetAttributes(n, names, values);
00314       NS_RELEASE(tinfo);
00315     }
00316 
00317     return rv;
00318   }
00319   else {
00320     n = 0;
00321     names = nsnull;
00322     values = nsnull;
00323 
00324     return NS_ERROR_FAILURE;
00325   }
00326 }
00327 
00328 NS_IMETHODIMP
00329 nsPluginInstancePeerImpl::GetAttribute(const char* name, const char* *result)
00330 {
00331   if (nsnull != mOwner) {
00332     nsIPluginTagInfo  *tinfo;
00333     nsresult rv;
00334 
00335     rv = mOwner->QueryInterface(kIPluginTagInfoIID, (void **)&tinfo);
00336 
00337     if (NS_OK == rv)  {
00338       rv = tinfo->GetAttribute(name, result);
00339       NS_RELEASE(tinfo);
00340     }
00341 
00342     return rv;
00343   }
00344   else {
00345     *result = "";
00346     return NS_ERROR_FAILURE;
00347   }
00348 }
00349 
00350 NS_IMETHODIMP
00351 nsPluginInstancePeerImpl::GetDOMElement(nsIDOMElement* *result)
00352 {
00353   if (mOwner == nsnull) {
00354     *result = nsnull;
00355     return NS_ERROR_FAILURE;
00356   }
00357 
00358   nsIPluginTagInfo2  *tinfo;
00359   nsresult rv;
00360 
00361   rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00362 
00363   if (NS_OK == rv)  {
00364     rv = tinfo->GetDOMElement(result);
00365     NS_RELEASE(tinfo);
00366   }
00367 
00368   return rv;
00369 }
00370 
00371 NS_IMETHODIMP
00372 nsPluginInstancePeerImpl::GetTagType(nsPluginTagType *result)
00373 {
00374   if (nsnull != mOwner) {
00375     nsIPluginTagInfo2 *tinfo;
00376     nsresult rv;
00377 
00378     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00379 
00380     if (NS_OK == rv)  {
00381       rv = tinfo->GetTagType(result);
00382       NS_RELEASE(tinfo);
00383     }
00384 
00385     return rv;
00386   }
00387   else {
00388     *result = nsPluginTagType_Unknown;
00389     return NS_ERROR_FAILURE;
00390   }
00391 }
00392 
00393 NS_IMETHODIMP
00394 nsPluginInstancePeerImpl::GetTagText(const char* *result)
00395 {
00396   if (nsnull != mOwner) {
00397     nsIPluginTagInfo2 *tinfo;
00398     nsresult          rv;
00399 
00400     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00401 
00402     if (NS_OK == rv) {
00403       rv = tinfo->GetTagText(result);
00404       NS_RELEASE(tinfo);
00405     }
00406 
00407     return rv;
00408   }
00409   else {
00410     *result = "";
00411     return NS_ERROR_FAILURE;
00412   }
00413 }
00414 
00415 NS_IMETHODIMP
00416 nsPluginInstancePeerImpl::GetParameters(PRUint16& n, const char*const*& names,
00417                                         const char*const*& values)
00418 {
00419   if (nsnull != mOwner) {
00420     nsIPluginTagInfo2 *tinfo;
00421     nsresult          rv;
00422 
00423     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00424 
00425     if (NS_OK == rv)  {
00426       rv = tinfo->GetParameters(n, names, values);
00427       NS_RELEASE(tinfo);
00428     }
00429 
00430     return rv;
00431   }
00432   else {
00433     n = 0;
00434     names = nsnull;
00435     values = nsnull;
00436 
00437     return NS_ERROR_FAILURE;
00438   }
00439 }
00440 
00441 NS_IMETHODIMP
00442 nsPluginInstancePeerImpl::GetParameter(const char* name, const char* *result)
00443 {
00444   if (nsnull != mOwner) {
00445     nsIPluginTagInfo2 *tinfo;
00446     nsresult          rv;
00447 
00448     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00449 
00450     if (NS_OK == rv) {
00451       rv = tinfo->GetParameter(name, result);
00452       NS_RELEASE(tinfo);
00453     }
00454 
00455     return rv;
00456   }
00457   else {
00458     *result = "";
00459     return NS_ERROR_FAILURE;
00460   }
00461 }
00462 
00463 NS_IMETHODIMP
00464 nsPluginInstancePeerImpl::GetDocumentBase(const char* *result)
00465 {
00466   if (nsnull != mOwner) {
00467     nsIPluginTagInfo2 *tinfo;
00468     nsresult          rv;
00469 
00470     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00471 
00472     if (NS_OK == rv) {
00473       rv = tinfo->GetDocumentBase(result);
00474       NS_RELEASE(tinfo);
00475     }
00476 
00477     return rv;
00478   }
00479   else {
00480     *result = "";
00481     return NS_ERROR_FAILURE;
00482   }
00483 }
00484 
00485 NS_IMETHODIMP
00486 nsPluginInstancePeerImpl::GetDocumentEncoding(const char* *result)
00487 {
00488   if (nsnull != mOwner) {
00489     nsIPluginTagInfo2 *tinfo;
00490     nsresult          rv;
00491 
00492     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00493 
00494     if (NS_OK == rv) {
00495       rv = tinfo->GetDocumentEncoding(result);
00496       NS_RELEASE(tinfo);
00497     }
00498 
00499     return rv;
00500   }
00501   else {
00502     *result = "";
00503     return NS_ERROR_FAILURE;
00504   }
00505 }
00506 
00507 NS_IMETHODIMP
00508 nsPluginInstancePeerImpl::GetAlignment(const char* *result)
00509 {
00510   if (nsnull != mOwner) {
00511     nsIPluginTagInfo2 *tinfo;
00512     nsresult          rv;
00513 
00514     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00515 
00516     if (NS_OK == rv) {
00517       rv = tinfo->GetAlignment(result);
00518       NS_RELEASE(tinfo);
00519     }
00520 
00521     return rv;
00522   }
00523   else {
00524     *result = "";
00525     return NS_ERROR_FAILURE;
00526   }
00527 }
00528 
00529 NS_IMETHODIMP
00530 nsPluginInstancePeerImpl::GetWidth(PRUint32 *result)
00531 {
00532   if (nsnull != mOwner) {
00533     nsIPluginTagInfo2 *tinfo;
00534     nsresult          rv;
00535 
00536     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00537 
00538     if (NS_OK == rv) {
00539       rv = tinfo->GetWidth(result);
00540       NS_RELEASE(tinfo);
00541     }
00542 
00543     return rv;
00544   }
00545   else {
00546     *result = 0;
00547     return NS_ERROR_FAILURE;
00548   }
00549 }
00550 
00551 NS_IMETHODIMP
00552 nsPluginInstancePeerImpl::GetHeight(PRUint32 *result)
00553 {
00554   if (nsnull != mOwner) {
00555     nsIPluginTagInfo2 *tinfo;
00556     nsresult          rv;
00557 
00558     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00559 
00560     if (NS_OK == rv) {
00561       rv = tinfo->GetHeight(result);
00562       NS_RELEASE(tinfo);
00563     }
00564 
00565     return rv;
00566   }
00567   else {
00568     *result = 0;
00569     return NS_ERROR_FAILURE;
00570   }
00571 }
00572 
00573 NS_IMETHODIMP
00574 nsPluginInstancePeerImpl::GetBorderVertSpace(PRUint32 *result)
00575 {
00576   if (nsnull != mOwner) {
00577     nsIPluginTagInfo2 *tinfo;
00578     nsresult          rv;
00579 
00580     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00581 
00582     if (NS_OK == rv) {
00583       rv = tinfo->GetBorderVertSpace(result);
00584       NS_RELEASE(tinfo);
00585     }
00586 
00587     return rv;
00588   }
00589   else {
00590     *result = 0;
00591     return NS_ERROR_FAILURE;
00592   }
00593 }
00594 
00595 NS_IMETHODIMP
00596 nsPluginInstancePeerImpl::GetBorderHorizSpace(PRUint32 *result)
00597 {
00598   if (nsnull != mOwner) {
00599     nsIPluginTagInfo2 *tinfo;
00600     nsresult          rv;
00601 
00602     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00603 
00604     if (NS_OK == rv) {
00605       rv = tinfo->GetBorderHorizSpace(result);
00606       NS_RELEASE(tinfo);
00607     }
00608 
00609     return rv;
00610   }
00611   else {
00612     *result = 0;
00613     return NS_ERROR_FAILURE;
00614   }
00615 }
00616 
00617 NS_IMETHODIMP
00618 nsPluginInstancePeerImpl::GetUniqueID(PRUint32 *result)
00619 {
00620   if (nsnull != mOwner) {
00621     nsIPluginTagInfo2 *tinfo;
00622     nsresult          rv;
00623 
00624     rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
00625 
00626     if (NS_OK == rv) {
00627       rv = tinfo->GetUniqueID(result);
00628       NS_RELEASE(tinfo);
00629     }
00630 
00631     return rv;
00632   }
00633   else {
00634     *result = 0;
00635     return NS_ERROR_FAILURE;
00636   }
00637 }
00638 
00639 NS_IMETHODIMP
00640 nsPluginInstancePeerImpl::GetCode(const char* *result)
00641 {
00642 #ifdef OJI
00643   if (nsnull != mOwner) {
00644     nsIJVMPluginTagInfo *tinfo;
00645     nsresult            rv;
00646 
00647     rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
00648 
00649     if (NS_OK == rv) {
00650       rv = tinfo->GetCode(result);
00651       NS_RELEASE(tinfo);
00652     }
00653 
00654     return rv;
00655   }
00656   else {
00657 #endif
00658     *result = 0;
00659     return NS_ERROR_FAILURE;
00660 #ifdef OJI
00661   }
00662 #endif
00663 }
00664 
00665 NS_IMETHODIMP
00666 nsPluginInstancePeerImpl::GetCodeBase(const char* *result)
00667 {
00668 #ifdef OJI
00669   if (nsnull != mOwner) {
00670     nsIJVMPluginTagInfo *tinfo;
00671     nsresult            rv;
00672 
00673     rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
00674 
00675     if (NS_OK == rv) {
00676       rv = tinfo->GetCodeBase(result);
00677       NS_RELEASE(tinfo);
00678     }
00679 
00680     return rv;
00681   }
00682   else {
00683 #endif
00684     *result = 0;
00685     return NS_ERROR_FAILURE;
00686 #ifdef OJI
00687   }
00688 #endif
00689 }
00690 
00691 NS_IMETHODIMP
00692 nsPluginInstancePeerImpl::GetArchive(const char* *result)
00693 {
00694 #ifdef OJI
00695   if (nsnull != mOwner) {
00696     nsIJVMPluginTagInfo *tinfo;
00697     nsresult            rv;
00698 
00699     rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
00700 
00701     if (NS_OK == rv) {
00702       rv = tinfo->GetArchive(result);
00703       NS_RELEASE(tinfo);
00704     }
00705 
00706     return rv;
00707   }
00708   else {
00709 #endif
00710     *result = 0;
00711     return NS_ERROR_FAILURE;
00712 #ifdef OJI
00713   }
00714 #endif
00715 }
00716 
00717 NS_IMETHODIMP
00718 nsPluginInstancePeerImpl::GetName(const char* *result)
00719 {
00720 #ifdef OJI
00721   if (nsnull != mOwner) {
00722     nsIJVMPluginTagInfo *tinfo;
00723     nsresult            rv;
00724 
00725     rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
00726 
00727     if (NS_OK == rv) {
00728       rv = tinfo->GetName(result);
00729       NS_RELEASE(tinfo);
00730     }
00731 
00732     return rv;
00733   }
00734   else {
00735 #endif
00736     *result = 0;
00737     return NS_ERROR_FAILURE;
00738 #ifdef OJI
00739   }
00740 #endif
00741 }
00742 
00743 NS_IMETHODIMP
00744 nsPluginInstancePeerImpl::GetMayScript(PRBool *result)
00745 {
00746 #ifdef OJI
00747   if (nsnull != mOwner) {
00748     nsIJVMPluginTagInfo *tinfo;
00749     nsresult            rv;
00750 
00751     rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
00752 
00753     if (NS_OK == rv) {
00754       rv = tinfo->GetMayScript(result);
00755       NS_RELEASE(tinfo);
00756     }
00757 
00758     return rv;
00759   }
00760   else {
00761 #endif
00762     *result = 0;
00763     return NS_ERROR_FAILURE;
00764 #ifdef OJI
00765   }
00766 #endif
00767 }
00768 
00769 NS_IMETHODIMP
00770 nsPluginInstancePeerImpl::SetWindowSize(PRUint32 width, PRUint32 height)
00771 {
00772   return NS_OK;
00773 }
00774 
00775 NS_IMETHODIMP
00776 nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow)
00777 {
00778   *outJSWindow = NULL;
00779   nsresult rv = NS_ERROR_FAILURE;
00780   nsCOMPtr<nsIDocument> document;   
00781 
00782   rv = mOwner->GetDocument(getter_AddRefs(document));
00783 
00784   if (NS_SUCCEEDED(rv) && document) {
00785     nsPIDOMWindow *win = document->GetWindow();
00786 
00787     nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(win);
00788     if(global) {
00789       *outJSWindow = global->GetGlobalJSObject();
00790     }
00791   } 
00792 
00793   return rv;
00794 }
00795 
00796 NS_IMETHODIMP
00797 nsPluginInstancePeerImpl::GetJSThread(PRUint32 *outThreadID)
00798 {
00799        *outThreadID = mThreadID;
00800        return NS_OK;
00801 }
00802 
00803 NS_IMETHODIMP
00804 nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext)
00805 {
00806   *outContext = NULL;
00807   nsresult rv = NS_ERROR_FAILURE;
00808   nsCOMPtr<nsIDocument> document;
00809 
00810   rv = mOwner->GetDocument(getter_AddRefs(document));
00811 
00812   if (NS_SUCCEEDED(rv) && document) {
00813     nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
00814 
00815     if (global) {
00816       nsIScriptContext *context = global->GetContext();
00817 
00818       if (context) {
00819         *outContext = (JSContext*) context->GetNativeContext();
00820       }
00821     }
00822   }
00823 
00824   return rv;
00825 }
00826 
00827 nsresult
00828 nsPluginInstancePeerImpl::Initialize(nsIPluginInstanceOwner *aOwner,
00829                                      const nsMIMEType aMIMEType)
00830 {
00831   mOwner = aOwner;
00832   NS_IF_ADDREF(mOwner);
00833 
00834   aOwner->GetInstance(mInstance);
00835   NS_IF_RELEASE(mInstance);
00836 
00837   if (nsnull != aMIMEType) {
00838     mMIMEType = (nsMIMEType)PR_Malloc(PL_strlen(aMIMEType) + 1);
00839 
00840     if (nsnull != mMIMEType)
00841       PL_strcpy((char *)mMIMEType, aMIMEType);
00842   }
00843   
00844   // record the thread we were created in.
00845   mThreadID = NS_PTR_TO_INT32(PR_GetCurrentThread());
00846 
00847   return NS_OK;
00848 }
00849 
00850 nsresult
00851 nsPluginInstancePeerImpl::SetOwner(nsIPluginInstanceOwner *aOwner)
00852 {
00853   // get rid of the previous owner
00854   NS_IF_RELEASE(mOwner);
00855 
00856   mOwner = aOwner;
00857   NS_IF_ADDREF(mOwner);
00858 
00859   aOwner->GetInstance(mInstance);
00860   NS_IF_RELEASE(mInstance);
00861   return NS_OK;
00862 }
00863 
00864 NS_IMETHODIMP
00865 nsPluginInstancePeerImpl::GetOwner(nsIPluginInstanceOwner **aOwner)
00866 {
00867   NS_ENSURE_ARG_POINTER(aOwner);
00868   *aOwner = mOwner;
00869   NS_IF_ADDREF(mOwner);
00870   return (mOwner) ? NS_OK : NS_ERROR_FAILURE;
00871 }
00872 
00873 NS_IMETHODIMP
00874 nsPluginInstancePeerImpl::InvalidateRect(nsPluginRect *invalidRect)
00875 {
00876   if(!mOwner)
00877     return NS_ERROR_FAILURE;
00878 
00879   return mOwner->InvalidateRect(invalidRect);
00880 }
00881 
00882 NS_IMETHODIMP
00883 nsPluginInstancePeerImpl::InvalidateRegion(nsPluginRegion invalidRegion)
00884 {
00885   if(!mOwner)
00886     return NS_ERROR_FAILURE;
00887 
00888   return mOwner->InvalidateRegion(invalidRegion);
00889 }
00890 
00891 NS_IMETHODIMP
00892 nsPluginInstancePeerImpl::ForceRedraw(void)
00893 {
00894   if(!mOwner)
00895     return NS_ERROR_FAILURE;
00896 
00897   return mOwner->ForceRedraw();
00898 }