Bug 1184283 - Add GenerateUUID to gfxUtils; use it instead of direct UUIDGenerator calls
From f20e01220547e0826e80ffcf9645a2b87dbc2bd6 Mon Sep 17 00:00:00 2001
--- a/gfx/thebes/gfxDWriteCommon.h
+++ b/gfx/thebes/gfxDWriteCommon.h
@@ -9,17 +9,16 @@
// Mozilla includes
#include "nscore.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "cairo-features.h"
#include "gfxFontConstants.h"
#include "nsTArray.h"
#include "gfxWindowsPlatform.h"
-#include "nsIUUIDGenerator.h"
#include <windows.h>
#include <dwrite.h>
static inline DWRITE_FONT_STRETCH
DWriteFontStretchFromStretch(int16_t aStretch)
{
switch (aStretch) {
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -13,16 +13,17 @@
#include "nsServiceManagerUtils.h"
#include "nsCharSeparatedTokenizer.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsISimpleEnumerator.h"
+#include "gfXUtils.h"
#include "gfxGDIFontList.h"
#include "nsIWindowsRegKey.h"
#include "harfbuzz/hb.h"
using namespace mozilla;
--- a/gfx/thebes/gfxFontUtils.cpp
+++ b/gfx/thebes/gfxFontUtils.cpp
@@ -2,27 +2,27 @@
/* 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 "mozilla/ArrayUtils.h"
#include "mozilla/BinarySearch.h"
#include "gfxFontUtils.h"
+#include "gfxUtils.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/Snprintf.h"
#include "nsCOMPtr.h"
-#include "nsIUUIDGenerator.h"
#include "nsIUnicodeDecoder.h"
#include "harfbuzz/hb.h"
#include "plbase64.h"
#include "mozilla/Logging.h"
#define LOG(log, args) MOZ_LOG(gfxPlatform::GetLog(log), \
@@ -858,27 +858,17 @@ void gfxFontUtils::GetPrefsFontList(cons
// produce a unique font name that is (1) a valid Postscript name and (2) less
// than 31 characters in length. Using AddFontMemResourceEx on Windows fails
// for names longer than 30 characters in length.
#define MAX_B64_LEN 32
nsresult gfxFontUtils::MakeUniqueUserFontName(nsAString& aName)
{
- nsCOMPtr<nsIUUIDGenerator> uuidgen =
- do_GetService("@mozilla.org/uuid-generator;1");
- NS_ENSURE_TRUE(uuidgen, NS_ERROR_OUT_OF_MEMORY);
-
- nsID guid;
-
- NS_ASSERTION(sizeof(guid) * 2 <= MAX_B64_LEN, "size of nsID has changed!");
-
- nsresult rv = uuidgen->GenerateUUIDInPlace(&guid);
- NS_ENSURE_SUCCESS(rv, rv);
-
+ nsID guid = gfxUtils::GenerateUUID();
char guidB64[MAX_B64_LEN] = {0};
if (!PL_Base64Encode(reinterpret_cast<char*>(&guid), sizeof(guid), guidB64))
return NS_ERROR_FAILURE;
// all b64 characters except for '/' are allowed in Postscript names, so convert / ==> -
char *p;
for (p = guidB64; *p; p++) {
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -7,16 +7,17 @@
#include "cairo.h"
#include "gfxContext.h"
#include "gfxEnv.h"
#include "gfxImageSurface.h"
#include "gfxPlatform.h"
#include "gfxDrawable.h"
#include "imgIEncoder.h"
+#include "mozilla/DebugOnly.h"
#include "mozilla/Base64.h"
#include "mozilla/dom/ImageEncoder.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/Maybe.h"
@@ -33,16 +34,17 @@
#include "nsServiceManagerUtils.h"
#include "yuv_convert.h"
#include "ycbcr_to_rgb565.h"
#include "GeckoProfiler.h"
#include "ImageContainer.h"
#include "ImageRegion.h"
#include "gfx2DGlue.h"
#include "gfxPrefs.h"
+#include "nsIUUIDGenerator.h"
#ifdef XP_WIN
#include "gfxWindowsPlatform.h"
#endif
using namespace mozilla;
using namespace mozilla::image;
using namespace mozilla::layers;
@@ -1558,16 +1560,29 @@ gfxUtils::ThreadSafeGetFeatureStatus(con
}
return runnable->GetNSResult();
}
return gfxInfo->GetFeatureStatus(feature, failureId, status);
}
+/* static */ nsID
+gfxUtils::GenerateUUID()
+{
+ nsCOMPtr<nsIUUIDGenerator> uuidgen =
+ do_GetService("@mozilla.org/uuid-generator;1");
+ MOZ_ASSERT(uuidgen, "Couldn't get UUID generator");
+
+ nsID val;
+ DebugOnly<nsresult> rv = uuidgen->GenerateUUIDInPlace(&val);
+ MOZ_ASSERT(NS_SUCCEEDED(rv), "Generating UUID failed");
+ return val;
+}
+
/* static */ bool
gfxUtils::DumpDisplayList() {
return gfxPrefs::LayoutDumpDisplayList() ||
(gfxPrefs::LayoutDumpDisplayListContent() && XRE_IsContentProcess());
}
FILE *gfxUtils::sDumpPaintFile = stderr;
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -295,16 +295,21 @@ public:
int32_t* status);
/**
* Copy to the clipboard as a PNG encoded Data URL.
*/
static void CopyAsDataURI(SourceSurface* aSourceSurface);
static void CopyAsDataURI(DrawTarget* aDT);
+ /**
+ * Generate a UUID
+ */
+ static nsID GenerateUUID();
+
static bool DumpDisplayList();
static FILE* sDumpPaintFile;
};
namespace mozilla {
namespace gfx {