summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/Document.cpp
diff options
context:
space:
mode:
authortonikitoo <tonikitoo@igalia.com>2016-08-26 14:41:29 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-26 14:41:29 -0700
commit0ee35908e906922a423fb18d7085ef80d0d8d8c8 (patch)
tree83921c5170c6a361b2317901f01d8d8928921282 /fpdfsdk/javascript/Document.cpp
parentb7fb1fd087cfe20cfc29cabc80af2c11e91538c6 (diff)
downloadpdfium-0ee35908e906922a423fb18d7085ef80d0d8d8c8.tar.xz
Add support to Document::getAnnots method
Although notably, the parameters handling support is not complete, CL intends to be the first step towards a more complete implementation of this API. TEST=testing/resources/javascript/bug_492_1.in BUG=pdfium:492 Review-Url: https://codereview.chromium.org/2281273002
Diffstat (limited to 'fpdfsdk/javascript/Document.cpp')
-rw-r--r--fpdfsdk/javascript/Document.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 8fb9ce60dc..c1381f5865 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -1090,7 +1090,48 @@ FX_BOOL Document::getAnnots(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- vRet.SetNull(CJS_Runtime::FromContext(cc));
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+
+ // TODO(tonikitoo): Add support supported parameters as per
+ // the PDF spec.
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+ int nPageNo = m_pDocument->GetPageCount();
+ CJS_Array annots;
+
+ for (int i = 0; i < nPageNo; ++i) {
+ CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(i);
+ if (!pPageView)
+ return FALSE;
+
+ CPDFSDK_AnnotIterator annotIterator(pPageView, false);
+ while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) {
+ CPDFSDK_BAAnnot* pSDKBAAnnot =
+ static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur);
+ if (!pSDKBAAnnot)
+ return FALSE;
+
+ v8::Local<v8::Object> pObj =
+ pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID);
+ if (pObj.IsEmpty())
+ return FALSE;
+
+ CJS_Annot* pJS_Annot =
+ static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
+ if (!pJS_Annot)
+ return FALSE;
+
+ Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
+ if (!pAnnot)
+ return FALSE;
+
+ pAnnot->SetSDKAnnot(pSDKBAAnnot);
+ annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot));
+ }
+ }
+
+ vRet = CJS_Value(pRuntime, annots);
return TRUE;
}