|
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 the License "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 * Implementation of Scheme handler interface implementation for file:// scheme |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "FileHandler.h" |
|
24 #include "SchemeDispLogger.h" |
|
25 #include <ECom.h> // For REComSession |
|
26 #include <eikenv.h> |
|
27 #include <apmstd.h> |
|
28 #include <apparc.h> |
|
29 #include <eikproc.h> |
|
30 #include <f32file.h> |
|
31 #include <APGTASK.H> |
|
32 #include <apgcli.h> |
|
33 |
|
34 // ================= CONSTANTS ======================= |
|
35 _LIT( KLocalhostPattern,"file://localhost/"); |
|
36 _LIT( KEmptyPattern,"file:///"); |
|
37 _LIT( KFilePattern,"file://"); |
|
38 _LIT( KBrowserPrefix, "4 " ); |
|
39 |
|
40 // ================= MEMBER FUNCTIONS ======================= |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CFileHandler::NewL() |
|
44 // --------------------------------------------------------- |
|
45 // |
|
46 CFileHandler* CFileHandler::NewL( const TDesC& aUrl ) |
|
47 { |
|
48 CLOG_ENTERFN( "CFileHandler::NewL()" ); |
|
49 |
|
50 CFileHandler* self=new(ELeave) CFileHandler(); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL( aUrl ); |
|
53 CleanupStack::Pop( self ); |
|
54 |
|
55 CLOG_LEAVEFN( "CFileHandler::NewL()" ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CFileHandler::~CFileHandler() |
|
61 // --------------------------------------------------------- |
|
62 // |
|
63 CFileHandler::~CFileHandler() |
|
64 { |
|
65 CLOG_ENTERFN( "CFileHandler::~CFileHandler()" ); |
|
66 |
|
67 if( iDocHandler ) |
|
68 { |
|
69 delete iDocHandler; |
|
70 } |
|
71 |
|
72 if(iDoc != NULL) |
|
73 { |
|
74 CEikProcess* hostProcess = CEikonEnv::Static()->Process(); |
|
75 hostProcess->DestroyDocument(iDoc); |
|
76 iDoc = NULL; |
|
77 } |
|
78 |
|
79 if( iLauncher ) |
|
80 { |
|
81 delete iLauncher; |
|
82 iLauncher = NULL; |
|
83 } |
|
84 |
|
85 CLOG_LEAVEFN( "CFileHandler::~CFileHandler()" ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CFileHandler::CFileHandler() |
|
90 // --------------------------------------------------------- |
|
91 // |
|
92 CFileHandler::CFileHandler() : CBaseHandler() |
|
93 { |
|
94 // Deliberately do nothing here : See ConstructL() for initialisation |
|
95 // completion. |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CFileHandler::ConstructL() |
|
100 // --------------------------------------------------------- |
|
101 // |
|
102 void CFileHandler::ConstructL( const TDesC& aUrl ) |
|
103 { |
|
104 iParsedUrl = HBufC::NewL( aUrl.Length() ); |
|
105 iParsedUrl->Des().Copy( aUrl ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CFileHandler::HandleUrlEmbeddedL() |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 void CFileHandler::HandleUrlEmbeddedL() |
|
113 { |
|
114 CLOG_ENTERFN( "CFileHandler::HandleUrlEmbeddedL()" ); |
|
115 |
|
116 TBool dochandler( ETrue ); |
|
117 HBufC* buf = ParseFileSchemeLC( dochandler ); |
|
118 |
|
119 if( dochandler ) |
|
120 { |
|
121 /* Documnet Handler launches the file */ |
|
122 iDocHandler = CDocumentHandler::NewL( |
|
123 CEikonEnv::Static()->Process() ); |
|
124 |
|
125 iDocHandler->SetExitObserver( this ); |
|
126 TDataType dataType; |
|
127 |
|
128 CAiwGenericParamList& paramList = iDocHandler->InParamListL(); |
|
129 RFile file; |
|
130 iDocHandler->OpenTempFileL( buf->Des(), file ); |
|
131 CLOG_WRITE(" OpenTempFileL OK"); |
|
132 CleanupClosePushL( file ); |
|
133 iDocHandler->OpenFileEmbeddedL( file, dataType, paramList ); |
|
134 CLOG_WRITE(" OpenFileEmbeddedL OK"); |
|
135 CleanupStack::PopAndDestroy( &file ); // file |
|
136 CLOG_WRITE(" PopAndDestroy( &file ) OK"); |
|
137 } |
|
138 else |
|
139 { |
|
140 HBufC* buf16 = HBufC::NewLC( |
|
141 iParsedUrl->Des().Length() + KBrowserPrefix.iTypeLength ); |
|
142 buf16->Des().Copy( KBrowserPrefix ); |
|
143 buf16->Des().Append( *buf ); |
|
144 |
|
145 iLauncher = CBrowserLauncher::NewL(); |
|
146 iLauncher->LaunchBrowserEmbeddedL( buf16->Des(), |
|
147 NULL, |
|
148 this ); |
|
149 CleanupStack::PopAndDestroy(); // buf16 |
|
150 } |
|
151 CleanupStack::PopAndDestroy(); //buf |
|
152 |
|
153 CLOG_LEAVEFN( "CFileHandler::HandleUrlEmbeddedL()" ); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------- |
|
157 // CFileHandler::HandleUrlStandaloneL() |
|
158 // --------------------------------------------------------- |
|
159 // |
|
160 void CFileHandler::HandleUrlStandaloneL() |
|
161 { |
|
162 CLOG_ENTERFN( "CFileHandler::HandleUrlStandaloneL()" ); |
|
163 |
|
164 LaunchSchemeAppWithCommandLineL(); |
|
165 |
|
166 CLOG_LEAVEFN( "CFileHandler::HandleUrlStandaloneL()" ); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------- |
|
170 // CFileHandler::HandleServerAppExit() |
|
171 // --------------------------------------------------------- |
|
172 // |
|
173 void CFileHandler::HandleServerAppExit(TInt aReason) |
|
174 { |
|
175 CLOG_ENTERFN( "CFileHandler::HandleServerAppExit" ); |
|
176 |
|
177 if( NULL != iSchemeDoc ) |
|
178 { |
|
179 iSchemeDoc->HandleServerAppExit( aReason ); |
|
180 } |
|
181 |
|
182 CLOG_LEAVEFN( "CFileHandler::HandleServerAppExit" ); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CFileHandler::ConvertUrlToPathL() |
|
187 // --------------------------------------------------------- |
|
188 // |
|
189 void CFileHandler::ConvertUrlToPathL( TDes& aLiteral ) |
|
190 { |
|
191 /* Search backslash in the path and change it to slash*/ |
|
192 _LIT16(KBackSlash16,"/"); |
|
193 _LIT16(KSlash16,"\\"); |
|
194 |
|
195 /* Find until the last occurance */ |
|
196 TInt pos; |
|
197 while( KErrNotFound != ( pos = aLiteral.FindF( KBackSlash16 ) ) ) |
|
198 { |
|
199 aLiteral.Replace(pos,1,KSlash16); |
|
200 } |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------- |
|
204 // CFileHandler::ConvertUrlToPathL() |
|
205 // --------------------------------------------------------- |
|
206 // |
|
207 void CFileHandler::ConvertPathToUrlL( TDes& aLiteral ) |
|
208 { |
|
209 /* Search backslash in the path and change it to slash*/ |
|
210 _LIT16(KBackSlash16,"/"); |
|
211 _LIT16(KSlash16,"\\"); |
|
212 |
|
213 /* Find until the last occurance */ |
|
214 TInt pos; |
|
215 while( KErrNotFound != ( pos = aLiteral.FindF( KSlash16 ) ) ) |
|
216 { |
|
217 aLiteral.Replace( pos, 1, KBackSlash16); |
|
218 } |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CFileHandler::ParseFileSchemeLC() |
|
223 // --------------------------------------------------------- |
|
224 // |
|
225 HBufC* CFileHandler::ParseFileSchemeLC( TBool& aDocHandler ) |
|
226 { |
|
227 TPtrC path; |
|
228 HBufC* pathCopy = NULL; |
|
229 TRAPD( err, path.Set( RemoveSchemeFromUrlL( KLocalhostPattern() ) ) ); |
|
230 if( !err ) |
|
231 { |
|
232 pathCopy = HBufC::NewLC( path.Length() ); |
|
233 pathCopy->Des().Copy( path ); |
|
234 TPtr ptr = pathCopy->Des(); |
|
235 ConvertUrlToPathL( ptr ); |
|
236 aDocHandler = ETrue; |
|
237 return pathCopy; |
|
238 } |
|
239 |
|
240 TRAP( err, path.Set( RemoveSchemeFromUrlL( KEmptyPattern() ) ) ); |
|
241 if( !err ) |
|
242 { |
|
243 pathCopy = HBufC::NewLC( path.Length() ); |
|
244 pathCopy->Des().Copy( path ); |
|
245 TPtr ptr = pathCopy->Des(); |
|
246 ConvertUrlToPathL( ptr ); |
|
247 aDocHandler = ETrue; |
|
248 return pathCopy; |
|
249 } |
|
250 |
|
251 TRAP( err, path.Set( RemoveSchemeFromUrlL( KFilePattern() ) ) ); |
|
252 if( !err ) |
|
253 { |
|
254 // Does our storage file exist? |
|
255 pathCopy = HBufC::NewLC( path.Length() ); |
|
256 pathCopy->Des().Copy( path ); |
|
257 TPtr ptr = pathCopy->Des(); |
|
258 ConvertUrlToPathL( ptr ); |
|
259 RFs fs; |
|
260 User::LeaveIfError( fs.Connect() ); |
|
261 TEntry storageFile; |
|
262 TInt err = fs.Entry( ptr, storageFile ); |
|
263 fs.Close(); |
|
264 if ( err ) |
|
265 { |
|
266 // It does not exist. |
|
267 ConvertPathToUrlL( ptr ); |
|
268 aDocHandler = EFalse; |
|
269 return pathCopy; |
|
270 } |
|
271 else |
|
272 { |
|
273 aDocHandler = ETrue; |
|
274 return pathCopy; |
|
275 } |
|
276 } |
|
277 |
|
278 User::Leave( err ); |
|
279 return pathCopy; |
|
280 } |