Bug 1852754: part 9) Add tests for dynamically loading <link rel="prefetch"> elements...
[gecko.git] / xpcom / glue / XREAppData.cpp
blob82084d3b5f82890f87f985237c0d5b8e4fde5aa7
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/XREAppData.h"
8 #include "nsCRTGlue.h"
10 namespace mozilla {
12 XREAppData& XREAppData::operator=(const StaticXREAppData& aOther) {
13 vendor = aOther.vendor;
14 name = aOther.name;
15 remotingName = aOther.remotingName;
16 version = aOther.version;
17 buildID = aOther.buildID;
18 ID = aOther.ID;
19 copyright = aOther.copyright;
20 flags = aOther.flags;
21 minVersion = aOther.minVersion;
22 maxVersion = aOther.maxVersion;
23 crashReporterURL = aOther.crashReporterURL;
24 profile = aOther.profile;
25 UAName = aOther.UAName;
26 sourceURL = aOther.sourceURL;
27 updateURL = aOther.updateURL;
29 return *this;
32 XREAppData& XREAppData::operator=(const XREAppData& aOther) = default;
34 void XREAppData::SanitizeNameForDBus(nsACString& aName) {
35 auto IsValidDBusNameChar = [](char aChar) {
36 return IsAsciiAlpha(aChar) || IsAsciiDigit(aChar) || aChar == '_';
39 // D-Bus names can contain only [a-z][A-Z][0-9]_, so we replace all characters
40 // that aren't in that range with underscores.
41 char* cur = aName.BeginWriting();
42 char* end = aName.EndWriting();
43 for (; cur != end; cur++) {
44 if (!IsValidDBusNameChar(*cur)) {
45 *cur = '_';
50 void XREAppData::GetDBusAppName(nsACString& aName) const {
51 const char* env = getenv("MOZ_DBUS_APP_NAME");
52 if (env) {
53 aName.Assign(env);
54 } else {
55 aName.Assign(remotingName);
56 SanitizeNameForDBus(aName);
60 } // namespace mozilla