Continued porting the web browser. QtWebEngine

Fri, 19 Feb 2016 19:26:54 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 19 Feb 2016 19:26:54 +0100
branch
QtWebEngine
changeset 4749
750577d35452
parent 4745
285bfd224a1b
child 4750
9fc5d2625d61

Continued porting the web browser.

- finished the passwords stuff

WebBrowser/JavaScript/AutoFillJsObject.py file | annotate | diff | comparison | revisions
WebBrowser/JavaScript/ExternalJsObject.py file | annotate | diff | comparison | revisions
WebBrowser/Passwords/LoginForm.py file | annotate | diff | comparison | revisions
WebBrowser/Passwords/PasswordManager.py file | annotate | diff | comparison | revisions
WebBrowser/Passwords/PasswordReader.py file | annotate | diff | comparison | revisions
WebBrowser/Passwords/PasswordWriter.py file | annotate | diff | comparison | revisions
WebBrowser/Passwords/PasswordsDialog.py file | annotate | diff | comparison | revisions
WebBrowser/Tools/Scripts.py file | annotate | diff | comparison | revisions
WebBrowser/UrlBar/BookmarkInfoDialog.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserPage.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserTabWidget.py file | annotate | diff | comparison | revisions
eric6.e4p file | annotate | diff | comparison | revisions
--- a/WebBrowser/JavaScript/AutoFillJsObject.py	Thu Feb 18 20:19:33 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
-#
-
-"""
-Module implementing the Auto Fill web channel endpoint.
-"""
-
-#
-# This code was ported from QupZilla.
-# Copyright (C) David Rosca <nowrep@gmail.com>
-#
-
-from __future__ import unicode_literals
-
-from PyQt5.QtCore import pyqtSlot, QObject, QByteArray
-
-
-class AutoFillJsObject(QObject):
-    """
-    Class implementing the Auto Fill web channel endpoint.
-    """
-    def __init__(self, parent):
-        """
-        Constructor
-        
-        @param parent reference to the parent object
-        @type ExternalJsObject
-        """
-        super(AutoFillJsObject, self).__init__(parent)
-        
-        self.__jsObject = parent
-    
-    @pyqtSlot(str, str, str, QByteArray)
-    def formSubmitted(self, urlStr, userName, password, data):
-        """
-        Public slot passing form data to the auto fill manager.
-        
-        @param urlStr form submission URL
-        @type str
-        @param userName name of the user
-        @type str
-        @param password user password
-        @type str
-        @param data data to be submitted
-        @type QByteArray
-        """
-        import WebBrowser.WebBrowserWindow
-        WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
-        .formSubmitted(urlStr, userName, password, data,
-                       self.__jsObject.page())
--- a/WebBrowser/JavaScript/ExternalJsObject.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/JavaScript/ExternalJsObject.py	Fri Feb 19 19:26:54 2016 +0100
@@ -9,15 +9,13 @@
 """
 
 #
-# This code was ported from QupZilla.
+# This code was ported from QupZilla and modified.
 # Copyright (C) David Rosca <nowrep@gmail.com>
 #
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSlot, QObject, QUrl
-
-from .AutoFillJsObject import AutoFillJsObject
+from PyQt5.QtCore import pyqtSlot, QObject, QUrl, QByteArray
 
 import WebBrowser.WebBrowserWindow
 
@@ -36,7 +34,6 @@
         super(ExternalJsObject, self).__init__(page)
         
         self.__page = page
-        self.__autoFill = AutoFillJsObject(self)
     
     def page(self):
         """
@@ -62,16 +59,6 @@
 ##        return WebBrowser.WebBrowserWindow.WebBrowserWindow.speedDial()
         return None
     
-    @pyqtSlot(result=QObject)
-    def autoFill(self):
-        """
-        Public method returning a reference to the auto fill object.
-        
-        @return reference to the auto fill object
-        @rtype AutoFillJsObject
-        """
-        return self.__autoFill
-    
     @pyqtSlot(str)
     def AddSearchProvider(self, engineUrl):
         """
@@ -82,9 +69,22 @@
         """
         WebBrowser.WebBrowserWindow.WebBrowserWindow.openSearchManager()\
         .addEngine(QUrl(engineUrl))
-##
-##int ExternalJsObject::IsSearchProviderInstalled(const QString &engineURL)
-##{ Slot
-##    qDebug() << "NOT IMPLEMENTED: IsSearchProviderInstalled()" << engineURL;
-##    return 0;
-##}
+    
+    @pyqtSlot(str, str, str, QByteArray)
+    def formSubmitted(self, urlStr, userName, password, data):
+        """
+        Public slot passing form data to the password manager.
+        
+        @param urlStr form submission URL
+        @type str
+        @param userName name of the user
+        @type str
+        @param password user password
+        @type str
+        @param data data to be submitted
+        @type QByteArray
+        """
+        import WebBrowser.WebBrowserWindow
+        WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
+        .formSubmitted(urlStr, userName, password, data,
+                       self.page())
--- a/WebBrowser/Passwords/LoginForm.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/Passwords/LoginForm.py	Fri Feb 19 19:26:54 2016 +0100
@@ -9,7 +9,7 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import QUrl, QByteArray
+from PyQt5.QtCore import QUrl
 
 
 class LoginForm(object):
@@ -22,7 +22,7 @@
         """
         self.url = QUrl()
         self.name = ""
-        self.postData = QByteArray()
+        self.postData = ""
     
     def isValid(self):
         """
@@ -31,4 +31,4 @@
         @return flag indicating a valid form (boolean)
         """
         return not self.url.isEmpty() and \
-            not self.postData.isEmpty()
+            bool(self.postData)
--- a/WebBrowser/Passwords/PasswordManager.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/Passwords/PasswordManager.py	Fri Feb 19 19:26:54 2016 +0100
@@ -268,7 +268,7 @@
         @param data data to be submitted
         @type QByteArray
         @param page reference to the calling page
-        @type QWrbEnginePage
+        @type QWebEnginePage
         """
         # shall passwords be saved?
         if not Preferences.getUser("SavePasswords"):
@@ -278,6 +278,9 @@
                 .isPrivate():
             return
         
+        if not self.__loaded:
+            self.__load()
+        
         if urlStr in self.__never:
             return
         
@@ -315,7 +318,9 @@
             form = LoginForm()
             form.url = url
             form.name = userName
-            form.postData = QByteArray(data)
+            form.postData = Utilities.crypto.pwConvert(
+                bytes(data).decode("utf-8"), encode=True)
+##            form.postData = QByteArray(data)
             self.__loginForms[key] = form
             self.changed.emit()
     
@@ -361,7 +366,9 @@
         if form.url != url:
             return
         
-        script = Scripts.completeFormData(form.postData)
+        postData = QByteArray(Utilities.crypto.pwConvert(
+                form.postData, encode=False).encode("utf-8"))
+        script = Scripts.completeFormData(postData)
         page.runJavaScript(script)
     
     def masterPasswordChanged(self, oldPassword, newPassword):
@@ -374,14 +381,17 @@
         if not self.__loaded:
             self.__load()
         
+        # TODO: change this to include postData
         progress = E5ProgressDialog(
             self.tr("Re-encoding saved passwords..."),
-            None, 0, len(self.__logins), self.tr("%v/%m Passwords"),
+            None, 0, len(self.__logins) + len(self.__loginForms),
+            self.tr("%v/%m Passwords"),
             QApplication.activeModalWidget())
         progress.setMinimumDuration(0)
         progress.setWindowTitle(self.tr("Passwords"))
         count = 0
         
+        # step 1: do the logins
         for key in self.__logins:
             progress.setValue(count)
             QCoreApplication.processEvents()
@@ -390,6 +400,16 @@
             self.__logins[key] = (username, hash)
             count += 1
         
-        progress.setValue(len(self.__logins))
+        # step 2: do the login forms
+        for key in self.__loginForms:
+            progress.setValue(count)
+            QCoreApplication.processEvents()
+            postData = self.__loginForms[key].postData
+            postData = Utilities.crypto.pwRecode(
+                postData, oldPassword, newPassword)
+            self.__loginForms[key].postData = postData
+            count += 1
+        
+        progress.setValue(len(self.__logins) + len(self.__loginForms))
         QCoreApplication.processEvents()
         self.changed.emit()
--- a/WebBrowser/Passwords/PasswordReader.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/Passwords/PasswordReader.py	Fri Feb 19 19:26:54 2016 +0100
@@ -124,8 +124,7 @@
                     form.name = attributes.value("name")
                     
                 elif self.name() == "PostData":
-                    form.postData = QByteArray(
-                        self.readElementText().encode("utf-8"))
+                    form.postData = self.readElementText()
                 else:
                     self.__skipUnknownElement()
             
@@ -133,6 +132,8 @@
                 if self.name() == "Form":
                     self.__loginForms[key] = form
                     continue
+                elif self.name() == "PostData":
+                    continue
                 elif self.name() in ["Elements", "Element"]:
                     continue
                 else:
--- a/WebBrowser/Passwords/PasswordWriter.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/Passwords/PasswordWriter.py	Fri Feb 19 19:26:54 2016 +0100
@@ -95,8 +95,7 @@
             self.writeAttribute("key", key)
             self.writeAttribute("url", form.url.toString())
             self.writeAttribute("name", str(form.name))
-            self.writeTextElement(
-                "PostData", bytes(form.postData).decode("utf-8"))
+            self.writeTextElement("PostData", form.postData)
             self.writeEndElement()
         self.writeEndElement()
     
--- a/WebBrowser/Passwords/PasswordsDialog.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/Passwords/PasswordsDialog.py	Fri Feb 19 19:26:54 2016 +0100
@@ -39,12 +39,13 @@
             self.passwordsTable.removeSelected)
         self.removeAllButton.clicked.connect(self.passwordsTable.removeAll)
         
-        import Helpviewer.HelpWindow
+        import WebBrowser.WebBrowserWindow
         from .PasswordModel import PasswordModel
         
         self.passwordsTable.verticalHeader().hide()
         self.__passwordModel = PasswordModel(
-            Helpviewer.HelpWindow.HelpWindow.passwordManager(), self)
+            WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager(),
+            self)
         self.__proxyModel = QSortFilterProxyModel(self)
         self.__proxyModel.setSourceModel(self.__passwordModel)
         self.searchEdit.textChanged.connect(
--- a/WebBrowser/Tools/Scripts.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/Tools/Scripts.py	Fri Feb 19 19:26:54 2016 +0100
@@ -296,8 +296,7 @@
                     data = data.substring(0, data.length - 1);
                     var url = window.location.href;
                     var username = findUsername(inputs);
-                    external.autoFill.formSubmitted(url, username, password,
-                                                    data);
+                    external.formSubmitted(url, username, password, data);
                 }, true);
             }
             
--- a/WebBrowser/UrlBar/BookmarkInfoDialog.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/UrlBar/BookmarkInfoDialog.py	Fri Feb 19 19:26:54 2016 +0100
@@ -54,8 +54,8 @@
         """
         Private slot to remove the current bookmark.
         """
-        import Helpviewer.HelpWindow
-        Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\
+        import WebBrowser.WebBrowserWindow
+        WebBrowser.WebBrowserWindow.WebBrowserWindow.bookmarksManager()\
             .removeBookmark(self.__bookmark)
         self.close()
     
--- a/WebBrowser/WebBrowserPage.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/WebBrowserPage.py	Fri Feb 19 19:26:54 2016 +0100
@@ -727,10 +727,10 @@
         """
         Private method to setup a web channel to our external object.
         """
-        self.__externalJsObject = ExternalJsObject(self)
+##        self.__externalJsObject = ExternalJsObject(self)
         oldChannel = self.webChannel()
         newChannel = QWebChannel(self)
-        newChannel.registerObject("eric_object", self.__externalJsObject)
+        newChannel.registerObject("eric_object", ExternalJsObject(self))
         self.setWebChannel(newChannel)
         
         if oldChannel:
--- a/WebBrowser/WebBrowserTabWidget.py	Thu Feb 18 20:19:33 2016 +0100
+++ b/WebBrowser/WebBrowserTabWidget.py	Fri Feb 19 19:26:54 2016 +0100
@@ -316,12 +316,12 @@
         from .UrlBar.UrlBar import UrlBar
         urlbar = UrlBar(self.__mainWindow, self)
         if self.__historyCompleter is None:
-            import Helpviewer.HelpWindow
+            import WebBrowser.WebBrowserWindow
             from .History.HistoryCompleter import HistoryCompletionModel, \
                 HistoryCompleter
             self.__historyCompletionModel = HistoryCompletionModel(self)
             self.__historyCompletionModel.setSourceModel(
-                Helpviewer.HelpWindow.HelpWindow.historyManager()
+                WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager()
                 .historyFilterModel())
             self.__historyCompleter = HistoryCompleter(
                 self.__historyCompletionModel, self)
--- a/eric6.e4p	Thu Feb 18 20:19:33 2016 +0100
+++ b/eric6.e4p	Fri Feb 19 19:26:54 2016 +0100
@@ -1301,7 +1301,6 @@
     <Source>WebBrowser/History/HistoryModel.py</Source>
     <Source>WebBrowser/History/HistoryTreeModel.py</Source>
     <Source>WebBrowser/History/__init__.py</Source>
-    <Source>WebBrowser/JavaScript/AutoFillJsObject.py</Source>
     <Source>WebBrowser/JavaScript/ExternalJsObject.py</Source>
     <Source>WebBrowser/JavaScript/__init__.py</Source>
     <Source>WebBrowser/Network/FollowRedirectReply.py</Source>

eric ide

mercurial