webengine/osswebengine/WebCore/platform/symbian/FileChooserSymbian.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "config.h"
       
    20 #include "Event.h"
       
    21 #include "FileChooser.h"
       
    22 #include "../bidi.h"
       
    23 #include "Document.h"
       
    24 #include "FontData.h"
       
    25 #include "Icon.h"
       
    26 #include "Frame.h"
       
    27 #include "LocalizedStrings.h"
       
    28 #include "RenderFileUploadControl.h"
       
    29 #include "WebCoreFrameBridge.h"
       
    30 #include <e32base.h>
       
    31 #include "WebFrame.h"
       
    32 #include "WebFrameView.h"
       
    33 #include "WebView.h"
       
    34 #include "Brctl.h"
       
    35 #include <BrCtlDialogsProvider.h>
       
    36 #include <CommonContentPolicy.h>
       
    37 #include <stringloader.h>
       
    38 #if defined(__BROWSER_SDK)
       
    39 #include <webkit_sdk.rsg>
       
    40 #else
       
    41 #include <Webkit.rsg>
       
    42 #endif
       
    43 
       
    44 
       
    45 class AsyncLaunch : public CAsyncOneShot
       
    46     {
       
    47     public:
       
    48         AsyncLaunch() : CAsyncOneShot(CActive::EPriorityHigh + 1) {}
       
    49 
       
    50         ~AsyncLaunch() {}
       
    51         void setFileChooser( WebCore::FileChooser* fileChooser, WebCore::Document* doc ) 
       
    52         {
       
    53             m_fileChooser = fileChooser;  
       
    54             m_document = doc;
       
    55         }
       
    56 
       
    57         void Cancel() { }
       
    58     private:
       
    59         void RunL()
       
    60         {
       
    61             TRAP_IGNORE(
       
    62             if( m_fileChooser ) {
       
    63                 // fixme s602
       
    64                 WebFrame* webFrame = kit(m_document->frame());
       
    65                 MBrCtlDialogsProvider* dialogs = webFrame->frameView()->topView()->brCtl()->brCtlDialogsProvider();
       
    66                 HBufC* buf = NULL;
       
    67                 
       
    68                 if( dialogs->DialogFileSelectLC( m_fileChooser->filename(), KNullDesC, buf) && m_fileChooser )
       
    69                     if( !isRestrictedFile( *buf ) )
       
    70                         m_fileChooser->chooseFile( *buf );
       
    71                     else {
       
    72                         TParsePtrC filenameParser( *buf );
       
    73                         HBufC* message = StringLoader::LoadLC(R_QTN_XHTML_QUERY_FILE_RESTRICTED, filenameParser.NameAndExt());
       
    74                         dialogs->DialogNoteL(*message);
       
    75                         CleanupStack::PopAndDestroy();  // message
       
    76                     }
       
    77                 CleanupStack::PopAndDestroy();  // buf
       
    78             });
       
    79             delete this;
       
    80         }
       
    81 
       
    82         bool isRestrictedFile(const TDesC& filename)
       
    83         {
       
    84             bool banned(ETrue);
       
    85             TRAP_IGNORE( 
       
    86             CCommonContentPolicy* contentPolicy = CCommonContentPolicy::NewLC();
       
    87             banned = contentPolicy->IsClosedFileL( filename );
       
    88             CleanupStack::PopAndDestroy(); //contentPolicy
       
    89             );
       
    90             return banned;
       
    91         }
       
    92 
       
    93         WebCore::FileChooser* m_fileChooser;
       
    94         WebCore::Document* m_document;
       
    95     };
       
    96 
       
    97 namespace WebCore {
       
    98 
       
    99 FileChooser::FileChooser(FileChooserClient* client, const String& initialFilename)
       
   100     : m_client(client)
       
   101     , m_filename(initialFilename)
       
   102     , m_icon(0)
       
   103     , m_controller( 0 )
       
   104 {
       
   105 }
       
   106 
       
   107 FileChooser::~FileChooser()
       
   108 {
       
   109     if (m_controller)
       
   110         m_controller->setFileChooser(0, 0);
       
   111 }
       
   112 
       
   113 void FileChooser::openFileChooser(Document* doc)
       
   114 {
       
   115     m_controller = new AsyncLaunch();
       
   116 
       
   117     if ( m_controller ) {
       
   118         m_controller->setFileChooser( this, doc );
       
   119         m_controller->Call();
       
   120     }
       
   121 }
       
   122 
       
   123 String FileChooser::basenameForWidth(const Font& font, int width) const
       
   124 {
       
   125     if (width <= 0)
       
   126         return String();
       
   127 
       
   128     TParsePtrC filenameParser( m_filename );
       
   129     return filenameParser.NameAndExt();
       
   130 
       
   131 // tot:fixme truncate needs work
       
   132 /*
       
   133     String strToTruncate;
       
   134     if (m_filename.isEmpty())
       
   135         strToTruncate = fileButtonNoFileSelectedLabel();
       
   136     else
       
   137         strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:m_filename];
       
   138 
       
   139     return [WebCoreStringTruncator centerTruncateString:strToTruncate
       
   140             toWidth:width withFont:m_uploadControl->style()->font().primaryFont()->getNSFont()];
       
   141 */
       
   142 }
       
   143 
       
   144 }