36 #include <QMessageBox> |
36 #include <QMessageBox> |
37 #include <QWebHistory> |
37 #include <QWebHistory> |
38 #include <QWebFrame> |
38 #include <QWebFrame> |
39 #include <QGraphicsWebView> |
39 #include <QGraphicsWebView> |
40 |
40 |
|
41 #ifdef QT_GEOLOCATION |
|
42 #include "geolocationManager.h" |
|
43 |
|
44 /* Declare the user defined meta type for use with QVariant in geolocation. */ |
|
45 Q_DECLARE_METATYPE(QWebPage::PermissionPolicy); |
|
46 #endif // QT_GEOLOCATION |
|
47 |
41 QDataStream &operator<<(QDataStream &out, const WebPageData &myObj) |
48 QDataStream &operator<<(QDataStream &out, const WebPageData &myObj) |
42 { |
49 { |
43 out << myObj.m_thumbnail << myObj.m_zoomFactor << myObj.m_contentsPos; |
50 out << myObj.magic |
|
51 << myObj.minScale |
|
52 << myObj.maxScale |
|
53 << myObj.userScalable |
|
54 << myObj.initialScale |
|
55 << myObj.rect |
|
56 << myObj.webViewRect |
|
57 << myObj.scale |
|
58 << myObj.viewportSize |
|
59 << myObj.specifiedWidth |
|
60 << myObj.specifiedHeight |
|
61 << myObj.fitToScreen; |
44 return out; |
62 return out; |
45 } |
63 } |
46 |
64 |
47 QDataStream &operator>>(QDataStream &in, WebPageData &myObj) |
65 QDataStream &operator>>(QDataStream &in, WebPageData &myObj) |
48 { |
66 { |
49 in >> myObj.m_thumbnail >> myObj.m_zoomFactor >> myObj.m_contentsPos; |
67 in >> myObj.magic |
|
68 >> myObj.minScale |
|
69 >> myObj.maxScale |
|
70 >> myObj.userScalable |
|
71 >> myObj.initialScale |
|
72 >> myObj.rect |
|
73 >> myObj.webViewRect |
|
74 >> myObj.scale |
|
75 >> myObj.viewportSize |
|
76 >> myObj.specifiedWidth |
|
77 >> myObj.specifiedHeight |
|
78 >> myObj.fitToScreen; |
50 return in; |
79 return in; |
51 } |
80 } |
52 |
81 |
53 namespace WRT |
82 namespace WRT |
54 { |
83 { |
107 WrtBrowserContainer::WrtBrowserContainer(QObject* parent) : |
136 WrtBrowserContainer::WrtBrowserContainer(QObject* parent) : |
108 QWebPage(parent), d(new WrtBrowserContainerPrivate(this, this)) |
137 QWebPage(parent), d(new WrtBrowserContainerPrivate(this, this)) |
109 { |
138 { |
110 |
139 |
111 settings()->setAttribute(QWebSettings::PluginsEnabled, true); |
140 settings()->setAttribute(QWebSettings::PluginsEnabled, true); |
112 settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("PopupBlocking").toInt()); |
141 BEDROCK_PROVISIONING::BedrockProvisioning * provisioning = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning(); |
113 // Download related enable "forwardUnsupportedContent" to redirect unsupported content to download manager |
142 settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !provisioning->value("PopupBlocking").toInt()); |
|
143 |
|
144 // Download related enable "forwardUnsupportedContent" to redirect unsupported content to download manager |
114 setForwardUnsupportedContent(true); |
145 setForwardUnsupportedContent(true); |
115 #ifdef BEDROCK_TILED_BACKING_STORE |
146 #ifdef BEDROCK_TILED_BACKING_STORE |
116 settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, true); |
147 #ifndef OWN_BACKING_STORE |
|
148 bool enableTiling = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("EnableTiling").toBool(); |
|
149 settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, enableTiling); |
|
150 #endif // OWN_BACKING_STORE |
117 settings()->setAttribute(QWebSettings::ZoomTextOnly, false); |
151 settings()->setAttribute(QWebSettings::ZoomTextOnly, false); |
118 settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, true); |
152 settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, true); |
119 |
153 |
120 //Configure tiling properties |
154 //Configure tiling properties |
121 //This would set tile size to (256, 256) and add 25ms delay between constructing |
155 //This would set tile size to (256, 256) and add 25ms delay between constructing |
122 //individual tiles. The settings would try to cache an area 1.5x width and 1.5x height |
156 //individual tiles. The settings would try to cache an area 1.5x width and 1.5x height |
123 //of the current viewport (centered to the viewport) with tiles and would drop tiles |
157 //of the current viewport (centered to the viewport) with tiles and would drop tiles |
124 //after they are outside an area 2x the width and 2.5x the height of the viewport. |
158 //after they are outside an area 2x the width and 2.5x the height of the viewport. |
125 //Refer https://bugs.webkit.org/show_bug.cgi?id=39874 |
159 //Refer https://bugs.webkit.org/show_bug.cgi?id=39874 |
126 |
160 |
127 setProperty("_q_TiledBackingStoreTileSize", QSize(256, 256)); |
161 BEDROCK_PROVISIONING::BedrockProvisioning* brSettings = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning(); |
128 setProperty("_q_TiledBackingStoreTileCreationDelay", 25); |
162 int tileW = brSettings->value("TilesWidth").toInt(); |
129 setProperty("_q_TiledBackingStoreCoverAreaMultiplier", QSizeF(1.5, 1.5)); |
163 int tileH = brSettings->value("TilesHeight").toInt(); |
130 setProperty("_q_TiledBackingStoreKeepAreaMultiplier", QSizeF(2., 2.5)); |
164 int tileCreationDelay = brSettings->value("TileCreationDelay").toInt(); |
|
165 qreal coverAreaMultiplier = brSettings->value("TileCoverAreaMultiplier").toDouble(); |
|
166 qreal keepAreaMultiplier = brSettings->value("TileKeepAreaMultiplier").toDouble(); |
|
167 setProperty("_q_TiledBackingStoreTileSize", QSize(tileW, tileH)); |
|
168 setProperty("_q_TiledBackingStoreTileCreationDelay", tileCreationDelay); |
|
169 setProperty("_q_TiledBackingStoreCoverAreaMultiplier", QSizeF(coverAreaMultiplier, coverAreaMultiplier)); |
|
170 setProperty("_q_TiledBackingStoreKeepAreaMultiplier", QSizeF(keepAreaMultiplier, keepAreaMultiplier)); |
131 #endif |
171 #endif |
132 |
172 |
133 #ifndef NO_NETWORK_ACCESS_MANAGER |
173 #ifndef NO_NETWORK_ACCESS_MANAGER |
134 setNetworkAccessManager(new WebNetworkAccessManager(this,this)); |
174 setNetworkAccessManager(new WebNetworkAccessManager(this,this)); |
135 #endif |
175 #endif |
144 |
184 |
145 connect(this, SIGNAL(loadStarted()), d->m_loadController, SLOT(loadStarted())); |
185 connect(this, SIGNAL(loadStarted()), d->m_loadController, SLOT(loadStarted())); |
146 connect(this, SIGNAL(loadProgress(int)), d->m_loadController, SLOT(loadProgress(int))); |
186 connect(this, SIGNAL(loadProgress(int)), d->m_loadController, SLOT(loadProgress(int))); |
147 connect(this, SIGNAL(loadFinished(bool)), d->m_loadController, SLOT(loadFinished(bool))); |
187 connect(this, SIGNAL(loadFinished(bool)), d->m_loadController, SLOT(loadFinished(bool))); |
148 connect(mainFrame(), SIGNAL(urlChanged(QUrl)), d->m_loadController, SLOT(urlChanged(QUrl))); |
188 connect(mainFrame(), SIGNAL(urlChanged(QUrl)), d->m_loadController, SLOT(urlChanged(QUrl))); |
149 connect(mainFrame(), SIGNAL(initialLayoutCompleted()), d->m_loadController, SLOT(initialLayoutCompleted())); |
189 connect(mainFrame(), SIGNAL(initialLayoutCompleted()), d->m_loadController, SLOT(initialLayoutCompleted())); |
150 |
190 |
|
191 #ifdef QT_GEOLOCATION |
|
192 d->m_geolocationManager = GeolocationManager::getSingleton(); |
|
193 |
|
194 /* Register user defined Meta Types used in geolocation API. */ |
|
195 qRegisterMetaType<QWebPage::PermissionPolicy>("QWebPage::PermissionPolicy"); |
|
196 /* Connect the geolocation permission signal to the geolocation handler. */ |
|
197 connect(this, SIGNAL(requestPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain)), |
|
198 this, SLOT(handleRequestPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain))); |
|
199 #endif // QT_GEOLOCATION |
151 } |
200 } |
152 |
201 |
153 /*! |
202 /*! |
154 * WrtBrowserContainer destructor |
203 * WrtBrowserContainer destructor |
155 */ |
204 */ |
210 { |
259 { |
211 return d->m_schemeHandler; |
260 return d->m_schemeHandler; |
212 } |
261 } |
213 |
262 |
214 /*! |
263 /*! |
215 * This function page thumbnail for this page as specified by X & Y co-ordinate scale factors |
264 * This function returns a thumbnail image for this page as specified by X & Y co-ordinate scale factors |
216 * @param scaleX : X Co-ordinate scale factor for the page thumbnail |
265 * @param scaleX : X Co-ordinate scale factor for the page thumbnail |
217 * @param scaleY : y Co-ordinate scale factor for the page thumbnail |
266 * @param scaleY : y Co-ordinate scale factor for the page thumbnail |
218 */ |
267 */ |
|
268 QImage WrtBrowserContainer::thumbnail(QSize s) |
|
269 { |
|
270 QImage image(s, QImage::Format_RGB32); |
|
271 qreal fitWidth = s.width(); |
|
272 QPoint renderPos(0, 0); |
|
273 WebPageData* d = pageZoomMetaData(); |
|
274 qreal scale = 1.0; |
|
275 if(d->isValid()) |
|
276 { |
|
277 fitWidth = d->rect.width(); |
|
278 if(fitWidth > d->webViewRect.width() * d->scale) |
|
279 fitWidth = d->webViewRect.width() * d->scale; |
|
280 renderPos = d->webViewRect.topLeft().toPoint(); |
|
281 scale = s.width() / (fitWidth / d->scale); |
|
282 } |
|
283 |
|
284 if (image.isNull()) { |
|
285 return QImage(); |
|
286 } |
|
287 QPainter painter(&image); |
|
288 QRect r(QPoint(0,0),s); |
|
289 QRegion clip(r); |
|
290 painter.setBrush(Qt::white); |
|
291 painter.fillRect(r,Qt::white); |
|
292 |
|
293 QTransform transform; |
|
294 transform.scale(scale,scale); |
|
295 renderPos /= scale; |
|
296 transform.translate(renderPos.x(),renderPos.y()); |
|
297 painter.setTransform(transform); |
|
298 |
|
299 mainFrame()->render(&painter); |
|
300 return image; |
|
301 } |
219 QImage WrtBrowserContainer::pageThumbnail(qreal scaleX, qreal scaleY) |
302 QImage WrtBrowserContainer::pageThumbnail(qreal scaleX, qreal scaleY) |
220 { |
303 { |
221 qDebug() << "WrtBrowserContainer::pageThumbnail:" << webWidget()->size(); |
304 #ifdef Q_WS_MAEMO_5 |
222 QSize size = webWidget()->size().toSize(); |
305 QSize size(800,424); |
|
306 #else |
|
307 QSize size(640,360); |
|
308 #endif |
223 QImage image(size, QImage::Format_RGB32); |
309 QImage image(size, QImage::Format_RGB32); |
224 |
310 |
225 QPainter painter(&image); |
311 QPainter painter(&image); |
226 QRect r(0, 0, size.width(), size.height()); |
312 QRect r(0, 0, size.width(), size.height()); |
227 QRegion clip(r); |
313 QRegion clip(r); |
228 painter.save(); |
314 painter.save(); |
229 painter.setBrush(Qt::white); |
315 painter.setBrush(Qt::white); |
230 painter.drawRect(r); |
316 painter.drawRect(r); |
231 painter.restore(); |
317 painter.restore(); |
|
318 qreal saveZoomFactor = mainFrame()->zoomFactor(); |
|
319 mainFrame()->setZoomFactor(1.0); |
232 mainFrame()->render(&painter, clip); |
320 mainFrame()->render(&painter, clip); |
233 QImage thumbnail = image.scaled(scaleX * size.width(), scaleY * size.height()); |
321 mainFrame()->setZoomFactor(saveZoomFactor); |
|
322 QImage thumbnail = image.scaled(scaleX * size.width(), scaleY * size.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation); |
234 return thumbnail; |
323 return thumbnail; |
235 } |
324 } |
236 |
325 |
237 /*! |
326 /*! |
238 Pulic Slots: |
327 Pulic Slots: |
253 if (frame != mainFrame() || !item->isValid() || !webWidget()) |
342 if (frame != mainFrame() || !item->isValid() || !webWidget()) |
254 { |
343 { |
255 return; |
344 return; |
256 } |
345 } |
257 if (restoreSession()) return; |
346 if (restoreSession()) return; |
258 |
347 |
259 WebPageData data(this); |
348 // item->setUserData(QVariant::fromValue(d->m_zoomData)); |
|
349 /* WebPageData data(this); |
260 // WebPageData data = item->userData().value<WebPageData>(); |
350 // WebPageData data = item->userData().value<WebPageData>(); |
261 data.m_zoomFactor = 1.0; // Need to find a way to get this. Not used right now anyway |
351 data.m_zoomFactor = 1.0; // Need to find a way to get this. Not used right now anyway |
262 data.m_thumbnail = pageThumbnail(0.5, 0.5);//data.m_zoomFactor, data.m_zoomFactor); |
352 data.m_thumbnail = pageThumbnail(0.5, 0.5);//data.m_zoomFactor, data.m_zoomFactor); |
263 |
353 |
264 QPoint pos(0, 0); |
354 QPoint pos(0, 0); |
265 // pos = static_cast<WebCanvasWidget*>(webWidget())->canvas()->canvasToDocument(pos); |
355 // pos = static_cast<WebCanvasWidget*>(webWidget())->canvas()->canvasToDocument(pos); |
266 pos = mainFrame()->scrollPosition(); |
356 pos = mainFrame()->scrollPosition(); |
267 data.m_contentsPos = pos; |
357 data.m_contentsPos = pos; |
268 QVariant variant; |
358 QVariant variant; |
269 variant.setValue(data); |
359 variant.setValue(data); |
270 item->setUserData(variant); |
360 item->setUserData(variant); */ |
271 //ii++; |
361 //ii++; |
272 } |
362 } |
273 |
363 |
274 /*! |
364 /*! |
275 * Public slot AuthenticationRequired |
365 * Public slot AuthenticationRequired |
301 { |
391 { |
302 authenticator->setUser(username); |
392 authenticator->setUser(username); |
303 authenticator->setPassword(password); |
393 authenticator->setPassword(password); |
304 } |
394 } |
305 } |
395 } |
|
396 |
|
397 #ifdef QT_GEOLOCATION |
|
398 void WrtBrowserContainer::handleRequestPermissionFromUser(QWebFrame* frame, QWebPage::PermissionDomain permissionDomain) |
|
399 { |
|
400 QList<QVariant> attributes; |
|
401 QUrl baseUrl = frame->baseUrl(); |
|
402 QString domain = baseUrl.host(); |
|
403 |
|
404 qDebug() << "handleRequestPermissionFromUser"; |
|
405 |
|
406 // Check if the domian from the frame already exisit in the database |
|
407 attributes = d->m_geolocationManager->findGeodomain(domain); |
|
408 |
|
409 if (!attributes.isEmpty()) |
|
410 { |
|
411 QWebPage::PermissionPolicy permission |
|
412 = attributes.at(0).value<QWebPage::PermissionPolicy>(); |
|
413 |
|
414 setUserPermission(frame, permissionDomain, permission); |
|
415 } |
|
416 else |
|
417 { |
|
418 // If the domain is empty string, provide whole base url |
|
419 if (domain == "") |
|
420 domain = baseUrl.toString(); |
|
421 |
|
422 emit requestGeolocationPermission(frame, permissionDomain, domain); |
|
423 } |
|
424 } |
|
425 |
|
426 void WrtBrowserContainer::setGeolocationPermission(QWebFrame* frame, QWebPage::PermissionDomain permissionDomain, |
|
427 bool permissionGranted, bool saveSetting) |
|
428 { |
|
429 QWebPage::PermissionPolicy permission = QWebPage::PermissionUnknown; |
|
430 |
|
431 if (permissionGranted == true) |
|
432 permission = QWebPage::PermissionGranted; |
|
433 else |
|
434 permission = QWebPage::PermissionDenied; |
|
435 |
|
436 setUserPermission(frame, permissionDomain, permission); |
|
437 |
|
438 // save the geolocation permission setting (granted/denied) in the data base |
|
439 if (saveSetting) |
|
440 { |
|
441 QUrl baseUrl = frame->baseUrl(); |
|
442 QString domain = baseUrl.host(); |
|
443 |
|
444 // If the domain is empty string, provide whole base url |
|
445 if (domain == "") |
|
446 domain = baseUrl.toString(); |
|
447 |
|
448 d->m_geolocationManager->addGeodomain(domain, permission); |
|
449 } |
|
450 } |
|
451 #endif // QT_GEOLOCATION |
306 |
452 |
307 void WrtBrowserContainer::setPageFactory(BrowserPageFactory* f) |
453 void WrtBrowserContainer::setPageFactory(BrowserPageFactory* f) |
308 { |
454 { |
309 d->m_pageFactory = f; |
455 d->m_pageFactory = f; |
310 } |
456 } |
356 result = true; |
502 result = true; |
357 |
503 |
358 return result; |
504 return result; |
359 } |
505 } |
360 |
506 |
361 ZoomMetaData WrtBrowserContainer::pageZoomMetaData() { |
507 WebPageData* WrtBrowserContainer::pageZoomMetaData() |
362 return d->m_zoomData ; |
508 { |
363 |
509 QVariant userData = history()->currentItem().userData(); |
364 } |
510 QVariant::Type t = userData.type(); |
365 void WrtBrowserContainer::setPageZoomMetaData( ZoomMetaData zoomData ){ |
511 int ut = userData.userType(); |
366 |
512 |
367 d->m_zoomData = zoomData; |
513 if(userData.isValid() && t == QVariant::UserType && |
|
514 ut == QMetaTypeId<WebPageData>::qt_metatype_id()) |
|
515 return (WebPageData*)(history()->currentItem().userData().constData()); |
|
516 else { |
|
517 static WebPageData dummyData; |
|
518 return &dummyData; |
|
519 } |
|
520 } |
|
521 |
|
522 void WrtBrowserContainer::setPageZoomMetaData(const WebPageData &zoomData ){ |
|
523 history()->currentItem().setUserData(qVariantFromValue(zoomData)); |
368 } |
524 } |
369 |
525 |
370 |
526 |
371 WrtBrowserFileChooser::~WrtBrowserFileChooser() |
527 WrtBrowserFileChooser::~WrtBrowserFileChooser() |
372 {} |
528 {} |