Sun, 28 Feb 2016 20:07:41 +0100
Continued porting the web browser.
- implemented the private browsing mode
--- a/WebBrowser/ClosedTabsManager.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/ClosedTabsManager.py Sun Feb 28 20:07:41 2016 +0100 @@ -67,8 +67,7 @@ @param position index of the tab to be closed (integer) """ import WebBrowser.WebBrowserWindow - if WebBrowser.WebBrowserWindow.WebBrowserWindow\ - .mainWindow().getWindow().isPrivate(): + if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate(): return if browser.url().isEmpty():
--- a/WebBrowser/Download/DownloadManager.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/Download/DownloadManager.py Sun Feb 28 20:07:41 2016 +0100 @@ -286,7 +286,7 @@ return from WebBrowser.WebBrowserWindow import WebBrowserWindow - if WebBrowserWindow.mainWindow().isPrivate(): + if WebBrowserWindow.isPrivate(): return downloads = []
--- a/WebBrowser/FeaturePermissions/FeaturePermissionManager.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/FeaturePermissions/FeaturePermissionManager.py Sun Feb 28 20:07:41 2016 +0100 @@ -162,8 +162,7 @@ return import WebBrowser.WebBrowserWindow - if WebBrowser.WebBrowserWindow.WebBrowserWindow\ - .mainWindow().getWindow().isPrivate(): + if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate(): return for (feature, permission), key in \
--- a/WebBrowser/History/HistoryManager.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/History/HistoryManager.py Sun Feb 28 20:07:41 2016 +0100 @@ -187,8 +187,7 @@ @type WebBrowserView """ import WebBrowser.WebBrowserWindow - if WebBrowser.WebBrowserWindow.WebBrowserWindow\ - .mainWindow().getWindow().isPrivate(): + if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate(): return url = view.url()
--- a/WebBrowser/Passwords/PasswordManager.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/Passwords/PasswordManager.py Sun Feb 28 20:07:41 2016 +0100 @@ -274,8 +274,7 @@ if not Preferences.getUser("SavePasswords"): return - if WebBrowser.WebBrowserWindow.WebBrowserWindow.mainWindow()\ - .isPrivate(): + if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate(): return if not self.__loaded: @@ -320,7 +319,6 @@ form.name = userName form.postData = Utilities.crypto.pwConvert( bytes(data).decode("utf-8"), encode=True) -## form.postData = QByteArray(data) self.__loginForms[key] = form self.changed.emit()
--- a/WebBrowser/UrlBar/UrlBar.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/UrlBar/UrlBar.py Sun Feb 28 20:07:41 2016 +0100 @@ -26,7 +26,7 @@ from E5Gui.E5LineEdit import E5LineEdit from E5Gui.E5LineEditButton import E5LineEditButton -import WebBrowser.WebBrowserWindow +from WebBrowser.WebBrowserWindow import WebBrowserWindow from .FavIconLabel import FavIconLabel ##from .SslLabel import SslLabel @@ -53,8 +53,7 @@ self.__mw = mainWindow self.__browser = None -## self.__privateMode = QWebSettings.globalSettings().testAttribute( -## QWebSettings.PrivateBrowsingEnabled) + self.__privateMode = WebBrowserWindow.isPrivate() self.__bmActiveIcon = UI.PixmapCache.getIcon("bookmark16.png") self.__bmInactiveIcon = QIcon( @@ -68,13 +67,6 @@ ## self.addWidget(self.__sslLabel, E5LineEdit.LeftSide) ## self.__sslLabel.setVisible(False) - # TODO: Privacy -## self.__privacyButton = E5LineEditButton(self) -## self.__privacyButton.setIcon( -## UI.PixmapCache.getIcon("privateBrowsing.png")) -## self.addWidget(self.__privacyButton, E5LineEdit.RightSide) -## self.__privacyButton.setVisible(self.__privateMode) - self.__rssButton = E5LineEditButton(self) self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16.png")) self.addWidget(self.__rssButton, E5LineEdit.RightSide) @@ -91,10 +83,7 @@ self.__bookmarkButton.clicked.connect(self.__showBookmarkInfo) self.__rssButton.clicked.connect(self.__rssClicked) - # TODO: Privacy -## self.__privacyButton.clicked.connect(self.__privacyClicked) self.__clearButton.clicked.connect(self.clear) -## self.__mw.privacyChanged.connect(self.__privacyButton.setVisible) self.textChanged.connect(self.__textChanged) self.__mw.bookmarksManager().entryChanged.connect( @@ -222,22 +211,6 @@ ## except RuntimeError: ## pass - # TODO: Privacy -## def setPrivateMode(self, on): -## """ -## Public method to set the private mode. -## -## @param on flag indicating the privacy state (boolean) -## """ -## self.__privateMode = on -## self.__privacyButton.setVisible(on) -## -## def __privacyClicked(self): -## """ -## Private slot to handle the click of the private mode button. -## """ -## self.__mw.setPrivateMode(False) -## def __textChanged(self, txt): """ Private slot to handle changes of the text. @@ -290,13 +263,12 @@ @param evt reference to the paint event (QPaintEvent) """ - # TODO: Privacy -## if self.__privateMode: -## backgroundColor = QColor(220, 220, 220) # light gray -## foregroundColor = Qt.black -## else: - backgroundColor = QApplication.palette().color(QPalette.Base) - foregroundColor = QApplication.palette().color(QPalette.Text) + if self.__privateMode: + backgroundColor = QColor(220, 220, 220) # light gray + foregroundColor = Qt.black + else: + backgroundColor = QApplication.palette().color(QPalette.Base) + foregroundColor = QApplication.palette().color(QPalette.Text) if self.__browser is not None: p = self.palette()
--- a/WebBrowser/WebBrowserPage.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/WebBrowserPage.py Sun Feb 28 20:07:41 2016 +0100 @@ -30,7 +30,7 @@ from E5Gui import E5MessageBox, E5FileDialog import WebBrowser -import WebBrowser.WebBrowserWindow +from WebBrowser.WebBrowserWindow import WebBrowserWindow from .JavaScript.ExternalJsObject import ExternalJsObject @@ -131,7 +131,8 @@ @param parent parent widget of this window (QWidget) """ - super(WebBrowserPage, self).__init__(parent) + super(WebBrowserPage, self).__init__( + WebBrowserWindow.webProfile(), parent) self.__setupWebChannel() @@ -140,13 +141,12 @@ ## self.__lastRequest = None ## self.__lastRequestType = QWebPage.NavigationTypeOther ## -## import WebBrowser.WebBrowserWindow ## from .Network.NetworkAccessManagerProxy import \ ## NetworkAccessManagerProxy ## self.__proxy = NetworkAccessManagerProxy(self) ## self.__proxy.setWebPage(self) ## self.__proxy.setPrimaryNetworkAccessManager( -## WebBrowser.WebBrowserWindow.WebBrowserWindow.networkManager()) +## WebBrowserWindow.networkManager()) ## self.setNetworkAccessManager(self.__proxy) self.__sslConfiguration = None @@ -163,12 +163,10 @@ self.__featurePermissionRequested) self.authenticationRequired.connect( - WebBrowser.WebBrowserWindow.WebBrowserWindow.networkManager() - .authentication) + WebBrowserWindow.networkManager().authentication) self.proxyAuthenticationRequired.connect( - WebBrowser.WebBrowserWindow.WebBrowserWindow.networkManager() - .proxyAuthentication) + WebBrowserWindow.networkManager().proxyAuthentication) def acceptNavigationRequest(self, url, type_, isMainFrame): """ @@ -197,8 +195,7 @@ # AdBlock if url.scheme() == "abp": - if WebBrowser.WebBrowserWindow.WebBrowserWindow.adBlockManager()\ - .addSubscriptionFromUrl(url): + if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url): return False ## ## if type_ == QWebPage.NavigationTypeFormResubmitted: @@ -456,9 +453,7 @@ ## @param url URL to determine user agent for (QUrl) ## @return user agent string (string) ## """ -## import WebBrowser.WebBrowserWindow -## agent = WebBrowser.WebBrowserWindow.WebBrowserWindow.userAgentsManager()\ -## .userAgentForUrl(url) +## agent = WebBrowserWindow.userAgentsManager().userAgentForUrl(url) ## if agent == "": ## # no agent string specified for the given host -> use global one ## agent = Preferences.getWebBrowser("UserAgent") @@ -501,8 +496,7 @@ ## reply.url() == self.mainFrame().url(): ## modified = reply.header(QNetworkRequest.LastModifiedHeader) ## if modified and modified.isValid(): -## import WebBrowser.WebBrowserWindow -## manager = WebBrowser.WebBrowserWindow.WebBrowserWindow.bookmarksManager() +## manager = WebBrowserWindow.bookmarksManager() ## from .Bookmarks.BookmarkNode import BookmarkNode ## for bookmark in manager.bookmarksForUrl(reply.url()): ## manager.setTimestamp(bookmark, BookmarkNode.TsModified, @@ -677,8 +671,7 @@ @param feature requested feature @type QWebEnginePage.Feature """ - manager = WebBrowser.WebBrowserWindow.WebBrowserWindow\ - .featurePermissionManager() + manager = WebBrowserWindow.featurePermissionManager() manager.requestFeaturePermission(self, url, feature) def execJavaScript(self, script): @@ -751,8 +744,8 @@ @return flag indicating to ignore this error @rtype bool """ - return WebBrowser.WebBrowserWindow.WebBrowserWindow.networkManager()\ - .certificateError(error, self.view()) + return WebBrowserWindow.networkManager().certificateError( + error, self.view()) ############################################## ## Methods below deal with JavaScript messages
--- a/WebBrowser/WebBrowserWebSearchWidget.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/WebBrowserWebSearchWidget.py Sun Feb 28 20:07:41 2016 +0100 @@ -99,8 +99,7 @@ return import WebBrowser.WebBrowserWindow - if WebBrowser.WebBrowserWindow.WebBrowserWindow\ - .mainWindow().getWindow().isPrivate(): + if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate(): return if searchText in self.__recentSearches:
--- a/WebBrowser/WebBrowserWindow.py Sun Feb 28 18:49:24 2016 +0100 +++ b/WebBrowser/WebBrowserWindow.py Sun Feb 28 20:07:41 2016 +0100 @@ -15,9 +15,10 @@ import os import shutil +import sys from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QByteArray, QSize, QTimer, \ - QUrl, QThread, QTextCodec + QUrl, QThread, QTextCodec, QProcess from PyQt5.QtGui import QDesktopServices, QKeySequence, QFont, QFontMetrics, \ QIcon from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QDockWidget, \ @@ -59,6 +60,8 @@ from .ZoomManager import ZoomManager +from eric6config import getConfig + class WebBrowserWindow(E5MainWindow): """ @@ -70,7 +73,6 @@ """ ## zoomTextOnlyChanged = pyqtSignal(bool) webBrowserClosed = pyqtSignal() -## privacyChanged = pyqtSignal(bool) BrowserWindows = [] @@ -78,6 +80,7 @@ ## _fromEric = False UseQtHelp = QTHELP_AVAILABLE + _isPrivate = False _webProfile = None _networkManager = None @@ -100,7 +103,7 @@ def __init__(self, home, path, parent, name, fromEric=False, initShortcutsOnly=False, searchWord=None, - private=False): + private=False, settingsDir=""): """ Constructor @@ -114,11 +117,13 @@ keyboard shortcuts (boolean) @keyparam searchWord word to search for (string) @keyparam private flag indicating a private browsing window (bool) + @keyparam settingsDir directory to be used for the settings files (str) """ super(WebBrowserWindow, self).__init__(parent) self.setObjectName(name) self.setWindowTitle(self.tr("eric6 Web Browser")) + self.__settingsDir = settingsDir self.__fromEric = fromEric WebBrowserWindow._fromEric = fromEric self.__initShortcutsOnly = initShortcutsOnly @@ -127,7 +132,7 @@ self.__mHistory = [] self.__lastConfigurationPageName = "" - self.__isPrivate = private + WebBrowserWindow._isPrivate = private self.__eventMouseButtons = Qt.NoButton self.__eventKeyboardModifiers = Qt.NoModifier @@ -528,13 +533,29 @@ self.newAct.setStatusTip(self.tr('Open a new web browser window')) self.newAct.setWhatsThis(self.tr( """<b>New Window</b>""" - """<p>This opens a new web browser window.</p>""" + """<p>This opens a new web browser window in the current""" + """ privacy mode.</p>""" )) if not self.__initShortcutsOnly: self.newAct.triggered.connect(self.newWindow) self.__actions.append(self.newAct) - # TODO: Private Window + self.newPrivateAct = E5Action( + self.tr('New Private Window'), + UI.PixmapCache.getIcon("privateMode.png"), + self.tr('New &Private Window'), + QKeySequence(self.tr("Ctrl+Shift+P", "File|New Private Window")), + 0, self, 'webbrowser_file_new_private_window') + self.newPrivateAct.setStatusTip(self.tr( + 'Open a new private web browser window')) + self.newPrivateAct.setWhatsThis(self.tr( + """<b>New Private Window</b>""" + """<p>This opens a new private web browser window by starting""" + """ a new web browser instance in private mode.</p>""" + )) + if not self.__initShortcutsOnly: + self.newPrivateAct.triggered.connect(self.newPrivateWindow) + self.__actions.append(self.newPrivateAct) self.openAct = E5Action( self.tr('Open File'), @@ -728,24 +749,6 @@ self.__tabWidget.closeAllBrowsers) self.__actions.append(self.closeAllAct) - # TODO: Private Browsing -## self.privateBrowsingAct = E5Action( -## self.tr('Private Browsing'), -## UI.PixmapCache.getIcon("privateBrowsing.png"), -## self.tr('Private &Browsing'), -## 0, 0, self, 'webbrowser_file_private_browsing') -## self.privateBrowsingAct.setStatusTip(self.tr('Private Browsing')) -## self.privateBrowsingAct.setWhatsThis(self.tr( -## """<b>Private Browsing</b>""" -## """<p>Enables private browsing. In this mode no history is""" -## """ recorded anymore.</p>""" -## )) -## if not self.__initShortcutsOnly: -## self.privateBrowsingAct.triggered.connect( -## self.__privateBrowsing) -## self.privateBrowsingAct.setCheckable(True) -## self.__actions.append(self.privateBrowsingAct) - self.exitAct = E5Action( self.tr('Quit'), UI.PixmapCache.getIcon("exit.png"), @@ -1749,6 +1752,7 @@ menu.setTearOffEnabled(True) menu.addAction(self.newTabAct) menu.addAction(self.newAct) + menu.addAction(self.newPrivateAct) menu.addAction(self.openAct) menu.addAction(self.openTabAct) menu.addSeparator() @@ -1918,6 +1922,7 @@ filetb.setIconSize(UI.Config.ToolBarIconSize) filetb.addAction(self.newTabAct) filetb.addAction(self.newAct) + filetb.addAction(self.newPrivateAct) filetb.addAction(self.openAct) filetb.addAction(self.openTabAct) filetb.addSeparator() @@ -2149,7 +2154,8 @@ """ Public slot called to open a new web browser window. - @param link file to be displayed in the new window (string or QUrl) + @param link URL to be displayed in the new window + @type str or QUrl """ if link is None: linkName = "" @@ -2158,10 +2164,45 @@ else: linkName = link h = WebBrowserWindow(linkName, ".", self.parent(), "webbrowser", - self.__fromEric) + self.__fromEric, private=self.isPrivate()) h.show() - # TODO: Private Window + @pyqtSlot() + def newPrivateWindow(self, link=None): + """ + Public slot called to open a new private web browser window. + + + @param link URL to be displayed in the new window + @type str or QUrl + """ + if link is None: + linkName = "" + elif isinstance(link, QUrl): + linkName = link.toString() + else: + linkName = link + + applPath = os.path.join(getConfig("ericDir"), "eric6_browser.py") + args = [] + args.append(applPath) + args.append("--config={0}".format(Utilities.getConfigDir())) + if self.__settingsDir: + args.append("--settings={0}".format(self.__settingsDir)) + args.append("--private") + if linkName: + args.append(linkName) + + if not os.path.isfile(applPath) or \ + not QProcess.startDetached(sys.executable, args): + E5MessageBox.critical( + self, + self.tr('New Private Window'), + self.tr( + '<p>Could not start the process.<br>' + 'Ensure that it is available as <b>{0}</b>.</p>' + ).format(applPath), + self.tr('OK')) def __openFile(self): """ @@ -2636,54 +2677,16 @@ Private slot to handle the select all action. """ self.currentBrowser().selectAll() - # TODO: Private Browsing -## -## def __privateBrowsing(self): -## """ -## Private slot to switch private browsing. -## """ -## settings = QWebSettings.globalSettings() -## pb = settings.testAttribute(QWebSettings.PrivateBrowsingEnabled) -## if not pb: -## txt = self.tr( -## """<b>Are you sure you want to turn on private""" -## """ browsing?</b><p>When private browsing is turned on,""" -## """ web pages are not added to the history, searches""" -## """ are not added to the list of recent searches and""" -## """ web site icons and cookies are not stored.""" -## """ HTML5 offline storage will be deactivated.""" -## """ Until you close the window, you can still click""" -## """ the Back and Forward buttons to return to the""" -## """ web pages you have opened.</p>""") -## res = E5MessageBox.yesNo(self, "", txt) -## if res: -## self.setPrivateMode(True) -## else: -## self.setPrivateMode(False) -## -## def setPrivateMode(self, on): -## """ -## Public method to set the privacy mode. -## -## @param on flag indicating the privacy state (boolean) -## """ -## QWebSettings.globalSettings().setAttribute( -## QWebSettings.PrivateBrowsingEnabled, on) -## if on: -## self.__setIconDatabasePath(False) -## else: -## self.__setIconDatabasePath(True) -## self.privateBrowsingAct.setChecked(on) -## self.privacyChanged.emit(on) - def isPrivate(self): + @classmethod + def isPrivate(cls): """ Public method to check the private browsing mode. @return flag indicating private browsing mode @rtype bool """ - return self.__isPrivate + return cls._isPrivate def currentBrowser(self): """
--- a/eric6_browser.py Sun Feb 28 18:49:24 2016 +0100 +++ b/eric6_browser.py Sun Feb 28 20:07:41 2016 +0100 @@ -48,6 +48,8 @@ .format(MIN_QT_VERSION)) sys.exit(100) +SettingsDir = None + for arg in sys.argv[:]: if arg.startswith("--config="): import Globals @@ -56,11 +58,11 @@ sys.argv.remove(arg) elif arg.startswith("--settings="): from PyQt5.QtCore import QSettings - settingsDir = os.path.expanduser(arg.replace("--settings=", "")) - if not os.path.isdir(settingsDir): - os.makedirs(settingsDir) + SettingsDir = os.path.expanduser(arg.replace("--settings=", "")) + if not os.path.isdir(SettingsDir): + os.makedirs(SettingsDir) QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, - settingsDir) + SettingsDir) sys.argv.remove(arg) # make ThirdParty package available as a packages repository @@ -102,7 +104,8 @@ home = "" browser = WebBrowserWindow(home, '.', None, 'web_browser', - searchWord=searchWord, private=private) + searchWord=searchWord, private=private, + settingsDir=SettingsDir) return browser