Bug 1541958 - remove nsIUserInfo which is unused, r=mossop
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 04 Apr 2019 20:09:34 +0000
changeset 468100 cb5bd749696eb4e1518b9d79295a9bd56320b21c
parent 468099 8b7042135b72463983297f0959eec39fb0cc819b
child 468101 1ea4b3582033d4d9777590af85c7299f68861ffd
push id112682
push userbtara@mozilla.com
push dateFri, 05 Apr 2019 09:57:50 +0000
treeherdermozilla-inbound@a9c1e80ab315 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1541958
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1541958 - remove nsIUserInfo which is unused, r=mossop Differential Revision: https://phabricator.services.mozilla.com/D26212
testing/modules/tests/xpcshell/test_mockRegistrar.js
toolkit/components/build/components.conf
toolkit/components/startup/moz.build
toolkit/components/startup/nsUserInfo.h
toolkit/components/startup/nsUserInfoMac.h
toolkit/components/startup/nsUserInfoMac.mm
toolkit/components/startup/nsUserInfoUnix.cpp
toolkit/components/startup/nsUserInfoWin.cpp
toolkit/components/startup/public/moz.build
toolkit/components/startup/public/nsIUserInfo.idl
--- a/testing/modules/tests/xpcshell/test_mockRegistrar.js
+++ b/testing/modules/tests/xpcshell/test_mockRegistrar.js
@@ -1,44 +1,41 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const {MockRegistrar} = ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
 
-function userInfo(username) {
-  this.username = username;
+function platformInfo(injectedValue) {
+  this.platformVersion = injectedValue;
 }
 
-userInfo.prototype = {
-  fullname: "fullname",
-  emailAddress: "emailAddress",
-  domain: "domain",
-  QueryInterface: ChromeUtils.generateQI([Ci.nsIUserInfo]),
+platformInfo.prototype = {
+  platformVersion: "some version",
+  platformBuildID: "some id",
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIPlatformInfo]),
 };
 
 add_test(function test_register() {
-  let localUserInfo = {
-    fullname: "fullname",
-    username: "localusername",
-    emailAddress: "emailAddress",
-    domain: "domain",
-    QueryInterface: ChromeUtils.generateQI([Ci.nsIUserInfo]),
+  let localPlatformInfo = {
+    platformVersion: "local version",
+    platformBuildID: "local id",
+    QueryInterface: ChromeUtils.generateQI([Ci.nsIPlatformInfo]),
   };
 
-  MockRegistrar.register("@mozilla.org/userinfo;1", localUserInfo);
-  Assert.equal(Cc["@mozilla.org/userinfo;1"].createInstance(Ci.nsIUserInfo).username, "localusername");
+  MockRegistrar.register("@mozilla.org/xre/app-info;1", localPlatformInfo);
+  Assert.equal(Cc["@mozilla.org/xre/app-info;1"].createInstance(Ci.nsIPlatformInfo).platformVersion, "local version");
   run_next_test();
 });
 
 add_test(function test_register_with_arguments() {
-  MockRegistrar.register("@mozilla.org/userinfo;1", userInfo, ["username"]);
-  Assert.equal(Cc["@mozilla.org/userinfo;1"].createInstance(Ci.nsIUserInfo).username, "username");
+  MockRegistrar.register("@mozilla.org/xre/app-info;1", platformInfo, ["override"]);
+  Assert.equal(Cc["@mozilla.org/xre/app-info;1"].createInstance(Ci.nsIPlatformInfo).platformVersion, "override");
   run_next_test();
 });
 
 add_test(function test_register_twice() {
-  MockRegistrar.register("@mozilla.org/userinfo;1", userInfo, ["originalname"]);
-  Assert.equal(Cc["@mozilla.org/userinfo;1"].createInstance(Ci.nsIUserInfo).username, "originalname");
+  MockRegistrar.register("@mozilla.org/xre/app-info;1", platformInfo, ["override"]);
+  Assert.equal(Cc["@mozilla.org/xre/app-info;1"].createInstance(Ci.nsIPlatformInfo).platformVersion, "override");
 
-  MockRegistrar.register("@mozilla.org/userinfo;1", userInfo, ["newname"]);
-  Assert.equal(Cc["@mozilla.org/userinfo;1"].createInstance(Ci.nsIUserInfo).username, "newname");
+  MockRegistrar.register("@mozilla.org/xre/app-info;1", platformInfo, ["override again"]);
+  Assert.equal(Cc["@mozilla.org/xre/app-info;1"].createInstance(Ci.nsIPlatformInfo).platformVersion, "override again");
   run_next_test();
 });
--- a/toolkit/components/build/components.conf
+++ b/toolkit/components/build/components.conf
@@ -152,23 +152,16 @@ Classes = [
     {
         'name': 'UrlClassifierUtils',
         'cid': '{b7b2ccec-7912-4ea6-a548-b038447004bd}',
         'contract_ids': ['@mozilla.org/url-classifier/utils;1'],
         'type': 'nsUrlClassifierUtils',
         'headers': ['/toolkit/components/url-classifier/nsUrlClassifierUtils.h'],
         'constructor': 'nsUrlClassifierUtils::GetXPCOMSingleton',
     },
-    {
-        'name': 'UserInfo',
-        'cid': '{14c13684-1dd2-11b2-9463-bb10ba742554}',
-        'contract_ids': ['@mozilla.org/userinfo;1'],
-        'type': 'nsUserInfo',
-        'headers': ['/toolkit/components/startup/nsUserInfo.h'],
-    },
 ]
 
 if defined('MOZ_UPDATER') and not IS_ANDROID:
     Classes += [
         {
             'cid': '{f3dcf644-79e8-4f59-a1bb-878454488ef9}',
             'contract_ids': ['@mozilla.org/updates/update-processor;1'],
             'type': 'nsUpdateProcessor',
--- a/toolkit/components/startup/moz.build
+++ b/toolkit/components/startup/moz.build
@@ -13,26 +13,12 @@ EXPORTS.mozilla += [
 BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
 XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
 
 UNIFIED_SOURCES += [
     'nsAppStartup.cpp',
     'StartupTimeline.cpp',
 ]
 
-if CONFIG['OS_ARCH'] == 'WINNT':
-    # This file cannot be built in unified mode because of name clashes with Windows headers.
-    SOURCES += [
-        'nsUserInfoWin.cpp',
-    ]
-elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
-    UNIFIED_SOURCES += [
-        'nsUserInfoMac.mm',
-    ]
-else:
-    UNIFIED_SOURCES += [
-        'nsUserInfoUnix.cpp',
-    ]
-
 FINAL_LIBRARY = 'xul'
 
 with Files('**'):
     BUG_COMPONENT = ('Toolkit', 'Startup and Profile System')
deleted file mode 100644
--- a/toolkit/components/startup/nsUserInfo.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef __nsUserInfo_h
-#define __nsUserInfo_h
-
-#include "nsIUserInfo.h"
-
-class nsUserInfo : public nsIUserInfo
-
-{
- public:
-  nsUserInfo(void);
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIUSERINFO
-
- protected:
-  virtual ~nsUserInfo();
-};
-
-#endif /* __nsUserInfo_h */
deleted file mode 100644
--- a/toolkit/components/startup/nsUserInfoMac.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef __nsUserInfoMac_h
-#define __nsUserInfoMac_h
-
-#include "nsIUserInfo.h"
-#include "nsReadableUtils.h"
-
-class nsUserInfo : public nsIUserInfo {
- public:
-  nsUserInfo();
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIUSERINFO
-
-  nsresult GetPrimaryEmailAddress(nsACString &aEmailAddress);
-
- protected:
-  virtual ~nsUserInfo() {}
-};
-
-#endif /* __nsUserInfo_h */
deleted file mode 100644
--- a/toolkit/components/startup/nsUserInfoMac.mm
+++ /dev/null
@@ -1,73 +0,0 @@
-/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsUserInfoMac.h"
-#include "nsObjCExceptions.h"
-#include "nsString.h"
-#include "mozilla/Span.h"
-
-#import <Cocoa/Cocoa.h>
-#import <AddressBook/AddressBook.h>
-
-NS_IMPL_ISUPPORTS(nsUserInfo, nsIUserInfo)
-
-nsUserInfo::nsUserInfo() {}
-
-NS_IMETHODIMP
-nsUserInfo::GetFullname(nsAString& aFullname) {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
-
-  CopyUTF8toUTF16(mozilla::MakeStringSpan([NSFullUserName() UTF8String]), aFullname);
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetUsername(nsACString& aUsername) {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
-
-  aUsername.Assign([NSUserName() UTF8String]);
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
-}
-
-nsresult nsUserInfo::GetPrimaryEmailAddress(nsACString& aEmailAddress) {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
-
-  // Try to get this user's primary email from the system addressbook's "me card"
-  // (if they've filled it)
-  ABPerson* me = [[ABAddressBook sharedAddressBook] me];
-  ABMultiValue* emailAddresses = [me valueForProperty:kABEmailProperty];
-  if ([emailAddresses count] > 0) {
-    // get the index of the primary email, in case there are more than one
-    int primaryEmailIndex = [emailAddresses indexForIdentifier:[emailAddresses primaryIdentifier]];
-    aEmailAddress.Assign([[emailAddresses valueAtIndex:primaryEmailIndex] UTF8String]);
-    return NS_OK;
-  }
-
-  return NS_ERROR_FAILURE;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetEmailAddress(nsACString& aEmailAddress) {
-  return GetPrimaryEmailAddress(aEmailAddress);
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetDomain(nsACString& aDomain) {
-  nsAutoCString email;
-  if (NS_SUCCEEDED(GetPrimaryEmailAddress(email))) {
-    int32_t index = email.FindChar('@');
-    if (index != -1) {
-      // chop off everything before, and including the '@'
-      aDomain.Assign(Substring(email, index + 1));
-    }
-  }
-  return NS_OK;
-}
deleted file mode 100644
--- a/toolkit/components/startup/nsUserInfoUnix.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsUserInfo.h"
-#include "nsCRT.h"
-
-#include <pwd.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/utsname.h>
-
-#include "nsString.h"
-#include "nsReadableUtils.h"
-#include "nsNativeCharsetUtils.h"
-
-/* Some UNIXy platforms don't have pw_gecos. In this case we use pw_name */
-#if defined(NO_PW_GECOS)
-#  define PW_GECOS pw_name
-#else
-#  define PW_GECOS pw_gecos
-#endif
-
-nsUserInfo::nsUserInfo() {}
-
-nsUserInfo::~nsUserInfo() {}
-
-NS_IMPL_ISUPPORTS(nsUserInfo, nsIUserInfo)
-
-NS_IMETHODIMP
-nsUserInfo::GetFullname(nsAString& aFullname) {
-  struct passwd* pw = nullptr;
-
-  pw = getpwuid(geteuid());
-
-  if (!pw || !pw->PW_GECOS) return NS_ERROR_FAILURE;
-
-#ifdef DEBUG_sspitzer
-  printf("fullname = %s\n", pw->PW_GECOS);
-#endif
-
-  nsAutoCString fullname(pw->PW_GECOS);
-
-  // now try to parse the GECOS information, which will be in the form
-  // Full Name, <other stuff> - eliminate the ", <other stuff>
-  // also, sometimes GECOS uses "&" to mean "the user name" so do
-  // the appropriate substitution
-
-  // truncate at first comma (field delimiter)
-  int32_t index;
-  if ((index = fullname.Find(",")) != kNotFound) fullname.Truncate(index);
-
-  // replace ampersand with username
-  if (pw->pw_name) {
-    nsAutoCString username(pw->pw_name);
-    if (!username.IsEmpty() && nsCRT::IsLower(username.CharAt(0)))
-      username.SetCharAt(nsCRT::ToUpper(username.CharAt(0)), 0);
-
-    fullname.ReplaceSubstring("&", username.get());
-  }
-
-  NS_CopyNativeToUnicode(fullname, aFullname);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetUsername(nsACString& aUsername) {
-  struct passwd* pw = nullptr;
-
-  // is this portable?  those are POSIX compliant calls, but I need to check
-  pw = getpwuid(geteuid());
-
-  if (!pw || !pw->pw_name) return NS_ERROR_FAILURE;
-
-#ifdef DEBUG_sspitzer
-  printf("username = %s\n", pw->pw_name);
-#endif
-
-  aUsername.Assign(pw->pw_name);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetDomain(nsACString& aDomain) {
-  nsresult rv = NS_ERROR_FAILURE;
-
-  struct utsname buf;
-  char* domainname = nullptr;
-
-  if (uname(&buf) < 0) {
-    return rv;
-  }
-
-#if defined(__linux__)
-  domainname = buf.domainname;
-#endif
-
-  if (domainname && domainname[0]) {
-    aDomain.Assign(domainname);
-    rv = NS_OK;
-  } else {
-    // try to get the hostname from the nodename
-    // on machines that use DHCP, domainname may not be set
-    // but the nodename might.
-    if (buf.nodename[0]) {
-      // if the nodename is foo.bar.org, use bar.org as the domain
-      char* pos = strchr(buf.nodename, '.');
-      if (pos) {
-        aDomain.Assign(pos + 1);
-        rv = NS_OK;
-      }
-    }
-  }
-
-  return rv;
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetEmailAddress(nsACString& aEmailAddress) {
-  // use username + "@" + domain for the email address
-  nsresult rv;
-
-  nsCString username;
-  nsCString domain;
-
-  rv = GetUsername(username);
-  if (NS_FAILED(rv)) return rv;
-
-  rv = GetDomain(domain);
-  if (NS_FAILED(rv)) return rv;
-
-  if (username.IsEmpty() || domain.IsEmpty()) {
-    return NS_ERROR_FAILURE;
-  }
-
-  aEmailAddress = username + NS_LITERAL_CSTRING("@") + domain;
-  return NS_OK;
-}
deleted file mode 100644
--- a/toolkit/components/startup/nsUserInfoWin.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsUserInfo.h"
-
-#include "mozilla/ArrayUtils.h"  // ArrayLength
-#include "mozilla/Span.h"        // MakeStringSpan
-#include "nsString.h"
-#include "windows.h"
-#include "nsCRT.h"
-
-#define SECURITY_WIN32
-#include "lm.h"
-#include "security.h"
-
-nsUserInfo::nsUserInfo() {}
-
-nsUserInfo::~nsUserInfo() {}
-
-NS_IMPL_ISUPPORTS(nsUserInfo, nsIUserInfo)
-
-NS_IMETHODIMP
-nsUserInfo::GetUsername(nsACString& aUsername) {
-  // UNLEN is the max username length as defined in lmcons.h
-  wchar_t username[UNLEN + 1];
-  DWORD size = mozilla::ArrayLength(username);
-  if (!GetUserNameW(username, &size)) return NS_ERROR_FAILURE;
-
-  CopyUTF16toUTF8(nsDependentString(username), aUsername);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetFullname(nsAString& aFullname) {
-  wchar_t fullName[512];
-  DWORD size = mozilla::ArrayLength(fullName);
-
-  if (GetUserNameExW(NameDisplay, fullName, &size)) {
-    aFullname.Assign(fullName);
-  } else {
-    DWORD getUsernameError = GetLastError();
-
-    // Try to use the net APIs regardless of the error because it may be
-    // able to obtain the information.
-    wchar_t username[UNLEN + 1];
-    size = mozilla::ArrayLength(username);
-    if (!GetUserNameW(username, &size)) {
-      // ERROR_NONE_MAPPED means the user info is not filled out on this
-      // computer
-      return getUsernameError == ERROR_NONE_MAPPED ? NS_ERROR_NOT_AVAILABLE
-                                                   : NS_ERROR_FAILURE;
-    }
-
-    const DWORD level = 2;
-    LPBYTE info;
-    // If the NetUserGetInfo function has no full name info it will return
-    // success with an empty string.
-    NET_API_STATUS status = NetUserGetInfo(nullptr, username, level, &info);
-    if (status != NERR_Success) {
-      // We have an error with NetUserGetInfo but we know the info is not
-      // filled in because GetUserNameExW returned ERROR_NONE_MAPPED.
-      return getUsernameError == ERROR_NONE_MAPPED ? NS_ERROR_NOT_AVAILABLE
-                                                   : NS_ERROR_FAILURE;
-    }
-
-    nsDependentString fullName = nsDependentString(
-        reinterpret_cast<USER_INFO_2*>(info)->usri2_full_name);
-
-    // NetUserGetInfo returns an empty string if the full name is not filled out
-    if (fullName.Length() == 0) {
-      NetApiBufferFree(info);
-      return NS_ERROR_NOT_AVAILABLE;
-    }
-
-    aFullname.Assign(fullName);
-    NetApiBufferFree(info);
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetDomain(nsACString& aDomain) {
-  const DWORD level = 100;
-  LPBYTE info;
-  NET_API_STATUS status = NetWkstaGetInfo(nullptr, level, &info);
-  if (status != NERR_Success) {
-    return NS_ERROR_FAILURE;
-  }
-
-  CopyUTF16toUTF8(nsDependentString(
-                      reinterpret_cast<WKSTA_INFO_100*>(info)->wki100_langroup),
-                  aDomain);
-  NetApiBufferFree(info);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsUserInfo::GetEmailAddress(nsACString& aEmailAddress) {
-  // RFC3696 says max length of an email address is 254
-  wchar_t emailAddress[255];
-  DWORD size = mozilla::ArrayLength(emailAddress);
-
-  if (!GetUserNameExW(NameUserPrincipal, emailAddress, &size)) {
-    DWORD getUsernameError = GetLastError();
-    return getUsernameError == ERROR_NONE_MAPPED ? NS_ERROR_NOT_AVAILABLE
-                                                 : NS_ERROR_FAILURE;
-  }
-
-  CopyUTF16toUTF8(nsDependentString(emailAddress), aEmailAddress);
-  return NS_OK;
-}
--- a/toolkit/components/startup/public/moz.build
+++ b/toolkit/components/startup/public/moz.build
@@ -1,13 +1,12 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPIDL_SOURCES += [
     'nsIAppStartup.idl',
-    'nsIUserInfo.idl',
 ]
 
 XPIDL_MODULE = 'appstartup'
 
deleted file mode 100644
--- a/toolkit/components/startup/public/nsIUserInfo.idl
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsISupports.idl"
-
-[scriptable, uuid(6c1034f0-1dd2-11b2-aa14-e6657ed7bb0b)]
-interface nsIUserInfo : nsISupports
-{
-    /* these are things the system may know about the current user */
-
-    readonly attribute AString fullname;
-
-    readonly attribute ACString emailAddress;
-
-    /* should this be an AString? */
-    readonly attribute ACString username;
-
-    readonly attribute ACString domain;
-};
-
-%{C++
-
-// 14c13684-1dd2-11b2-9463-bb10ba742554
-#define NS_USERINFO_CID \
-{  0x14c13684, 0x1dd2, 0x11b2, \
-  {0x94, 0x63, 0xbb, 0x10, 0xba, 0x74, 0x25, 0x54}}
-
-#define NS_USERINFO_CONTRACTID "@mozilla.org/userinfo;1"
-
-%}