[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/base/kwebkitpart/src
From: Dawit Alemayehu <adawit () kde ! org>
Date: 2010-12-01 0:20:06
Message-ID: 20101201002006.5B6F1AC8A3 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1202466 by adawit:
- Better workaround for BR# 253708 so that the issue mentioned in comment #6
of that report is handled properly.
- Set a dynamic QObject property named NavigationTypeUrlEntered whenever openUrl
is invoked so that we can distinguish user entered requests from other types.
- Reduced nested if statements whereever possible.
- Enclosed literal text with QLatin1String.
CCBUG:253708
M +48 -46 webpage.cpp
M +2 -0 webview.cpp
--- trunk/extragear/base/kwebkitpart/src/webpage.cpp #1202465:1202466
@@ -185,7 +185,7 @@
manager->setCookieJarWindowId(parent->window()->winId());
setNetworkAccessManager(manager);
- setSessionMetaData("ssl_activate_warnings", "TRUE");
+ setSessionMetaData(QL1S("ssl_activate_warnings"), QL1S("TRUE"));
// Set font sizes accordingly...
if (view())
@@ -193,8 +193,9 @@
setForwardUnsupportedContent(true);
- // Tell QtWebKit to treat man:/ protocol as a local resource...
+ // Tell QWebSecurityOrigin that man:/ and info:/ are local resources...
QWebSecurityOrigin::addLocalScheme(QL1S("man"));
+ QWebSecurityOrigin::addLocalScheme(QL1S("info"));
connect(this, SIGNAL(geometryChangeRequested(const QRect &)),
this, SLOT(slotGeometryChangeRequested(const QRect &)));
@@ -228,11 +229,21 @@
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest \
&request, NavigationType type) {
QUrl reqUrl (request.url());
+ const bool isMainFrameRequest = (frame == mainFrame());
+ /*
+ NOTE: We use a dynamic QObject property called "NavigationTypeUrlEntered"
+ to distinguish between requests generated by user entering a url vs those
+ that were generated programatically through javascript.
+ */
+ const bool isTypedUrl = property("NavigationTypeUrlEntered").toBool();
// Handle "mailto:" url here...
if (handleMailToUrl(reqUrl, type))
return false;
+ if (isMainFrameRequest && isTypedUrl)
+ setProperty("NavigationTypeUrlEntered", QVariant());
+
if (frame) {
// inPage requests are those generarted within the current page through
// link clicks, javascript queries, and button clicks (form submission).
@@ -260,13 +271,7 @@
inPageRequest = false;
break;
case QWebPage::NavigationTypeOther:
- /*
- NOTE: This navigation type is used for both user entered urls
- as well as javascript based link clicks. However, since there
- is no easy way to distinguish b/n
- */
- //if (d->part->url() == reqUrl)
- inPageRequest = false;
+ inPageRequest = !isTypedUrl;
if (d->ignoreHistoryNavigationRequest)
d->ignoreHistoryNavigationRequest = false;
break;
@@ -279,23 +284,21 @@
return false;
if (d->sslInfo.isValid())
- setRequestMetaData("ssl_was_in_use", "TRUE");
+ setRequestMetaData(QL1S("ssl_was_in_use"), QL1S("TRUE"));
}
- if (frame == mainFrame()) {
- setRequestMetaData("main_frame_request", "TRUE");
+ if (isMainFrameRequest) {
+ setRequestMetaData(QL1S("main_frame_request"), QL1S("TRUE"));
if (d->sslInfo.isValid() && !domainSchemeMatch(request.url(), \
d->sslInfo.url())) d->sslInfo = WebSslInfo();
} else {
- setRequestMetaData("main_frame_request", "FALSE");
+ setRequestMetaData(QL1S("main_frame_request"), QL1S("FALSE"));
}
// Insert the request into the queue...
reqUrl.setUserInfo(QString());
d->requestQueue << reqUrl;
- d->userRequestedCreateWindow = false;
} else {
- d->userRequestedCreateWindow = true;
d->newWindowUrl = reqUrl;
}
@@ -304,27 +307,30 @@
QWebPage *WebPage::createWindow(WebWindowType type)
{
- KParts::ReadOnlyPart *part = 0;
- KParts::OpenUrlArguments args;
KParts::BrowserArguments bargs;
- args.setActionRequestedByUser(d->userRequestedCreateWindow);
-
if (type == WebModalDialog)
bargs.setForcesNewWindow(true);
- d->part->browserExtension()->createNewWindow(KUrl("about:blank"), args, bargs, \
KParts::WindowArgs(), &part);
-
- KWebKitPart *webKitPart = qobject_cast<KWebKitPart*>(part);
- if (webKitPart)
- return webKitPart->view()->page();
-
- if (part) {
- part->openUrl(d->newWindowUrl);
+ // For non-javascript based links, we simply create a new window and
+ // and return a null QWebPage since we already know the url. Otherwise,
+ // we have to wait for the part to be created and pass back an instance
+ // of a QWebPage object so that QtWebKit can open the requested url.
+ if (d->newWindowUrl.isValid()) {
+ KParts::OpenUrlArguments args;
+ args.setActionRequestedByUser(true);
+ d->part->browserExtension()->createNewWindow(d->newWindowUrl, args, bargs);
d->newWindowUrl.clear();
+ return 0;
+ } else {
+ KParts::ReadOnlyPart *part = 0;
+ d->part->browserExtension()->createNewWindow(KUrl(), \
KParts::OpenUrlArguments(), bargs, + \
KParts::WindowArgs(), &part); + KWebKitPart* webkitpart = \
qobject_cast<KWebKitPart*>(part); + if (webkitpart)
+ return webkitpart->view()->page();
}
- else
- kWarning() << "Got a NULL part when attempting to create new window!";
+ kWarning() << "Failed to create new window! See bug# 253708 in KDE bug \
database"; return 0;
}
@@ -337,15 +343,10 @@
if (metaData.isEmpty())
hasContentDisposition = reply->hasRawHeader("Content-Disposition");
else
- hasContentDisposition = metaData.contains("content-disposition-filename");
+ hasContentDisposition = \
metaData.contains(QL1S("content-disposition-filename"));
if (hasContentDisposition) {
-#if KDE_IS_VERSION(4,4,75)
downloadResponse(reply);
-#else
- reply->abort();
- downloadRequest(reply->request());
-#endif
return;
}
@@ -462,23 +463,27 @@
void WebPage::slotRequestFinished(QNetworkReply *reply)
{
Q_ASSERT(reply);
+
QUrl url (reply->request().url());
- const int index = d->requestQueue.indexOf(reply->request().url());
+ const int index = d->requestQueue.indexOf(url);
+ if (index == -1)
+ return;
- if (index > -1) {
d->requestQueue.remove(index);
QWebFrame* frame = qobject_cast<QWebFrame \
*>(reply->request().originatingObject());
- if (frame) {
- //kDebug() << url;
+ if (!frame)
+ return;
+
const int statusCode = \
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- const bool isMainFrameRequest = (frame == mainFrame());
-
// Only deal with non-redirect responses...
if (statusCode > 299 && statusCode < 400) {
d->sslInfo.restoreFrom(reply->attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData)),
reply->url());
- } else {
+ return;
+ }
+
const int errCode = errorCodeFromReply(reply);
+ const bool isMainFrameRequest = (frame == mainFrame());
// Handle any error...
switch (errCode) {
case 0:
@@ -521,9 +526,6 @@
emit d->part->browserExtension()->setPageSecurity(security);
}
}
- }
- }
-}
bool WebPage::checkLinkSecurity(const QNetworkRequest &req, NavigationType type) \
const {
@@ -695,7 +697,7 @@
protocol = reqUrl.protocol();
datetime = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(), \
KLocale::LongDate );
- QString filename( KStandardDirs::locate( "data", "kwebkitpart/error.html" ) );
+ QString filename (KStandardDirs::locate ("data", QL1S("kwebkitpart/error.html")));
QFile file( filename );
if ( !file.open( QIODevice::ReadOnly ) )
return i18n("<html><body><h3>Unable to display error message</h3>"
--- trunk/extragear/base/kwebkitpart/src/webview.cpp #1202465:1202466
@@ -80,6 +80,8 @@
void WebView::loadUrl(const KUrl &url, const KParts::OpenUrlArguments &args, const \
KParts::BrowserArguments &bargs) {
+ page()->setProperty("NavigationTypeUrlEntered", true);
+
if (args.reload()) {
pageAction(KWebPage::Reload)->trigger();
return;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic