| OLD | NEW |
| 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 "global.h" | 7 #include "global.h" |
| 8 | 8 |
| 9 #include "../../../core/include/fxcrt/fx_ext.h" | 9 #include "../../../core/include/fxcrt/fx_ext.h" |
| 10 #include "../../include/javascript/IJavaScript.h" | 10 #include "../../include/javascript/IJavaScript.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 BEGIN_JS_STATIC_PROP(CJS_Global) | 81 BEGIN_JS_STATIC_PROP(CJS_Global) |
| 82 END_JS_STATIC_PROP() | 82 END_JS_STATIC_PROP() |
| 83 | 83 |
| 84 BEGIN_JS_STATIC_METHOD(CJS_Global) | 84 BEGIN_JS_STATIC_METHOD(CJS_Global) |
| 85 JS_STATIC_METHOD_ENTRY(setPersistent) | 85 JS_STATIC_METHOD_ENTRY(setPersistent) |
| 86 END_JS_STATIC_METHOD() | 86 END_JS_STATIC_METHOD() |
| 87 | 87 |
| 88 IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, JSGlobalAlternate, global); | 88 IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, JSGlobalAlternate, global); |
| 89 | 89 |
| 90 FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc) { | 90 FX_BOOL CJS_Global::InitInstance(IJS_Context* cc) { |
| 91 CJS_Context* pContext = (CJS_Context*)cc; | 91 CJS_Context* pContext = (CJS_Context*)cc; |
| 92 ASSERT(pContext != NULL); | 92 ASSERT(pContext != NULL); |
| 93 | 93 |
| 94 JSGlobalAlternate* pGlobal = (JSGlobalAlternate*)GetEmbedObject(); | 94 JSGlobalAlternate* pGlobal = (JSGlobalAlternate*)GetEmbedObject(); |
| 95 ASSERT(pGlobal != NULL); | 95 ASSERT(pGlobal != NULL); |
| 96 | 96 |
| 97 pGlobal->Initial(pContext->GetReaderApp()); | 97 pGlobal->Initial(pContext->GetReaderApp()); |
| 98 | 98 |
| 99 return TRUE; | 99 return TRUE; |
| 100 }; | 100 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 void JSGlobalAlternate::Initial(CPDFDoc_Environment* pApp) { | 111 void JSGlobalAlternate::Initial(CPDFDoc_Environment* pApp) { |
| 112 m_pApp = pApp; | 112 m_pApp = pApp; |
| 113 m_pGlobalData = CJS_GlobalData::GetRetainedInstance(pApp); | 113 m_pGlobalData = CJS_GlobalData::GetRetainedInstance(pApp); |
| 114 UpdateGlobalPersistentVariables(); | 114 UpdateGlobalPersistentVariables(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 FX_BOOL JSGlobalAlternate::QueryProperty(const FX_WCHAR* propname) { | 117 FX_BOOL JSGlobalAlternate::QueryProperty(const FX_WCHAR* propname) { |
| 118 return CFX_WideString(propname) != L"setPersistent"; | 118 return CFX_WideString(propname) != L"setPersistent"; |
| 119 } | 119 } |
| 120 | 120 |
| 121 FX_BOOL JSGlobalAlternate::DelProperty(IFXJS_Context* cc, | 121 FX_BOOL JSGlobalAlternate::DelProperty(IJS_Context* cc, |
| 122 const FX_WCHAR* propname, | 122 const FX_WCHAR* propname, |
| 123 CFX_WideString& sError) { | 123 CFX_WideString& sError) { |
| 124 auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); | 124 auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); |
| 125 if (it == m_mapGlobal.end()) | 125 if (it == m_mapGlobal.end()) |
| 126 return FALSE; | 126 return FALSE; |
| 127 | 127 |
| 128 it->second->bDeleted = TRUE; | 128 it->second->bDeleted = TRUE; |
| 129 return TRUE; | 129 return TRUE; |
| 130 } | 130 } |
| 131 | 131 |
| 132 FX_BOOL JSGlobalAlternate::DoProperty(IFXJS_Context* cc, | 132 FX_BOOL JSGlobalAlternate::DoProperty(IJS_Context* cc, |
| 133 const FX_WCHAR* propname, | 133 const FX_WCHAR* propname, |
| 134 CJS_PropValue& vp, | 134 CJS_PropValue& vp, |
| 135 CFX_WideString& sError) { | 135 CFX_WideString& sError) { |
| 136 if (vp.IsSetting()) { | 136 if (vp.IsSetting()) { |
| 137 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); | 137 CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); |
| 138 switch (vp.GetType()) { | 138 switch (vp.GetType()) { |
| 139 case CJS_Value::VT_number: { | 139 case CJS_Value::VT_number: { |
| 140 double dData; | 140 double dData; |
| 141 vp >> dData; | 141 vp >> dData; |
| 142 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData, | 142 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 case JS_GLOBALDATA_TYPE_NULL: | 201 case JS_GLOBALDATA_TYPE_NULL: |
| 202 vp.SetNull(); | 202 vp.SetNull(); |
| 203 return TRUE; | 203 return TRUE; |
| 204 default: | 204 default: |
| 205 break; | 205 break; |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 return FALSE; | 208 return FALSE; |
| 209 } | 209 } |
| 210 | 210 |
| 211 FX_BOOL JSGlobalAlternate::setPersistent(IFXJS_Context* cc, | 211 FX_BOOL JSGlobalAlternate::setPersistent(IJS_Context* cc, |
| 212 const CJS_Parameters& params, | 212 const CJS_Parameters& params, |
| 213 CJS_Value& vRet, | 213 CJS_Value& vRet, |
| 214 CFX_WideString& sError) { | 214 CFX_WideString& sError) { |
| 215 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 215 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 216 if (params.size() != 2) { | 216 if (params.size() != 2) { |
| 217 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 217 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 218 return FALSE; | 218 return FALSE; |
| 219 } | 219 } |
| 220 | 220 |
| 221 auto it = m_mapGlobal.find(params[0].ToCFXByteString()); | 221 auto it = m_mapGlobal.find(params[0].ToCFXByteString()); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 return CJS_Value::VT_boolean; | 524 return CJS_Value::VT_boolean; |
| 525 if (nHash == JSCONST_nDateHash) | 525 if (nHash == JSCONST_nDateHash) |
| 526 return CJS_Value::VT_date; | 526 return CJS_Value::VT_date; |
| 527 if (nHash == JSCONST_nObjectHash) | 527 if (nHash == JSCONST_nObjectHash) |
| 528 return CJS_Value::VT_object; | 528 return CJS_Value::VT_object; |
| 529 if (nHash == JSCONST_nFXobjHash) | 529 if (nHash == JSCONST_nFXobjHash) |
| 530 return CJS_Value::VT_fxobject; | 530 return CJS_Value::VT_fxobject; |
| 531 | 531 |
| 532 return CJS_Value::VT_unknown; | 532 return CJS_Value::VT_unknown; |
| 533 } | 533 } |
| OLD | NEW |