browsercore/appfw/Api/Managers/webpagecontroller.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 9 b39122337a00
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009 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
       
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    11 *
    13 *
    12 * Contributors:
    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/".
    13 *
    17 *
    14 * Description: 
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
    21 
    18 
       
    19 #include <assert.h>
    22 #include <assert.h>
    20 
    23 
       
    24 #include "BookmarksManager.h"
    21 #include "actionjsobject.h"
    25 #include "actionjsobject.h"
    22 #include "qwebframe.h"
       
    23 #include "qwebhistory.h"
       
    24 #include "qgraphicswebview.h"
       
    25 #include "webpagedata.h"
    26 #include "webpagedata.h"
    26 #include "wrtbrowsercontainer.h"
    27 #include "wrtbrowsercontainer.h"
    27 #include "wrtbrowsercontainer_p.h"
    28 #include "wrtbrowsercontainer_p.h"
    28 #include "webpagecontroller_p.h"
    29 #include "webpagecontroller_p.h"
    29 #include "webpagecontroller.h"
    30 #include "webpagecontroller.h"
    30 #include "webcontentview.h"
       
    31 #include "UiUtil.h"
    31 #include "UiUtil.h"
    32 //#include "wrtsettings.h"
       
    33 #include "bedrockprovisioning.h"
    32 #include "bedrockprovisioning.h"
    34 #include "secureuicontroller.h"
    33 #include "secureuicontroller.h"
    35 #include "LoadController.h"
    34 #include "LoadController.h"
       
    35 #include "ContentAgent.h"
       
    36 #include "lowmemoryhandler.h"
       
    37 #include <QWebFrame>
       
    38 #include <QWebHistory>
       
    39 #include <QGraphicsWebView>
    36 #include <QFile>
    40 #include <QFile>
    37 #include <QDir>
    41 #include <QDir>
    38 #include <QtGui>
    42 #include <QtGui>
    39 #include <qdesktopservices.h>
       
    40 #include <QCoreApplication>
    43 #include <QCoreApplication>
    41 
    44 #include <QWebSecurityOrigin>
    42 #define BEDROCK_APPLICATION_NAME "Bedrock"
    45 #include <QWebDatabase>
    43 #define BEDROCK_VERSION_DEFAULT "BetaRelease"
    46 #include <QWebSettings>
       
    47 #include <QtCore/QSettings>
       
    48 using namespace WRT;
       
    49 
       
    50 #if defined(Q_OS_SYMBIAN) // for shareToMail
       
    51 #include <miutset.h>                
       
    52 #include <sendui.h>      
       
    53 #include <cmessagedata.h> 
       
    54 #include <txtrich.h>   
       
    55 #include <SendUiConsts.h>
       
    56 const TUid KShareOnline = { 0x200009D5 }; 
       
    57 const TUid KShareOnOvi = { 0x2001AA43 }; 
       
    58 #endif 
       
    59 
    44 #define MAX_NUM_WINDOWS_TO_RESTORE 5
    60 #define MAX_NUM_WINDOWS_TO_RESTORE 5
    45 #define MAX_NUM_WINDOWS 5
    61 #define MAX_NUM_WINDOWS 5
    46 
    62 
    47 static const char KHISTORYEXTENSION[]       = ".history";
    63 static const char KHISTORYEXTENSION[]       = ".history";
    48 
       
    49 void BWF_EXPORT qt_websettings_setLocalStorageDatabasePath(QWebSettings* settings, const QString& path);
       
    50 
       
    51 // --------------------------------------------
       
    52 
       
    53 //QEvent::Type WebPageControllerUpdateViewPortEvent::staticType() {
       
    54 //    static int s_type = QEvent::registerEventType();
       
    55 //    return (QEvent::Type)s_type;
       
    56 //}
       
    57 
       
    58 // --------------------------------------------
       
    59 
    64 
    60 WebPageControllerPrivate::WebPageControllerPrivate(WebPageController* qq) :
    65 WebPageControllerPrivate::WebPageControllerPrivate(WebPageController* qq) :
    61     q(qq),
    66     q(qq),
    62     m_widgetParent(0),
    67     m_widgetParent(0),
    63     m_currentPage(-1),
    68     m_currentPage(-1),
    74     m_actionStop->setObjectName("stop");
    79     m_actionStop->setObjectName("stop");
    75     m_actionBack = new QAction("Back",m_widgetParent);
    80     m_actionBack = new QAction("Back",m_widgetParent);
    76     m_actionBack->setObjectName("back");
    81     m_actionBack->setObjectName("back");
    77     m_actionForward = new QAction("Forward",m_widgetParent);
    82     m_actionForward = new QAction("Forward",m_widgetParent);
    78     m_actionForward->setObjectName("forward");
    83     m_actionForward->setObjectName("forward");
    79     m_actionWebInspector = new QAction("Web Inspector",m_widgetParent);
       
    80     m_actionWebInspector->setObjectName("webInspector");
       
    81 
    84 
    82     m_actionReload->setEnabled(false);
    85     m_actionReload->setEnabled(false);
    83     m_actionStop->setEnabled(false);
    86     m_actionStop->setEnabled(false);
    84     m_actionBack->setEnabled(false);
    87     m_actionBack->setEnabled(false);
    85     m_actionForward->setEnabled(false);
    88     m_actionForward->setEnabled(false);
    86     m_actionWebInspector->setVisible(false);
       
    87     
    89     
    88 }
    90 }
    89 
    91 
    90 WebPageControllerPrivate::~WebPageControllerPrivate()
    92 WebPageControllerPrivate::~WebPageControllerPrivate()
    91 {
    93 {
    92     // save history in the persistent storage, delete history files first
    94     // save history in the persistent storage, delete history files first
       
    95    
    93     bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession");
    96     bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession");
    94     if (enabled)
    97     if (enabled)
    95     {
    98     {
    96       q->deleteHistory();
    99       q->deleteHistory();
    97       if(donotsaveFlag == false)
   100       if(donotsaveFlag == false)
    98       {	
   101       {	
    99     	  q->saveNumberOfWindows();    
   102         int windowsSaved = 0;
   100     	  q->saveHistory();
   103         int activeWindowId = 0;
       
   104     	  q->saveHistory(&windowsSaved, &activeWindowId);
       
   105     	  q->saveNumberOfWindows(windowsSaved);    
       
   106         q->saveActiveWindowId(activeWindowId);
   101   	  }
   107   	  }
   102   	  donotsaveFlag = true;
   108   	  donotsaveFlag = true;
       
   109     }
       
   110     else
       
   111     {
       
   112     	q->deleteDataFiles();
   103     }
   113     }
   104 /*    #if defined(Q_OS_SYMBIAN)
   114 /*    #if defined(Q_OS_SYMBIAN)
   105     // clean up all pages
   115     // clean up all pages
   106     while ( !m_allPages.isEmpty() )
   116     while ( !m_allPages.isEmpty() )
   107         q->closePage(m_allPages.at(0));
   117         q->closePage(m_allPages.at(0));
   132  * so that higher-level functions need not know or care about what the active page is, etc.
   142  * so that higher-level functions need not know or care about what the active page is, etc.
   133  */
   143  */
   134 
   144 
   135 WebPageController::WebPageController ( QObject* parent ) :
   145 WebPageController::WebPageController ( QObject* parent ) :
   136     QObject ( parent ),
   146     QObject ( parent ),
   137     d(new WebPageControllerPrivate(this))
   147     m_networkError (false),
       
   148     m_networkErrorMsg("No network error"),           
       
   149     m_networkErrorUrl("No Url"),
       
   150     m_promptMsg("No message"),           
       
   151     m_promptReserved(""),
       
   152     m_memoryHandler(new LowMemoryHandler(this)),
       
   153     d(new WebPageControllerPrivate(this)),
       
   154     m_settingsLoaded(0),
       
   155     m_bErrorUrlMatches(false)
   138 {
   156 {
   139     // Register a new MetaType WebPageData. It is needed to serialize history (starage)
   157     // Register a new MetaType WebPageData. It is needed to serialize history (starage)
   140     qRegisterMetaTypeStreamOperators<WebPageData> ("WebPageData");
   158     qRegisterMetaTypeStreamOperators<WebPageData> ("WebPageData");
   141 
   159 
   142 #ifndef QT_NO_DESKTOPSERVICES
   160     d->m_historyDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseDirectory");
   143     d->m_historyDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
       
   144 #else
       
   145     d->m_historyDir = QDir::homePath();
       
   146 #endif
       
   147 #ifdef Q_OS_SYMBIAN
       
   148     if (d->m_historyDir.startsWith("Z"))
       
   149         d->m_historyDir.replace(0,1,"C");
       
   150 #endif
       
   151 
   161 
   152     // auto-connect actions
   162     // auto-connect actions
   153     connect( d->m_actionReload, SIGNAL( triggered() ), this, SLOT( currentReload() ) );
   163     connect( d->m_actionReload, SIGNAL( triggered() ), this, SLOT( currentReload() ) );
   154     connect( d->m_actionStop, SIGNAL( triggered() ), this, SLOT( currentStop() ) );
   164     connect( d->m_actionStop, SIGNAL( triggered() ), this, SLOT( currentStop() ) );
   155     connect( d->m_actionBack, SIGNAL( triggered() ), this, SLOT( currentBack() ) );
   165     connect( d->m_actionBack, SIGNAL( triggered() ), this, SLOT( currentBack() ) );
   156     connect( d->m_actionForward, SIGNAL( triggered() ), this, SLOT( currentForward() ) );
   166     connect( d->m_actionForward, SIGNAL( triggered() ), this, SLOT( currentForward() ) );
   157     connect( d->m_actionWebInspector, SIGNAL( triggered() ), this, SLOT( webInspector() ) );
   167 
   158 
   168     connect( m_memoryHandler, SIGNAL( lowMemory() ), this, SIGNAL( lowMemory() ) );
   159     // Catch changes to settings
   169     connect( m_memoryHandler, SIGNAL( lowMemory() ), this, SLOT( handleLowMemory() ) );
   160     connect(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning(), SIGNAL(settingChanged(const QString &)), this, SLOT(settingChanged(const QString &)));
   170     connect( m_memoryHandler, SIGNAL( outOfMemory() ), this, SIGNAL( outOfMemory() ) );
   161     
   171     connect( m_memoryHandler, SIGNAL( outOfMemory() ), this, SLOT( handleOutOfMemory() ) );
   162     // Initialize UA specific params.
   172     m_memoryHandler->start();
   163     initUASettingsAndData();
   173 
   164     // initialize from settings
       
   165     settingChanged("DeveloperExtras");
       
   166     updateJSActions();
   174     updateJSActions();
   167     
   175     
   168     m_bRestoreSession = false;
   176     m_bRestoreSession = false;
   169     bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession");
   177     bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession");
   170     if (enabled) m_bRestoreSession = true;
   178     if (enabled) m_bRestoreSession = true;
   171 
   179 
   172 }
   180 }
   173     
   181     
   174 WebPageController::~WebPageController()
   182 WebPageController::~WebPageController()
   175 {
   183 {
       
   184     m_memoryHandler->stop();
   176     delete d;
   185     delete d;
   177 }
   186 }
   178 
   187 
   179 
   188 
   180 
   189 
   195 
   204 
   196         // emit signal for creating network connection.
   205         // emit signal for creating network connection.
   197 
   206 
   198         Q_ASSERT( page );
   207         Q_ASSERT( page );
   199         page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("DeveloperExtras"));
   208         page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("DeveloperExtras"));
       
   209         connect( page, SIGNAL( loadFinished(bool) ), SLOT( onLoadFinishedForBackgroundWindow(bool) ) );
       
   210 
       
   211         // emit signal indicating that new page is being created
       
   212         emit creatingPage( page );
   200 
   213 
   201         /* Add the new page after the current page */
   214         /* Add the new page after the current page */
   202         WRT::WrtBrowserContainer * theCurrentPage = currentPage();
   215         WRT::WrtBrowserContainer * theCurrentPage = currentPage();
   203         int index = d->m_allPages.indexOf(theCurrentPage);
   216         int index = d->m_allPages.indexOf(theCurrentPage);
   204         d->m_allPages.insert (index+1, page );
   217         d->m_allPages.insert (index+1, page );
   205 
   218 
       
   219   // set the max number of pages to hold in the memory page cache to pages
       
   220   // The Page Cache allows for a nicer user experience when navigating forth or back to pages in 
       
   221   // the forward/back history, by pausing and resuming up to pages per page group
       
   222 
       
   223 		int maxPagesInCache = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("MaxPagesInCache");
       
   224         page->settings()->setMaximumPagesInCache(maxPagesInCache);
   206 
   225 
   207         // emit signal
   226         // emit signal
   208         emit pageCreated( page );
   227         emit pageCreated( page );
   209 
   228 
   210        
       
   211         // AUTO-activate this page ONLY if there are no other pages
   229         // AUTO-activate this page ONLY if there are no other pages
   212         if(d->m_allPages.size() == 1) {
   230         if(d->m_allPages.size() == 1) {
   213             setCurrentPage(page);
   231             setCurrentPage(page);
   214         }
   232         }
   215         int count = historyWindowCount();
   233         int count = historyWindowCount();
   216         if(index+1 < count)
   234         int activeWinId = activeWindowId();
       
   235 
       
   236         if (m_bRestoreSession)
   217         	startupRestoreHistory(NULL, index+1, page);
   237         	startupRestoreHistory(NULL, index+1, page);
   218     	  
   238     	  
   219     }
   239     }
   220     return page;
   240     return page;
   221 }
   241 }
   222 
   242 
   223 
   243 
   224 QWebPage* WebPageController::openPage()
   244 WRT::WrtBrowserContainer* WebPageController::openPage()
   225 {
   245 {
   226 	WRT::WrtBrowserContainer* page = NULL;
   246 	WRT::WrtBrowserContainer* page = NULL;
   227 	
   247 	
   228 	page = openPage(this, 0);
   248 	page = openPage(this, 0);
   229 	page->setPageFactory(this);
   249 	page->setPageFactory(this);
   230 	
   250 	
   231 	return page;
   251 	return page;
   232 }
   252 }
   233 
   253 
   234 QWebPage* WebPageController::openPageFromHistory(int index)
   254 WRT::WrtBrowserContainer* WebPageController::openPageFromHistory(int index)
   235 {
   255 {
   236     QDir dir(d->m_historyDir);
   256     QDir dir(d->m_historyDir);
   237     QFileInfoList fileList(dir.entryInfoList(QDir::Files));
   257     QFileInfoList fileList(dir.entryInfoList(QDir::Files));
   238     QString indexStr;
   258     QString indexStr;
   239     indexStr.setNum(index);
   259     indexStr.setNum(index);
   261  * @param page   WRT::WrtBrowserContainer instance to be closed 
   281  * @param page   WRT::WrtBrowserContainer instance to be closed 
   262  * @see  WRT::WrtBrowserContainer
   282  * @see  WRT::WrtBrowserContainer
   263  */
   283  */
   264 void WebPageController::closePage ( WRT::WrtBrowserContainer *page )
   284 void WebPageController::closePage ( WRT::WrtBrowserContainer *page )
   265 {
   285 {
   266     WRT::WrtBrowserContainer * theCurrentPage = currentPage();
   286     if(pageCount() > 1) {
   267     bool updateCurrentPageIndex = false;
   287         WRT::WrtBrowserContainer * theCurrentPage = currentPage();
   268 
   288         bool updateCurrentPageIndex = false;
   269     // get index of page we want to remove
   289 
   270     int closeIndex = d->m_allPages.indexOf(page);
   290         // get index of page we want to remove
   271     if(closeIndex < 0)
   291         int closeIndex = d->m_allPages.indexOf(page);
   272         return;
   292         if(closeIndex < 0)
   273     
   293             return;
   274     // was this page the "current page?"
   294     
   275     // if so, we need to select the page to become the new one
   295         // was this page the "current page?"
   276     // select the previous page unless at the beginning, then select next
   296         // if so, we need to select the page to become the new one
   277     if(page == theCurrentPage) {
   297         // select the previous page unless at the beginning, then select next
   278         int newCurrIndex = closeIndex - 1;
   298         if(page == theCurrentPage) {
   279         if(closeIndex == 0 ) {
   299             int newCurrIndex = closeIndex - 1;
   280             newCurrIndex = closeIndex + 1;
   300             if(closeIndex == 0 ) {
   281         }
   301                 newCurrIndex = closeIndex + 1;
       
   302             }
   282         
   303         
   283         // change the current page
   304             // change the current page
   284         if(newCurrIndex >= 0) {
   305             if(newCurrIndex >= 0) {
   285             theCurrentPage = d->m_allPages.at(newCurrIndex);
   306                 theCurrentPage = d->m_allPages.at(newCurrIndex);
   286             setCurrentPage(theCurrentPage);
   307                 setCurrentPage(theCurrentPage);
   287             updateCurrentPageIndex = true;
   308                 updateCurrentPageIndex = true;
       
   309             }
       
   310             else {
       
   311                 d->m_currentPage = -1;
       
   312                 emit pageChanged(page, NULL);
       
   313             }
   288         }
   314         }
   289         else {
   315         else {
   290             d->m_currentPage = -1;
   316              /* Adjust m_currentPage if the index of the page deleted is less than 
   291             emit pageChanged(page, NULL);
   317              * current page 
       
   318              */
       
   319            if (closeIndex < d->m_currentPage ) 
       
   320                updateCurrentPageIndex = true;
   292         }
   321         }
   293     }
   322 
   294     else {
   323         // actually delete the page from the list
   295         /* Adjust m_currentPage if the index of the page deleted is less than 
   324         d->m_allPages.removeAt(closeIndex);
   296          * current page 
   325 
   297          */
   326         // update the current page index if necessary
   298        if (closeIndex < d->m_currentPage ) 
   327         // (this will just update the index now that we've removed the page from the list)
   299            updateCurrentPageIndex = true;
   328         if(updateCurrentPageIndex) {
   300     }
   329             int index = d->m_allPages.indexOf(theCurrentPage);
   301 
   330             if(index >= 0)
   302     // actually delete the page from the list
   331                 d->m_currentPage = index;
   303     d->m_allPages.removeAt(closeIndex);
   332         }
   304 
   333 
   305     // update the current page index if necessary
   334         // and emit sig that it was done
   306     // (this will just update the index now that we've removed the page from the list)
   335         emit pageDeleted(page);
   307     if(updateCurrentPageIndex) {
   336 
   308         int index = d->m_allPages.indexOf(theCurrentPage);
   337         delete page;
   309         if(index >= 0)
   338     }
   310             d->m_currentPage = index;
       
   311     }
       
   312 
       
   313     // and emit sig that it was done
       
   314     emit pageDeleted(page);
       
   315 
       
   316     delete page;
       
   317 }
   339 }
   318 
   340 
   319 /*!
   341 /*!
   320  *  Activate the given page as the current page
   342  *  Activate the given page as the current page
   321  *  @param page   page handle for setting current page
   343  *  @param page   page handle for setting current page
   345         disconnect(oldPage, 0, this, 0);
   367         disconnect(oldPage, 0, this, 0);
   346         disconnect(oldPage->mainFrame(), 0, this, 0);
   368         disconnect(oldPage->mainFrame(), 0, this, 0);
   347         disconnect(oldPage->networkAccessManager(), 0, this, 0);
   369         disconnect(oldPage->networkAccessManager(), 0, this, 0);
   348         disconnect(oldPage->loadController(), 0, this, 0);
   370         disconnect(oldPage->loadController(), 0, this, 0);
   349         connect(oldPage, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*)));
   371         connect(oldPage, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*)));
   350     }
   372         connect(oldPage, SIGNAL(loadFinished(bool)), SLOT(onLoadFinishedForBackgroundWindow(bool)));
   351 
   373     }
   352     // aggregate "current page" signalling from this page to PageMgr clients
   374     // aggregate "current page" signalling from this page to PageMgr clients
   353     connect(page, SIGNAL(secureStateChange(int)), this, SLOT(secureStateChange(int)));
   375     connect(page, SIGNAL(secureStateChange(int)), this, SLOT(secureStateChange(int)));
   354     connect( page->mainFrame(), SIGNAL ( titleChanged ( const QString& ) ), SIGNAL ( titleChanged ( const QString& ) ) );
   376     connect( page->mainFrame(), SIGNAL ( titleChanged ( const QString& ) ), SIGNAL ( titleChanged ( const QString& ) ) );
   355     connect( page, SIGNAL( loadStarted() ), SIGNAL( loadStarted() ) );
   377     connect( page, SIGNAL( loadStarted() ), SIGNAL( loadStarted() ) );
       
   378     connect( page->mainFrame(), SIGNAL(initialLayoutCompleted() ), SIGNAL( initialLayoutCompleted() ) );
   356     connect( page, SIGNAL( loadProgress(int) ), SIGNAL( loadProgress(int) ) );
   379     connect( page, SIGNAL( loadProgress(int) ), SIGNAL( loadProgress(int) ) );
   357     connect( page, SIGNAL( loadFinished(bool) ), SIGNAL( loadFinished(bool) ) );
   380     connect( page, SIGNAL( loadFinished(bool) ), SLOT( onLoadFinished(bool) ) );
       
   381     
       
   382     connect( page, SIGNAL( databaseQuotaExceeded (QWebFrame *,QString) ), SLOT( onDatabaseQuotaExceeded (QWebFrame *,QString)) );  
       
   383     
   358     connect( page->mainFrame(), SIGNAL( iconChanged() ), SIGNAL( pageIconChanged() ) );
   384     connect( page->mainFrame(), SIGNAL( iconChanged() ), SIGNAL( pageIconChanged() ) );
   359     connect( page->loadController(), SIGNAL( pageLoadStarted() ), SIGNAL( pageLoadStarted() ) );
   385     connect( page->loadController(), SIGNAL( pageLoadStarted() ), SIGNAL( pageLoadStarted() ) );
       
   386     connect( page->loadController(), SIGNAL( pageLoadFailed() ), SIGNAL( pageLoadFailed() ) );
   360     connect( page->loadController(), SIGNAL( pageLoadProgress(int) ), SIGNAL( pageLoadProgress(int) ) );
   387     connect( page->loadController(), SIGNAL( pageLoadProgress(int) ), SIGNAL( pageLoadProgress(int) ) );
   361     connect( page->loadController(), SIGNAL( pageLoadFinished(bool) ), SIGNAL( pageLoadFinished(bool) ) );
   388     connect( page->loadController(), SIGNAL( pageLoadFinished(bool) ), SIGNAL( pageLoadFinished(bool) ) );
   362     connect( page->loadController(), SIGNAL( pageUrlChanged(QString) ), SIGNAL( pageUrlChanged(QString) ) );
   389     connect( page->loadController(), SIGNAL( pageUrlChanged(QString) ), SIGNAL( pageUrlChanged(QString) ) );
   363     connect( page, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*)));
   390     connect( page, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*)));
   364 
   391 
       
   392 
   365     // Connect the unsuportedContent signal to start a new download
   393     // Connect the unsuportedContent signal to start a new download
   366     connect( page, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(unsupportedContentArrived(QNetworkReply *)));
   394     connect( page, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(unsupportedContentArrived(QNetworkReply *)));
   367 
   395 
   368     connect( page, SIGNAL( loadStarted() ), SLOT( updateStatePageLoading() ) );
   396     connect( page, SIGNAL( loadStarted() ), SLOT( updateStatePageLoading() ) );
   369     connect( page, SIGNAL( loadFinished(bool) ), SLOT( updateStatePageLoadComplete(bool) ) );
   397     
   370 
   398 
   371     connect( page->mainFrame(), SIGNAL( iconChanged() ), this, SIGNAL( currentPageIconChanged() ) );
   399     connect( page->mainFrame(), SIGNAL( iconChanged() ), this, SIGNAL( currentPageIconChanged() ) );
   372     connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SIGNAL( currentPageUrlChanged( const QUrl &) ));
   400     connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SIGNAL( currentPageUrlChanged( const QUrl &) ));
   373     connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SLOT( urlChanged( const QUrl &) ));
   401     connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SLOT( urlChanged( const QUrl &) ));
   374 
   402 
   375     connect( page, SIGNAL( networkRequestStarted(QWebFrame*, QNetworkRequest*)), this, SIGNAL( networkRequestStarted(QWebFrame*, QNetworkRequest*)));
       
   376     connect( page->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)), this, SIGNAL( sslErrors(QNetworkReply *, const QList<QSslError> &)));
   403     connect( page->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)), this, SIGNAL( sslErrors(QNetworkReply *, const QList<QSslError> &)));
   377     connect( page->networkAccessManager(), SIGNAL(showMessageBox(WRT::MessageBoxProxy*)), this, SIGNAL(showMessageBox(WRT::MessageBoxProxy*)));
   404     connect( page->networkAccessManager(), SIGNAL(showMessageBox(WRT::MessageBoxProxy*)), this, SIGNAL(showMessageBox(WRT::MessageBoxProxy*)));
       
   405 	// Connect network reply errors 
       
   406     connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SIGNAL( networkErrorHappened(const QString &) ) );
       
   407     connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SLOT( processNetworkErrorHappened(const QString &) ) );
       
   408     connect( page->networkAccessManager(), SIGNAL( networkErrorUrl(const QUrl &) ), this, SLOT( processNetworkErrorUrl(const QUrl &) ) );
       
   409     
   378     connect(currentPage(), SIGNAL(pageScrollPositionZero()), this, SIGNAL(pageScrollPositionZero()) );
   410     connect(currentPage(), SIGNAL(pageScrollPositionZero()), this, SIGNAL(pageScrollPositionZero()) );
   379     connect(page, SIGNAL(scrollRequested(int, int, const QRect & )), this, SIGNAL(pageScrollRequested(int, int, const QRect & )) );
   411     connect(page, SIGNAL(scrollRequested(int, int, const QRect & )), this, SIGNAL(pageScrollRequested(int, int, const QRect & )) );
   380 
   412 
   381     Q_ASSERT ( d->m_currentPage >= 0 );
   413     Q_ASSERT ( d->m_currentPage >= 0 );
   382 
   414     
   383     updateActions(false);
   415     updateActions(false);
   384     
   416     
   385     emit pageChanged( oldPage, page );
   417     emit pageChanged( oldPage, page );
   386 }
   418 }
       
   419 
       
   420 
       
   421 
       
   422 void WebPageController::onLoadFinished(bool ok)
       
   423 {
       
   424     updateStatePageLoadComplete(ok);
       
   425     if (ok) {
       
   426         QTimer::singleShot(300, this, SLOT(updateHistory()));
       
   427     }
       
   428     else {
       
   429         emit(loadFinished(false));
       
   430     }
       
   431 }
       
   432 
       
   433 
       
   434 void WebPageController::onDatabaseQuotaExceeded (QWebFrame *frame, QString database)  
       
   435 {
       
   436 	QString  dbdir = QWebSettings::offlineStoragePath ();	
       
   437   QDir dir(dbdir);
       
   438   
       
   439   if(!dir.exists()||(dir.count() <= 1)) // empty DB
       
   440   	return;
       
   441 	
       
   442 		
       
   443 	if(frame)
       
   444 	{
       
   445 		QWebSecurityOrigin qwso = frame->securityOrigin();
       
   446 		qint64 quota = qwso.databaseQuota() ;
       
   447 		qint64 usage = qwso.databaseUsage() ;		
       
   448 	}
       
   449 	m_promptMsg = "Database Quota Error";
       
   450 	emit databaseQuotaExceeded (frame, database);
       
   451 	
       
   452 	return;
       
   453 }
       
   454 
       
   455 void WebPageController::onLoadFinishedForBackgroundWindow(bool ok)
       
   456 {
       
   457     if (!ok)
       
   458         return;
       
   459     WRT::WrtBrowserContainer* page = qobject_cast<WRT::WrtBrowserContainer*> (sender());
       
   460     if (page)
       
   461         page->setUpdateThumbnail(true);
       
   462 }
       
   463 
       
   464 void WebPageController::updateHistory()
       
   465 {
       
   466     BookmarksManager::getSingleton()->addHistory(currentDocUrl(), currentDocTitle());
       
   467     emit(loadFinished(true));
       
   468 }
       
   469 
       
   470 /*!
       
   471  * Handling of network error happens signal 
       
   472  * @return    Returns current page handle
       
   473  * @see WRT::WrtBrowserContainer
       
   474  */ 
       
   475 void WebPageController::processNetworkErrorHappened(const QString & msg )
       
   476     {
       
   477     m_networkError = true;
       
   478     m_networkErrorMsg = msg; 
       
   479     }
       
   480 
       
   481 /*!
       
   482  * Handling of network error associated url
       
   483  * @return    Returns current page handle
       
   484  * @see WRT::WrtBrowserContainer
       
   485  */
       
   486 void WebPageController::processNetworkErrorUrl(const QUrl & url )
       
   487     {
       
   488     QString errorUrl = url.toString();
       
   489     QString requestedUrl = currentRequestedUrl(); 
       
   490     m_networkErrorUrl = url.toString(); 
       
   491     
       
   492     // Check if requestedUrl matches the URL from the network error
       
   493     // This is to resolve the problems when error popups occur when they shouldn't
       
   494     // especially during download.
       
   495     int matches = m_networkErrorUrl.compare(requestedUrl);
       
   496     if (matches == 0) m_bErrorUrlMatches = true;
       
   497     }
       
   498 
       
   499 //void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();
       
   500 
       
   501 /*! 
       
   502  * Try to release as much memory as possible from caches and collectors
       
   503  */
       
   504 void WebPageController::releaseMemory()
       
   505     {
       
   506     // clears JavaScript Collector heap; private export in QWebFrame, so commented out for now
       
   507     // qt_drt_garbageCollector_collect(); 
       
   508     
       
   509     // webkit/webkit/qt/api
       
   510     QWebSettings::clearIconDatabase();    
       
   511     QWebSettings::clearMemoryCaches();
       
   512     
       
   513     QPixmapCache::clear();    
       
   514     }
       
   515 
       
   516 /*! 
       
   517  * Handle low memory signals from LowMemoryHandler
       
   518  * @see LowMemoryHandler
       
   519  */
       
   520 void WebPageController::handleLowMemory()
       
   521     {
       
   522     currentStop();
       
   523     releaseMemory();
       
   524     }
       
   525 
       
   526 /*! 
       
   527  * Handle out of memory signals from LowMemoryHandler
       
   528  * @see LowMemoryHandler
       
   529  */
       
   530 void WebPageController::handleOutOfMemory()
       
   531     {
       
   532     currentStop();
       
   533     releaseMemory();
       
   534     }
   387 
   535 
   388 /*!
   536 /*!
   389  * Retrieve a pointer to the current WRT::WrtBrowserContainer
   537  * Retrieve a pointer to the current WRT::WrtBrowserContainer
   390  * @return    Returns current page handle
   538  * @return    Returns current page handle
   391  * @see WRT::WrtBrowserContainer
   539  * @see WRT::WrtBrowserContainer
   397     else
   545     else
   398         return NULL;
   546         return NULL;
   399 }
   547 }
   400 
   548 
   401 /*!
   549 /*!
   402   Close the current page
       
   403 */
       
   404 void WebPageController::closeCurrentPage()
       
   405 {
       
   406     closePage(currentPage());
       
   407 }
       
   408 
       
   409 /*! 
       
   410  * Retrieve a list of all of the pages managed by WebPageController
   550  * Retrieve a list of all of the pages managed by WebPageController
   411  * @return   List of all the pages opened by WebPageController
   551  * @return   List of all the pages opened by WebPageController
   412  * @see WRT::WrtBrowserContainer
   552  * @see WRT::WrtBrowserContainer
   413  */
   553  */
   414 QList<WRT::WrtBrowserContainer*>* WebPageController::allPages()
   554 QList<WRT::WrtBrowserContainer*>* WebPageController::allPages()
   416     return &d->m_allPages;
   556     return &d->m_allPages;
   417 }
   557 }
   418 
   558 
   419 /*! 
   559 /*! 
   420  * Retrieve the number of pages managed by WebPageController
   560  * Retrieve the number of pages managed by WebPageController
   421  * @return  count of all the pages currently opend by WrtPagemanager
   561  * @return  count of all the pages currently opend by WebPageController
   422  */
   562  */
   423 int WebPageController::pageCount()
   563 int WebPageController::pageCount()
   424 {
   564 {
   425     return d->m_allPages.count();
   565     return d->m_allPages.count();
   426 }
       
   427 
       
   428 /*!
       
   429  * Find a given page by looking for its window name
       
   430  * @param  name : main frame name of the page to be searched
       
   431  * @return : Handle to WRT::WrtBrowserContainer with frame name 
       
   432  * @see refer WRT::WrtBrowserContainer
       
   433  */
       
   434 WRT::WrtBrowserContainer * WebPageController::findPageByMainFrameName(const QString & name)
       
   435 {
       
   436     foreach(WRT::WrtBrowserContainer* page, d->m_allPages) {
       
   437         if(name == page->mainFrame()->frameName())
       
   438             return page;
       
   439     }
       
   440     return NULL;
       
   441 }
       
   442 
       
   443 /*!
       
   444   Retrieve the title of the current page's main frame or
       
   445   an empty string if there is no current page
       
   446 */
       
   447 QString WebPageController::title()
       
   448 {
       
   449     WRT::WrtBrowserContainer* page = currentPage();
       
   450     if ( page )
       
   451         return page->pageTitle();
       
   452     else
       
   453         return QString();
       
   454 }
   566 }
   455 
   567 
   456 /*!
   568 /*!
   457   Retrieve the icon of the current page's main frame or
   569   Retrieve the icon of the current page's main frame or
   458   an NULL icon if there is no current page
   570   an NULL icon if there is no current page
   475 }*/
   587 }*/
   476 
   588 
   477 /*! 
   589 /*! 
   478   Return the list of public QActions most relevant to the managers's current context
   590   Return the list of public QActions most relevant to the managers's current context
   479   (most approptiate for contextual menus, etc.)
   591   (most approptiate for contextual menus, etc.)
   480  * @return : returns public actions list (Reload, Stop, Forward, Back, WebInspector)
   592  * @return : returns public actions list (Reload, Stop, Forward, Back)
   481  */
   593  */
   482 QList<QAction*> WebPageController::getContext()
   594 QList<QAction*> WebPageController::getContext()
   483 {
   595 {
   484     // return all actions for now
   596     // return all actions for now
   485     QList<QAction*> contextList;
   597     QList<QAction*> contextList;
   486     contextList << 
   598     contextList << 
   487         d->m_actionBack <<
   599         d->m_actionBack <<
   488         d->m_actionForward <<
   600         d->m_actionForward <<
   489         d->m_actionReload <<
   601         d->m_actionReload <<
   490         d->m_actionStop <<
   602         d->m_actionStop <<
   491         d->m_actionForward <<
   603         d->m_actionForward;
   492         d->m_actionWebInspector;
       
   493     return contextList;
   604     return contextList;
   494 }
   605 }
   495 
   606 
   496 /*!
   607 /*!
   497  * Action for reloading the current page
   608  * Action for reloading the current page
   525  * @return : Returns handle to Forward action(Ownership with WebPageController)
   636  * @return : Returns handle to Forward action(Ownership with WebPageController)
   526 */
   637 */
   527 QAction * WebPageController::getActionForward()
   638 QAction * WebPageController::getActionForward()
   528 {
   639 {
   529     return d->m_actionForward;
   640     return d->m_actionForward;
   530 }
       
   531 
       
   532 /*!
       
   533  * Action for invoking the WebInspector
       
   534  * @return : Returns handle to WebInspector public handle (Ownership with WebPageController)
       
   535 */
       
   536 QAction * WebPageController::getActionWebInspector()
       
   537 {
       
   538     return d->m_actionWebInspector;
       
   539 }
   641 }
   540 
   642 
   541 /*!
   643 /*!
   542 *  Reload for the current page
   644 *  Reload for the current page
   543 */
   645 */
   594 void WebPageController::currentLoad(const QString &url)
   696 void WebPageController::currentLoad(const QString &url)
   595 {
   697 {
   596     currentLoad(QUrl(url));
   698     currentLoad(QUrl(url));
   597 }
   699 }
   598 
   700 
       
   701 /*
       
   702 Share the url through mail client 
       
   703 */
       
   704 #if defined(Q_OS_SYMBIAN) 
       
   705 void WebPageController::share(const QString &url)
       
   706 {
       
   707     QString body = url;    
       
   708     CSendUi* sendUi = CSendUi::NewLC();
       
   709     CMessageData* messageData = CMessageData::NewLC();
       
   710 
       
   711     TSendingCapabilities sendingCapabilities;
       
   712     sendingCapabilities.iFlags = TSendingCapabilities::ESupportsAttachments;
       
   713         	
       
   714     // Not interested in these following services
       
   715 	CArrayFixFlat<TUid>* array = new (ELeave) CArrayFixFlat<TUid>(8); 
       
   716     CleanupStack::PushL(array);
       
   717    	array->AppendL(KSenduiTechnologyMmsUid);
       
   718     array->AppendL(KSenduiTechnologyIMUid);	    
       
   719     array->AppendL(KMmsDirectUpload);
       
   720     array->AppendL(KMmsIndirectUpload);
       
   721     array->AppendL(KMmsUploadService1Id);
       
   722     array->AppendL(KMmsUploadService2Id);
       
   723     array->AppendL(KMmsUploadService3Id);
       
   724     array->AppendL(KMmsUploadService4Id);
       
   725     array->AppendL(KShareOnline);
       
   726     array->AppendL(KShareOnOvi);
       
   727 				    
       
   728     // Body
       
   729     CParaFormatLayer* paraFormat = CParaFormatLayer::NewL();
       
   730     CleanupStack::PushL( paraFormat );
       
   731     CCharFormatLayer* charFormat = CCharFormatLayer::NewL();
       
   732     CleanupStack::PushL( charFormat );
       
   733     CRichText* bodyRichText = CRichText::NewL( paraFormat, charFormat );
       
   734     CleanupStack::PushL( bodyRichText );
       
   735 
       
   736     TPtrC bodyPtr(reinterpret_cast<const TUint16*>(body.utf16()));
       
   737 
       
   738     if( bodyPtr.Length() )
       
   739         bodyRichText->InsertL( 0, bodyPtr );
       
   740     else
       
   741         bodyRichText->InsertL( 0, KNullDesC );
       
   742 
       
   743     messageData->SetBodyTextL( bodyRichText );
       
   744     sendUi->ShowQueryAndSendL(messageData, sendingCapabilities, array); 
       
   745     CleanupStack::PopAndDestroy( 6 ); // bodyRichText, charFormat, paraFormat, messageData, sendUi
       
   746  }
       
   747 #else
       
   748 void WebPageController::share(const QString &url)
       
   749 {
       
   750     return; // Not supported 
       
   751 }
       
   752 #endif 
       
   753 
       
   754 /*
       
   755 Feedback from user
       
   756 */
       
   757 #if defined(Q_OS_SYMBIAN) 
       
   758 void WebPageController::feedbackMail(const QString &mailAddress, const QString &mailBody)
       
   759 {
       
   760     QString to = mailAddress; 
       
   761     QString body = mailBody;
       
   762     CSendUi* sendUi = CSendUi::NewLC();
       
   763     CMessageData* messageData = CMessageData::NewLC();
       
   764 
       
   765     // Body
       
   766     CParaFormatLayer* paraFormat = CParaFormatLayer::NewL();
       
   767     CleanupStack::PushL( paraFormat );
       
   768     CCharFormatLayer* charFormat = CCharFormatLayer::NewL();
       
   769     CleanupStack::PushL( charFormat );
       
   770     CRichText* bodyRichText = CRichText::NewL( paraFormat, charFormat );
       
   771     CleanupStack::PushL( bodyRichText );
       
   772     TPtrC ToPtr(reinterpret_cast<const TUint16*>(to.utf16()));
       
   773     TPtrC bodyPtr(reinterpret_cast<const TUint16*>(body.utf16()));
       
   774     if( bodyPtr.Length() )
       
   775         bodyRichText->InsertL( 0, bodyPtr );
       
   776     else
       
   777         bodyRichText->InsertL( 0, KNullDesC );
       
   778 
       
   779     messageData->AppendToAddressL( ToPtr );
       
   780     messageData->SetBodyTextL( bodyRichText );
       
   781 
       
   782     TRAP_IGNORE(sendUi->CreateAndSendMessageL( KUidMsgTypeSMTP, messageData ));
       
   783 //    TRAP_IGNORE(sendUi->CreateAndSendMessageL( KSenduiMtmSmsUid, messageData ));
       
   784     CleanupStack::PopAndDestroy( 5 ); 
       
   785 }
       
   786 #else
       
   787 void WebPageController::feedbackMail(const QString &mailAddress, const QString &mailBody)
       
   788 {
       
   789     return; // Not supported 
       
   790 }
       
   791 #endif 
   599 /*!
   792 /*!
   600   Load an item into the current page from a given /a historyIndex
   793   Load an item into the current page from a given /a historyIndex
   601 */
   794 */
   602 void WebPageController::currentSetFromHistory(int historyIndex)
   795 void WebPageController::currentSetFromHistory(int historyIndex)
   603 {
   796 {
   624             currentPage()->history()->goToItem(item);
   817             currentPage()->history()->goToItem(item);
   625         }
   818         }
   626     }
   819     }
   627 }
   820 }
   628 
   821 
   629 void WebPageController::pageGotoCurrentItem(int index)
       
   630 {
       
   631 
       
   632     WRT::WrtBrowserContainer* page = d->m_allPages.at(index);
       
   633     if(page) {
       
   634         QList<QWebHistoryItem> items = page->history()->items();
       
   635         QWebHistoryItem item = page->history()->currentItem();
       
   636         if (item.isValid()) {
       
   637            page->history()->goToItem(item);
       
   638         }
       
   639     }
       
   640 }
       
   641 
       
   642 void WebPageController::pageReload(int index)
       
   643 {
       
   644 
       
   645     WRT::WrtBrowserContainer* page = d->m_allPages.at(index);
       
   646     if(page) {
       
   647         QList<QWebHistoryItem> items = page->history()->items();
       
   648         QWebHistoryItem item = page->history()->currentItem();
       
   649         if (item.isValid()) {
       
   650           page->mainFrame()->load(item.url());
       
   651         }
       
   652     }
       
   653 }
       
   654 
       
   655 
       
   656 /*! 
   822 /*! 
   657   Initialize User Agent specific data / params. 
       
   658  */
       
   659 void WebPageController::initUASettingsAndData()
       
   660 {
       
   661     QCoreApplication::setApplicationName(BEDROCK_APPLICATION_NAME);
       
   662     //Set BrowserVersion: Format - VersionMajor.VersionMinor.SVNRevision
       
   663     QString browserAppVersion = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("BedrockVersion");
       
   664     if (browserAppVersion.isEmpty())
       
   665     {
       
   666       browserAppVersion = QString(BEDROCK_VERSION_DEFAULT);
       
   667     }
       
   668     QCoreApplication::setApplicationVersion(browserAppVersion);
       
   669 }
       
   670 
       
   671 /*!
       
   672   Activate Web Inspector
       
   673 */
       
   674 void WebPageController::webInspector()
       
   675 {
       
   676     if (QWebSettings::globalSettings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) {
       
   677         WRT::WrtBrowserContainer * activePage = currentPage();
       
   678         if(activePage)
       
   679             activePage->triggerAction(QWebPage::InspectElement);
       
   680     }
       
   681 }
       
   682 
       
   683 /*!
       
   684  * Private slot
   823  * Private slot
   685  */
   824  */
   686 void WebPageController::settingChanged(const QString &key)
       
   687 {
       
   688     if (d->m_actionWebInspector && key.endsWith("DeveloperExtras"))
       
   689         d->m_actionWebInspector->setVisible(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("DeveloperExtras"));
       
   690 }
       
   691 
       
   692 /*!
       
   693  * Private slot
       
   694  */
       
   695 void WebPageController::updateStatePageLoading()
   825 void WebPageController::updateStatePageLoading()
   696 {
   826 {
   697     updateActions(true);
   827     updateActions(true);
       
   828     
       
   829     // Reset to false for new page
       
   830     m_bErrorUrlMatches = false;
   698     
   831     
   699     // This is needed for loading a restored window (otherwise url bar is empty)
   832     // This is needed for loading a restored window (otherwise url bar is empty)
   700     currentPage()->loadController()->setUrlText(currentPage()->history()->currentItem().url().toString());
   833     currentPage()->loadController()->setUrlText(currentPage()->history()->currentItem().url().toString());
   701 }
   834 }
   702 
   835 
   713  */
   846  */
   714 void WebPageController::updateActions(bool pageIsLoading)
   847 void WebPageController::updateActions(bool pageIsLoading)
   715 {
   848 {
   716     d->m_actionReload->setEnabled(!pageIsLoading);
   849     d->m_actionReload->setEnabled(!pageIsLoading);
   717     d->m_actionStop->setEnabled(pageIsLoading);
   850     d->m_actionStop->setEnabled(pageIsLoading);
   718 
   851     
   719     WRT::WrtBrowserContainer* activePage = currentPage();    
   852     WRT::WrtBrowserContainer* activePage = currentPage();    
   720 
   853 
   721     if(activePage) {
   854     if(activePage) {
   722         int histLength = activePage->history()->count();
   855         int histLength = activePage->history()->count();
   723         int currItemIndex = activePage->history()->currentItemIndex();
   856         int currItemIndex = activePage->history()->currentItemIndex();
   724         d->m_actionBack->setEnabled((histLength > 1) && (currItemIndex > 0));
   857         d->m_actionBack->setEnabled((histLength > 1) && (currItemIndex > 0));
   725         d->m_actionForward->setEnabled((histLength > 1) && (currItemIndex < (histLength-1)));
   858         d->m_actionForward->setEnabled((histLength > 1) && (currItemIndex < (histLength-1)));
   726         d->m_actionWebInspector->setVisible(QWebSettings::globalSettings()->testAttribute(QWebSettings::DeveloperExtrasEnabled));
       
   727         	
   859         	
   728     }
   860     }
   729 }
   861 }
   730 
   862 
   731 /*!
   863 /*!
   740  * Private slot
   872  * Private slot
   741  */
   873  */
   742 void WebPageController::createWindow(WrtBrowserContainer* page)
   874 void WebPageController::createWindow(WrtBrowserContainer* page)
   743 {
   875 {
   744    openPage(this,page) ;
   876    openPage(this,page) ;
       
   877 }
       
   878 
       
   879 void WebPageController::LoadInNewWindow(const QString & url)
       
   880 {
       
   881     QWebPage* newPage = openPage();
       
   882     if (newPage) {
       
   883         newPage->mainFrame()->load(QUrl(url));
       
   884     }
   745 }
   885 }
   746 
   886 
   747 /*!
   887 /*!
   748  * Private slot
   888  * Private slot
   749  * Emits signals based on secure state 
   889  * Emits signals based on secure state 
   778 
   918 
   779     assert(singleton);
   919     assert(singleton);
   780     return singleton;
   920     return singleton;
   781 }
   921 }
   782 
   922 
   783 QWebPage* BrowserPageFactory::openBrowserPage()
   923 WRT::WrtBrowserContainer* BrowserPageFactory::openBrowserPage()
   784 {
   924 {
   785     return WebPageController::getSingleton()->openPage();
   925     return WebPageController::getSingleton()->openPage();
   786 }
   926 }
   787 
   927 
   788 QString WebPageController::guessUrlFromString(const QString &s){
   928 QString WebPageController::guessUrlFromString(const QString &s){
   789     QUrl u = WRT::UiUtil::guessUrlFromString(s);
   929 	  QUrl u = WRT::UiUtil::guessUrlFromString(s);
   790     return u.toString();
   930     return u.toString();
   791 }
   931 }
   792 
   932 
       
   933 QString WebPageController::searchUrl(const QString &s){
       
   934     QUrl u = WRT::UiUtil::searchUrl(s);
       
   935     return u.toString();
       
   936 }
       
   937 
       
   938 QObjectList WebPageController::fetchSuggestions(const QString &s){
       
   939     QObjectList suggestList = WRT::ContentAgent::getSingleton()->getUISuggestion(s);
       
   940 	return suggestList;
       
   941 }
   793 
   942 
   794 void WebPageController::loadLocalFile()
   943 void WebPageController::loadLocalFile()
   795 	{
   944 	{
   796     QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory2");
   945     QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("LocalPagesBaseDirectory");
   797     QString startPage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage");
   946     QString startPage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage");
   798     QString startPagePath = chromeBaseDir + startPage;
   947     QString startPagePath = chromeBaseDir + startPage;
       
   948 
   799     currentLoad(startPagePath);
   949     currentLoad(startPagePath);
   800 	}
   950 	}
       
   951 
       
   952 void WebPageController::loadInitialUrlFromOtherApp(QString url)
       
   953 {
       
   954     m_bRestoreSession = FALSE;
       
   955     currentLoad(url);
       
   956 }
   801 
   957 
   802 void WebPageController::loadFromHistory() 
   958 void WebPageController::loadFromHistory() 
   803 {
   959 {
   804 
   960 
   805    int count = historyWindowCount();
   961    int count = historyWindowCount();
   820     	 	
   976     	 	
   821     	 	for(int i = 0; i < count2-1; i++) //all windows except current
   977     	 	for(int i = 0; i < count2-1; i++) //all windows except current
   822     	 	{
   978     	 	{
   823     	 		openPageFromHistory(i);
   979     	 		openPageFromHistory(i);
   824     	 	}		
   980     	 	}		
   825     	 m_bRestoreSession = false;
   981     	  m_bRestoreSession = false;
   826     	 // current window
   982 
       
   983     	 // Go to current window
       
   984     	 int pageIndex = activeWindowId();
       
   985     	 WRT::WrtBrowserContainer* page = d->m_allPages.at(pageIndex);
       
   986     	 setCurrentPage(page);
   827     	 gotoCurrentItem();
   987     	 gotoCurrentItem();
   828     	 	
   988     	 	
   829     	 }
   989     	 }
   830     	 else // browser did not close correctly; exception handler: delete all files and load start page as in first startup
   990     	 else // browser did not close correctly; exception handler: delete all files and load start page as in first startup
   831     	 {
   991     	 {
   837     m_bRestoreSession = false;
   997     m_bRestoreSession = false;
   838     return ;
   998     return ;
   839 
   999 
   840 }
  1000 }
   841 
  1001 
   842 WRT::WrtBrowserContainer* WebPageController::restoreHistory(QWidget* parent, int index)
       
   843 {
       
   844     Q_UNUSED(parent)
       
   845     // restore the history state from the disk for the current page
       
   846     QString indexStr;
       
   847     indexStr.setNum(index);
       
   848     QString historyFile = d->m_historyDir + QLatin1String("/history") + indexStr + QLatin1String(".history");
       
   849     WRT::WrtBrowserContainer* page = openPage(this,0);
       
   850 
       
   851     qDebug() << "historyFile>>:" << historyFile;
       
   852     QFile file(historyFile);
       
   853     if(file.open(QIODevice::ReadOnly)) {
       
   854         QDataStream restore(&file);
       
   855         restore >> *(page->history());
       
   856         file.close();
       
   857     }
       
   858     return page;
       
   859 }
       
   860 
  1002 
   861 WRT::WrtBrowserContainer* WebPageController::startupRestoreHistory(QWidget* parent, int index, WRT::WrtBrowserContainer* page)
  1003 WRT::WrtBrowserContainer* WebPageController::startupRestoreHistory(QWidget* parent, int index, WRT::WrtBrowserContainer* page)
   862 {
  1004 {
   863     Q_UNUSED(parent)
  1005     Q_UNUSED(parent)
   864     // restore the history state from the disk for the current page
  1006     // restore the history state from the disk for the current page
   865     QString indexStr;
  1007     QString indexStr;
   866     indexStr.setNum(index);
  1008     indexStr.setNum(index);
   867     QString historyFile = d->m_historyDir + QLatin1String("/history") + indexStr + QLatin1String(".history");
  1009     QString historyFile = d->m_historyDir + QLatin1String("/history") + indexStr + QLatin1String(".history");
   868    
  1010    
   869     qDebug() << "historyFile>>:" << historyFile;
       
   870     QFile file(historyFile);
  1011     QFile file(historyFile);
   871     if(file.open(QIODevice::ReadOnly)) {
  1012     if(file.open(QIODevice::ReadOnly)) {
   872         QDataStream restore(&file);
  1013         QDataStream restore(&file);
   873         restore >> *(page->history());
  1014         restore >> *(page->history());
   874         file.close();
  1015         file.close();
   903      }
  1044      }
   904     
  1045     
   905 	  return winStr;
  1046 	  return winStr;
   906 }
  1047 }
   907 
  1048 
   908 void WebPageController::saveHistory()
  1049 void WebPageController::saveHistory(int* windowsSaved, int* activeWindowId)
   909 {
  1050 {
   910     QString indexStr;
  1051     QString indexStr;
       
  1052     int index = 0;
       
  1053     
   911     unsigned int pageCount =  d->m_allPages.count();
  1054     unsigned int pageCount =  d->m_allPages.count();
   912     int index = 0;
  1055     
   913     
  1056     // Get index of current page
   914     WRT::WrtBrowserContainer* theCurrentPage = currentPage();
  1057     WRT::WrtBrowserContainer* theCurrentPage = currentPage();
   915     int currentIndex = d->m_allPages.indexOf(theCurrentPage);
  1058     int currentIndex = d->m_allPages.indexOf(theCurrentPage);
   916     
  1059          
   917     //if(pageCount == 1)
       
   918     //{	
       
   919     	QWebHistoryItem	item = theCurrentPage->history()->currentItem();
       
   920 	  	
       
   921 	  	setLastUrl(item.url().toString());
       
   922 	  //}
       
   923     
       
   924     for (int tIndex = 0; tIndex < pageCount; tIndex++)
  1060     for (int tIndex = 0; tIndex < pageCount; tIndex++)
   925     {
  1061     {
   926     	  if(tIndex == pageCount-1)
  1062        	// Don't save blank windows
   927     	  	index = currentIndex;
  1063        	WrtBrowserContainer* page = d->m_allPages.at(tIndex);
   928     	  else if(tIndex == currentIndex)
  1064        	QString pageUrl = page->history()->currentItem().url().toString();
   929     	  	index = pageCount-1;
  1065        	if (!pageUrl.isEmpty())
   930     	  else
  1066         {    	  
   931     	  	index = tIndex;	
  1067 
   932     	
  1068           // In case of blank windows, reset the active window id
   933         if (index >= MAX_NUM_WINDOWS_TO_RESTORE) return;
  1069           if (currentIndex == tIndex) *activeWindowId = index;
   934         indexStr.setNum(tIndex);
  1070 
   935         QString historyFile = d->m_historyDir + QLatin1String("/history") + indexStr + QLatin1String(".history");
  1071           // Serialize page to file
   936         // Save the History state to disk
  1072           indexStr.setNum(index);
   937         QFile file(historyFile);
  1073           QString historyFile = d->m_historyDir + QLatin1String("/history") + indexStr + QLatin1String(".history");
   938         if(file.open(QIODevice::WriteOnly)) {
  1074           QFile file(historyFile);
   939            QDataStream save(&file);
  1075           if(file.open(QIODevice::WriteOnly)) {
   940            save << *(d->m_allPages.at(index)->history());
  1076              QDataStream save(&file);
   941            qDebug() << "Saved History<<:" << historyFile;
  1077              save << *(d->m_allPages.at(tIndex)->history());
   942            file.flush();
  1078              file.flush();
   943            file.close();
  1079              file.close();
       
  1080           }
       
  1081           index++;
   944         }
  1082         }
   945     }
  1083     }
       
  1084 
       
  1085     // Save last url
       
  1086     WRT::WrtBrowserContainer* currentPage = d->m_allPages.at(*activeWindowId);
       
  1087     QWebHistoryItem	item = theCurrentPage->history()->currentItem();
       
  1088     QString lastUrl = item.url().toString();
       
  1089   	setLastUrl(lastUrl);
       
  1090     *windowsSaved = index;
   946 }
  1091 }
   947 
  1092 
   948 void WebPageController::deleteDataFiles()
  1093 void WebPageController::deleteDataFiles()
   949 {
  1094 {
       
  1095     
   950     QDir dir(d->m_historyDir);
  1096     QDir dir(d->m_historyDir);
   951     
  1097     
   952     QString lasturlFile = d->m_historyDir + QLatin1String("/lasturl") + QLatin1String(".dat");
  1098     QString lasturlFile = d->m_historyDir + QLatin1String("/lasturl") + QLatin1String(".dat");
   953     QFile file1(lasturlFile);
  1099     QFile file1(lasturlFile);
   954     if(file1.open(QIODevice::ReadOnly)) 
  1100     if(file1.open(QIODevice::ReadOnly)) 
   962     if(file2.open(QIODevice::ReadOnly)) 
  1108     if(file2.open(QIODevice::ReadOnly)) 
   963     {
  1109     {
   964          file2.remove();
  1110          file2.remove();
   965          file2.close();
  1111          file2.close();
   966     }
  1112     }
       
  1113     
       
  1114     d->donotsaveFlag = true;
   967           
  1115           
   968 }
  1116 }
   969 
  1117 
       
  1118 QString WebPageController::getTextEncoding()
       
  1119 {
       
  1120  //QString encoding = QWebSettings::globalSettings()->defaultTextEncoding();
       
  1121  QString encoding = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("BrowserEncoding").toString();
       
  1122  	
       
  1123  if(encoding == "Automatic")
       
  1124  	QWebSettings::globalSettings()->setDefaultTextEncoding("");
       
  1125  else		
       
  1126   QWebSettings::globalSettings()->setDefaultTextEncoding(encoding);
       
  1127  	
       
  1128  return encoding;
       
  1129 } 	
       
  1130 
       
  1131 
       
  1132 void WebPageController::setTextEncoding(const QString & encoding )
       
  1133 {
       
  1134  if(encoding == "Automatic")
       
  1135  	QWebSettings::globalSettings()->setDefaultTextEncoding("");
       
  1136  else		
       
  1137  	QWebSettings::globalSettings()->setDefaultTextEncoding(encoding);
       
  1138  	
       
  1139  BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("BrowserEncoding", encoding);
       
  1140  return ;
       
  1141 } 	
       
  1142 
       
  1143 
       
  1144 void WebPageController::setSettingsLoaded(int value)
       
  1145 {
       
  1146  	m_settingsLoaded = value;
       
  1147 }	
       
  1148  	
       
  1149 int WebPageController::getSettingsLoaded()
       
  1150 {
       
  1151 	return m_settingsLoaded;
       
  1152 }    
       
  1153 
   970 void WebPageController::savePopupSettings(int val)
  1154 void WebPageController::savePopupSettings(int val)
   971 {
  1155 {
   972 	  BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("PopupBlocking", val);
  1156     BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("PopupBlocking", val);
       
  1157   
       
  1158     //qDebug() << "WebPageController::savePopupSettings " << val  <<  d->m_allPages.count();
       
  1159     for (int tIndex = 0; tIndex <  d->m_allPages.count(); tIndex++)
       
  1160     {
       
  1161         WrtBrowserContainer* page = d->m_allPages.at(tIndex);
       
  1162         page->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !val);
       
  1163 
       
  1164     }
       
  1165 
   973 }
  1166 }
   974 
  1167 
   975 bool WebPageController::getPopupSettings()
  1168 bool WebPageController::getPopupSettings()
   976 {
  1169 {
   977 		bool val = (bool)BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("PopupBlocking").toInt();
  1170 		bool val = (bool)BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("PopupBlocking").toInt();
   978 		return val;
  1171 		return val;
   979 		
  1172 		
   980 }
  1173 }
   981 
  1174 
   982 void WebPageController::saveNumberOfWindows()
  1175 
       
  1176 void WebPageController::saveSaverestoreSettings(int val)
       
  1177 {
       
  1178 	  BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("SaveSession", val);
       
  1179 	  BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("SaveHistory", val);
       
  1180 	  	
       
  1181 	  	if(val == 0)
       
  1182 	  		d->donotsaveFlag = true; // do not save .dat file
       
  1183 	  	else // val = 1
       
  1184 	  		d->donotsaveFlag = false;
       
  1185 	  		
       
  1186 }
       
  1187 
       
  1188 bool WebPageController::getSaverestoreSettings()
       
  1189 {
       
  1190 		bool val = (bool)BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("SaveSession").toInt();
       
  1191 		return val;
       
  1192 		
       
  1193 }
       
  1194 
       
  1195 void WebPageController::saveNumberOfWindows(int windowsSaved)
   983 {
  1196 {
   984 	QString winFile = d->m_historyDir + QLatin1String("/numwindow") + QLatin1String(".dat");
  1197 	QString winFile = d->m_historyDir + QLatin1String("/numwindow") + QLatin1String(".dat");
   985   int winCount =  d->m_allPages.count();
       
   986     
  1198     
   987   QFile file(winFile);
  1199   QFile file(winFile);
   988   if(file.open(QIODevice::WriteOnly)) {
  1200   if(file.open(QIODevice::WriteOnly)) {
   989         QTextStream textStream(&file);
  1201         QTextStream textStream(&file);
   990         textStream << winCount;
  1202         textStream << windowsSaved;
       
  1203         textStream.flush();
       
  1204         file.close();
       
  1205    }
       
  1206 	
       
  1207 }
       
  1208 void WebPageController::saveActiveWindowId(int activeWindowId)
       
  1209 {
       
  1210 	QString winFile = d->m_historyDir + QLatin1String("/activewindow") + QLatin1String(".dat");
       
  1211   
       
  1212   QFile file(winFile);
       
  1213   if(file.open(QIODevice::WriteOnly)) {
       
  1214         QTextStream textStream(&file);
       
  1215         textStream << activeWindowId;
   991         textStream.flush();
  1216         textStream.flush();
   992         file.close();
  1217         file.close();
   993    }
  1218    }
   994 	
  1219 	
   995 }
  1220 }
  1005         file.close();
  1230         file.close();
  1006     }
  1231     }
  1007     return winStr.toInt();
  1232     return winStr.toInt();
  1008 }
  1233 }
  1009 
  1234 
       
  1235 int WebPageController::activeWindowId()
       
  1236 {
       
  1237 	QString winFile = d->m_historyDir + QLatin1String("/activewindow") + QLatin1String(".dat");
       
  1238     QFile file(winFile);
       
  1239     QString winStr = "0";
       
  1240     if(file.open(QIODevice::ReadOnly)) {
       
  1241         QTextStream textStream(&file);
       
  1242         textStream >> winStr;
       
  1243         file.close();
       
  1244     }
       
  1245     return winStr.toInt();
       
  1246 }
       
  1247 
  1010 int WebPageController::historyWindowCount()
  1248 int WebPageController::historyWindowCount()
  1011 {
  1249 {
  1012     QDir dir(d->m_historyDir);
  1250     QDir dir(d->m_historyDir);
  1013     QFileInfoList fileList(dir.entryInfoList(QDir::Files));
  1251     QFileInfoList fileList(dir.entryInfoList(QDir::Files));
  1014     int windowCount = 0;
  1252     int windowCount = 0;
  1020         }
  1258         }
  1021     }
  1259     }
  1022     return windowCount;
  1260     return windowCount;
  1023 }
  1261 }
  1024 
  1262 
  1025 void WebPageController::networkRequestFinished(QNetworkReply *reply){
       
  1026   if(reply->error() != QNetworkReply::NoError) {
       
  1027     emit networkRequestError(reply);
       
  1028   }
       
  1029 }
       
  1030 
       
  1031 QString WebPageController::currentDocTitle()
  1263 QString WebPageController::currentDocTitle()
  1032 {
  1264 {
  1033     assert(currentPage());
  1265     assert(currentPage());
  1034     return currentPage()->pageTitle();
  1266     return currentPage()->pageTitle();
  1035 }
  1267 }
  1041 }
  1273 }
  1042 
  1274 
  1043 QString WebPageController::currentRequestedUrl() const
  1275 QString WebPageController::currentRequestedUrl() const
  1044 {
  1276 {
  1045     assert(currentPage());
  1277     assert(currentPage());
       
  1278     //qDebug() << __func__ << "Current Page" << currentPage() << "Requested Url " << currentPage()->mainFrame()->requestedUrl().toString();
  1046     return currentPage()->mainFrame()->requestedUrl().toString();
  1279     return currentPage()->mainFrame()->requestedUrl().toString();
  1047 }
  1280 }
  1048 
  1281 
  1049 QString WebPageController::currentPartialUrl() 
  1282 QString WebPageController::currentPartialUrl() 
  1050 {
  1283 {
  1051     assert(currentPage());
  1284     assert(currentPage());
  1052     return (partialUrl(currentPage()->mainFrame()->url()));
  1285     return (partialUrl(currentPage()->mainFrame()->url()));
  1053 }
  1286 }
  1054 
  1287 
  1055 QVariant WebPageController::currentContentWindowObject()
  1288 QString WebPageController::currentPartialReqUrl() 
  1056 {
  1289 {
  1057     try {
  1290     assert(currentPage());
  1058         return currentPage()->mainFrame()->evaluateJavaScript("window");
  1291     return (partialUrl(currentPage()->mainFrame()->requestedUrl()));
  1059     }
       
  1060     catch(...) {
       
  1061         qDebug() << "WebPageController::currentContentWindowObject: caught expection";
       
  1062         return QVariant();
       
  1063     }
       
  1064 }
  1292 }
  1065 
  1293 
  1066 int WebPageController::contentsYPos()
  1294 int WebPageController::contentsYPos()
  1067 {
  1295 {
  1068     assert(currentPage());
  1296     assert(currentPage());
  1074     return d->m_currentPage;
  1302     return d->m_currentPage;
  1075 }
  1303 }
  1076 
  1304 
  1077 int WebPageController::secureState() {
  1305 int WebPageController::secureState() {
  1078 
  1306 
  1079     //qDebug() << __func__ << currentPage()->secureState();
       
  1080     return (currentPage()->secureState());
  1307     return (currentPage()->secureState());
  1081 }
  1308 }
  1082 
  1309 
  1083 // copy/paste from controllableviewjstobject. TODO: merge common code
  1310 // copy/paste from controllableviewjstobject. TODO: merge common code
  1084 void WebPageController::updateJSActions()
  1311 void WebPageController::updateJSActions()
  1094             ActionJSObject *jso = new ActionJSObject(d->m_actionsParent, action);
  1321             ActionJSObject *jso = new ActionJSObject(d->m_actionsParent, action);
  1095         }
  1322         }
  1096     }
  1323     }
  1097 }
  1324 }
  1098 
  1325 
       
  1326 
       
  1327 bool WebPageController::removeDirectory(QDir &aDir)
       
  1328 {
       
  1329 		bool has_err = false;
       
  1330 		if (aDir.exists())
       
  1331 		{
       
  1332 				QFileInfoList entries = aDir.entryInfoList(QDir::NoDotAndDotDot | 
       
  1333 				QDir::Dirs | QDir::Files);
       
  1334 				int count = entries.size();
       
  1335 				for (int idx = 0; ((idx < count) && (0 == has_err)); idx++)
       
  1336 				{
       
  1337 						QFileInfo entryInfo = entries[idx];
       
  1338 						QString path = entryInfo.absoluteFilePath();
       
  1339 						if (entryInfo.isDir())
       
  1340 						{
       
  1341 							QDir dir(path);
       
  1342 							has_err = removeDirectory(dir);
       
  1343 						}
       
  1344 						else
       
  1345 						{
       
  1346 							QFile file(path);
       
  1347 							if (!file.remove())
       
  1348 							has_err = true;
       
  1349 						}
       
  1350 				}
       
  1351 				if (!aDir.rmdir(aDir.absolutePath()))
       
  1352 					has_err = true;
       
  1353 		}
       
  1354 		return(has_err);
       
  1355 }
       
  1356 
  1099 void WebPageController::clearHistoryInMemory()
  1357 void WebPageController::clearHistoryInMemory()
  1100 {
  1358 {
  1101     WRT::WrtBrowserContainer * activePage = currentPage();
  1359     WRT::WrtBrowserContainer * activePage = currentPage();
  1102     if(activePage)
  1360     if(activePage)
  1103     {
  1361     {
  1104         activePage->history()->clear();
  1362         activePage->history()->clear();
  1105     }
  1363     }
  1106     d->donotsaveFlag = true;
       
  1107 }
  1364 }
  1108 
  1365 
  1109 void WebPageController::deleteHistory()
  1366 void WebPageController::deleteHistory()
  1110 {
  1367 {
  1111     QDir dir(d->m_historyDir);
  1368     QDir dir(d->m_historyDir);
  1148     }
  1405     }
  1149 }
  1406 }
  1150 
  1407 
  1151 void WebPageController::deleteCache()
  1408 void WebPageController::deleteCache()
  1152 {
  1409 {
       
  1410 	  
       
  1411     QWebDatabase::removeAllDatabases();
       
  1412     
       
  1413     QString  str1 = QWebSettings::offlineStoragePath ();
       
  1414     QString  str2 = QWebSettings::offlineWebApplicationCachePath ();
       
  1415     QWebSettings * globalSettings = QWebSettings::globalSettings();
       
  1416     QString  LocalStoragePath = globalSettings->localStoragePath();
       
  1417     	
       
  1418     /*QString deleteFlag = d->m_historyDir + QLatin1String("/deleteOfflineStorage");
       
  1419     QFile deleteFileFlag(deleteFlag);
       
  1420     if(deleteFileFlag.open(QIODevice::WriteOnly)) { // create indicator that marks offline storage for deletion while next browser startup
       
  1421          deleteFileFlag.close();
       
  1422     }*/
       
  1423     
       
  1424     QDir LocalStorage(LocalStoragePath);  	
       
  1425     removeDirectory(LocalStorage); 
       
  1426     
       
  1427     QString applicationCacheFile = d->m_historyDir + QLatin1String("/ApplicationCache.db");  
       
  1428     QFile file(applicationCacheFile);
       
  1429     if(file.open(QIODevice::ReadOnly)) {
       
  1430          file.remove(); // may fail if file in usage; will be deleted in next browser startup
       
  1431          file.close();
       
  1432     }
       
  1433     
  1153 	  if ( !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheEnabled").toBool() ) 
  1434 	  if ( !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheEnabled").toBool() ) 
  1154 			return;
  1435 			return;
  1155 		
  1436 		
  1156 		QString diskCacheDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheDirectoryPath").toString();
  1437 		QString diskCacheDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheDirectoryPath").toString();
  1157 			
  1438 			
  1201     }
  1482     }
  1202     
  1483     
  1203     
  1484     
  1204 }
  1485 }
  1205 
  1486 
  1206 
       
  1207 void WebPageController::urlChanged(const QUrl& url)
  1487 void WebPageController::urlChanged(const QUrl& url)
  1208 {
  1488 {
  1209     //private slot
  1489     //private slot
  1210     QString urlString = partialUrl(url);
  1490     QString urlString = partialUrl(url);
  1211     emit partialUrlChanged(urlString);    
  1491     emit partialUrlChanged(urlString);    
  1212 }
  1492 }
  1213 
       
  1214 
  1493 
  1215 QString WebPageController::partialUrl(const QUrl& url)
  1494 QString WebPageController::partialUrl(const QUrl& url)
  1216 {
  1495 {
  1217 
  1496 
  1218     QString urlString = url.toString();
  1497     QString urlString = url.toString();
  1244     QSize currSize = view->size().toSize();
  1523     QSize currSize = view->size().toSize();
  1245 
  1524 
  1246     bool needRestore =  false;
  1525     bool needRestore =  false;
  1247 
  1526 
  1248     for (int i = 0; i < allPages()->count(); i++) {
  1527     for (int i = 0; i < allPages()->count(); i++) {
  1249          WRT::WrtBrowserContainer* page = allPages()->at(i);
  1528         WRT::WrtBrowserContainer* page = allPages()->at(i);
  1250          QWebHistoryItem item = page->history()->currentItem();
  1529         QWebHistoryItem item = page->history()->currentItem();
  1251 
  1530         WebPageData data = item.userData().value<WebPageData>();
  1252          WebPageData data = item.userData().value<WebPageData>();
       
  1253 
  1531 
  1254         // If not still a blank window, check whether we need to update the img
  1532         // If not still a blank window, check whether we need to update the img
  1255         if (!page->emptyWindow() ){
  1533         if (!page->emptyWindow() ){
  1256             QImage img = data.m_thumbnail;
  1534             QImage img = data.m_thumbnail;
  1257     
  1535             bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) );
  1258              bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) );
  1536             if (img.isNull() || !isSameMode) {
  1259              if (img.isNull() || !isSameMode) {
  1537                 needRestore = true;
  1260          
  1538                 view->setPage(page);
  1261                  qDebug() << "need new thumbnail!!!" << img.size() << ":" << currSize;
  1539                 page->setWebWidget(view);
  1262                  needRestore = true;
  1540                 QCoreApplication::sendEvent(view, new WebPageControllerUpdateViewPortEvent());
  1263                  view->setPage(page);
  1541                 page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1264                  page->setWebWidget(view);
  1542                 page->setUpdateThumbnail(false);
  1265                  QCoreApplication::sendEvent(view, new WebPageControllerUpdateViewPortEvent());
  1543             }
  1266                  page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1544             if (page->needUpdateThumbnail()) {
  1267              }
  1545                 page->savePageDataToHistoryItem(page->mainFrame(), &item);
       
  1546                 page->setUpdateThumbnail(false);
       
  1547             }
  1268          }
  1548          }
  1269     }
  1549     }
  1270 
  1550 
  1271     // restore
  1551     // restore
  1272     if (needRestore)
  1552     if (needRestore) {    
  1273     {    
       
  1274         view->setPage(savedPage);
  1553         view->setPage(savedPage);
  1275         savedPage->setWebWidget(view);
  1554         savedPage->setWebWidget(view);
  1276     }
  1555     }
  1277 }
  1556 }
  1278 
  1557 
  1279 void WebPageController::updatePageThumbnails()
  1558 void WebPageController::updatePageThumbnails()
  1280 {
  1559 {
  1281     // update current page's thumbnail forcely
  1560     // update current page's thumbnail forcely since the scrolling position may change
  1282     WRT::WrtBrowserContainer *page = currentPage();
  1561     WRT::WrtBrowserContainer *page = currentPage();
  1283     QWebHistoryItem item = page->history()->currentItem();
  1562     QWebHistoryItem item = page->history()->currentItem();
  1284 
       
  1285     page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1563     page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1286 
  1564     page->setUpdateThumbnail(false);
  1287     WebPageData data = item.userData().value<WebPageData>();
       
  1288 
       
  1289     checkAndUpdatePageThumbnails();
  1565     checkAndUpdatePageThumbnails();
  1290 }
  1566 }
  1291 
  1567 
  1292 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s)
  1568 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s)
  1293 {
  1569 {
  1296     checkAndUpdatePageThumbnails();
  1572     checkAndUpdatePageThumbnails();
  1297 }
  1573 }
  1298 
  1574 
  1299 void WebPageController::urlTextChanged(QString str ) {
  1575 void WebPageController::urlTextChanged(QString str ) {
  1300 
  1576 
       
  1577    //qDebug() << __func__ << "Current Page" << currentPage() << "Url " << str;
  1301    currentPage()->loadController()->setUrlText(str);
  1578    currentPage()->loadController()->setUrlText(str);
  1302 }
  1579 }
  1303 
  1580 
  1304 int WebPageController::loadState() {
  1581 int WebPageController::loadState() {
  1305     //if (currentPage())
  1582     //if (currentPage())
  1320     return currentPage()->loadController()->progressValue();
  1597     return currentPage()->loadController()->progressValue();
  1321 }
  1598 }
  1322 
  1599 
  1323 QString WebPageController::loadText() {
  1600 QString WebPageController::loadText() {
  1324 
  1601 
  1325     //qDebug() << __func__ << currentPage()->loadController()->urlText();
  1602     //qDebug() << __func__ << "Current Page" << currentPage() << currentPage()->loadController()->urlText();
  1326     return currentPage()->loadController()->urlText();
  1603     return currentPage()->loadController()->urlText();
  1327 }
  1604 }
  1328 
  1605 
  1329 bool WebPageController::isPageLoading() {
  1606 bool WebPageController::isPageLoading() {
  1330     return currentPage()->loadController()->isPageLoading();
  1607     return currentPage()->loadController()->isPageLoading();
  1331 }
  1608 }
  1332 
  1609 
  1333 bool WebPageController::loadCanceled() {
  1610 bool WebPageController::loadCanceled() {
  1334     return currentPage()->loadController()->loadCanceled();
  1611     return currentPage()->loadController()->loadCanceled();
  1335 }
  1612 }
       
  1613 
       
  1614 bool WebPageController::networkError() {
       
  1615     return m_networkError; 
       
  1616 }
       
  1617 
       
  1618 QString WebPageController::networkErrorMsg() {
       
  1619     return m_networkErrorMsg; 
       
  1620 }
       
  1621 
       
  1622 QString WebPageController::networkErrorUrl() {
       
  1623     return m_networkErrorUrl; 
       
  1624 }
       
  1625 
       
  1626 bool WebPageController::errorUrlMatches() {
       
  1627   return m_bErrorUrlMatches;
       
  1628 }
       
  1629 
       
  1630 QString WebPageController::promptMsg() {
       
  1631     return m_promptMsg; 
       
  1632 }
       
  1633 
       
  1634 QString WebPageController::promptReserved() {
       
  1635     return m_promptReserved; 
       
  1636 } 
       
  1637 
  1336 /*!
  1638 /*!
  1337   \fn void WebPageController::pageCreated(WrtPage* newPage);
  1639   \fn void WebPageController::pageCreated(WrtPage* newPage);
  1338   emitted when a page is created
  1640   emitted when a page is created
  1339 */
  1641 */
  1340 
  1642