|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
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. |
|
13 * |
|
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/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "browser.h" |
|
23 #ifndef NO_QSTM_GESTURE |
|
24 #include "WebGestureHelper.h" |
|
25 #endif |
|
26 #include "../ChromeLayout.h" |
|
27 #include "../ChromeWidget.h" |
|
28 #include "../ChromeDOM.h" |
|
29 #include "../Application.h" |
|
30 #include "HistoryFlowView.h" |
|
31 #include "WindowFlowView.h" |
|
32 #include "webpagecontroller.h" |
|
33 #include "bedrockprovisioning.h" |
|
34 #include "Utilities.h" |
|
35 #include "mostvisitedpagestore.h" |
|
36 |
|
37 #include <QApplication> |
|
38 #include <QDebug> |
|
39 #ifdef _GVA_INSPECT_CHROME_ |
|
40 #include <QWebInspector> |
|
41 #endif |
|
42 #include <QWebSettings> |
|
43 |
|
44 #ifndef Q_OS_SYMBIAN |
|
45 // Uncomment the next line to enable the javascript console dialog. |
|
46 //#define CHROME_CONSOLE 1 |
|
47 #ifdef CHROME_CONSOLE |
|
48 #include "ChromeConsole.h" |
|
49 #endif |
|
50 #endif |
|
51 |
|
52 |
|
53 #ifdef Q_WS_MAEMO_5 |
|
54 #include "../ContentViews/WindowsView.h" |
|
55 #include "../ContentViews/BrowserWindow.h" |
|
56 #endif |
|
57 |
|
58 GinebraBrowser::GinebraBrowser(QObject * parent, QString *url) |
|
59 : QObject(parent) |
|
60 , m_scene(new QGraphicsScene()) |
|
61 , m_app(0) |
|
62 #ifdef Q_WS_MAEMO_5 |
|
63 , m_mainWindow(0) |
|
64 , m_menu(new QMenu(tr("Menu"))) |
|
65 , m_splashScreenM5(0) |
|
66 #else |
|
67 , m_splashScreen(0) |
|
68 #endif |
|
69 { |
|
70 |
|
71 |
|
72 // Create the chrome widget |
|
73 m_chrome = new GVA::ChromeWidget(); |
|
74 |
|
75 platformSpecificInit(); |
|
76 |
|
77 // The initial url to go to when the browser is called from another app |
|
78 if (url != 0) { |
|
79 m_initialUrl = *url; |
|
80 } |
|
81 QString startUpChrome(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartUpChrome")); |
|
82 m_install = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory") |
|
83 + startUpChrome.section('/', 0, -2) + "/"; |
|
84 m_chromeUrl = startUpChrome.section('/', -1); |
|
85 m_contentUrl = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage"); |
|
86 |
|
87 setApplicationNameVersion(); |
|
88 |
|
89 m_app = new GVA::GinebraApplication(); |
|
90 |
|
91 // Instantiate Most Visited Page store. |
|
92 MostVisitedPageStoreSingleton::Instance(); |
|
93 |
|
94 #ifdef Q_WS_MAEMO_5 |
|
95 safe_connect(m_app, SIGNAL(addMenuBarActionRequest(QAction *)), |
|
96 this, SLOT(addMenuBarAction(QAction *))); |
|
97 safe_connect(m_app, SIGNAL(setMenuBarEnabledRequest(bool)), |
|
98 this, SLOT(setMenuBarEnabled(bool))); |
|
99 #endif |
|
100 |
|
101 m_chrome->setApp(m_app); |
|
102 |
|
103 #ifdef _GVA_INSPECT_CHROME_ |
|
104 QWebSettings * s = m_chrome->page()->settings(); |
|
105 s->setAttribute(QWebSettings::DeveloperExtrasEnabled, true ); |
|
106 QWebInspector *inspector = new QWebInspector; |
|
107 inspector->setPage(m_chrome->page()); |
|
108 inspector->resize(400,600); |
|
109 inspector->show(); |
|
110 connect(m_chrome->page(), SIGNAL(webInspectorTriggered(QWebElement)), inspector, SLOT(show())); |
|
111 #endif |
|
112 |
|
113 #ifndef Q_WS_MAEMO_5 //In maemo5 views, gesture handling are per window |
|
114 //Create a view onto the chrome |
|
115 m_view = new GVA::ChromeView(m_scene, m_chrome); |
|
116 #ifndef NO_QSTM_GESTURE |
|
117 WebGestureHelper* gh = new WebGestureHelper(m_view); |
|
118 browserApp->setGestureHelper(gh); |
|
119 browserApp->setMainWindow(m_view); |
|
120 m_view->grabGesture(QStm_Gesture::assignedType()); |
|
121 #endif |
|
122 #if defined(Q_OS_SYMBIAN) |
|
123 m_view->showFullScreen(); |
|
124 #else |
|
125 m_view->setGeometry(0,0,360,640); |
|
126 #endif |
|
127 #endif //End non-Maemo5 initialization |
|
128 |
|
129 showSplashScreen(); |
|
130 |
|
131 #ifndef __gva_no_chrome__ |
|
132 QObject::connect(m_chrome, SIGNAL(internalChromeComplete()), this, SLOT(onChromeComplete())); |
|
133 //Load the chrome |
|
134 m_chrome->setChromeBaseDirectory(m_install); |
|
135 m_chrome->setChromeFile(m_chromeUrl); |
|
136 #ifdef CHROME_CONSOLE |
|
137 // Show the javascript console. |
|
138 ChromeConsole *console = new ChromeConsole(m_chrome); |
|
139 console->show(); |
|
140 //console->move(m_view->geometry().topLeft() + QPoint(m_view->width()+6, 0)); |
|
141 #endif |
|
142 #else |
|
143 onChromeComplete(); |
|
144 #endif |
|
145 |
|
146 // Handle openUrl signals |
|
147 connect(this, SIGNAL(openUrlRequested(QString)), this, SLOT(openUrl(QString))); |
|
148 } |
|
149 |
|
150 GinebraBrowser::~GinebraBrowser() |
|
151 { |
|
152 delete m_chrome; |
|
153 delete WebPageController::getSingleton(); |
|
154 //delete m_view; |
|
155 destroySplashScreen(); |
|
156 delete m_scene; |
|
157 delete m_app; |
|
158 #ifdef Q_WS_MAEMO_5 |
|
159 delete m_windows; |
|
160 #endif |
|
161 |
|
162 #ifndef NO_QSTM_GESTURE |
|
163 WebGestureHelper* gh = browserApp->gestureHelper(); |
|
164 delete gh; |
|
165 #endif |
|
166 } |
|
167 |
|
168 void GinebraBrowser::platformSpecificInit() { |
|
169 #ifdef Q_WS_MAEMO_5 |
|
170 m_windows = new GVA::WindowsView(m_chrome); |
|
171 m_windows->setMenu(m_menu); |
|
172 m_windows->handlePageEvents(true); |
|
173 #else |
|
174 // Add initialization code for other platforms here... |
|
175 #endif |
|
176 } |
|
177 |
|
178 void GinebraBrowser::show() |
|
179 { |
|
180 //m_view->show(); |
|
181 } |
|
182 |
|
183 void GinebraBrowser::onChromeComplete() |
|
184 { |
|
185 #ifndef __gva_no_chrome__ |
|
186 #ifndef Q_WS_MAEMO_5 |
|
187 ControllableViewBase *windowView = WRT::WindowFlowView::createNew(m_chrome->layout()); |
|
188 windowView->setObjectName("WindowView"); |
|
189 m_chrome->addView(windowView); |
|
190 ControllableViewBase *historyView = WRT::HistoryFlowView::createNew(m_chrome->layout()); |
|
191 historyView->setObjectName("HistoryView"); |
|
192 m_chrome->addView(historyView); |
|
193 #endif |
|
194 #endif |
|
195 |
|
196 //Create a content window and add it to the chrome |
|
197 |
|
198 GVA::GWebContentView *content = new GVA::GWebContentView(m_chrome, 0, "WebView"); |
|
199 m_chrome->addView(content); |
|
200 |
|
201 #ifndef Q_WS_MAEMO_5 |
|
202 safe_connect(content, SIGNAL(titleChanged(const QString &)), |
|
203 this, SLOT(onTitleChanged(const QString &))); |
|
204 #endif |
|
205 |
|
206 QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("LocalPagesBaseDirectory"); |
|
207 QString startPage = chromeBaseDir + m_contentUrl; |
|
208 |
|
209 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession"); |
|
210 |
|
211 // If the browser was launched by some other app calling QDesktopServices.openUrl, go to that url |
|
212 if (!m_initialUrl.isEmpty()) { |
|
213 openUrl(m_initialUrl); |
|
214 } |
|
215 // Otherwise, load the previous page from history (if that option is enabled) |
|
216 else if (enabled && m_initialUrl.isEmpty()) { |
|
217 WebPageController::getSingleton()->loadFromHistory(); |
|
218 } |
|
219 // Otherwise, load the start page |
|
220 else { |
|
221 content->loadUrlToCurrentPage(startPage); |
|
222 } |
|
223 m_chrome->showView("WebView"); |
|
224 destroySplashScreen(); |
|
225 } |
|
226 |
|
227 #ifdef Q_WS_MAEMO_5 |
|
228 |
|
229 void GinebraBrowser::addMenuBarAction(QAction *action) { |
|
230 m_menu->addAction(action); |
|
231 } |
|
232 |
|
233 /// Hack to hide the menu bar arrow when the menu is disabled. |
|
234 void GinebraBrowser::fixupWindowTitle() { |
|
235 /* QString title = m_mainWindow->windowTitle(); |
|
236 title = title.trimmed(); |
|
237 if(m_menu && !m_menu->isEnabled()) { |
|
238 // The menu is disabled, add some spaces to the title to push the down arrow out of view. |
|
239 title += QString(60, ' '); |
|
240 } |
|
241 m_mainWindow->setWindowTitle(title);*/ |
|
242 } |
|
243 |
|
244 void GinebraBrowser::setMenuBarEnabled(bool value) { |
|
245 // m_menu->setEnabled(value); |
|
246 m_windows->setMenuEnabled(value); |
|
247 fixupWindowTitle(); |
|
248 } |
|
249 |
|
250 void GinebraBrowser::onTitleChanged(const QString &title) { |
|
251 // Update the title in the Maemo status bar. |
|
252 if(m_mainWindow) { |
|
253 if(title.isEmpty()) { |
|
254 m_mainWindow->setWindowTitle(QApplication::applicationName()); |
|
255 } |
|
256 else { |
|
257 m_mainWindow->setWindowTitle(title); |
|
258 } |
|
259 fixupWindowTitle(); |
|
260 } |
|
261 } |
|
262 |
|
263 #endif |
|
264 |
|
265 void GinebraBrowser::queueOpenUrl(QString url) |
|
266 { |
|
267 emit openUrlRequested(url); |
|
268 } |
|
269 |
|
270 void GinebraBrowser::openUrl(QString url) |
|
271 { |
|
272 #ifdef Q_OS_SYMBIAN |
|
273 // Handle the url as per the old standard at |
|
274 // http://wiki.forum.nokia.com/index.php/TSS000340_-_Launching_the_Web_browser_on_S60_3rd_Edition_to_open_a_specified_URL |
|
275 QChar urlType = url.at(0); |
|
276 // Bookmark (by uid) - not handled |
|
277 if (urlType == '1') { |
|
278 return; |
|
279 } |
|
280 // Saved deck (by uid) - not handled |
|
281 else if (urlType == '2') { |
|
282 return; |
|
283 } |
|
284 // Start page - not handled |
|
285 else if (urlType == '5') { |
|
286 return; |
|
287 } |
|
288 // Bookmark folder (by uid) - not handled |
|
289 else if (urlType == '6') { |
|
290 return; |
|
291 } |
|
292 // Url or Url + space + access point |
|
293 else if (urlType == '4') { |
|
294 url = url.mid(2); // Get the real url |
|
295 if (url.contains(' ')) { // Chop off the access point if there is one because it's not currently handled |
|
296 url = url.left(url.indexOf(' ')); |
|
297 } |
|
298 } |
|
299 // If no number then it's just a plain url |
|
300 #endif /* Q_OS_SYMBIAN */ |
|
301 // Bring the browser to the front (QDesktopServices openurl is supposed to do this but doesn't) |
|
302 //if (m_view) { |
|
303 // m_view->activateWindow(); |
|
304 // m_view->raise(); |
|
305 //} |
|
306 m_contentUrl = url; |
|
307 WebPageController::getSingleton()->loadInitialUrlFromOtherApp(url); |
|
308 // GVA::GWebContentView *webView = (GVA::GWebContentView *)m_chrome->getView("WebView"); |
|
309 // if (webView != 0) { |
|
310 // m_contentUrl = url; |
|
311 // webView->loadUrlToCurrentPage(url); |
|
312 // } |
|
313 } |
|
314 |
|
315 void GinebraBrowser::showSplashScreen() { |
|
316 QString splashImage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("SplashImage"); |
|
317 QString baseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory"); |
|
318 QString imagePath = baseDir + splashImage; |
|
319 |
|
320 #ifdef Q_WS_MAEMO_5 |
|
321 m_splashScreenM5 = new QSplashScreen(m_mainWindow, QPixmap(imagePath)); |
|
322 m_splashScreenM5->show(); |
|
323 #else |
|
324 |
|
325 if (!imagePath.isNull()) { |
|
326 m_splashScreen = new QLabel(NULL); |
|
327 m_splashScreen->setAlignment(Qt::AlignCenter); |
|
328 m_splashScreen->setStyleSheet("background-color: #FFF"); |
|
329 m_splashScreen->setPixmap(QPixmap(imagePath)); |
|
330 if (m_splashScreen->pixmap()->isNull()) { |
|
331 ;//qDebug() << "ChromeView::chromeLoaded: ERROR splashscreen creation failed. " << imagePath; |
|
332 } |
|
333 else { |
|
334 #ifdef Q_OS_SYMBIAN |
|
335 m_splashScreen->showFullScreen(); |
|
336 m_view->showFullScreen(); |
|
337 #else |
|
338 m_splashScreen->setGeometry(0,0,360,640); |
|
339 m_splashScreen->show(); |
|
340 #endif |
|
341 } |
|
342 } |
|
343 #endif |
|
344 } |
|
345 |
|
346 void GinebraBrowser::destroySplashScreen() |
|
347 { |
|
348 #ifdef Q_WS_MAEMO_5 |
|
349 if(m_splashScreenM5) { |
|
350 delete m_splashScreenM5; |
|
351 m_splashScreenM5 = 0; |
|
352 } |
|
353 #else |
|
354 if (m_splashScreen) { |
|
355 delete m_splashScreen; |
|
356 m_splashScreen = NULL; |
|
357 } |
|
358 #endif |
|
359 } |
|
360 |
|
361 void GinebraBrowser::setApplicationNameVersion() |
|
362 { |
|
363 QCoreApplication::setApplicationName(BEDROCK_APPLICATION_NAME); |
|
364 QString browserAppVersion = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("BedrockVersion"); |
|
365 QCoreApplication::setApplicationVersion(browserAppVersion); |
|
366 } |