Browse Source

b=623887, r=mfinkle, Unregister protocol handler

matthew.gertner@gmail.com 13 years ago
parent
commit
0a5e5db6b0

+ 12 - 5
client/winbuild/regprot.nsi

@@ -21,18 +21,18 @@ IfErrors 0 +2
 GoTo autostart
 ${StrTok} $R2 $R1 "/" "0" "0"
 
+${GetOptions} $R0 "/DefaultIcon" $R4
+IfErrors 0 +2
+GoTo finish
+
 ${GetOptions} $R0 "/Unregister" $R3
 IfErrors register +1
-GoTo finish
+GoTo unregister
 
 register:
 ${GetOptions} $R0 "/ApplicationPath" $R1
 ${StrTok} $R3 $R1 "/" "0" "0"
 
-${GetOptions} $R0 "/DefaultIcon" $R4
-IfErrors 0 +2
-GoTo finish
-
 WriteRegStr HKCU "SOFTWARE\Classes\$R2" "EditFlags" 2
 WriteRegStr HKCU "SOFTWARE\Classes\$R2" "URL Protocol" ""
 WriteRegStr HKCU "SOFTWARE\Classes\$R2" "FriendlyTypeName" ""
@@ -40,6 +40,13 @@ WriteRegStr HKCU "SOFTWARE\Classes\$R2\DefaultIcon" "" "$R4"
 WriteRegStr HKCU "SOFTWARE\Classes\$R2\shell\open\command" "" "$\"$R3$\" -url $\"%1$\""
 GoTo finish
 
+unregister:
+ReadRegStr $R5 HKCU "SOFTWARE\Classes\$R2\DefaultIcon" ""
+${If} "$R4" == "$R5"
+  DeleteRegKey HKCU "SOFTWARE\Classes\$R2"
+${EndIf}
+GoTo finish
+
 autostart:
 ${GetOptions} $R0 "/AutoStart" $R1
 IfErrors 0 +2

+ 5 - 0
components/src/mac/nsDesktopEnvironmentMac.mm

@@ -331,6 +331,11 @@ NS_IMETHODIMP nsDesktopEnvironment::RegisterProtocol(
 
 NS_IMETHODIMP nsDesktopEnvironment::UnregisterProtocol(const nsAString& aScheme)
 {
+  NSString* scheme = [NSString stringWithCharacters:nsString(aScheme).get() length:aScheme.Length()];
+  // Pass in a dummy value since there doesn't seem to be a proper API for unregistering the handler
+  LSSetDefaultHandlerForURLScheme((CFStringRef) scheme, CFSTR("dummy"));
+  
+  _LSSaveAndRefresh();
   return NS_OK;
 }
 

+ 8 - 2
components/src/nsPlatformGlue.js

@@ -196,6 +196,7 @@ PlatformProtocolHandler.prototype = {
 }
 
 var protocolCallbacks = {};
+var shutdownCallback = null;
 
 function PlatformGlue() {
   var windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
@@ -388,8 +389,13 @@ PlatformGlue.prototype = {
     var contractId = "@mozilla.org/network/protocol;1?name=" + uriScheme;
     // Now what?
 
-    // And remove the pref
-    this._prefs.clearUserPref(PRISM_PROTOCOL_PREFIX + uriScheme);
+    try {
+      // And remove the pref
+      this._prefs.clearUserPref(PRISM_PROTOCOL_PREFIX + uriScheme);
+    }
+    catch (e) {
+      // Presumably the pref is not there so just ignore
+    }
     
     // Remove the callback, if any
     if (uriScheme in protocolCallbacks) {

+ 7 - 0
components/src/windows/nsDesktopEnvironmentWin.cpp

@@ -392,6 +392,13 @@ NS_IMETHODIMP nsDesktopEnvironment::UnregisterProtocol(const nsAString& aScheme)
   helperPath += NS_LITERAL_STRING(" /Protocol ");
   helperPath += aScheme;
   
+  nsAutoString iconPath;
+  rv = GetIconPath(iconPath);
+  NS_ENSURE_SUCCESS(rv, rv);
+   
+  helperPath += NS_LITERAL_STRING(" /DefaultIcon ");
+  helperPath += iconPath;
+
   helperPath += NS_LITERAL_STRING(" /Unregister");
   
   STARTUPINFOW si = {sizeof(si), 0};