Bug 1033090 - Truncate a large URI in the user message about it. r=seth
authorMilan Sreckovic <milan@mozilla.com>
Thu, 21 May 2015 16:23:42 -0400
changeset 275927 b30c80ba44f3f8ada4c03e8bffbb65a9f161ae47
parent 275926 e602cb65a030c19fecfa912be51f92fc0160d70f
child 275928 b6dd069ab9a500632749e38e4ee8e077f47fcdd1
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth
bugs1033090
milestone41.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 1033090 - Truncate a large URI in the user message about it. r=seth
image/Decoder.cpp
image/ImageURL.h
--- a/image/Decoder.cpp
+++ b/image/Decoder.cpp
@@ -290,22 +290,28 @@ Decoder::Finish()
   // If we detected an error in CompleteDecode(), log it to the error console.
   if (mShouldReportError && !WasAborted()) {
     nsCOMPtr<nsIConsoleService> consoleService =
       do_GetService(NS_CONSOLESERVICE_CONTRACTID);
     nsCOMPtr<nsIScriptError> errorObject =
       do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
 
     if (consoleService && errorObject && !HasDecoderError()) {
-      nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated: ") +
-                       NS_ConvertUTF8toUTF16(mImage->GetURIString()));
-
+      nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated."));
+      nsAutoString src;
+      if (mImage->GetURI()) {
+        nsCString uri;
+        if (mImage->GetURI()->GetSpecTruncatedTo1k(uri) == ImageURL::TruncatedTo1k) {
+          msg += NS_LITERAL_STRING(" URI in this note truncated due to length.");
+        }
+        src = NS_ConvertUTF8toUTF16(uri);
+      }
       if (NS_SUCCEEDED(errorObject->InitWithWindowID(
                          msg,
-                         NS_ConvertUTF8toUTF16(mImage->GetURIString()),
+                         src,
                          EmptyString(), 0, 0, nsIScriptError::errorFlag,
                          "Image", mImage->InnerWindowID()
                        ))) {
         consoleService->LogMessage(errorObject);
       }
     }
   }
 
--- a/image/ImageURL.h
+++ b/image/ImageURL.h
@@ -42,16 +42,33 @@ public:
   {
     result = mSpec;
     return NS_OK;
   }
 
   /// A weak pointer to the URI spec for this ImageURL. For logging only.
   const char* Spec() const { return mSpec.get(); }
 
+  enum TruncatedSpecStatus {
+    FitsInto1k,
+    TruncatedTo1k
+  };
+  TruncatedSpecStatus GetSpecTruncatedTo1k(nsACString& result)
+  {
+    static const size_t sMaxTruncatedLength = 1024;
+
+    if (sMaxTruncatedLength >= mSpec.Length()) {
+      result = mSpec;
+      return FitsInto1k;
+    }
+
+    result = Substring(mSpec, 0, sMaxTruncatedLength);
+    return TruncatedTo1k;
+  }
+
   nsresult GetScheme(nsACString& result)
   {
     result = mScheme;
     return NS_OK;
   }
 
   nsresult SchemeIs(const char* scheme, bool* result)
   {