Changeset 2526

Show
Ignore:
Timestamp:
11/14/08 13:38:37 (8 weeks ago)
Author:
ahodgkinson
Message:

digitalme: Re-structured the Firefox launcher to be more modular.

Location:
trunk/digitalme/launchers/firefox-addon
Files:
5 added
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/digitalme/launchers/firefox-addon/CMakeLists.txt

    r2525 r2526  
    6666  COMMAND ${CMAKE_COMMAND} -E echo "       <em:version>0.4.${PROJECT_REVISION}</em:version>" >> ${INSTALL_RDF_FILE} 
    6767  COMMAND ${CMAKE_COMMAND} -E echo "       <em:description>Enables browser support for websites that use information cards</em:description>" >> ${INSTALL_RDF_FILE} 
    68   COMMAND ${CMAKE_COMMAND} -E echo "       <em:iconURL>chrome://identityselector/content/cbisicon.png</em:iconURL>" >> ${INSTALL_RDF_FILE} 
    69   COMMAND ${CMAKE_COMMAND} -E echo "       <em:optionsURL>chrome://identityselector/content/cbisPrefs.xul</em:optionsURL>" >> ${INSTALL_RDF_FILE} 
     68  COMMAND ${CMAKE_COMMAND} -E echo "       <em:iconURL>chrome://identityselector/content/DigitalMeIcon.png</em:iconURL>" >> ${INSTALL_RDF_FILE} 
     69  COMMAND ${CMAKE_COMMAND} -E echo "       <em:optionsURL>chrome://identityselector/content/DigitalMePrefs.xul</em:optionsURL>" >> ${INSTALL_RDF_FILE} 
    7070  COMMAND ${CMAKE_COMMAND} -E echo "       <!-- Firefox -->" >> ${INSTALL_RDF_FILE} 
    7171  COMMAND ${CMAKE_COMMAND} -E echo "       <em:targetApplication>" >> ${INSTALL_RDF_FILE} 
    … …  
    9595        DEPENDS ${PACKAGE_STAGE_DIR}  
    9696        DEPENDS ${INSTALL_RDF_FILE} 
     97 
    9798        COMMAND ${CMAKE_COMMAND} -E copy COPYING ${PACKAGE_STAGE_DIR} 
    9899        COMMAND ${CMAKE_COMMAND} -E copy COPYRIGHT ${PACKAGE_STAGE_DIR} 
    99100        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome.manifest ${PACKAGE_STAGE_DIR} 
     101 
    100102        COMMAND mkdir -p ${PACKAGE_STAGE_DIR}/chrome/content 
    101         COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/cbisicon.png ${PACKAGE_STAGE_DIR}/chrome/content 
     103 
     104        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/IdentitySelector.xul ${PACKAGE_STAGE_DIR}/chrome/content 
    102105        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/IdentitySelector.js ${PACKAGE_STAGE_DIR}/chrome/content 
    103         COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/IdentitySelector.xul ${PACKAGE_STAGE_DIR}/chrome/content 
    104         COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/cbis.js ${PACKAGE_STAGE_DIR}/chrome/content 
    105         COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/cbisPrefs.xul ${PACKAGE_STAGE_DIR}/chrome/content 
    106         COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/cbisPrefs.js ${PACKAGE_STAGE_DIR}/chrome/content 
     106        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/IdentitySelectorDiag.js ${PACKAGE_STAGE_DIR}/chrome/content 
     107        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/IdentitySelectorPrefs.js ${PACKAGE_STAGE_DIR}/chrome/content 
     108        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/IdentitySelectorUtil.js ${PACKAGE_STAGE_DIR}/chrome/content 
     109        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/NoIdentitySelector.js ${PACKAGE_STAGE_DIR}/chrome/content 
    107110        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/Intercept.js ${PACKAGE_STAGE_DIR}/chrome/content 
     111 
     112        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/DigitalMe.xul ${PACKAGE_STAGE_DIR}/chrome/content 
     113        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/DigitalMe.js ${PACKAGE_STAGE_DIR}/chrome/content 
     114 
     115        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/DigitalMePrefs.xul ${PACKAGE_STAGE_DIR}/chrome/content 
     116        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/DigitalMePrefs.js ${PACKAGE_STAGE_DIR}/chrome/content 
     117 
     118        COMMAND ${CMAKE_COMMAND} -E copy xul/chrome/content/DigitalMeIcon.png ${PACKAGE_STAGE_DIR}/chrome/content 
     119 
    108120        COMMAND mkdir -p ${PACKAGE_STAGE_DIR}/defaults/preferences 
    109121        COMMAND mkdir -p ${PACKAGE_STAGE_DIR}/components 
  • trunk/digitalme/launchers/firefox-addon/xul/chrome/content/IdentitySelector.js

    r2525 r2526  
    2222// ************************************************************************** 
    2323 
    24 const nsIX509Cert = Components.interfaces.nsIX509Cert; 
    25  
    26 const nsIX509CertDB = Components.interfaces.nsIX509CertDB; 
    27 const nsX509CertDB = "@mozilla.org/security/x509certdb;1"; 
    28  
    29 const nsINSSCertCache = Components.interfaces.nsINSSCertCache; 
    30 const nsNSSCertCache = "@mozilla.org/security/nsscertcache;1"; 
    31  
    32 const nsICertTree = Components.interfaces.nsICertTree; 
    33 const nsCertTree = "@mozilla.org/security/nsCertTree;1"; 
    34  
    35 const nsILocalFile = Components.interfaces.nsILocalFile; 
    36 const nsLocalFile = "@mozilla.org/file/local;1"; 
    37  
    38 const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream; 
    39 const nsFileOutputStream = "@mozilla.org/network/file-output-stream;1"; 
    40  
    41 const nsICardObjTypeStr = "application/x-informationcard"; 
     24var nsIX509Cert = Components.interfaces.nsIX509Cert; 
     25 
     26var nsIX509CertDB = Components.interfaces.nsIX509CertDB; 
     27var nsX509CertDB = "@mozilla.org/security/x509certdb;1"; 
     28 
     29var nsINSSCertCache = Components.interfaces.nsINSSCertCache; 
     30var nsNSSCertCache = "@mozilla.org/security/nsscertcache;1"; 
     31 
     32var nsICertTree = Components.interfaces.nsICertTree; 
     33var nsCertTree = "@mozilla.org/security/nsCertTree;1"; 
     34 
     35var nsILocalFile = Components.interfaces.nsILocalFile; 
     36var nsLocalFile = "@mozilla.org/file/local;1"; 
     37 
     38var nsIFileOutputStream = Components.interfaces.nsIFileOutputStream; 
     39var nsFileOutputStream = "@mozilla.org/network/file-output-stream;1"; 
     40 
     41var nsICardObjTypeStr = "application/x-informationcard"; 
    4242                 
    4343// ************************************************************************** 
    … …  
    4545// ************************************************************************** 
    4646 
    47 var gPrefService = Components.classes[  
    48                 "@mozilla.org/preferences-service;1"]. 
    49                         getService( Components.interfaces.nsIPrefBranch); 
    50 var gConsoleService = Components.classes[ "@mozilla.org/consoleservice;1"]. 
    51                         getService( Components.interfaces.nsIConsoleService); 
    52 var gbLoggingEnabled = false; 
    5347var gLastFailedGetTokenDate = null; 
    5448var gDisableStartTime = null; 
    … …  
    5650 
    5751// ************************************************************************** 
    58 // Desc: Other global variables 
    59 // ************************************************************************** 
    60  
    61 var gNavPlat = navigator.platform; 
    62 var gbIsWin = ((gNavPlat.indexOf( "Win") > -1) ? true : false); 
    63 var gbIsMac = ((gNavPlat.indexOf( "Mac") > -1) ? true : false); 
    64 var gbIsLinux = ((gNavPlat.indexOf( "Linux") > -1) ? true : false); 
    65                                          
    66 // ************************************************************************** 
    6752// Desc: 
    6853// ************************************************************************** 
    6954 
    70 var ICProgressListener = 
    71 { 
    72         QueryInterface : function( aIID) 
    73         { 
    74                 if( aIID.equals( Components.interfaces.nsIWebProgressListener) || 
    75                          aIID.equals( Components.interfaces.nsISupportsWeakReference) || 
    76                          aIID.equals( Components.interfaces.nsISupports)) 
    77                 { 
    78                         return( this); 
    79                 } 
    80                  
    81                 throw Components.results.NS_NOINTERFACE; 
    82         }, 
    83          
    84         onStateChange : function( aProgress, aRequest, aFlag, aStatus) 
    85         { 
    86                 var progListIFace = Components.interfaces.nsIWebProgressListener; 
    87                  
    88                 // Log the flags 
    89                  
    90                 IdentitySelector.logMessage( "onStateChange", "flags = " + aFlag); 
    91                  
    92                 if( aFlag & progListIFace.STATE_IS_DOCUMENT) 
    93                 { 
    94                         IdentitySelector.logMessage( "onStateChange", "flag & document"); 
    95                 } 
    96                          
    97                 if( aFlag & progListIFace.STATE_IS_WINDOW) 
    98                 { 
    99                         IdentitySelector.logMessage( "onStateChange", "flag & window"); 
    100                 } 
    101                  
    102                 if( aFlag & progListIFace.STATE_START) 
    103                 { 
    104                         IdentitySelector.logMessage( "onStateChange", "flag & start"); 
    105                 } 
    106                  
    107                 if( aFlag & progListIFace.STATE_STOP) 
    108                 { 
    109                         IdentitySelector.logMessage( "onStateChange", "flag & stop"); 
    110                 } 
    111                  
    112                 // Process the document.  The 'STOP' state isn't reached until after 
    113                 // the page is fully loaded and all onload events have completed. 
    114                 // We need to re-process the page in case an onload event added 
    115                 // information card elements or objects to the page.  An example of  
    116                 // a page that does this is login.live.com. 
    117                  
    118                 if( aFlag & progListIFace.STATE_STOP) 
    119                 { 
    120                         if( aFlag & progListIFace.STATE_IS_WINDOW) 
    121                         { 
    122                                 IdentitySelector.logMessage( "onStateChange",  
    123                                         "stop status code = " + aStatus); 
    124                                          
    125                                 if( aStatus == 0) 
    126                                 { 
    127                                         // Process any information card items 
    128                                          
    129                                         try 
    130                                         { 
    131                                                 IdentitySelector.processICardItems(  
    132                                                         aProgress.DOMWindow.document, true); 
    133                                         } 
    134                                         catch( e) 
    135                                         { 
    136                                                 alert( e); 
    137                                         } 
    138                                 } 
    139                         } 
    140                 } 
    141                  
    142                 return( 0); 
    143         }, 
    144          
    145         onLocationChange : function( aProgress, aRequest, aURI) 
    146         { 
    147                 // This fires when a load event has been confirmed or when the 
    148                 // user switches tabs.  At this point, Firefox has created a skeletal 
    149                 // document into which the source document will be loaded.  This is  
    150                 // where we run our global intercept script. 
    151                  
    152                 try 
    153                 { 
    154                         IdentitySelector.runInterceptScript( aProgress.DOMWindow.document); 
    155                 } 
    156                 catch( e) 
    157                 { 
    158                         if( gDebugMode) 
    159                         { 
    160                                 IdentitySelector.reportError( "onLocationChange", e); 
    161                         } 
    162                 } 
    163                  
    164                 return( 0); 
    165         }, 
    166          
    167         onProgressChange : function() 
    168         { 
    169                 return( 0); 
    170         }, 
    171          
    172         onStatusChange : function() 
    173         { 
    174                 return( 0); 
    175         }, 
    176          
    177         onSecurityChange : function() 
    178         { 
    179                 return( 0); 
    180         }, 
    181          
    182         onLinkIconAvailable : function() 
    183         { 
    184                 return( 0); 
    185         } 
    186 }; 
    187  
    188 // ************************************************************************** 
    189 // Desc: 
    190 // ************************************************************************** 
    191  
    19255var IdentitySelector =  
    19356{ 
    19457        // *********************************************************************** 
    195         // Method: reportError 
    196         // *********************************************************************** 
    197          
    198         reportError : function( location, description) 
    199         { 
    200                 alert( "IdentitySelector Error:" + location + ": " + description); 
    201                 IdentitySelector.logMessage( location, "Error:" + description); 
    202         }, 
    203  
    204         // *********************************************************************** 
    205         // Method: throwError 
    206         // *********************************************************************** 
    207          
    208         throwError : function( location, description) 
    209         { 
    210                 IdentitySelector.reportError( location, description); 
    211                 throw( "IdentitySelector Exception:" + location + ": " + description); 
    212         }, 
    213          
    214         // *********************************************************************** 
    215         // Method: logMessage 
    216         // *********************************************************************** 
    217          
    218         logMessage : function( location, message)  
    219         { 
    220                 if( gbLoggingEnabled) 
    221                 { 
    222                         gConsoleService.logStringMessage( "IdentitySelector:" +  
    223                                 location + ": " + message); 
    224                 } 
    225         }, 
    226          
    227         // *********************************************************************** 
    228         // Method: dumpConsoleToLogFile 
    229         // *********************************************************************** 
    230          
    231         dumpConsoleLogToFile : function( filePath) 
    232         { 
    233                 var messageArray = {}; 
    234                 var messageCount = {}; 
    235                 var logBuffer = ""; 
    236                  
    237                 try 
    238                 { 
    239                         gConsoleService.getMessageArray( messageArray, messageCount); 
    240                          
    241                         for( var i = 0; i < messageCount.value; i++) 
    242                         { 
    243                                 var messageStr = messageArray.value[ i].message; 
    244                                  
    245                                 if( messageStr.indexOf( "IdentitySelector:") > -1) 
    246                                 { 
    247                                         logBuffer += messageStr + "\n"; 
    248                                 } 
    249                         } 
    250                          
    251                         if( gbIsMac || gbIsLinux) 
    252                         { 
    253                                 IdentitySelector.writeFile( "/tmp/icardxpi.log", logBuffer); 
    254                         } 
    255                 } 
    256                 catch( e) 
    257                 { 
    258                         IdentitySelector.reportError( "dumpConsoleLogToFile", e); 
    259                 } 
    260         }, 
    261  
    262         // *********************************************************************** 
    263         // Method: logPlatformInfo 
    264         // *********************************************************************** 
    265          
    266         logPlatformInfo : function() 
    267         { 
    268                 try 
    269                 { 
    270                         IdentitySelector.logMessage( "logPlatformInfo",  
    271                                 "platform = " + navigator.platform); 
    272                                  
    273                         IdentitySelector.logMessage( "logPlatformInfo",  
    274                                 "appName = " + navigator.appName); 
    275                                  
    276                         IdentitySelector.logMessage( "logPlatformInfo",  
    277                                 "appVersion = " + navigator.appVersion); 
    278                                  
    279                         IdentitySelector.logMessage( "logPlatformInfo",  
    280                                 "product = " + navigator.product); 
    281                                  
    282                         IdentitySelector.logMessage( "logPlatformInfo",  
    283                                 "productSub = " + navigator.productSub); 
    284                                  
    285                         IdentitySelector.logMessage( "logPlatformInfo",  
    286                                 "userAgent = " + navigator.userAgent); 
    287                                  
    288                         IdentitySelector.logMessage( "logPlatformInfo",  
    289                                 "oscpu = " + navigator.oscpu); 
    290                 } 
    291                 catch( e) 
    292                 { 
    293                 } 
    294         }, 
    295                          
    296         // *********************************************************************** 
    29758        // Method: onInstall 
    29859        // *********************************************************************** 
    … …  
    32485                        if( !handlerAlreadyInstalled) 
    32586                        { 
    326                                 var event = document.createEvent( "Event"); 
    327  
    328                                 event.initEvent( "IdentitySelectorAvailable", true, true); 
    329                                 top.dispatchEvent( event); 
    330                                  
    331                                 if( top.IdentitySelectorAvailable == true) 
     87                                var availEvent = document.createEvent( "Event"); 
     88 
     89                                availEvent.initEvent( "IdentitySelectorAvailable", true, true); 
     90                                top.dispatchEvent( availEvent); 
     91                                 
     92                                if( top.IdentitySelectorAvailable === true) 
    33293                                { 
    33394                                        handlerAlreadyInstalled = true; 
    … …  
    385146                        else 
    386147                        { 
    387                                 IdentitySelector.logMessage( "onInstall",  
     148                                IdentitySelectorDiag.logMessage( "onInstall",  
    388149                                        "Another identity selector is already installed."); 
    389150                        } 
    … …  
    391152                catch( e) 
    392153                { 
    393                         IdentitySelector.throwError( "onInstall", e); 
     154                        IdentitySelectorDiag.throwError( "onInstall", e); 
    394155                } 
    395156        }, 
    … …  
    444205                catch( e) 
    445206                { 
    446                         IdentitySelector.throwError( "onUninstall", e); 
     207                        IdentitySelectorDiag.throwError( "onUninstall", e); 
    447208                } 
    448209        }, 
    … …  
    459220                } 
    460221                 
    461                 if( doc.__identityselector__ == undefined) 
     222                if( doc.__identityselector__ === undefined) 
    462223                { 
    463224                        // Load and execute the script 
    … …  
    466227                                "@mozilla.org/moz/jssubscript-loader;1"].getService( 
    467228                                Components.interfaces.mozIJSSubScriptLoader).loadSubScript( 
    468                                 "chrome://identityselector/content/Intercept.js", doc) 
    469                          
    470                         IdentitySelector.logMessage( "runInterceptScript",  
     229                                "chrome://identityselector/content/Intercept.js", doc); 
     230                         
     231                        IdentitySelectorDiag.logMessage( "runInterceptScript",  
    471232                                "Executed script on " + doc.location); 
    472233                } 
    … …  
    488249                try 
    489250                { 
    490                         if( (doc = target.ownerDocument) == undefined) 
     251                        if( (doc = target.ownerDocument) === undefined) 
    491252                        { 
    492253                                return; 
    493254                        } 
    494255         
    495                         var event = doc.createEvent( "Event"); 
    496                         event.initEvent( "ICDOMChanged", true, true); 
    497                         target.dispatchEvent( event); 
     256                        var changedEvent = doc.createEvent( "Event"); 
     257                        changedEvent.initEvent( "ICDOMChanged", true, true); 
     258                        target.dispatchEvent( changedEvent); 
    498259                } 
    499260                catch( e) 
    … …  
    501262                        if( gDebugMode) 
    502263                        { 
    503                                 IdentitySelector.reportError( "onDOMChanged", e); 
     264                                IdentitySelectorDiag.reportError( "onDOMChanged", e); 
    504265                        } 
    505266                } 
    … …  
    529290                        // __identityselector__ should be defined. 
    530291                         
    531                         if( doc.__identityselector__ == undefined) 
     292                        if( doc.__identityselector__ === undefined) 
    532293                        { 
    533294                                // Since there are information card items on the page, warn 
    … …  
    536297                                // disabled. 
    537298                                 
    538                                 var jsEnabled = gPrefService.getBoolPref( "javascript.enabled"); 
    539                  
    540                                 // Warn if JavaScript is disabled 
    541                                  
    542                                 if( !jsEnabled) 
    543                                 { 
    544                                         IdentitySelector.reportError( "onProcessItems",  
     299                                if( !IdentitySelectorUtil.isJavaScriptEnabled()) 
     300                                { 
     301                                        IdentitySelectorDiag.reportError( "onProcessItems",  
    545302                                                "This page contains information card objects, but " + 
    546303                                                "JavaScript is disabled.  The information card " + 
    … …  
    550307                                else 
    551308                                { 
    552                                         IdentitySelector.reportError( "onProcessItems",  
     309                                        IdentitySelectorDiag.reportError( "onProcessItems",  
    553310                                                "This page contains information card objects, but " + 
    554311                                                "the information card selector was unable to fully " + 
    … …  
    579336                        if( gDebugMode) 
    580337                        { 
    581                                 IdentitySelector.reportError( "onProcessItems", e); 
     338                                IdentitySelectorDiag.reportError( "onProcessItems", e); 
    582339                        } 
    583340                } 
    … …  
    592349                try 
    593350                { 
     351                        var iLoop; 
    594352                        var itemCount = 0; 
    595353                         
    … …  
    599357                        var icardObjectCount = 0; 
    600358                         
    601                         IdentitySelector.logMessage( "processICardItems", "Found " +  
     359                        IdentitySelectorDiag.logMessage( "processICardItems", "Found " +  
    602360                                objElems.length + " object(s) on " + doc.location); 
    603361                                 
    604                         for( var i = 0; i < objElems.length; i++)  
    605                         { 
    606                                 var objElem = objElems[ i]; 
     362                        for( iLoop = 0; iLoop < objElems.length; iLoop++)  
     363                        { 
     364                                var objElem = objElems[ iLoop]; 
    607365                                var objTypeStr = objElem.getAttribute( "TYPE"); 
    608366                                 
    609                                 if( (objTypeStr != null &&  
     367                                if( (objTypeStr !== null &&  
    610368                                                objTypeStr.toLowerCase() == nsICardObjTypeStr) || 
    611369                                        objElem._type == nsICardObjTypeStr) 
    … …  
    622380                        } 
    623381                         
    624                         IdentitySelector.logMessage( "processICardItems", "Found " +  
     382                        IdentitySelectorDiag.logMessage( "processICardItems", "Found " +  
    625383                                icardObjectCount + " ICard object(s) on " + doc.location); 
    626384                                 
    … …  
    632390                        if( dispatchEvents) 
    633391                        { 
    634                                 for( var i = 0; i < icardElems.length; i++)  
    635                                 { 
    636                                         var icardElem = icardElems[ i]; 
    637                                          
    638                                         var event = doc.createEvent( "Event"); 
    639                                         event.initEvent( "ICElementLoaded", true, true); 
    640                                         icardElem.dispatchEvent( event); 
    641                                 } 
    642                         } 
    643                          
    644                         IdentitySelector.logMessage( "processICardItems", "Found " +  
     392                                for( iLoop = 0; iLoop < icardElems.length; iLoop++)  
     393                                { 
     394                                        var icardElem = icardElems[ iLoop]; 
     395                                        var elementEvent = doc.createEvent( "Event"); 
     396                                         
     397                                        elementEvent.initEvent( "ICElementLoaded", true, true); 
     398                                        icardElem.dispatchEvent( elementEvent); 
     399                                } 
     400                        } 
     401                         
     402                        IdentitySelectorDiag.logMessage( "processICardItems", "Found " +  
    645403                                icardElementCount + " ICard element(s) on " + doc.location); 
    646404                                 
    … …  
    651409                        if( gDebugMode)Â