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

Side by Side Diff: xfa/fxfa/parser/xfa_document_serialize.cpp

Issue 1981003002: Replace Release() { delete this; } in fde_xml_imp.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: One more unique_ptr Created 4 years, 7 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 "xfa/fxfa/parser/xfa_document_serialize.h" 7 #include "xfa/fxfa/parser/xfa_document_serialize.h"
8 8
9 #include <memory>
10
9 #include "xfa/fde/xml/fde_xml_imp.h" 11 #include "xfa/fde/xml/fde_xml_imp.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 12 #include "xfa/fgas/crt/fgas_codepage.h"
11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" 13 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h"
12 #include "xfa/fxfa/parser/xfa_doclayout.h" 14 #include "xfa/fxfa/parser/xfa_doclayout.h"
13 #include "xfa/fxfa/parser/xfa_document.h" 15 #include "xfa/fxfa/parser/xfa_document.h"
14 #include "xfa/fxfa/parser/xfa_localemgr.h" 16 #include "xfa/fxfa/parser/xfa_localemgr.h"
15 #include "xfa/fxfa/parser/xfa_object.h" 17 #include "xfa/fxfa/parser/xfa_object.h"
16 #include "xfa/fxfa/parser/xfa_parser.h" 18 #include "xfa/fxfa/parser/xfa_parser.h"
17 #include "xfa/fxfa/parser/xfa_parser_imp.h" 19 #include "xfa/fxfa/parser/xfa_parser_imp.h"
18 #include "xfa/fxfa/parser/xfa_script.h" 20 #include "xfa/fxfa/parser/xfa_script.h"
19 #include "xfa/fxfa/parser/xfa_utils.h" 21 #include "xfa/fxfa/parser/xfa_utils.h"
20 22
21 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) 23 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument)
22 : m_pDocument(pDocument) { 24 : m_pDocument(pDocument) {
23 ASSERT(m_pDocument); 25 ASSERT(m_pDocument);
24 } 26 }
27
25 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) { 28 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) {
26 IXFA_Parser* pDataDocumentParser = IXFA_Parser::Create(m_pDocument); 29 std::unique_ptr<IXFA_Parser> pDataDocumentParser(
27 if (!pDataDocumentParser) { 30 IXFA_Parser::Create(m_pDocument));
31 if (!pDataDocumentParser)
Lei Zhang 2016/05/16 20:38:09 Always evals to false?
Tom Sepez 2016/05/16 21:29:06 Done.
32 return FALSE;
33
34 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) !=
35 XFA_PARSESTATUS_Ready) {
28 return FALSE; 36 return FALSE;
29 } 37 }
30 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != 38 if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done)
31 XFA_PARSESTATUS_Ready) {
32 pDataDocumentParser->Release();
33 return FALSE; 39 return FALSE;
34 } 40
35 if (pDataDocumentParser->DoParse(NULL) < XFA_PARSESTATUS_Done) { 41 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
36 pDataDocumentParser->Release(); 42 if (!pImportDataRoot)
37 return FALSE; 43 return FALSE;
38 } 44
39 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
40 if (!pImportDataRoot) {
41 pDataDocumentParser->Release();
42 return FALSE;
43 }
44 CXFA_Node* pDataModel = 45 CXFA_Node* pDataModel =
45 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); 46 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
46 if (!pDataModel) { 47 if (!pDataModel)
47 pDataDocumentParser->Release();
48 return FALSE; 48 return FALSE;
49 } 49
50 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data)); 50 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data));
51 if (pDataNode) { 51 if (pDataNode) {
52 pDataModel->RemoveChild(pDataNode); 52 pDataModel->RemoveChild(pDataNode);
53 } 53 }
54 if (pImportDataRoot->GetClassID() == XFA_ELEMENT_DataModel) { 54 if (pImportDataRoot->GetClassID() == XFA_ELEMENT_DataModel) {
55 while (CXFA_Node* pChildNode = 55 while (CXFA_Node* pChildNode =
56 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) { 56 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
57 pImportDataRoot->RemoveChild(pChildNode); 57 pImportDataRoot->RemoveChild(pChildNode);
58 pDataModel->InsertChild(pChildNode); 58 pDataModel->InsertChild(pChildNode);
59 } 59 }
60 } else { 60 } else {
61 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode(); 61 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode();
62 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); 62 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
63 if (pParentXMLNode) { 63 if (pParentXMLNode) {
64 pParentXMLNode->RemoveChildNode(pXMLNode); 64 pParentXMLNode->RemoveChildNode(pXMLNode);
65 } 65 }
66 pDataModel->InsertChild(pImportDataRoot); 66 pDataModel->InsertChild(pImportDataRoot);
67 } 67 }
68 m_pDocument->DoDataRemerge(FALSE); 68 m_pDocument->DoDataRemerge(FALSE);
69 pDataDocumentParser->Release();
70 return TRUE; 69 return TRUE;
71 } 70 }
71
72 CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) { 72 CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) {
73 CFX_WideTextBuf textBuf; 73 CFX_WideTextBuf textBuf;
74 int32_t iLen = str.GetLength(); 74 int32_t iLen = str.GetLength();
75 for (int32_t i = 0; i < iLen; i++) { 75 for (int32_t i = 0; i < iLen; i++) {
76 switch (str[i]) { 76 switch (str[i]) {
77 case '&': 77 case '&':
78 textBuf << FX_WSTRC(L"&amp;"); 78 textBuf << FX_WSTRC(L"&amp;");
79 break; 79 break;
80 case '<': 80 case '<':
81 textBuf << FX_WSTRC(L"&lt;"); 81 textBuf << FX_WSTRC(L"&lt;");
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 pXMLElement->RemoveAttribute(L"xfa:dataNode"); 574 pXMLElement->RemoveAttribute(L"xfa:dataNode");
575 } 575 }
576 } else { 576 } else {
577 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); 577 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
578 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); 578 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
579 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode", 579 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode",
580 L"dataGroup"); 580 L"dataGroup");
581 } 581 }
582 } 582 }
583 } 583 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698