Bug 960149 ShellService Fixups. Port Some Firefox bugs (Bug 531174, Bug 784739, Bug 791694, Bug 945245, Bug 949821) r= Neil SEA_2_26_1_RELBRANCH
authorPhilip Chee <philip.chee@gmail.com>
Thu, 20 Feb 2014 01:44:17 +0800
branchSEA_2_26_1_RELBRANCH
changeset 31064 64aa494ec68c5f7e9b2f02e653171afcc240d72a
parent 31063 1be8b2fb73506a852d49ca7b0c1455c20841c4d0
child 31065 38065a20158cb05b99144ccff794247481863590
push id1
push userclokep@gmail.com
push dateMon, 07 May 2018 22:45:56 +0000
treeherdercomm-esr60@57eacde5ef40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs960149, 531174, 784739, 791694, 945245, 949821, 927728
Bug 960149 ShellService Fixups. Port Some Firefox bugs (Bug 531174, Bug 784739, Bug 791694, Bug 945245, Bug 949821) r= Neil Bug 531174 [@ WriteBitmap] (Crash) Bug 784739 Switch from NULL to nullptr Bug 791694 Use XRE_EXECUTABLE_FILE in browser shell instead of guesswork from NS_XPCOM_CURRENT_PROCESS_DIR and MOZ_APP_NAME. Bug 945245 Fixed misc char16_t/wchar_t mismatches Bug 949821 use MOZ_UTF16 more and NS_LITERAL_STRING less Bug 927728 Replace PRUnichar with char16_t
suite/shell/src/nsGNOMEShellService.cpp
suite/shell/src/nsMacShellService.cpp
suite/shell/src/nsWindowsShellService.cpp
--- a/suite/shell/src/nsGNOMEShellService.cpp
+++ b/suite/shell/src/nsGNOMEShellService.cpp
@@ -82,17 +82,17 @@ GetBrandName(nsACString& aBrandName)
   nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIStringBundle> brandBundle;
   rv = bundleService->CreateBundle(BRAND_PROPERTIES, getter_AddRefs(brandBundle));
   NS_ENSURE_TRUE(brandBundle, rv);
 
   nsString brandName;
-  rv = brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
+  rv = brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"),
                                       getter_Copies(brandName));
   NS_ENSURE_SUCCESS(rv, rv);
 
   CopyUTF16toUTF8(brandName, aBrandName);
   return rv;
 }
 
 nsresult
@@ -133,22 +133,23 @@ nsGNOMEShellService::Init()
 }
 
 bool
 nsGNOMEShellService::HandlerMatchesAppName(const char* aHandler)
 {
   bool matches = false;
   gint argc;
   gchar** argv;
-  if (g_shell_parse_argv(aHandler, &argc, &argv, NULL) && argc > 0) {
-    gchar* command = NULL;
+  if (g_shell_parse_argv(aHandler, &argc, &argv, nullptr) && argc > 0) {
+    gchar* command = nullptr;
     if (!mUseLocaleFilenames)
       command = g_find_program_in_path(argv[0]);
     else {
-      gchar* nativeFile = g_filename_from_utf8(argv[0], -1, NULL, NULL, NULL);
+      gchar* nativeFile = g_filename_from_utf8(argv[0], -1,
+                                               nullptr, nullptr, nullptr);
       if (nativeFile) {
         command = g_find_program_in_path(nativeFile);
         g_free(nativeFile);
       }
     }
     matches = command && mAppPath.Equals(command);
     g_free(command);
     g_strfreev(argv);
@@ -334,17 +335,18 @@ nsGNOMEShellService::SetDesktopBackgroun
   if (!imgToPixbuf)
     return NS_ERROR_NOT_AVAILABLE;
 
   GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(container);
   if (!pixbuf)
     return NS_ERROR_NOT_AVAILABLE;
 
   // write the image to a file in the home dir
-  gboolean res = gdk_pixbuf_save(pixbuf, filePath.get(), "png", NULL, NULL);
+  gboolean res = gdk_pixbuf_save(pixbuf, filePath.get(), "png",
+                                 nullptr, nullptr);
 
   g_object_unref(pixbuf);
   if (!res)
     return NS_ERROR_FAILURE;
 
   // set desktop wallpaper filling style
   const char* options;
   switch (aPosition) {
@@ -369,17 +371,17 @@ nsGNOMEShellService::SetDesktopBackgroun
   // to using GConf instead. Note that if GSettings works ok, the changes get
   // mirrored to GConf by the gsettings->gconf bridge in gnome-settings-daemon
   nsCOMPtr<nsIGSettingsService> gsettings(do_GetService(NS_GSETTINGSSERVICE_CONTRACTID));
   if (gsettings) {
     nsCOMPtr<nsIGSettingsCollection> background_settings;
     gsettings->GetCollectionForSchema(NS_LITERAL_CSTRING(OGDB_SCHEMA),
                                       getter_AddRefs(background_settings));
     if (background_settings) {
-      gchar *file_uri = g_filename_to_uri(filePath.get(), NULL, NULL);
+      gchar *file_uri = g_filename_to_uri(filePath.get(), nullptr, nullptr);
       if (!file_uri)
        return NS_ERROR_FAILURE;
 
       background_settings->SetString(NS_LITERAL_CSTRING(OGDB_OPTIONS),
                                      nsDependentCString(options));
       background_settings->SetString(NS_LITERAL_CSTRING(OGDB_IMAGE),
                                      nsDependentCString(file_uri));
       g_free(file_uri);
--- a/suite/shell/src/nsMacShellService.cpp
+++ b/suite/shell/src/nsMacShellService.cpp
@@ -121,17 +121,17 @@ nsMacShellService::SetShouldCheckDefault
 bool
 nsMacShellService::isDefaultHandlerForProtocol(CFStringRef aScheme)
 {
   bool isDefault = false;
 
   CFStringRef suiteID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
   if (!suiteID)
   {
-    // CFBundleGetIdentifier is expected to return NULL only if the specified
+    // CFBundleGetIdentifier is expected to return nullptr only if the specified
     // bundle doesn't have a bundle identifier in its dictionary. In this case,
     // that means a failure, since our bundle does have an identifier.
     return isDefault;
   }
 
   // Get the default handler's bundle ID for the scheme.
   CFStringRef defaultHandlerID = ::LSCopyDefaultHandlerForURLScheme(aScheme);
   if (defaultHandlerID)
@@ -302,17 +302,18 @@ nsMacShellService::OnStateChange(nsIWebP
 
     AEDesc tAEDesc = { typeNull, nil };
     OSErr err = noErr;
     AliasHandle aliasHandle = nil;
     FSRef pictureRef;
     OSStatus status;
 
     // Convert the path into a FSRef:
-    status = ::FSPathMakeRef((const UInt8*)nativePath.get(), &pictureRef, NULL);
+    status = ::FSPathMakeRef((const UInt8*)nativePath.get(), &pictureRef,
+                             nullptr);
     if (status == noErr)
     {
       err = ::FSNewAlias(nil, &pictureRef, &aliasHandle);
       if (err == noErr && aliasHandle == nil)
         err = paramErr;
 
       if (err == noErr)
       {
@@ -377,36 +378,36 @@ nsMacShellService::OpenApplicationWithUR
   nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(aApplication));
   CFURLRef appURL;
   nsresult rv = lfm->GetCFURL(&appURL);
   if (NS_FAILED(rv))
     return rv;
   
   const nsCString& spec = PromiseFlatCString(aURI);
   const UInt8* uriString = (const UInt8*)spec.get();
-  CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, aURI.Length(),
-                                        kCFStringEncodingUTF8, NULL);
+  CFURLRef uri = ::CFURLCreateWithBytes(nullptr, uriString, aURI.Length(),
+                                        kCFStringEncodingUTF8, nullptr);
   if (!uri) 
     return NS_ERROR_OUT_OF_MEMORY;
   
-  CFArrayRef uris = ::CFArrayCreate(NULL, (const void**)&uri, 1, NULL);
+  CFArrayRef uris = ::CFArrayCreate(nullptr, (const void**)&uri, 1, nullptr);
   if (!uris)
   {
     ::CFRelease(uri);
     return NS_ERROR_OUT_OF_MEMORY;
   }
   
   LSLaunchURLSpec launchSpec;
   launchSpec.appURL = appURL;
   launchSpec.itemURLs = uris;
-  launchSpec.passThruParams = NULL;
+  launchSpec.passThruParams = nullptr;
   launchSpec.launchFlags = kLSLaunchDefaults;
-  launchSpec.asyncRefCon = NULL;
+  launchSpec.asyncRefCon = nullptr;
   
-  OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL);
+  OSErr err = ::LSOpenFromURLSpec(&launchSpec, nullptr);
   
   ::CFRelease(uris);
   ::CFRelease(uri);
   
   return err != noErr ? NS_ERROR_FAILURE : NS_OK;
 }
 
 NS_IMETHODIMP
@@ -418,21 +419,21 @@ nsMacShellService::GetDefaultFeedReader(
   CFStringRef defaultHandlerID = ::LSCopyDefaultHandlerForURLScheme(CFSTR("feed"));
   if (!defaultHandlerID)
   {
     defaultHandlerID = ::CFStringCreateWithCString(kCFAllocatorDefault,
                                                    SAFARI_BUNDLE_IDENTIFIER,
                                                    kCFStringEncodingASCII);
   }
 
-  CFURLRef defaultHandlerURL = NULL;
+  CFURLRef defaultHandlerURL = nullptr;
   OSStatus status = ::LSFindApplicationForInfo(kLSUnknownCreator,
                                                defaultHandlerID,
-                                               NULL, // inName
-                                               NULL, // outAppRef
+                                               nullptr, // inName
+                                               nullptr, // outAppRef
                                                &defaultHandlerURL);
 
   if (status == noErr && defaultHandlerURL)
   {
     nsCOMPtr<nsILocalFileMac> defaultReader =
       do_CreateInstance("@mozilla.org/file/local;1", &rv);
     if (NS_SUCCEEDED(rv))
     {
--- a/suite/shell/src/nsWindowsShellService.cpp
+++ b/suite/shell/src/nsWindowsShellService.cpp
@@ -20,16 +20,17 @@
 #include "nsIServiceManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsIWindowsRegKey.h"
 #include "nsIWinTaskbar.h"
 #include "nsISupportsPrimitives.h"
+#include "nsXULAppAPI.h"
 #include <mbstring.h>
 #include "mozilla/Services.h"
 
 #ifdef _WIN32_WINNT
 #undef _WIN32_WINNT
 #endif
 #define _WIN32_WINNT 0x0600
 #define INITGUID
@@ -45,17 +46,17 @@
 #define REG_FAILED(val) \
   (val != ERROR_SUCCESS)
 
 #define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1"
 
 NS_IMPL_ISUPPORTS2(nsWindowsShellService, nsIWindowsShellService, nsIShellService)
 
 static nsresult
-OpenKeyForReading(HKEY aKeyRoot, const char16_t* aKeyName, HKEY* aKey)
+OpenKeyForReading(HKEY aKeyRoot, const wchar_t* aKeyName, HKEY* aKey)
 {
   DWORD res = ::RegOpenKeyExW(aKeyRoot, aKeyName, 0, KEY_READ, aKey);
   switch (res) {
   case ERROR_SUCCESS:
    break;
   case ERROR_ACCESS_DENIED:
     return NS_ERROR_FILE_ACCESS_DENIED;
   case ERROR_FILE_NOT_FOUND:
@@ -300,22 +301,22 @@ nsresult
 GetHelperPath(nsString& aPath)
 {
   nsresult rv;
   nsCOMPtr<nsIProperties> directoryService = 
     do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIFile> appHelper;
-  rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
+  rv = directoryService->Get(XRE_EXECUTABLE_FILE,
                              NS_GET_IID(nsIFile),
                              getter_AddRefs(appHelper));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = appHelper->AppendNative(NS_LITERAL_CSTRING("uninstall"));
+  rv = appHelper->SetNativeLeafName(NS_LITERAL_CSTRING("uninstall"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = appHelper->AppendNative(NS_LITERAL_CSTRING("helper.exe"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = appHelper->GetPath(aPath);
 
   aPath.Insert('"', 0);
@@ -325,18 +326,18 @@ GetHelperPath(nsString& aPath)
 }
 
 nsresult
 LaunchHelper(const nsString& aPath)
 {
   STARTUPINFOW si = {sizeof(si), 0};
   PROCESS_INFORMATION pi = {0};
 
-  BOOL ok = CreateProcessW(NULL, (LPWSTR)aPath.get(), NULL, NULL,
-                           FALSE, 0, NULL, NULL, &si, &pi);
+  BOOL ok = CreateProcessW(nullptr, (LPWSTR)aPath.get(), nullptr, nullptr,
+                           FALSE, 0, nullptr, nullptr, &si, &pi);
 
   if (!ok)
     return NS_ERROR_FAILURE;
 
   CloseHandle(pi.hProcess);
   CloseHandle(pi.hThread);
   return NS_OK;
 }
@@ -415,17 +416,17 @@ nsWindowsShellService::ShortcutMaintenan
 }
 
 /* helper routine. Iterate over the passed in settings object,
    testing each key to see if we are handling it.
 */
 bool
 nsWindowsShellService::TestForDefault(SETTING aSettings[], int32_t aSize)
 {
-  char16_t currValue[MAX_BUF];
+  wchar_t currValue[MAX_BUF];
   SETTING* end = aSettings + aSize;
   for (SETTING * settings = aSettings; settings < end; ++settings) {
     NS_ConvertUTF8toUTF16 dataLongPath(settings->valueData);
     NS_ConvertUTF8toUTF16 dataShortPath(settings->valueData);
     NS_ConvertUTF8toUTF16 key(settings->keyName);
     NS_ConvertUTF8toUTF16 value(settings->valueName);
     if (settings->flags & APP_PATH_SUBSTITUTION) {
       int32_t offset = dataLongPath.Find("%APPPATH%");
@@ -442,33 +443,33 @@ nsWindowsShellService::TestForDefault(SE
     HKEY theKey;
     nsresult rv = OpenKeyForReading(HKEY_CLASSES_ROOT, key.get(), &theKey);
     if (NS_FAILED(rv))
       // Key does not exist
       return false;
 
     DWORD len = sizeof currValue;
     DWORD res = ::RegQueryValueExW(theKey, value.get(),
-                                   NULL, NULL, (LPBYTE)currValue, &len);
+                                   nullptr, nullptr, (LPBYTE)currValue, &len);
     // Close the key we opened.
     ::RegCloseKey(theKey);
     if (REG_FAILED(res) ||
         !dataLongPath.Equals(currValue, CaseInsensitiveCompare) &&
         !dataShortPath.Equals(currValue, CaseInsensitiveCompare)) {
       // Key wasn't set, or was set to something else (something else became the default client)
       return false;
     }
   }
 
   return true;
 }
 
 nsresult nsWindowsShellService::Init()
 {
-  char16_t appPath[MAX_BUF];
+  wchar_t appPath[MAX_BUF];
   if (!::GetModuleFileNameW(0, appPath, MAX_BUF))
     return NS_ERROR_FAILURE;
 
   mAppLongPath = appPath;
 
   // Support short path to the exe so if it is already set the user is not
   // prompted to set the default mail client again.
   if (!::GetShortPathNameW(appPath, appPath, MAX_BUF))
@@ -480,17 +481,17 @@ nsresult nsWindowsShellService::Init()
 }
 
 bool
 nsWindowsShellService::IsDefaultClientVista(uint16_t aApps, bool* aIsDefaultClient)
 {
   IApplicationAssociationRegistration* pAAR;
 
   HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
-                                NULL,
+                                nullptr,
                                 CLSCTX_INPROC,
                                 IID_IApplicationAssociationRegistration,
                                 (void**)&pAAR);
   
   if (SUCCEEDED(hr)) {
     BOOL isDefaultBrowser = true;
     BOOL isDefaultMail    = true;
     BOOL isDefaultNews    = true;
@@ -568,18 +569,18 @@ nsWindowsShellService::SetDefaultClient(
 
     if (aApps & nsIShellService::NEWS)
       appHelperPath.AppendLiteral(" News");
    }
 
   STARTUPINFOW si = {sizeof(si), 0};
   PROCESS_INFORMATION pi = {0};
 
-  BOOL ok = CreateProcessW(NULL, (LPWSTR)appHelperPath.get(), NULL, NULL,
-                           FALSE, 0, NULL, NULL, &si, &pi);
+  BOOL ok = CreateProcessW(nullptr, (LPWSTR)appHelperPath.get(), nullptr,
+                           nullptr, FALSE, 0, nullptr, nullptr, &si, &pi);
 
   if (!ok)
     return NS_ERROR_FAILURE;
 
   CloseHandle(pi.hProcess);
   CloseHandle(pi.hThread);
 
   return NS_OK;
@@ -722,16 +723,17 @@ nsWindowsShellService::SetDesktopBackgro
 {
   nsresult rv;
 
   nsCOMPtr<imgIContainer> container;
 
   nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aElement));
   if (!imgElement) {
     // XXX write background loading stuff!
+    return NS_ERROR_NOT_AVAILABLE;
   }
   else {
     nsCOMPtr<nsIImageLoadingContent> imageContent =
       do_QueryInterface(aElement, &rv);
     if (!imageContent)
       return rv;
 
     // get the image container
@@ -754,17 +756,17 @@ nsWindowsShellService::SetDesktopBackgro
   nsCOMPtr<nsIStringBundle> shellBundle;
   rv = bundleService->CreateBundle(SHELLSERVICE_PROPERTIES,
                                    getter_AddRefs(shellBundle));
   NS_ENSURE_SUCCESS(rv, rv);
  
   // e.g. "Desktop Background.bmp"
   nsString fileLeafName;
   rv = shellBundle->GetStringFromName
-                      (NS_LITERAL_STRING("desktopBackgroundLeafNameWin").get(),
+                      (MOZ_UTF16("desktopBackgroundLeafNameWin"),
                        getter_Copies(fileLeafName));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // get the profile root directory
   nsCOMPtr<nsIFile> file;
   rv = NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_DIR,
                               getter_AddRefs(file));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -810,18 +812,18 @@ nsWindowsShellService::SetDesktopBackgro
 
     value.Assign(aPosition == BACKGROUND_TILE ? '1' : '0');
     rv = key->WriteStringValue(NS_LITERAL_STRING("TileWallpaper"), value);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = key->Close();
     NS_ENSURE_SUCCESS(rv, rv);
 
-   ::SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (PVOID)path.get(),
-                           SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
+    ::SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (PVOID)path.get(),
+                            SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsWindowsShellService::GetDesktopBackgroundColor(uint32_t* aColor)
 {
   uint32_t color = ::GetSysColor(COLOR_DESKTOP);
@@ -844,17 +846,17 @@ nsWindowsShellService::SetDesktopBackgro
   nsCOMPtr<nsIWindowsRegKey> key(do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = key->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
                    NS_LITERAL_STRING("Control Panel\\Colors"),
                    nsIWindowsRegKey::ACCESS_SET_VALUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  char16_t rgb[12];
+  wchar_t rgb[12];
   _snwprintf(rgb, 12, L"%u %u %u", r, g, b);
   rv = key->WriteStringValue(NS_LITERAL_STRING("Background"),
                              nsDependentString(rgb));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return key->Close();
 }