Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / plugin / base / src / nsPluginInstancePeer.cpp
blobf698af273956d145516835160f041a0e88f4375b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Pierre Phaneuf <pp@ludusdesign.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nscore.h"
40 #include "nsPluginInstancePeer.h"
41 #include "nsIPluginInstance.h"
42 #include <stdio.h>
43 #include "prmem.h"
44 #include "prthread.h"
45 #include "plstr.h"
46 #include "prprf.h"
47 #include "nsIFile.h"
48 #include "nsCOMPtr.h"
49 #ifdef OJI
50 #include "nsIJVMManager.h"
51 #endif
52 #include "nsIServiceManager.h"
54 #include "nsIDocument.h"
55 #include "nsPIDOMWindow.h"
56 #include "nsIScriptGlobalObject.h"
57 #include "nsIScriptContext.h"
58 #include "nsIDirectoryService.h"
59 #include "nsDirectoryServiceDefs.h"
60 #include "nsIFileStreams.h"
61 #include "nsNetUtil.h"
63 #ifdef XP_WIN
64 #include <windows.h>
65 #include <winbase.h>
66 #endif
68 nsPluginInstancePeerImpl::nsPluginInstancePeerImpl()
70 mInstance = nsnull;
71 mOwner = nsnull;
72 mMIMEType = nsnull;
75 nsPluginInstancePeerImpl::~nsPluginInstancePeerImpl()
77 mInstance = nsnull;
78 NS_IF_RELEASE(mOwner);
80 if (nsnull != mMIMEType) {
81 PR_Free((void *)mMIMEType);
82 mMIMEType = nsnull;
86 static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
87 static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
88 #ifdef OJI
89 static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
91 NS_IMPL_ISUPPORTS7(nsPluginInstancePeerImpl,
92 nsIPluginInstancePeer,
93 nsIPluginInstancePeer2,
94 nsIWindowlessPluginInstancePeer,
95 nsIPluginTagInfo,
96 nsIPluginTagInfo2,
97 nsIJVMPluginTagInfo,
98 nsPIPluginInstancePeer)
99 #else
100 NS_IMPL_ISUPPORTS6(nsPluginInstancePeerImpl,
101 nsIPluginInstancePeer,
102 nsIPluginInstancePeer2,
103 nsIWindowlessPluginInstancePeer,
104 nsIPluginTagInfo,
105 nsIPluginTagInfo2,
106 nsPIPluginInstancePeer)
107 #endif
109 NS_IMETHODIMP
110 nsPluginInstancePeerImpl::GetValue(nsPluginInstancePeerVariable variable,
111 void *value)
113 if(!mOwner)
114 return NS_ERROR_FAILURE;
116 return mOwner->GetValue(variable, value);
119 NS_IMETHODIMP
120 nsPluginInstancePeerImpl::GetMIMEType(nsMIMEType *result)
122 if (nsnull == mMIMEType)
123 *result = "";
124 else
125 *result = mMIMEType;
127 return NS_OK;
130 NS_IMETHODIMP
131 nsPluginInstancePeerImpl::GetMode(nsPluginMode *result)
133 if (nsnull != mOwner)
134 return mOwner->GetMode(result);
135 else
136 return NS_ERROR_FAILURE;
139 // nsPluginStreamToFile
140 // --------------------
141 // Used to handle NPN_NewStream() - writes the stream as received by the plugin
142 // to a file and at completion (NPN_DestroyStream), tells the browser to load it into
143 // a plugin-specified target
145 static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
147 class nsPluginStreamToFile : public nsIOutputStream
149 public:
151 nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner);
152 virtual ~nsPluginStreamToFile();
154 NS_DECL_ISUPPORTS
155 NS_DECL_NSIOUTPUTSTREAM
157 protected:
158 char* mTarget;
159 nsCString mFileURL;
160 nsCOMPtr<nsILocalFile> mTempFile;
161 nsCOMPtr<nsIOutputStream> mOutputStream;
162 nsIPluginInstanceOwner* mOwner;
165 NS_IMPL_ADDREF(nsPluginStreamToFile)
166 NS_IMPL_RELEASE(nsPluginStreamToFile)
168 nsPluginStreamToFile::nsPluginStreamToFile(const char* target,
169 nsIPluginInstanceOwner* owner)
170 : mTarget(PL_strdup(target)),
171 mOwner(owner)
173 nsresult rv;
174 nsCOMPtr<nsIFile> pluginTmp;
175 rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp));
176 if (NS_FAILED(rv)) return;
178 mTempFile = do_QueryInterface(pluginTmp, &rv);
179 if (NS_FAILED(rv)) return;
181 // need to create a file with a unique name - use target as the basis
182 rv = mTempFile->AppendNative(nsDependentCString(target));
183 if (NS_FAILED(rv)) return;
185 // Yes, make it unique.
186 rv = mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0700);
187 if (NS_FAILED(rv)) return;
189 // create the file
190 rv = NS_NewLocalFileOutputStream(getter_AddRefs(mOutputStream), mTempFile, -1, 00600);
191 if (NS_FAILED(rv))
192 return;
194 mOutputStream->Close();
196 // construct the URL we'll use later in calls to GetURL()
197 NS_GetURLSpecFromFile(mTempFile, mFileURL);
199 #ifdef NS_DEBUG
200 printf("File URL = %s\n", mFileURL.get());
201 #endif
204 nsPluginStreamToFile::~nsPluginStreamToFile()
206 // should we be deleting mTempFile here?
207 if (nsnull != mTarget)
208 PL_strfree(mTarget);
211 nsresult
212 nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
213 void** aInstancePtrResult)
215 NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
217 if (nsnull == aInstancePtrResult)
218 return NS_ERROR_NULL_POINTER;
220 if (aIID.Equals(kIOutputStreamIID)) {
221 *aInstancePtrResult = (void *)((nsIOutputStream *)this);
222 AddRef();
223 return NS_OK;
226 return NS_NOINTERFACE;
229 NS_IMETHODIMP
230 nsPluginStreamToFile::Flush()
232 return NS_OK;
235 NS_IMETHODIMP
236 nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount,
237 PRUint32 *aWriteCount)
239 PRUint32 actualCount;
240 mOutputStream->Write(aBuf, aCount, &actualCount);
241 mOutputStream->Flush();
242 mOwner->GetURL(mFileURL.get(), mTarget, nsnull, 0, nsnull, 0);
244 return NS_OK;
247 NS_IMETHODIMP
248 nsPluginStreamToFile::WriteFrom(nsIInputStream *inStr, PRUint32 count,
249 PRUint32 *_retval)
251 NS_NOTREACHED("WriteFrom");
252 return NS_ERROR_NOT_IMPLEMENTED;
255 NS_IMETHODIMP
256 nsPluginStreamToFile::WriteSegments(nsReadSegmentFun reader, void * closure,
257 PRUint32 count, PRUint32 *_retval)
259 NS_NOTREACHED("WriteSegments");
260 return NS_ERROR_NOT_IMPLEMENTED;
263 NS_IMETHODIMP
264 nsPluginStreamToFile::IsNonBlocking(PRBool *aNonBlocking)
266 *aNonBlocking = PR_FALSE;
267 return NS_OK;
270 NS_IMETHODIMP
271 nsPluginStreamToFile::Close(void)
273 mOwner->GetURL(mFileURL.get(), mTarget, nsnull, 0, nsnull, 0);
274 return NS_OK;
277 // end of nsPluginStreamToFile
279 NS_IMETHODIMP
280 nsPluginInstancePeerImpl::NewStream(nsMIMEType type, const char* target,
281 nsIOutputStream* *result)
283 nsresult rv;
284 nsPluginStreamToFile* stream = new nsPluginStreamToFile(target, mOwner);
285 if(stream == nsnull)
286 return NS_ERROR_OUT_OF_MEMORY;
288 rv = stream->QueryInterface(kIOutputStreamIID, (void **)result);
290 return rv;
293 NS_IMETHODIMP
294 nsPluginInstancePeerImpl::ShowStatus(const char* message)
296 if (nsnull != mOwner)
297 return mOwner->ShowStatus(message);
298 else
299 return NS_ERROR_FAILURE;
302 NS_IMETHODIMP
303 nsPluginInstancePeerImpl::GetAttributes(PRUint16& n, const char*const*& names,
304 const char*const*& values)
306 if (nsnull != mOwner) {
307 nsIPluginTagInfo *tinfo;
308 nsresult rv;
310 rv = mOwner->QueryInterface(kIPluginTagInfoIID, (void **)&tinfo);
312 if (NS_OK == rv) {
313 rv = tinfo->GetAttributes(n, names, values);
314 NS_RELEASE(tinfo);
317 return rv;
319 else {
320 n = 0;
321 names = nsnull;
322 values = nsnull;
324 return NS_ERROR_FAILURE;
328 NS_IMETHODIMP
329 nsPluginInstancePeerImpl::GetAttribute(const char* name, const char* *result)
331 if (nsnull != mOwner) {
332 nsIPluginTagInfo *tinfo;
333 nsresult rv;
335 rv = mOwner->QueryInterface(kIPluginTagInfoIID, (void **)&tinfo);
337 if (NS_OK == rv) {
338 rv = tinfo->GetAttribute(name, result);
339 NS_RELEASE(tinfo);
342 return rv;
344 else {
345 *result = "";
346 return NS_ERROR_FAILURE;
350 NS_IMETHODIMP
351 nsPluginInstancePeerImpl::GetDOMElement(nsIDOMElement* *result)
353 if (mOwner == nsnull) {
354 *result = nsnull;
355 return NS_ERROR_FAILURE;
358 nsIPluginTagInfo2 *tinfo;
359 nsresult rv;
361 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
363 if (NS_OK == rv) {
364 rv = tinfo->GetDOMElement(result);
365 NS_RELEASE(tinfo);
368 return rv;
371 NS_IMETHODIMP
372 nsPluginInstancePeerImpl::GetTagType(nsPluginTagType *result)
374 if (nsnull != mOwner) {
375 nsIPluginTagInfo2 *tinfo;
376 nsresult rv;
378 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
380 if (NS_OK == rv) {
381 rv = tinfo->GetTagType(result);
382 NS_RELEASE(tinfo);
385 return rv;
387 else {
388 *result = nsPluginTagType_Unknown;
389 return NS_ERROR_FAILURE;
393 NS_IMETHODIMP
394 nsPluginInstancePeerImpl::GetTagText(const char* *result)
396 if (nsnull != mOwner) {
397 nsIPluginTagInfo2 *tinfo;
398 nsresult rv;
400 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
402 if (NS_OK == rv) {
403 rv = tinfo->GetTagText(result);
404 NS_RELEASE(tinfo);
407 return rv;
409 else {
410 *result = "";
411 return NS_ERROR_FAILURE;
415 NS_IMETHODIMP
416 nsPluginInstancePeerImpl::GetParameters(PRUint16& n, const char*const*& names,
417 const char*const*& values)
419 if (nsnull != mOwner) {
420 nsIPluginTagInfo2 *tinfo;
421 nsresult rv;
423 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
425 if (NS_OK == rv) {
426 rv = tinfo->GetParameters(n, names, values);
427 NS_RELEASE(tinfo);
430 return rv;
432 else {
433 n = 0;
434 names = nsnull;
435 values = nsnull;
437 return NS_ERROR_FAILURE;
441 NS_IMETHODIMP
442 nsPluginInstancePeerImpl::GetParameter(const char* name, const char* *result)
444 if (nsnull != mOwner) {
445 nsIPluginTagInfo2 *tinfo;
446 nsresult rv;
448 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
450 if (NS_OK == rv) {
451 rv = tinfo->GetParameter(name, result);
452 NS_RELEASE(tinfo);
455 return rv;
457 else {
458 *result = "";
459 return NS_ERROR_FAILURE;
463 NS_IMETHODIMP
464 nsPluginInstancePeerImpl::GetDocumentBase(const char* *result)
466 if (nsnull != mOwner) {
467 nsIPluginTagInfo2 *tinfo;
468 nsresult rv;
470 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
472 if (NS_OK == rv) {
473 rv = tinfo->GetDocumentBase(result);
474 NS_RELEASE(tinfo);
477 return rv;
479 else {
480 *result = "";
481 return NS_ERROR_FAILURE;
485 NS_IMETHODIMP
486 nsPluginInstancePeerImpl::GetDocumentEncoding(const char* *result)
488 if (nsnull != mOwner) {
489 nsIPluginTagInfo2 *tinfo;
490 nsresult rv;
492 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
494 if (NS_OK == rv) {
495 rv = tinfo->GetDocumentEncoding(result);
496 NS_RELEASE(tinfo);
499 return rv;
501 else {
502 *result = "";
503 return NS_ERROR_FAILURE;
507 NS_IMETHODIMP
508 nsPluginInstancePeerImpl::GetAlignment(const char* *result)
510 if (nsnull != mOwner) {
511 nsIPluginTagInfo2 *tinfo;
512 nsresult rv;
514 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
516 if (NS_OK == rv) {
517 rv = tinfo->GetAlignment(result);
518 NS_RELEASE(tinfo);
521 return rv;
523 else {
524 *result = "";
525 return NS_ERROR_FAILURE;
529 NS_IMETHODIMP
530 nsPluginInstancePeerImpl::GetWidth(PRUint32 *result)
532 if (nsnull != mOwner) {
533 nsIPluginTagInfo2 *tinfo;
534 nsresult rv;
536 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
538 if (NS_OK == rv) {
539 rv = tinfo->GetWidth(result);
540 NS_RELEASE(tinfo);
543 return rv;
545 else {
546 *result = 0;
547 return NS_ERROR_FAILURE;
551 NS_IMETHODIMP
552 nsPluginInstancePeerImpl::GetHeight(PRUint32 *result)
554 if (nsnull != mOwner) {
555 nsIPluginTagInfo2 *tinfo;
556 nsresult rv;
558 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
560 if (NS_OK == rv) {
561 rv = tinfo->GetHeight(result);
562 NS_RELEASE(tinfo);
565 return rv;
567 else {
568 *result = 0;
569 return NS_ERROR_FAILURE;
573 NS_IMETHODIMP
574 nsPluginInstancePeerImpl::GetBorderVertSpace(PRUint32 *result)
576 if (nsnull != mOwner) {
577 nsIPluginTagInfo2 *tinfo;
578 nsresult rv;
580 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
582 if (NS_OK == rv) {
583 rv = tinfo->GetBorderVertSpace(result);
584 NS_RELEASE(tinfo);
587 return rv;
589 else {
590 *result = 0;
591 return NS_ERROR_FAILURE;
595 NS_IMETHODIMP
596 nsPluginInstancePeerImpl::GetBorderHorizSpace(PRUint32 *result)
598 if (nsnull != mOwner) {
599 nsIPluginTagInfo2 *tinfo;
600 nsresult rv;
602 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
604 if (NS_OK == rv) {
605 rv = tinfo->GetBorderHorizSpace(result);
606 NS_RELEASE(tinfo);
609 return rv;
611 else {
612 *result = 0;
613 return NS_ERROR_FAILURE;
617 NS_IMETHODIMP
618 nsPluginInstancePeerImpl::GetUniqueID(PRUint32 *result)
620 if (nsnull != mOwner) {
621 nsIPluginTagInfo2 *tinfo;
622 nsresult rv;
624 rv = mOwner->QueryInterface(kIPluginTagInfo2IID, (void **)&tinfo);
626 if (NS_OK == rv) {
627 rv = tinfo->GetUniqueID(result);
628 NS_RELEASE(tinfo);
631 return rv;
633 else {
634 *result = 0;
635 return NS_ERROR_FAILURE;
639 NS_IMETHODIMP
640 nsPluginInstancePeerImpl::GetCode(const char* *result)
642 #ifdef OJI
643 if (nsnull != mOwner) {
644 nsIJVMPluginTagInfo *tinfo;
645 nsresult rv;
647 rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
649 if (NS_OK == rv) {
650 rv = tinfo->GetCode(result);
651 NS_RELEASE(tinfo);
654 return rv;
656 else {
657 #endif
658 *result = 0;
659 return NS_ERROR_FAILURE;
660 #ifdef OJI
662 #endif
665 NS_IMETHODIMP
666 nsPluginInstancePeerImpl::GetCodeBase(const char* *result)
668 #ifdef OJI
669 if (nsnull != mOwner) {
670 nsIJVMPluginTagInfo *tinfo;
671 nsresult rv;
673 rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
675 if (NS_OK == rv) {
676 rv = tinfo->GetCodeBase(result);
677 NS_RELEASE(tinfo);
680 return rv;
682 else {
683 #endif
684 *result = 0;
685 return NS_ERROR_FAILURE;
686 #ifdef OJI
688 #endif
691 NS_IMETHODIMP
692 nsPluginInstancePeerImpl::GetArchive(const char* *result)
694 #ifdef OJI
695 if (nsnull != mOwner) {
696 nsIJVMPluginTagInfo *tinfo;
697 nsresult rv;
699 rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
701 if (NS_OK == rv) {
702 rv = tinfo->GetArchive(result);
703 NS_RELEASE(tinfo);
706 return rv;
708 else {
709 #endif
710 *result = 0;
711 return NS_ERROR_FAILURE;
712 #ifdef OJI
714 #endif
717 NS_IMETHODIMP
718 nsPluginInstancePeerImpl::GetName(const char* *result)
720 #ifdef OJI
721 if (nsnull != mOwner) {
722 nsIJVMPluginTagInfo *tinfo;
723 nsresult rv;
725 rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
727 if (NS_OK == rv) {
728 rv = tinfo->GetName(result);
729 NS_RELEASE(tinfo);
732 return rv;
734 else {
735 #endif
736 *result = 0;
737 return NS_ERROR_FAILURE;
738 #ifdef OJI
740 #endif
743 NS_IMETHODIMP
744 nsPluginInstancePeerImpl::GetMayScript(PRBool *result)
746 #ifdef OJI
747 if (nsnull != mOwner) {
748 nsIJVMPluginTagInfo *tinfo;
749 nsresult rv;
751 rv = mOwner->QueryInterface(kIJVMPluginTagInfoIID, (void **)&tinfo);
753 if (NS_OK == rv) {
754 rv = tinfo->GetMayScript(result);
755 NS_RELEASE(tinfo);
758 return rv;
760 else {
761 #endif
762 *result = 0;
763 return NS_ERROR_FAILURE;
764 #ifdef OJI
766 #endif
769 NS_IMETHODIMP
770 nsPluginInstancePeerImpl::SetWindowSize(PRUint32 width, PRUint32 height)
772 return NS_OK;
775 NS_IMETHODIMP
776 nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow)
778 *outJSWindow = NULL;
779 nsresult rv = NS_ERROR_FAILURE;
780 nsCOMPtr<nsIDocument> document;
782 rv = mOwner->GetDocument(getter_AddRefs(document));
784 if (NS_SUCCEEDED(rv) && document) {
785 nsPIDOMWindow *win = document->GetWindow();
787 nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(win);
788 if(global) {
789 *outJSWindow = global->GetGlobalJSObject();
793 return rv;
796 NS_IMETHODIMP
797 nsPluginInstancePeerImpl::GetJSThread(PRUint32 *outThreadID)
799 *outThreadID = mThreadID;
800 return NS_OK;
803 NS_IMETHODIMP
804 nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext)
806 *outContext = NULL;
807 nsresult rv = NS_ERROR_FAILURE;
808 nsCOMPtr<nsIDocument> document;
810 rv = mOwner->GetDocument(getter_AddRefs(document));
812 if (NS_SUCCEEDED(rv) && document) {
813 nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
815 if (global) {
816 nsIScriptContext *context = global->GetContext();
818 if (context) {
819 *outContext = (JSContext*) context->GetNativeContext();
824 return rv;
827 nsresult
828 nsPluginInstancePeerImpl::Initialize(nsIPluginInstanceOwner *aOwner,
829 const nsMIMEType aMIMEType)
831 mOwner = aOwner;
832 NS_IF_ADDREF(mOwner);
834 aOwner->GetInstance(mInstance);
835 NS_IF_RELEASE(mInstance);
837 if (nsnull != aMIMEType) {
838 mMIMEType = (nsMIMEType)PR_Malloc(PL_strlen(aMIMEType) + 1);
840 if (nsnull != mMIMEType)
841 PL_strcpy((char *)mMIMEType, aMIMEType);
844 // record the thread we were created in.
845 mThreadID = NS_PTR_TO_INT32(PR_GetCurrentThread());
847 return NS_OK;
850 nsresult
851 nsPluginInstancePeerImpl::SetOwner(nsIPluginInstanceOwner *aOwner)
853 // get rid of the previous owner
854 NS_IF_RELEASE(mOwner);
856 mOwner = aOwner;
857 NS_IF_ADDREF(mOwner);
859 aOwner->GetInstance(mInstance);
860 NS_IF_RELEASE(mInstance);
861 return NS_OK;
864 NS_IMETHODIMP
865 nsPluginInstancePeerImpl::GetOwner(nsIPluginInstanceOwner **aOwner)
867 NS_ENSURE_ARG_POINTER(aOwner);
868 *aOwner = mOwner;
869 NS_IF_ADDREF(mOwner);
870 return (mOwner) ? NS_OK : NS_ERROR_FAILURE;
873 NS_IMETHODIMP
874 nsPluginInstancePeerImpl::InvalidateRect(nsPluginRect *invalidRect)
876 if(!mOwner)
877 return NS_ERROR_FAILURE;
879 return mOwner->InvalidateRect(invalidRect);
882 NS_IMETHODIMP
883 nsPluginInstancePeerImpl::InvalidateRegion(nsPluginRegion invalidRegion)
885 if(!mOwner)
886 return NS_ERROR_FAILURE;
888 return mOwner->InvalidateRegion(invalidRegion);
891 NS_IMETHODIMP
892 nsPluginInstancePeerImpl::ForceRedraw(void)
894 if(!mOwner)
895 return NS_ERROR_FAILURE;
897 return mOwner->ForceRedraw();