Back to index

lightning-sunbird  0.9+nobinonly
MRJPage.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1998
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /*
00038        MRJPage.cpp
00039        
00040        Encapsulates the new MRJ Page API, which loads applets into a common context.
00041        
00042        by Patrick C. Beard.
00043  */
00044 
00045 #include "MRJPage.h"
00046 #include "MRJSession.h"
00047 
00048 #include "StringUtils.h"
00049 
00050 MRJPage::MRJPage(MRJSession* session, UInt32 documentID, const char* codeBase, const char* archive, Boolean mayScript)
00051        :      mRefCount(0), mNextPage(NULL), mSession(session), mPageRef(NULL),
00052               mDocumentID(documentID), mCodeBase(strdup(codeBase)), mArchive(strdup(archive)), mMayScript(mayScript)
00053 {
00054        pushPage();
00055 
00056        if (&::JMNewAppletPage != NULL) {
00057               OSStatus status = ::JMNewAppletPage(&mPageRef, session->getSessionRef());
00058               if (status != noErr) mPageRef = NULL;
00059        }
00060 }
00061 
00062 MRJPage::MRJPage(MRJSession* session, const MRJPageAttributes& attributes)
00063        :      mRefCount(0), mNextPage(NULL), mSession(session), mPageRef(NULL),
00064               mDocumentID(attributes.documentID), mCodeBase(strdup(attributes.codeBase)),
00065               mArchive(strdup(attributes.archive)), mMayScript(attributes.mayScript)
00066 {
00067        pushPage();
00068 
00069        if (&::JMNewAppletPage != NULL) {
00070               OSStatus status = ::JMNewAppletPage(&mPageRef, session->getSessionRef());
00071               if (status != noErr) mPageRef = NULL;
00072        }
00073 }
00074 
00075 MRJPage::~MRJPage()
00076 {
00077        popPage();
00078        
00079        if (&::JMDisposeAppletPage != NULL && mPageRef != NULL) {
00080               OSStatus status = ::JMDisposeAppletPage(mPageRef);
00081               mPageRef = NULL;
00082        }
00083        
00084        if (mCodeBase != NULL) {
00085               delete[] mCodeBase;
00086               mCodeBase = NULL;
00087        }
00088        
00089        if (mArchive != NULL) {
00090               delete[] mArchive;
00091               mArchive = NULL;
00092        }
00093 }
00094 
00095 UInt16 MRJPage::AddRef()
00096 {
00097        return (++mRefCount);
00098 }
00099 
00100 UInt16 MRJPage::Release()
00101 {
00102        UInt16 result = --mRefCount;
00103        if (result == 0) {
00104               delete this;
00105        }
00106        return result;
00107 }
00108 
00109 Boolean MRJPage::createContext(JMAWTContextRef* outContext, const JMAWTContextCallbacks * callbacks, JMClientData data)
00110 {
00111        OSStatus status = noErr;
00112        if (&::JMNewAWTContextInPage != NULL && mPageRef != NULL) {
00113               status = ::JMNewAWTContextInPage(outContext, mSession->getSessionRef(), mPageRef, callbacks, data);
00114        } else {
00115               status = ::JMNewAWTContext(outContext, mSession->getSessionRef(), callbacks, data);
00116        }
00117        return (status == noErr);
00118 }
00119 
00120 static MRJPage* thePageList = NULL;
00121 
00122 MRJPage* MRJPage::getFirstPage()
00123 {
00124        return thePageList;
00125 }
00126 
00127 MRJPage* MRJPage::getNextPage()
00128 {
00129        return mNextPage;
00130 }
00131 
00132 void MRJPage::pushPage()
00133 {
00134        // put this on the global list of pages.
00135        mNextPage = thePageList;
00136        thePageList = this;
00137 }
00138 
00139 void MRJPage::popPage()
00140 {
00141        // Remove this page from the global list.
00142        MRJPage** link = &thePageList;
00143        MRJPage* page  = *link;
00144        while (page != NULL) {
00145               if (page == this) {
00146                      *link = mNextPage;
00147                      mNextPage = NULL;
00148                      break;
00149               }
00150               link = &page->mNextPage;
00151               page = *link;
00152        }
00153 }