1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "wrtpage.h" |
|
20 #include "qwebhistory.h" |
|
21 #include "webpagedata.h" |
|
22 //#include "wrtsettings.h" |
|
23 #include "bedrockprovisioning.h" |
|
24 #ifdef QT_MOBILITY_BEARER_MANAGEMENT |
|
25 #include "WebNetworkConnectionManager.h" |
|
26 #endif // QT_MOBILITY_BEARER_MANAGEMENT |
|
27 |
|
28 #include <QMessageBox> |
|
29 #include <QFile> |
|
30 #include <QTextStream> |
|
31 #include <QDesktopServices> |
|
32 #include <QDir> |
|
33 |
|
34 void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName); |
|
35 void QWEBKIT_EXPORT qt_websettings_setOfflineWebApplicationCachePath(const QString& path); |
|
36 |
|
37 QDataStream &operator<<(QDataStream &out, const WebPageData &myObj) |
|
38 { |
|
39 out << myObj.m_thumbnail << myObj.m_zoomFactor << myObj.m_contentsPos; |
|
40 return out; |
|
41 } |
|
42 |
|
43 QDataStream &operator>>(QDataStream &in, WebPageData &myObj) |
|
44 { |
|
45 in >> myObj.m_thumbnail >> myObj.m_zoomFactor >> myObj.m_contentsPos; |
|
46 return in; |
|
47 } |
|
48 |
|
49 namespace WRT { |
|
50 |
|
51 WrtPage::WrtPage(QObject *parent) : QWebPage(parent) |
|
52 { |
|
53 settings()->setAttribute(QWebSettings::PluginsEnabled, true); |
|
54 settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("PopupBlocking").toInt()); |
|
55 |
|
56 // Initialization below can only be done once per Webkit instance (and not once per page) |
|
57 // otherwise it hits an ASSERT in WebKit in debug mode |
|
58 static bool initialized = false; |
|
59 |
|
60 if (!initialized) { |
|
61 QString storagePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); |
|
62 |
|
63 QWebSettings::setOfflineStoragePath(QDir::toNativeSeparators(QDir(storagePath).filePath("WebDatabase"))); |
|
64 #if defined CWRTINTERNALWEBKIT |
|
65 qt_websettings_setOfflineWebApplicationCachePath(QDir::toNativeSeparators(QDir(storagePath).filePath("ApplicationCache"))); |
|
66 #endif |
|
67 initialized = true; |
|
68 } |
|
69 |
|
70 #ifdef QT_MOBILITY_BEARER_MANAGEMENT |
|
71 m_ConnectionManager = 0; |
|
72 #endif // QT_MOBILITY_BEARER_MANAGEMENT |
|
73 } |
|
74 |
|
75 WrtPage::~WrtPage() |
|
76 { |
|
77 QList<QWebHistoryItem> items = history()->items(); |
|
78 |
|
79 for (int i = 0; i < history()->count(); i++) { |
|
80 QWebHistoryItem item = items.at(i); |
|
81 WebPageData* data = (WebPageData*)(item.userData().value<void*>()); |
|
82 if(data){ |
|
83 QVariant variant; |
|
84 item.setUserData(variant); |
|
85 delete data; |
|
86 } |
|
87 } |
|
88 #ifdef QT_MOBILITY_BEARER_MANAGEMENT |
|
89 if (m_ConnectionManager) |
|
90 delete m_ConnectionManager; |
|
91 #endif // QT_MOBILITY_BEARER_MANAGEMENT |
|
92 } |
|
93 |
|
94 void WrtPage::setPageGroupName(const QString& groupName) |
|
95 { |
|
96 qt_webpage_setGroupName(this, groupName); |
|
97 } |
|
98 |
|
99 QWebPage* WrtPage::createWindow(QWebPage::WebWindowType webWindowType) |
|
100 { |
|
101 WrtPage* wrtPage = new WrtPage(); |
|
102 emit createWindow(wrtPage); |
|
103 return wrtPage; |
|
104 } |
|
105 |
|
106 |
|
107 /*! |
|
108 // implementation of javaScriptConsoleMessage defined in WebKit qwebpage.h |
|
109 // User settings are provided through WrtSettingsUI. |
|
110 // The following choices are offered: |
|
111 // Logging Off;Log to file;Show pop-up notes;Log to file and show pop-up notes |
|
112 */ |
|
113 void WrtPage::javaScriptConsoleMessage(const QString& messageSource, const QString& messageLevel, const QString& message, int lineNumber, const QString& sourceID) |
|
114 { |
|
115 |
|
116 int jsSetting = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value ( "JavaScriptConsoleLog" ).toInt(); |
|
117 QString logFileName = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value ( "JavaScriptConsoleLogFilePath" ).toString(); |
|
118 QString msg = ( "JS Console Log: "+ ( QDate::currentDate() ).toString ( "dd.MM.yyyy" ) +" "+ ( QTime::currentTime() ).toString ( "hh:mm:ss ap" ) +"\nMessage src: "+messageSource+" : "+messageLevel+"\nMessage: " + message + "\nSource: "+sourceID+" : "+QString::number(lineNumber) ); |
|
119 |
|
120 if ( jsSetting == 2 || jsSetting == 3 ){ |
|
121 //display this simple dialog box for now. |
|
122 QMessageBox::about(view(), "JavaScript Console", msg); |
|
123 } |
|
124 if ( jsSetting == 1 || jsSetting == 3 ){ |
|
125 // message is logged to file |
|
126 QFile jsFile ( logFileName ); |
|
127 if ( !jsFile.open ( QIODevice::Append ) ) return; |
|
128 |
|
129 QTextStream jsLog ( &jsFile ); |
|
130 jsLog << msg << "\n"; |
|
131 jsFile.close(); |
|
132 } |
|
133 // Emit message in case some view manager wants to implement a better GUI to display console messages |
|
134 emit jsConsoleMessage(messageSource, messageLevel, message, lineNumber, sourceID); |
|
135 |
|
136 } |
|
137 |
|
138 #ifdef QT_MOBILITY_BEARER_MANAGEMENT |
|
139 void WrtPage::setNetworkConnectionManager(WebNetworkConnectionManager *manager) |
|
140 { |
|
141 if (manager == m_ConnectionManager) |
|
142 return; |
|
143 if (m_ConnectionManager && m_ConnectionManager->parent() == this) |
|
144 delete m_ConnectionManager; |
|
145 m_ConnectionManager = manager; |
|
146 } |
|
147 #endif // QT_MOBILITY_BEARER_MANAGEMENT |
|
148 } // end of namespace WRT |
|
149 |
|