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

Side by Side Diff: core/src/fpdfdoc/doc_action.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: self review Created 5 years 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 "core/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 8
9 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { 9 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
10 if (!m_pDict) { 10 if (!m_pDict) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return eType; 49 return eType;
50 } 50 }
51 CFX_WideString CPDF_Action::GetFilePath() const { 51 CFX_WideString CPDF_Action::GetFilePath() const {
52 CFX_ByteString type = m_pDict->GetString("S"); 52 CFX_ByteString type = m_pDict->GetString("S");
53 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && 53 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" &&
54 type != "ImportData") { 54 type != "ImportData") {
55 return CFX_WideString(); 55 return CFX_WideString();
56 } 56 }
57 CPDF_Object* pFile = m_pDict->GetElementValue("F"); 57 CPDF_Object* pFile = m_pDict->GetElementValue("F");
58 CFX_WideString path; 58 CFX_WideString path;
59 if (pFile == NULL) { 59 if (!pFile) {
60 if (type == "Launch") { 60 if (type == "Launch") {
61 CPDF_Dictionary* pWinDict = m_pDict->GetDict("Win"); 61 CPDF_Dictionary* pWinDict = m_pDict->GetDict("Win");
62 if (pWinDict) { 62 if (pWinDict) {
63 return CFX_WideString::FromLocal(pWinDict->GetString("F")); 63 return CFX_WideString::FromLocal(pWinDict->GetString("F"));
64 } 64 }
65 } 65 }
66 return path; 66 return path;
67 } 67 }
68 CPDF_FileSpec filespec(pFile); 68 CPDF_FileSpec filespec(pFile);
69 filespec.GetFileName(path); 69 filespec.GetFileName(path);
70 return path; 70 return path;
71 } 71 }
72 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const { 72 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
73 CFX_ByteString csURI; 73 CFX_ByteString csURI;
74 if (m_pDict == NULL) { 74 if (!m_pDict) {
75 return csURI; 75 return csURI;
76 } 76 }
77 if (m_pDict->GetString("S") != "URI") { 77 if (m_pDict->GetString("S") != "URI") {
78 return csURI; 78 return csURI;
79 } 79 }
80 csURI = m_pDict->GetString("URI"); 80 csURI = m_pDict->GetString("URI");
81 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 81 CPDF_Dictionary* pRoot = pDoc->GetRoot();
82 CPDF_Dictionary* pURI = pRoot->GetDict("URI"); 82 CPDF_Dictionary* pURI = pRoot->GetDict("URI");
83 if (pURI) { 83 if (pURI) {
84 if (csURI.Find(":", 0) < 1) { 84 if (csURI.Find(":", 0) < 1) {
85 csURI = pURI->GetString("Base") + csURI; 85 csURI = pURI->GetString("Base") + csURI;
86 } 86 }
87 } 87 }
88 return csURI; 88 return csURI;
89 } 89 }
90 FX_DWORD CPDF_ActionFields::GetFieldsCount() const { 90 FX_DWORD CPDF_ActionFields::GetFieldsCount() const {
91 if (m_pAction == NULL) { 91 if (!m_pAction) {
92 return 0; 92 return 0;
93 } 93 }
94 CPDF_Dictionary* pDict = m_pAction->GetDict(); 94 CPDF_Dictionary* pDict = m_pAction->GetDict();
95 if (pDict == NULL) { 95 if (!pDict) {
96 return 0; 96 return 0;
97 } 97 }
98 CFX_ByteString csType = pDict->GetString("S"); 98 CFX_ByteString csType = pDict->GetString("S");
99 CPDF_Object* pFields = NULL; 99 CPDF_Object* pFields = NULL;
100 if (csType == "Hide") { 100 if (csType == "Hide") {
101 pFields = pDict->GetElementValue("T"); 101 pFields = pDict->GetElementValue("T");
102 } else { 102 } else {
103 pFields = pDict->GetArray("Fields"); 103 pFields = pDict->GetArray("Fields");
104 } 104 }
105 if (!pFields) 105 if (!pFields)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 CPDF_Object* pObj = pArray->GetElementValue(i); 139 CPDF_Object* pObj = pArray->GetElementValue(i);
140 if (pObj) { 140 if (pObj) {
141 fields.push_back(pObj); 141 fields.push_back(pObj);
142 } 142 }
143 } 143 }
144 } 144 }
145 return fields; 145 return fields;
146 } 146 }
147 147
148 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { 148 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const {
149 if (m_pAction == NULL) { 149 if (!m_pAction) {
150 return NULL; 150 return NULL;
151 } 151 }
152 CPDF_Dictionary* pDict = m_pAction->GetDict(); 152 CPDF_Dictionary* pDict = m_pAction->GetDict();
153 if (pDict == NULL) { 153 if (!pDict) {
154 return NULL; 154 return NULL;
155 } 155 }
156 CFX_ByteString csType = pDict->GetString("S"); 156 CFX_ByteString csType = pDict->GetString("S");
157 CPDF_Object* pFields = NULL; 157 CPDF_Object* pFields = NULL;
158 if (csType == "Hide") { 158 if (csType == "Hide") {
159 pFields = pDict->GetElementValue("T"); 159 pFields = pDict->GetElementValue("T");
160 } else { 160 } else {
161 pFields = pDict->GetArray("Fields"); 161 pFields = pDict->GetArray("Fields");
162 } 162 }
163 if (pFields == NULL) { 163 if (!pFields) {
164 return NULL; 164 return NULL;
165 } 165 }
166 CPDF_Object* pFindObj = NULL; 166 CPDF_Object* pFindObj = NULL;
167 if (pFields->IsDictionary() || pFields->IsString()) { 167 if (pFields->IsDictionary() || pFields->IsString()) {
168 if (iIndex == 0) 168 if (iIndex == 0)
169 pFindObj = pFields; 169 pFindObj = pFields;
170 } else if (CPDF_Array* pArray = pFields->AsArray()) { 170 } else if (CPDF_Array* pArray = pFields->AsArray()) {
171 pFindObj = pArray->GetElementValue(iIndex); 171 pFindObj = pArray->GetElementValue(iIndex);
172 } 172 }
173 return pFindObj; 173 return pFindObj;
174 } 174 }
175 175
176 CFX_WideString CPDF_Action::GetJavaScript() const { 176 CFX_WideString CPDF_Action::GetJavaScript() const {
177 CFX_WideString csJS; 177 CFX_WideString csJS;
178 if (m_pDict == NULL) { 178 if (!m_pDict) {
179 return csJS; 179 return csJS;
180 } 180 }
181 CPDF_Object* pJS = m_pDict->GetElementValue("JS"); 181 CPDF_Object* pJS = m_pDict->GetElementValue("JS");
182 if (pJS) { 182 if (pJS) {
183 return pJS->GetUnicodeText(); 183 return pJS->GetUnicodeText();
184 } 184 }
185 return csJS; 185 return csJS;
186 } 186 }
187 CPDF_Dictionary* CPDF_Action::GetAnnot() const { 187 CPDF_Dictionary* CPDF_Action::GetAnnot() const {
188 if (!m_pDict) { 188 if (!m_pDict) {
189 return nullptr; 189 return nullptr;
190 } 190 }
191 CFX_ByteString csType = m_pDict->GetString("S"); 191 CFX_ByteString csType = m_pDict->GetString("S");
192 if (csType == "Rendition") { 192 if (csType == "Rendition") {
193 return m_pDict->GetDict("AN"); 193 return m_pDict->GetDict("AN");
194 } 194 }
195 if (csType == "Movie") { 195 if (csType == "Movie") {
196 return m_pDict->GetDict("Annotation"); 196 return m_pDict->GetDict("Annotation");
197 } 197 }
198 return nullptr; 198 return nullptr;
199 } 199 }
200 int32_t CPDF_Action::GetOperationType() const { 200 int32_t CPDF_Action::GetOperationType() const {
201 if (m_pDict == NULL) { 201 if (!m_pDict) {
202 return 0; 202 return 0;
203 } 203 }
204 CFX_ByteString csType = m_pDict->GetString("S"); 204 CFX_ByteString csType = m_pDict->GetString("S");
205 if (csType == "Rendition") { 205 if (csType == "Rendition") {
206 return m_pDict->GetInteger("OP"); 206 return m_pDict->GetInteger("OP");
207 } 207 }
208 if (csType == "Movie") { 208 if (csType == "Movie") {
209 CFX_ByteString csOP = m_pDict->GetString("Operation"); 209 CFX_ByteString csOP = m_pDict->GetString("Operation");
210 if (csOP == "Play") { 210 if (csOP == "Play") {
211 return 0; 211 return 0;
(...skipping 17 matching lines...) Expand all
229 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); 229 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
230 if (!pNext) 230 if (!pNext)
231 return 0; 231 return 0;
232 if (pNext->IsDictionary()) 232 if (pNext->IsDictionary())
233 return 1; 233 return 1;
234 if (CPDF_Array* pArray = pNext->AsArray()) 234 if (CPDF_Array* pArray = pNext->AsArray())
235 return pArray->GetCount(); 235 return pArray->GetCount();
236 return 0; 236 return 0;
237 } 237 }
238 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { 238 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const {
239 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { 239 if (!m_pDict || !m_pDict->KeyExist("Next")) {
240 return CPDF_Action(); 240 return CPDF_Action();
241 } 241 }
242 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); 242 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
243 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { 243 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) {
244 if (iIndex == 0) 244 if (iIndex == 0)
245 return CPDF_Action(pDict); 245 return CPDF_Action(pDict);
246 } else if (CPDF_Array* pArray = ToArray(pNext)) { 246 } else if (CPDF_Array* pArray = ToArray(pNext)) {
247 return CPDF_Action(pArray->GetDict(iIndex)); 247 return CPDF_Action(pArray->GetDict(iIndex));
248 } 248 }
249 return CPDF_Action(); 249 return CPDF_Action();
250 } 250 }
251 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", 251 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC",
252 "PV", "PI", "O", "C", "K", "F", "V", "C", 252 "PV", "PI", "O", "C", "K", "F", "V", "C",
253 "WC", "WS", "DS", "WP", "DP", ""}; 253 "WC", "WS", "DS", "WP", "DP", ""};
254 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { 254 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const {
255 if (m_pDict == NULL) { 255 if (!m_pDict) {
256 return FALSE; 256 return FALSE;
Tom Sepez 2015/12/14 18:27:00 nit: return m_pDict && m_pDictKeyExist(...);
Lei Zhang 2015/12/15 01:58:35 Done.
257 } 257 }
258 return m_pDict->KeyExist(g_sAATypes[(int)eType]); 258 return m_pDict->KeyExist(g_sAATypes[(int)eType]);
259 } 259 }
260 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { 260 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const {
261 if (!m_pDict) { 261 if (!m_pDict) {
262 return CPDF_Action(); 262 return CPDF_Action();
263 } 263 }
264 return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType])); 264 return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType]));
265 } 265 }
266 FX_POSITION CPDF_AAction::GetStartPos() const { 266 FX_POSITION CPDF_AAction::GetStartPos() const {
267 if (m_pDict == NULL) { 267 if (!m_pDict) {
268 return NULL; 268 return NULL;
269 } 269 }
270 return m_pDict->GetStartPos(); 270 return m_pDict->GetStartPos();
271 } 271 }
272 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, 272 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos,
273 AActionType& eType) const { 273 AActionType& eType) const {
274 if (m_pDict == NULL) { 274 if (!m_pDict) {
275 return CPDF_Action(); 275 return CPDF_Action();
276 } 276 }
277 CFX_ByteString csKey; 277 CFX_ByteString csKey;
278 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); 278 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey);
279 if (!pObj) { 279 if (!pObj) {
280 return CPDF_Action(); 280 return CPDF_Action();
281 } 281 }
282 CPDF_Object* pDirect = pObj->GetDirect(); 282 CPDF_Object* pDirect = pObj->GetDirect();
283 CPDF_Dictionary* pDict = ToDictionary(pDirect); 283 CPDF_Dictionary* pDict = ToDictionary(pDirect);
284 if (!pDict) 284 if (!pDict)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if (!ToDictionary(pAction)) { 319 if (!ToDictionary(pAction)) {
320 return CPDF_Action(); 320 return CPDF_Action();
321 } 321 }
322 return CPDF_Action(pAction->GetDict()); 322 return CPDF_Action(pAction->GetDict());
323 } 323 }
324 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { 324 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const {
325 ASSERT(m_pDocument); 325 ASSERT(m_pDocument);
326 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); 326 CPDF_NameTree name_tree(m_pDocument, "JavaScript");
327 return name_tree.GetIndex(csName); 327 return name_tree.GetIndex(csName);
328 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698