Bug 1185236 - Add adjustPrintJobName in order to avoid IPP job name limit. r=karlt
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Fri, 13 Oct 2017 15:47:33 +0900
changeset 386090 388a4fce5b4eb8ae950c02d489bb59599c8f3a10
parent 386089 39d219f0a5224a9bcf351143b3068f3ea8c50ccc
child 386091 f39bad8999fadeb151a3d2de867f55568649aac8
push id32675
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 21:36:21 +0000
treeherdermozilla-central@684b9ee0468e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1185236
milestone58.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 1185236 - Add adjustPrintJobName in order to avoid IPP job name limit. r=karlt MozReview-Commit-ID: n2k9lwfoyW
gfx/thebes/PrintTarget.cpp
gfx/thebes/PrintTarget.h
--- a/gfx/thebes/PrintTarget.cpp
+++ b/gfx/thebes/PrintTarget.cpp
@@ -10,16 +10,23 @@
 #include "cairo-quartz.h"
 #endif
 #ifdef CAIRO_HAS_WIN32_SURFACE
 #include "cairo-win32.h"
 #endif
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/HelpersCairo.h"
 #include "mozilla/gfx/Logging.h"
+#include "nsReadableUtils.h"
+#include "nsString.h"
+#include "nsUTF8Utils.h"
+
+// IPP spec disallow the job-name which is over 255 characters.
+// RFC: https://tools.ietf.org/html/rfc2911#section-4.1.2
+#define IPP_JOB_NAME_LIMIT_LENGTH 255
 
 namespace mozilla {
 namespace gfx {
 
 PrintTarget::PrintTarget(cairo_surface_t* aCairoSurface, const IntSize& aSize)
   : mCairoSurface(aCairoSurface)
   , mSize(aSize)
   , mIsFinished(false)
@@ -155,16 +162,32 @@ PrintTarget::GetReferenceDrawTarget(Draw
 #endif
 
     return do_AddRef(mRecordingRefDT);
   }
 
   return do_AddRef(mRefDT);
 }
 
+/* static */
+void
+PrintTarget::AdjustPrintJobNameForIPP(const nsAString& aJobName,
+                                      nsCString& aAdjustedJobName)
+{
+  CopyUTF16toUTF8(aJobName, aAdjustedJobName);
+
+  if (aAdjustedJobName.Length() > IPP_JOB_NAME_LIMIT_LENGTH) {
+    uint32_t length =
+      RewindToPriorUTF8Codepoint(aAdjustedJobName.get(),
+                                 (IPP_JOB_NAME_LIMIT_LENGTH - 3U));
+    aAdjustedJobName.SetLength(length);
+    aAdjustedJobName.AppendLiteral("...");
+  }
+}
+
 /* static */ already_AddRefed<DrawTarget>
 PrintTarget::CreateWrapAndRecordDrawTarget(DrawEventRecorder* aRecorder,
                                        DrawTarget* aDrawTarget)
 {
   MOZ_ASSERT(aRecorder);
   MOZ_ASSERT(aDrawTarget);
 
   RefPtr<DrawTarget> dt;
--- a/gfx/thebes/PrintTarget.h
+++ b/gfx/thebes/PrintTarget.h
@@ -131,16 +131,19 @@ public:
   /**
    * Returns a reference DrawTarget. Unlike MakeDrawTarget, this method is not
    * restricted to being called between BeginPage()/EndPage() calls, and the
    * returned DrawTarget it is still valid to use after EndPage() has been
    * called.
    */
   virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget(DrawEventRecorder* aRecorder);
 
+  static void AdjustPrintJobNameForIPP(const nsAString& aJobName,
+                                       nsCString& aAdjustedJobName);
+
 protected:
 
   // Only created via subclass's constructors
   explicit PrintTarget(cairo_surface_t* aCairoSurface, const IntSize& aSize);
 
   // Protected because we're refcounted
   virtual ~PrintTarget();