contentstorage/cahandler/url/src/caurlhandler.cpp
author hgs
Fri, 30 Apr 2010 15:22:08 +0300
changeset 93 82b66994846c
parent 88 7f0462e8c3da
child 83 156f692b1687
permissions -rw-r--r--
201017
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description:  ?Description
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <w32std.h>
hgs
parents:
diff changeset
    19
#include <apgtask.h>
hgs
parents:
diff changeset
    20
#include <apgcli.h>
hgs
parents:
diff changeset
    21
#include <AknTaskList.h>
hgs
parents:
diff changeset
    22
hgs
parents:
diff changeset
    23
#include "caurlhandler.h"
hgs
parents:
diff changeset
    24
#include "cadef.h"
hgs
parents:
diff changeset
    25
#include "cainnerentry.h"
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
// ================= MEMBER FUNCTIONS =======================
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    30
// CCaUrlHandler::~CCaUrlHandler
hgs
parents:
diff changeset
    31
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    32
//
hgs
parents:
diff changeset
    33
CCaUrlHandler::~CCaUrlHandler()
hgs
parents:
diff changeset
    34
    {
hgs
parents:
diff changeset
    35
    }
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    38
// CCaUrlHandler::NewL
hgs
parents:
diff changeset
    39
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    40
//
hgs
parents:
diff changeset
    41
CCaUrlHandler* CCaUrlHandler::NewL()
hgs
parents:
diff changeset
    42
    {
hgs
parents:
diff changeset
    43
    CCaUrlHandler* handler = new ( ELeave ) CCaUrlHandler();
hgs
parents:
diff changeset
    44
    CleanupStack::PushL( handler );
hgs
parents:
diff changeset
    45
    handler->ConstructL();
hgs
parents:
diff changeset
    46
    CleanupStack::Pop( handler );
hgs
parents:
diff changeset
    47
    return handler;
hgs
parents:
diff changeset
    48
    }
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    51
// CCaUrlHandler::CCaUrlHandler
hgs
parents:
diff changeset
    52
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    53
//
hgs
parents:
diff changeset
    54
CCaUrlHandler::CCaUrlHandler()
hgs
parents:
diff changeset
    55
    {
hgs
parents:
diff changeset
    56
    }
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    59
// CCaUrlHandler::ConstructL
hgs
parents:
diff changeset
    60
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    61
//
hgs
parents:
diff changeset
    62
void CCaUrlHandler::ConstructL()
hgs
parents:
diff changeset
    63
    {
hgs
parents:
diff changeset
    64
    }
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    67
// CCaUrlHandler::HandleCommandL
hgs
parents:
diff changeset
    68
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
//
hgs
parents:
diff changeset
    70
void CCaUrlHandler::HandleCommandL( CCaInnerEntry& aEntry,
hgs
parents:
diff changeset
    71
        const TDesC8& aCommand )
hgs
parents:
diff changeset
    72
    {
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
    if( !aCommand.Compare( KCaCmdOpen() ) )
hgs
parents:
diff changeset
    75
        {
hgs
parents:
diff changeset
    76
        const RCaEntryAttrArray& attributes = aEntry.GetAttributes();
hgs
parents:
diff changeset
    77
        TInt attributesArrayCount = attributes.Count();
hgs
parents:
diff changeset
    78
        for( int i = 0; i < attributesArrayCount; ++i )
hgs
parents:
diff changeset
    79
            {
hgs
parents:
diff changeset
    80
            const CCaEntryAttribute * const attribute = attributes[i];
hgs
parents:
diff changeset
    81
            if( attribute->Name().Compare( KCaAttrUrl ) == 0 )
hgs
parents:
diff changeset
    82
                {
hgs
parents:
diff changeset
    83
                LaunchUrlL( attribute->Value() );
hgs
parents:
diff changeset
    84
                break;
hgs
parents:
diff changeset
    85
                }
hgs
parents:
diff changeset
    86
            }
hgs
parents:
diff changeset
    87
        }
hgs
parents:
diff changeset
    88
    else
hgs
parents:
diff changeset
    89
        {
hgs
parents:
diff changeset
    90
        User::Leave( KErrNotSupported );
hgs
parents:
diff changeset
    91
        }
hgs
parents:
diff changeset
    92
    }
hgs
parents:
diff changeset
    93
hgs
parents:
diff changeset
    94
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    95
// CCaUrlHandler::LaunchUrlL
hgs
parents:
diff changeset
    96
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    97
//
hgs
parents:
diff changeset
    98
hgs
parents:
diff changeset
    99
void CCaUrlHandler::LaunchUrlL( const TDesC& aUrl )
hgs
parents:
diff changeset
   100
    {
hgs
parents:
diff changeset
   101
    // Launches browser stand-alone.
hgs
parents:
diff changeset
   102
    // Browser is launched with a parameter 4 ("4 http://...."), which 
hgs
parents:
diff changeset
   103
    // Start/Continue the browser specifying a URL. 
hgs
parents:
diff changeset
   104
    // Other available parameters are described in the Browser API Specification
hgs
parents:
diff changeset
   105
    // Document.
hgs
parents:
diff changeset
   106
    TInt length = aUrl.Length() + KBrowserPrefix.iTypeLength;
hgs
parents:
diff changeset
   107
hgs
parents:
diff changeset
   108
    RWsSession wsSession;
hgs
parents:
diff changeset
   109
    User::LeaveIfError( wsSession.Connect() );
hgs
parents:
diff changeset
   110
    CleanupClosePushL<RWsSession> ( wsSession );
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
    CAknTaskList* taskList = CAknTaskList::NewL( wsSession );
hgs
parents:
diff changeset
   113
    TApaTask task = taskList->FindRootApp( KUidBrowser );
hgs
parents:
diff changeset
   114
    delete taskList;
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
    if( task.Exists() )
hgs
parents:
diff changeset
   117
        {
hgs
parents:
diff changeset
   118
        HBufC8* param8 = HBufC8::NewLC( length );
hgs
parents:
diff changeset
   119
        TPtr8 ptr8 = param8->Des();
hgs
parents:
diff changeset
   120
        ptr8.Append( KBrowserPrefix );
hgs
parents:
diff changeset
   121
        ptr8.Append( aUrl );
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
        // Sends message to existing Browser task.
hgs
parents:
diff changeset
   124
        task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
hgs
parents:
diff changeset
   125
        CleanupStack::PopAndDestroy( param8 );
hgs
parents:
diff changeset
   126
        }
hgs
parents:
diff changeset
   127
    else
hgs
parents:
diff changeset
   128
        {
hgs
parents:
diff changeset
   129
        HBufC* buf = HBufC::NewLC( length );
hgs
parents:
diff changeset
   130
        TPtr ptr = buf->Des();
hgs
parents:
diff changeset
   131
        ptr.Append( KBrowserPrefix );
hgs
parents:
diff changeset
   132
        ptr.Append( aUrl );
hgs
parents:
diff changeset
   133
hgs
parents:
diff changeset
   134
        RApaLsSession appArcSession;
hgs
parents:
diff changeset
   135
        User::LeaveIfError( appArcSession.Connect() );
hgs
parents:
diff changeset
   136
        CleanupClosePushL<RApaLsSession> ( appArcSession );
hgs
parents:
diff changeset
   137
        TThreadId id;
hgs
parents:
diff changeset
   138
        appArcSession.StartDocument( *buf, KUidBrowser, id );
hgs
parents:
diff changeset
   139
        CleanupStack::PopAndDestroy( &appArcSession );
hgs
parents:
diff changeset
   140
        CleanupStack::PopAndDestroy( buf );
hgs
parents:
diff changeset
   141
        }
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
    CleanupStack::PopAndDestroy( &wsSession );
hgs
parents:
diff changeset
   144
    }