diff -r f9e2e536d130 -r ad3f6c1caf8d WebBrowser/WebBrowserWindow.py --- a/WebBrowser/WebBrowserWindow.py Mon Feb 15 20:01:02 2016 +0100 +++ b/WebBrowser/WebBrowserWindow.py Wed Feb 17 19:49:51 2016 +0100 @@ -80,6 +80,7 @@ _fromEric = False UseQtHelp = QTHELP_AVAILABLE + _webProfile = None _networkManager = None ## _cookieJar = None ## _helpEngine = None @@ -135,21 +136,22 @@ if self.__initShortcutsOnly: self.__initActions() else: - if self.isPrivate(): - self.__webProfile = QWebEngineProfile(self) - else: - self.__webProfile = QWebEngineProfile.defaultProfile() - self.__webProfile.downloadRequested.connect( - self.__downloadRequested) - - # Setup QWebChannel user script - script = QWebEngineScript() - script.setName("_eric_webchannel") - script.setInjectionPoint(QWebEngineScript.DocumentCreation) - script.setWorldId(QWebEngineScript.MainWorld) - script.setRunsOnSubFrames(True) - script.setSourceCode(Scripts.setupWebChannel()) - self.__webProfile.scripts().insert(script) + self.webProfile(private) +## if self.isPrivate(): +## self.__webProfile = QWebEngineProfile(self) +## else: +## self.__webProfile = QWebEngineProfile.defaultProfile() +## self.__webProfile.downloadRequested.connect( +## self.__downloadRequested) +## +## # Setup QWebChannel user script +## script = QWebEngineScript() +## script.setName("_eric_webchannel") +## script.setInjectionPoint(QWebEngineScript.DocumentCreation) +## script.setWorldId(QWebEngineScript.MainWorld) +## script.setRunsOnSubFrames(True) +## script.setSourceCode(Scripts.setupWebChannel()) +## self.__webProfile.scripts().insert(script) from .SearchWidget import SearchWidget # TODO: QtHelp @@ -260,6 +262,8 @@ self.__setIconDatabasePath() self.__initWebEngineSettings() + self.passwordManager() + self.__initActions() self.__initMenus() self.__initToolbars() @@ -4029,9 +4033,9 @@ .replace("\n", "") name = "_eric_userstylesheet" - oldScript = self.__webProfile.scripts().findScript(name) + oldScript = self.webProfile().scripts().findScript(name) if not oldScript.isNull(): - self.__webProfile.scripts().remove(oldScript) + self.webProfile().scripts().remove(oldScript) if userStyle: script = QWebEngineScript() @@ -4040,7 +4044,7 @@ script.setWorldId(QWebEngineScript.ApplicationWorld) script.setRunsOnSubFrames(True) script.setSourceCode(Scripts.setStyleSheet(userStyle)) - self.__webProfile.scripts().insert(script) + self.webProfile().scripts().insert(script) ########################################## ## Support for desktop notifications below @@ -4088,9 +4092,10 @@ ## Support for download files below ################################### - def __downloadRequested(self, download): + @classmethod + def downloadRequested(self, download): """ - Private slot to handle a download request. + Class method to handle a download request. @param download reference to the download data @type QWebEngineDownloadItem @@ -4098,3 +4103,36 @@ pass # TODO: DownloadManager ## self.downloadManager().download(download, mainWindow=self) + + ######################################## + ## Support for web engine profiles below + ######################################## + + @classmethod + def webProfile(cls, private=False): + """ + Class method handling the web engine profile. + + @param private flag indicating the privacy mode + @type bool + @return reference to the web profile object + @rtype QWebEngineProfile + """ + if cls._webProfile is None: + if private: + cls._webProfile = QWebEngineProfile() + else: + cls._webProfile = QWebEngineProfile.defaultProfile() + cls._webProfile.downloadRequested.connect( + cls.downloadRequested) + + # Setup QWebChannel user script + script = QWebEngineScript() + script.setName("_eric_webchannel") + script.setInjectionPoint(QWebEngineScript.DocumentCreation) + script.setWorldId(QWebEngineScript.MainWorld) + script.setRunsOnSubFrames(True) + script.setSourceCode(Scripts.setupWebChannel()) + cls._webProfile.scripts().insert(script) + + return cls._webProfile