home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / urlecho.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.9 KB  |  179 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. #include "stdafx.h"
  20.  
  21. #include "urlecho.h"
  22.  
  23. #include "wfedde.h"
  24.  
  25. extern "C" void FE_URLEcho(URL_Struct *pURL, int iStatus, MWContext *pContext)  {
  26. //  Purpose:  Echo the URL to all appropriately registered applications that are monitoring such URL traffic.
  27. //  Arguments:  pURL  The URL which is being loaded.
  28. //        iStatus The status of the load.
  29. //        pContext  The context in which the load occurred.
  30. //  Returns:  void
  31. //  Comments: Well, sometimes there isn't a window in which the load occurred, what to do then?
  32. //        Just don't report.
  33. //  Revision History:
  34. //    01-18-95  created GAB
  35. //
  36.  
  37.   //  Check to make sure everything's OK to continue onwards.
  38.   if(pURL == NULL)  {
  39.     return;
  40.   }
  41.   else if(pURL->address == NULL)  {
  42.     return;
  43.   } 
  44.   else if(pContext == NULL) {
  45.     return;
  46.   }
  47.   else if(GetFrame(pContext) == NULL) {
  48.     //  Have to have a frame, as the DDE implementation assumes there are windows around.
  49.     return;
  50.   }
  51.   
  52.   //    Let the progress applications know what's up.
  53.   if(pURL->server_status / 100 != 2 && pURL->server_status / 100 != 3 && pURL->server_status != 0) {
  54.     //  The server actually reported an error, be we won't display this as an error but render it in a window.
  55.     //  We will send these messages to an external type of applciation in this case only though that is monitoring
  56.     //    progress.
  57.     
  58.     CString myMsg = szLoadString(IDS_SERVER_ERR_NUM);
  59.     char aBuffer[16];
  60.     sprintf(aBuffer, "%d", pURL->server_status);
  61.     myMsg += aBuffer;
  62.     return;
  63.   }
  64.  
  65.   //  Okay, let's start checking stuff out.
  66.   //  We will NOT report on failures to load.
  67.   if(iStatus != MK_DATA_LOADED) {
  68.     //  This is an error.
  69.     //  Perhaps just an interrupting load by the user.
  70.     //  In any event, it will be reported to any monitoring applications in WFE_Alert.
  71.     return;
  72.   }
  73.  
  74.   //  So the data was actually loaded.
  75.   //  Build a URL, and a Referrer URL.
  76.   //  Build the mime type, and a windowID.
  77.   CString csURL;
  78.   CString csReferrer;
  79.   CString csMimeType;
  80.   DWORD dwWindowID;
  81.   
  82.   csURL = pURL->address;
  83.   if(pURL->referer != NULL) {
  84.     csReferrer = pURL->referer;
  85.   }
  86.   if(pURL->content_type != NULL)  {
  87.     csMimeType = pURL->content_type;
  88.   }
  89.   dwWindowID = FE_GetContextID(pContext);
  90.   
  91.   CEchoItem::Echo(csURL, csMimeType, dwWindowID, csReferrer);
  92.   return;
  93.  
  94. //  Static property.
  95. CPtrList CEchoRegistry::m_Registry;
  96.  
  97. void CEchoItem::Echo(CString& csURL, CString& csMimeType, DWORD dwWindowID, CString& csReferrer)  {
  98. //  Purpose:  Go through every object in the registry, and echo the URL information to them.
  99. //  Arguments:  csURL The url being loaded.
  100. //        csMimeType  The mime type of the URL being loaded.
  101. //        dwWindowID  The window performing the load.
  102. //        csReferrer  The referring URL.
  103. //  Returns:  void
  104. //  Comments:
  105. //  Revision History:
  106. //    01-18-95  created GAB
  107. //
  108.  
  109.   //  Go through the registry.
  110.   CEchoItem *pItem;
  111.   POSITION rIndex = m_Registry.GetHeadPosition();
  112.   while(rIndex != NULL) {
  113.     pItem = (CEchoItem *)m_Registry.GetNext(rIndex);
  114.     
  115.     //  Depending on how the watching server was registered, it is handled through this virtual
  116.     //    member mapping to the correct class.
  117.     pItem->EchoURL(csURL, csMimeType, dwWindowID, csReferrer);
  118.   }
  119. }
  120.  
  121. void CDDEEchoItem::DDERegister(CString &csServiceName)  {
  122. //  Purpose:  Register a DDE applciation to watch url echos.
  123. //  Arguments:  csServiceName The service name of the DDE server which wants to watch the urls.
  124. //  Returns:  void
  125. //  Comments: Always works.
  126. //  Revision History:
  127. //    01-18-95  created GAB
  128. //
  129.  
  130.   //  Just create the item.  Our job's done.
  131.   CDDEEchoItem *pDontCare = new CDDEEchoItem(csServiceName);
  132. }
  133.  
  134. BOOL CDDEEchoItem::DDEUnRegister(CString &csServiceName)  {
  135. //  Purpose:  Deregister a DDE applciation watching url echos.
  136. //  Arguments:  csServiceName The DDE service name to unregister.
  137. //  Returns:  BOOL  Wether or not unregistered.
  138. //  Comments: Have to look through every entry in the registry, until we find the entry.
  139. //  Revision History:
  140. //    01-18-95  created GAB
  141. //
  142.  
  143.   //  Go through all registrations.
  144.   POSITION rIndex = m_Registry.GetHeadPosition();
  145.   CEchoItem *pItem;
  146.   CDDEEchoItem *pDelMe;
  147.   
  148.   while(rIndex != NULL) {
  149.     pItem = (CEchoItem *)m_Registry.GetNext(rIndex);
  150.     
  151.     //  Check the type of the registered app, could be OLE or something.
  152.     if(pItem->GetType() == m_DDE) {
  153.       pDelMe = (CDDEEchoItem *)pItem;
  154.         if(pDelMe->GetServiceName() == csServiceName)  {
  155.             delete pDelMe;
  156.             return(TRUE);
  157.         }
  158.     }
  159.   }
  160.  
  161.   return(FALSE);
  162. }
  163.  
  164. void CDDEEchoItem::EchoURL(CString& csURL, CString& csMimeType, DWORD dwWindowID, CString& csReferrer)  {
  165. //  Purpose:  Send a registered DDE server an URL echo event.
  166. //  Arguments:  csURL The url loaded.
  167. //        csMimeType  The mime type of the loading URL.
  168. //        dwWindowID  The window performing the load.
  169. //        csReferrer  The referrer URL.
  170. //  Returns:  void
  171. //  Comments: 
  172. //  Revision History:
  173. //    01-18-95  created GAB
  174. //
  175.  
  176.   CDDEWrapper::URLEcho(this, csURL, csMimeType, dwWindowID, csReferrer);
  177. }
  178.