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

Side by Side Diff: fpdfsdk/src/fsdk_baseform.cpp

Issue 1411663013: Cleanup: Remove some NULL checks in fpdfsdk. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: even simplier? Created 5 years, 1 month 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
« no previous file with comments | « fpdfsdk/src/fpdfeditpage.cpp ('k') | fpdfsdk/src/javascript/PublicMethods.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../third_party/base/nonstd_unique_ptr.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 #include "../include/fsdk_mgr.h" 9 #include "../include/fsdk_mgr.h"
10 #include "../include/fsdk_baseannot.h" 10 #include "../include/fsdk_baseannot.h"
(...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 if (pFormField->CountSelectedItems() > 0) { 1799 if (pFormField->CountSelectedItems() > 0) {
1800 int index = pFormField->GetSelectedIndex(0); 1800 int index = pFormField->GetSelectedIndex(0);
1801 if (index >= 0) 1801 if (index >= 0)
1802 sValue = pFormField->GetOptionLabel(index); 1802 sValue = pFormField->GetOptionLabel(index);
1803 } 1803 }
1804 } 1804 }
1805 1805
1806 bFormated = FALSE; 1806 bFormated = FALSE;
1807 1807
1808 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 1808 CPDF_AAction aAction = pFormField->GetAdditionalAction();
1809 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) { 1809 if (aAction && aAction.ActionExist(CPDF_AAction::Format)) {
1810 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); 1810 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
1811 if (action) { 1811 if (action) {
1812 CFX_WideString script = action.GetJavaScript(); 1812 CFX_WideString script = action.GetJavaScript();
1813 if (!script.IsEmpty()) { 1813 if (!script.IsEmpty()) {
1814 CFX_WideString Value = sValue; 1814 CFX_WideString Value = sValue;
1815 1815
1816 IJS_Context* pContext = pRuntime->NewContext(); 1816 IJS_Context* pContext = pRuntime->NewContext();
1817 ASSERT(pContext != NULL); 1817 ASSERT(pContext != NULL);
1818 1818
1819 pContext->OnField_Format(pFormField, Value, TRUE); 1819 pContext->OnField_Format(pFormField, Value, TRUE);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 } 1869 }
1870 } 1870 }
1871 } 1871 }
1872 1872
1873 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, 1873 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
1874 CFX_WideString& csValue, 1874 CFX_WideString& csValue,
1875 FX_BOOL& bRC) { 1875 FX_BOOL& bRC) {
1876 ASSERT(pFormField != NULL); 1876 ASSERT(pFormField != NULL);
1877 1877
1878 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 1878 CPDF_AAction aAction = pFormField->GetAdditionalAction();
1879 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke)) { 1879 if (aAction && aAction.ActionExist(CPDF_AAction::KeyStroke)) {
1880 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); 1880 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
1881 if (action) { 1881 if (action) {
1882 ASSERT(m_pDocument != NULL); 1882 ASSERT(m_pDocument != NULL);
1883 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); 1883 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1884 ASSERT(pEnv != NULL); 1884 ASSERT(pEnv != NULL);
1885 1885
1886 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); 1886 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
1887 ASSERT(pActionHandler != NULL); 1887 ASSERT(pActionHandler != NULL);
1888 1888
1889 PDFSDK_FieldAction fa; 1889 PDFSDK_FieldAction fa;
1890 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); 1890 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
1891 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); 1891 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
1892 fa.sValue = csValue; 1892 fa.sValue = csValue;
1893 1893
1894 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, 1894 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
1895 m_pDocument, pFormField, fa); 1895 m_pDocument, pFormField, fa);
1896 bRC = fa.bRC; 1896 bRC = fa.bRC;
1897 } 1897 }
1898 } 1898 }
1899 } 1899 }
1900 1900
1901 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, 1901 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
1902 CFX_WideString& csValue, 1902 CFX_WideString& csValue,
1903 FX_BOOL& bRC) { 1903 FX_BOOL& bRC) {
1904 ASSERT(pFormField != NULL); 1904 ASSERT(pFormField != NULL);
1905 1905
1906 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 1906 CPDF_AAction aAction = pFormField->GetAdditionalAction();
1907 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate)) { 1907 if (aAction && aAction.ActionExist(CPDF_AAction::Validate)) {
1908 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); 1908 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
1909 if (action) { 1909 if (action) {
1910 ASSERT(m_pDocument != NULL); 1910 ASSERT(m_pDocument != NULL);
1911 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); 1911 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1912 ASSERT(pEnv != NULL); 1912 ASSERT(pEnv != NULL);
1913 1913
1914 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); 1914 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
1915 ASSERT(pActionHandler != NULL); 1915 ASSERT(pActionHandler != NULL);
1916 1916
1917 PDFSDK_FieldAction fa; 1917 PDFSDK_FieldAction fa;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, 2031 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile,
2032 CFX_WideString csTxtFile) { 2032 CFX_WideString csTxtFile) {
2033 return TRUE; 2033 return TRUE;
2034 } 2034 }
2035 2035
2036 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, 2036 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
2037 FX_STRSIZE& nBufSize) { 2037 FX_STRSIZE& nBufSize) {
2038 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); 2038 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
2039 if (pFDF) { 2039 if (pFDF) {
2040 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); 2040 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
2041 if (pMainDict == NULL) 2041 if (!pMainDict)
2042 return FALSE; 2042 return FALSE;
2043 2043
2044 // Get fields 2044 // Get fields
2045 CPDF_Array* pFields = pMainDict->GetArray("Fields"); 2045 CPDF_Array* pFields = pMainDict->GetArray("Fields");
2046 if (pFields == NULL) 2046 if (!pFields)
2047 return FALSE; 2047 return FALSE;
2048 2048
2049 CFX_ByteTextBuf fdfEncodedData; 2049 CFX_ByteTextBuf fdfEncodedData;
2050 2050
2051 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { 2051 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
2052 CPDF_Dictionary* pField = pFields->GetDict(i); 2052 CPDF_Dictionary* pField = pFields->GetDict(i);
2053 if (pField == NULL) 2053 if (!pField)
2054 continue; 2054 continue;
2055 CFX_WideString name; 2055 CFX_WideString name;
2056 name = pField->GetUnicodeText("T"); 2056 name = pField->GetUnicodeText("T");
2057 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); 2057 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
2058 CFX_ByteString csBValue = pField->GetString("V"); 2058 CFX_ByteString csBValue = pField->GetString("V");
2059 CFX_WideString csWValue = PDF_DecodeText(csBValue); 2059 CFX_WideString csWValue = PDF_DecodeText(csBValue);
2060 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); 2060 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
2061 2061
2062 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); 2062 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength());
2063 name_b.ReleaseBuffer(); 2063 name_b.ReleaseBuffer();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 } 2099 }
2100 2100
2101 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, 2101 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
2102 FX_BOOL bUrlEncoded) { 2102 FX_BOOL bUrlEncoded) {
2103 if (sDestination.IsEmpty()) 2103 if (sDestination.IsEmpty())
2104 return FALSE; 2104 return FALSE;
2105 2105
2106 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); 2106 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2107 ASSERT(pEnv != NULL); 2107 ASSERT(pEnv != NULL);
2108 2108
2109 if (NULL == m_pDocument) 2109 if (!m_pDocument)
2110 return FALSE; 2110 return FALSE;
2111 CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); 2111 CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
2112 2112
2113 if (NULL == m_pInterForm) 2113 if (!m_pInterForm)
2114 return FALSE; 2114 return FALSE;
2115 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath); 2115 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
2116 if (NULL == pFDFDoc) 2116 if (!pFDFDoc)
2117 return FALSE; 2117 return FALSE;
2118 2118
2119 CFX_ByteTextBuf FdfBuffer; 2119 CFX_ByteTextBuf FdfBuffer;
2120 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); 2120 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
2121 delete pFDFDoc; 2121 delete pFDFDoc;
2122 if (!bRet) 2122 if (!bRet)
2123 return FALSE; 2123 return FALSE;
2124 2124
2125 uint8_t* pBuffer = FdfBuffer.GetBuffer(); 2125 uint8_t* pBuffer = FdfBuffer.GetBuffer();
2126 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); 2126 FX_STRSIZE nBufSize = FdfBuffer.GetLength();
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 break; 2550 break;
2551 } 2551 }
2552 } 2552 }
2553 } 2553 }
2554 2554
2555 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { 2555 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) {
2556 CPDF_Rect rcAnnot; 2556 CPDF_Rect rcAnnot;
2557 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); 2557 pAnnot->GetPDFAnnot()->GetRect(rcAnnot);
2558 return rcAnnot; 2558 return rcAnnot;
2559 } 2559 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfeditpage.cpp ('k') | fpdfsdk/src/javascript/PublicMethods.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698