xpcom/glue/AppData.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/AppData.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "mozilla/AppData.h"
    1.10 +#include "nsXULAppAPI.h"
    1.11 +#include "nsINIParser.h"
    1.12 +#include "nsIFile.h"
    1.13 +#include "nsCRTGlue.h"
    1.14 +#include "nsAutoPtr.h"
    1.15 +
    1.16 +namespace mozilla {
    1.17 +
    1.18 +void
    1.19 +SetAllocatedString(const char *&str, const char *newvalue)
    1.20 +{
    1.21 +  NS_Free(const_cast<char*>(str));
    1.22 +  if (newvalue) {
    1.23 +    str = NS_strdup(newvalue);
    1.24 +  }
    1.25 +  else {
    1.26 +    str = nullptr;
    1.27 +  }
    1.28 +}
    1.29 +
    1.30 +void
    1.31 +SetAllocatedString(const char *&str, const nsACString &newvalue)
    1.32 +{
    1.33 +  NS_Free(const_cast<char*>(str));
    1.34 +  if (newvalue.IsEmpty()) {
    1.35 +    str = nullptr;
    1.36 +  }
    1.37 +  else {
    1.38 +    str = ToNewCString(newvalue);
    1.39 +  }
    1.40 +}
    1.41 +
    1.42 +ScopedAppData::ScopedAppData(const nsXREAppData* aAppData)
    1.43 +{
    1.44 +  Zero();
    1.45 +
    1.46 +  this->size = aAppData->size;
    1.47 +
    1.48 +  SetAllocatedString(this->vendor, aAppData->vendor);
    1.49 +  SetAllocatedString(this->name, aAppData->name);
    1.50 +  SetAllocatedString(this->version, aAppData->version);
    1.51 +  SetAllocatedString(this->buildID, aAppData->buildID);
    1.52 +  SetAllocatedString(this->ID, aAppData->ID);
    1.53 +  SetAllocatedString(this->copyright, aAppData->copyright);
    1.54 +  SetAllocatedString(this->profile, aAppData->profile);
    1.55 +  SetStrongPtr(this->directory, aAppData->directory);
    1.56 +  this->flags = aAppData->flags;
    1.57 +
    1.58 +  if (aAppData->size > offsetof(nsXREAppData, xreDirectory)) {
    1.59 +    SetStrongPtr(this->xreDirectory, aAppData->xreDirectory);
    1.60 +    SetAllocatedString(this->minVersion, aAppData->minVersion);
    1.61 +    SetAllocatedString(this->maxVersion, aAppData->maxVersion);
    1.62 +  }
    1.63 +
    1.64 +  if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) {
    1.65 +    SetAllocatedString(this->crashReporterURL, aAppData->crashReporterURL);
    1.66 +  }
    1.67 +
    1.68 +  if (aAppData->size > offsetof(nsXREAppData, UAName)) {
    1.69 +    SetAllocatedString(this->UAName, aAppData->UAName);
    1.70 +  }
    1.71 +}
    1.72 +
    1.73 +ScopedAppData::~ScopedAppData()
    1.74 +{
    1.75 +  SetAllocatedString(this->vendor, nullptr);
    1.76 +  SetAllocatedString(this->name, nullptr);
    1.77 +  SetAllocatedString(this->version, nullptr);
    1.78 +  SetAllocatedString(this->buildID, nullptr);
    1.79 +  SetAllocatedString(this->ID, nullptr);
    1.80 +  SetAllocatedString(this->copyright, nullptr);
    1.81 +  SetAllocatedString(this->profile, nullptr);
    1.82 +
    1.83 +  NS_IF_RELEASE(this->directory);
    1.84 +
    1.85 +  SetStrongPtr(this->xreDirectory, (nsIFile*) nullptr);
    1.86 +  SetAllocatedString(this->minVersion, nullptr);
    1.87 +  SetAllocatedString(this->maxVersion, nullptr);
    1.88 +
    1.89 +  SetAllocatedString(this->crashReporterURL, nullptr);
    1.90 +  SetAllocatedString(this->UAName, nullptr);
    1.91 +}
    1.92 +
    1.93 +} // namespace mozilla

mercurial