Browse Source

fix: bind fake mojo service for badging (#25369)

* fix: bind fake mojo service for badging

* Add a test

Co-authored-by: Shelley Vohr <[email protected]>
trop[bot] 4 years ago
parent
commit
88d7bdc8c8
2 changed files with 17 additions and 0 deletions
  1. 9 0
      shell/browser/electron_browser_client.cc
  2. 8 0
      spec/chromium-spec.js

+ 9 - 0
shell/browser/electron_browser_client.cc

@@ -96,6 +96,7 @@
 #include "shell/common/options_switches.h"
 #include "shell/common/platform_util.h"
 #include "third_party/blink/public/common/loader/url_loader_throttle.h"
+#include "third_party/blink/public/mojom/badging/badging.mojom.h"
 #include "ui/base/resource/resource_bundle.h"
 #include "ui/native_theme/native_theme.h"
 #include "v8/include/v8.h"
@@ -1583,6 +1584,12 @@ void ElectronBrowserClient::BindHostReceiverForRenderer(
 #endif
 }
 
+void BindBadgeManagerFrameReceiver(
+    content::RenderFrameHost* frame,
+    mojo::PendingReceiver<blink::mojom::BadgeService> receiver) {
+  LOG(WARNING) << "The Chromium Badging API is not available in Electron";
+}
+
 #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
 void BindMimeHandlerService(
     content::RenderFrameHost* frame_host,
@@ -1619,6 +1626,8 @@ void ElectronBrowserClient::RegisterBrowserInterfaceBindersForFrame(
     mojo::BinderMapWithContext<content::RenderFrameHost*>* map) {
   map->Add<network_hints::mojom::NetworkHintsHandler>(
       base::BindRepeating(&BindNetworkHintsHandler));
+  map->Add<blink::mojom::BadgeService>(
+      base::BindRepeating(&BindBadgeManagerFrameReceiver));
 #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
   map->Add<extensions::mime_handler::MimeHandlerService>(
       base::BindRepeating(&BindMimeHandlerService));

+ 8 - 0
spec/chromium-spec.js

@@ -17,6 +17,14 @@ const features = process.electronBinding('features');
 describe('chromium feature', () => {
   const fixtures = path.resolve(__dirname, 'fixtures');
 
+  describe('Badging API', () => {
+    it('does not crash', () => {
+      expect(() => {
+        navigator.setAppBadge(42);
+      }).to.not.throw();
+    });
+  });
+
   describe('heap snapshot', () => {
     it('does not crash', function () {
       process.electronBinding('v8_util').takeHeapSnapshot();