ffa346e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ffa346e
From: Martin Sirringhaus <msirringhaus@suse.de>
ffa346e
Date: Tue, 8 Aug 2023 16:18:24 +0300
ffa346e
Subject: [PATCH] Add KDE integration to Firefox
ffa346e
ffa346e
Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=140751
ffa346e
Bug: https://bugzilla.suse.com/show_bug.cgi?id=170055
ffa346e
ffa346e
How to apply this patch:
ffa346e
ffa346e
1. Import and apply it
ffa346e
2. cp browser/base/content/browser.xul browser/base/content/browser-kde.xul
ffa346e
3. Find editBookmarkPanelDoneButton
ffa346e
4. Replace #ifndef with #ifdef in the line above (this hanges the button order from Gnome-style to KDE-style)
ffa346e
5. hg qrefresh
ffa346e
---
ffa346e
 browser/components/preferences/main.js        |  18 +++
ffa346e
 browser/components/shell/moz.build            |   2 +
ffa346e
 .../components/shell/nsKDEShellService.cpp    | 109 ++++++++++++++++++
ffa346e
 browser/components/shell/nsKDEShellService.h  |  32 +++++
ffa346e
 .../components/shell/nsUnixShellService.cpp   |  22 ++++
ffa346e
 browser/components/shell/nsUnixShellService.h |  15 +++
ffa346e
 6 files changed, 198 insertions(+)
ffa346e
 create mode 100644 browser/components/shell/nsKDEShellService.cpp
ffa346e
 create mode 100644 browser/components/shell/nsKDEShellService.h
ffa346e
 create mode 100644 browser/components/shell/nsUnixShellService.cpp
ffa346e
 create mode 100644 browser/components/shell/nsUnixShellService.h
ffa346e
ffa346e
diff --git a/browser/components/preferences/main.js b/browser/components/preferences/main.js
ffa346e
index 820e46fb006567bfdf93e2a46da5e3c07d42bf10..57d1c21bdecc2d55d0bed30246e684d3b97ad7fa 100644
ffa346e
--- a/browser/components/preferences/main.js
ffa346e
+++ b/browser/components/preferences/main.js
ffa346e
@@ -294,6 +294,13 @@ var gMainPane = {
ffa346e
       }, backoffTimes[this._backoffIndex]);
ffa346e
     }
ffa346e
 
ffa346e
+    var env = Components.classes["@mozilla.org/process/environment;1"]
ffa346e
+      .getService(Components.interfaces.nsIEnvironment);
ffa346e
+    var kde_session = 0;
ffa346e
+    if (env.get('KDE_FULL_SESSION') == "true") {
ffa346e
+      kde_session = 1;
ffa346e
+    }
ffa346e
+
ffa346e
     this.initBrowserContainers();
ffa346e
     this.buildContentProcessCountMenuList();
ffa346e
 
ffa346e
@@ -1727,6 +1734,17 @@ var gMainPane = {
ffa346e
       }
ffa346e
       try {
ffa346e
         shellSvc.setDefaultBrowser(true, false);
ffa346e
+        if (kde_session == 1) {
ffa346e
+          var shellObj = Components.classes["@mozilla.org/file/local;1"]
ffa346e
+            .createInstance(Components.interfaces.nsILocalFile);
ffa346e
+          shellObj.initWithPath("/usr/bin/kwriteconfig");
ffa346e
+          var process = Components.classes["@mozilla.org/process/util;1"]
ffa346e
+            .createInstance(Components.interfaces.nsIProcess);
ffa346e
+          process.init(shellObj);
ffa346e
+          var args = ["--file", "kdeglobals", "--group", "General", "--key",
ffa346e
+              "BrowserApplication", "firefox"];
ffa346e
+          process.run(false, args, args.length);
ffa346e
+        }
ffa346e
       } catch (ex) {
ffa346e
         console.error(ex);
ffa346e
         return;
ffa346e
diff --git a/browser/components/shell/moz.build b/browser/components/shell/moz.build
ffa346e
index eb88cb287dc3f04022b74b978666118bbd5fa6b2..95277533781a7224d108e3c45731a6d9a89ba1a0 100644
ffa346e
--- a/browser/components/shell/moz.build
ffa346e
+++ b/browser/components/shell/moz.build
ffa346e
@@ -36,6 +36,8 @@ elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
ffa346e
 
ffa346e
     SOURCES += [
ffa346e
         "nsGNOMEShellService.cpp",
ffa346e
+        "nsKDEShellService.cpp",
ffa346e
+        "nsUnixShellService.cpp",
ffa346e
     ]
ffa346e
     if CONFIG["MOZ_ENABLE_DBUS"]:
ffa346e
         SOURCES += [
ffa346e
diff --git a/browser/components/shell/nsKDEShellService.cpp b/browser/components/shell/nsKDEShellService.cpp
ffa346e
new file mode 100644
ffa346e
index 0000000000000000000000000000000000000000..152a3aca87ea73477bc75c4e93c01e5a52dda102
ffa346e
--- /dev/null
ffa346e
+++ b/browser/components/shell/nsKDEShellService.cpp
ffa346e
@@ -0,0 +1,109 @@
ffa346e
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
ffa346e
+/* This Source Code Form is subject to the terms of the Mozilla Public
ffa346e
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
ffa346e
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
ffa346e
+
ffa346e
+#include "mozilla/ArrayUtils.h"
ffa346e
+
ffa346e
+#include "nsCOMPtr.h"
ffa346e
+#include "nsKDEShellService.h"
ffa346e
+#include "nsShellService.h"
ffa346e
+#include "nsKDEUtils.h"
ffa346e
+#include "nsIPrefService.h"
ffa346e
+#include "nsIProcess.h"
ffa346e
+#include "nsIFile.h"
ffa346e
+#include "nsServiceManagerUtils.h"
ffa346e
+#include "nsComponentManagerUtils.h"
ffa346e
+#include "nsIMutableArray.h"
ffa346e
+#include "nsISupportsPrimitives.h"
ffa346e
+#include "nsArrayUtils.h"
ffa346e
+
ffa346e
+using namespace mozilla;
ffa346e
+
ffa346e
+nsresult
ffa346e
+nsKDEShellService::Init()
ffa346e
+{
ffa346e
+    if( !nsKDEUtils::kdeSupport())
ffa346e
+        return NS_ERROR_NOT_AVAILABLE;
ffa346e
+    return NS_OK;
ffa346e
+}
ffa346e
+
ffa346e
+NS_IMPL_ISUPPORTS(nsKDEShellService, nsIGNOMEShellService, nsIShellService)
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsKDEShellService::IsDefaultBrowser(bool aForAllTypes,
ffa346e
+                                    bool* aIsDefaultBrowser)
ffa346e
+{
ffa346e
+    *aIsDefaultBrowser = false;
ffa346e
+
ffa346e
+    nsCOMPtr<nsIMutableArray> command = do_CreateInstance( NS_ARRAY_CONTRACTID );
ffa346e
+    if (!command)
ffa346e
+        return NS_ERROR_FAILURE;
ffa346e
+
ffa346e
+    nsCOMPtr<nsISupportsCString> str = do_CreateInstance( NS_SUPPORTS_CSTRING_CONTRACTID );
ffa346e
+    if (!str)
ffa346e
+        return NS_ERROR_FAILURE;
ffa346e
+
ffa346e
+    str->SetData("ISDEFAULTBROWSER"_ns);
ffa346e
+    command->AppendElement( str );
ffa346e
+
ffa346e
+    if( nsKDEUtils::command( command ))
ffa346e
+        *aIsDefaultBrowser = true;
ffa346e
+    return NS_OK;
ffa346e
+}
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsKDEShellService::SetDefaultBrowser(bool aClaimAllTypes,
ffa346e
+                                     bool aForAllUsers)
ffa346e
+{
ffa346e
+    nsCOMPtr<nsIMutableArray> command = do_CreateInstance( NS_ARRAY_CONTRACTID );
ffa346e
+    if (!command)
ffa346e
+        return NS_ERROR_FAILURE;
ffa346e
+
ffa346e
+    nsCOMPtr<nsISupportsCString> cmdstr = do_CreateInstance( NS_SUPPORTS_CSTRING_CONTRACTID );
ffa346e
+    nsCOMPtr<nsISupportsCString> paramstr = do_CreateInstance( NS_SUPPORTS_CSTRING_CONTRACTID );
ffa346e
+    if (!cmdstr || !paramstr)
ffa346e
+        return NS_ERROR_FAILURE;
ffa346e
+
ffa346e
+    cmdstr->SetData("SETDEFAULTBROWSER"_ns);
ffa346e
+    command->AppendElement( cmdstr );
ffa346e
+
ffa346e
+    paramstr->SetData( aClaimAllTypes ? "ALLTYPES"_ns : "NORMAL"_ns );
ffa346e
+    command->AppendElement( paramstr );
ffa346e
+
ffa346e
+    return nsKDEUtils::command( command ) ? NS_OK : NS_ERROR_FAILURE;
ffa346e
+}
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsKDEShellService::GetCanSetDesktopBackground(bool* aResult)
ffa346e
+{
ffa346e
+  *aResult = true;
ffa346e
+  return NS_OK;
ffa346e
+}
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsKDEShellService::SetDesktopBackground(dom::Element* aElement,
ffa346e
+                                        int32_t aPosition,
ffa346e
+                                        const nsACString& aImageName)
ffa346e
+{
ffa346e
+    return NS_ERROR_NOT_IMPLEMENTED;
ffa346e
+}
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsKDEShellService::GetDesktopBackgroundColor(PRUint32 *aColor)
ffa346e
+{
ffa346e
+    return NS_ERROR_NOT_IMPLEMENTED;
ffa346e
+}
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsKDEShellService::SetDesktopBackgroundColor(PRUint32 aColor)
ffa346e
+{
ffa346e
+    return NS_ERROR_NOT_IMPLEMENTED;
ffa346e
+}
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsKDEShellService::IsDefaultForScheme(nsTSubstring<char> const& aScheme, bool* aIsDefaultBrowser)
ffa346e
+{
ffa346e
+    return NS_ERROR_NOT_IMPLEMENTED;
ffa346e
+}
ffa346e
+
ffa346e
diff --git a/browser/components/shell/nsKDEShellService.h b/browser/components/shell/nsKDEShellService.h
ffa346e
new file mode 100644
ffa346e
index 0000000000000000000000000000000000000000..8b0bb19164352453cfa453dd87c19263160b9ad8
ffa346e
--- /dev/null
ffa346e
+++ b/browser/components/shell/nsKDEShellService.h
ffa346e
@@ -0,0 +1,32 @@
ffa346e
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
ffa346e
+/* This Source Code Form is subject to the terms of the Mozilla Public
ffa346e
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
ffa346e
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
ffa346e
+
ffa346e
+#ifndef nskdeshellservice_h____
ffa346e
+#define nskdeshellservice_h____
ffa346e
+
ffa346e
+#include "nsIGNOMEShellService.h"
ffa346e
+#include "nsToolkitShellService.h"
ffa346e
+#include "nsString.h"
ffa346e
+#include "mozilla/Attributes.h"
ffa346e
+
ffa346e
+class nsKDEShellService final : public nsIGNOMEShellService,
ffa346e
+                                public nsToolkitShellService
ffa346e
+{
ffa346e
+public:
ffa346e
+  nsKDEShellService() : mCheckedThisSession(false) { }
ffa346e
+
ffa346e
+  NS_DECL_ISUPPORTS
ffa346e
+  NS_DECL_NSISHELLSERVICE
ffa346e
+  NS_DECL_NSIGNOMESHELLSERVICE
ffa346e
+
ffa346e
+  nsresult Init();
ffa346e
+
ffa346e
+private:
ffa346e
+  ~nsKDEShellService() {}
ffa346e
+
ffa346e
+  bool mCheckedThisSession;
ffa346e
+};
ffa346e
+
ffa346e
+#endif // nskdeshellservice_h____
ffa346e
diff --git a/browser/components/shell/nsUnixShellService.cpp b/browser/components/shell/nsUnixShellService.cpp
ffa346e
new file mode 100644
ffa346e
index 0000000000000000000000000000000000000000..abf266ebdc52e136f495911da3454e69c770c6db
ffa346e
--- /dev/null
ffa346e
+++ b/browser/components/shell/nsUnixShellService.cpp
ffa346e
@@ -0,0 +1,22 @@
ffa346e
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
ffa346e
+/* This Source Code Form is subject to the terms of the Mozilla Public
ffa346e
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
ffa346e
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
ffa346e
+
ffa346e
+
ffa346e
+#include "nsUnixShellService.h"
ffa346e
+#include "nsGNOMEShellService.h"
ffa346e
+#include "nsKDEShellService.h"
ffa346e
+#include "nsKDEUtils.h"
ffa346e
+#include "mozilla/ModuleUtils.h"
ffa346e
+
ffa346e
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGNOMEShellService, Init)
ffa346e
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsKDEShellService, Init)
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsUnixShellServiceConstructor(REFNSIID aIID, void **aResult)
ffa346e
+{
ffa346e
+    if( nsKDEUtils::kdeSupport())
ffa346e
+        return nsKDEShellServiceConstructor( aIID, aResult );
ffa346e
+    return nsGNOMEShellServiceConstructor( aIID, aResult );
ffa346e
+}
ffa346e
diff --git a/browser/components/shell/nsUnixShellService.h b/browser/components/shell/nsUnixShellService.h
ffa346e
new file mode 100644
ffa346e
index 0000000000000000000000000000000000000000..26b5dbac47dd9a8ec1fcb6c93575cca750692735
ffa346e
--- /dev/null
ffa346e
+++ b/browser/components/shell/nsUnixShellService.h
ffa346e
@@ -0,0 +1,15 @@
ffa346e
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
ffa346e
+/* This Source Code Form is subject to the terms of the Mozilla Public
ffa346e
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
ffa346e
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
ffa346e
+
ffa346e
+
ffa346e
+#ifndef nsunixshellservice_h____
ffa346e
+#define nsunixshellservice_h____
ffa346e
+
ffa346e
+#include "nsIGNOMEShellService.h"
ffa346e
+
ffa346e
+NS_IMETHODIMP
ffa346e
+nsUnixShellServiceConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult);
ffa346e
+
ffa346e
+#endif // nsunixshellservice_h____