Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: fpdfsdk/src/javascript/app.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/PublicMethods.cpp ('k') | fpdfsdk/src/javascript/color.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../../third_party/base/nonstd_unique_ptr.h"
8 #include "../../include/javascript/JavaScript.h" 8 #include "../../include/javascript/JavaScript.h"
9 #include "../../include/javascript/IJavaScript.h" 9 #include "../../include/javascript/IJavaScript.h"
10 #include "../../include/javascript/JS_Define.h" 10 #include "../../include/javascript/JS_Define.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 app::~app(void) 129 app::~app(void)
130 { 130 {
131 for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++) 131 for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
132 delete m_aTimer[i]; 132 delete m_aTimer[i];
133 133
134 m_aTimer.RemoveAll(); 134 m_aTimer.RemoveAll();
135 } 135 }
136 136
137 FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 137 bool app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sErro r)
138 { 138 {
139 if (!vp.IsGetting()) 139 if (!vp.IsGetting())
140 return FALSE; 140 return false;
141 141
142 CJS_Context* pContext = (CJS_Context *)cc; 142 CJS_Context* pContext = (CJS_Context *)cc;
143 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 143 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
144 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 144 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
145 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); 145 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
146 CJS_Array aDocs(pRuntime->GetIsolate()); 146 CJS_Array aDocs(pRuntime->GetIsolate());
147 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) 147 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
148 { 148 {
149 CJS_Document* pJSDocument = NULL; 149 CJS_Document* pJSDocument = NULL;
150 if (pDoc == pCurDoc) 150 if (pDoc == pCurDoc)
151 { 151 {
152 JSFXObject pObj = JS_GetThisObj(*pRuntime); 152 JSFXObject pObj = JS_GetThisObj(*pRuntime);
153 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document") ) 153 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document") )
154 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate( ),pObj); 154 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate( ),pObj);
155 } 155 }
156 else 156 else
157 { 157 {
158 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjD efnID(*pRuntime,L"Document")); 158 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjD efnID(*pRuntime,L"Document"));
159 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pO bj); 159 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pO bj);
160 ASSERT(pJSDocument != NULL); 160 ASSERT(pJSDocument != NULL);
161 } 161 }
162 aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); 162 aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
163 } 163 }
164 if (aDocs.GetLength() > 0) 164 if (aDocs.GetLength() > 0)
165 vp << aDocs; 165 vp << aDocs;
166 else 166 else
167 vp.SetNull(); 167 vp.SetNull();
168 168
169 return TRUE; 169 return true;
170 } 170 }
171 171
172 FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr ror) 172 bool app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError )
173 { 173 {
174 if (vp.IsSetting()) 174 if (vp.IsSetting())
175 { 175 {
176 bool bVP; 176 bool bVP;
177 vp >> bVP; 177 vp >> bVP;
178 » » m_bCalculate = (FX_BOOL)bVP; 178 » » m_bCalculate = (bool)bVP;
179 179
180 CJS_Context* pContext = (CJS_Context*)cc; 180 CJS_Context* pContext = (CJS_Context*)cc;
181 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 181 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
182 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 182 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
183 CJS_Array aDocs(pRuntime->GetIsolate()); 183 CJS_Array aDocs(pRuntime->GetIsolate());
184 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) 184 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
185 » » » pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalcul ate); 185 » » » pDoc->GetInterForm()->EnableCalculate((bool)m_bCalculate );
186 } 186 }
187 else 187 else
188 { 188 {
189 vp << (bool)m_bCalculate; 189 vp << (bool)m_bCalculate;
190 } 190 }
191 » return TRUE; 191 » return true;
192 } 192 }
193 193
194 FX_BOOL app::formsVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 194 bool app::formsVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr ror)
195 { 195 {
196 if (vp.IsGetting()) 196 if (vp.IsGetting())
197 { 197 {
198 vp << JS_NUM_FORMSVERSION; 198 vp << JS_NUM_FORMSVERSION;
199 » » return TRUE; 199 » » return true;
200 } 200 }
201 201
202 » return FALSE; 202 » return false;
203 } 203 }
204 204
205 FX_BOOL app::viewerType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 205 bool app::viewerType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sErro r)
206 { 206 {
207 if (vp.IsGetting()) 207 if (vp.IsGetting())
208 { 208 {
209 vp << L"unknown"; 209 vp << L"unknown";
210 » » return TRUE; 210 » » return true;
211 } 211 }
212 212
213 » return FALSE; 213 » return false;
214 } 214 }
215 215
216 FX_BOOL app::viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideStrin g& sError) 216 bool app::viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
217 { 217 {
218 if (vp.IsGetting()) 218 if (vp.IsGetting())
219 { 219 {
220 vp << JS_STR_VIEWERVARIATION; 220 vp << JS_STR_VIEWERVARIATION;
221 » » return TRUE; 221 » » return true;
222 } 222 }
223 223
224 » return FALSE; 224 » return false;
225 } 225 }
226 226
227 FX_BOOL app::viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 227 bool app::viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror)
228 { 228 {
229 if (vp.IsGetting()) 229 if (vp.IsGetting())
230 { 230 {
231 vp << JS_STR_VIEWERVERSION; 231 vp << JS_STR_VIEWERVERSION;
232 » » return TRUE; 232 » » return true;
233 } 233 }
234 234
235 » return FALSE; 235 » return false;
236 } 236 }
237 237
238 FX_BOOL app::platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sErr or) 238 bool app::platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
239 { 239 {
240 if (vp.IsGetting()) 240 if (vp.IsGetting())
241 { 241 {
242 vp << JS_STR_PLATFORM; 242 vp << JS_STR_PLATFORM;
243 » » return TRUE; 243 » » return true;
244 } 244 }
245 245
246 » return FALSE; 246 » return false;
247 } 247 }
248 248
249 FX_BOOL app::language(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sErr or) 249 bool app::language(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
250 { 250 {
251 if (vp.IsGetting()) 251 if (vp.IsGetting())
252 { 252 {
253 vp << JS_STR_LANGUANGE; 253 vp << JS_STR_LANGUANGE;
254 » » return TRUE; 254 » » return true;
255 } 255 }
256 256
257 » return FALSE; 257 » return false;
258 } 258 }
259 259
260 //creates a new fdf object that contains no data 260 //creates a new fdf object that contains no data
261 //comment: need reader support 261 //comment: need reader support
262 //note: 262 //note:
263 //CFDF_Document * CPDFDoc_Environment::NewFDF(); 263 //CFDF_Document * CPDFDoc_Environment::NewFDF();
264 FX_BOOL app::newFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 264 bool app::newFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRe t, CFX_WideString& sError)
265 { 265 {
266 » return TRUE; 266 » return true;
267 } 267 }
268 //opens a specified pdf document and returns its document object 268 //opens a specified pdf document and returns its document object
269 //comment:need reader support 269 //comment:need reader support
270 //note: as defined in js reference, the proto of this function's fourth parmeter s, how old an fdf document while do not show it. 270 //note: as defined in js reference, the proto of this function's fourth parmeter s, how old an fdf document while do not show it.
271 //CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv); 271 //CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
272 272
273 FX_BOOL app::openFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 273 bool app::openFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR et, CFX_WideString& sError)
274 { 274 {
275 » return TRUE; 275 » return true;
276 } 276 }
277 277
278 FX_BOOL app::alert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& v Ret, CFX_WideString& sError) 278 bool app::alert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet , CFX_WideString& sError)
279 { 279 {
280 int iSize = params.size(); 280 int iSize = params.size();
281 if (iSize < 1) 281 if (iSize < 1)
282 » » return FALSE; 282 » » return false;
283 283
284 CFX_WideString swMsg = L""; 284 CFX_WideString swMsg = L"";
285 CFX_WideString swTitle = L""; 285 CFX_WideString swTitle = L"";
286 int iIcon = 0; 286 int iIcon = 0;
287 int iType = 0; 287 int iType = 0;
288 288
289 v8::Isolate* isolate = GetIsolate(cc); 289 v8::Isolate* isolate = GetIsolate(cc);
290 290
291 if (iSize == 1) 291 if (iSize == 1)
292 { 292 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 delete pValue; 330 delete pValue;
331 } 331 }
332 } 332 }
333 333
334 if (swTitle == L"") 334 if (swTitle == L"")
335 swTitle = JSGetStringFromID((CJS_Context*)cc, ID S_STRING_JSALERT); 335 swTitle = JSGetStringFromID((CJS_Context*)cc, ID S_STRING_JSALERT);
336 } 336 }
337 else if (params[0].GetType() == VT_boolean) 337 else if (params[0].GetType() == VT_boolean)
338 { 338 {
339 » » » FX_BOOL bGet = params[0].ToBool(); 339 » » » bool bGet = params[0].ToBool();
340 if (bGet) 340 if (bGet)
341 swMsg = L"true"; 341 swMsg = L"true";
342 else 342 else
343 swMsg = L"false"; 343 swMsg = L"false";
344 344
345 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING _JSALERT); 345 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING _JSALERT);
346 } 346 }
347 else 347 else
348 { 348 {
349 swMsg = params[0].ToCFXWideString(); 349 swMsg = params[0].ToCFXWideString();
350 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING _JSALERT); 350 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING _JSALERT);
351 } 351 }
352 } 352 }
353 else 353 else
354 { 354 {
355 if (params[0].GetType() == VT_boolean) 355 if (params[0].GetType() == VT_boolean)
356 { 356 {
357 » » » FX_BOOL bGet = params[0].ToBool(); 357 » » » bool bGet = params[0].ToBool();
358 if (bGet) 358 if (bGet)
359 swMsg = L"true"; 359 swMsg = L"true";
360 else 360 else
361 swMsg = L"false"; 361 swMsg = L"false";
362 } 362 }
363 else 363 else
364 { 364 {
365 swMsg = params[0].ToCFXWideString(); 365 swMsg = params[0].ToCFXWideString();
366 } 366 }
367 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT ); 367 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT );
(...skipping 11 matching lines...) Expand all
379 379
380 380
381 CJS_Context* pContext = (CJS_Context*)cc; 381 CJS_Context* pContext = (CJS_Context*)cc;
382 ASSERT(pContext != NULL); 382 ASSERT(pContext != NULL);
383 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 383 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
384 ASSERT(pRuntime != NULL); 384 ASSERT(pRuntime != NULL);
385 pRuntime->BeginBlock(); 385 pRuntime->BeginBlock();
386 vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc), swMsg.c_str() , swTitle.c_str(), iType, iIcon); 386 vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc), swMsg.c_str() , swTitle.c_str(), iType, iIcon);
387 pRuntime->EndBlock(); 387 pRuntime->EndBlock();
388 388
389 » return TRUE; 389 » return true;
390 } 390 }
391 391
392 392
393 FX_BOOL app::beep(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR et, CFX_WideString& sError) 393 bool app::beep(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
394 { 394 {
395 if (params.size() == 1) 395 if (params.size() == 1)
396 { 396 {
397 CJS_Context* pContext = (CJS_Context*)cc; 397 CJS_Context* pContext = (CJS_Context*)cc;
398 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 398 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
399 CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp(); 399 CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
400 pEnv->JS_appBeep(params[0].ToInt()); 400 pEnv->JS_appBeep(params[0].ToInt());
401 » » return TRUE; 401 » » return true;
402 } 402 }
403 403
404 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); 404 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
405 » return FALSE; 405 » return false;
406 } 406 }
407 407
408 FX_BOOL app::findComponent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError) 408 bool app::findComponent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Val ue& vRet, CFX_WideString& sError)
409 { 409 {
410 » return TRUE; 410 » return true;
411 } 411 }
412 412
413 FX_BOOL app::popUpMenuEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError) 413 bool app::popUpMenuEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value & vRet, CFX_WideString& sError)
414 { 414 {
415 » return FALSE; 415 » return false;
416 } 416 }
417 417
418 FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 418 bool app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
419 { 419 {
420 » return FALSE; 420 » return false;
421 } 421 }
422 422
423 FX_BOOL app::setInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError) 423 bool app::setInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value & vRet, CFX_WideString& sError)
424 { 424 {
425 CJS_Context* pContext = (CJS_Context*)cc; 425 CJS_Context* pContext = (CJS_Context*)cc;
426 if (params.size() > 2 || params.size() == 0) 426 if (params.size() > 2 || params.size() == 0)
427 { 427 {
428 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 428 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
429 » » return FALSE; 429 » » return false;
430 } 430 }
431 431
432 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L""; 432 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
433 if (script.IsEmpty()) 433 if (script.IsEmpty())
434 { 434 {
435 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYST ROKE); 435 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYST ROKE);
436 » » return TRUE; 436 » » return true;
437 } 437 }
438 438
439 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 439 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
440 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; 440 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
441 441
442 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 442 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
443 ASSERT(pApp); 443 ASSERT(pApp);
444 CJS_Timer* pTimer = new CJS_Timer(this, pApp); 444 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
445 m_aTimer.Add(pTimer); 445 m_aTimer.Add(pTimer);
446 446
447 pTimer->SetType(0); 447 pTimer->SetType(0);
448 pTimer->SetRuntime(pRuntime); 448 pTimer->SetRuntime(pRuntime);
449 pTimer->SetJScript(script); 449 pTimer->SetJScript(script);
450 pTimer->SetTimeOut(0); 450 pTimer->SetTimeOut(0);
451 // pTimer->SetStartTime(GetTickCount()); 451 // pTimer->SetStartTime(GetTickCount());
452 pTimer->SetJSTimer(dwInterval); 452 pTimer->SetJSTimer(dwInterval);
453 453
454 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"TimerObj")); 454 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"TimerObj"));
455 455
456 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetI solate(),pRetObj); 456 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetI solate(),pRetObj);
457 ASSERT(pJS_TimerObj != NULL); 457 ASSERT(pJS_TimerObj != NULL);
458 458
459 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 459 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
460 ASSERT(pTimerObj != NULL); 460 ASSERT(pTimerObj != NULL);
461 461
462 pTimerObj->SetTimer(pTimer); 462 pTimerObj->SetTimer(pTimer);
463 463
464 vRet = pRetObj; 464 vRet = pRetObj;
465 465
466 » return TRUE; 466 » return true;
467 } 467 }
468 468
469 FX_BOOL app::setTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Val ue& vRet, CFX_WideString& sError) 469 bool app::setTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
470 { 470 {
471 if (params.size() > 2 || params.size() == 0) 471 if (params.size() > 2 || params.size() == 0)
472 { 472 {
473 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR); 473 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR);
474 » » return FALSE; 474 » » return false;
475 } 475 }
476 476
477 CJS_Context* pContext = (CJS_Context*)cc; 477 CJS_Context* pContext = (CJS_Context*)cc;
478 ASSERT(pContext != NULL); 478 ASSERT(pContext != NULL);
479 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 479 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
480 ASSERT(pRuntime != NULL); 480 ASSERT(pRuntime != NULL);
481 481
482 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L""; 482 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
483 if (script.IsEmpty()) 483 if (script.IsEmpty())
484 { 484 {
485 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMB ER_KEYSTROKE); 485 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMB ER_KEYSTROKE);
486 » » return TRUE; 486 » » return true;
487 } 487 }
488 488
489 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; 489 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
490 490
491 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 491 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
492 ASSERT(pApp); 492 ASSERT(pApp);
493 493
494 CJS_Timer* pTimer = new CJS_Timer(this, pApp); 494 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
495 m_aTimer.Add(pTimer); 495 m_aTimer.Add(pTimer);
496 496
497 pTimer->SetType(1); 497 pTimer->SetType(1);
498 pTimer->SetRuntime(pRuntime); 498 pTimer->SetRuntime(pRuntime);
499 pTimer->SetJScript(script); 499 pTimer->SetJScript(script);
500 pTimer->SetTimeOut(dwTimeOut); 500 pTimer->SetTimeOut(dwTimeOut);
501 pTimer->SetJSTimer(dwTimeOut); 501 pTimer->SetJSTimer(dwTimeOut);
502 502
503 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"TimerObj")); 503 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"TimerObj"));
504 504
505 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetI solate(),pRetObj); 505 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetI solate(),pRetObj);
506 ASSERT(pJS_TimerObj != NULL); 506 ASSERT(pJS_TimerObj != NULL);
507 507
508 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 508 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
509 ASSERT(pTimerObj != NULL); 509 ASSERT(pTimerObj != NULL);
510 510
511 pTimerObj->SetTimer(pTimer); 511 pTimerObj->SetTimer(pTimer);
512 512
513 vRet = pRetObj; 513 vRet = pRetObj;
514 514
515 » return TRUE; 515 » return true;
516 } 516 }
517 517
518 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) 518 bool app::clearTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError)
519 { 519 {
520 CJS_Context* pContext = (CJS_Context*)cc; 520 CJS_Context* pContext = (CJS_Context*)cc;
521 ASSERT(pContext != NULL); 521 ASSERT(pContext != NULL);
522 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 522 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
523 ASSERT(pRuntime != NULL); 523 ASSERT(pRuntime != NULL);
524 524
525 if (params.size() != 1) 525 if (params.size() != 1)
526 { 526 {
527 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR); 527 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR);
528 » » return FALSE; 528 » » return false;
529 } 529 }
530 530
531 if (params[0].GetType() == VT_fxobject) 531 if (params[0].GetType() == VT_fxobject)
532 { 532 {
533 JSFXObject pObj = params[0].ToV8Object(); 533 JSFXObject pObj = params[0].ToV8Object();
534 { 534 {
535 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) 535 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
536 { 536 {
537 if (CJS_Object* pJSObj = params[0].ToCJSObject() ) 537 if (CJS_Object* pJSObj = params[0].ToCJSObject() )
538 { 538 {
(...skipping 14 matching lines...) Expand all
553 553
554 delete pTimer; 554 delete pTimer;
555 pTimerObj->SetTimer(NULL ); 555 pTimerObj->SetTimer(NULL );
556 } 556 }
557 } 557 }
558 } 558 }
559 } 559 }
560 } 560 }
561 } 561 }
562 562
563 » return TRUE; 563 » return true;
564 } 564 }
565 565
566 FX_BOOL app::clearInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError) 566 bool app::clearInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Val ue& vRet, CFX_WideString& sError)
567 { 567 {
568 CJS_Context* pContext = (CJS_Context*)cc; 568 CJS_Context* pContext = (CJS_Context*)cc;
569 ASSERT(pContext != NULL); 569 ASSERT(pContext != NULL);
570 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 570 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
571 ASSERT(pRuntime != NULL); 571 ASSERT(pRuntime != NULL);
572 572
573 if (params.size() != 1) 573 if (params.size() != 1)
574 { 574 {
575 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR); 575 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR);
576 » » return FALSE; 576 » » return false;
577 } 577 }
578 578
579 if (params[0].GetType() == VT_fxobject) 579 if (params[0].GetType() == VT_fxobject)
580 { 580 {
581 JSFXObject pObj = params[0].ToV8Object(); 581 JSFXObject pObj = params[0].ToV8Object();
582 { 582 {
583 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) 583 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
584 { 584 {
585 if (CJS_Object* pJSObj = params[0].ToCJSObject() ) 585 if (CJS_Object* pJSObj = params[0].ToCJSObject() )
586 { 586 {
(...skipping 14 matching lines...) Expand all
601 601
602 delete pTimer; 602 delete pTimer;
603 pTimerObj->SetTimer(NULL ); 603 pTimerObj->SetTimer(NULL );
604 } 604 }
605 } 605 }
606 } 606 }
607 } 607 }
608 } 608 }
609 } 609 }
610 610
611 » return TRUE; 611 » return true;
612 } 612 }
613 613
614 FX_BOOL app::execMenuItem(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) 614 bool app::execMenuItem(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError)
615 { 615 {
616 » return FALSE; 616 » return false;
617 } 617 }
618 618
619 void app::TimerProc(CJS_Timer* pTimer) 619 void app::TimerProc(CJS_Timer* pTimer)
620 { 620 {
621 ASSERT(pTimer != NULL); 621 ASSERT(pTimer != NULL);
622 622
623 switch (pTimer->GetType()) 623 switch (pTimer->GetType())
624 { 624 {
625 case 0: //interval 625 case 0: //interval
626 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript()); 626 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
(...skipping 17 matching lines...) Expand all
644 { 644 {
645 IFXJS_Context* pContext = pRuntime->NewContext(); 645 IFXJS_Context* pContext = pRuntime->NewContext();
646 ASSERT(pContext != NULL); 646 ASSERT(pContext != NULL);
647 pContext->OnExternal_Exec(); 647 pContext->OnExternal_Exec();
648 CFX_WideString wtInfo; 648 CFX_WideString wtInfo;
649 pContext->RunScript(wsScript,wtInfo); 649 pContext->RunScript(wsScript,wtInfo);
650 pRuntime->ReleaseContext(pContext); 650 pRuntime->ReleaseContext(pContext);
651 } 651 }
652 } 652 }
653 653
654 FX_BOOL app::goBack(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 654 bool app::goBack(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRe t, CFX_WideString& sError)
655 { 655 {
656 // Not supported. 656 // Not supported.
657 return TRUE; 657 return true;
658 } 658 }
659 659
660 FX_BOOL app::goForward(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError) 660 bool app::goForward(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
661 { 661 {
662 // Not supported. 662 // Not supported.
663 return TRUE; 663 return true;
664 } 664 }
665 665
666 FX_BOOL app::mailMsg(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 666 bool app::mailMsg(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR et, CFX_WideString& sError)
667 { 667 {
668 CJS_Context* pContext = (CJS_Context*)cc; 668 CJS_Context* pContext = (CJS_Context*)cc;
669 v8::Isolate* isolate = GetIsolate(cc); 669 v8::Isolate* isolate = GetIsolate(cc);
670 670
671 » FX_BOOL bUI = TRUE; 671 » bool bUI = true;
672 CFX_WideString cTo = L""; 672 CFX_WideString cTo = L"";
673 CFX_WideString cCc = L""; 673 CFX_WideString cCc = L"";
674 CFX_WideString cBcc = L""; 674 CFX_WideString cBcc = L"";
675 CFX_WideString cSubject = L""; 675 CFX_WideString cSubject = L"";
676 CFX_WideString cMsg = L""; 676 CFX_WideString cMsg = L"";
677 677
678 if (params.size() < 1) 678 if (params.size() < 1)
679 » » return FALSE; 679 » » return false;
680 680
681 if (params[0].GetType() == VT_object) 681 if (params[0].GetType() == VT_object)
682 { 682 {
683 JSObject pObj = params[0].ToV8Object(); 683 JSObject pObj = params[0].ToV8Object();
684 684
685 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); 685 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI");
686 bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool( ); 686 bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool( );
687 687
688 pValue = JS_GetObjectElement(isolate, pObj, L"cTo"); 688 pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
689 cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWi deString(); 689 cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWi deString();
690 690
691 pValue = JS_GetObjectElement(isolate, pObj, L"cCc"); 691 pValue = JS_GetObjectElement(isolate, pObj, L"cCc");
692 cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWi deString(); 692 cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWi deString();
693 693
694 pValue = JS_GetObjectElement(isolate, pObj, L"cBcc"); 694 pValue = JS_GetObjectElement(isolate, pObj, L"cBcc");
695 cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXW ideString(); 695 cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXW ideString();
696 696
697 pValue = JS_GetObjectElement(isolate, pObj, L"cSubject"); 697 pValue = JS_GetObjectElement(isolate, pObj, L"cSubject");
698 cSubject = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).To CFXWideString(); 698 cSubject = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).To CFXWideString();
699 699
700 pValue = JS_GetObjectElement(isolate, pObj, L"cMsg"); 700 pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
701 cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXW ideString(); 701 cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXW ideString();
702 } else { 702 } else {
703 if (params.size() < 2) 703 if (params.size() < 2)
704 » » » return FALSE; 704 » » » return false;
705 705
706 bUI = params[0].ToBool(); 706 bUI = params[0].ToBool();
707 cTo = params[1].ToCFXWideString(); 707 cTo = params[1].ToCFXWideString();
708 708
709 if (params.size() >= 3) 709 if (params.size() >= 3)
710 cCc = params[2].ToCFXWideString(); 710 cCc = params[2].ToCFXWideString();
711 if (params.size() >= 4) 711 if (params.size() >= 4)
712 cBcc = params[3].ToCFXWideString(); 712 cBcc = params[3].ToCFXWideString();
713 if (params.size() >= 5) 713 if (params.size() >= 5)
714 cSubject = params[4].ToCFXWideString(); 714 cSubject = params[4].ToCFXWideString();
715 if (params.size() >= 6) 715 if (params.size() >= 6)
716 cMsg = params[5].ToCFXWideString(); 716 cMsg = params[5].ToCFXWideString();
717 } 717 }
718 718
719 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 719 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
720 ASSERT(pRuntime != NULL); 720 ASSERT(pRuntime != NULL);
721 721
722 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 722 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
723 ASSERT(pApp != NULL); 723 ASSERT(pApp != NULL);
724 724
725 pRuntime->BeginBlock(); 725 pRuntime->BeginBlock();
726 pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_ str(), cBcc.c_str(), cMsg.c_str()); 726 pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_ str(), cBcc.c_str(), cMsg.c_str());
727 pRuntime->EndBlock(); 727 pRuntime->EndBlock();
728 728
729 » return FALSE; 729 » return false;
730 } 730 }
731 731
732 FX_BOOL app::launchURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError) 732 bool app::launchURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
733 { 733 {
734 // Unsafe, not supported. 734 // Unsafe, not supported.
735 return TRUE; 735 return true;
736 } 736 }
737 737
738 FX_BOOL app::runtimeHighlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideStri ng& sError) 738 bool app::runtimeHighlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
739 { 739 {
740 if (vp.IsSetting()) 740 if (vp.IsSetting())
741 { 741 {
742 vp>>m_bRuntimeHighLight; 742 vp>>m_bRuntimeHighLight;
743 } 743 }
744 else 744 else
745 { 745 {
746 vp<<m_bRuntimeHighLight; 746 vp<<m_bRuntimeHighLight;
747 } 747 }
748 748
749 » return TRUE; 749 » return true;
750 } 750 }
751 751
752 FX_BOOL app::fullscreen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 752 bool app::fullscreen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sErro r)
753 { 753 {
754 » return FALSE; 754 » return false;
755 } 755 }
756 756
757 FX_BOOL app::popUpMenu(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError) 757 bool app::popUpMenu(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
758 { 758 {
759 » return FALSE; 759 » return false;
760 } 760 }
761 761
762 762
763 FX_BOOL app::browseForDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) 763 bool app::browseForDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError)
764 { 764 {
765 // Unsafe, not supported. 765 // Unsafe, not supported.
766 return TRUE; 766 return true;
767 } 767 }
768 768
769 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) 769 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)
770 { 770 {
771 CFX_WideString sRet = L"/"; 771 CFX_WideString sRet = L"/";
772 772
773 for (int i=0,sz=sOldPath.GetLength(); i<sz; i++) 773 for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)
774 { 774 {
775 wchar_t c = sOldPath.GetAt(i); 775 wchar_t c = sOldPath.GetAt(i);
776 if (c == L':') 776 if (c == L':')
777 { 777 {
778 } 778 }
779 else 779 else
780 { 780 {
781 if (c == L'\\') 781 if (c == L'\\')
782 { 782 {
783 sRet += L"/"; 783 sRet += L"/";
784 } 784 }
785 else 785 else
786 { 786 {
787 sRet += c; 787 sRet += c;
788 } 788 }
789 } 789 }
790 } 790 }
791 791
792 return sRet; 792 return sRet;
793 } 793 }
794 794
795 FX_BOOL app::newDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 795 bool app::newDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRe t, CFX_WideString& sError)
796 { 796 {
797 » return FALSE; 797 » return false;
798 } 798 }
799 799
800 FX_BOOL app::openDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 800 bool app::openDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR et, CFX_WideString& sError)
801 { 801 {
802 » return FALSE; 802 » return false;
803 } 803 }
804 804
805 FX_BOOL app::response(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value & vRet, CFX_WideString& sError) 805 bool app::response(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& v Ret, CFX_WideString& sError)
806 { 806 {
807 CFX_WideString swQuestion = L""; 807 CFX_WideString swQuestion = L"";
808 CFX_WideString swLabel = L""; 808 CFX_WideString swLabel = L"";
809 CFX_WideString swTitle = L"PDF"; 809 CFX_WideString swTitle = L"PDF";
810 CFX_WideString swDefault = L""; 810 CFX_WideString swDefault = L"";
811 bool bPassWord = false; 811 bool bPassWord = false;
812 812
813 v8::Isolate* isolate = GetIsolate(cc); 813 v8::Isolate* isolate = GetIsolate(cc);
814 814
815 int iLength = params.size(); 815 int iLength = params.size();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); 866 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
867 int nLengthBytes = pApp->JS_appResponse(swQuestion.c_str(), 867 int nLengthBytes = pApp->JS_appResponse(swQuestion.c_str(),
868 swTitle.c_str(), 868 swTitle.c_str(),
869 swDefault.c_str(), 869 swDefault.c_str(),
870 swLabel.c_str(), 870 swLabel.c_str(),
871 bPassWord, 871 bPassWord,
872 pBuff.get(), 872 pBuff.get(),
873 MAX_INPUT_BYTES); 873 MAX_INPUT_BYTES);
874 if (nLengthBytes <= 0) { 874 if (nLengthBytes <= 0) {
875 vRet.SetNull(); 875 vRet.SetNull();
876 return FALSE; 876 return false;
877 } 877 }
878 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES); 878 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
879 879
880 CFX_WideString ret_string = 880 CFX_WideString ret_string =
881 CFX_WideString::FromUTF16LE((unsigned short*)pBuff.get(), 881 CFX_WideString::FromUTF16LE((unsigned short*)pBuff.get(),
882 nLengthBytes / sizeof(unsigned short)); 882 nLengthBytes / sizeof(unsigned short));
883 vRet = ret_string.c_str(); 883 vRet = ret_string.c_str();
884 return TRUE; 884 return true;
885 } 885 }
886 886
887 FX_BOOL app::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 887 bool app::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
888 { 888 {
889 » return FALSE; 889 » return false;
890 } 890 }
891 891
892 FX_BOOL app::execDialog(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Val ue& vRet, CFX_WideString& sError) 892 bool app::execDialog(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
893 { 893 {
894 » return TRUE; 894 » return true;
895 } 895 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/PublicMethods.cpp ('k') | fpdfsdk/src/javascript/color.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698