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

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

Issue 971013002: Merge to XFA: Return error information from pdfium to JS. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 9 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/include/jsapi/fxjs_v8.h ('k') | fpdfsdk/src/javascript/console.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 "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
11 #include "../../include/javascript/JS_Value.h" 11 #include "../../include/javascript/JS_Value.h"
12 #include "../../include/javascript/Document.h" 12 #include "../../include/javascript/Document.h"
13 #include "../../include/javascript/JS_EventHandler.h" 13 #include "../../include/javascript/JS_EventHandler.h"
14 #include "../../include/javascript/JS_Context.h" 14 #include "../../include/javascript/JS_Context.h"
15 #include "../../include/javascript/JS_Runtime.h" 15 #include "../../include/javascript/JS_Runtime.h"
16 #include "../../include/javascript/app.h" 16 #include "../../include/javascript/app.h"
17 #include "../../include/javascript/Field.h" 17 #include "../../include/javascript/Field.h"
18 #include "../../include/javascript/Icon.h" 18 #include "../../include/javascript/Icon.h"
19 #include "../../include/javascript/Field.h" 19 #include "../../include/javascript/resource.h"
20 20
21 #include "../../../third_party/base/numerics/safe_math.h" 21 #include "../../../third_party/base/numerics/safe_math.h"
22 22
23 static v8::Isolate* GetIsolate(IFXJS_Context* cc) 23 static v8::Isolate* GetIsolate(IFXJS_Context* cc)
24 { 24 {
25 CJS_Context* pContext = (CJS_Context *)cc; 25 CJS_Context* pContext = (CJS_Context *)cc;
26 ASSERT(pContext != NULL); 26 ASSERT(pContext != NULL);
27 27
28 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 28 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
29 ASSERT(pRuntime != NULL); 29 ASSERT(pRuntime != NULL);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 185 }
186 } 186 }
187 187
188 m_DelayData.RemoveAll(); 188 m_DelayData.RemoveAll();
189 m_DelayAnnotData.RemoveAll(); 189 m_DelayAnnotData.RemoveAll();
190 } 190 }
191 191
192 //the total number of fileds in document. 192 //the total number of fileds in document.
193 FX_BOOL Document::numFields(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString & sError) 193 FX_BOOL Document::numFields(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString & sError)
194 { 194 {
195 » if (!vp.IsGetting()) return FALSE; 195 » if (vp.IsSetting()) {
196 196 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
197 » ASSERT(m_pDocument != NULL); 197 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
198 198 » » return FALSE;
199 » }
199 CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm(); 200 CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
200 ASSERT(pInterForm != NULL);
201
202 CPDF_InterForm *pPDFForm = pInterForm->GetInterForm(); 201 CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
203 ASSERT(pPDFForm != NULL);
204
205 vp << (int)pPDFForm->CountFields(); 202 vp << (int)pPDFForm->CountFields();
206
207 return TRUE; 203 return TRUE;
208 } 204 }
209 205
210 FX_BOOL Document::dirty(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sE rror) 206 FX_BOOL Document::dirty(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sE rror)
211 { 207 {
212 ASSERT(m_pDocument != NULL); 208 ASSERT(m_pDocument != NULL);
213 209
214 if (vp.IsGetting()) 210 if (vp.IsGetting())
215 { 211 {
216 if (m_pDocument->GetChangeMark()) 212 if (m_pDocument->GetChangeMark())
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 CFX_WideString cwTitle = pDictionary->GetUnicodeText("T itle"); 867 CFX_WideString cwTitle = pDictionary->GetUnicodeText("T itle");
872 CFX_WideString cwSubject = pDictionary->GetUnicodeText("S ubject"); 868 CFX_WideString cwSubject = pDictionary->GetUnicodeText("S ubject");
873 CFX_WideString cwKeywords = pDictionary->GetUnicodeText("K eywords"); 869 CFX_WideString cwKeywords = pDictionary->GetUnicodeText("K eywords");
874 CFX_WideString cwCreator = pDictionary->GetUnicodeText("C reator"); 870 CFX_WideString cwCreator = pDictionary->GetUnicodeText("C reator");
875 CFX_WideString cwProducer = pDictionary->GetUnicodeText("P roducer"); 871 CFX_WideString cwProducer = pDictionary->GetUnicodeText("P roducer");
876 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationD ate"); 872 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationD ate");
877 CFX_WideString cwModDate = pDictionary->GetUnicodeText("M odDate"); 873 CFX_WideString cwModDate = pDictionary->GetUnicodeText("M odDate");
878 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("T rapped"); 874 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("T rapped");
879 875
880 v8::Isolate* isolate = GetIsolate(cc); 876 v8::Isolate* isolate = GetIsolate(cc);
881 » if (!vp.IsSetting()) 877 » if (vp.IsGetting())
882 { 878 {
883 CJS_Context* pContext = (CJS_Context *)cc; 879 CJS_Context* pContext = (CJS_Context *)cc;
884 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 880 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
885 881
886 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1); 882 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
887 883
888 JS_PutObjectString(isolate,pObj, L"Author", cwAuthor); 884 JS_PutObjectString(isolate,pObj, L"Author", cwAuthor);
889 JS_PutObjectString(isolate,pObj, L"Title", cwTitle); 885 JS_PutObjectString(isolate,pObj, L"Title", cwTitle);
890 JS_PutObjectString(isolate,pObj, L"Subject", cwSubject); 886 JS_PutObjectString(isolate,pObj, L"Subject", cwSubject);
891 JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords); 887 JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 CFX_WideString cstitle; 1124 CFX_WideString cstitle;
1129 vp >> cstitle; 1125 vp >> cstitle;
1130 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); 1126 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
1131 m_pDocument->SetChangeMark(); 1127 m_pDocument->SetChangeMark();
1132 return TRUE; 1128 return TRUE;
1133 } 1129 }
1134 } 1130 }
1135 1131
1136 FX_BOOL Document::numPages(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sError) 1132 FX_BOOL Document::numPages(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sError)
1137 { 1133 {
1138 » if (vp.IsGetting()) 1134 » if (vp.IsSetting()) {
1139 » { 1135 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1140 » » ASSERT(m_pDocument != NULL); 1136 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1141 » » vp << m_pDocument->GetPageCount();
1142 » » return TRUE;
1143 » }
1144 » else
1145 » {
1146 return FALSE; 1137 return FALSE;
1147 } 1138 }
1139 vp << m_pDocument->GetPageCount();
1140 return TRUE;
1148 } 1141 }
1149 1142
1150 FX_BOOL Document::external(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sError) 1143 FX_BOOL Document::external(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sError)
1151 { 1144 {
1152 //In Chrome case,should always return true. 1145 //In Chrome case,should always return true.
1153 vp << TRUE; 1146 vp << TRUE;
1154 return TRUE; 1147 return TRUE;
1155 } 1148 }
1156 1149
1157 FX_BOOL Document::filesize(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sError) 1150 FX_BOOL Document::filesize(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sError)
1158 { 1151 {
1159 » if (!vp.IsGetting())return FALSE; 1152 » if (vp.IsSetting()) {
1160 1153 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1154 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1155 » » return FALSE;
1156 » }
1161 vp << 0; 1157 vp << 0;
1162 return TRUE; 1158 return TRUE;
1163 } 1159 }
1164 1160
1165 FX_BOOL Document::mouseX(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& s Error) 1161 FX_BOOL Document::mouseX(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& s Error)
1166 { 1162 {
1167 return TRUE; 1163 return TRUE;
1168 } 1164 }
1169 1165
1170 FX_BOOL Document::mouseY(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& s Error) 1166 FX_BOOL Document::mouseY(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& s Error)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 vp >> bCalculate; 1202 vp >> bCalculate;
1207 1203
1208 pInterForm->EnableCalculate(bCalculate); 1204 pInterForm->EnableCalculate(bCalculate);
1209 } 1205 }
1210 1206
1211 return TRUE; 1207 return TRUE;
1212 } 1208 }
1213 1209
1214 FX_BOOL Document::documentFileName(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError) 1210 FX_BOOL Document::documentFileName(IFXJS_Context* cc, CJS_PropValue& vp, JS_Erro rString& sError)
1215 { 1211 {
1216 » if (!vp.IsGetting()) 1212 » if (vp.IsSetting()) {
1213 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1214 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1217 return FALSE; 1215 return FALSE;
1218 1216 » }
1219 CFX_WideString wsFilePath = m_pDocument->GetPath(); 1217 CFX_WideString wsFilePath = m_pDocument->GetPath();
1220
1221 FX_INT32 i = wsFilePath.GetLength() - 1; 1218 FX_INT32 i = wsFilePath.GetLength() - 1;
1222 for ( ; i >= 0; i-- ) 1219 for ( ; i >= 0; i-- )
1223 { 1220 {
1224 if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' ) 1221 if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )
1225 break; 1222 break;
1226 } 1223 }
1227 if ( i >= 0 && i < wsFilePath.GetLength() - 1 ) 1224 if ( i >= 0 && i < wsFilePath.GetLength() - 1 )
1228 { 1225 {
1229 vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 ) ; 1226 vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 ) ;
1230 }else{ 1227 }else{
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 1272
1276 cbFrom.ReleaseBuffer(); 1273 cbFrom.ReleaseBuffer();
1277 CFX_WideString cbRet = CFX_WideString(pResult); 1274 CFX_WideString cbRet = CFX_WideString(pResult);
1278 free(pResult); 1275 free(pResult);
1279 pResult = NULL; 1276 pResult = NULL;
1280 return cbRet; 1277 return cbRet;
1281 } 1278 }
1282 1279
1283 FX_BOOL Document::path(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sEr ror) 1280 FX_BOOL Document::path(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sEr ror)
1284 { 1281 {
1285 » if (!vp.IsGetting()) return FALSE; 1282 » if (vp.IsSetting()) {
1286 1283 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1284 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1285 » » return FALSE;
1286 » }
1287 vp << app::SysPathToPDFPath(m_pDocument->GetPath()); 1287 vp << app::SysPathToPDFPath(m_pDocument->GetPath());
1288
1289 return TRUE; 1288 return TRUE;
1290 } 1289 }
1291 1290
1292 FX_BOOL Document::pageWindowRect(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorS tring& sError) 1291 FX_BOOL Document::pageWindowRect(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorS tring& sError)
1293 { 1292 {
1294 return TRUE; 1293 return TRUE;
1295 } 1294 }
1296 1295
1297 FX_BOOL Document::layout(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& s Error) 1296 FX_BOOL Document::layout(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& s Error)
1298 { 1297 {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 IconElement* pNewIcon = new IconElement(); 1483 IconElement* pNewIcon = new IconElement();
1485 pNewIcon->IconName = swIconName; 1484 pNewIcon->IconName = swIconName;
1486 pNewIcon->NextIcon = NULL; 1485 pNewIcon->NextIcon = NULL;
1487 pNewIcon->IconStream = pIcon; 1486 pNewIcon->IconStream = pIcon;
1488 m_pIconTree->InsertIconElement(pNewIcon); 1487 m_pIconTree->InsertIconElement(pNewIcon);
1489 return TRUE; 1488 return TRUE;
1490 } 1489 }
1491 1490
1492 FX_BOOL Document::icons(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sE rror) 1491 FX_BOOL Document::icons(IFXJS_Context* cc, CJS_PropValue& vp, JS_ErrorString& sE rror)
1493 { 1492 {
1494 » if (vp.IsSetting()) 1493 » if (vp.IsSetting()) {
1494 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1495 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1495 return FALSE; 1496 return FALSE;
1497 }
1496 1498
1497 if (!m_pIconTree) 1499 if (!m_pIconTree)
1498 { 1500 {
1499 vp.SetNull(); 1501 vp.SetNull();
1500 return TRUE; 1502 return TRUE;
1501 } 1503 }
1502 1504
1503 CJS_Array Icons(m_isolate); 1505 CJS_Array Icons(m_isolate);
1504 IconElement* pIconElement = NULL; 1506 IconElement* pIconElement = NULL;
1505 int iIconTreeLength = m_pIconTree->GetLength(); 1507 int iIconTreeLength = m_pIconTree->GetLength();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 1614
1613 int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0; 1615 int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
1614 int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0; 1616 int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;
1615 bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true; 1617 bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;
1616 1618
1617 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc(); 1619 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
1618 if (!pDocument) return FALSE; 1620 if (!pDocument) return FALSE;
1619 1621
1620 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) 1622 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
1621 { 1623 {
1622 » » //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 1624 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1625 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1623 return FALSE; 1626 return FALSE;
1624 } 1627 }
1625 1628
1626 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); 1629 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1627 if (!pPageDict) return FALSE; 1630 if (!pPageDict) return FALSE;
1628 1631
1629 CPDF_Page page; 1632 CPDF_Page page;
1630 page.Load(pDocument, pPageDict); 1633 page.Load(pDocument, pPageDict);
1631 page.StartParse(); 1634 page.StartParse();
1632 page.ParseContent(); 1635 page.ParseContent();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 1684
1682 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; 1685 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
1683 1686
1684 int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0; 1687 int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
1685 1688
1686 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc(); 1689 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
1687 ASSERT(pDocument != NULL); 1690 ASSERT(pDocument != NULL);
1688 1691
1689 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) 1692 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
1690 { 1693 {
1691 » » //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 1694 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1695 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1692 return FALSE; 1696 return FALSE;
1693 } 1697 }
1694 1698
1695 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); 1699 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1696 if (!pPageDict) return FALSE; 1700 if (!pPageDict) return FALSE;
1697 1701
1698 CPDF_Page page; 1702 CPDF_Page page;
1699 page.Load(pDocument, pPageDict); 1703 page.Load(pDocument, pPageDict);
1700 page.StartParse(); 1704 page.StartParse();
1701 page.ParseContent(); 1705 page.ParseContent();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 1949
1946 void Document::DoAnnotDelay() 1950 void Document::DoAnnotDelay()
1947 { 1951 {
1948 CFX_DWordArray DelArray; 1952 CFX_DWordArray DelArray;
1949 1953
1950 for (int j=DelArray.GetSize()-1; j>=0; j--) 1954 for (int j=DelArray.GetSize()-1; j>=0; j--)
1951 { 1955 {
1952 m_DelayData.RemoveAt(DelArray[j]); 1956 m_DelayData.RemoveAt(DelArray[j]);
1953 } 1957 }
1954 } 1958 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/jsapi/fxjs_v8.h ('k') | fpdfsdk/src/javascript/console.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698