JavaScriptEnabled: Added a configuration option to globally disable/enable JavaScript support.

Fri, 16 Feb 2018 20:11:36 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 16 Feb 2018 20:11:36 +0100
changeset 6151
29564aad2f97
parent 6150
20efcd29b237
child 6152
a98925d5a214

JavaScriptEnabled: Added a configuration option to globally disable/enable JavaScript support.

Preferences/ConfigurationPages/WebBrowserPage.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/WebBrowserPage.ui file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
WebBrowser/StatusBar/JavaScriptIcon.py file | annotate | diff | comparison | revisions
WebBrowser/StatusBar/JavaScriptSettingsDialog.py file | annotate | diff | comparison | revisions
WebBrowser/StatusBar/JavaScriptSettingsDialog.ui file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
--- a/Preferences/ConfigurationPages/WebBrowserPage.py	Thu Feb 15 19:05:22 2018 +0100
+++ b/Preferences/ConfigurationPages/WebBrowserPage.py	Fri Feb 16 20:11:36 2018 +0100
@@ -74,6 +74,8 @@
             self.screenCaptureCheckBox.setEnabled(False)
             self.webGLCheckBox.setEnabled(False)
         
+        self.javaScriptGroup.setChecked(
+            Preferences.getWebBrowser("JavaScriptEnabled"))
         self.jsOpenWindowsCheckBox.setChecked(
             Preferences.getWebBrowser("JavaScriptCanOpenWindows"))
         try:
@@ -239,6 +241,9 @@
                 self.webGLCheckBox.isChecked())
         
         Preferences.setWebBrowser(
+            "JavaScriptEnabled",
+            self.javaScriptGroup.isChecked())
+        Preferences.setWebBrowser(
             "JavaScriptCanOpenWindows",
             self.jsOpenWindowsCheckBox.isChecked())
         if self.jsActivateWindowsCheckBox.isEnabled():
--- a/Preferences/ConfigurationPages/WebBrowserPage.ui	Thu Feb 15 19:05:22 2018 +0100
+++ b/Preferences/ConfigurationPages/WebBrowserPage.ui	Fri Feb 16 20:11:36 2018 +0100
@@ -378,10 +378,13 @@
       <item>
        <widget class="QGroupBox" name="javaScriptGroup">
         <property name="toolTip">
-         <string/>
+         <string>Select to enable JavaScript support</string>
         </property>
         <property name="title">
-         <string>JavaScript</string>
+         <string>Enable JavaScript</string>
+        </property>
+        <property name="checkable">
+         <bool>true</bool>
         </property>
         <layout class="QVBoxLayout" name="verticalLayout_2">
          <item>
@@ -960,6 +963,7 @@
   <tabstop>saveSessionCheckBox</tabstop>
   <tabstop>sessionTimerSpinBox</tabstop>
   <tabstop>defaultSchemeCombo</tabstop>
+  <tabstop>javaScriptGroup</tabstop>
   <tabstop>jsOpenWindowsCheckBox</tabstop>
   <tabstop>jsActivateWindowsCheckBox</tabstop>
   <tabstop>jsClipboardCheckBox</tabstop>
--- a/Preferences/__init__.py	Thu Feb 15 19:05:22 2018 +0100
+++ b/Preferences/__init__.py	Fri Feb 16 20:11:36 2018 +0100
@@ -1191,6 +1191,8 @@
             
             "AutoLoadImages": webEngineSettings.testAttribute(
                 QWebEngineSettings.AutoLoadImages),
+            "JavaScriptEnabled": webEngineSettings.testAttribute(
+                QWebEngineSettings.JavascriptEnabled),
             "JavaScriptCanOpenWindows": webEngineSettings.testAttribute(
                 QWebEngineSettings.JavascriptCanOpenWindows),
             "JavaScriptCanAccessClipboard": webEngineSettings.testAttribute(
@@ -2988,7 +2990,8 @@
         return int(prefClass.settings.value(
             "WebBrowser/" + key, prefClass.webBrowserDefaults[key]))
     elif key in ["SingleWebBrowserWindow", "SaveGeometry",
-                 "JavaScriptCanOpenWindows", "JavaScriptCanAccessClipboard",
+                 "JavaScriptEnabled", "JavaScriptCanOpenWindows",
+                 "JavaScriptCanAccessClipboard",
                  "AutoLoadImages", "LocalStorageEnabled",
                  "SpatialNavigationEnabled", "LinksIncludedInFocusChain",
                  "LocalContentCanAccessRemoteUrls",
--- a/WebBrowser/StatusBar/JavaScriptIcon.py	Thu Feb 15 19:05:22 2018 +0100
+++ b/WebBrowser/StatusBar/JavaScriptIcon.py	Fri Feb 16 20:11:36 2018 +0100
@@ -14,7 +14,7 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSlot, Qt, QPoint
+from PyQt5.QtCore import pyqtSlot, Qt, QPoint, QTimer
 from PyQt5.QtWidgets import QGraphicsColorizeEffect, QMenu, QDialog
 from PyQt5.QtWebEngineWidgets import QWebEngineSettings
 
@@ -134,6 +134,7 @@
         dlg = JavaScriptSettingsDialog(self._window)
         if dlg.exec_() == QDialog.Accepted:
             self._window.preferencesChanged()
+            QTimer.singleShot(500, self.__updateIcon)
     
     def __navigationRequestAccepted(self, url, navigationType, isMainFrame,
                                     page):
--- a/WebBrowser/StatusBar/JavaScriptSettingsDialog.py	Thu Feb 15 19:05:22 2018 +0100
+++ b/WebBrowser/StatusBar/JavaScriptSettingsDialog.py	Fri Feb 16 20:11:36 2018 +0100
@@ -34,8 +34,17 @@
         super(JavaScriptSettingsDialog, self).__init__(parent)
         self.setupUi(self)
         
+        self.javaScriptGroup.setChecked(
+            Preferences.getWebBrowser("JavaScriptEnabled"))
         self.jsOpenWindowsCheckBox.setChecked(
             Preferences.getWebBrowser("JavaScriptCanOpenWindows"))
+        try:
+            # Qt 5.10
+            self.jsActivateWindowsCheckBox.setChecked(
+                Preferences.getWebBrowser(
+                    "AllowWindowActivationFromJavaScript"))
+        except KeyError:
+            self.jsActivateWindowsCheckBox.setEnabled(False)
         self.jsClipboardCheckBox.setChecked(
             Preferences.getWebBrowser("JavaScriptCanAccessClipboard"))
         
@@ -48,8 +57,15 @@
         Public slot to accept the dialog.
         """
         Preferences.setWebBrowser(
+            "JavaScriptEnabled",
+            self.javaScriptGroup.isChecked())
+        Preferences.setWebBrowser(
             "JavaScriptCanOpenWindows",
             self.jsOpenWindowsCheckBox.isChecked())
+        if self.jsActivateWindowsCheckBox.isEnabled():
+            Preferences.setWebBrowser(
+                "AllowWindowActivationFromJavaScript",
+                self.jsActivateWindowsCheckBox.isChecked())
         Preferences.setWebBrowser(
             "JavaScriptCanAccessClipboard",
             self.jsClipboardCheckBox.isChecked())
--- a/WebBrowser/StatusBar/JavaScriptSettingsDialog.ui	Thu Feb 15 19:05:22 2018 +0100
+++ b/WebBrowser/StatusBar/JavaScriptSettingsDialog.ui	Fri Feb 16 20:11:36 2018 +0100
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>400</width>
-    <height>87</height>
+    <height>179</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -18,23 +18,48 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QCheckBox" name="jsOpenWindowsCheckBox">
+    <widget class="QGroupBox" name="javaScriptGroup">
      <property name="toolTip">
-      <string>Select to allow JavaScript to open windows</string>
+      <string>Select to enable JavaScript support</string>
      </property>
-     <property name="text">
-      <string>JavaScript can open windows</string>
+     <property name="title">
+      <string>Enable JavaScript</string>
+     </property>
+     <property name="checkable">
+      <bool>true</bool>
      </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QCheckBox" name="jsClipboardCheckBox">
-     <property name="toolTip">
-      <string>Select to allow JavaScript to access the clipboard</string>
-     </property>
-     <property name="text">
-      <string>JavaScript can access clipboard</string>
-     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <widget class="QCheckBox" name="jsOpenWindowsCheckBox">
+        <property name="toolTip">
+         <string>Select to allow JavaScript to open windows</string>
+        </property>
+        <property name="text">
+         <string>Allow to open windows</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QCheckBox" name="jsActivateWindowsCheckBox">
+        <property name="toolTip">
+         <string>Select to allow JavaScript to activate windows</string>
+        </property>
+        <property name="text">
+         <string>Allow to activate windows</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QCheckBox" name="jsClipboardCheckBox">
+        <property name="toolTip">
+         <string>Select to allow JavaScript to access the clipboard</string>
+        </property>
+        <property name="text">
+         <string>Allow to access the clipboard</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
     </widget>
    </item>
    <item>
--- a/WebBrowser/WebBrowserWindow.py	Thu Feb 15 19:05:22 2018 +0100
+++ b/WebBrowser/WebBrowserWindow.py	Fri Feb 16 20:11:36 2018 +0100
@@ -570,10 +570,9 @@
         settings.setAttribute(
             QWebEngineSettings.AutoLoadImages,
             Preferences.getWebBrowser("AutoLoadImages"))
-        # TODO: make this configurable as it is overwritten for pages that need it enabled
         settings.setAttribute(
             QWebEngineSettings.JavascriptEnabled,
-            True)
+            Preferences.getWebBrowser("JavaScriptEnabled"))
         # JavaScript is needed for the web browser functionality
         settings.setAttribute(
             QWebEngineSettings.JavascriptCanOpenWindows,

eric ide

mercurial