Skip to content

Instantly share code, notes, and snippets.

@zpao
Created June 16, 2012 01:05
Show Gist options
  • Save zpao/2939448 to your computer and use it in GitHub Desktop.
Save zpao/2939448 to your computer and use it in GitHub Desktop.
# HG changeset patch
# Parent 18542ed8614b337f29235d846133d15be1f6f065
# User Paul O’Shannessy <paul@oshannessy.com>
diff --git a/browser/base/content/browser-sets.inc b/browser/base/content/browser-sets.inc
--- a/browser/base/content/browser-sets.inc
+++ b/browser/base/content/browser-sets.inc
@@ -68,16 +68,17 @@
<command id="cmd_pageSetup" oncommand="PrintUtils.showPageSetup();"/>
<command id="cmd_print" oncommand="PrintUtils.print();"/>
<command id="cmd_printPreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
<command id="cmd_close" oncommand="BrowserCloseTabOrWindow()"/>
<command id="cmd_closeWindow" oncommand="BrowserTryToCloseWindow()"/>
<command id="cmd_ToggleTabsOnTop" oncommand="TabsOnTop.toggle()"/>
<command id="cmd_CustomizeToolbars" oncommand="BrowserCustomizeToolbar()"/>
<command id="cmd_quitApplication" oncommand="goQuitApplication()"/>
+ <command id="cmd_quitApplicationKB" oncommand="goQuitApplicationKB()"/>
<commandset id="editMenuCommands"/>
<command id="View:PageSource" oncommand="BrowserViewSourceOfDocument(content.document);" observes="isImage"/>
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
<command id="cmd_find"
@@ -398,17 +399,17 @@
<key id="key_tabview" key="&tabView.commandkey;" command="Browser:ToggleTabView" modifiers="accel,shift"/>
<key id="key_privatebrowsing" command="Tools:PrivateBrowsing" key="&privateBrowsingCmd.commandkey;" modifiers="accel,shift"/>
<key id="key_sanitize" command="Tools:Sanitize" keycode="VK_DELETE" modifiers="accel,shift"/>
#ifdef XP_MACOSX
<key id="key_sanitize_mac" command="Tools:Sanitize" keycode="VK_BACK" modifiers="accel,shift"/>
#endif
#ifdef XP_UNIX
- <key id="key_quitApplication" key="&quitApplicationCmdMac.key;" command="cmd_quitApplication" modifiers="accel"/>
+ <key id="key_quitApplication" key="&quitApplicationCmdMac.key;" command="cmd_quitApplicationKB" modifiers="accel"/>
#endif
#ifdef FULL_BROWSER_WINDOW
<key id="key_undoCloseTab" command="History:UndoCloseTab" key="&tabCmd.commandkey;" modifiers="accel,shift"/>
#endif
<key id="key_undoCloseWindow" command="History:UndoCloseWindow" key="&newNavigatorCmd.key;" modifiers="accel,shift"/>
#ifdef XP_GNOME
diff --git a/toolkit/content/globalOverlay.js b/toolkit/content/globalOverlay.js
--- a/toolkit/content/globalOverlay.js
+++ b/toolkit/content/globalOverlay.js
@@ -50,16 +50,38 @@ function canQuitApplication(aData)
// Something aborted the quit process.
if (cancelQuit.data)
return false;
}
catch (ex) { }
return true;
}
+function goQuitApplicationKB() {
+ let canQuit = true;
+
+ dump("\n\nquit via keyboard\n\n");
+
+#ifdef XP_MACOSX
+ // on OSX we want to do something special to prevent the KB quit from being too easy
+ // For now, just another observer topic will do
+ var os = Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Components.interfaces.nsIObserverService);
+ if (os) {
+ var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
+ .createInstance(Components.interfaces.nsISupportsPRBool);
+ os.notifyObservers(cancelQuit, "quit-application-requested-keyboard", null);
+ canQuit = !cancelQuit.data;
+ }
+#endif
+
+ if (canQuit)
+ goQuitApplication();
+}
+
function goQuitApplication()
{
if (!canQuitApplication())
return false;
var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
getService(Components.interfaces.nsIAppStartup);
diff --git a/toolkit/xre/MacApplicationDelegate.mm b/toolkit/xre/MacApplicationDelegate.mm
--- a/toolkit/xre/MacApplicationDelegate.mm
+++ b/toolkit/xre/MacApplicationDelegate.mm
@@ -342,19 +342,35 @@ ProcessPendingGetURLAppleEvents()
return NSTerminateNow;
nsCOMPtr<nsISupportsPRBool> cancelQuit =
do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID);
if (!cancelQuit)
return NSTerminateNow;
cancelQuit->SetData(false);
+ bool abortQuit;
+
+
+ // Because we aren't really native, we only get here if quitting via some
+ // means that aren't us, eg. cmd+q while in cmd+tab, quitting via activity monitor
+ printf("\n\napplicationShouldTerminate\n\n");
+
+ // Is this a keyboard quit event?
+ NSEvent* event = [sender currentEvent];
+ if ([event type] == NSKeyDown) {
+ printf("\n\nquit via keyboard!\n\n");
+ obsServ->NotifyObservers(cancelQuit, "quit-application-requested-keyboard", nsnull);
+ cancelQuit->GetData(&abortQuit);
+ if (abortQuit)
+ return NSTerminateCancel;
+ }
+
obsServ->NotifyObservers(cancelQuit, "quit-application-requested", nsnull);
- bool abortQuit;
cancelQuit->GetData(&abortQuit);
if (abortQuit)
return NSTerminateCancel;
nsCOMPtr<nsIAppStartup> appService =
do_GetService("@mozilla.org/toolkit/app-startup;1");
if (appService)
appService->Quit(nsIAppStartup::eForceQuit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment