|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Implementation of DCF handler class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <s32mem.h> |
|
21 #include <coemain.h> |
|
22 |
|
23 #include <DRMCommon.h> |
|
24 #include <DRMHelper.h> |
|
25 #include <AiwGenericParam.h> |
|
26 #include <AknQueryDialog.h> // CAknQueryDialog |
|
27 #include <documenthandlerui.rsg> // Resource ids |
|
28 #include <StringLoader.h> // For loading resource strings |
|
29 #include <stringresourcereader.h> // CStringResourceReader |
|
30 |
|
31 #include "DocDCFHandler.h" |
|
32 #include "DocDefaultHandler.h" |
|
33 #include "DocResourceFile.h" |
|
34 #include "DocSaver.h" |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // --------------------------------------------------------- |
|
40 // |
|
41 CDocDCFHandler::CDocDCFHandler( |
|
42 const TDataType& aDataType, |
|
43 TDocOperation aOperation, |
|
44 const TUid& aUid, |
|
45 CDocumentHandler* aDocDispatcher): |
|
46 CDocDefaultHandler( aDataType, aUid, aDocDispatcher, EDocOpenAndSave ), |
|
47 iEntryFunc( aOperation ) |
|
48 { |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // Two-phased constructor. |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 CDocDCFHandler* CDocDCFHandler::NewL( |
|
56 const TDataType& aDataType, |
|
57 TDocOperation aOperation, |
|
58 const TUid& aUid, |
|
59 CDocumentHandler* aDocDispatcher) |
|
60 { |
|
61 CDocDCFHandler *self = new (ELeave) CDocDCFHandler( aDataType, aOperation, aUid, aDocDispatcher ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // Epoc contructor |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 void CDocDCFHandler::ConstructL() |
|
73 { |
|
74 BaseConstructL(); |
|
75 iDRMCommon = DRMCommon::NewL(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------- |
|
79 // Destructor |
|
80 // --------------------------------------------------------- |
|
81 // |
|
82 CDocDCFHandler::~CDocDCFHandler() |
|
83 { |
|
84 delete iDRMCommon; |
|
85 delete iDocHandler; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CDocDCFHandler::SetDataTypeL() |
|
90 // Set the data type (iDataType) |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 void CDocDCFHandler::SetDataTypeL(HBufC8* MIMEType) |
|
94 { |
|
95 TPtr8 ptr = MIMEType->Des(); |
|
96 ptr.Copy(*MIMEType); |
|
97 iDataType = TDataType( ptr ); |
|
98 #ifdef _DEBUG |
|
99 TPtrC mimetype = iDataType.Des(); |
|
100 RDebug::Print( _L("DocumentHandler: CDocDCFHandler::SetDataTypeL: iDataType: %S "), &mimetype); |
|
101 #endif |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CDocDCFHandler::GetPath() |
|
106 // Return the path where the content was saved/copied |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 void CDocDCFHandler::GetPath( TDes& aPath ) const |
|
110 { |
|
111 if ( iDocHandler ) |
|
112 { |
|
113 iDocHandler->GetPath( aPath ); |
|
114 } |
|
115 else |
|
116 { |
|
117 aPath.Zero(); |
|
118 } |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------- |
|
122 // CDocDCFHandler::HandlerAppUid() |
|
123 // Returns handler application Uid. |
|
124 // --------------------------------------------------------- |
|
125 // |
|
126 void CDocDCFHandler::HandlerAppUid( TUid& aUid ) const |
|
127 { |
|
128 if ( iDocHandler ) |
|
129 { |
|
130 iDocHandler->HandlerAppUid( aUid ); |
|
131 } |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CDocDCFHandler::CanOpen() |
|
136 // Is the handler capable of opening the mime type |
|
137 // --------------------------------------------------------- |
|
138 // |
|
139 TBool CDocDCFHandler::CanOpen() const |
|
140 { |
|
141 return ETrue; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CDocDCFHandler::CanSave() |
|
146 // Is the handler capable of saving the mime type |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 TBool CDocDCFHandler::CanSave() const |
|
150 { |
|
151 return ETrue; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CDocDCFHandler::ConvertErrorCode() |
|
156 // Converts DRM error code to more generic one |
|
157 // --------------------------------------------------------- |
|
158 // |
|
159 TInt CDocDCFHandler::ConvertErrorCode(TInt aDrmError) |
|
160 { |
|
161 switch (aDrmError) |
|
162 { |
|
163 case DRMCommon::EOk: |
|
164 return KErrNone; |
|
165 case DRMCommon::EGeneralError: |
|
166 return KErrGeneral; |
|
167 case DRMCommon::EUnknownMIME: |
|
168 return KMimeNotSupported; |
|
169 case DRMCommon::EVersionNotSupported: |
|
170 return KDRMErrInvalidVersion; |
|
171 case DRMCommon::ESessionError: |
|
172 return KDRMErrSession; |
|
173 case DRMCommon::ENoRights: |
|
174 return KDRMErrNoRights; |
|
175 case DRMCommon::ERightsDBCorrupted: |
|
176 return KDRMErrRightsDBCorrupted; |
|
177 case DRMCommon::EUnsupported: |
|
178 return KErrNotSupported; |
|
179 default: |
|
180 break; |
|
181 } |
|
182 |
|
183 // It is possible that DRM error is normal errorcode |
|
184 // those are passed without conversion. |
|
185 return aDrmError; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CDocDCFHandler::OpenFileL( ) |
|
190 // Calls OpenDCFFileL. |
|
191 // --------------------------------------------------------- |
|
192 // |
|
193 TInt CDocDCFHandler::OpenFileL(RFile& aFileHandle) |
|
194 { |
|
195 #ifdef _DEBUG |
|
196 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::OpenFileL called.")); |
|
197 #endif |
|
198 return OpenDCFFileL( aFileHandle ); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CDocDCFHandler::OpenFileEmbeddedL( ) |
|
203 // Calls OpenDCFFileL. |
|
204 // --------------------------------------------------------- |
|
205 // |
|
206 TInt CDocDCFHandler::OpenFileEmbeddedL(RFile& aFileHandle) |
|
207 { |
|
208 #ifdef _DEBUG |
|
209 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::OpenFileEmbeddedL called.")); |
|
210 #endif |
|
211 return OpenDCFFileL( aFileHandle ); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------- |
|
215 // CDocDCFHandler::CopyOrMoveL( ) |
|
216 // Calls CopyDCFFileL. |
|
217 // CopyL & MoveL & SilentMoveL is supported |
|
218 // --------------------------------------------------------- |
|
219 // |
|
220 TInt CDocDCFHandler::CopyOrMoveL( const TUint aAttr) |
|
221 { |
|
222 #ifdef _DEBUG |
|
223 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::CopyOrMoveL called.")); |
|
224 #endif |
|
225 |
|
226 RFile tempHandle; // This is only temporary, not used to anything |
|
227 TInt retValue = CopyDCFFileL(EFalse, tempHandle, aAttr); |
|
228 tempHandle.Close(); |
|
229 return retValue; |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // CDocDCFHandler::CopyOrMoveL( ) |
|
234 // Calls CopyDCFFileL. |
|
235 // CopyL is supported |
|
236 // --------------------------------------------------------- |
|
237 // |
|
238 TInt CDocDCFHandler::CopyHandleL( const RFile& aSourceFile, const TUint aAttr ) |
|
239 { |
|
240 // CopyL (with filehandle) is supported |
|
241 #ifdef _DEBUG |
|
242 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::CopyHandleL called.")); |
|
243 #endif |
|
244 |
|
245 return CopyDCFFileL(ETrue, const_cast<RFile&>(aSourceFile), aAttr); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------- |
|
249 // CDocDCFHandler::OpenDCFFileL( ) |
|
250 // Check DRM rights and create new CDocumentHandler instance |
|
251 // for handling actual operation with payload MIME-type. |
|
252 // --------------------------------------------------------- |
|
253 // |
|
254 TInt CDocDCFHandler::OpenDCFFileL(RFile& aFileHandle) |
|
255 { |
|
256 TUint bufLength; |
|
257 DRMCommon::TContentProtection protection; |
|
258 HBufC8* MIMEType = NULL; |
|
259 HBufC8* contentURI = NULL; |
|
260 TInt error; |
|
261 |
|
262 error = iDRMCommon->GetFileInfo(aFileHandle, |
|
263 protection, |
|
264 MIMEType, |
|
265 contentURI, |
|
266 bufLength); |
|
267 |
|
268 if (error != DRMCommon::EOk) |
|
269 { |
|
270 #ifdef _DEBUG |
|
271 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::OpenDCFFileL: GetFileInfo returned=%d"), error); |
|
272 #endif |
|
273 return ConvertErrorCode(error); |
|
274 } |
|
275 else |
|
276 { |
|
277 error = KErrNone; |
|
278 } |
|
279 |
|
280 // Errorcode from iDRMCommon cannot be trusted. Check here params first. |
|
281 if (!MIMEType || !contentURI) |
|
282 { |
|
283 if (MIMEType) |
|
284 delete MIMEType; |
|
285 |
|
286 if (contentURI) |
|
287 delete contentURI; |
|
288 |
|
289 return KDRMErrInvalidVersion; // This is one possible reason |
|
290 } |
|
291 |
|
292 CleanupStack::PushL( MIMEType ); |
|
293 CleanupStack::PushL( contentURI ); |
|
294 |
|
295 if ( MIMEType->FindF( KDataTypeDCF ) != KErrNotFound ) |
|
296 { |
|
297 CleanupStack::PopAndDestroy(2); // MIMEType, contentURI |
|
298 return KBadMimeType; |
|
299 } |
|
300 |
|
301 SetDataTypeL( MIMEType ); |
|
302 |
|
303 CDRMRights* rightsObject = NULL; |
|
304 TInt rights = iDRMCommon->GetActiveRights(*contentURI, 0, rightsObject); |
|
305 delete rightsObject; |
|
306 CleanupStack::PopAndDestroy(2); // MIMEType, contentURI |
|
307 |
|
308 #ifdef _DEBUG |
|
309 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::OpenDCFFileL: Rights of file are=%d"), rights); |
|
310 #endif |
|
311 |
|
312 // Check if file is empty (rights must exist before we can trust bufLength) |
|
313 if (rights != DRMCommon::ENoRights && bufLength == 0) |
|
314 { |
|
315 return KNullContent; |
|
316 } |
|
317 |
|
318 if ( !iDocHandler ) |
|
319 { |
|
320 iDocHandler = CDocumentHandler::NewL( ); |
|
321 if (iDocDispatcher->ServerAppExitObserver()) |
|
322 { |
|
323 iDocHandler->SetExitObserver(iDocDispatcher->ServerAppExitObserver()); |
|
324 } |
|
325 } |
|
326 |
|
327 if (rights == DRMCommon::ENoRights) |
|
328 { |
|
329 return KDRMErrNoRights; |
|
330 } |
|
331 |
|
332 switch ( iEntryFunc ) |
|
333 { |
|
334 case EDocOpenFileEmb: |
|
335 error = iDocHandler->OpenFileEmbeddedL( aFileHandle, iDataType, *iAiwParams ); |
|
336 break; |
|
337 case EDocOpenFile: |
|
338 error = iDocHandler->OpenFileL( aFileHandle, iDataType ); |
|
339 break; |
|
340 default: |
|
341 User::Leave( KErrNotSupported ); |
|
342 } |
|
343 |
|
344 iStatus = error; |
|
345 |
|
346 return error; |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------- |
|
350 // CDocDCFHandler::CopyDCFFileL( ) |
|
351 // Check DRM rights and create new CDocumentHandler instance |
|
352 // for handling actual operation with payload MIME-type. |
|
353 // --------------------------------------------------------- |
|
354 // |
|
355 TInt CDocDCFHandler::CopyDCFFileL(TBool aUseHandle, RFile& aFileHandle, const TUint aAttr) |
|
356 { |
|
357 TUint bufLength; |
|
358 DRMCommon::TContentProtection protection; |
|
359 HBufC8* MIMEType = NULL; |
|
360 HBufC8* contentURI = NULL; |
|
361 TInt error; |
|
362 |
|
363 if (aUseHandle) // Filehandle version |
|
364 { |
|
365 error = iDRMCommon->GetFileInfo(aFileHandle, |
|
366 protection, |
|
367 MIMEType, |
|
368 contentURI, |
|
369 bufLength); |
|
370 } |
|
371 else // FileName version |
|
372 { |
|
373 error = iDRMCommon->GetFileInfo(iSourceFile, |
|
374 protection, |
|
375 MIMEType, |
|
376 contentURI, |
|
377 bufLength); |
|
378 } |
|
379 |
|
380 if (error != DRMCommon::EOk) |
|
381 { |
|
382 #ifdef _DEBUG |
|
383 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::CopyDCFFileL: GetFileInfo returned=%d"), error); |
|
384 #endif |
|
385 return ConvertErrorCode(error); |
|
386 } |
|
387 else |
|
388 { |
|
389 error = KErrNone; |
|
390 } |
|
391 |
|
392 // Errorcode from iDRMCommon cannot be trusted. Check here params first. |
|
393 if (!MIMEType || !contentURI) |
|
394 { |
|
395 if (MIMEType) |
|
396 delete MIMEType; |
|
397 if (contentURI) |
|
398 delete contentURI; |
|
399 return KDRMErrInvalidVersion; // This is one possible reason |
|
400 } |
|
401 |
|
402 CleanupStack::PushL( MIMEType ); |
|
403 CleanupStack::PushL( contentURI ); |
|
404 |
|
405 if ( MIMEType->FindF( KDataTypeDCF ) != KErrNotFound ) |
|
406 { |
|
407 CleanupStack::PopAndDestroy(2); // MIMEType, contentURI |
|
408 return KBadMimeType; |
|
409 } |
|
410 |
|
411 SetDataTypeL( MIMEType ); |
|
412 |
|
413 CDRMRights* rightsObject = NULL; |
|
414 TInt rights = iDRMCommon->GetActiveRights(*contentURI, 0, rightsObject); |
|
415 delete rightsObject; |
|
416 CleanupStack::PopAndDestroy(2); // MIMEType, contentURI |
|
417 |
|
418 #ifdef _DEBUG |
|
419 RDebug::Print( _L("DocumentHandler : CDocDCFHandler::CopyDCFFileL: Rights of file are=%d"), rights); |
|
420 #endif |
|
421 |
|
422 // Check if file is empty (rights must exist before we can trust bufLength) |
|
423 if (rights != DRMCommon::ENoRights && bufLength == 0) |
|
424 { |
|
425 return KNullContent; |
|
426 } |
|
427 |
|
428 // Check if file is with PreviewRights (preview file is not allowed to save) |
|
429 if (rights == CDRMRights::EPreviewRights && protection == DRMCommon::EForwardLocked) |
|
430 { |
|
431 return KDRMErrPreviewRights; |
|
432 } |
|
433 |
|
434 if ( !iDocHandler ) |
|
435 { |
|
436 iDocHandler = CDocumentHandler::NewL( ); |
|
437 if (iDocDispatcher->ServerAppExitObserver()) |
|
438 { |
|
439 iDocHandler->SetExitObserver(iDocDispatcher->ServerAppExitObserver()); |
|
440 } |
|
441 } |
|
442 |
|
443 switch ( iEntryFunc ) |
|
444 { |
|
445 case EDocCopy: |
|
446 if (aUseHandle) // Filehandle version |
|
447 { |
|
448 error = iDocHandler->CopyL( aFileHandle, iDestFile, iDataType, aAttr ); |
|
449 } |
|
450 else // FileName version |
|
451 { |
|
452 error = iDocHandler->CopyL( iSourceFile, iDestFile, iDataType, aAttr ); |
|
453 } |
|
454 break; |
|
455 case EDocMove: |
|
456 error = iDocHandler->MoveL( iSourceFile, iDestFile, iDataType, aAttr ); |
|
457 break; |
|
458 case EDocSilentMove: |
|
459 error = iDocHandler->SilentMoveL( iSourceFile, iDestFile, iRootPath, iDataType, aAttr ); |
|
460 break; |
|
461 default: |
|
462 User::Leave( KErrNotSupported ); |
|
463 } |
|
464 |
|
465 iStatus = error; |
|
466 |
|
467 return error; |
|
468 } |
|
469 |
|
470 // End of File |