summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/Document.cpp
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-10-19 13:29:48 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-19 13:29:48 -0700
commitdadea5f87d35f8a692b659dbff54cc8780d48ef8 (patch)
treeeaa090007d1ee40cfdf889fa8dbfb46c6fe2a6fc /fpdfsdk/javascript/Document.cpp
parente58febc04514694935fcdf00f604419a1e5076b0 (diff)
downloadpdfium-dadea5f87d35f8a692b659dbff54cc8780d48ef8.tar.xz
Make Document::m_IconList a vector of IconElements. (try 2)chromium/2896
It does not need to be a std::list. This time keep the elements as unique_ptrs. Previous attempt: https://codereview.chromium.org/2428743004/ Review-Url: https://chromiumcodereview.appspot.com/2428373004
Diffstat (limited to 'fpdfsdk/javascript/Document.cpp')
-rw-r--r--fpdfsdk/javascript/Document.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 0b08f66f33..0c2e3f7399 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -33,6 +33,7 @@
#include "fpdfsdk/javascript/cjs_runtime.h"
#include "fpdfsdk/javascript/resource.h"
#include "third_party/base/numerics/safe_math.h"
+#include "third_party/base/ptr_util.h"
BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
END_JS_STATIC_CONST()
@@ -1256,8 +1257,8 @@ FX_BOOL Document::addIcon(IJS_Context* cc,
return FALSE;
}
- m_IconList.push_back(std::unique_ptr<IconElement>(
- new IconElement(swIconName, (Icon*)pEmbedObj)));
+ m_Icons.push_back(pdfium::MakeUnique<IconElement>(
+ swIconName, static_cast<Icon*>(pEmbedObj)));
return TRUE;
}
@@ -1270,7 +1271,7 @@ FX_BOOL Document::icons(IJS_Context* cc,
}
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- if (m_IconList.empty()) {
+ if (m_Icons.empty()) {
vp.GetJSValue()->SetNull(pRuntime);
return TRUE;
}
@@ -1278,7 +1279,7 @@ FX_BOOL Document::icons(IJS_Context* cc,
CJS_Array Icons;
int i = 0;
- for (const auto& pIconElement : m_IconList) {
+ for (const auto& pIconElement : m_Icons) {
v8::Local<v8::Object> pObj =
pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
if (pObj.IsEmpty())
@@ -1289,7 +1290,7 @@ FX_BOOL Document::icons(IJS_Context* cc,
if (!pJS_Icon)
return FALSE;
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject());
if (!pIcon)
return FALSE;
@@ -1311,35 +1312,35 @@ FX_BOOL Document::getIcon(IJS_Context* cc,
return FALSE;
}
- if (m_IconList.empty())
+ if (m_Icons.empty())
return FALSE;
CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
- for (const auto& pIconElement : m_IconList) {
- if (pIconElement->IconName == swIconName) {
- Icon* pRetIcon = pIconElement->IconStream;
+ for (const auto& pIconElement : m_Icons) {
+ if (pIconElement->IconName != swIconName)
+ continue;
- v8::Local<v8::Object> pObj =
- pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
- if (pObj.IsEmpty())
- return FALSE;
+ v8::Local<v8::Object> pObj =
+ pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
+ if (pObj.IsEmpty())
+ return FALSE;
- CJS_Icon* pJS_Icon =
- static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
- if (!pJS_Icon)
- return FALSE;
+ CJS_Icon* pJS_Icon =
+ static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
+ if (!pJS_Icon)
+ return FALSE;
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- if (!pIcon)
- return FALSE;
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ if (!pIcon)
+ return FALSE;
- pIcon->SetIconName(swIconName);
- pIcon->SetStream(pRetIcon->GetStream());
- vRet = CJS_Value(pRuntime, pJS_Icon);
- return TRUE;
- }
+ pIcon->SetIconName(swIconName);
+ pIcon->SetStream(pIconElement->IconStream->GetStream());
+
+ vRet = CJS_Value(pRuntime, pJS_Icon);
+ return TRUE;
}
return FALSE;