85
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <w32std.h>
|
|
19 |
#include <apgtask.h>
|
|
20 |
#include <apgcli.h>
|
|
21 |
#include <AknTaskList.h>
|
|
22 |
|
|
23 |
#include "caurlhandlerplugin.h"
|
|
24 |
#include "cadef.h"
|
|
25 |
#include "cainnerentry.h"
|
|
26 |
|
|
27 |
// ================= MEMBER FUNCTIONS =======================
|
|
28 |
|
|
29 |
// --------------------------------------------------------------------------
|
|
30 |
// CCaUrlHandlerPlugin::~CCaUrlHandlerPlugin
|
|
31 |
// --------------------------------------------------------------------------
|
|
32 |
//
|
|
33 |
CCaUrlHandlerPlugin::~CCaUrlHandlerPlugin()
|
|
34 |
{
|
|
35 |
}
|
|
36 |
|
|
37 |
// --------------------------------------------------------------------------
|
|
38 |
// CCaUrlHandlerPlugin::NewL
|
|
39 |
// --------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CCaUrlHandlerPlugin* CCaUrlHandlerPlugin::NewL()
|
|
42 |
{
|
|
43 |
CCaUrlHandlerPlugin* handler = new ( ELeave ) CCaUrlHandlerPlugin();
|
|
44 |
CleanupStack::PushL( handler );
|
|
45 |
handler->ConstructL();
|
|
46 |
CleanupStack::Pop( handler );
|
|
47 |
return handler;
|
|
48 |
}
|
|
49 |
|
|
50 |
// --------------------------------------------------------------------------
|
|
51 |
// CCaUrlHandlerPlugin::CCaUrlHandlerPlugin
|
|
52 |
// --------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
CCaUrlHandlerPlugin::CCaUrlHandlerPlugin()
|
|
55 |
{
|
|
56 |
}
|
|
57 |
|
|
58 |
// --------------------------------------------------------------------------
|
|
59 |
// CCaUrlHandlerPlugin::ConstructL
|
|
60 |
// --------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
void CCaUrlHandlerPlugin::ConstructL()
|
|
63 |
{
|
|
64 |
BaseConstructL();
|
|
65 |
}
|
|
66 |
|
|
67 |
// --------------------------------------------------------------------------
|
|
68 |
// CCaUrlHandlerPlugin::SupportsType
|
|
69 |
// --------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
TBool CCaUrlHandlerPlugin::SupportsType( const TDesC& aType )
|
|
72 |
{
|
|
73 |
if( !aType.Compare( KCaTypeUrl() ) )
|
|
74 |
{
|
|
75 |
return ETrue;
|
|
76 |
}
|
|
77 |
|
|
78 |
return EFalse;
|
|
79 |
}
|
|
80 |
|
|
81 |
// --------------------------------------------------------------------------
|
|
82 |
// CCaUrlHandlerPlugin::HandleCommandL
|
|
83 |
// --------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
void CCaUrlHandlerPlugin::HandleCommandL( CCaInnerEntry& aEntry,
|
|
86 |
const TDesC8& aCommand )
|
|
87 |
{
|
|
88 |
|
|
89 |
if( !aCommand.Compare( KCaCmdOpen() ) )
|
|
90 |
{
|
|
91 |
const RCaEntryAttrArray& attributes = aEntry.GetAttributes();
|
|
92 |
TInt attributesArrayCount = attributes.Count();
|
|
93 |
for( int i = 0; i < attributesArrayCount; ++i )
|
|
94 |
{
|
|
95 |
const CCaEntryAttribute * const attribute = attributes[i];
|
|
96 |
if( attribute->Name().Compare( KCaAttrUrl ) == 0 )
|
|
97 |
{
|
|
98 |
LaunchUrlL( attribute->Value() );
|
|
99 |
break;
|
|
100 |
}
|
|
101 |
}
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
User::Leave( KErrNotSupported );
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
// --------------------------------------------------------------------------
|
|
110 |
// CCaUrlHandlerPlugin::LaunchUrlL
|
|
111 |
// --------------------------------------------------------------------------
|
|
112 |
//
|
|
113 |
|
|
114 |
void CCaUrlHandlerPlugin::LaunchUrlL( const TDesC& aUrl )
|
|
115 |
{
|
|
116 |
// Launches browser stand-alone.
|
|
117 |
// Browser is launched with a parameter 4 ("4 http://...."), which
|
|
118 |
// Start/Continue the browser specifying a URL.
|
|
119 |
// Other available parameters are described in the Browser API Specification
|
|
120 |
// Document.
|
|
121 |
TInt length = aUrl.Length() + KBrowserPrefix.iTypeLength;
|
|
122 |
|
|
123 |
RWsSession wsSession;
|
|
124 |
User::LeaveIfError( wsSession.Connect() );
|
|
125 |
CleanupClosePushL<RWsSession> ( wsSession );
|
|
126 |
|
|
127 |
CAknTaskList* taskList = CAknTaskList::NewL( wsSession );
|
|
128 |
TApaTask task = taskList->FindRootApp( KUidBrowser );
|
|
129 |
delete taskList;
|
|
130 |
|
|
131 |
if( task.Exists() )
|
|
132 |
{
|
|
133 |
HBufC8* param8 = HBufC8::NewLC( length );
|
|
134 |
TPtr8 ptr8 = param8->Des();
|
|
135 |
ptr8.Append( KBrowserPrefix );
|
|
136 |
ptr8.Append( aUrl );
|
|
137 |
|
|
138 |
// Sends message to existing Browser task.
|
|
139 |
task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
|
|
140 |
CleanupStack::PopAndDestroy( param8 );
|
|
141 |
}
|
|
142 |
else
|
|
143 |
{
|
|
144 |
HBufC* buf = HBufC::NewLC( length );
|
|
145 |
TPtr ptr = buf->Des();
|
|
146 |
ptr.Append( KBrowserPrefix );
|
|
147 |
ptr.Append( aUrl );
|
|
148 |
|
|
149 |
RApaLsSession appArcSession;
|
|
150 |
User::LeaveIfError( appArcSession.Connect() );
|
|
151 |
CleanupClosePushL<RApaLsSession> ( appArcSession );
|
|
152 |
TThreadId id;
|
|
153 |
appArcSession.StartDocument( *buf, KUidBrowser, id );
|
|
154 |
CleanupStack::PopAndDestroy( &appArcSession );
|
|
155 |
CleanupStack::PopAndDestroy( buf );
|
|
156 |
}
|
|
157 |
|
|
158 |
CleanupStack::PopAndDestroy( &wsSession );
|
|
159 |
}
|