|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Utility class for resolving DRM protection. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "MsgMailDRMHandler.h" |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <DRMHelper.h> |
|
25 #include <caf/data.h> |
|
26 #include <MsgAttachmentInfo.h> |
|
27 #include <MsgAttachmentModel.h> |
|
28 #include <caf/caf.h> |
|
29 #include "MailLog.h" |
|
30 |
|
31 // LOCAL CONSTANTS AND MACROS |
|
32 |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // C++ default constructor cannot contain any code that might leave |
|
37 MsgMailDRMHandler::MsgMailDRMHandler() |
|
38 { |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CMsgMailEditorAppUi::FileSize() |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 void MsgMailDRMHandler::ConstructL() |
|
46 { |
|
47 iDRMHelper = CDRMHelper::NewL(); |
|
48 } |
|
49 |
|
50 // Symbian OS default constructor can leave. |
|
51 EXPORT_C MsgMailDRMHandler* MsgMailDRMHandler::NewL() |
|
52 { |
|
53 MsgMailDRMHandler* self = new (ELeave) MsgMailDRMHandler(); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop();// self |
|
57 return self; |
|
58 } |
|
59 |
|
60 // Destructor |
|
61 EXPORT_C MsgMailDRMHandler::~MsgMailDRMHandler() |
|
62 { |
|
63 delete iDRMHelper; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // MsgMailDRMHandler::IsForwardLockedFileL() |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C TBool MsgMailDRMHandler::IsForwardLockedFileL ( |
|
71 RFile& aFileHandle ) |
|
72 { |
|
73 |
|
74 TBool isForwardable; |
|
75 TBool valid; |
|
76 TBool drmProtected; |
|
77 GetFileInfoL ( aFileHandle, isForwardable, valid, drmProtected); |
|
78 |
|
79 |
|
80 if(drmProtected) |
|
81 { |
|
82 return !isForwardable; |
|
83 } |
|
84 else |
|
85 { |
|
86 //No drm protection, so can't be forward locked. |
|
87 return EFalse; |
|
88 } |
|
89 |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // MsgMailDRMHandler::IsSeparateDeliveryFileL() |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C TBool MsgMailDRMHandler::IsSuperDistributableFileL ( |
|
97 RFile& aFileHandle ) |
|
98 { |
|
99 |
|
100 TBool isForwardable; |
|
101 TBool valid; |
|
102 TBool drmProtected; |
|
103 |
|
104 GetFileInfoL ( aFileHandle, isForwardable, valid, drmProtected); |
|
105 |
|
106 if(drmProtected) |
|
107 { |
|
108 return isForwardable; |
|
109 } |
|
110 else |
|
111 { |
|
112 //No drm protection, so can't be super distributable. |
|
113 return EFalse; |
|
114 } |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // MsgMailDRMHandler::SetDRMDataTypeL() |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C void MsgMailDRMHandler::SetDRMDataTypeL ( |
|
122 CMsgAttachmentInfo& aAttachmentInfo, RFile& aFileHandle ) |
|
123 { |
|
124 LOG(">MsgMailDRMHandler::SetDRMDataTypeL"); |
|
125 TBool isForwardable; |
|
126 TBool valid; |
|
127 TBool drmProtected; |
|
128 |
|
129 GetFileInfoL ( aFileHandle, isForwardable, valid, drmProtected); |
|
130 |
|
131 if ( drmProtected && isForwardable ) |
|
132 { |
|
133 LOG("MsgMailDRMHandler::SetDRMDataTypeL - drm protected"); |
|
134 CMsgAttachmentInfo::TDRMDataType drmType = valid ? |
|
135 CMsgAttachmentInfo::ESeparateDeliveryValidRights : |
|
136 CMsgAttachmentInfo::ESeparateDeliveryInvalidRights; |
|
137 |
|
138 aAttachmentInfo.SetDRMDataType( drmType ); |
|
139 } |
|
140 else if( drmProtected && !isForwardable ) |
|
141 { |
|
142 LOG("MsgMailDRMHandler::SetDRMDataTypeL - forward locked"); |
|
143 aAttachmentInfo.SetDRMDataType( |
|
144 CMsgAttachmentInfo::EForwardLockedOrCombinedDelivery ); |
|
145 } |
|
146 LOG("<MsgMailDRMHandler::SetDRMDataTypeL"); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // MsgMailDRMHandler::GetDRMDataTypeL() |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C CMsgAttachmentInfo::TDRMDataType MsgMailDRMHandler::GetDRMDataTypeL( |
|
154 RFile aFileHandle ) |
|
155 { |
|
156 |
|
157 TBool isForwardable; |
|
158 TBool valid; |
|
159 TBool drmProtected; |
|
160 |
|
161 GetFileInfoL ( aFileHandle, isForwardable, valid, drmProtected); |
|
162 |
|
163 CMsgAttachmentInfo::TDRMDataType drmType( |
|
164 CMsgAttachmentInfo::ENoLimitations ); |
|
165 |
|
166 if ( drmProtected && isForwardable ) |
|
167 { |
|
168 drmType = valid ? |
|
169 CMsgAttachmentInfo::ESeparateDeliveryValidRights : |
|
170 CMsgAttachmentInfo::ESeparateDeliveryInvalidRights; |
|
171 } |
|
172 else if(drmProtected && !isForwardable) |
|
173 { |
|
174 drmType = CMsgAttachmentInfo::EForwardLockedOrCombinedDelivery; |
|
175 } |
|
176 return drmType; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // MsgMailDRMHandler::GetFileInfo() |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void MsgMailDRMHandler::GetFileInfoL ( RFile& aFileHandle, |
|
184 TBool& aIsForwardable, TBool& aValidRights, TBool& aProtection) |
|
185 { |
|
186 LOG(">MsgMailDRMHandler::GetFileInfoL"); |
|
187 aProtection = EFalse; |
|
188 |
|
189 //These two are only valid if file is drm protected. |
|
190 aValidRights = EFalse; |
|
191 aIsForwardable = EFalse; |
|
192 |
|
193 LOG("MsgMailDRMHandler::GetFileInfoL - CContent"); |
|
194 CContent* content = CContent::NewLC(aFileHandle); |
|
195 |
|
196 TInt isDRMProtected = 0; |
|
197 |
|
198 //Check if file is drm protected. If not no need for further checks. |
|
199 LOG("MsgMailDRMHandler::GetFileInfoL - CContent::GetAttribute protected"); |
|
200 User::LeaveIfError(content->GetAttribute(EIsProtected, isDRMProtected)); |
|
201 |
|
202 if (isDRMProtected) |
|
203 { |
|
204 aProtection = ETrue; |
|
205 |
|
206 //Check if forwardable or superdistributable. |
|
207 TInt isForwardable; |
|
208 LOG("MsgMailDRMHandler::GetFileInfoL - CContent::GetAttribute forwardable"); |
|
209 User::LeaveIfError(content->GetAttribute(EIsForwardable, isForwardable)); |
|
210 |
|
211 aIsForwardable = isForwardable; |
|
212 |
|
213 CData* data = NULL; |
|
214 |
|
215 // In the case of invalid rights, CData::NewLC will leave with KErrCANoRights, |
|
216 // KErrCANoPermission, or KErrCAPendingRights |
|
217 TRAPD(rightscheck, data = CData::NewL( aFileHandle, KDefaultContentObject, EUnknown )); |
|
218 |
|
219 if(rightscheck == KErrNone) |
|
220 { |
|
221 aValidRights = ETrue; |
|
222 delete data; |
|
223 } |
|
224 } |
|
225 CleanupStack::PopAndDestroy(content); |
|
226 LOG("<MsgMailDRMHandler::GetFileInfoL"); |
|
227 } |
|
228 |
|
229 // End of File |