ginebra2/emulator/main.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 9 b39122337a00
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 *
     5 * under the terms of "Eclipse Public License v1.0"
     5 * This program is free software: you can redistribute it and/or modify
     6 * which accompanies this distribution, and is available
     6 * it under the terms of the GNU Lesser General Public License as published by
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * the Free Software Foundation, version 2.1 of the License.
     8 *
     8 *
     9 * Initial Contributors:
     9 * This program is distributed in the hope that it will be useful,
    10 * Nokia Corporation - initial contribution.
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 *
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12 * Contributors:
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #include <QtGui>
    22 #include <QtGui>
    20 #include <QWebView>
    23 #include <QWebView>
    21 #include <QWebPage>
    24 #include <QWebPage>
    22 #include <QWebFrame>
    25 #include <QWebFrame>
    29 #endif
    32 #endif
    30 
    33 
    31 #include <QNetworkProxyFactory>
    34 #include <QNetworkProxyFactory>
    32 #include "browser.h"
    35 #include "browser.h"
    33 
    36 
       
    37 #include "bedrockprovisioning.h"
       
    38 
    34 #include <QDebug>
    39 #include <QDebug>
    35 
    40 
    36 //#define HARDWARE_DEBUG_TRACE
    41 //#define HARDWARE_DEBUG_TRACE
    37 
    42 
    38 #ifdef ENABLE_PERF_TRACE  
    43 #ifdef ENABLE_PERF_TRACE
    39     #include "wrtperftracer.h"
    44 #include "wrtperftracer.h"
    40     // Global reference to WrtPerfTracer
       
    41     WrtPerfTracer* g_wrtPerfTracing;
       
    42 #endif
    45 #endif
    43 
    46 
    44 #ifdef HARDWARE_DEBUG_TRACE
    47 #ifdef HARDWARE_DEBUG_TRACE
    45 
    48 
    46 static const QString DebugLogPath("C:/Data/debug.txt");
    49 static const QString DebugLogPath("C:/Data/debug.txt");
    52 }
    55 }
    53 
    56 
    54 static void debugOutput(QtMsgType type, const char *msg)
    57 static void debugOutput(QtMsgType type, const char *msg)
    55 {
    58 {
    56     QFile file(DebugLogPath);
    59     QFile file(DebugLogPath);
    57     
    60 
    58     if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
    61     if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
    59         return;
    62         return;
    60     
    63 
    61     QTextStream out(&file);
    64     QTextStream out(&file);
    62     out << "\nDebug: " << msg;
    65     out << "\nDebug: " << msg;
    63     
    66 
    64     file.flush();
    67     file.flush();
    65     file.close();
    68     file.close();
    66 }
    69 }
    67 #endif
    70 #endif
    68 
    71 
   107 };
   110 };
   108 
   111 
   109 static BrowserProxyFactory proxies;
   112 static BrowserProxyFactory proxies;
   110 #endif //NO_NETWORK_ACCESS_MANAGER
   113 #endif //NO_NETWORK_ACCESS_MANAGER
   111 
   114 
   112 #ifdef ENABLE_PERF_TRACE
   115 #ifdef ORBIT_UI
   113     WrtPerfTracer* perfTracer = 0;
   116 #include <hbapplication.h>
   114 #endif
   117 #endif // ORBIT_UI
       
   118 
       
   119 #ifdef OPENURL
       
   120 #include "BrowserMainS60.h"
       
   121 
       
   122 static CApaApplication *AppFactoryL()
       
   123 {
       
   124     return(&CBrowserMainAppSingleton::Instance());
       
   125 }
       
   126 #endif // OPENURL
       
   127 
       
   128 
       
   129 static void configureHtml5OfflineStorage()
       
   130 {
       
   131     BEDROCK_PROVISIONING::BedrockProvisioning * provisioning =
       
   132         BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning();
       
   133 
       
   134     QWebSettings * globalSettings = QWebSettings::globalSettings();
       
   135 
       
   136     // Enable all kinds of persistent storage, then fine-tune using
       
   137     // bedrock provisioning attributes.
       
   138 
       
   139     QWebSettings::enablePersistentStorage();
       
   140 
       
   141     // Local and database storage (using the global javascript localStorage
       
   142     // and openDatabase items) is shared across pages and browser invocations,
       
   143     // but it tied to the domain of the page in which the javascript code is
       
   144     // running.  This allows webpages hosted at, say, cnn.com to store data
       
   145     // using the same keys as webpages hosted at bbc.co.uk without conflict.
       
   146     //
       
   147     // Note that local and database storage is persisted in directories
       
   148     // beneath the application's private directory, so it is not shared
       
   149     // with other browsers.
       
   150 
       
   151     bool localStorageEnabled =
       
   152         provisioning->valueAsInt("Html5LocalStorage") != 0;
       
   153 
       
   154     bool databaseStorageEnabled =
       
   155         provisioning->valueAsInt("Html5DatabaseStorage") != 0;
       
   156 
       
   157     globalSettings->setAttribute(
       
   158                 QWebSettings::LocalStorageEnabled,
       
   159                 localStorageEnabled);
       
   160 
       
   161     globalSettings->setAttribute(
       
   162                 QWebSettings::OfflineStorageDatabaseEnabled,
       
   163                 databaseStorageEnabled);
       
   164 
       
   165     // There is no separate QWebSettings method to configure
       
   166     // the default quota for local storage databases.
       
   167     // It appears that both local storage and database storage
       
   168     // use the same default quota.
       
   169 
       
   170     if (localStorageEnabled || databaseStorageEnabled) {
       
   171         globalSettings->setOfflineStorageDefaultQuota(
       
   172                 provisioning->valueAsInt64("Html5DatabaseStorageMaxSize"));
       
   173     }
       
   174 
       
   175     // The application cache allows websites to specify a manifest file in
       
   176     // the outermost <html> element.  The manifest file defines which files
       
   177     // may be stored at the client and used when the network is inaccessible.
       
   178     //
       
   179     // Webkit stores the application cache in a single SQLite database
       
   180     // named ApplicationCache.db.  By default this database is located
       
   181     // in the application's private directory, so it is not shared with
       
   182     // other browsers.
       
   183 
       
   184     bool applicationCacheEnabled =
       
   185         provisioning->valueAsInt("Html5ApplicationCache") != 0;
       
   186 
       
   187     globalSettings->setAttribute(
       
   188                 QWebSettings::OfflineWebApplicationCacheEnabled,
       
   189                 applicationCacheEnabled);
       
   190 
       
   191     if (applicationCacheEnabled) {
       
   192         globalSettings->setOfflineWebApplicationCacheQuota(
       
   193                 provisioning->valueAsInt64("Html5ApplicationCacheMaxSize"));
       
   194     }
       
   195 }
       
   196 
   115 
   197 
   116 int main(int argc, char * argv[])
   198 int main(int argc, char * argv[])
   117 {
   199 {
   118 #ifdef NO_NETWORK_ACCESS_MANAGER	
   200 #ifdef NO_NETWORK_ACCESS_MANAGER
   119     QNetworkProxyFactory::setApplicationProxyFactory(&proxies);
   201     QNetworkProxyFactory::setApplicationProxyFactory(&proxies);
   120 #endif //NO_NETWORK_ACCESS_MANAGER    
   202 #endif //NO_NETWORK_ACCESS_MANAGER
   121     int res=0;
   203     int res=0;
   122 
   204 
   123 #ifdef HARDWARE_DEBUG_TRACE
   205 #ifdef HARDWARE_DEBUG_TRACE
   124     initDebugOutput();    
   206     initDebugOutput();
   125     qInstallMsgHandler(debugOutput);
   207     qInstallMsgHandler(debugOutput);
   126 #endif
   208 #endif
   127 
   209 
       
   210 //    qDebug() << "main - before app, argc=" << argc;
       
   211 //    for (int i = 0; i < argc; ++i)
       
   212 //        {
       
   213 //        qDebug() << "main - argv[" << i << "] = " << argv[i];
       
   214 //        }
       
   215 
       
   216 /* openurl should only work in Orbit UI application. */
       
   217 #ifdef ORBIT_UI
       
   218 #ifdef OPENURL
       
   219 #ifdef NO_QSTM_GESTURE
       
   220     HbApplication app(AppFactoryL, argc, argv);
       
   221 #else
       
   222     BrowserApp app(AppFactoryL, argc, argv);
       
   223 #endif
       
   224 #else /* !OPENURL */
       
   225 #ifdef NO_QSTM_GESTURE
       
   226   HbApplication app(argc, argv);
       
   227 #else // ORBIT_UI
       
   228   BrowserApp app(argc, argv);
       
   229 #endif
       
   230 #endif /* OPENURL */
       
   231 #else
   128 #ifdef NO_QSTM_GESTURE
   232 #ifdef NO_QSTM_GESTURE
   129   QApplication app(argc, argv);
   233   QApplication app(argc, argv);
   130 #else
   234 #else
   131   BrowserApp app(argc, argv);
   235   BrowserApp app(argc, argv);
   132 #endif
   236 #endif
   133 
   237 #endif // ORBIT_UI
       
   238 
       
   239 //  qDebug() << "main - after app";
   134 #ifdef Q_OS_SYMBIAN
   240 #ifdef Q_OS_SYMBIAN
   135   //Object cache settings. NB: these need to be tuned per device
   241     //Object cache settings. NB: these need to be tuned per device
   136   QWebSettings::globalSettings()->setObjectCacheCapacities(128*1024, 1024*1024, 1024*1024);
   242     QWebSettings::globalSettings()->setObjectCacheCapacities(128*1024, 1024*1024, 1024*1024);
   137 #endif
   243 #endif
       
   244 
       
   245     if (BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DnsPrefetchEnabled").toBool())
       
   246 	{
       
   247 	// Specifies whether QtWebkit will try to pre-fetch DNS entries to speed up browsing.
       
   248 	// Without this technique, the DNS lookup is performed only when you click on the link, 
       
   249 	// adding a wait of 250ms (on average) before the page even starts to show up.
       
   250 	// This only works as a global attribute.
       
   251 	   QWebSettings::globalSettings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
       
   252 	}
       
   253 
       
   254     configureHtml5OfflineStorage();
   138 
   255 
   139     QString lang = QLocale::system().name();
   256     QString lang = QLocale::system().name();
   140 
   257 
   141     //install the common translator from platform
   258     //install the common translator from platform
   142     QTranslator common;
   259     QTranslator common;
   143     common.load(":/resource/qt/translations/common_" + lang);
   260     common.load(":/resource/qt/translations/common_" + lang);
   144     QApplication::installTranslator(&common);
   261     QApplication::installTranslator(&common);
   145 
   262 
   146     
   263 
   147     //install the translator from Browser
   264     //install the translator from Browser
   148     QTranslator translator;
   265     QTranslator translator;
   149     QString transFilePath = ":/translations";
   266     QString transFilePath = ":/translations";
   150     //Todo: when platform delivers .ts file
   267     //Todo: when platform delivers .ts file
   151     //QString transFilePath = "Z:/resource/qt/translations/";
   268     //QString transFilePath = "Z:/resource/qt/translations/";
   152     QString transFile = QLatin1String("browserLoc_") +  lang;
   269     QString transFile = QLatin1String("browserLoc_") +  lang;
   153     translator.load(transFile, transFilePath);
   270     translator.load(transFile, transFilePath);
   154     QApplication::installTranslator(&translator);
   271     QApplication::installTranslator(&translator);
       
   272 
       
   273 // To make the native urlsearch bar selection visible, the following lines have to be removed
       
   274 // The keypad navigation still works for ginebra2 even without enabling keypad navigation
       
   275 /*
   155 #ifdef Q_OS_SYMBIAN
   276 #ifdef Q_OS_SYMBIAN
   156     QApplication::setKeypadNavigationEnabled(true);
   277     QApplication::setKeypadNavigationEnabled(true);
   157 #endif
   278 #endif
       
   279 */
       
   280 #ifdef OPENURL
       
   281     // Handle QDesktopServices.openUrl (when browser wasn't already running)
       
   282     QString url = CBrowserMainAppSingleton::Instance().InitialUrl();
       
   283     GinebraBrowser * browser = new GinebraBrowser(0, &url); // Pass the initial url so it will be loaded as soon as the browser chrome finishes
       
   284     // Set things up to handle QDesktopServices.openUrl calls when browser is already running
       
   285     CBrowserMainAppSingleton::Instance().setUrlHandler(browser);
       
   286 #else
   158     GinebraBrowser * browser = new GinebraBrowser();
   287     GinebraBrowser * browser = new GinebraBrowser();
       
   288 #endif
       
   289 
   159 
   290 
   160 #ifdef ENABLE_PERF_TRACE
   291 #ifdef ENABLE_PERF_TRACE
   161     g_wrtPerfTracing = new WrtPerfTracer(0);
   292 #if defined(NO_NETWORK_ACCESS_MANAGER)
       
   293     PERF_TRACE_OUT() << "NO_NETWORK_ACCESS_MANAGER\n";
       
   294 #endif
       
   295 #if defined(NO_RESIZE_ON_LOAD)
       
   296     PERF_TRACE_OUT() << "NO_RESIZE_ON_LOAD\n";
       
   297 #endif
       
   298 #if defined(NO_QSTM_GESTURE)
       
   299     PERF_TRACE_OUT() << "NO_QSTM_GESTURE\n";
       
   300 #endif
       
   301 #if defined(__gva_no_chrome__)
       
   302     PERF_TRACE_OUT() << "__gva_no_chrome__\n";
       
   303 #endif
       
   304 #if defined(SET_DEFAULT_IAP)
       
   305     PERF_TRACE_OUT() << "SET_DEFAULT_IAP\n";
       
   306 #endif
       
   307 #if defined(NO_HISTORY)
       
   308     PERF_TRACE_OUT() << "NO_HISTORY\n";
       
   309 #endif
       
   310 
   162 #endif //ENABLE_PERF_TRACE
   311 #endif //ENABLE_PERF_TRACE
   163     
   312 
   164     browser->show();
   313     browser->show();
   165     res = app.exec();
   314     res = app.exec();
   166     delete browser;
   315     delete browser;
   167     
   316 
   168 #ifdef ENABLE_PERF_TRACE    
   317 #ifdef ENABLE_PERF_TRACE
   169        // delete g_wrtPerfTracing instance
   318       WrtPerfTracer::tracer()->close();
   170        if (g_wrtPerfTracing) {
       
   171            g_wrtPerfTracing->close();
       
   172            delete g_wrtPerfTracing;
       
   173        }   
       
   174 #endif //ENABLE_PERF_TRACE
   319 #endif //ENABLE_PERF_TRACE
   175        
   320 
   176     return res;
   321     return res;
   177 }
   322 }