From e0947b37c012144cefb523a33e548d3fadc211d8 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 17 Sep 2015 14:51:48 -0700 Subject: Merge to XFA: Implement FPDFAction_GetFilePath(). The API is the same as the Foxit version, except the encoding is specified as UTF-8 instead of local encoding. Also remove CPDF_LWinParam since it's unused. BUG=chromium:517713 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1335373002 . (cherry picked from commit 0b3c8f742613da294f812e2f6e908f4026499f96) (cherry picked from commit a9d4bc541179ec0436adc4b2e18b7fdecc5952dc) (cherry picked from commit 4ffd89ed556e32a6527d0e88952fe20ec1e2f362) Review URL: https://codereview.chromium.org/1345953002 . --- fpdfsdk/src/fpdfdoc.cpp | 49 ++++++++++++++++++++++-------------- fpdfsdk/src/fpdfdoc_embeddertest.cpp | 25 ++++++++++++++++++ fpdfsdk/src/fpdfview_c_api_test.c | 1 + 3 files changed, 56 insertions(+), 19 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp index 47225dd2b1..34caf95b52 100644 --- a/fpdfsdk/src/fpdfdoc.cpp +++ b/fpdfsdk/src/fpdfdoc.cpp @@ -128,7 +128,8 @@ DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) { if (!pDict) - return 0; + return PDFACTION_UNSUPPORTED; + CPDF_Action action((CPDF_Dictionary*)pDict); CPDF_Action::ActionType type = action.GetType(); switch (type) { @@ -143,43 +144,53 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) { default: return PDFACTION_UNSUPPORTED; } - return PDFACTION_UNSUPPORTED; } DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTION pDict) { - if (!document) - return NULL; - if (!pDict) - return NULL; + if (!document || !pDict) + return nullptr; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); CPDF_Action action((CPDF_Dictionary*)pDict); return action.GetDest(pDoc).GetObject(); } +DLLEXPORT unsigned long STDCALL +FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { + unsigned long type = FPDFAction_GetType(pDict); + if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) + return 0; + + CPDF_Action action((CPDF_Dictionary*)pDict); + CFX_ByteString path = action.GetFilePath().UTF8Encode(); + unsigned long len = path.GetLength() + 1; + if (buffer && buflen >= len) + FXSYS_memcpy(buffer, path.c_str(), len); + return len; +} + DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION pDict, void* buffer, unsigned long buflen) { - if (!document) - return 0; - if (!pDict) + if (!document || !pDict) return 0; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); CPDF_Action action((CPDF_Dictionary*)pDict); CFX_ByteString path = action.GetURI(pDoc); unsigned long len = path.GetLength() + 1; - if (buffer != NULL && buflen >= len) + if (buffer && buflen >= len) FXSYS_memcpy(buffer, path.c_str(), len); return len; } DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FPDF_DEST pDict) { - if (!document) - return 0; - if (!pDict) + if (!document || !pDict) return 0; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); CPDF_Dest dest((CPDF_Array*)pDict); return dest.GetPageIndex(pDoc); @@ -218,10 +229,9 @@ FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) { DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK pDict) { - if (!document) - return NULL; - if (!pDict) - return NULL; + if (!document || !pDict) + return nullptr; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); CPDF_Link link((CPDF_Dictionary*)pDict); FPDF_DEST dest = link.GetDest(pDoc).GetObject(); @@ -230,13 +240,14 @@ DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, // If this link is not directly associated with a dest, we try to get action CPDF_Action action = link.GetAction(); if (!action) - return NULL; + return nullptr; return action.GetDest(pDoc).GetObject(); } DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) { if (!pDict) - return NULL; + return nullptr; + CPDF_Link link((CPDF_Dictionary*)pDict); return link.GetAction().GetDict(); } diff --git a/fpdfsdk/src/fpdfdoc_embeddertest.cpp b/fpdfsdk/src/fpdfdoc_embeddertest.cpp index b263fafe16..8b1c4fb3e8 100644 --- a/fpdfsdk/src/fpdfdoc_embeddertest.cpp +++ b/fpdfsdk/src/fpdfdoc_embeddertest.cpp @@ -35,3 +35,28 @@ TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { EXPECT_NE(nullptr, dest); EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), dest)); } + +TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) { + EXPECT_TRUE(OpenDocument("testing/resources/launch_action.pdf")); + + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // The target action is nearly the size of the whole page. + FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); + ASSERT_TRUE(link); + + FPDF_ACTION action = FPDFLink_GetAction(link); + ASSERT_TRUE(action); + + const char kExpectedResult[] = "test.pdf"; + const unsigned long kExpectedLength = sizeof(kExpectedResult); + unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0); + ASSERT_EQ(kExpectedLength, bufsize); + + char buf[kExpectedLength]; + EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize)); + EXPECT_EQ(std::string(kExpectedResult), std::string(buf)); + + FPDF_ClosePage(page); +} diff --git a/fpdfsdk/src/fpdfview_c_api_test.c b/fpdfsdk/src/fpdfview_c_api_test.c index 01789b4432..d16bf99f07 100644 --- a/fpdfsdk/src/fpdfview_c_api_test.c +++ b/fpdfsdk/src/fpdfview_c_api_test.c @@ -51,6 +51,7 @@ int CheckPDFiumCApi() { CHK(FPDFBookmark_GetAction); CHK(FPDFAction_GetType); CHK(FPDFAction_GetDest); + CHK(FPDFAction_GetFilePath); CHK(FPDFAction_GetURIPath); CHK(FPDFDest_GetPageIndex); CHK(FPDFLink_GetLinkAtPoint); -- cgit v1.2.3