Annotation of chimera/NSBrowserView.mm, revision 1.9

1.1       hyatt       1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
                      2: /* ***** BEGIN LICENSE BLOCK *****
                      3:  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
                      4:  *
                      5:  * The contents of this file are subject to the Netscape Public License
                      6:  * Version 1.1 (the "License"); you may not use this file except in
                      7:  * compliance with the License. You may obtain a copy of the License at
                      8:  * http://www.mozilla.org/NPL/
                      9:  *
                     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.
                     14:  *
                     15:  * The Original Code is mozilla.org code.
                     16:  *
                     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.
                     21:  *
                     22:  * Contributor(s):
                     23:  *
                     24:  * Alternatively, the contents of this file may be used under the terms of
                     25:  * either the GNU General Public License Version 2 or later (the "GPL"), or 
                     26:  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
                     27:  * in which case the provisions of the GPL or the LGPL are applicable instead
                     28:  * of those above. If you wish to allow use of your version of this file only
                     29:  * under the terms of either the GPL or the LGPL, and not to allow others to
                     30:  * use your version of this file under the terms of the NPL, indicate your
                     31:  * decision by deleting the provisions above and replace them with the notice
                     32:  * and other provisions required by the GPL or the LGPL. If you do not delete
                     33:  * the provisions above, a recipient may use your version of this file under
                     34:  * the terms of any one of the NPL, the GPL or the LGPL.
                     35:  *
                     36:  * ***** END LICENSE BLOCK ***** */
                     37: 
                     38: #import "NSBrowserView.h"
1.2       hyatt      39: #import "ProgressDlgController.h"
1.1       hyatt      40: #import "nsCocoaBrowserService.h"
                     41: 
                     42: // Embedding includes
                     43: #include "nsCWebBrowser.h"
                     44: #include "nsIInterfaceRequestor.h"
                     45: #include "nsIWebBrowserChrome.h"
                     46: #include "nsIEmbeddingSiteWindow.h"
                     47: #include "nsIWebProgressListener.h"
                     48: #include "nsIWebBrowser.h"
                     49: #include "nsIWebNavigation.h"
                     50: #include "nsIURI.h"
                     51: #include "nsIDOMWindow.h"
                     52: #include "nsWeakReference.h"
                     53: 
                     54: // XPCOM and String includes
                     55: #include "nsCRT.h"
                     56: #include "nsXPIDLString.h"
                     57: #include "nsCOMPtr.h"
                     58: 
1.8       hyatt      59: // Printing
                     60: #include "nsIWebBrowserPrint.h"
                     61: #include "nsIPrintSettings.h"
                     62: 
                     63: // Saving of links/images/docs
1.2       hyatt      64: #include "nsIWebBrowserFocus.h"
                     65: #include "nsIDOMHTMLDocument.h"
                     66: #include "nsIDocument.h"
                     67: #include "nsIURL.h"
                     68: #include "nsIWebBrowserPersist.h"
                     69: #include "nsIProperties.h"
                     70: #include "nsIRequest.h"
                     71: #include "nsIChannel.h"
                     72: #include "nsIHttpChannel.h"
                     73: #include "nsIPref.h"
                     74: #include "nsIMIMEService.h"
                     75: #include "nsIMIMEInfo.h"
                     76: #include "nsISHistory.h"
1.3       hyatt      77: #include "nsIHistoryEntry.h"
                     78: #include "nsISHEntry.h"
1.1       hyatt      79: 
1.4       hyatt      80: const char* persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1";
                     81: const char* dirServiceContractID = "@mozilla.org/file/directory_service;1";
                     82: 
1.1       hyatt      83: class nsCocoaBrowserListener : public nsSupportsWeakReference,
                     84:                                public nsIInterfaceRequestor,
                     85:             public nsIWebBrowserChrome,
                     86:             public nsIEmbeddingSiteWindow,
                     87:                                public nsIWebProgressListener
                     88: {
                     89: public:
                     90:   nsCocoaBrowserListener(NSBrowserView* aView);
                     91:   virtual ~nsCocoaBrowserListener();
                     92: 
                     93:   NS_DECL_ISUPPORTS
                     94:   NS_DECL_NSIINTERFACEREQUESTOR
                     95:   NS_DECL_NSIWEBBROWSERCHROME
                     96:   NS_DECL_NSIEMBEDDINGSITEWINDOW
                     97:   NS_DECL_NSIWEBPROGRESSLISTENER
                     98: 
                     99:   void AddListener(id <NSBrowserListener> aListener);
                    100:   void RemoveListener(id <NSBrowserListener> aListener);
                    101:   void SetContainer(id <NSBrowserContainer> aContainer);
                    102: 
                    103: private:
                    104:   NSBrowserView* mView;     // WEAK - it owns us
                    105:   NSMutableArray* mListeners;
                    106:   id <NSBrowserContainer> mContainer;
                    107:   PRBool mIsModal;
                    108:   PRUint32 mChromeFlags;
                    109: };
                    110: 
                    111: nsCocoaBrowserListener::nsCocoaBrowserListener(NSBrowserView* aView)
                    112:   : mView(aView), mContainer(nsnull), mIsModal(PR_FALSE), mChromeFlags(0)
                    113: {
                    114:   NS_INIT_ISUPPORTS();
                    115:   mListeners = [[NSMutableArray alloc] init];
                    116: }
                    117: 
                    118: nsCocoaBrowserListener::~nsCocoaBrowserListener()
                    119: {
                    120:   [mListeners release];
                    121:   mView = nsnull;
                    122:   if (mContainer) {
                    123:     [mContainer release];
                    124:   }
                    125: }
                    126: 
                    127: NS_IMPL_ISUPPORTS5(nsCocoaBrowserListener,
                    128:       nsIInterfaceRequestor,
                    129:       nsIWebBrowserChrome,
                    130:       nsIEmbeddingSiteWindow,
                    131:       nsIWebProgressListener,
                    132:             nsISupportsWeakReference)
                    133: 
                    134: // Implementation of nsIInterfaceRequestor
                    135: NS_IMETHODIMP 
                    136: nsCocoaBrowserListener::GetInterface(const nsIID &aIID, void** aInstancePtr)
                    137: {
                    138:   if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) {
                    139:     nsCOMPtr<nsIWebBrowser> browser = dont_AddRef([mView getWebBrowser]);
                    140:     if (browser)
                    141:       return browser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
                    142:   }
                    143:   
                    144:   return QueryInterface(aIID, aInstancePtr);
                    145: }
                    146: 
                    147: // Implementation of nsIWebBrowserChrome
                    148: /* void setStatus (in unsigned long statusType, in wstring status); */
                    149: NS_IMETHODIMP 
                    150: nsCocoaBrowserListener::SetStatus(PRUint32 statusType, const PRUnichar *status)
                    151: {
                    152:   if (!mContainer) {
                    153:     return NS_ERROR_FAILURE;
                    154:   }
                    155: 
                    156:   NSString* str = nsnull;
                    157:   if (status && (*status != PRUnichar(0))) {
                    158:     str = [NSString stringWithCharacters:status length:nsCRT::strlen(status)];
                    159:   }
                    160: 
                    161:   [mContainer setStatus:str ofType:(NSStatusType)statusType];
                    162: 
                    163:   return NS_OK;
                    164: }
                    165: 
                    166: /* attribute nsIWebBrowser webBrowser; */
                    167: NS_IMETHODIMP 
                    168: nsCocoaBrowserListener::GetWebBrowser(nsIWebBrowser * *aWebBrowser)
                    169: {
                    170:   NS_ENSURE_ARG_POINTER(aWebBrowser);
                    171:   if (!mView) {
                    172:     return NS_ERROR_FAILURE;
                    173:   }
                    174:   *aWebBrowser = [mView getWebBrowser];
                    175: 
                    176:   return NS_OK;
                    177: }
                    178: NS_IMETHODIMP 
                    179: nsCocoaBrowserListener::SetWebBrowser(nsIWebBrowser * aWebBrowser)
                    180: {
                    181:   if (!mView) {
                    182:     return NS_ERROR_FAILURE;
                    183:   }
                    184: 
                    185:   [mView setWebBrowser:aWebBrowser];
                    186: 
                    187:   return NS_OK;
                    188: }
                    189: 
                    190: /* attribute unsigned long chromeFlags; */
                    191: NS_IMETHODIMP 
                    192: nsCocoaBrowserListener::GetChromeFlags(PRUint32 *aChromeFlags)
                    193: {
                    194:   NS_ENSURE_ARG_POINTER(aChromeFlags);
                    195:   *aChromeFlags = mChromeFlags;
                    196:   return NS_OK;
                    197: }
                    198: NS_IMETHODIMP 
                    199: nsCocoaBrowserListener::SetChromeFlags(PRUint32 aChromeFlags)
                    200: {
                    201:   // XXX Do nothing with them for now
                    202:   mChromeFlags = aChromeFlags;
                    203:   return NS_OK;
                    204: }
                    205: 
                    206: /* void destroyBrowserWindow (); */
                    207: NS_IMETHODIMP 
                    208: nsCocoaBrowserListener::DestroyBrowserWindow()
                    209: {
                    210:   // XXX Could send this up to the container, but for now,
                    211:   // we just destroy the enclosing window.
                    212:   NSWindow* window = [mView window];
                    213: 
                    214:   if (window) {
                    215:     [window close];
                    216:   }
                    217: 
                    218:   return NS_OK;
                    219: }
                    220: 
                    221: /* void sizeBrowserTo (in long aCX, in long aCY); */
                    222: NS_IMETHODIMP 
                    223: nsCocoaBrowserListener::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
                    224: {
                    225:   if (mContainer) {
                    226:     NSSize size;
                    227:     
                    228:     size.width = (float)aCX;
                    229:     size.height = (float)aCY;
                    230: 
                    231:     [mContainer sizeBrowserTo:size];
                    232:   }
                    233:   
                    234:   return NS_OK;
                    235: }
                    236: 
                    237: /* void showAsModal (); */
                    238: NS_IMETHODIMP 
                    239: nsCocoaBrowserListener::ShowAsModal()
                    240: {
                    241:   if (!mView) {
                    242:     return NS_ERROR_FAILURE;
                    243:   }
                    244: 
                    245:   NSWindow* window = [mView window];
                    246: 
                    247:   if (!window) {
                    248:     return NS_ERROR_FAILURE;
                    249:   }
                    250: 
                    251:   mIsModal = PR_TRUE;
                    252:   int result = [NSApp runModalForWindow:window];
                    253:   mIsModal = PR_FALSE;
                    254: 
                    255:   return (nsresult)result;
                    256: }
                    257: 
                    258: /* boolean isWindowModal (); */
                    259: NS_IMETHODIMP 
                    260: nsCocoaBrowserListener::IsWindowModal(PRBool *_retval)
                    261: {
                    262:   NS_ENSURE_ARG_POINTER(_retval);
                    263: 
                    264:   *_retval = mIsModal;
                    265: 
                    266:   return NS_OK;
                    267: }
                    268: 
                    269: /* void exitModalEventLoop (in nsresult aStatus); */
                    270: NS_IMETHODIMP 
                    271: nsCocoaBrowserListener::ExitModalEventLoop(nsresult aStatus)
                    272: {
                    273:   [NSApp stopModalWithCode:(int)aStatus];
                    274: 
                    275:   return NS_OK;
                    276: }
                    277: 
                    278: // Implementation of nsIEmbeddingSiteWindow
                    279: /* void setDimensions (in unsigned long flags, in long x, in long y, in long cx, in long cy); */
                    280: NS_IMETHODIMP 
                    281: nsCocoaBrowserListener::SetDimensions(PRUint32 flags, 
                    282:              PRInt32 x, 
                    283:              PRInt32 y, 
                    284:              PRInt32 cx, 
                    285:              PRInt32 cy)
                    286: {
                    287:   if (!mView) {
                    288:     return NS_ERROR_FAILURE;
                    289:   }
                    290: 
                    291:   NSWindow* window = [mView window];
                    292:   if (!window) {
                    293:     return NS_ERROR_FAILURE;
                    294:   }
                    295: 
                    296:   if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
                    297:     NSPoint origin;
                    298:     origin.x = (float)x;
                    299:     origin.y = (float)y;
                    300:     [window setFrameOrigin:origin];
                    301:   }
                    302: 
                    303:   if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) {
                    304:     NSRect frame = [window frame];
                    305:     frame.size.width = (float)cx;
                    306:     frame.size.height = (float)cy;
                    307:     [window setFrame:frame display:YES];
                    308:   }
                    309:   else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) {
                    310:     NSSize size;
                    311:     size.width = (float)cx;
                    312:     size.height = (float)cy;
                    313:     [window setContentSize:size];
                    314:   }
                    315: 
                    316:   return NS_OK;
                    317: }
                    318: 
                    319: /* void getDimensions (in unsigned long flags, out long x, out long y, out long cx, out long cy); */
                    320: NS_IMETHODIMP 
                    321: nsCocoaBrowserListener::GetDimensions(PRUint32 flags, 
                    322:              PRInt32 *x, 
                    323:              PRInt32 *y, 
                    324:              PRInt32 *cx, 
                    325:              PRInt32 *cy)
                    326: {
                    327:   NS_ENSURE_ARG_POINTER(x);
                    328:   NS_ENSURE_ARG_POINTER(y);
                    329:   NS_ENSURE_ARG_POINTER(cx);
                    330:   NS_ENSURE_ARG_POINTER(cy);
                    331: 
                    332:   if (!mView) {
                    333:     return NS_ERROR_FAILURE;
                    334:   }
                    335: 
                    336:   NSWindow* window = [mView window];
                    337:   if (!window) {
                    338:     return NS_ERROR_FAILURE;
                    339:   }
                    340: 
                    341:   NSRect frame = [window frame];
                    342:   if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
                    343:     *x = (PRInt32)frame.origin.x;
                    344:     *y = (PRInt32)frame.origin.y;
                    345:   }
                    346:   if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) {
                    347:     *cx = (PRInt32)frame.size.width;
                    348:     *cy = (PRInt32)frame.size.height;
                    349:   }
                    350:   else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) {
                    351:     NSView* contentView = [window contentView];
                    352:     NSRect contentFrame = [contentView frame];
                    353:     *cx = (PRInt32)contentFrame.size.width;
                    354:     *cy = (PRInt32)contentFrame.size.height;    
                    355:   }
                    356: 
                    357:   return NS_OK;
                    358: }
                    359: 
                    360: /* void setFocus (); */
                    361: NS_IMETHODIMP 
                    362: nsCocoaBrowserListener::SetFocus()
                    363: {
                    364:   if (!mView) {
                    365:     return NS_ERROR_FAILURE;
                    366:   }
                    367: 
                    368:   NSWindow* window = [mView window];
                    369:   if (!window) {
                    370:     return NS_ERROR_FAILURE;
                    371:   }
                    372: 
                    373:   [window makeKeyAndOrderFront:window];
                    374: 
                    375:   return NS_OK;
                    376: }
                    377: 
                    378: /* attribute boolean visibility; */
                    379: NS_IMETHODIMP 
                    380: nsCocoaBrowserListener::GetVisibility(PRBool *aVisibility)
                    381: {
                    382:   NS_ENSURE_ARG_POINTER(aVisibility);
                    383: 
                    384:   if (!mView) {
                    385:     return NS_ERROR_FAILURE;
                    386:   }
                    387: 
                    388:   NSWindow* window = [mView window];
                    389:   if (!window) {
                    390:     return NS_ERROR_FAILURE;
                    391:   }
                    392: 
                    393:   *aVisibility = [window isMiniaturized];
                    394: 
                    395:   return NS_OK;
                    396: }
                    397: NS_IMETHODIMP 
                    398: nsCocoaBrowserListener::SetVisibility(PRBool aVisibility)
                    399: {
                    400:   if (!mView) {
                    401:     return NS_ERROR_FAILURE;
                    402:   }
                    403: 
                    404:   NSWindow* window = [mView window];
                    405:   if (!window) {
                    406:     return NS_ERROR_FAILURE;
                    407:   }
                    408: 
                    409:   if (aVisibility) {
                    410:     [window deminiaturize:window];
                    411:   }
                    412:   else {
                    413:     [window miniaturize:window];
                    414:   }
                    415: 
                    416:   return NS_OK;
                    417: }
                    418: 
                    419: /* attribute wstring title; */
                    420: NS_IMETHODIMP 
                    421: nsCocoaBrowserListener::GetTitle(PRUnichar * *aTitle)
                    422: {
                    423:   NS_ENSURE_ARG_POINTER(aTitle);
                    424: 
                    425:   if (!mContainer) {
                    426:     return NS_ERROR_FAILURE;
                    427:   }
                    428: 
                    429:   NSString* title = [mContainer title];
                    430:   unsigned int length = [title length];
                    431:   if (length) {
                    432:     *aTitle = (PRUnichar*)nsMemory::Alloc((length+1)*sizeof(PRUnichar));
                    433:     if (!*aTitle) {
                    434:       return NS_ERROR_OUT_OF_MEMORY;
                    435:     }
                    436:     [title getCharacters:*aTitle];
                    437:   }
                    438:   else {
                    439:     *aTitle = nsnull;
                    440:   }
                    441:   
                    442:   return NS_OK;
                    443: }
                    444: NS_IMETHODIMP 
                    445: nsCocoaBrowserListener::SetTitle(const PRUnichar * aTitle)
                    446: {
                    447:   NS_ENSURE_ARG(aTitle);
                    448: 
                    449:   if (!mContainer) {
                    450:     return NS_ERROR_FAILURE;
                    451:   }
                    452: 
                    453:   NSString* str = [NSString stringWithCharacters:aTitle length:nsCRT::strlen(aTitle)];
                    454:   [mContainer setTitle:str];
                    455: 
                    456:   return NS_OK;
                    457: }
                    458: 
                    459: /* [noscript] readonly attribute voidPtr siteWindow; */
                    460: NS_IMETHODIMP 
                    461: nsCocoaBrowserListener::GetSiteWindow(void * *aSiteWindow)
                    462: {
                    463:   NS_ENSURE_ARG_POINTER(aSiteWindow);
                    464: 
                    465:   if (!mView) {
                    466:     return NS_ERROR_FAILURE;
                    467:   }
                    468: 
                    469:   NSWindow* window = [mView window];
                    470:   if (!window) {
                    471:     return NS_ERROR_FAILURE;
                    472:   }
                    473: 
                    474:   *aSiteWindow = (void*)window;
                    475: 
                    476:   return NS_OK;
                    477: }
                    478: 
                    479: // Implementation of nsIWebProgressListener
                    480: /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
                    481: NS_IMETHODIMP 
                    482: nsCocoaBrowserListener::OnStateChange(nsIWebProgress *aWebProgress, 
                    483:              nsIRequest *aRequest, 
                    484:              PRInt32 aStateFlags, 
                    485:              PRUint32 aStatus)
                    486: {
                    487:   NSEnumerator* enumerator = [mListeners objectEnumerator];
                    488:   id obj;
                    489:   
                    490:   if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) {
                    491:     if (aStateFlags & nsIWebProgressListener::STATE_START) {
                    492:       while ((obj = [enumerator nextObject])) {
                    493:  [obj onLoadingStarted];
                    494:       }
                    495:     }
                    496:     else if (aStateFlags & nsIWebProgressListener::STATE_STOP) {
                    497:       while ((obj = [enumerator nextObject])) {
                    498:  [obj onLoadingCompleted:(NS_SUCCEEDED(aStatus))];
                    499:       }
                    500:     }
                    501:   }
                    502: 
                    503: 
                    504:   return NS_OK;
                    505: }
                    506: 
                    507: /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
                    508: NS_IMETHODIMP 
                    509: nsCocoaBrowserListener::OnProgressChange(nsIWebProgress *aWebProgress, 
                    510:           nsIRequest *aRequest, 
                    511:           PRInt32 aCurSelfProgress, 
                    512:           PRInt32 aMaxSelfProgress, 
                    513:           PRInt32 aCurTotalProgress, 
                    514:           PRInt32 aMaxTotalProgress)
                    515: {
                    516:   NSEnumerator* enumerator = [mListeners objectEnumerator];
                    517:   id obj;
                    518:  
                    519:   while ((obj = [enumerator nextObject])) {
                    520:     [obj onProgressChange:aCurTotalProgress outOf:aMaxTotalProgress];
                    521:   }
                    522:   
                    523:   return NS_OK;
                    524: }
                    525: 
                    526: /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
                    527: NS_IMETHODIMP 
                    528: nsCocoaBrowserListener::OnLocationChange(nsIWebProgress *aWebProgress, 
                    529:           nsIRequest *aRequest, 
                    530:           nsIURI *location)
                    531: {
                    532:   nsXPIDLCString spec;
                    533:   
                    534:   location->GetSpec(getter_Copies(spec));
                    535:   if (!spec) {
                    536:     return NS_ERROR_FAILURE;
                    537:   }
                    538: 
                    539:   const char* cstr = spec.get();
                    540:   NSString* str = [NSString stringWithCString:cstr];
                    541:   NSURL* url = [NSURL URLWithString:str];
                    542: 
                    543:   NSEnumerator* enumerator = [mListeners objectEnumerator];
                    544:   id obj;
                    545:  
                    546:   while ((obj = [enumerator nextObject])) {
                    547:     [obj onLocationChange:url];
                    548:   }
                    549: 
                    550:   return NS_OK;
                    551: }
                    552: 
                    553: /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
                    554: NS_IMETHODIMP 
                    555: nsCocoaBrowserListener::OnStatusChange(nsIWebProgress *aWebProgress, 
                    556:               nsIRequest *aRequest, 
                    557:               nsresult aStatus, 
                    558:               const PRUnichar *aMessage)
                    559: {
                    560:   return NS_OK;
                    561: }
                    562: 
                    563: /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
                    564: NS_IMETHODIMP 
                    565: nsCocoaBrowserListener::OnSecurityChange(nsIWebProgress *aWebProgress, 
                    566:           nsIRequest *aRequest, 
                    567:           PRInt32 state)
                    568: {
                    569:   return NS_OK;
                    570: }
                    571: 
                    572: void 
                    573: nsCocoaBrowserListener::AddListener(id <NSBrowserListener> aListener)
                    574: {
                    575:   [mListeners addObject:aListener];
                    576: }
                    577: 
                    578: void 
                    579: nsCocoaBrowserListener::RemoveListener(id <NSBrowserListener> aListener)
                    580: {
                    581:   [mListeners removeObject:aListener];
                    582: }
                    583: 
                    584: void 
                    585: nsCocoaBrowserListener::SetContainer(id <NSBrowserContainer> aContainer)
                    586: {
                    587:   [mContainer autorelease];
                    588: 
                    589:   mContainer = aContainer;
                    590: 
                    591:   [mContainer retain];
                    592: }
                    593: 
1.2       hyatt     594: // Implementation of a header sniffer class that is used when saving Web pages and images.
                    595: class nsHeaderSniffer :  public nsIWebProgressListener
                    596: {
                    597: public:
                    598:     nsHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL,
1.3       hyatt     599:                     nsIDOMDocument* aDocument, nsIInputStream* aPostData, PRBool aBypassCache,
1.2       hyatt     600:                     NSView* aFilterView, NSPopUpButton* aFilterList)
                    601:     {
                    602:         NS_INIT_REFCNT();
                    603:         mPersist = aPersist;
                    604:         mTmpFile = aFile;
                    605:         mURL = aURL;
                    606:         mDocument = aDocument;
1.3       hyatt     607:         mPostData = aPostData;
1.2       hyatt     608:         mBypassCache = aBypassCache;
                    609:         mFilterView = aFilterView;
                    610:         mFilterList = aFilterList;
                    611:     }
                    612:                   
1.4       hyatt     613:     virtual ~nsHeaderSniffer() 
                    614:     {
                    615:     };
1.2       hyatt     616: 
                    617:     NS_DECL_ISUPPORTS
                    618:     NS_DECL_NSIWEBPROGRESSLISTENER
                    619:   
                    620: protected:
                    621:     void PerformSave();
                    622:     
                    623: private:
                    624:     nsIWebBrowserPersist* mPersist; // Weak. It owns us as a listener.
                    625:     nsCOMPtr<nsIFile> mTmpFile;
                    626:     nsCOMPtr<nsIURI> mURL;
                    627:     nsCOMPtr<nsIDOMDocument> mDocument;
1.3       hyatt     628:     nsCOMPtr<nsIInputStream> mPostData;
1.2       hyatt     629:     PRBool mBypassCache;
                    630:     nsCString mContentType;
                    631:     nsCString mContentDisposition;
                    632:     NSView* mFilterView;
                    633:     NSPopUpButton* mFilterList;
                    634: };
                    635: 
                    636: NS_IMPL_ISUPPORTS1(nsHeaderSniffer, nsIWebProgressListener)
                    637: 
                    638: // Implementation of nsIWebProgressListener
                    639: /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
                    640: NS_IMETHODIMP 
                    641: nsHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, 
                    642:              nsIRequest *aRequest, 
                    643:              PRInt32 aStateFlags, 
                    644:              PRUint32 aStatus)
                    645: {
                    646:     if (aStateFlags & nsIWebProgressListener::STATE_START) {
                    647:         nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
                    648:         nsXPIDLCString contentType;
                    649:         channel->GetContentType(getter_Copies(contentType));
                    650:         mContentType = contentType;
                    651:         
                    652:         // Get the content-disposition if we're an HTTP channel.
                    653:         nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
                    654:         if (httpChannel) {
                    655:             nsXPIDLCString disp;
                    656:             httpChannel->GetResponseHeader("content-disposition", getter_Copies(disp));
                    657:             mContentDisposition = disp;
                    658:         }
                    659:         
                    660:         mPersist->CancelSave();
                    661:         PRBool exists;
                    662:         mTmpFile->Exists(&exists);
                    663:         if (exists)
                    664:             mTmpFile->Remove(PR_FALSE);
                    665:         PerformSave();
                    666:     }
                    667:     return NS_OK;
                    668: }
                    669: 
                    670: void nsHeaderSniffer::PerformSave()
                    671: {
                    672:     // Are we an HTML document? If so, we will want to append an accessory view to
                    673:     // the save dialog to provide the user with the option of doing a complete
                    674:     // save vs. a single file save.
                    675:     PRBool isHTML = (mDocument && mContentType.Equals("text/html") ||
                    676:                      mContentType.Equals("text/xml") ||
                    677:                      mContentType.Equals("application/xhtml+xml"));
                    678:     
                    679:     // Next find out the directory that we should start in.
                    680:     nsCOMPtr<nsIPrefService> prefs(do_GetService("@mozilla.org/preferences-service;1"));
                    681:     if (!prefs)
                    682:         return;
                    683:     nsCOMPtr<nsIPrefBranch> dirBranch;
                    684:     prefs->GetBranch("browser.download.", getter_AddRefs(dirBranch));
                    685:     PRInt32 filterIndex = 0;
                    686:     if (dirBranch) {
                    687:         nsresult rv = dirBranch->GetIntPref("save_converter_index", &filterIndex);
                    688:         if (NS_FAILED(rv))
                    689:             filterIndex = 0;
                    690:     }
                    691:     if (mFilterList)
                    692:         [mFilterList selectItemAtIndex: filterIndex];
                    693:         
                    694:     // We need to figure out what file name to use.
                    695:     nsCAutoString defaultFileName;
                    696:     
                    697:     if (!mContentDisposition.IsEmpty()) {
                    698:         // (1) Use the HTTP header suggestion.
                    699:         PRInt32 index = mContentDisposition.Find("filename=");
                    700:         if (index >= 0) {
                    701:             // Take the substring following the prefix.
                    702:             index += 9;
                    703:             nsCAutoString filename;
                    704:             mContentDisposition.Right(filename, mContentDisposition.Length() - index);
                    705:             defaultFileName = filename;
                    706:         }
                    707:     }
                    708:     
                    709:     if (defaultFileName.IsEmpty()) {
                    710:         nsCOMPtr<nsIURL> url(do_QueryInterface(mURL));
                    711:         if (url) {
                    712:             nsXPIDLCString fileName;
                    713:             url->GetFileName(getter_Copies(fileName));
                    714:             defaultFileName = fileName; // (2) For file URLs, use the file name.
                    715:         }
                    716:     }
                    717:     
                    718:     if (defaultFileName.IsEmpty() && mDocument && isHTML) {
                    719:         nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(mDocument));
                    720:         nsAutoString title;
                    721:         if (htmlDoc)
                    722:             htmlDoc->GetTitle(title); // (3) Use the title of the document.
                    723:         defaultFileName.AssignWithConversion(title);
                    724:     }
                    725:     
                    726:     if (defaultFileName.IsEmpty()) {
                    727:         // (4) Use the caller provided name. XXXdwh
                    728:     }
                    729: 
                    730:     if (defaultFileName.IsEmpty()) {
                    731:         // (5) Use the host.
                    732:         nsXPIDLCString host;
                    733:         mURL->GetHost(getter_Copies(host));
                    734:         defaultFileName = host;
                    735:     }
                    736:     
                    737:     // One last case to handle about:blank and other fruity untitled pages.
                    738:     if (defaultFileName.IsEmpty())
                    739:         defaultFileName = "untitled";
                    740:         
                    741:     // Validate the file name to ensure legality.
                    742:     for (PRUint32 i = 0; i < defaultFileName.Length(); i++)
                    743:         if (defaultFileName[i] == ':' || defaultFileName[i] == '/')
                    744:             defaultFileName.SetCharAt(i, ' ');
                    745:             
                    746:     // Make sure the appropriate extension is appended to the suggested file name.
                    747:     nsCOMPtr<nsIURI> fileURI(do_CreateInstance("@mozilla.org/network/standard-url;1"));
                    748:     nsCOMPtr<nsIURL> fileURL(do_QueryInterface(fileURI));
                    749:     if (!fileURL)
                    750:         return;
                    751:     fileURL->SetFilePath(defaultFileName.get());
                    752:     
                    753:     nsXPIDLCString fileEx;
                    754:     fileURL->GetFileExtension(getter_Copies(fileEx));
                    755:     nsDependentCString fileExtension(fileEx.get());
                    756:     
                    757:     PRBool setExtension = PR_FALSE;
                    758:     if (mContentType.Equals("text/html")) {
                    759:         if (fileExtension.IsEmpty() || (!fileExtension.Equals("htm") && !fileExtension.Equals("html"))) {
                    760:             defaultFileName += ".html";
                    761:             setExtension = PR_TRUE;
                    762:         }
                    763:     }
                    764:     
                    765:     if (!setExtension && fileExtension.IsEmpty()) {
                    766:         nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1"));
                    767:         if (!mimeService)
                    768:             return;
                    769:         nsCOMPtr<nsIMIMEInfo> mimeInfo;
                    770:         mimeService->GetFromMIMEType(mContentType.get(), getter_AddRefs(mimeInfo));
                    771:         
                    772:         PRUint32 extCount;
                    773:         char** extList;
                    774:         mimeInfo->GetFileExtensions(&extCount, &extList);
                    775:         
                    776:         if (extCount > 0) {
                    777:             defaultFileName += ".";
                    778:             defaultFileName += extList[0];
                    779:         }
                    780:     }
                    781:     
                    782:     // Now it's time to pose the save dialog.
                    783:     NSSavePanel* savePanel = [NSSavePanel savePanel];
                    784:     NSString* file = nil;
                    785:     if (!defaultFileName.IsEmpty())
                    786:         file = [[NSString alloc] initWithCString: defaultFileName.get()];
                    787:         
                    788:     if (isHTML)
                    789:         [savePanel setAccessoryView: mFilterView];
                    790:         
                    791:     if ([savePanel runModalForDirectory: nil file: file] == NSFileHandlingPanelCancelButton)
                    792:         return;
                    793:        
                    794:     // Release the file string.
                    795:     [file release];
                    796:     
                    797:     // Update the filter index.
                    798:     if (isHTML && mFilterList) {
                    799:         filterIndex = [mFilterList indexOfSelectedItem];
                    800:         dirBranch->SetIntPref("save_converter_index", filterIndex);
                    801:     }
                    802:     
                    803:     // Convert the content type to text/plain if it was selected in the filter.
                    804:     if (isHTML && filterIndex == 2)
                    805:         mContentType = "text/plain";
                    806:     
                    807:     nsCOMPtr<nsISupports> sourceData;
                    808:     if (isHTML && filterIndex != 1)
                    809:         sourceData = do_QueryInterface(mDocument);
                    810:     else
                    811:         sourceData = do_QueryInterface(mURL);
                    812:         
1.4       hyatt     813:     nsCOMPtr<nsIWebBrowserPersist> webPersist(do_CreateInstance(persistContractID));
1.2       hyatt     814:     ProgressDlgController* progressDialog = [[ProgressDlgController alloc] initWithWindowNibName: @"ProgressDialog"];
1.4       hyatt     815:     [progressDialog setWebPersist: webPersist 
1.2       hyatt     816:                     source: sourceData.get()
                    817:                     destination: [savePanel filename]
                    818:                     contentType: mContentType.get()
1.3       hyatt     819:                     postData: mPostData
                    820:                     bypassCache: mBypassCache];
                    821:                     
1.2       hyatt     822:     [progressDialog showWindow: progressDialog];
                    823: }
                    824: 
                    825: /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
                    826: NS_IMETHODIMP 
                    827: nsHeaderSniffer::OnProgressChange(nsIWebProgress *aWebProgress, 
                    828:           nsIRequest *aRequest, 
                    829:           PRInt32 aCurSelfProgress, 
                    830:           PRInt32 aMaxSelfProgress, 
                    831:           PRInt32 aCurTotalProgress, 
                    832:           PRInt32 aMaxTotalProgress)
                    833: {
                    834:   return NS_OK;
                    835: }
                    836: 
                    837: /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
                    838: NS_IMETHODIMP 
                    839: nsHeaderSniffer::OnLocationChange(nsIWebProgress *aWebProgress, 
                    840:           nsIRequest *aRequest, 
                    841:           nsIURI *location)
                    842: {
                    843:   return NS_OK;
                    844: }
                    845: 
                    846: /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
                    847: NS_IMETHODIMP 
                    848: nsHeaderSniffer::OnStatusChange(nsIWebProgress *aWebProgress, 
                    849:               nsIRequest *aRequest, 
                    850:               nsresult aStatus, 
                    851:               const PRUnichar *aMessage)
                    852: {
                    853:   return NS_OK;
                    854: }
                    855: 
                    856: /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
                    857: NS_IMETHODIMP 
                    858: nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, 
                    859:                        nsIRequest *aRequest, 
                    860:                                   PRInt32 state)
                    861: {
                    862:   return NS_OK;
                    863: }
                    864: 
1.1       hyatt     865: 
                    866: @implementation NSBrowserView
                    867: 
                    868: - (id)initWithFrame:(NSRect)frame
                    869: {
                    870:   [super initWithFrame:frame];
                    871: 
                    872:   nsresult rv = nsCocoaBrowserService::InitEmbedding();
                    873:   if (NS_FAILED(rv)) {
                    874:     // XXX need to throw
                    875:   }
                    876:   
                    877:   _listener = new nsCocoaBrowserListener(self);
                    878:   NS_ADDREF(_listener);
                    879: 
                    880:   // Create the web browser instance
                    881:   nsCOMPtr<nsIWebBrowser> browser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
                    882:   if (NS_FAILED(rv)) {
                    883:     // XXX need to throw
                    884:   }
                    885: 
                    886:   _webBrowser = browser;
                    887:   NS_ADDREF(_webBrowser);
                    888: 
                    889:   // Set the container nsIWebBrowserChrome
                    890:   _webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, 
                    891:             _listener));
                    892:   
                    893:   // Register as a listener for web progress
                    894:   nsCOMPtr<nsIWeakReference> weak = do_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, _listener));
                    895:   _webBrowser->AddWebBrowserListener(weak, NS_GET_IID(nsIWebProgressListener));
                    896: 
                    897:   // Hook up the widget hierarchy with us as the parent
                    898:   nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(_webBrowser);
                    899:   baseWin->InitWindow((NSView*)self, nsnull, 0, 0, 
                    900:          frame.size.width, frame.size.height);
                    901:   baseWin->Create();
                    902: 
                    903:   return self;
                    904: }
                    905: 
1.6       hyatt     906: - (void)destroyWebBrowser
                    907: {
                    908:   nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(_webBrowser);
                    909:   baseWin->Destroy();
                    910: }
                    911: 
1.1       hyatt     912: - (void)dealloc 
                    913: {
                    914:   NS_RELEASE(_listener);
                    915:   NS_IF_RELEASE(_webBrowser);
                    916:   [super dealloc];
                    917: }
                    918: 
                    919: - (void)setFrame:(NSRect)frameRect 
                    920: {
                    921:   [super setFrame:frameRect];
                    922:   if (_webBrowser) {
                    923:     nsCOMPtr<nsIBaseWindow> window = do_QueryInterface(_webBrowser);
                    924:     window->SetSize((PRInt32)frameRect.size.width, 
                    925:        (PRInt32)frameRect.size.height,
                    926:        PR_TRUE);
                    927:   }
                    928: }
                    929: 
                    930: - (void)addListener:(id <NSBrowserListener>)listener
                    931: {
                    932:   _listener->AddListener(listener);
                    933: }
                    934: 
                    935: - (void)removeListener:(id <NSBrowserListener>)listener
                    936: {
                    937:   _listener->RemoveListener(listener);
                    938: }
                    939: 
                    940: - (void)setContainer:(id <NSBrowserContainer>)container
                    941: {
                    942:   _listener->SetContainer(container);
                    943: }
                    944: 
                    945: - (nsIDOMWindow*)getContentWindow
                    946: {
                    947:   nsIDOMWindow* window;
                    948: 
                    949:   _webBrowser->GetContentDOMWindow(&window);
                    950: 
                    951:   return window;
                    952: }
                    953: 
                    954: - (void)loadURI:(NSURL *)url flags:(unsigned int)flags
                    955: {
                    956:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                    957:   
                    958:   NSString* spec = [url absoluteString];
                    959:   int length = [spec length];
                    960:   PRUnichar* specStr = nsMemory::Alloc((length+1) * sizeof(PRUnichar));
                    961:   [spec getCharacters:specStr];
                    962:   specStr[length] = PRUnichar(0);
                    963:   
                    964: 
                    965:   PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
                    966:   if (flags & NSLoadFlagsDontPutInHistory) {
                    967:     navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY;
                    968:   }
                    969:   if (flags & NSLoadFlagsReplaceHistoryEntry) {
                    970:     navFlags |= nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY;
                    971:   }
                    972:   if (flags & NSLoadFlagsBypassCacheAndProxy) {
                    973:     navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | 
                    974:                 nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
                    975:   }
                    976: 
                    977:   nsresult rv = nav->LoadURI(specStr, navFlags, nsnull, nsnull, nsnull);
                    978:   if (NS_FAILED(rv)) {
                    979:     // XXX need to throw
                    980:   }
                    981: 
                    982:   nsMemory::Free(specStr);
                    983: }
                    984: 
                    985: - (void)reload:(unsigned int)flags
                    986: {
                    987:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                    988: 
                    989:   PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
                    990:   if (flags & NSLoadFlagsBypassCacheAndProxy) {
                    991:     navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | 
                    992:                 nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
                    993:   }
                    994: 
                    995:   nsresult rv = nav->Reload(navFlags);
                    996:   if (NS_FAILED(rv)) {
                    997:     // XXX need to throw
                    998:   }  
                    999: }
                   1000: 
                   1001: - (BOOL)canGoBack
                   1002: {
                   1003:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                   1004: 
                   1005:   PRBool can;
                   1006:   nav->GetCanGoBack(&can);
                   1007: 
                   1008:   return can ? YES : NO;
                   1009: }
                   1010: 
                   1011: - (BOOL)canGoForward
                   1012: {
                   1013:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                   1014: 
                   1015:   PRBool can;
                   1016:   nav->GetCanGoForward(&can);
                   1017: 
                   1018:   return can ? YES : NO;
                   1019: }
                   1020: 
                   1021: - (void)goBack
                   1022: {
                   1023:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                   1024: 
                   1025:   nsresult rv = nav->GoBack();
                   1026:   if (NS_FAILED(rv)) {
                   1027:     // XXX need to throw
                   1028:   }  
                   1029: }
                   1030: 
                   1031: - (void)goForward
                   1032: {
                   1033:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                   1034: 
                   1035:   nsresult rv = nav->GoForward();
                   1036:   if (NS_FAILED(rv)) {
                   1037:     // XXX need to throw
                   1038:   }  
                   1039: }
                   1040: 
                   1041: - (void)gotoIndex:(int)index
                   1042: {
                   1043:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                   1044: 
                   1045:   nsresult rv = nav->GotoIndex(index);
                   1046:   if (NS_FAILED(rv)) {
                   1047:     // XXX need to throw
                   1048:   }    
                   1049: }
                   1050: 
                   1051: - (void)stop:(unsigned int)flags
                   1052: {
                   1053:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                   1054: 
                   1055:   nsresult rv = nav->Stop(flags);
                   1056:   if (NS_FAILED(rv)) {
                   1057:     // XXX need to throw
                   1058:   }    
                   1059: }
                   1060: 
                   1061: - (NSURL*)getCurrentURI
                   1062: {
                   1063:   nsCOMPtr<nsIURI> uri;
                   1064:   nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
                   1065: 
                   1066:   nav->GetCurrentURI(getter_AddRefs(uri));
                   1067:   if (!uri) {
                   1068:     return nsnull;
                   1069:   }
                   1070: 
                   1071:   nsXPIDLCString spec;
                   1072:   uri->GetSpec(getter_Copies(spec));
                   1073:   
                   1074:   const char* cstr = spec.get();
                   1075:   NSString* str = [NSString stringWithCString:cstr];
                   1076:   NSURL* url = [NSURL URLWithString:str];
                   1077:   
                   1078:   return url;
                   1079: }
                   1080: 
                   1081: - (nsIWebBrowser*)getWebBrowser
                   1082: {
                   1083:   NS_IF_ADDREF(_webBrowser);
                   1084:   return _webBrowser;
                   1085: }
                   1086: 
                   1087: - (void)setWebBrowser:(nsIWebBrowser*)browser
                   1088: {
                   1089:   _webBrowser = browser;
                   1090: 
                   1091:   if (_webBrowser) {
                   1092:     // Set the container nsIWebBrowserChrome
                   1093:     _webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, 
                   1094:               _listener));
                   1095: 
                   1096:     NSRect frame = [self frame];
                   1097:  
                   1098:     // Hook up the widget hierarchy with us as the parent
                   1099:     nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(_webBrowser);
                   1100:     baseWin->InitWindow((NSView*)self, nsnull, 0, 0, 
                   1101:      frame.size.width, frame.size.height);
                   1102:     baseWin->Create();
                   1103:   }
                   1104: 
1.2       hyatt    1105: }
                   1106: 
                   1107: -(void) saveInternal: (nsIURI*)aURI
                   1108:         withDocument: (nsIDOMDocument*)aDocument
                   1109:         bypassCache: (BOOL)aBypassCache
                   1110:         filterView: (NSView*)aFilterView
                   1111:         filterList: (NSPopUpButton*)aFilterList
                   1112: {
                   1113:     // Create our web browser persist object.  This is the object that knows
                   1114:     // how to actually perform the saving of the page (and of the images
                   1115:     // on the page).
                   1116:     nsCOMPtr<nsIWebBrowserPersist> webPersist(do_CreateInstance(persistContractID));
                   1117:     if (!webPersist)
                   1118:         return;
                   1119:     
                   1120:     // Make a temporary file object that we can save to.
                   1121:     nsCOMPtr<nsIProperties> dirService(do_GetService(dirServiceContractID));
                   1122:     if (!dirService)
                   1123:         return;
                   1124:     nsCOMPtr<nsIFile> tmpFile;
                   1125:     dirService->Get("TmpD", NS_GET_IID(nsIFile), getter_AddRefs(tmpFile));
                   1126:     static short unsigned int tmpRandom = 0;
                   1127:     nsCAutoString tmpNo; tmpNo.AssignWithConversion(tmpRandom++);
                   1128:     nsCAutoString saveFile("-sav");
                   1129:     saveFile += tmpNo;
                   1130:     saveFile += "tmp";
                   1131:     tmpFile->Append(saveFile.get()); 
                   1132:     
                   1133:     // Get the post data if we're an HTML doc.
                   1134:     nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(_webBrowser));
                   1135:     nsCOMPtr<nsISHistory> sessionHistory;
                   1136:     webNav->GetSessionHistory(getter_AddRefs(sessionHistory));
1.3       hyatt    1137:     nsCOMPtr<nsIHistoryEntry> entry;
                   1138:     PRInt32 sindex;
                   1139:     sessionHistory->GetIndex(&sindex);
                   1140:     sessionHistory->GetEntryAtIndex(sindex, PR_FALSE, getter_AddRefs(entry));
                   1141:     nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(entry));
                   1142:     nsCOMPtr<nsIInputStream> postData;
                   1143:     if (shEntry)
                   1144:         shEntry->GetPostData(getter_AddRefs(postData));
                   1145:     
1.2       hyatt    1146:     nsHeaderSniffer* sniffer = new nsHeaderSniffer(webPersist, tmpFile, aURI, 
1.3       hyatt    1147:                                                    aDocument, postData, aBypassCache,
1.2       hyatt    1148:                                                    aFilterView, aFilterList);
                   1149:     if (!sniffer)
                   1150:         return;
                   1151:     webPersist->SetProgressListener(sniffer);
                   1152:     webPersist->SaveURI(aURI, nsnull, tmpFile);
1.8       hyatt    1153: }
                   1154: 
                   1155: -(void)printDocument
                   1156: {
                   1157:     nsCOMPtr<nsIDOMWindow> domWindow;
                   1158:     _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
                   1159:     nsCOMPtr<nsIInterfaceRequestor> ir(do_QueryInterface(domWindow));
                   1160:     nsCOMPtr<nsIWebBrowserPrint> print;
                   1161:     ir->GetInterface(NS_GET_IID(nsIWebBrowserPrint), getter_AddRefs(print));
                   1162:     print->Print(nsnull, nsnull);
1.2       hyatt    1163: }
                   1164: 
                   1165: -(void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
                   1166: {
                   1167:     nsCOMPtr<nsIWebBrowserFocus> wbf(do_QueryInterface(_webBrowser));
                   1168:     nsCOMPtr<nsIDOMWindow> domWindow;
                   1169:     wbf->GetFocusedWindow(getter_AddRefs(domWindow));
                   1170:     if (!domWindow)
                   1171:         _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
                   1172:     if (!domWindow)
                   1173:         return;
                   1174:     
                   1175:     nsCOMPtr<nsIDOMDocument> domDocument;
                   1176:     domWindow->GetDocument(getter_AddRefs(domDocument));
                   1177:     if (!domDocument)
                   1178:         return;
                   1179:     nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDocument));
                   1180:     if (!doc)
                   1181:         return;
                   1182:     nsCOMPtr<nsIURI> url;
                   1183:     doc->GetDocumentURL(getter_AddRefs(url));
                   1184:      
                   1185:     [self saveInternal: url.get()
                   1186:           withDocument: domDocument
                   1187:           bypassCache: NO
                   1188:           filterView: aFilterView
                   1189:           filterList: aFilterList];
1.1       hyatt    1190: }
                   1191: 
                   1192: @end
                   1193: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>