From 7a73effb9fe071fbc852b30865d7a332e96fbd56 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 8 Feb 2016 13:39:53 -0800 Subject: Tidy fpdfsave.cpp Remove CFX_PtrArray filelist. Promote ScopedFileStream to .h file and use it. Fix _CAPS names, bool returns, and put in anonymous namespace. FX_CreateMemoryStream() can't return null, so remove checks. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1672153002 . --- xfa/src/fxfa/src/app/xfa_ffdoc.cpp | 7 ---- xfa/src/fxfa/src/parser/xfa_object_imp.cpp | 54 ++++++++++++------------------ 2 files changed, 22 insertions(+), 39 deletions(-) (limited to 'xfa/src') diff --git a/xfa/src/fxfa/src/app/xfa_ffdoc.cpp b/xfa/src/fxfa/src/app/xfa_ffdoc.cpp index 87745616e0..513098c7a9 100644 --- a/xfa/src/fxfa/src/app/xfa_ffdoc.cpp +++ b/xfa/src/fxfa/src/app/xfa_ffdoc.cpp @@ -113,13 +113,6 @@ int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { IFX_FileRead* pXFAReader = NULL; if (XFA_GetPDFContentsFromPDFXML(pPDFXML, pByteBuffer, iBufferSize)) { pXFAReader = FX_CreateMemoryStream(pByteBuffer, iBufferSize, TRUE); - if (!pXFAReader) { - if (pByteBuffer) { - FX_Free(pByteBuffer); - pByteBuffer = NULL; - } - return XFA_PARSESTATUS_SyntaxErr; - } } else { CFX_WideString wsHref; ((IFDE_XMLElement*)pPDFXML)->GetString(L"href", wsHref); diff --git a/xfa/src/fxfa/src/parser/xfa_object_imp.cpp b/xfa/src/fxfa/src/parser/xfa_object_imp.cpp index 10d5e24abf..278ad85324 100644 --- a/xfa/src/fxfa/src/parser/xfa_object_imp.cpp +++ b/xfa/src/fxfa/src/parser/xfa_object_imp.cpp @@ -1056,6 +1056,7 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { } void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { } + void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 0 || iLength > 1) { @@ -1065,20 +1066,15 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { FX_BOOL bPrettyMode = FALSE; if (iLength == 1) { CFX_ByteString bsPretty = pArguments->GetUTF8String(0); - if (bsPretty.Equal("pretty")) { - bPrettyMode = TRUE; - } else { + if (!bsPretty.Equal("pretty")) { ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); return; } + bPrettyMode = TRUE; } CFX_ByteStringC bsXMLHeader = "\n"; if (GetPacketID() == XFA_XDPPACKET_Form) { IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE); - if (!pMemoryStream) { - FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); - return; - } IFX_Stream* pStream = IFX_Stream::CreateStream( (IFX_FileWrite*)pMemoryStream, FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); @@ -1101,7 +1097,8 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { pMemoryStream = NULL; } return; - } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { + } + if (GetPacketID() == XFA_XDPPACKET_Datasets) { IFDE_XMLNode* pElement = this->GetXMLMappingNode(); if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); @@ -1109,35 +1106,28 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { } XFA_DataExporter_DealWithDataGroupNode(this); IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE); - if (!pMemoryStream) { - FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); - return; + IFX_Stream* pStream = IFX_Stream::CreateStream( + (IFX_FileWrite*)pMemoryStream, + FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); + if (pStream) { + pStream->SetCodePage(FX_CODEPAGE_UTF8); + pStream->WriteData(bsXMLHeader.GetPtr(), bsXMLHeader.GetLength()); + pElement->SaveXMLNode(pStream); + FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), + CFX_ByteStringC(pMemoryStream->GetBuffer(), + pMemoryStream->GetSize())); + pStream->Release(); + pStream = NULL; } if (pMemoryStream) { - IFX_Stream* pStream = IFX_Stream::CreateStream( - (IFX_FileWrite*)pMemoryStream, FX_STREAMACCESS_Text | - FX_STREAMACCESS_Write | - FX_STREAMACCESS_Append); - if (pStream) { - pStream->SetCodePage(FX_CODEPAGE_UTF8); - pStream->WriteData(bsXMLHeader.GetPtr(), bsXMLHeader.GetLength()); - pElement->SaveXMLNode(pStream); - FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), - CFX_ByteStringC(pMemoryStream->GetBuffer(), - pMemoryStream->GetSize())); - pStream->Release(); - pStream = NULL; - } - if (pMemoryStream) { - pMemoryStream->Release(); - pMemoryStream = NULL; - } - return; + pMemoryStream->Release(); + pMemoryStream = NULL; } - } else { - FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), ""); + return; } + FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), ""); } + void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength != 2) { -- cgit v1.2.3