Skip to content

Commit

Permalink
Fix displaying confirmation dialog when opening out of scope links (f…
Browse files Browse the repository at this point in the history
…ixes #646)
  • Loading branch information
filips123 committed Feb 12, 2025
1 parent 8372e9a commit 2159922
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 8 additions & 0 deletions native/userchrome/profile/chrome/pwa/boot.sys.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppConstants } from 'resource://gre/modules/AppConstants.sys.mjs';
import { NetUtil } from 'resource://gre/modules/NetUtil.sys.mjs';
import { nsContentDispatchChooser } from 'resource://gre/modules/ContentDispatchChooser.sys.mjs';
import { nsDefaultCommandLineHandler, nsBrowserContentHandler } from 'resource:///modules/BrowserContentHandler.sys.mjs';
import { BrowserWindowTracker } from 'resource:///modules/BrowserWindowTracker.sys.mjs';

Expand Down Expand Up @@ -188,6 +189,13 @@ if (AppConstants.platform === 'macosx') {
}
}

// Allow opening HTTP(S) links in a default browser without a confirmation popup
nsContentDispatchChooser.prototype._hasProtocolHandlerPermissionOriginal = nsContentDispatchChooser.prototype._hasProtocolHandlerPermission;
nsContentDispatchChooser.prototype._hasProtocolHandlerPermission = function(scheme, principal, triggeredExternally) {
if (scheme === 'http' || scheme === 'https') return true;
return this._hasProtocolHandlerPermissionOriginal(scheme, principal, triggeredExternally);
};

// Register a localization source for the packaged locales
Services.obs.addObserver(async () => {
const languages = Services.locale.packagedLocales;
Expand Down
9 changes: 0 additions & 9 deletions native/userchrome/profile/chrome/pwa/content/browser.sys.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { OnboardingMessageProvider } from 'resource:///modules/asrouter/OnboardingMessageProvider.sys.mjs';
import { nsContentDispatchChooser } from 'resource://gre/modules/ContentDispatchChooser.sys.mjs';
import { WebNavigationManager } from 'resource://gre/modules/WebNavigation.sys.mjs';
import { XPCOMUtils } from 'resource://gre/modules/XPCOMUtils.sys.mjs';
import { BrowserGlue } from 'resource:///modules/BrowserGlue.sys.mjs';
Expand Down Expand Up @@ -511,14 +510,6 @@ class PwaBrowser {

if (ChromeLoader.INITIALIZED_BROWSER) return;

// Allow opening HTTP links without confirmation popup
// This applies to all ways of opening HTTP links in default browser
nsContentDispatchChooser.prototype._hasProtocolHandlerPermissionOriginal = nsContentDispatchChooser.prototype._hasProtocolHandlerPermission;
nsContentDispatchChooser.prototype._hasProtocolHandlerPermission = function(scheme, principal, triggeredExternally) {
if (scheme === 'http' || scheme === 'https') return true;
return this._hasProtocolHandlerPermissionOriginal(scheme, principal, triggeredExternally);
};

// Handle blocking out-of-scope URLs and redirecting them to the main browser
Services.obs.addObserver(subject => {
const httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
Expand Down

0 comments on commit 2159922

Please sign in to comment.