From cb52623d8d2cbb0423876d707ea87a23baa4c92d Mon Sep 17 00:00:00 2001
From: Kevin Mihelich <kevin@archlinuxarm.org>
Date: Wed, 18 Jan 2023 00:35:17 +0000
Subject: [PATCH] extra/firefox to 109.0-1

---
 .../0001-libwebrtc-screen-cast-sync.patch     | 53 +++++++++++--------
 ...and-Check-size-for-valid-EGLWindows-.patch | 25 +++++++++
 extra/firefox/PKGBUILD                        | 14 +++--
 3 files changed, 65 insertions(+), 27 deletions(-)
 create mode 100644 extra/firefox/0002-Bug-1804973-Wayland-Check-size-for-valid-EGLWindows-.patch

diff --git a/extra/firefox/0001-libwebrtc-screen-cast-sync.patch b/extra/firefox/0001-libwebrtc-screen-cast-sync.patch
index 708072656..76f109020 100644
--- a/extra/firefox/0001-libwebrtc-screen-cast-sync.patch
+++ b/extra/firefox/0001-libwebrtc-screen-cast-sync.patch
@@ -21,7 +21,7 @@ Fixes: https://bugzilla.mozilla.org/show_bug.cgi?id=1790496
  third_party/gbm/gbm/gbm.h                     |  452 ++++++
  .../libpipewire => gbm/libgbm}/moz.build      |    4 +-
  third_party/gbm/libgbm/mozgbm.cpp             |   66 +
- .../desktop_capture_generic_gn/moz.build      |   45 +-
+ .../desktop_capture_gn/moz.build              |   48 +-
  .../desktop_capture_options.cc                |    4 +-
  .../desktop_capture/desktop_capture_options.h |    6 +-
  .../linux/wayland/base_capturer_pipewire.cc   |    2 +-
@@ -29,7 +29,7 @@ Fixes: https://bugzilla.mozilla.org/show_bug.cgi?id=1790496
  .../desktop_capture/window_capturer_linux.cc  |    8 -
  third_party/moz.build                         |    6 +
  .../pipewire/libpipewire/mozpipewire.cpp      |   49 +-
- 20 files changed, 5450 insertions(+), 33 deletions(-)
+ 20 files changed, 5453 insertions(+), 33 deletions(-)
  create mode 100644 third_party/drm/README
  create mode 100644 third_party/drm/drm/drm.h
  create mode 100644 third_party/drm/drm/drm_fourcc.h
@@ -43,7 +43,7 @@ Fixes: https://bugzilla.mozilla.org/show_bug.cgi?id=1790496
  create mode 100644 third_party/gbm/libgbm/mozgbm.cpp
 
 diff --git a/dom/media/webrtc/moz.build b/dom/media/webrtc/moz.build
-index ddf9321b58ea..af0f7ab64cc3 100644
+index b6e09dbb5c9a..ada0fcb4a5d9 100644
 --- a/dom/media/webrtc/moz.build
 +++ b/dom/media/webrtc/moz.build
 @@ -84,6 +84,8 @@ if CONFIG["MOZ_WEBRTC_SIGNALING"]:
@@ -5498,10 +5498,10 @@ index 000000000000..bc024a11c0b7
 +  }
 +  return gbm_device_destroy_fn(gbm);
 +}
-diff --git a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
-index 809899a92847..8869fae89703 100644
---- a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
-+++ b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
+diff --git a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_gn/moz.build b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_gn/moz.build
+index 8631744ab1bf..366ea67aa9ab 100644
+--- a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_gn/moz.build
++++ b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_gn/moz.build
 @@ -8,25 +8,28 @@
  if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
      CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
@@ -5532,14 +5532,15 @@ index 809899a92847..8869fae89703 100644
      "/third_party/libwebrtc/",
      "/third_party/libwebrtc/third_party/abseil-cpp/",
      "/third_party/pipewire/",
-@@ -240,7 +243,15 @@ if CONFIG["CPU_ARCH"] == "arm":
+@@ -242,7 +245,16 @@ if CONFIG["CPU_ARCH"] == "arm":
      DEFINES["_GNU_SOURCE"] = True
  
-     UNIFIED_SOURCES += [
+     SOURCES += [
 -        "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/moz_base_capturer_pipewire.cc"
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/egl_dmabuf.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/mouse_cursor_monitor_pipewire.cc",
++      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/restore_token_manager.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/scoped_glib.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screen_capture_portal_interface.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screencast_portal.cc",
@@ -5549,15 +5550,15 @@ index 809899a92847..8869fae89703 100644
      ]
  
  if CONFIG["CPU_ARCH"] == "ppc64":
-@@ -295,27 +306,51 @@ if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux":
+@@ -297,27 +309,53 @@ if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux":
      DEFINES["_GNU_SOURCE"] = True
  
-     UNIFIED_SOURCES += [
+     SOURCES += [
 -        "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/moz_base_capturer_pipewire.cc"
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/egl_dmabuf.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/mouse_cursor_monitor_pipewire.cc",
-+      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/scoped_glib.cc",
++      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/restore_token_manager.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screen_capture_portal_interface.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screencast_portal.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screencast_stream_utils.cc",
@@ -5571,11 +5572,12 @@ index 809899a92847..8869fae89703 100644
      DEFINES["WEBRTC_USE_PIPEWIRE"] = True
      DEFINES["_GNU_SOURCE"] = True
  
-     UNIFIED_SOURCES += [
+     SOURCES += [
 -        "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/moz_base_capturer_pipewire.cc"
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/egl_dmabuf.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/mouse_cursor_monitor_pipewire.cc",
++      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/restore_token_manager.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/scoped_glib.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screen_capture_portal_interface.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screencast_portal.cc",
@@ -5590,11 +5592,12 @@ index 809899a92847..8869fae89703 100644
      DEFINES["WEBRTC_USE_PIPEWIRE"] = True
      DEFINES["_GNU_SOURCE"] = True
  
-     UNIFIED_SOURCES += [
+     SOURCES += [
 -        "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/moz_base_capturer_pipewire.cc"
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/egl_dmabuf.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/mouse_cursor_monitor_pipewire.cc",
++      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/restore_token_manager.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/scoped_glib.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screen_capture_portal_interface.cc",
 +      "/third_party/libwebrtc/modules/desktop_capture/linux/wayland/screencast_portal.cc",
@@ -5605,10 +5608,10 @@ index 809899a92847..8869fae89703 100644
  
  if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux":
 diff --git a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.cc b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.cc
-index 8bdc83b76218..ab7932195c85 100644
+index 767dbfefa543..22c59ef4cccd 100644
 --- a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.cc
 +++ b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.cc
-@@ -14,33 +14,33 @@
+@@ -17,31 +17,31 @@
  #elif defined(WEBRTC_WIN)
  #include "modules/desktop_capture/win/full_screen_win_application_handler.h"
  #endif
@@ -5617,8 +5620,6 @@ index 8bdc83b76218..ab7932195c85 100644
  #include "modules/desktop_capture/linux/wayland/shared_screencast_stream.h"
  #endif
  
- #include "rtc_base/ref_counted_object.h"
- 
  namespace webrtc {
  
  DesktopCaptureOptions::DesktopCaptureOptions() {}
@@ -5645,7 +5646,7 @@ index 8bdc83b76218..ab7932195c85 100644
  #endif
  #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
 diff --git a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.h b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.h
-index 1605d30f82d1..eb5b8a2a8777 100644
+index 4d2a8da334da..bab39ccf5661 100644
 --- a/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.h
 +++ b/third_party/libwebrtc/modules/desktop_capture/desktop_capture_options.h
 @@ -17,7 +17,7 @@
@@ -5657,7 +5658,7 @@ index 1605d30f82d1..eb5b8a2a8777 100644
  #include "modules/desktop_capture/linux/wayland/shared_screencast_stream.h"
  #endif
  
-@@ -181,22 +181,20 @@ class RTC_EXPORT DesktopCaptureOptions {
+@@ -181,28 +181,26 @@ class RTC_EXPORT DesktopCaptureOptions {
    bool allow_pipewire() const { return allow_pipewire_; }
    void set_allow_pipewire(bool allow) { allow_pipewire_ = allow; }
  
@@ -5669,6 +5670,12 @@ index 1605d30f82d1..eb5b8a2a8777 100644
        rtc::scoped_refptr<SharedScreenCastStream> stream) {
      screencast_stream_ = stream;
    }
+ 
+   void set_width(uint32_t width) { width_ = width; }
+   uint32_t get_width() const { return width_; }
+ 
+   void set_height(uint32_t height) { height_ = height; }
+   uint32_t get_height() const { return height_; }
 -#endif
  #endif
  
@@ -5682,14 +5689,14 @@ index 1605d30f82d1..eb5b8a2a8777 100644
    // BaseCapturerPipeWire and MouseCursorMonitorPipeWire as cursor information
    // is sent together with screen content.
 diff --git a/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc b/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc
-index 75659a9eb9e2..32578411059b 100644
+index e9158bf0cccf..655ec50ce9d7 100644
 --- a/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc
 +++ b/third_party/libwebrtc/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc
-@@ -105,7 +105,7 @@ bool BaseCapturerPipeWire::GetSourceList(SourceList* sources) {
+@@ -136,7 +136,7 @@ bool BaseCapturerPipeWire::GetSourceList(SourceList* sources) {
    // is often treated as a null/placeholder id, so we shouldn't use that.
    // TODO(https://crbug.com/1297671): Reconsider type of ID when plumbing
    // token that will enable stream re-use.
--  sources->push_back({1});
+-  sources->push_back({source_id_});
 +  sources->push_back({PIPEWIRE_ID, 0, PIPEWIRE_NAME});
    return true;
  }
diff --git a/extra/firefox/0002-Bug-1804973-Wayland-Check-size-for-valid-EGLWindows-.patch b/extra/firefox/0002-Bug-1804973-Wayland-Check-size-for-valid-EGLWindows-.patch
new file mode 100644
index 000000000..4735a44c7
--- /dev/null
+++ b/extra/firefox/0002-Bug-1804973-Wayland-Check-size-for-valid-EGLWindows-.patch
@@ -0,0 +1,25 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: stransky <stransky@redhat.com>
+Date: Thu, 15 Dec 2022 08:09:22 +0000
+Subject: [PATCH] Bug 1804973 [Wayland] Check size for valid EGLWindows only
+ r=emilio
+
+Differential Revision: https://phabricator.services.mozilla.com/D164651
+---
+ widget/gtk/MozContainerWayland.cpp | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/widget/gtk/MozContainerWayland.cpp b/widget/gtk/MozContainerWayland.cpp
+index 954c650af533..2a4a492077c3 100644
+--- a/widget/gtk/MozContainerWayland.cpp
++++ b/widget/gtk/MozContainerWayland.cpp
+@@ -704,6 +704,9 @@ bool moz_container_wayland_egl_window_needs_size_update(MozContainer* container,
+                                                         nsIntSize aSize,
+                                                         int aScale) {
+   MozContainerWayland* wl_container = &container->wl_container;
++  if (!wl_container->eglwindow) {
++    return false;
++  }
+   if (wl_container->buffer_scale != aScale) {
+     return true;
+   }
diff --git a/extra/firefox/PKGBUILD b/extra/firefox/PKGBUILD
index c42c3718b..b11f00bdd 100644
--- a/extra/firefox/PKGBUILD
+++ b/extra/firefox/PKGBUILD
@@ -10,7 +10,7 @@
 highmem=1
 
 pkgname=firefox
-pkgver=108.0.2
+pkgver=109.0
 pkgrel=1
 pkgdesc="Standalone web browser from mozilla.org"
 url="https://www.mozilla.org/firefox/"
@@ -70,22 +70,25 @@ source=(
   $pkgname.desktop
   identity-icons-brand.svg
   0001-libwebrtc-screen-cast-sync.patch
+  0002-Bug-1804973-Wayland-Check-size-for-valid-EGLWindows-.patch
   build-arm-libopus.patch
 )
 validpgpkeys=(
   '14F26682D0916CDD81E37B6D61B7B526D98F0353'  # Mozilla Software Releases <release@mozilla.com>
 )
-sha256sums=('42e6d6b27ad0694a4fc9dd736888ad36c99eb2dbcce96e134584805d644ca300'
+sha256sums=('0678a03b572b5992fb85f0923a25b236acf81e5ea2c08e549b63a56076a69351'
             'SKIP'
             '298eae9de76ec53182f38d5c549d0379569916eebf62149f9d7f4a7edef36abf'
             'a9b8b4a0a1f4a7b4af77d5fc70c2686d624038909263c795ecc81e0aec7711e9'
-            '5c164f6dfdf2d97f3f317e417aaa2e6ae46a9b3a160c3162d5073fe39d203286'
+            'b1ce6936749ab1614bbce4fddc87058341ed207dde77af609fdc5ac83538517a'
+            '34439dfb17371520e5e99444096ded97325ab2559b9039ae16055975d015ac51'
             '2d4d91f7e35d0860225084e37ec320ca6cae669f6c9c8fe7735cdbd542e3a7c9')
 b2sums=('8032c4250c975dfbe159eac8db3a8909c45b9ceccba206f7a5aba9650bcb40df658a50890efa5572d9cacc22411d6f1a2253905fff2d0791604debfebd986c29'
         'SKIP'
         'e18f2c22e394ca3b6758bc130245b254947e4d15921be3da443d6d7c3c4b0d22ead1b39fbc10a4f896edd19e2a1dffbd1cbb34dc4beb0621a6ddb70ccc53b3a7'
         '63a8dd9d8910f9efb353bed452d8b4b2a2da435857ccee083fc0c557f8c4c1339ca593b463db320f70387a1b63f1a79e709e9d12c69520993e26d85a3d742e34'
-        '28a22a11572fba86bf8412f86a2eca8dc34ce42e790d9c9b1e0b1a66959b2b0240353e0aef22741d6d2baa08bc7ff35ddfd3770b706654ffa8089a26495e4ee3'
+        '3a7de17f0a56c4ccbbd4754a63a8798f787e87acc947b0fc0c1e5086c99337979b7f66a741fdc5475b34085eaf80dbc99d742c22a95d6ed412e38012794a44c9'
+        'ad4618e6c0e6ac8cca387579f26e8f9a0eaab8e6f8ac8f9e2ad179bce09f5247848a9ce78d4042f3e400771f9c0914e8d6504f792d002481529e755f5eaf8916'
         '6e5980e56343a23bce4fcda58f6abc8f2debca0c278c87b09e53abb17ff15849c26e8df3bbff2388985f8fe5a4e9be9982c602ef7159546f0ae335fca1000a41')
 
 # Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
@@ -110,6 +113,9 @@ prepare() {
   # https://src.fedoraproject.org/rpms/firefox/blob/rawhide/f/libwebrtc-screen-cast-sync.patch
   patch -Np1 -i ../0001-libwebrtc-screen-cast-sync.patch
 
+  # https://bugzilla.mozilla.org/show_bug.cgi?id=1804973
+  patch -Np1 -i ../0002-Bug-1804973-Wayland-Check-size-for-valid-EGLWindows-.patch
+
   echo -n "$_google_api_key" >google-api-key
   echo -n "$_mozilla_api_key" >mozilla-api-key