]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add a WebEngine Default user agent.
authorSoren Stoutner <soren@stoutner.com>
Tue, 12 Apr 2022 20:29:06 +0000 (13:29 -0700)
committerSoren Stoutner <soren@stoutner.com>
Tue, 12 Apr 2022 20:29:06 +0000 (13:29 -0700)
src/dialogs/DomainSettingsDialog.cpp
src/helpers/UserAgentHelper.cpp
src/helpers/UserAgentHelper.h
src/ui.rc/browser_ui.rc
src/ui/DomainSettingsDialog.ui
src/ui/SettingsPrivacy.ui
src/views/BrowserView.cpp
src/views/BrowserView.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index b7f2c93416038293e5ff79a637a3987735238d5d..b5be32a29effaf1d99607a45b44512889ac54725 100644 (file)
@@ -391,7 +391,7 @@ void DomainSettingsDialog::populateUserAgentLabel(const QString &userAgentName)
     if (userAgentName == UserAgentHelper::SYSTEM_DEFAULT_TRANSLATED)
     {
         // Display the system default user agent name.
-        userAgentLabelPointer->setText(UserAgentHelper::getTranslatedUserAgentName(Settings::userAgent()));
+        userAgentLabelPointer->setText(UserAgentHelper::getTranslatedUserAgentNameFromDatabaseName(Settings::userAgent()));
     }
     else
     {
@@ -508,7 +508,7 @@ void DomainSettingsDialog::userAgentChanged(const QString &updatedUserAgent) con
 {
     // Update the domains table model.
     domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)),
-                                      UserAgentHelper::getDatabaseUserAgentName(updatedUserAgent));
+                                      UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(updatedUserAgent));
 
     // Populate the user agent label.
     populateUserAgentLabel(updatedUserAgent);
index 1b02146c370820c4ce5e581c82836ce4f5fb8866..9a51f227679962cbd6588b8fa6bb61de6c822835 100644 (file)
@@ -20,6 +20,7 @@
 // Application headers.
 #include "Settings.h"
 #include "UserAgentHelper.h"
+#include "views/BrowserView.h"
 
 // KDE Framework headers.
 #include <KLocalizedString>
@@ -27,6 +28,7 @@
 // Define the public database constants.
 const QString UserAgentHelper::SYSTEM_DEFAULT_DATABASE = QStringLiteral("System Default");
 const QString UserAgentHelper::PRIVACY_BROWSER_DATABASE = QStringLiteral("Privacy Browser");
+const QString UserAgentHelper::WEB_ENGINE_DEFAULT_DATABASE = QStringLiteral("WebEngine Default");
 const QString UserAgentHelper::FIREFOX_LINUX_DATABASE = QStringLiteral("Firefox Linux");
 const QString UserAgentHelper::CHROMIUM_LINUX_DATABASE = QStringLiteral("Chromium Linux");
 const QString UserAgentHelper::FIREFOX_WINDOWS_DATABASE = QStringLiteral("Firefox Windows");
@@ -37,6 +39,7 @@ const QString UserAgentHelper::SAFARI_MACOS_DATABASE = QStringLiteral("Safari ma
 // Define the public translated constants.
 const QString UserAgentHelper::SYSTEM_DEFAULT_TRANSLATED = i18n("System default");
 const QString UserAgentHelper::PRIVACY_BROWSER_TRANSLATED = i18n("Privacy Browser");
+const QString UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED = i18n("WebEngine default");
 const QString UserAgentHelper::FIREFOX_LINUX_TRANSLATED = i18n("Firefox on Linux");
 const QString UserAgentHelper::CHROMIUM_LINUX_TRANSLATED = i18n("Chromium on Linux");
 const QString UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED = i18n("Firefox on Windows");
@@ -56,9 +59,40 @@ const QString UserAgentHelper::SAFARI_MACOS_USER_AGENT = QStringLiteral("Mozilla
 // The default constructor.
 UserAgentHelper::UserAgentHelper() {};
 
+QString UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(const QString &translatedUserAgentName)
+{
+    // Return the database user agent name.
+    if (translatedUserAgentName == SYSTEM_DEFAULT_TRANSLATED) return SYSTEM_DEFAULT_DATABASE;  // System Default.
+    else if (translatedUserAgentName == PRIVACY_BROWSER_TRANSLATED) return PRIVACY_BROWSER_DATABASE;  // Privacy Browser.
+    else if (translatedUserAgentName == WEB_ENGINE_DEFAULT_TRANSLATED) return WEB_ENGINE_DEFAULT_DATABASE;  // WebEngine default.
+    else if (translatedUserAgentName == FIREFOX_LINUX_TRANSLATED) return FIREFOX_LINUX_DATABASE;  // Firefox Linux.
+    else if (translatedUserAgentName == CHROMIUM_LINUX_TRANSLATED) return CHROMIUM_LINUX_DATABASE;  // Chromium Linux.
+    else if (translatedUserAgentName == FIREFOX_WINDOWS_TRANSLATED) return FIREFOX_WINDOWS_DATABASE;  // Firefox Windows.
+    else if (translatedUserAgentName == CHROME_WINDOWS_TRANSLATED) return CHROME_WINDOWS_DATABASE;  // Chrome Windows.
+    else if (translatedUserAgentName == EDGE_WINDOWS_TRANSLATED) return EDGE_WINDOWS_DATABASE;  // Edge Windows.
+    else if (translatedUserAgentName == SAFARI_MACOS_TRANSLATED) return SAFARI_MACOS_DATABASE;  // Safari macOS.
+    else return translatedUserAgentName;  // Return the custom user agent.
+}
+
+int UserAgentHelper::getDomainSettingsUserAgentIndex(const QString &userAgentName)
+{
+    // Return the domain settings user agent index.
+    if (userAgentName == SYSTEM_DEFAULT_DATABASE) return 0;  // System Default.
+    else if (userAgentName == PRIVACY_BROWSER_DATABASE) return 1;  // Privacy Browser.
+    else if (userAgentName == WEB_ENGINE_DEFAULT_DATABASE) return 2;  // WebEngine default.
+    else if (userAgentName == FIREFOX_LINUX_DATABASE) return 3;  // Firefox Linux.
+    else if (userAgentName == CHROMIUM_LINUX_DATABASE) return 4;  // Chromium Linux.
+    else if (userAgentName == FIREFOX_WINDOWS_DATABASE) return 5;  // Firefox Windows.
+    else if (userAgentName == CHROME_WINDOWS_DATABASE) return 6;  // Chrome Windows.
+    else if (userAgentName == EDGE_WINDOWS_DATABASE) return 7;  // Edge Windows.
+    else if (userAgentName == SAFARI_MACOS_DATABASE) return 8;  // Safari macOS.
+    else return -1;  // Custom user agent.
+}
+
 QString UserAgentHelper::getUserAgentFromDatabaseName(const QString &userAgentDatabaseName)
 {
     if (userAgentDatabaseName == PRIVACY_BROWSER_DATABASE) return PRIVACY_BROWSER_USER_AGENT;  // Privacy Browser.
+    else if (userAgentDatabaseName == WEB_ENGINE_DEFAULT_DATABASE) return BrowserView::webEngineDefaultUserAgent;  // WebEngine default.
     else if (userAgentDatabaseName == FIREFOX_LINUX_DATABASE) return FIREFOX_LINUX_USER_AGENT;  // Firefox Linux.
     else if (userAgentDatabaseName == CHROMIUM_LINUX_DATABASE) return CHROMIUM_LINUX_USER_AGENT;  // Chromium Linux.
     else if (userAgentDatabaseName == FIREFOX_WINDOWS_DATABASE) return FIREFOX_WINDOWS_USER_AGENT;  // Firefox Windows.
@@ -71,6 +105,7 @@ QString UserAgentHelper::getUserAgentFromDatabaseName(const QString &userAgentDa
 QString UserAgentHelper::getUserAgentFromTranslatedName(const QString &userAgentTranslatedName)
 {
     if (userAgentTranslatedName == PRIVACY_BROWSER_TRANSLATED) return PRIVACY_BROWSER_USER_AGENT;  // Privacy Browser.
+    else if (userAgentTranslatedName == WEB_ENGINE_DEFAULT_TRANSLATED) return BrowserView::webEngineDefaultUserAgent;  // WebEngine default.
     else if (userAgentTranslatedName == FIREFOX_LINUX_TRANSLATED) return FIREFOX_LINUX_USER_AGENT;  // Firefox on Linux.
     else if (userAgentTranslatedName == CHROMIUM_LINUX_TRANSLATED) return CHROMIUM_LINUX_USER_AGENT;  // Chromium on Linux.
     else if (userAgentTranslatedName == FIREFOX_WINDOWS_TRANSLATED) return FIREFOX_WINDOWS_USER_AGENT;  // Firefox on Windows.
@@ -80,45 +115,18 @@ QString UserAgentHelper::getUserAgentFromTranslatedName(const QString &userAgent
     else return userAgentTranslatedName;  // Return the custom user agent.
 }
 
-QString UserAgentHelper::getDatabaseUserAgentName(const QString &translatedUserAgentName)
-{
-    // Return the database user agent name.
-    if (translatedUserAgentName == SYSTEM_DEFAULT_TRANSLATED) return SYSTEM_DEFAULT_DATABASE;  // System Default.
-    else if (translatedUserAgentName == PRIVACY_BROWSER_TRANSLATED) return PRIVACY_BROWSER_DATABASE;  // Privacy Browser.
-    else if (translatedUserAgentName == FIREFOX_LINUX_TRANSLATED) return FIREFOX_LINUX_DATABASE;  // Firefox Linux.
-    else if (translatedUserAgentName == CHROMIUM_LINUX_TRANSLATED) return CHROMIUM_LINUX_DATABASE;  // Chromium Linux.
-    else if (translatedUserAgentName == FIREFOX_WINDOWS_TRANSLATED) return FIREFOX_WINDOWS_DATABASE;  // Firefox Windows.
-    else if (translatedUserAgentName == CHROME_WINDOWS_TRANSLATED) return CHROME_WINDOWS_DATABASE;  // Chrome Windows.
-    else if (translatedUserAgentName == EDGE_WINDOWS_TRANSLATED) return EDGE_WINDOWS_DATABASE;  // Edge Windows.
-    else if (translatedUserAgentName == SAFARI_MACOS_TRANSLATED) return SAFARI_MACOS_DATABASE;  // Safari macOS.
-    else return translatedUserAgentName;  // Return the custom user agent.
-}
-
-int UserAgentHelper::getDomainSettingsUserAgentIndex(const QString &userAgentName)
-{
-    // Return the domain settings user agent index.
-    if (userAgentName == SYSTEM_DEFAULT_DATABASE) return 0;  // System Default.
-    else if (userAgentName == PRIVACY_BROWSER_DATABASE) return 1;  // Privacy Browser.
-    else if (userAgentName == FIREFOX_LINUX_DATABASE) return 2;  // Firefox Linux.
-    else if (userAgentName == CHROMIUM_LINUX_DATABASE) return 3;  // Chromium Linux.
-    else if (userAgentName == FIREFOX_WINDOWS_DATABASE) return 4;  // Firefox Windows.
-    else if (userAgentName == CHROME_WINDOWS_DATABASE) return 5;  // Chrome Windows.
-    else if (userAgentName == EDGE_WINDOWS_DATABASE) return 6;  // Edge Windows.
-    else if (userAgentName == SAFARI_MACOS_DATABASE) return 7;  // Safari macOS.
-    else return -1;  // Custom user agent.
-}
-
 QString UserAgentHelper::getResultingDomainSettingsUserAgent(const QString &rawUserAgent)
 {
-    // Return the resulting user agent.
+    // Return the resulting user agent.  If `System default` is selected, it looks up the default user agent from the settings.
     if (rawUserAgent == SYSTEM_DEFAULT_DATABASE) return getUserAgentFromDatabaseName(Settings::userAgent());  // Return the default user agent.
     else return getUserAgentFromDatabaseName(rawUserAgent);  // Return the domain user agent.
 }
 
-QString UserAgentHelper::getTranslatedUserAgentName(const QString &userAgentName)
+QString UserAgentHelper::getTranslatedUserAgentNameFromDatabaseName(const QString &userAgentName)
 {
     // Return the translated user agent name.
     if (userAgentName == PRIVACY_BROWSER_DATABASE) return PRIVACY_BROWSER_TRANSLATED;  // Privacy Browser.
+    else if (userAgentName == WEB_ENGINE_DEFAULT_DATABASE) return WEB_ENGINE_DEFAULT_TRANSLATED;  // WebEngine default.
     else if (userAgentName == FIREFOX_LINUX_DATABASE) return FIREFOX_LINUX_TRANSLATED;  // Firefox on Linux.
     else if (userAgentName == CHROMIUM_LINUX_DATABASE) return CHROMIUM_LINUX_TRANSLATED;  // Chromium on Linux.
     else if (userAgentName == FIREFOX_WINDOWS_DATABASE) return FIREFOX_WINDOWS_TRANSLATED;  // Firefox on Windows.
index 1043d372b3920973a30c11d91b123684b6298522..839a5ed917f8dc2414719e9ead9e5cb033a55d98 100644 (file)
@@ -53,13 +53,15 @@ public:
     static const QString SAFARI_MACOS_USER_AGENT;
     static const QString SYSTEM_DEFAULT_DATABASE;
     static const QString SYSTEM_DEFAULT_TRANSLATED;
+    static const QString WEB_ENGINE_DEFAULT_DATABASE;
+    static const QString WEB_ENGINE_DEFAULT_TRANSLATED;
 
     // The public functions.
+    static QString getDatabaseUserAgentNameFromTranslatedName(const QString &translatedUserAgentName);
+    static int getDomainSettingsUserAgentIndex(const QString &userAgentName);
     static QString getUserAgentFromDatabaseName(const QString &userAgentDatabaseName);
     static QString getUserAgentFromTranslatedName(const QString &userAgentTranslatedName);
-    static QString getDatabaseUserAgentName(const QString &translatedUserAgentName);
-    static int getDomainSettingsUserAgentIndex(const QString &userAgentName);
     static QString getResultingDomainSettingsUserAgent(const QString &rawUserAgent);
-    static QString getTranslatedUserAgentName(const QString &userAgentName);
+    static QString getTranslatedUserAgentNameFromDatabaseName(const QString &userAgentName);
 };
 #endif
index dbbeb317f140e08a83ddc694b464c1f0ade984ac..0e1d60b2ddd2c9c451c1f7f2b4fa42c2c44540b9 100644 (file)
@@ -32,6 +32,7 @@
         <Menu name="on_the_fly_settings"> <text>On-The-Fly Settings</text>
             <Menu name="user_agent" icon="user-group-properties"> <text>User Agent</text>
                 <Action name="user_agent_privacy_browser" />
+                <Action name="user_agent_webengine_default" />
                 <Action name="user_agent_firefox_linux" />
                 <Action name="user_agent_chromium_linux" />
                 <Action name="user_agent_firefox_windows" />
index 0b2f56f5e4ba1dabbb927562f312baaa4e0b317d..c39047ce5249e21c45e9a9d0620779dcf13e07ed 100644 (file)
                                             </property>
                                         </item>
 
+                                        <item>
+                                            <property name="text">
+                                                <string>WebEngine default</string>
+                                            </property>
+                                        </item>
+
                                         <item>
                                             <property name="text">
                                                 <string>Firefox on Linux</string>
index a1445b6c345e99dd43be42fc2cd13f96376d5089..6fa7c5be393361d83c4c8716f1f663cc7ff8a77b 100644 (file)
                         </property>
                     </item>
 
+                    <item>
+                        <property name="text">
+                            <string>WebEngine Default</string>
+                        </property>
+                    </item>
+
                     <item>
                         <property name="text">
                             <string>Firefox Linux</string>
index fb2473a6977c406deb3221bcadac4ca5394409d9..2e29ea0caf9fd515690e9205f498cdd621659c20 100644 (file)
@@ -32,6 +32,9 @@
 #include <QAction>
 #include <QWebEngineProfile>
 
+// Initialize the public static variables.
+QString BrowserView::webEngineDefaultUserAgent = QStringLiteral("");
+
 BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
 {
     // Instantiate the browser view UI.
@@ -56,6 +59,9 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     webEngineHistoryPointer = webEnginePagePointer->history();
     webEngineSettingsPointer = webEngineViewPointer->settings();
 
+    // Store a copy of the WebEngine default user agent.
+    webEngineDefaultUserAgent = webEngineProfilePointer->httpUserAgent();
+
     // Update the URL line edit when the URL changes.
     connect(webEngineViewPointer, SIGNAL(urlChanged(const QUrl)), this, SLOT(updateUrl(const QUrl)));
 
index 3c3bd7db9bb33e392abde39354d5610900736f47..d61ceaefd8b371694561e3d887e442b4730e9a56 100644 (file)
@@ -44,6 +44,9 @@ public:
     void toggleJavaScript() const;
     void toggleLocalStorage() const;
 
+    // The public static variables.
+    static QString webEngineDefaultUserAgent;
+
 signals:
     // The signals.
     void hideProgressBar() const;
index 44614194b78b1e75621316ed4afc52ff5d541781..a29b5037c83af5ae69dcfd9f146228fc96f0e251 100644 (file)
@@ -56,6 +56,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
 
     // Add the custom actions.
     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
+    userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
     userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
     userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
     userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
@@ -81,6 +82,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
 
     // Add the actions to the groups.
     userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
     userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
     userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
     userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
@@ -98,6 +100,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
 
     // Set some actions to be checkable.
     userAgentPrivacyBrowserActionPointer->setCheckable(true);
+    userAgentWebEngineDefaultActionPointer->setCheckable(true);
     userAgentFirefoxLinuxActionPointer->setCheckable(true);
     userAgentChromiumLinuxActionPointer->setCheckable(true);
     userAgentFirefoxWindowsActionPointer->setCheckable(true);
@@ -115,6 +118,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
 
     // Set the non-mutable action text.
     userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
+    userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED);
     userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
     userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
     userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
@@ -133,6 +137,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
 
     // Set the action icons.
     userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
+    userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
     userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
     userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
     userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
@@ -552,6 +557,7 @@ void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
 
     // Check the indicated on-the-fly user agent.
     if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true);  // Privacy Browser.
+    else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true);  // WebEngine default.
     else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true);  // Firefox Linux.
     else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true);  // Chromium Linux.
     else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true);  // Firefox Windows.
index e4eee69a012b28324069c4c72f4a0f1649b9f0ec..5be55f489ed6dda00f38bc2e1c7b093ff0eb0ced 100644 (file)
@@ -91,6 +91,7 @@ private:
     QAction *searchEngineCustomActionPointer;
     QLabel *userAgentLabelPointer;
     QAction *userAgentPrivacyBrowserActionPointer;
+    QAction *userAgentWebEngineDefaultActionPointer;
     QAction *userAgentFirefoxLinuxActionPointer;
     QAction *userAgentChromiumLinuxActionPointer;
     QAction *userAgentFirefoxWindowsActionPointer;