Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "fpdfsdk/javascript/Annot.h" | 7 #include "fpdfsdk/javascript/Annot.h" |
| 8 | 8 |
| 9 #include "fpdfsdk/javascript/JS_Define.h" | 9 #include "fpdfsdk/javascript/JS_Define.h" |
| 10 #include "fpdfsdk/javascript/JS_Object.h" | 10 #include "fpdfsdk/javascript/JS_Object.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 BEGIN_JS_STATIC_METHOD(CJS_Annot) | 31 BEGIN_JS_STATIC_METHOD(CJS_Annot) |
| 32 END_JS_STATIC_METHOD() | 32 END_JS_STATIC_METHOD() |
| 33 | 33 |
| 34 IMPLEMENT_JS_CLASS(CJS_Annot, Annot) | 34 IMPLEMENT_JS_CLASS(CJS_Annot, Annot) |
| 35 | 35 |
| 36 Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} | 36 Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} |
| 37 | 37 |
| 38 Annot::~Annot() {} | 38 Annot::~Annot() {} |
| 39 | 39 |
| 40 bool Annot::hidden(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 40 bool Annot::hidden(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 41 CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot.Get()); | |
| 42 if (!baAnnot) | |
| 43 return false; | |
| 44 | |
| 45 if (vp.IsGetting()) { | 41 if (vp.IsGetting()) { |
| 46 CPDF_Annot* pPDFAnnot = baAnnot->GetPDFAnnot(); | 42 if (!m_pAnnot) { |
| 43 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | |
| 44 return false; | |
| 45 } | |
| 46 CPDF_Annot* pPDFAnnot = ToBAAnnot(m_pAnnot.Get())->GetPDFAnnot(); | |
| 47 vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()); | 47 vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()); |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool bHidden; | 51 bool bHidden; |
| 52 vp >> bHidden; | 52 vp >> bHidden; // May invalidate m_pAnnot. |
|
dsinclair
2017/01/12 19:14:40
This seems like a crazy side effect. Should we log
| |
| 53 if (!m_pAnnot) { | |
| 54 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | |
| 55 return false; | |
| 56 } | |
| 53 | 57 |
| 54 uint32_t flags = baAnnot->GetFlags(); | 58 uint32_t flags = ToBAAnnot(m_pAnnot.Get())->GetFlags(); |
| 55 if (bHidden) { | 59 if (bHidden) { |
| 56 flags |= ANNOTFLAG_HIDDEN; | 60 flags |= ANNOTFLAG_HIDDEN; |
| 57 flags |= ANNOTFLAG_INVISIBLE; | 61 flags |= ANNOTFLAG_INVISIBLE; |
| 58 flags |= ANNOTFLAG_NOVIEW; | 62 flags |= ANNOTFLAG_NOVIEW; |
| 59 flags &= ~ANNOTFLAG_PRINT; | 63 flags &= ~ANNOTFLAG_PRINT; |
| 60 } else { | 64 } else { |
| 61 flags &= ~ANNOTFLAG_HIDDEN; | 65 flags &= ~ANNOTFLAG_HIDDEN; |
| 62 flags &= ~ANNOTFLAG_INVISIBLE; | 66 flags &= ~ANNOTFLAG_INVISIBLE; |
| 63 flags &= ~ANNOTFLAG_NOVIEW; | 67 flags &= ~ANNOTFLAG_NOVIEW; |
| 64 flags |= ANNOTFLAG_PRINT; | 68 flags |= ANNOTFLAG_PRINT; |
| 65 } | 69 } |
| 66 baAnnot->SetFlags(flags); | 70 ToBAAnnot(m_pAnnot.Get())->SetFlags(flags); |
| 67 return true; | 71 return true; |
| 68 } | 72 } |
| 69 | 73 |
| 70 bool Annot::name(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 74 bool Annot::name(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 71 CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot.Get()); | |
| 72 if (!baAnnot) | |
| 73 return false; | |
| 74 | |
| 75 if (vp.IsGetting()) { | 75 if (vp.IsGetting()) { |
| 76 vp << baAnnot->GetAnnotName(); | 76 if (!m_pAnnot) { |
| 77 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | |
| 78 return false; | |
| 79 } | |
| 80 vp << ToBAAnnot(m_pAnnot.Get())->GetAnnotName(); | |
| 77 return true; | 81 return true; |
| 78 } | 82 } |
| 79 | 83 |
| 80 CFX_WideString annotName; | 84 CFX_WideString annotName; |
| 81 vp >> annotName; | 85 vp >> annotName; // May invalidate m_pAnnot. |
| 82 baAnnot->SetAnnotName(annotName); | 86 if (!m_pAnnot) { |
| 87 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | |
| 88 return false; | |
| 89 } | |
| 90 | |
| 91 ToBAAnnot(m_pAnnot.Get())->SetAnnotName(annotName); | |
| 83 return true; | 92 return true; |
| 84 } | 93 } |
| 85 | 94 |
| 86 bool Annot::type(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 95 bool Annot::type(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 87 if (vp.IsSetting()) { | 96 if (vp.IsSetting()) { |
| 88 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 97 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 89 return false; | 98 return false; |
| 90 } | 99 } |
| 91 | 100 if (!m_pAnnot) { |
| 92 CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot.Get()); | 101 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 93 if (!baAnnot) | |
| 94 return false; | 102 return false; |
| 95 | 103 } |
| 96 vp << CPDF_Annot::AnnotSubtypeToString(baAnnot->GetAnnotSubtype()); | 104 vp << CPDF_Annot::AnnotSubtypeToString( |
| 105 ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype()); | |
| 97 return true; | 106 return true; |
| 98 } | 107 } |
| 99 | 108 |
| 100 void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { | 109 void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { |
| 101 m_pAnnot.Reset(annot); | 110 m_pAnnot.Reset(annot); |
| 102 } | 111 } |
| OLD | NEW |