summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-30 20:27:21 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-30 20:27:21 +0000
commit649e059f5fe93c0de53aaa48a74068703df46301 (patch)
tree94db3f5d67962bda272203a8c11d79b5ffcda33f
parent921d24416f310b6a899f09daa4a2628be5be16f3 (diff)
downloadpdfium-649e059f5fe93c0de53aaa48a74068703df46301.tar.xz
Return unique_ptr from CXFA_FFNotify::OnCreate{Container,Content}LayoutItem()
... and then immediately release it, but it is a step in the right direction. Change-Id: Ib52972c6789d8f98a576d1c69f8019541c96ac51 Reviewed-on: https://pdfium-review.googlesource.com/39152 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--xfa/fxfa/cxfa_ffnotify.cpp68
-rw-r--r--xfa/fxfa/cxfa_ffnotify.h8
-rw-r--r--xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp3
4 files changed, 48 insertions, 38 deletions
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp
index 586b048b8a..715877c620 100644
--- a/xfa/fxfa/cxfa_ffnotify.cpp
+++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -6,7 +6,6 @@
#include "xfa/fxfa/cxfa_ffnotify.h"
-#include <memory>
#include <utility>
#include "xfa/fxfa/cxfa_ffapp.h"
@@ -91,101 +90,106 @@ void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_Node* pSender,
}
}
-CXFA_ContainerLayoutItem* CXFA_FFNotify::OnCreateContainerLayoutItem(
- CXFA_Node* pNode) {
+std::unique_ptr<CXFA_ContainerLayoutItem>
+CXFA_FFNotify::OnCreateContainerLayoutItem(CXFA_Node* pNode) {
XFA_Element type = pNode->GetElementType();
- ASSERT(type == XFA_Element::ContentArea || type == XFA_Element::PageArea);
-
if (type == XFA_Element::PageArea) {
CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetLayoutProcessor();
- return new CXFA_FFPageView(m_pDoc->GetDocView(pLayout), pNode);
+ return pdfium::MakeUnique<CXFA_FFPageView>(m_pDoc->GetDocView(pLayout),
+ pNode);
}
- return new CXFA_ContainerLayoutItem(pNode);
+ if (type == XFA_Element::ContentArea)
+ return pdfium::MakeUnique<CXFA_ContainerLayoutItem>(pNode);
+
+ NOTREACHED();
+ return nullptr;
}
-CXFA_ContentLayoutItem* CXFA_FFNotify::OnCreateContentLayoutItem(
- CXFA_Node* pNode) {
+std::unique_ptr<CXFA_ContentLayoutItem>
+CXFA_FFNotify::OnCreateContentLayoutItem(CXFA_Node* pNode) {
ASSERT(pNode->GetElementType() != XFA_Element::ContentArea);
ASSERT(pNode->GetElementType() != XFA_Element::PageArea);
// We only need to create the widget for certain types of objects.
if (!pNode->HasCreatedUIWidget())
- return new CXFA_ContentLayoutItem(pNode);
+ return pdfium::MakeUnique<CXFA_ContentLayoutItem>(pNode);
- CXFA_FFWidget* pWidget = nullptr;
+ std::unique_ptr<CXFA_FFWidget> pWidget;
switch (pNode->GetFFWidgetType()) {
case XFA_FFWidgetType::kBarcode: {
CXFA_Node* child = pNode->GetUIChildNode();
- if (child->GetElementType() == XFA_Element::Barcode)
- pWidget = new CXFA_FFBarcode(pNode, static_cast<CXFA_Barcode*>(child));
+ if (child->GetElementType() == XFA_Element::Barcode) {
+ pWidget = pdfium::MakeUnique<CXFA_FFBarcode>(
+ pNode, static_cast<CXFA_Barcode*>(child));
+ }
break;
}
case XFA_FFWidgetType::kButton: {
CXFA_Node* child = pNode->GetUIChildNode();
if (child->GetElementType() == XFA_Element::Button) {
- pWidget =
- new CXFA_FFPushButton(pNode, static_cast<CXFA_Button*>(child));
+ pWidget = pdfium::MakeUnique<CXFA_FFPushButton>(
+ pNode, static_cast<CXFA_Button*>(child));
}
break;
}
case XFA_FFWidgetType::kCheckButton: {
CXFA_Node* child = pNode->GetUIChildNode();
if (child->GetElementType() == XFA_Element::CheckButton) {
- pWidget = new CXFA_FFCheckButton(pNode,
- static_cast<CXFA_CheckButton*>(child));
+ pWidget = pdfium::MakeUnique<CXFA_FFCheckButton>(
+ pNode, static_cast<CXFA_CheckButton*>(child));
}
break;
}
case XFA_FFWidgetType::kChoiceList: {
if (pNode->IsListBox())
- pWidget = new CXFA_FFListBox(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFListBox>(pNode);
else
- pWidget = new CXFA_FFComboBox(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFComboBox>(pNode);
break;
}
case XFA_FFWidgetType::kDateTimeEdit:
- pWidget = new CXFA_FFDateTimeEdit(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFDateTimeEdit>(pNode);
break;
case XFA_FFWidgetType::kImageEdit:
- pWidget = new CXFA_FFImageEdit(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFImageEdit>(pNode);
break;
case XFA_FFWidgetType::kNumericEdit:
- pWidget = new CXFA_FFNumericEdit(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFNumericEdit>(pNode);
break;
case XFA_FFWidgetType::kPasswordEdit: {
CXFA_Node* child = pNode->GetUIChildNode();
if (child->GetElementType() == XFA_Element::PasswordEdit) {
- pWidget = new CXFA_FFPasswordEdit(
+ pWidget = pdfium::MakeUnique<CXFA_FFPasswordEdit>(
pNode, static_cast<CXFA_PasswordEdit*>(child));
}
break;
}
case XFA_FFWidgetType::kSignature:
- pWidget = new CXFA_FFSignature(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFSignature>(pNode);
break;
case XFA_FFWidgetType::kTextEdit:
- pWidget = new CXFA_FFTextEdit(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFTextEdit>(pNode);
break;
case XFA_FFWidgetType::kArc:
- pWidget = new CXFA_FFArc(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFArc>(pNode);
break;
case XFA_FFWidgetType::kLine:
- pWidget = new CXFA_FFLine(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFLine>(pNode);
break;
case XFA_FFWidgetType::kRectangle:
- pWidget = new CXFA_FFRectangle(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFRectangle>(pNode);
break;
case XFA_FFWidgetType::kText:
- pWidget = new CXFA_FFText(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFText>(pNode);
break;
case XFA_FFWidgetType::kImage:
- pWidget = new CXFA_FFImage(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFImage>(pNode);
break;
case XFA_FFWidgetType::kSubform:
- pWidget = new CXFA_FFWidget(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFWidget>(pNode);
break;
case XFA_FFWidgetType::kExclGroup:
- pWidget = new CXFA_FFExclGroup(pNode);
+ pWidget = pdfium::MakeUnique<CXFA_FFExclGroup>(pNode);
break;
case XFA_FFWidgetType::kNone:
return nullptr;
diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h
index 6715f825ff..298a10123d 100644
--- a/xfa/fxfa/cxfa_ffnotify.h
+++ b/xfa/fxfa/cxfa_ffnotify.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXFA_CXFA_FFNOTIFY_H_
#define XFA_FXFA_CXFA_FFNOTIFY_H_
+#include <memory>
+
#include "xfa/fxfa/cxfa_eventparam.h"
#include "xfa/fxfa/parser/cxfa_document.h"
@@ -39,8 +41,10 @@ class CXFA_FFNotify {
void OnChildAdded(CXFA_Node* pSender);
void OnChildRemoved();
- CXFA_ContainerLayoutItem* OnCreateContainerLayoutItem(CXFA_Node* pNode);
- CXFA_ContentLayoutItem* OnCreateContentLayoutItem(CXFA_Node* pNode);
+ std::unique_ptr<CXFA_ContainerLayoutItem> OnCreateContainerLayoutItem(
+ CXFA_Node* pNode);
+ std::unique_ptr<CXFA_ContentLayoutItem> OnCreateContentLayoutItem(
+ CXFA_Node* pNode);
void OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout,
CXFA_LayoutItem* pSender,
diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
index 60dd8a37a5..e09b17d730 100644
--- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
+++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
@@ -652,9 +652,10 @@ CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::CreateContentLayoutItem(
m_pOldLayoutItem = m_pOldLayoutItem->m_pNext;
return pLayoutItem;
}
- pLayoutItem =
- pFormNode->GetDocument()->GetNotify()->OnCreateContentLayoutItem(
- pFormNode);
+ pLayoutItem = pFormNode->GetDocument()
+ ->GetNotify()
+ ->OnCreateContentLayoutItem(pFormNode)
+ .release();
CXFA_ContentLayoutItem* pPrevLayoutItem =
ToContentLayoutItem(pFormNode->JSObject()->GetLayoutItem());
if (pPrevLayoutItem) {
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index b6c95c1d56..411ad24e45 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -582,7 +582,8 @@ void CXFA_LayoutPageMgr::AddPageAreaLayoutItem(CXFA_ContainerRecord* pNewRecord,
pNewPageAreaLayoutItem = pContainerItem;
} else {
CXFA_FFNotify* pNotify = pNewPageArea->GetDocument()->GetNotify();
- auto* pContainerItem = pNotify->OnCreateContainerLayoutItem(pNewPageArea);
+ auto* pContainerItem =
+ pNotify->OnCreateContainerLayoutItem(pNewPageArea).release();
m_PageArray.push_back(pContainerItem);
m_nAvailPages++;
pNotify->OnPageEvent(pContainerItem, XFA_PAGEVIEWEVENT_PostRemoved);