home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CURLDispatcher.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.0 KB  |  211 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. //    CURLDispatcher.h
  20.  
  21.  
  22. #ifndef CURLDispatcher_H
  23. #define CURLDispatcher_H
  24. #pragma once
  25.  
  26. #include <LPeriodical.h>
  27. #include <LListener.h>
  28.  
  29. #include "structs.h"
  30. #include "CAutoPtr.h"
  31. #include "ntypes.h"
  32. #include "net.h" // for FO_CACHE_AND_PRESENT
  33.  
  34. class CNSContext;
  35. class CBrowserContext;
  36. class CBrowserWindow;
  37.  
  38. class CURLDispatchInfo;
  39.  
  40. // Dispatch function prototype
  41.  
  42. const ResIDT BrowserWindow_ResID = 1010;
  43.  
  44. typedef void (*DispatchProcPtr)(CURLDispatchInfo* inDispatchInfo);
  45.  
  46. class CURLDispatcher : 
  47.     public LPeriodical,
  48.     public LListener
  49. {
  50.     public:
  51.     
  52.         static void                DispatchToStorage(
  53.                                         URL_Struct*                inURL,
  54.                                         const FSSpec&            inDestSpec,
  55.                                         FO_Present_Types        inOutputFormat = FO_SAVE_AS,
  56.                                         Boolean                    inDelay = false);
  57.         
  58.         static void                DispatchToStorage(CURLDispatchInfo* inDispatchInfo);
  59.         
  60.         
  61.         virtual    void            SpendTime(const EventRecord&    inMacEvent);
  62.         
  63.         virtual void            ListenToMessage(
  64.                                         MessageT                inMessage,
  65.                                         void*                    ioParam);
  66.                         
  67.         static Uint32             CountDelayedURLs() { return GetURLDispatcher()->GetCountDelayedURLs(); }
  68.         
  69.         // 97-05-13 pkc -- New URL dispatch mechanism
  70.         
  71.         static void                    DispatchURL(
  72.                                         const char*                inURL,
  73.                                         CNSContext*                inTargetContext,
  74.                                         Boolean                    inDelay = false,
  75.                                         Boolean                    inForceCreate = false,
  76.                                         ResIDT                    inWindowResID = BrowserWindow_ResID,
  77.                                         Boolean                    inInitiallyVisible = true,
  78.                                         FO_Present_Types        inOutputFormat = FO_CACHE_AND_PRESENT,
  79.                                         NET_ReloadMethod        inReloadMethod = NET_DONT_RELOAD);
  80.                                         
  81.         static void                    DispatchURL(
  82.                                         URL_Struct*                inURLStruct,
  83.                                         CNSContext*                inTargetContext,
  84.                                         Boolean                    inDelay = false,
  85.                                         Boolean                    inForceCreate = false,
  86.                                         ResIDT                    inWindowResID = BrowserWindow_ResID,
  87.                                         Boolean                    inInitiallyVisible = true,
  88.                                         FO_Present_Types        inOutputFormat = FO_CACHE_AND_PRESENT,
  89.                                         Boolean                    inWaitingForMochaImageLoad = false);
  90.  
  91.         static void                    DispatchURL(CURLDispatchInfo* inDispatchInfo);
  92.  
  93.         // Dispatch procs
  94.         
  95.         static void                DispatchToLibNet(CURLDispatchInfo* inDispatchInfo);
  96.         static void                DispatchToBrowserWindow(CURLDispatchInfo* inDispatchInfo);
  97.         static void                DispatchMailboxURL(CURLDispatchInfo* inDispatchInfo);
  98.         static void                DispatchToMailNewsWindow(CURLDispatchInfo* inDispatchInfo);
  99.  
  100.         // Utility functions
  101.         
  102.         static void                DispatchToNewBrowserWindow(CURLDispatchInfo* inDispatchInfo);
  103.         static CBrowserWindow*    CreateNewBrowserWindow(
  104.                                         ResIDT inWindowResID = BrowserWindow_ResID,
  105.                                         Boolean inInitiallyVisible = true);
  106.  
  107.         // Return the browser window created by the last call to DispatchToView. Note that
  108.         // if the dispatch was delayed, this will be null until the pending dispatch is processed.
  109.         static CBrowserWindow*    GetLastBrowserWindowCreated() { return sLastBrowserWindowCreated; }
  110.         
  111.     protected:
  112.  
  113.         static CURLDispatcher* GetURLDispatcher();    // singleton class
  114.  
  115.         static void                DispatchToDisk(CURLDispatchInfo* inDispatchInfo);
  116.  
  117.         static void                DispatchToDiskAsText(CURLDispatchInfo* inDispatchInfo);
  118.             
  119.         Uint32                     GetCountDelayedURLs() const { return mDelayedURLs.GetCount(); }
  120.  
  121.         virtual    void            PostPendingDispatch(CURLDispatchInfo* inDispatchInfo);
  122.                                         
  123.         virtual void            UpdatePendingDispatch(
  124.                                         CNSContext*                inForContext);
  125.                                         
  126.         virtual    void            ProcessPendingDispatch(void);
  127.  
  128.         LArray                    mDelayedURLs;
  129.         
  130.         // reset to NULL on entry in DispatchToView(), set in DispatchToNewBrowserWindow()
  131.         static CBrowserWindow*    sLastBrowserWindowCreated;
  132.  
  133.         static CAutoPtr<CURLDispatcher>    sDispatcher;
  134.         static CAutoPtr<CBrowserContext>    sDispatchContext;
  135.         
  136.  
  137. private:    
  138.         friend class CAutoPtr<CURLDispatcher>;
  139.         friend class CAutoPtr<CBrowserContext>;
  140.         
  141.                                 CURLDispatcher();
  142.         virtual                    ~CURLDispatcher();
  143.         
  144. };
  145.  
  146. // Info needed to dispatch a URL
  147. class CURLDispatchInfo
  148. {
  149.     public:
  150.                                 CURLDispatchInfo();
  151.  
  152.                                 CURLDispatchInfo(
  153.                                         const char*                inURL,
  154.                                         CNSContext*                inTargetContext,
  155.                                         FO_Present_Types        inOutputFormat,
  156.                                         NET_ReloadMethod        inReloadMethod = NET_DONT_RELOAD,
  157.                                         Boolean                    inDelay = false /* BLECH! */,
  158.                                         Boolean                    inForceCreate = false,
  159.                                         Boolean                    inIsSaving = false,
  160.                                         ResIDT                    inWindowResID = BrowserWindow_ResID,
  161.                                         Boolean                    inInitiallyVisible = true);
  162.  
  163.                                 CURLDispatchInfo(
  164.                                         URL_Struct*                inURLStruct,
  165.                                         CNSContext*                inTargetContext,
  166.                                         FO_Present_Types        inOutputFormat,
  167.                                         Boolean                    inDelay = false /* BLECH! */,
  168.                                         Boolean                    inForceCreate = false,
  169.                                         Boolean                    inIsSaving = false,
  170.                                         ResIDT                    inWindowResID = BrowserWindow_ResID,
  171.                                         Boolean                    inInitiallyVisible = true,
  172.                                         Boolean                    inWaitingForMochaImageLoad = false);
  173.  
  174.         virtual                    ~CURLDispatchInfo();
  175.         
  176.         Int32                    GetURLType() { return mURLType; }
  177.         char*                    GetURL();
  178.         URL_Struct*                GetURLStruct() { return mURLStruct; }
  179.         CNSContext*                GetTargetContext() { return mTargetContext; }
  180.         FO_Present_Types        GetOutputFormat() { return mOutputFormat; }
  181.         Boolean                    GetDelay() { return mDelayDispatch; }
  182.         Boolean                    GetIsSaving() { return mIsSaving; }
  183.         Boolean                    GetInitiallyVisible() { return mInitiallyVisible; }
  184.         FSSpec&                    GetFileSpec() { return mFileSpec; }
  185.         ResIDT                    GetWindowResID() { return mWindowResID; }
  186.         Boolean                    GetForceCreate() { return mForceCreate; }
  187.         Boolean                    GetIsWaitingForMochaImageLoad()
  188.                                 { return mIsWaitingForMochaImageLoad; }
  189.         
  190.         URL_Struct*                ReleaseURLStruct();
  191.  
  192.         void                    ClearDelay() { mDelayDispatch = false; }        
  193.         void                    SetFileSpec(const FSSpec& inFileSpec);
  194.         void                    SetTargetContext(CNSContext* inTargetContext)
  195.                                 { mTargetContext = inTargetContext; }
  196.         
  197.     protected:
  198.         Int32                    mURLType;
  199.         URL_Struct*                mURLStruct;
  200.         CNSContext*                mTargetContext;
  201.         FO_Present_Types        mOutputFormat;
  202.         Boolean                    mDelayDispatch;
  203.         Boolean                    mForceCreate;
  204.         Boolean                    mIsSaving;
  205.         Boolean                    mInitiallyVisible;
  206.         Boolean                    mIsWaitingForMochaImageLoad;
  207.         FSSpec                    mFileSpec;
  208.         ResIDT                    mWindowResID;
  209. };
  210. #endif
  211.