browsercore/core/wrtbrowsercontainer.cpp
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
--- a/browsercore/core/wrtbrowsercontainer.cpp	Fri May 14 15:40:36 2010 +0300
+++ b/browsercore/core/wrtbrowsercontainer.cpp	Wed Jun 23 17:59:43 2010 +0300
@@ -1,36 +1,31 @@
 /*
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
+* 
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License for more details.
 *
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program.  If not, 
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
 *
-* Description: 
+* Description:
 *
 */
 
-
 #include "browserpagefactory.h"
-#include "webcontentview.h"
-#include "wrtpage.h"
 #include "wrtbrowsercontainer_p.h"
 #include "wrtbrowsercontainer.h"
 #include "webpagedata.h"
-#include "qwebhistory.h"
-#include "qwebframe.h"
 #include "SchemeHandlerBr.h"
 #include "webnetworkaccessmanager.h"
-#ifdef QT_MOBILITY_BEARER_MANAGEMENT
-#include "WebNetworkConnectionManager.h"
-#endif // QT_MOBILITY_BEARER_MANAGEMENT
 #include "webcookiejar.h"
-#include "webnavigation.h"
 #include "secureuicontroller.h"
 #include "LoadController.h"
 #include "WebDialogProvider.h"
@@ -39,18 +34,32 @@
 #include <QAuthenticator>
 #include <QFile>
 #include <QMessageBox>
+#include <QWebHistory>
+#include <QWebFrame>
+#include <QGraphicsWebView>
+
+QDataStream &operator<<(QDataStream &out, const WebPageData &myObj)
+{
+   out << myObj.m_thumbnail << myObj.m_zoomFactor << myObj.m_contentsPos;
+   return out;
+}
+
+QDataStream &operator>>(QDataStream &in, WebPageData &myObj)
+{
+   in >> myObj.m_thumbnail >> myObj.m_zoomFactor >> myObj.m_contentsPos;
+   return in;
+}
 
 namespace WRT
 {
-
-const int historyItemsCount = 20;
+const int historyItemsCount = 10;
 
 WrtBrowserContainerPrivate::WrtBrowserContainerPrivate(QObject* parent,
 		WrtBrowserContainer* page/*never NULL*/) : m_schemeHandler(new SchemeHandler())
 ,   m_pageFactory(0)
 ,   m_widget(0)
+,   m_fileChooser(0)
 {
-    assert(page);
     m_page = page;
 
     m_secureController = new WRT::SecureUIController(parent);
@@ -70,6 +79,7 @@
 	delete m_schemeHandler;
   delete m_secureController;
   delete m_loadController;
+  delete m_fileChooser;
 }
 
 /*!
@@ -90,19 +100,15 @@
 }
 
 /*!
- * \class WrtBrowserContainer
- * \brief Description: This class is a handle to open page on which user can
- * load an url , view history items, load an history item into the page etc.
- * @see WrtPageManager
- */
-
-/*!
  * WrtBrowserContainer Constructor
  * @param parent : Widget parent
  */
 WrtBrowserContainer::WrtBrowserContainer(QObject* parent) :
-	WrtPage(parent), d(new WrtBrowserContainerPrivate(this, this))
+	QWebPage(parent), d(new WrtBrowserContainerPrivate(this, this))
 {
+    
+  settings()->setAttribute(QWebSettings::PluginsEnabled, true);
+  settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("PopupBlocking").toInt());
 	// Download related enable "forwardUnsupportedContent" to redirect unsupported content to download manager
 	setForwardUnsupportedContent(true);
 
@@ -110,15 +116,8 @@
 	setNetworkAccessManager(new WebNetworkAccessManager(this,this));
 #endif
 	
-#ifdef QT_MOBILITY_BEARER_MANAGEMENT
-	setNetworkConnectionManager(new WebNetworkConnectionManager(this));
-#endif // QT_MOBILITY_BEARER_MANAGEMENT
 	history()->setMaximumItemCount(historyItemsCount);
 
-	connect(this,
-			SIGNAL(saveFrameStateRequested(QWebFrame*, QWebHistoryItem*)),
-			this, SLOT(savePageDataToHistoryItem(QWebFrame*, QWebHistoryItem*)));
-
     /* Connect secure related signals and slots */
     connect(mainFrame(), SIGNAL(urlChanged(QUrl)), d->m_secureController, SLOT(setTopLevelScheme(const QUrl &)));
     connect(this, SIGNAL(loadFinished(bool)), d->m_secureController, SLOT( endSecureCheck(bool) ) );
@@ -130,9 +129,6 @@
     connect(this, SIGNAL(loadFinished(bool)), d->m_loadController, SLOT(loadFinished(bool)));
     connect(mainFrame(), SIGNAL(urlChanged(QUrl)), d->m_loadController, SLOT(urlChanged(QUrl)));
     
-	// All pages in the browser share the same pageGroup.
-	d->m_pageGroupName = "nokia_page_group";
-	setPageGroupName(d->m_pageGroupName);
 }
 
 /*!
@@ -146,6 +142,19 @@
 
     //setNetworkAccessManager(NULL);
    delete d;
+   
+   // 
+   QList<QWebHistoryItem> items = history()->items();
+
+   for (int i = 0; i < history()->count(); i++) {
+       QWebHistoryItem item = items.at(i);
+       WebPageData* data = (WebPageData*)(item.userData().value<void*>());
+       if(data){
+           QVariant variant;
+           item.setUserData(variant);
+           delete data;
+       }
+   }
 }
 
 QGraphicsWidget* WrtBrowserContainer::webWidget() const
@@ -155,10 +164,6 @@
 
 void WrtBrowserContainer::setWebWidget(QGraphicsWidget* view)
 {
-    if(d->m_widget) {
-        disconnect(static_cast<WebContentWidget*>(webWidget()), SIGNAL(pageZoomMetaDataChange(QWebFrame*, ZoomMetaData)), this, SLOT(pageZoomMetaDataChange(QWebFrame*, ZoomMetaData)));
-    }
-
     d->m_widget = view;
 
     if (view)
@@ -167,11 +172,6 @@
         if(webView)
             webView->setPage(this);
 
-        /* Currently connecting it here. Need to revisit if the dialog is enabled in the
-         * context of multiple windows */
-        connect( d->m_secureController, SIGNAL( showMessageBox(WRT::MessageBoxProxy*)), static_cast<WebContentWidget*>(webWidget())->view(), SLOT( showMessageBox(WRT::MessageBoxProxy*)));
-
-        connect(static_cast<WebContentWidget*>(webWidget()), SIGNAL(pageZoomMetaDataChange(QWebFrame*, ZoomMetaData)), this, SLOT(pageZoomMetaDataChange(QWebFrame*, ZoomMetaData)));
     }
 }
  
@@ -193,48 +193,6 @@
 }
 
 /*!
- * Gets the history count for this page, i.e gets the number of urls loaded
- * onto this page
- * @return  History count of this page
- */
-int WrtBrowserContainer::getHistoryCount() const
-{
-	return history()->count();
-}
-
-/*!
- * Triggers public Action
- * @param WebAction : web action to be triggred
- * @param checked  : true/false
- * @see   WebAction
- */
-/*void WrtBrowserContainer::triggerAction(QWebPage::WebAction action, bool checked)
- {
- triggerAction(action, checked);
- }
- */
-
-/*!
- * clears cookies
- */
-void WrtBrowserContainer::clearCookies()
-{
-	return ((CookieJar*) networkAccessManager()->cookieJar())->clear();
-}
-
-bool WrtBrowserContainer::clearNetworkCache()
-{
-   bool ok = false;
-    QAbstractNetworkCache* diskCache = networkAccessManager()->cache();
-    diskCache->clear();
-    if (!diskCache->cacheSize()) { 
-       // Unless there was failures clearing the cache cacheSize() should return 0 after a call to clear 
-       ok = true;
-   }
-   return ok;
-}
-
-/*!
  * This function page thumbnail for this page as specified by X & Y co-ordinate scale factors
  * @param  scaleX :  X Co-ordinate scale factor for the page thumbnail
  * @param  scaleY :  y Co-ordinate scale factor for the page thumbnail
@@ -253,97 +211,11 @@
     painter.drawRect(r);
     painter.restore();
     mainFrame()->render(&painter, clip);
-    return image;
-}
-
-/*!
- * sets the page zoom factor as specified by zoom
- * @param zoom : page zoom factor to be set
- */
-void WrtBrowserContainer::setPageZoomFactor(qreal zoom)
-{
-   // FiX ME ... canvas zoom doesn't seem to support text-only zooming.
-   //static_cast<WebCanvasWidget*>(webWidget())->canvas()->setPageZoomFactor(zoom);
-
-	bool isZoomTextOnly = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value(
-			"ZoomTextOnly").toBool();
-
-	if (!isZoomTextOnly)
-	{
-		// mainFrame()->setZoomFactor(zoom);
-		static_cast<WebContentWidget*> (webWidget())->setZoomFactor(zoom);
-	}
-	else
-	{
-		//mainFrame()->setTextSizeMultiplier(zoom);
-		static_cast<WebContentWidget*> (webWidget())->setTextSizeMultiplier(
-				zoom);
-    }
-}
-
-/*!
- * setpageDirtyZoomFactor
- * @param zoom: page zoom factor to be set
- */
-void WrtBrowserContainer::setPageDirtyZoomFactor(qreal zoom)
-{
-   // FIXME: dirty page zoom is not supported yet in single-buffer mode.
-   static_cast<WebContentWidget*> (webWidget())->setDirtyZoomFactor(zoom);
+    QImage thumbnail = image.scaled(scaleX * size.width(), scaleY * size.height());
+    return thumbnail;
 }
 
 /*!
- * setpageCenterZoomFactor
- * @param zoom: center page zoom factor to be set
- */
-// TODO: hold on this change until zoom/scrolling improvement 
-/*
- void WrtBrowserContainer::setPageCenterZoomFactor(qreal zoom)
- {
- static_cast<WebCanvasWidget*>(webWidget())->canvas()->setPageCenterZoomFactor(zoom);
- }
- */
-/*!
- * returns the current page zoom factor of this page
- * @return current zoom factor
- */
-qreal WrtBrowserContainer::pageZoomFactor() const
-{
-   return static_cast<WebContentWidget*> (webWidget())->zoomFactor();
-}
-
-/*!
- * sets the Canvas ScaleFactor  for this page
- * @param  scaleX :  X Co-ordinate scale factor
- * @param  scaleY :  Y Co-ordinate scale factor
- */
-void WrtBrowserContainer::setCanvasScaleFactor(qreal scaleX, qreal scaleY)
-{
-   QTransform transform;
-   transform.scale(scaleX, scaleY);
-   //     static_cast<ContentView*>(webWidget())->setTransform(transform);
-}
-
-/*!
- * allows offlineStorage for url
- * @param url : url for which offlinestorage has to be enabled
- */
-bool WrtBrowserContainer::allowOfflineStorage(const QUrl& url)
-{
-   if (BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("SecurityLevel").toInt()
-         != SecurityHigh)
-      return true;
-
-	QStringList yesno;
-	yesno << "Yes" << "No";
-	return (WebDialogProvider::getButtonResponse(
-			0, /* webWidget(), Check, that widget is required */
-			QString(
-					"Offline Database: This host asking for storing data in offline database, allow?"),
-			yesno));
-}
-
-
-/*!
  Pulic Slots:
  void savePageDataToHistoryItem(QWebFrame*, QWebHistoryItem* item);
  void slotAuthenticationRequired(QNetworkReply *, QAuthenticator *);
@@ -367,8 +239,8 @@
     	
     WebPageData data(this);
     //   WebPageData data = item->userData().value<WebPageData>();
-    data.m_zoomFactor = pageZoomFactor();
-    data.m_thumbnail = pageThumbnail(1.0, 1.0);//data.m_zoomFactor, data.m_zoomFactor);
+    data.m_zoomFactor = 1.0; // Need to find a way to get this.  Not used right now anyway
+    data.m_thumbnail = pageThumbnail(0.5, 0.5);//data.m_zoomFactor, data.m_zoomFactor);
 
     QPoint pos(0, 0);
     //    pos = static_cast<WebCanvasWidget*>(webWidget())->canvas()->canvasToDocument(pos);
@@ -413,39 +285,11 @@
     }
 }
 
-QWebPage* WrtBrowserContainer::createWindow(
-    QWebPage::WebWindowType webWindowType)
-{
-
-    /* When WrtPage is created, QWebSettings::JavascriptCanOpenWindows is initialized
-     * to popup setting value. Need not do any check here 
-     */
-    if (d->m_pageFactory)
-    {
-        // no need to signal in this case
-        return d->m_pageFactory->openPage();
-    }
-
-    WrtBrowserContainer* wrtPage = new WrtBrowserContainer();
-    emit createNewWindow(wrtPage);
-    return wrtPage;
-}
-
 void WrtBrowserContainer::setPageFactory(BrowserPageFactory* f)
 {
     d->m_pageFactory = f;
 }
 
-void WrtBrowserContainer::setElementType(
-      wrtBrowserDefs::BrowserElementType& aElType)
-{
-    m_elementType = aElType;
-}
-wrtBrowserDefs::BrowserElementType WrtBrowserContainer::getElementType()
-{
-   return m_elementType;
-}
-
 QString WrtBrowserContainer::pageTitle(){
 
     QString title = mainFrame()->title();
@@ -495,14 +339,6 @@
     return result;
 }
 
-void WrtBrowserContainer::pageZoomMetaDataChange(QWebFrame* frame,  ZoomMetaData  zoomData ){
-
-    //qDebug() << __func__ << "Frame " << frame << "My Frame " << mainFrame();
-    if (frame == mainFrame()) {
-        setPageZoomMetaData(zoomData);
-    } 
-}
-
 ZoomMetaData WrtBrowserContainer::pageZoomMetaData() {
     return d->m_zoomData ;
 
@@ -513,6 +349,45 @@
 }
 
 
+WrtBrowserFileChooser::~WrtBrowserFileChooser()
+{}
+
+void WrtBrowserContainer::setFileChooser(WrtBrowserFileChooser * chooser)
+{
+    if (d->m_fileChooser) {
+        delete d->m_fileChooser;
+    }
+
+    d->m_fileChooser = chooser;
+}
+
+QString WrtBrowserContainer::chooseFile(QWebFrame * parentFrame, const QString & suggestedFile)
+{
+    if (d->m_fileChooser != 0) {
+        return d->m_fileChooser->chooseFile(parentFrame, suggestedFile);
+    }
+
+    return QWebPage::chooseFile(parentFrame, suggestedFile);
+}
+
+WRT::WrtBrowserContainer* WrtBrowserContainer::createWindow(
+    QWebPage::WebWindowType webWindowType)
+{
+
+    /* When WrtPage is created, QWebSettings::JavascriptCanOpenWindows is initialized
+     * to popup setting value. Need not do any check here 
+     */
+    if (d->m_pageFactory)
+    {
+        // no need to signal in this case
+        return d->m_pageFactory->openPage();
+    }
+
+    WrtBrowserContainer* wrtPage = new WrtBrowserContainer();
+    emit createNewWindow(wrtPage);
+    return wrtPage;
 }
 
 
+} // namespace WRT
+