[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwebkitpart] src: Connect to loadStarted and loadFinished signal
From:       Dawit Alemayehu <adawit () kde ! org>
Date:       2011-12-16 5:49:14
Message-ID: 20111216054914.09F45A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit a193b99ae36ebafeb7328ff94ef5acdaca309a69 by Dawit Alemayehu.
Committed on 16/12/2011 at 06:46.
Pushed by adawit into branch 'master'.

Connect to loadStarted and loadFinished signal from the main QWebFrame only.
Otherwise, these signals would be emitted from every other frame that is part
of a page and cause performance issues when we try to parse the page for fillable
forms.

M  +48   -51   src/kwebkitpart.cpp
M  +0    -1    src/kwebkitpart.h

http://commits.kde.org/kwebkitpart/a193b99ae36ebafeb7328ff94ef5acdaca309a69

diff --git a/src/kwebkitpart.cpp b/src/kwebkitpart.cpp
index 074ffc8..b6fffd9 100644
--- a/src/kwebkitpart.cpp
+++ b/src/kwebkitpart.cpp
@@ -148,7 +148,7 @@ KWebKitPart::KWebKitPart(QWidget *parentWidget, QObject *parent,
     // Connect the signals/slots from the webview...
     connect(m_webView, SIGNAL(titleChanged(QString)),
             this, SIGNAL(setWindowCaption(QString)));
-    connect(m_webView, SIGNAL(loadFinished(bool)),
+    connect(m_webView->page()->mainFrame(), SIGNAL(loadFinished(bool)),
             this, SLOT(slotLoadFinished(bool)));
     connect(m_webView, SIGNAL(urlChanged(QUrl)),
             this, SLOT(slotUrlChanged(QUrl)));
@@ -260,7 +260,7 @@ void KWebKitPart::connectWebPageSignals(WebPage* page)
     if (!page)
         return;
 
-    connect(page, SIGNAL(loadStarted()),
+    connect(page->mainFrame(), SIGNAL(loadStarted()),
             this, SLOT(slotLoadStarted()));
     connect(page, SIGNAL(loadAborted(KUrl)),
             this, SLOT(slotLoadAborted(KUrl)));
@@ -438,60 +438,57 @@ void KWebKitPart::slotLoadStarted()
 void KWebKitPart::slotLoadFinished(bool ok)
 {
     KWebPage* p = page();
-    const QUrl currentUrl = m_webView->url();
-
-    if (m_lastUrl != currentUrl) {
-        m_lastUrl = currentUrl;
-        m_emitOpenUrlNotify = true;
-
-        if (ok) {
-            if (m_webView->title().trimmed().isEmpty()) {
-                // If the document title is empty, then set it to the current url
-                const QString caption = \
                m_webView->url().toString((QUrl::RemoveQuery|QUrl::RemoveFragment));
-                emit setWindowCaption(caption);
-
-                // The urlChanged signal is emitted if and only if the main frame
-                // receives the title of the page so we manually invoke the slot as
-                // a work around here for pages that do not contain it, such as
-                // text documents...
-                slotUrlChanged(m_webView->url());
-            }
+    m_emitOpenUrlNotify = true;
 
-            if (currentUrl != sAboutBlankUrl && p) {
-                m_hasCachedFormData = false;
+    if (ok) {
+        if (m_webView->title().trimmed().isEmpty()) {
+            // If the document title is empty, then set it to the current url
+            const QString caption = \
m_webView->url().toString((QUrl::RemoveQuery|QUrl::RemoveFragment)); +            \
emit setWindowCaption(caption); +
+            // The urlChanged signal is emitted if and only if the main frame
+            // receives the title of the page so we manually invoke the slot as
+            // a work around here for pages that do not contain it, such as
+            // text documents...
+            slotUrlChanged(m_webView->url());
+        }
 
-                if (WebKitSettings::self()->isNonPasswordStorableSite(currentUrl.host())) \
                {
-                    addWalletStatusBarIcon(); // Add wallet status
-                } else {
-                    // Attempt to fill the web form...
-                    KWebWallet *webWallet = p->wallet();
-                    kDebug() << webWallet;
-                    if (webWallet) {
-                        webWallet->fillFormData(p->mainFrame());
-                    }
-                }
+        const QUrl currentUrl (m_webView->url());
 
-                // Set the favicon specified through the <link> tag...
-                if (WebKitSettings::self()->favIconsEnabled() &&
-                    currentUrl.scheme().startsWith(QL1S("http"), \
                Qt::CaseInsensitive)) {
-                    const QWebElement element = \
                p->mainFrame()->findFirstElement(QL1S("head>link[rel=icon], "
-                                                                                     \
                "head>link[rel=\"shortcut icon\"]"));
-                    KUrl shortcutIconUrl;
-                    if (element.isNull()) {
-                        shortcutIconUrl = p->mainFrame()->baseUrl();
-                        QString urlPath = shortcutIconUrl.path();
-                        const int index = urlPath.indexOf(QL1C('/'));
-                        if (index > -1)
-                          urlPath.truncate(index);
-                        urlPath += QL1S("/favicon.ico");
-                        shortcutIconUrl.setPath(urlPath);
-                    } else {
-                        shortcutIconUrl = KUrl (p->mainFrame()->baseUrl(), \
                element.attribute("href"));
-                    }
+        if (currentUrl != sAboutBlankUrl && p) {
+            m_hasCachedFormData = false;
+
+            if (WebKitSettings::self()->isNonPasswordStorableSite(currentUrl.host())) \
{ +                addWalletStatusBarIcon(); // Add wallet status
+            } else {
+                // Attempt to fill the web form...
+                KWebWallet *webWallet = p->wallet();
+                kDebug() << webWallet;
+                if (webWallet) {
+                    webWallet->fillFormData(p->mainFrame());
+                }
+            }
 
-                    kDebug() << "setting favicon to" << shortcutIconUrl;
-                    m_browserExtension->setIconUrl(shortcutIconUrl);
+            // Set the favicon specified through the <link> tag...
+            if (WebKitSettings::self()->favIconsEnabled() &&
+                currentUrl.scheme().startsWith(QL1S("http"), Qt::CaseInsensitive)) {
+                const QWebElement element = \
p->mainFrame()->findFirstElement(QL1S("head>link[rel=icon], " +                       \
"head>link[rel=\"shortcut icon\"]")); +                KUrl shortcutIconUrl;
+                if (element.isNull()) {
+                    shortcutIconUrl = p->mainFrame()->baseUrl();
+                    QString urlPath = shortcutIconUrl.path();
+                    const int index = urlPath.indexOf(QL1C('/'));
+                    if (index > -1)
+                      urlPath.truncate(index);
+                    urlPath += QL1S("/favicon.ico");
+                    shortcutIconUrl.setPath(urlPath);
+                } else {
+                    shortcutIconUrl = KUrl (p->mainFrame()->baseUrl(), \
element.attribute("href"));  }
+
+                kDebug() << "setting favicon to" << shortcutIconUrl;
+                m_browserExtension->setIconUrl(shortcutIconUrl);
             }
         }
 
diff --git a/src/kwebkitpart.h b/src/kwebkitpart.h
index 7509d19..f59ee8e 100644
--- a/src/kwebkitpart.h
+++ b/src/kwebkitpart.h
@@ -143,7 +143,6 @@ private:
     void initActions();
     void addWalletStatusBarIcon();
 
-    KUrl m_lastUrl;
     bool m_emitOpenUrlNotify;
     bool m_pageRestored;
     bool m_hasCachedFormData;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic