Back to index

lightning-sunbird  0.9+nobinonly
scrpthlp.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "xp.h"
00039 
00040 #include "scrpthlp.h"
00041 #include "profile.h"
00042 #include "strconv.h"
00043 
00044 static char szDefaultString[] = PROFILE_DEFAULT_STRING;
00045 
00046 static void makeDataEntry(ScriptArgumentStruct * psas, DWORD dwArgument, int iSize)
00047 {
00048   if((dwArgument != 0L) && (dwArgument != DEFAULT_DWARG_VALUE) && (iSize > 0))
00049   {
00050     psas->iLength = iSize;
00051     char * p = new char[psas->iLength];
00052     memcpy(p, (LPVOID)dwArgument, psas->iLength);
00053     psas->dwArg = (DWORD)p;
00054   }
00055   else
00056   {
00057     psas->iLength = 0;
00058     psas->dwArg = dwArgument;
00059   }
00060 }
00061 
00062 ScriptItemStruct * makeScriptItemStruct(NPAPI_Action action, DWORD dw1, DWORD dw2, 
00063                                         DWORD dw3, DWORD dw4, DWORD dw5, DWORD dw6, 
00064                                         DWORD dw7, DWORD dwDelay)
00065 {
00066   ScriptItemStruct * psis = new ScriptItemStruct;
00067   if(psis == NULL)
00068     return NULL;
00069 
00070   psis->dwDelay = (dwDelay >= 0L) ? dwDelay : 0L;
00071   psis->action = action;
00072   psis->arg1.dwArg = dw1;
00073   psis->arg2.dwArg = dw2;
00074   psis->arg3.dwArg = dw3;
00075   psis->arg4.dwArg = dw4;
00076   psis->arg5.dwArg = dw5;
00077   psis->arg6.dwArg = dw6;
00078   psis->arg7.dwArg = dw7;
00079 
00080   DWORD dwTNVFlags = 0L;
00081 
00082   switch (action)
00083   {
00084     case action_invalid:
00085       break;
00086     case action_npn_version:
00087       convertStringToDWORD4(&psis->arg1.dwArg, &psis->arg2.dwArg, &psis->arg3.dwArg, &psis->arg4.dwArg);
00088       break;
00089     case action_npn_get_url:
00090       convertStringToDWORD1(&psis->arg1.dwArg);
00091       dwTNVFlags = convertStringToLPSTR2(&dw2, &dw3);
00092       makeDataEntry(&psis->arg2, dw2, (dwTNVFlags & fTNV1) ? 0 : strlen((LPSTR)dw2) + 1);
00093       makeDataEntry(&psis->arg3, dw3, (dwTNVFlags & fTNV2) ? 0 : strlen((LPSTR)dw3) + 1);
00094       break;
00095     case action_npn_get_url_notify:
00096       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg4.dwArg);
00097       dwTNVFlags = convertStringToLPSTR2(&dw2, &dw3);
00098       makeDataEntry(&psis->arg2, dw2, (dwTNVFlags & fTNV1) ? 0 : strlen((LPSTR)dw2) + 1);
00099       makeDataEntry(&psis->arg3, dw3, (dwTNVFlags & fTNV2) ? 0 : strlen((LPSTR)dw3) + 1);
00100       break;
00101     case action_npn_post_url:
00102     {
00103       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg4.dwArg);
00104       dwTNVFlags = convertStringToLPSTR3(&dw2, &dw3, &dw5);
00105       convertStringToBOOL1(&psis->arg6.dwArg);
00106       makeDataEntry(&psis->arg2, dw2, (dwTNVFlags & fTNV1) ? 0 : strlen((LPSTR)dw2) + 1);
00107       makeDataEntry(&psis->arg3, dw3, (dwTNVFlags & fTNV2) ? 0 : strlen((LPSTR)dw3) + 1);
00108 
00109       int iSize;
00110       if(dwTNVFlags & fTNV3)
00111         iSize = 0;
00112       else
00113         if(psis->arg5.dwArg == DEFAULT_DWARG_VALUE)
00114         {
00115           iSize = strlen((LPSTR)dw5) + 1;
00116           psis->arg5.dwArg = iSize - 1;
00117         }
00118         else
00119           iSize = psis->arg5.dwArg;
00120 
00121       makeDataEntry(&psis->arg5, dw5, (dwTNVFlags & fTNV3) ? 0 : strlen((LPSTR)dw5) + 1);
00122       break;
00123     }
00124     case action_npn_post_url_notify:
00125     {
00126       convertStringToDWORD3(&psis->arg1.dwArg, &psis->arg4.dwArg, &psis->arg7.dwArg);
00127       dwTNVFlags = convertStringToLPSTR3(&dw2, &dw3, &dw5);
00128       convertStringToBOOL1(&psis->arg6.dwArg);
00129       makeDataEntry(&psis->arg2, dw2, (dwTNVFlags & fTNV1) ? 0 : strlen((LPSTR)dw2) + 1);
00130       makeDataEntry(&psis->arg3, dw3, (dwTNVFlags & fTNV2) ? 0 : strlen((LPSTR)dw3) + 1);
00131 
00132       int iSize;
00133       if(dwTNVFlags & fTNV3)
00134         iSize = 0;
00135       else
00136         if(psis->arg5.dwArg == DEFAULT_DWARG_VALUE)
00137         {
00138           iSize = strlen((LPSTR)dw5) + 1;
00139           psis->arg5.dwArg = iSize - 1;
00140         }
00141         else
00142           iSize = psis->arg5.dwArg;
00143 
00144       makeDataEntry(&psis->arg5, dw5, (dwTNVFlags & fTNV3) ? 0 : strlen((LPSTR)dw5) + 1);
00145       break;
00146     }
00147     case action_npn_new_stream:
00148       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg4.dwArg);
00149       dwTNVFlags = convertStringToLPSTR2(&dw2, &dw3);
00150       makeDataEntry(&psis->arg2, dw2, (dwTNVFlags & fTNV1) ? 0 : strlen((LPSTR)dw2) + 1);
00151       makeDataEntry(&psis->arg3, dw3, (dwTNVFlags & fTNV2) ? 0 : strlen((LPSTR)dw3) + 1);
00152       break;
00153     case action_npn_destroy_stream:
00154       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg2.dwArg);
00155       convertStringToNPReason1(&psis->arg3.dwArg);
00156       break;
00157     case action_npn_request_read:
00158       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg2.dwArg);
00159       break;
00160     case action_npn_write:
00161     {
00162       convertStringToDWORD3(&psis->arg1.dwArg, &psis->arg2.dwArg, &psis->arg3.dwArg);
00163       dwTNVFlags = convertStringToLPSTR1(&dw4);
00164 
00165       int iSize;
00166       if(dwTNVFlags & fTNV1)
00167         iSize = 0;
00168       else
00169         if(psis->arg3.dwArg == DEFAULT_DWARG_VALUE)
00170         {
00171           iSize = strlen((LPSTR)dw4) + 1;
00172           psis->arg3.dwArg = iSize - 1;
00173         }
00174         else
00175           iSize = psis->arg3.dwArg;
00176 
00177       makeDataEntry(&psis->arg4, dw4, iSize);
00178       break;
00179     }
00180     case action_npn_status:
00181       convertStringToDWORD1(&psis->arg1.dwArg);
00182       dwTNVFlags = convertStringToLPSTR1(&dw2);
00183       makeDataEntry(&psis->arg2, dw2, (dwTNVFlags & fTNV1) ? 0 : strlen((LPSTR)dw2) + 1);
00184       break;
00185 
00186     case action_npn_user_agent:
00187     case action_npn_mem_alloc:
00188     case action_npn_mem_free:
00189     case action_npn_mem_flush:
00190     case action_npn_get_java_peer:
00191       convertStringToDWORD1(&psis->arg1.dwArg);
00192       break;
00193 
00194     case action_npn_reload_plugins:
00195       convertStringToBOOL1(&psis->arg1.dwArg);
00196       break;
00197     case action_npn_get_java_env:
00198       break;
00199     case action_npn_get_value:
00200       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg3.dwArg);
00201       convertStringToNPNVariable1(&psis->arg2.dwArg);
00202       break;
00203     case action_npn_set_value:
00204     {
00205       convertStringToDWORD1(&psis->arg1.dwArg);
00206       convertStringToNPPVariable1(&psis->arg2.dwArg);
00207       NPPVariable nppVar = (NPPVariable)psis->arg2.dwArg;
00208 
00209       switch (nppVar)
00210       {
00211         case NPPVpluginNameString:
00212         case NPPVpluginDescriptionString:
00213           dwTNVFlags = convertStringToLPSTR1(&dw3);
00214           makeDataEntry(&psis->arg3, dw3, (dwTNVFlags & fTNV1) ? 0 : strlen((LPSTR)dw3) + 1);
00215           break;
00216         case NPPVpluginWindowBool:
00217         case NPPVpluginTransparentBool:
00218         case NPPVpluginKeepLibraryInMemory:
00219           dwTNVFlags = convertStringToBOOL1(&dw3);
00220           makeDataEntry(&psis->arg3, dw3, (dwTNVFlags & fTNV1) ? 0 : sizeof(NPBool));
00221           break;
00222         case NPPVpluginWindowSize:
00223         {
00224           int iDataSize = 0;
00225           static NPSize npsize;
00226  
00227           convertStringToDWORD1(&psis->arg3.dwArg);
00228 
00229           if(psis->arg3.dwArg == DEFAULT_DWARG_VALUE)
00230           {
00231             npsize.width  = dw4;
00232             npsize.height = dw5;
00233             dw3 = (DWORD)&npsize;
00234             iDataSize = sizeof(NPSize);
00235           }
00236           makeDataEntry(&psis->arg3, dw3, iDataSize);
00237           break;
00238         }
00239         default:
00240           break;
00241       }
00242       break;
00243     }
00244     case action_npn_invalidate_rect:
00245     {
00246       int iDataSize = 0;
00247       static NPRect nprect;
00248 
00249       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg2.dwArg);
00250 
00251       if(psis->arg2.dwArg == DEFAULT_DWARG_VALUE)
00252       {
00253         nprect.top    = (int)dw3;
00254         nprect.left   = (int)dw4;
00255         nprect.bottom = (int)dw5;
00256         nprect.right  = (int)dw6;
00257         dw2 = (DWORD)&nprect;
00258         iDataSize = sizeof(NPSize);
00259       }
00260       makeDataEntry(&psis->arg2, dw2, iDataSize);
00261       break;
00262     }
00263     case action_npn_invalidate_region:
00264       convertStringToDWORD2(&psis->arg1.dwArg, &psis->arg2.dwArg);
00265       break;
00266     case action_npn_force_redraw:
00267       convertStringToDWORD1(&psis->arg1.dwArg);
00268       break;
00269 
00270     default:
00271       break;
00272   }
00273 
00274   return psis;
00275 }