Custom browser feature for Linux/macOS

* Also move "search in all databases" to the general tab
This commit is contained in:
varjolintu 2020-05-17 22:44:52 +03:00 committed by Jonathan White
parent d863496f62
commit 43c82ccb09
9 changed files with 378 additions and 79 deletions

View File

@ -182,6 +182,36 @@ void BrowserSettings::setCustomProxyLocation(const QString& location)
config()->set(Config::Browser_CustomProxyLocation, location);
}
bool BrowserSettings::customBrowserSupport()
{
return config()->get(Config::Browser_UseCustomBrowser).toBool();
}
void BrowserSettings::setCustomBrowserSupport(bool enabled)
{
config()->set(Config::Browser_UseCustomBrowser, enabled);
}
int BrowserSettings::customBrowserType()
{
return config()->get(Config::Browser_CustomBrowserType).toInt();
}
void BrowserSettings::setCustomBrowserType(int type)
{
config()->set(Config::Browser_CustomBrowserType, type);
}
QString BrowserSettings::customBrowserLocation()
{
return config()->get(Config::Browser_CustomBrowserLocation).toString();
}
void BrowserSettings::setCustomBrowserLocation(const QString& location)
{
config()->set(Config::Browser_CustomBrowserLocation, location);
}
QString BrowserSettings::proxyLocation()
{
return m_nativeMessageInstaller.getProxyPath();

View File

@ -75,7 +75,12 @@ public:
bool browserSupport(BrowserShared::SupportedBrowsers browser);
void setBrowserSupport(BrowserShared::SupportedBrowsers browser, bool enabled);
bool customBrowserSupport();
void setCustomBrowserSupport(bool enabled);
int customBrowserType();
void setCustomBrowserType(int type);
QString customBrowserLocation();
void setCustomBrowserLocation(const QString& location);
bool passwordUseNumbers();
void setPasswordUseNumbers(bool useNumbers);
bool passwordUseLowercase();

View File

@ -57,8 +57,20 @@ BrowserSettingsWidget::BrowserSettingsWidget(QWidget* parent)
m_ui->tabWidget->setEnabled(m_ui->enableBrowserSupport->isChecked());
connect(m_ui->enableBrowserSupport, SIGNAL(toggled(bool)), m_ui->tabWidget, SLOT(setEnabled(bool)));
// Custom Browser option
#ifdef Q_OS_WIN
// TODO: Custom browser is disabled on Windows
m_ui->customBrowserSupport->setVisible(false);
m_ui->customBrowserGroupBox->setVisible(false);
#else
connect(m_ui->customBrowserLocationBrowseButton, SIGNAL(clicked()), SLOT(showCustomBrowserLocationFileDialog()));
connect(m_ui->customBrowserSupport, SIGNAL(toggled(bool)), m_ui->customBrowserGroupBox, SLOT(setEnabled(bool)));
#endif
// Custom Proxy option
m_ui->customProxyLocation->setEnabled(m_ui->useCustomProxy->isChecked());
m_ui->customProxyLocationBrowseButton->setEnabled(m_ui->useCustomProxy->isChecked());
connect(m_ui->useCustomProxy, SIGNAL(toggled(bool)), m_ui->customProxyLocation, SLOT(setEnabled(bool)));
connect(m_ui->useCustomProxy, SIGNAL(toggled(bool)), m_ui->customProxyLocationBrowseButton, SLOT(setEnabled(bool)));
connect(m_ui->useCustomProxy, SIGNAL(toggled(bool)), SLOT(validateCustomProxyLocation()));
@ -150,6 +162,9 @@ void BrowserSettingsWidget::loadSettings()
m_ui->browsersGroupBox->setEnabled(false);
m_ui->updateBinaryPath->setChecked(false);
m_ui->updateBinaryPath->setVisible(false);
// No custom browser for snaps
m_ui->customBrowserSupport->setVisible(false);
m_ui->customBrowserGroupBox->setVisible(false);
// Show notice to user
m_ui->browserGlobalWarningWidget->showMessage(tr("Please see special instructions for browser extension use below"),
MessageWidget::Warning);
@ -157,6 +172,18 @@ void BrowserSettingsWidget::loadSettings()
m_ui->browserGlobalWarningWidget->setAutoHideTimeout(-1);
#endif
const auto customBrowserSet = settings->customBrowserSupport();
m_ui->customBrowserSupport->setChecked(customBrowserSet);
m_ui->customBrowserGroupBox->setEnabled(customBrowserSet);
m_ui->browserTypeComboBox->clear();
m_ui->browserTypeComboBox->addItem(tr("Firefox"), BrowserShared::SupportedBrowsers::FIREFOX);
m_ui->browserTypeComboBox->addItem(tr("Chromium"), BrowserShared::SupportedBrowsers::CHROMIUM);
auto typeIndex = m_ui->browserTypeComboBox->findData(settings->customBrowserType());
if (typeIndex >= 0) {
m_ui->browserTypeComboBox->setCurrentIndex(typeIndex);
}
m_ui->customBrowserLocation->setText(settings->customBrowserLocation());
#ifdef QT_DEBUG
m_ui->customExtensionId->setText(settings->customExtensionId());
#endif
@ -211,6 +238,18 @@ void BrowserSettingsWidget::saveSettings()
settings->setBrowserSupport(BrowserShared::BRAVE, m_ui->braveSupport->isChecked());
settings->setBrowserSupport(BrowserShared::VIVALDI, m_ui->vivaldiSupport->isChecked());
settings->setBrowserSupport(BrowserShared::TOR_BROWSER, m_ui->torBrowserSupport->isChecked());
// Custom browser settings
bool customBrowserEnabled = m_ui->customBrowserSupport->isChecked();
settings->setCustomBrowserType(m_ui->browserTypeComboBox->currentData().toInt());
settings->setCustomBrowserLocation(m_ui->customBrowserLocation->text());
settings->setCustomBrowserSupport(customBrowserEnabled);
settings->setBrowserSupport(BrowserShared::CUSTOM, customBrowserEnabled);
// If we disabled the custom browser support make sure to clear variables
if (!customBrowserEnabled) {
settings->setCustomBrowserLocation("");
}
#endif
}
@ -228,3 +267,13 @@ void BrowserSettingsWidget::showProxyLocationFileDialog()
m_ui->customProxyLocation->setText(proxyLocation);
validateCustomProxyLocation();
}
void BrowserSettingsWidget::showCustomBrowserLocationFileDialog()
{
auto location = QFileDialog::getExistingDirectory(this,
tr("Select native messaging host folder location"),
QFileInfo(QCoreApplication::applicationDirPath()).filePath());
if (!location.isEmpty()) {
m_ui->customBrowserLocation->setText(location);
}
}

View File

@ -42,6 +42,7 @@ public slots:
private slots:
void showProxyLocationFileDialog();
void validateCustomProxyLocation();
void showCustomBrowserLocationFileDialog();
private:
QScopedPointer<Ui::BrowserSettingsWidget> m_ui;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>523</width>
<height>456</height>
<width>584</width>
<height>467</height>
</rect>
</property>
<property name="windowTitle">
@ -84,23 +84,20 @@
<property name="horizontalSpacing">
<number>40</number>
</property>
<item row="0" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>179</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chromeSupport">
<item row="1" column="1">
<widget class="QCheckBox" name="vivaldiSupport">
<property name="text">
<string>Google Chrome</string>
<string>Vivaldi</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="edgeSupport">
<property name="text">
<string>&amp;Edge</string>
</property>
<property name="checked">
<bool>false</bool>
@ -117,26 +114,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="chromiumSupport">
<property name="text">
<string>Chromium</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="vivaldiSupport">
<property name="text">
<string>Vivaldi</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="torBrowserSupport">
<property name="text">
@ -157,16 +134,39 @@
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="edgeSupport">
<item row="0" column="0">
<widget class="QCheckBox" name="chromeSupport">
<property name="text">
<string>&amp;Edge</string>
<string>Google Chrome</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="chromiumSupport">
<property name="text">
<string>Chromium</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -236,6 +236,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="searchInAllDatabases">
<property name="toolTip">
<string>All databases connected to the extension will return matching credentials.</string>
</property>
<property name="text">
<string extracomment="Credentials mean login data requested via browser extension">Search in all opened databases for matching credentials</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="sortByTitle">
<property name="text">
@ -301,16 +311,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="searchInAllDatabases">
<property name="toolTip">
<string>All databases connected to the extension will return matching credentials.</string>
</property>
<property name="text">
<string extracomment="Credentials mean login data requested via browser extension">Search in all opened databases for matching credentials</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="supportKphFields">
<property name="toolTip">
@ -347,14 +347,42 @@
<string>Use a custom proxy location if you installed a proxy manually.</string>
</property>
<property name="text">
<string comment="Meant is the proxy for KeePassXC-Browser">Use a custom proxy location</string>
<string comment="Meant is the proxy for KeePassXC-Browser">Use a custom proxy location:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>15</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="customProxyLocation">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>450</width>
<height>0</height>
</size>
</property>
<property name="accessibleName">
<string>Custom proxy location field</string>
</property>
@ -376,12 +404,155 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="customExtensionBox">
<widget class="QCheckBox" name="customBrowserSupport">
<property name="text">
<string>Use a custom browser configuration location:</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="customBrowserGroupBox">
<property name="title">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="customBrowserLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">margin-right: 5px</string>
</property>
<property name="text">
<string>Browser type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="browserTypeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Toolbar button style</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="customBrowserLabel_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">margin-right: 5px</string>
</property>
<property name="text">
<string>Config Location:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="customBrowserLocation">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>350</width>
<height>0</height>
</size>
</property>
<property name="accessibleName">
<string>Custom browser location field</string>
</property>
<property name="maxLength">
<number>999</number>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="placeholderText">
<string>~/.custom/config/Mozilla/native-messaging-hosts/</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="customBrowserLocationBrowseButton">
<property name="accessibleName">
<string>Browse for custom browser path</string>
</property>
<property name="text">
<string extracomment="Button for opening file dialog">Browse...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="customExtensionIdContainer" native="true">
<layout class="QHBoxLayout" name="customExtensionBox" stretch="0,0,1">
<property name="topMargin">
<number>20</number>
<number>6</number>
</property>
<item>
<widget class="QLabel" name="customExtensionLabel">
@ -392,6 +563,18 @@
</item>
<item>
<widget class="QLineEdit" name="customExtensionId">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
<property name="accessibleName">
<string>Custom extension ID</string>
</property>
@ -403,7 +586,21 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">

View File

@ -33,6 +33,7 @@ namespace BrowserShared
TOR_BROWSER,
BRAVE,
EDGE,
CUSTOM,
MAX_SUPPORTED
};

View File

@ -114,7 +114,7 @@ void NativeMessageInstaller::setBrowserEnabled(SupportedBrowsers browser, bool e
}
} else {
// Remove the script file
QString fileName = getNativeMessagePath(browser);
const QString fileName = getNativeMessagePath(browser);
QFile::remove(fileName);
#ifdef Q_OS_WIN
// Remove the registry entry
@ -159,6 +159,8 @@ QString NativeMessageInstaller::getTargetPath(SupportedBrowsers browser) const
return TARGET_DIR_BRAVE;
case SupportedBrowsers::EDGE:
return TARGET_DIR_EDGE;
case SupportedBrowsers::CUSTOM:
return browserSettings()->customBrowserLocation();
default:
return {};
}
@ -188,6 +190,8 @@ QString NativeMessageInstaller::getBrowserName(SupportedBrowsers browser) const
return QStringLiteral("brave");
case SupportedBrowsers::EDGE:
return QStringLiteral("edge");
case SupportedBrowsers::CUSTOM:
return QStringLiteral("custom");
default:
return {};
}
@ -223,6 +227,10 @@ QString NativeMessageInstaller::getNativeMessagePath(SupportedBrowsers browser)
#else
basePath = QDir::homePath();
#endif
if (browser == SupportedBrowsers::CUSTOM) {
return QString("%1/%2.json").arg(getTargetPath(browser), HOST_NAME);
}
return QStringLiteral("%1%2/%3.json").arg(basePath, getTargetPath(browser), HOST_NAME);
}
@ -267,7 +275,9 @@ QJsonObject NativeMessageInstaller::constructFile(SupportedBrowsers browser)
script["type"] = QStringLiteral("stdio");
QJsonArray arr;
if (browser == SupportedBrowsers::FIREFOX || browser == SupportedBrowsers::TOR_BROWSER) {
if (browser == SupportedBrowsers::FIREFOX || browser == SupportedBrowsers::TOR_BROWSER
|| (browser == SupportedBrowsers::CUSTOM
&& browserSettings()->customBrowserType() == SupportedBrowsers::FIREFOX)) {
for (const QString& extension : ALLOWED_EXTENSIONS) {
arr.append(extension);
}

View File

@ -152,6 +152,9 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::Browser_SearchInAllDatabases, {QS("Browser/SearchInAllDatabases"), Roaming, false}},
{Config::Browser_SupportKphFields, {QS("Browser/SupportKphFields"), Roaming, true}},
{Config::Browser_NoMigrationPrompt, {QS("Browser/NoMigrationPrompt"), Roaming, false}},
{Config::Browser_UseCustomBrowser, {QS("Browser/UseCustomBrowser"), Local, false}},
{Config::Browser_CustomBrowserType, {QS("Browser/CustomBrowserType"), Local, -1}},
{Config::Browser_CustomBrowserLocation, {QS("Browser/CustomBrowserLocation"), Local, {}}},
#ifdef QT_DEBUG
{Config::Browser_CustomExtensionId, {QS("Browser/CustomExtensionId"), Local, {}}},
#endif

View File

@ -133,6 +133,9 @@ public:
Browser_SearchInAllDatabases,
Browser_SupportKphFields,
Browser_NoMigrationPrompt,
Browser_UseCustomBrowser,
Browser_CustomBrowserType,
Browser_CustomBrowserLocation,
#ifdef QT_DEBUG
Browser_CustomExtensionId,
#endif