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

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

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

Powered by Google App Engine
This is Rietveld 408576698