browsercore/appfw/Api/Managers/webpagecontroller.cpp
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 10 232fbd5a2dcb
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    39 #include <QGraphicsWebView>
    39 #include <QGraphicsWebView>
    40 #include <QFile>
    40 #include <QFile>
    41 #include <QDir>
    41 #include <QDir>
    42 #include <QtGui>
    42 #include <QtGui>
    43 #include <QCoreApplication>
    43 #include <QCoreApplication>
       
    44 #include <QWebSecurityOrigin>
       
    45 #include <QWebDatabase>
       
    46 #include <QWebSettings>
       
    47 #include <QtCore/QSettings>
    44 using namespace WRT;
    48 using namespace WRT;
    45 
    49 
    46 #if defined(Q_OS_SYMBIAN) // for shareToMail
    50 #if defined(Q_OS_SYMBIAN) // for shareToMail
    47 #include <miutset.h>                
    51 #include <miutset.h>                
    48 #include <sendui.h>      
    52 #include <sendui.h>      
   141 WebPageController::WebPageController ( QObject* parent ) :
   145 WebPageController::WebPageController ( QObject* parent ) :
   142     QObject ( parent ),
   146     QObject ( parent ),
   143     m_networkError (false),
   147     m_networkError (false),
   144     m_networkErrorMsg("No network error"),           
   148     m_networkErrorMsg("No network error"),           
   145     m_networkErrorUrl("No Url"),
   149     m_networkErrorUrl("No Url"),
       
   150     m_promptMsg("No message"),           
       
   151     m_promptReserved(""),
   146     m_memoryHandler(new LowMemoryHandler(this)),
   152     m_memoryHandler(new LowMemoryHandler(this)),
   147     d(new WebPageControllerPrivate(this)),
   153     d(new WebPageControllerPrivate(this)),
   148     m_settingsLoaded(0)
   154     m_settingsLoaded(0),
       
   155     m_bErrorUrlMatches(false)
   149 {
   156 {
   150     // 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)
   151     qRegisterMetaTypeStreamOperators<WebPageData> ("WebPageData");
   158     qRegisterMetaTypeStreamOperators<WebPageData> ("WebPageData");
   152 
   159 
   153     d->m_historyDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseDirectory");
   160     d->m_historyDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseDirectory");
   156     connect( d->m_actionReload, SIGNAL( triggered() ), this, SLOT( currentReload() ) );
   163     connect( d->m_actionReload, SIGNAL( triggered() ), this, SLOT( currentReload() ) );
   157     connect( d->m_actionStop, SIGNAL( triggered() ), this, SLOT( currentStop() ) );
   164     connect( d->m_actionStop, SIGNAL( triggered() ), this, SLOT( currentStop() ) );
   158     connect( d->m_actionBack, SIGNAL( triggered() ), this, SLOT( currentBack() ) );
   165     connect( d->m_actionBack, SIGNAL( triggered() ), this, SLOT( currentBack() ) );
   159     connect( d->m_actionForward, SIGNAL( triggered() ), this, SLOT( currentForward() ) );
   166     connect( d->m_actionForward, SIGNAL( triggered() ), this, SLOT( currentForward() ) );
   160 
   167 
       
   168     connect( m_memoryHandler, SIGNAL( lowMemory() ), this, SIGNAL( lowMemory() ) );
   161     connect( m_memoryHandler, SIGNAL( lowMemory() ), this, SLOT( handleLowMemory() ) );
   169     connect( m_memoryHandler, SIGNAL( lowMemory() ), this, SLOT( handleLowMemory() ) );
       
   170     connect( m_memoryHandler, SIGNAL( outOfMemory() ), this, SIGNAL( outOfMemory() ) );
   162     connect( m_memoryHandler, SIGNAL( outOfMemory() ), this, SLOT( handleOutOfMemory() ) );
   171     connect( m_memoryHandler, SIGNAL( outOfMemory() ), this, SLOT( handleOutOfMemory() ) );
   163     m_memoryHandler->start();
   172     m_memoryHandler->start();
   164 
   173 
   165     updateJSActions();
   174     updateJSActions();
   166     
   175     
   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"));
   200 
   209         connect( page, SIGNAL( loadFinished(bool) ), SLOT( onLoadFinishedForBackgroundWindow(bool) ) );
   201 
   210 
   202         // emit signal indicating that new page is being created
   211         // emit signal indicating that new page is being created
   203         emit creatingPage( page );
   212         emit creatingPage( page );
   204 
   213 
   205         /* Add the new page after the current page */
   214         /* Add the new page after the current page */
   272  * @param page   WRT::WrtBrowserContainer instance to be closed 
   281  * @param page   WRT::WrtBrowserContainer instance to be closed 
   273  * @see  WRT::WrtBrowserContainer
   282  * @see  WRT::WrtBrowserContainer
   274  */
   283  */
   275 void WebPageController::closePage ( WRT::WrtBrowserContainer *page )
   284 void WebPageController::closePage ( WRT::WrtBrowserContainer *page )
   276 {
   285 {
   277     WRT::WrtBrowserContainer * theCurrentPage = currentPage();
   286     if(pageCount() > 1) {
   278     bool updateCurrentPageIndex = false;
   287         WRT::WrtBrowserContainer * theCurrentPage = currentPage();
   279 
   288         bool updateCurrentPageIndex = false;
   280     // get index of page we want to remove
   289 
   281     int closeIndex = d->m_allPages.indexOf(page);
   290         // get index of page we want to remove
   282     if(closeIndex < 0)
   291         int closeIndex = d->m_allPages.indexOf(page);
   283         return;
   292         if(closeIndex < 0)
   284     
   293             return;
   285     // was this page the "current page?"
   294     
   286     // if so, we need to select the page to become the new one
   295         // was this page the "current page?"
   287     // 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
   288     if(page == theCurrentPage) {
   297         // select the previous page unless at the beginning, then select next
   289         int newCurrIndex = closeIndex - 1;
   298         if(page == theCurrentPage) {
   290         if(closeIndex == 0 ) {
   299             int newCurrIndex = closeIndex - 1;
   291             newCurrIndex = closeIndex + 1;
   300             if(closeIndex == 0 ) {
   292         }
   301                 newCurrIndex = closeIndex + 1;
       
   302             }
   293         
   303         
   294         // change the current page
   304             // change the current page
   295         if(newCurrIndex >= 0) {
   305             if(newCurrIndex >= 0) {
   296             theCurrentPage = d->m_allPages.at(newCurrIndex);
   306                 theCurrentPage = d->m_allPages.at(newCurrIndex);
   297             setCurrentPage(theCurrentPage);
   307                 setCurrentPage(theCurrentPage);
   298             updateCurrentPageIndex = true;
   308                 updateCurrentPageIndex = true;
       
   309             }
       
   310             else {
       
   311                 d->m_currentPage = -1;
       
   312                 emit pageChanged(page, NULL);
       
   313             }
   299         }
   314         }
   300         else {
   315         else {
   301             d->m_currentPage = -1;
   316              /* Adjust m_currentPage if the index of the page deleted is less than 
   302             emit pageChanged(page, NULL);
   317              * current page 
       
   318              */
       
   319            if (closeIndex < d->m_currentPage ) 
       
   320                updateCurrentPageIndex = true;
   303         }
   321         }
   304     }
   322 
   305     else {
   323         // actually delete the page from the list
   306         /* Adjust m_currentPage if the index of the page deleted is less than 
   324         d->m_allPages.removeAt(closeIndex);
   307          * current page 
   325 
   308          */
   326         // update the current page index if necessary
   309        if (closeIndex < d->m_currentPage ) 
   327         // (this will just update the index now that we've removed the page from the list)
   310            updateCurrentPageIndex = true;
   328         if(updateCurrentPageIndex) {
   311     }
   329             int index = d->m_allPages.indexOf(theCurrentPage);
   312 
   330             if(index >= 0)
   313     // actually delete the page from the list
   331                 d->m_currentPage = index;
   314     d->m_allPages.removeAt(closeIndex);
   332         }
   315 
   333 
   316     // update the current page index if necessary
   334         // and emit sig that it was done
   317     // (this will just update the index now that we've removed the page from the list)
   335         emit pageDeleted(page);
   318     if(updateCurrentPageIndex) {
   336 
   319         int index = d->m_allPages.indexOf(theCurrentPage);
   337         delete page;
   320         if(index >= 0)
   338     }
   321             d->m_currentPage = index;
       
   322     }
       
   323 
       
   324     // and emit sig that it was done
       
   325     emit pageDeleted(page);
       
   326 
       
   327     delete page;
       
   328 }
   339 }
   329 
   340 
   330 /*!
   341 /*!
   331  *  Activate the given page as the current page
   342  *  Activate the given page as the current page
   332  *  @param page   page handle for setting current page
   343  *  @param page   page handle for setting current page
   356         disconnect(oldPage, 0, this, 0);
   367         disconnect(oldPage, 0, this, 0);
   357         disconnect(oldPage->mainFrame(), 0, this, 0);
   368         disconnect(oldPage->mainFrame(), 0, this, 0);
   358         disconnect(oldPage->networkAccessManager(), 0, this, 0);
   369         disconnect(oldPage->networkAccessManager(), 0, this, 0);
   359         disconnect(oldPage->loadController(), 0, this, 0);
   370         disconnect(oldPage->loadController(), 0, this, 0);
   360         connect(oldPage, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*)));
   371         connect(oldPage, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*)));
   361 
   372         connect(oldPage, SIGNAL(loadFinished(bool)), SLOT(onLoadFinishedForBackgroundWindow(bool)));
   362     }
   373     }
   363     // aggregate "current page" signalling from this page to PageMgr clients
   374     // aggregate "current page" signalling from this page to PageMgr clients
   364     connect(page, SIGNAL(secureStateChange(int)), this, SLOT(secureStateChange(int)));
   375     connect(page, SIGNAL(secureStateChange(int)), this, SLOT(secureStateChange(int)));
   365     connect( page->mainFrame(), SIGNAL ( titleChanged ( const QString& ) ), SIGNAL ( titleChanged ( const QString& ) ) );
   376     connect( page->mainFrame(), SIGNAL ( titleChanged ( const QString& ) ), SIGNAL ( titleChanged ( const QString& ) ) );
   366     connect( page, SIGNAL( loadStarted() ), SIGNAL( loadStarted() ) );
   377     connect( page, SIGNAL( loadStarted() ), SIGNAL( loadStarted() ) );
   367     connect( page->mainFrame(), SIGNAL(initialLayoutCompleted() ), SIGNAL( initialLayoutCompleted() ) );
   378     connect( page->mainFrame(), SIGNAL(initialLayoutCompleted() ), SIGNAL( initialLayoutCompleted() ) );
   368     connect( page, SIGNAL( loadProgress(int) ), SIGNAL( loadProgress(int) ) );
   379     connect( page, SIGNAL( loadProgress(int) ), SIGNAL( loadProgress(int) ) );
   369     connect( page, SIGNAL( loadFinished(bool) ), SLOT( onLoadFinished(bool) ) );
   380     connect( page, SIGNAL( loadFinished(bool) ), SLOT( onLoadFinished(bool) ) );
       
   381     
       
   382     connect( page, SIGNAL( databaseQuotaExceeded (QWebFrame *,QString) ), SLOT( onDatabaseQuotaExceeded (QWebFrame *,QString)) );  
       
   383     
   370     connect( page->mainFrame(), SIGNAL( iconChanged() ), SIGNAL( pageIconChanged() ) );
   384     connect( page->mainFrame(), SIGNAL( iconChanged() ), SIGNAL( pageIconChanged() ) );
   371     connect( page->loadController(), SIGNAL( pageLoadStarted() ), SIGNAL( pageLoadStarted() ) );
   385     connect( page->loadController(), SIGNAL( pageLoadStarted() ), SIGNAL( pageLoadStarted() ) );
   372     connect( page->loadController(), SIGNAL( pageLoadFailed() ), SIGNAL( pageLoadFailed() ) );
   386     connect( page->loadController(), SIGNAL( pageLoadFailed() ), SIGNAL( pageLoadFailed() ) );
   373     connect( page->loadController(), SIGNAL( pageLoadProgress(int) ), SIGNAL( pageLoadProgress(int) ) );
   387     connect( page->loadController(), SIGNAL( pageLoadProgress(int) ), SIGNAL( pageLoadProgress(int) ) );
   374     connect( page->loadController(), SIGNAL( pageLoadFinished(bool) ), SIGNAL( pageLoadFinished(bool) ) );
   388     connect( page->loadController(), SIGNAL( pageLoadFinished(bool) ), SIGNAL( pageLoadFinished(bool) ) );
   412         QTimer::singleShot(300, this, SLOT(updateHistory()));
   426         QTimer::singleShot(300, this, SLOT(updateHistory()));
   413     }
   427     }
   414     else {
   428     else {
   415         emit(loadFinished(false));
   429         emit(loadFinished(false));
   416     }
   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);
   417 }
   462 }
   418 
   463 
   419 void WebPageController::updateHistory()
   464 void WebPageController::updateHistory()
   420 {
   465 {
   421     BookmarksManager::getSingleton()->addHistory(currentDocUrl(), currentDocTitle());
   466     BookmarksManager::getSingleton()->addHistory(currentDocUrl(), currentDocTitle());
   439  * @see WRT::WrtBrowserContainer
   484  * @see WRT::WrtBrowserContainer
   440  */
   485  */
   441 void WebPageController::processNetworkErrorUrl(const QUrl & url )
   486 void WebPageController::processNetworkErrorUrl(const QUrl & url )
   442     {
   487     {
   443     QString errorUrl = url.toString();
   488     QString errorUrl = url.toString();
   444     QString currentUrl = currentDocUrl(); 
   489     QString requestedUrl = currentRequestedUrl(); 
   445     m_networkErrorUrl = url.toString(); 
   490     m_networkErrorUrl = url.toString(); 
   446 // TODO: may not necessary 
   491     
   447 // Here we should be able to do various handling of the error url, such 
   492     // Check if requestedUrl matches the URL from the network error
   448 // as comparing with QWebPage URL, ... etc 
   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;
   449     }
   497     }
   450 
   498 
   451 //void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();
   499 //void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();
   452 
   500 
   453 /*! 
   501 /*! 
   776  */
   824  */
   777 void WebPageController::updateStatePageLoading()
   825 void WebPageController::updateStatePageLoading()
   778 {
   826 {
   779     updateActions(true);
   827     updateActions(true);
   780     
   828     
       
   829     // Reset to false for new page
       
   830     m_bErrorUrlMatches = false;
       
   831     
   781     // 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)
   782     currentPage()->loadController()->setUrlText(currentPage()->history()->currentItem().url().toString());
   833     currentPage()->loadController()->setUrlText(currentPage()->history()->currentItem().url().toString());
   783 }
   834 }
   784 
   835 
   785 /*!
   836 /*!
   795  */
   846  */
   796 void WebPageController::updateActions(bool pageIsLoading)
   847 void WebPageController::updateActions(bool pageIsLoading)
   797 {
   848 {
   798     d->m_actionReload->setEnabled(!pageIsLoading);
   849     d->m_actionReload->setEnabled(!pageIsLoading);
   799     d->m_actionStop->setEnabled(pageIsLoading);
   850     d->m_actionStop->setEnabled(pageIsLoading);
   800 
   851     
   801     WRT::WrtBrowserContainer* activePage = currentPage();    
   852     WRT::WrtBrowserContainer* activePage = currentPage();    
   802 
   853 
   803     if(activePage) {
   854     if(activePage) {
   804         int histLength = activePage->history()->count();
   855         int histLength = activePage->history()->count();
   805         int currItemIndex = activePage->history()->currentItemIndex();
   856         int currItemIndex = activePage->history()->currentItemIndex();
   889 	return suggestList;
   940 	return suggestList;
   890 }
   941 }
   891 
   942 
   892 void WebPageController::loadLocalFile()
   943 void WebPageController::loadLocalFile()
   893 	{
   944 	{
   894     QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory");
   945     QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("LocalPagesBaseDirectory");
   895     QString startPage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage");
   946     QString startPage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage");
   896     QString startPagePath = chromeBaseDir + startPage;
   947     QString startPagePath = chromeBaseDir + startPage;
       
   948 
   897     currentLoad(startPagePath);
   949     currentLoad(startPagePath);
   898 	}
   950 	}
   899 
   951 
   900 void WebPageController::loadInitialUrlFromOtherApp(QString url)
   952 void WebPageController::loadInitialUrlFromOtherApp(QString url)
   901 {
   953 {
  1269             ActionJSObject *jso = new ActionJSObject(d->m_actionsParent, action);
  1321             ActionJSObject *jso = new ActionJSObject(d->m_actionsParent, action);
  1270         }
  1322         }
  1271     }
  1323     }
  1272 }
  1324 }
  1273 
  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 
  1274 void WebPageController::clearHistoryInMemory()
  1357 void WebPageController::clearHistoryInMemory()
  1275 {
  1358 {
  1276     WRT::WrtBrowserContainer * activePage = currentPage();
  1359     WRT::WrtBrowserContainer * activePage = currentPage();
  1277     if(activePage)
  1360     if(activePage)
  1278     {
  1361     {
  1322     }
  1405     }
  1323 }
  1406 }
  1324 
  1407 
  1325 void WebPageController::deleteCache()
  1408 void WebPageController::deleteCache()
  1326 {
  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     
  1327 	  if ( !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheEnabled").toBool() ) 
  1434 	  if ( !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheEnabled").toBool() ) 
  1328 			return;
  1435 			return;
  1329 		
  1436 		
  1330 		QString diskCacheDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheDirectoryPath").toString();
  1437 		QString diskCacheDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheDirectoryPath").toString();
  1331 			
  1438 			
  1375     }
  1482     }
  1376     
  1483     
  1377     
  1484     
  1378 }
  1485 }
  1379 
  1486 
  1380 
       
  1381 void WebPageController::urlChanged(const QUrl& url)
  1487 void WebPageController::urlChanged(const QUrl& url)
  1382 {
  1488 {
  1383     //private slot
  1489     //private slot
  1384     QString urlString = partialUrl(url);
  1490     QString urlString = partialUrl(url);
  1385     emit partialUrlChanged(urlString);    
  1491     emit partialUrlChanged(urlString);    
  1386 }
  1492 }
  1387 
       
  1388 
  1493 
  1389 QString WebPageController::partialUrl(const QUrl& url)
  1494 QString WebPageController::partialUrl(const QUrl& url)
  1390 {
  1495 {
  1391 
  1496 
  1392     QString urlString = url.toString();
  1497     QString urlString = url.toString();
  1418     QSize currSize = view->size().toSize();
  1523     QSize currSize = view->size().toSize();
  1419 
  1524 
  1420     bool needRestore =  false;
  1525     bool needRestore =  false;
  1421 
  1526 
  1422     for (int i = 0; i < allPages()->count(); i++) {
  1527     for (int i = 0; i < allPages()->count(); i++) {
  1423          WRT::WrtBrowserContainer* page = allPages()->at(i);
  1528         WRT::WrtBrowserContainer* page = allPages()->at(i);
  1424          QWebHistoryItem item = page->history()->currentItem();
  1529         QWebHistoryItem item = page->history()->currentItem();
  1425 
  1530         WebPageData data = item.userData().value<WebPageData>();
  1426          WebPageData data = item.userData().value<WebPageData>();
       
  1427 
  1531 
  1428         // 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
  1429         if (!page->emptyWindow() ){
  1533         if (!page->emptyWindow() ){
  1430             QImage img = data.m_thumbnail;
  1534             QImage img = data.m_thumbnail;
  1431     
  1535             bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) );
  1432              bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) );
  1536             if (img.isNull() || !isSameMode) {
  1433              if (img.isNull() || !isSameMode) {
  1537                 needRestore = true;
  1434          
  1538                 view->setPage(page);
  1435                  qDebug() << "need new thumbnail!!!" << img.size() << ":" << currSize;
  1539                 page->setWebWidget(view);
  1436                  needRestore = true;
  1540                 QCoreApplication::sendEvent(view, new WebPageControllerUpdateViewPortEvent());
  1437                  view->setPage(page);
  1541                 page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1438                  page->setWebWidget(view);
  1542                 page->setUpdateThumbnail(false);
  1439                  QCoreApplication::sendEvent(view, new WebPageControllerUpdateViewPortEvent());
  1543             }
  1440                  page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1544             if (page->needUpdateThumbnail()) {
  1441              }
  1545                 page->savePageDataToHistoryItem(page->mainFrame(), &item);
       
  1546                 page->setUpdateThumbnail(false);
       
  1547             }
  1442          }
  1548          }
  1443     }
  1549     }
  1444 
  1550 
  1445     // restore
  1551     // restore
  1446     if (needRestore)
  1552     if (needRestore) {    
  1447     {    
       
  1448         view->setPage(savedPage);
  1553         view->setPage(savedPage);
  1449         savedPage->setWebWidget(view);
  1554         savedPage->setWebWidget(view);
  1450     }
  1555     }
  1451 }
  1556 }
  1452 
  1557 
  1453 void WebPageController::updatePageThumbnails()
  1558 void WebPageController::updatePageThumbnails()
  1454 {
  1559 {
  1455     // update current page's thumbnail forcely
  1560     // update current page's thumbnail forcely since the scrolling position may change
  1456     WRT::WrtBrowserContainer *page = currentPage();
  1561     WRT::WrtBrowserContainer *page = currentPage();
  1457     QWebHistoryItem item = page->history()->currentItem();
  1562     QWebHistoryItem item = page->history()->currentItem();
  1458 
       
  1459     page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1563     page->savePageDataToHistoryItem(page->mainFrame(), &item);
  1460 
  1564     page->setUpdateThumbnail(false);
  1461     WebPageData data = item.userData().value<WebPageData>();
       
  1462 
       
  1463     checkAndUpdatePageThumbnails();
  1565     checkAndUpdatePageThumbnails();
  1464 }
  1566 }
  1465 
  1567 
  1466 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s)
  1568 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s)
  1467 {
  1569 {
  1519 
  1621 
  1520 QString WebPageController::networkErrorUrl() {
  1622 QString WebPageController::networkErrorUrl() {
  1521     return m_networkErrorUrl; 
  1623     return m_networkErrorUrl; 
  1522 }
  1624 }
  1523 
  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 
  1524 /*!
  1638 /*!
  1525   \fn void WebPageController::pageCreated(WrtPage* newPage);
  1639   \fn void WebPageController::pageCreated(WrtPage* newPage);
  1526   emitted when a page is created
  1640   emitted when a page is created
  1527 */
  1641 */
  1528 
  1642