Remove unused features of BlobBuilder
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2012 00:08:57 +0000 (00:08 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2012 00:08:57 +0000 (00:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=98331

Reviewed by Eric Seidel.

Now that we don't expose BlobBuilder as a web platform API, we can
strip down the class to handle only those cases that are needed by the
Blob constructor.

I've also renamed the class from WebKitBlobBuilder to BlobBuilder and
made it stack allocated rather than RefCounted. A future patch will
actually move the files around. (I didn't want to mix moving code
around with modifying the code.)

* bindings/js/JSBlobCustom.cpp:
(WebCore::JSBlobConstructor::constructJSBlob):
* bindings/v8/custom/V8BlobCustom.cpp:
(WebCore::V8Blob::constructorCallback):
* fileapi/WebKitBlobBuilder.cpp:
(WebCore):
(WebCore::BlobBuilder::BlobBuilder):
(WebCore::BlobBuilder::getBuffer):
(WebCore::BlobBuilder::append):
(WebCore::BlobBuilder::appendBytesData):
(WebCore::BlobBuilder::getBlob):
* fileapi/WebKitBlobBuilder.h:
(WebCore):
(BlobBuilder):
* page/FeatureObserver.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130705 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSBlobCustom.cpp
Source/WebCore/bindings/v8/custom/V8BlobCustom.cpp
Source/WebCore/fileapi/WebKitBlobBuilder.cpp
Source/WebCore/fileapi/WebKitBlobBuilder.h
Source/WebCore/page/FeatureObserver.h

index 27ee342..9f7d91f 100644 (file)
@@ -1,3 +1,35 @@
+2012-10-08  Adam Barth  <abarth@webkit.org>
+
+        Remove unused features of BlobBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=98331
+
+        Reviewed by Eric Seidel.
+
+        Now that we don't expose BlobBuilder as a web platform API, we can
+        strip down the class to handle only those cases that are needed by the
+        Blob constructor.
+
+        I've also renamed the class from WebKitBlobBuilder to BlobBuilder and
+        made it stack allocated rather than RefCounted. A future patch will
+        actually move the files around. (I didn't want to mix moving code
+        around with modifying the code.)
+
+        * bindings/js/JSBlobCustom.cpp:
+        (WebCore::JSBlobConstructor::constructJSBlob):
+        * bindings/v8/custom/V8BlobCustom.cpp:
+        (WebCore::V8Blob::constructorCallback):
+        * fileapi/WebKitBlobBuilder.cpp:
+        (WebCore):
+        (WebCore::BlobBuilder::BlobBuilder):
+        (WebCore::BlobBuilder::getBuffer):
+        (WebCore::BlobBuilder::append):
+        (WebCore::BlobBuilder::appendBytesData):
+        (WebCore::BlobBuilder::getBlob):
+        * fileapi/WebKitBlobBuilder.h:
+        (WebCore):
+        (BlobBuilder):
+        * page/FeatureObserver.h:
+
 2012-10-08  Martin Robinson  <mrobinson@igalia.com>
 
         Try to fix the debug build after r130699
index 5ea4401..f699fed 100644 (file)
@@ -111,8 +111,7 @@ EncodedJSValue JSC_HOST_CALL JSBlobConstructor::constructJSBlob(ExecState* exec)
 
     ASSERT(endings == "transparent" || endings == "native");
 
-    // FIXME: this would be better if the WebKitBlobBuilder were a stack object to avoid the allocation.
-    RefPtr<WebKitBlobBuilder> blobBuilder = WebKitBlobBuilder::create();
+    BlobBuilder blobBuilder;
 
     JSArray* array = asArray(firstArg);
     unsigned length = array->length();
@@ -121,22 +120,22 @@ EncodedJSValue JSC_HOST_CALL JSBlobConstructor::constructJSBlob(ExecState* exec)
         JSValue item = array->getIndex(exec, i);
 #if ENABLE(BLOB)
         if (item.inherits(&JSArrayBuffer::s_info))
-            blobBuilder->append(context, toArrayBuffer(item));
+            blobBuilder.append(context, toArrayBuffer(item));
         else if (item.inherits(&JSArrayBufferView::s_info))
-            blobBuilder->append(toArrayBufferView(item));
+            blobBuilder.append(toArrayBufferView(item));
         else
 #endif
         if (item.inherits(&JSBlob::s_info))
-            blobBuilder->append(toBlob(item));
+            blobBuilder.append(toBlob(item));
         else {
             String string = item.toString(exec)->value(exec);
             if (exec->hadException())
                 return JSValue::encode(jsUndefined());
-            blobBuilder->append(string, endings, ASSERT_NO_EXCEPTION);
+            blobBuilder.append(string, endings);
         }
     }
 
-    RefPtr<Blob> blob = blobBuilder->getBlob(type, BlobConstructedByConstructor);
+    RefPtr<Blob> blob = blobBuilder.getBlob(type);
     return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), Blob, blob.get()));
 }
 
index 0a81a8d..0ecc59e 100644 (file)
@@ -105,7 +105,7 @@ v8::Handle<v8::Value> V8Blob::constructorCallback(const v8::Arguments& args)
 
     ASSERT(endings == "transparent" || endings == "native");
 
-    RefPtr<WebKitBlobBuilder> blobBuilder = WebKitBlobBuilder::create();
+    BlobBuilder blobBuilder;
 
     EXCEPTION_BLOCK(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast(firstArg));
     uint32_t length = blobParts->Length();
@@ -117,24 +117,24 @@ v8::Handle<v8::Value> V8Blob::constructorCallback(const v8::Arguments& args)
         if (V8ArrayBuffer::HasInstance(item)) {
             ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(item));
             ASSERT(arrayBuffer);
-            blobBuilder->append(context, arrayBuffer);
+            blobBuilder.append(context, arrayBuffer);
         } else if (V8ArrayBufferView::HasInstance(item)) {
             ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(item));
             ASSERT(arrayBufferView);
-            blobBuilder->append(arrayBufferView);
+            blobBuilder.append(arrayBufferView);
         } else
 #endif
         if (V8Blob::HasInstance(item)) {
             Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item));
             ASSERT(blob);
-            blobBuilder->append(blob);
+            blobBuilder.append(blob);
         } else {
             EXCEPTION_BLOCK(String, stringValue, toWebCoreString(item));
-            blobBuilder->append(stringValue, endings, ASSERT_NO_EXCEPTION);
+            blobBuilder.append(stringValue, endings);
         }
     }
 
-    RefPtr<Blob> blob = blobBuilder->getBlob(type, BlobConstructedByConstructor);
+    RefPtr<Blob> blob = blobBuilder.getBlob(type);
     return toV8(blob.get(), args.Holder(), args.GetIsolate());
 }
 
index d073c36..8312a54 100644 (file)
@@ -35,7 +35,6 @@
 #include "Blob.h"
 #include "Document.h"
 #include "ExceptionCode.h"
-#include "FeatureObserver.h"
 #include "File.h"
 #include "HistogramSupport.h"
 #include "LineEnding.h"
 
 namespace WebCore {
 
+// FIXME: Move this file to BlobBuilder.cpp
+
 enum BlobConstructorArrayBufferOrView {
     BlobConstructorArrayBuffer,
     BlobConstructorArrayBufferView,
     BlobConstructorArrayBufferOrViewMax,
 };
 
-// static
-PassRefPtr<WebKitBlobBuilder> WebKitBlobBuilder::create(ScriptExecutionContext* context)
-{
-    String message("BlobBuilder is deprecated. Use \"Blob\" constructor instead.");
-    context->addConsoleMessage(JSMessageSource, LogMessageType, WarningMessageLevel, message);
-
-    if (context->isDocument()) {
-        Document* document = static_cast<Document*>(context);
-        FeatureObserver::observe(document->domWindow(), FeatureObserver::LegacyBlobBuilder);
-    }
-
-    return adoptRef(new WebKitBlobBuilder());
-}
-
-WebKitBlobBuilder::WebKitBlobBuilder()
+BlobBuilder::BlobBuilder()
     : m_size(0)
 {
 }
 
-Vector<char>& WebKitBlobBuilder::getBuffer()
+Vector<char>& BlobBuilder::getBuffer()
 {
     // If the last item is not a data item, create one. Otherwise, we simply append the new string to the last data item.
     if (m_items.isEmpty() || m_items[m_items.size() - 1].type != BlobDataItem::Data)
@@ -85,34 +72,24 @@ Vector<char>& WebKitBlobBuilder::getBuffer()
     return *m_items[m_items.size() - 1].data->mutableData();
 }
 
-void WebKitBlobBuilder::append(const String& text, const String& endingType, ExceptionCode& ec)
+void BlobBuilder::append(const String& text, const String& endingType)
 {
-    bool isEndingTypeTransparent = endingType == "transparent";
-    bool isEndingTypeNative = endingType == "native";
-    if (!endingType.isEmpty() && !isEndingTypeTransparent && !isEndingTypeNative) {
-        ec = SYNTAX_ERR;
-        return;
-    }
-
     CString utf8Text = UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables);
 
     Vector<char>& buffer = getBuffer();
     size_t oldSize = buffer.size();
 
-    if (isEndingTypeNative)
+    if (endingType == "native")
         normalizeLineEndingsToNative(utf8Text, buffer);
-    else
+    else {
+        ASSERT(endingType == "transparent");
         buffer.append(utf8Text.data(), utf8Text.length());
+    }
     m_size += buffer.size() - oldSize;
 }
 
-void WebKitBlobBuilder::append(const String& text, ExceptionCode& ec)
-{
-    append(text, String(), ec);
-}
-
 #if ENABLE(BLOB)
-void WebKitBlobBuilder::append(ScriptExecutionContext* context, ArrayBuffer* arrayBuffer)
+void BlobBuilder::append(ScriptExecutionContext* context, ArrayBuffer* arrayBuffer)
 {
     String consoleMessage("ArrayBuffer values are deprecated in Blob Constructor. Use ArrayBufferView instead.");
     context->addConsoleMessage(JSMessageSource, LogMessageType, WarningMessageLevel, consoleMessage);
@@ -125,7 +102,7 @@ void WebKitBlobBuilder::append(ScriptExecutionContext* context, ArrayBuffer* arr
     appendBytesData(arrayBuffer->data(), arrayBuffer->byteLength());
 }
 
-void WebKitBlobBuilder::append(ArrayBufferView* arrayBufferView)
+void BlobBuilder::append(ArrayBufferView* arrayBufferView)
 {
     HistogramSupport::histogramEnumeration("WebCore.Blob.constructor.ArrayBufferOrView", BlobConstructorArrayBufferView, BlobConstructorArrayBufferOrViewMax);
 
@@ -136,7 +113,7 @@ void WebKitBlobBuilder::append(ArrayBufferView* arrayBufferView)
 }
 #endif
 
-void WebKitBlobBuilder::append(Blob* blob)
+void BlobBuilder::append(Blob* blob)
 {
     if (!blob)
         return;
@@ -162,7 +139,7 @@ void WebKitBlobBuilder::append(Blob* blob)
     }
 }
 
-void WebKitBlobBuilder::appendBytesData(const void* data, size_t length)
+void BlobBuilder::appendBytesData(const void* data, size_t length)
 {
     Vector<char>& buffer = getBuffer();
     size_t oldSize = buffer.size();
@@ -170,10 +147,8 @@ void WebKitBlobBuilder::appendBytesData(const void* data, size_t length)
     m_size += buffer.size() - oldSize;
 }
 
-PassRefPtr<Blob> WebKitBlobBuilder::getBlob(const String& contentType, BlobConstructionReason constructionReason)
+PassRefPtr<Blob> BlobBuilder::getBlob(const String& contentType)
 {
-    HistogramSupport::histogramEnumeration("WebCore.BlobBuilder.getBlob", constructionReason, BlobConstructionReasonMax);
-
     OwnPtr<BlobData> blobData = BlobData::create();
     blobData->setContentType(contentType);
     blobData->swapItems(m_items);
index b869def..75090ba 100644 (file)
 
 namespace WebCore {
 
+// FIXME: Move this file to BlobBuilder.h
+
 class Blob;
 class ScriptExecutionContext;
 class TextEncoding;
 
 typedef int ExceptionCode;
 
-enum BlobConstructionReason {
-    BlobConstructedByBlobBuilder,
-    BlobConstructedByConstructor,
-    BlobConstructionReasonMax,
-};
-
-class WebKitBlobBuilder : public RefCounted<WebKitBlobBuilder> {
+class BlobBuilder {
 public:
-    // Called when BlobBuilder is instantiated in JS API. We show deprecate warning message.
-    static PassRefPtr<WebKitBlobBuilder> create(ScriptExecutionContext*);
-
-    // Called by Blob constructor.
-    static PassRefPtr<WebKitBlobBuilder> create() { return adoptRef(new WebKitBlobBuilder()); }
+    BlobBuilder();
 
     void append(Blob*);
-    void append(const String& text, ExceptionCode&);
-    void append(const String& text, const String& ending, ExceptionCode&);
+    void append(const String& text, const String& ending);
 #if ENABLE(BLOB)
     void append(ScriptExecutionContext*, ArrayBuffer*);
     void append(ArrayBufferView*);
 #endif
 
-    PassRefPtr<Blob> getBlob(const String& contentType = String(), BlobConstructionReason = BlobConstructedByBlobBuilder);
+    PassRefPtr<Blob> getBlob(const String& contentType);
 
 private:
-    WebKitBlobBuilder();
-
     void appendBytesData(const void*, size_t);
 
     Vector<char>& getBuffer();
index ecadd7a..aca8d7f 100644 (file)
@@ -41,7 +41,7 @@ public:
     enum Feature {
         PageDestruction,
         LegacyNotifications,
-        LegacyBlobBuilder,
+        UnusedSlot01, // Prior to 10/2012, we used this slot for LegacyBlobBuilder.
         PrefixedIndexedDB,
         WorkerStart,
         SharedWorkerStart,