diff --git a/CMakeLists.txt b/CMakeLists.txt index efa63036..753546d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,99 +1,100 @@ cmake_minimum_required(VERSION 3.0) project(plasma-browser-integration) set(PROJECT_VERSION "5.18.4") set(PROJECT_VERSION_MAJOR 5) set(QT_MIN_VERSION "5.9.0") set(KF5_MIN_VERSION "5.42.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) include(KDEClangFormat) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Gui DBus Widgets ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS KIO I18n + CoreAddons Config Crash DBusAddons Notifications Runner Activities Purpose FileMetaData ) add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) #add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) # Options option(INSTALL_CHROME_MANIFEST "Whether to install a configuration file that makes Chrome automatically download the extension from the store" FALSE) add_feature_info(INSTALL_CHROME_MANIFEST ${INSTALL_CHROME_MANIFEST} "Install extension from Chrome store automatically") # in ubuntu and derivatives, this should be installed in the chromium-browser/extensions, # but since this is distribution specific path, let's use what upstream uses # ideally ubuntu and derivatives should patch this in their packaging set(CHROMIUM_EXTENSIONS_DIR "chromium" CACHE STRING "Directory name to install Chromium extensions into") add_feature_info(CHROMIUM_EXTENSIONS_DIR On "Directory name to install Chromium extensions into is '${CHROMIUM_EXTENSIONS_DIR}'") option(COPY_MESSAGING_HOST_FILE_HOME "Copy the native messaging hosts json file to user home dir" FALSE) add_feature_info(COPY_MESSAGING_HOST_FILE_HOME ${COPY_MESSAGING_HOST_FILE_HOME} "Enable this option to copy the native messaging hosts json file to home dir if you install plasma-browser-integration to custom prefix (non-/usr)") set(MOZILLA_DIR "${CMAKE_INSTALL_PREFIX}/lib/mozilla" CACHE STRING "Mozilla directory") add_feature_info(MOZILLA_DIR On "Mozilla directory is '${MOZILLA_DIR}'") add_subdirectory(host) add_subdirectory(tabsrunner) add_subdirectory(reminder) if(NOT DEFINED CHROME_EXTENSION_ID) # The extension ID is based on the key used to sign the extension # see https://stackoverflow.com/questions/23873623/obtaining-chrome-extension-id-for-development set(CHROME_EXTENSION_ID "cimiefiiaegbelhefglklhhakcgmhkai") endif() # TODO configure manifest.json configure_file(org.kde.plasma.chrome_integration.json.in org.kde.plasma.chrome_integration.json @ONLY) configure_file(org.kde.plasma.firefox_integration.json.in org.kde.plasma.firefox_integration.json @ONLY) # #chromium install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION ${KDE_INSTALL_FULL_SYSCONFDIR}/chromium/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) # #google-chrome install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION ${KDE_INSTALL_FULL_SYSCONFDIR}/opt/chrome/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) # firefox install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.firefox_integration.json DESTINATION ${MOZILLA_DIR}/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) if (COPY_MESSAGING_HOST_FILE_HOME) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.firefox_integration.json DESTINATION $ENV{HOME}/.mozilla/native-messaging-hosts/ RENAME org.kde.plasma.browser_integration.json) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION $ENV{HOME}/.config/chromium/NativeMessagingHosts/ RENAME org.kde.plasma.browser_integration.json) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasma.chrome_integration.json DESTINATION $ENV{HOME}/.config/google-chrome/NativeMessagingHosts/ RENAME org.kde.plasma.browser_integration.json) endif() if (INSTALL_CHROME_MANIFEST) # Install a policy to have browsers automatically add the extension # google-chrome install(FILES chrome_install_from_store_policy DESTINATION ${KDE_INSTALL_DATADIR}/google-chrome/extensions RENAME ${CHROME_EXTENSION_ID}.json) # chromium install(FILES chrome_install_from_store_policy DESTINATION ${KDE_INSTALL_DATADIR}/${CHROMIUM_EXTENSIONS_DIR}/extensions RENAME ${CHROME_EXTENSION_ID}.json) endif() # TODO firefox # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 3d92c6ab..7cf375b0 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -1,38 +1,39 @@ add_definitions(-DTRANSLATION_DOMAIN=\"plasma-browser-integration-host\") configure_file(config-host.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-host.h) set(HOST_SOURCES main.cpp connection.cpp pluginmanager.cpp settings.cpp mprisplugin.cpp abstractbrowserplugin.cpp kdeconnectplugin.cpp downloadplugin.cpp downloadjob.cpp tabsrunnerplugin.cpp purposeplugin.cpp ) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.kde.plasma.browser_integration.TabsRunner.xml tabsrunnerplugin.h TabsRunnerPlugin) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.kde.plasma.browser_integration.Settings.xml settings.h Settings) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.mpris.MediaPlayer2.xml mprisplugin.h MPrisPlugin mprisroot MPrisRoot) qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.mpris.MediaPlayer2.Player.xml mprisplugin.h MPrisPlugin mprisplayer MPrisPlayer) add_executable(plasma-browser-integration-host ${HOST_SOURCES}) target_link_libraries( plasma-browser-integration-host Qt5::DBus Qt5::Gui Qt5::Widgets KF5::Activities + KF5::CoreAddons KF5::Crash KF5::I18n KF5::KIOCore KF5::PurposeWidgets KF5::FileMetaData ) install(TARGETS plasma-browser-integration-host ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/host/settings.cpp b/host/settings.cpp index aa516379..7ae787a4 100644 --- a/host/settings.cpp +++ b/host/settings.cpp @@ -1,184 +1,198 @@ /* Copyright (C) 2017 by Kai Uwe Broulik Copyright (C) 2017 by David Edmundson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "settings.h" +#include // getppid + #include #include #include +#include + #include "pluginmanager.h" #include "settingsadaptor.h" #include const QMap Settings::environmentNames = { {Settings::Environment::Chrome, QStringLiteral("chrome")}, {Settings::Environment::Chromium, QStringLiteral("chromium")}, {Settings::Environment::Firefox, QStringLiteral("firefox")}, {Settings::Environment::Opera, QStringLiteral("opera")}, {Settings::Environment::Vivaldi, QStringLiteral("vivaldi")}, }; const QMap Settings::environmentDescriptions = { {Settings::Environment::Chrome, { QStringLiteral("google-chrome"), QStringLiteral("Google Chrome"), QStringLiteral("google-chrome"), QStringLiteral("google.com"), QStringLiteral("Google") } }, {Settings::Environment::Chromium, { QStringLiteral("chromium-browser"), QStringLiteral("Chromium"), QStringLiteral("chromium-browser"), QStringLiteral("google.com"), QStringLiteral("Google") } }, {Settings::Environment::Firefox, { QStringLiteral("firefox"), QStringLiteral("Mozilla Firefox"), QStringLiteral("firefox"), QStringLiteral("mozilla.org"), QStringLiteral("Mozilla") } }, {Settings::Environment::Opera, { QStringLiteral("opera"), QStringLiteral("Opera"), QStringLiteral("opera"), QStringLiteral("opera.com"), QStringLiteral("Opera") } }, {Settings::Environment::Vivaldi, { QStringLiteral("vivaldi"), QStringLiteral("Vivaldi"), // This is what the official package on their website uses QStringLiteral("vivaldi-stable"), QStringLiteral("vivaldi.com"), QStringLiteral("Vivaldi") } } }; Settings::Settings() : AbstractBrowserPlugin(QStringLiteral("settings"), 1, nullptr) { new SettingsAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"), this); } Settings &Settings::self() { static Settings s_self; return s_self; } void Settings::handleData(const QString &event, const QJsonObject &data) { if (event == QLatin1String("changed")) { m_settings = data; for (auto it = data.begin(), end = data.end(); it != end; ++it) { const QString &subsystem = it.key(); const QJsonObject &settingsObject = it->toObject(); const QJsonValue enabledVariant = settingsObject.value(QStringLiteral("enabled")); // probably protocol overhead, not a plugin setting, skip. if (enabledVariant.type() == QJsonValue::Undefined) { continue; } auto *plugin = PluginManager::self().pluginForSubsystem(subsystem); if (!plugin) { continue; } if (enabledVariant.toBool()) { PluginManager::self().loadPlugin(plugin); } else { PluginManager::self().unloadPlugin(plugin); } PluginManager::self().settingsChanged(plugin, settingsObject); } emit changed(data); } else if (event == QLatin1String("openKRunnerSettings")) { QProcess::startDetached(QStringLiteral("kcmshell5"), {QStringLiteral("kcm_plasmasearch")}); } else if (event == QLatin1String("setEnvironment")) { QString name = data[QStringLiteral("browserName")].toString(); + + // Most chromium-based browsers just impersonate Chromium nowadays to keep websites from locking them out + // so we'll need to make an educated guess from our parent process + if (name == QLatin1String("chromium")) { + const auto processInfo = KProcessList::processInfo(getppid()); + if (processInfo.name().contains(QLatin1String("vivaldi"))) { + name = QStringLiteral("vivaldi"); + } + } + m_environment = Settings::environmentNames.key(name, Settings::Environment::Unknown); m_currentEnvironment = Settings::environmentDescriptions.value(m_environment); qApp->setApplicationName(m_currentEnvironment.applicationName); qApp->setApplicationDisplayName(m_currentEnvironment.applicationDisplayName); qApp->setDesktopFileName(m_currentEnvironment.desktopFileName); qApp->setOrganizationDomain(m_currentEnvironment.organizationDomain); qApp->setOrganizationName(m_currentEnvironment.organizationName); } } QJsonObject Settings::handleData(int serial, const QString &event, const QJsonObject &data) { Q_UNUSED(serial) Q_UNUSED(data) QJsonObject ret; if (event == QLatin1String("getSubsystemStatus")) { // should we add a PluginManager::knownSubsystems() that returns a QList? const QStringList subsystems = PluginManager::self().knownPluginSubsystems(); for (const QString &subsystem : subsystems) { const AbstractBrowserPlugin *plugin = PluginManager::self().pluginForSubsystem(subsystem); QJsonObject details = plugin->status(); details.insert(QStringLiteral("version"), plugin->protocolVersion()); details.insert(QStringLiteral("loaded"), plugin->isLoaded()); ret.insert(subsystem, details); } } else if (event == QLatin1String("getVersion")) { ret.insert(QStringLiteral("host"), QStringLiteral(HOST_VERSION_STRING)); } return ret; } Settings::Environment Settings::environment() const { return m_environment; } QString Settings::environmentString() const { return Settings::environmentNames.value(m_environment); } bool Settings::pluginEnabled(const QString &subsystem) const { return settingsForPlugin(subsystem).value(QStringLiteral("enabled")).toBool(); } QJsonObject Settings::settingsForPlugin(const QString &subsystem) const { return m_settings.value(subsystem).toObject(); }