| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #ifndef FileReader_h | 31 #ifndef FileReader_h |
| 32 #define FileReader_h | 32 #define FileReader_h |
| 33 | 33 |
| 34 #include "bindings/v8/ScriptWrappable.h" | 34 #include "bindings/v8/ScriptWrappable.h" |
| 35 #include "core/dom/ActiveDOMObject.h" | 35 #include "core/dom/ActiveDOMObject.h" |
| 36 #include "core/events/EventTarget.h" | 36 #include "core/events/EventTarget.h" |
| 37 #include "core/fileapi/FileError.h" | 37 #include "core/fileapi/FileError.h" |
| 38 #include "core/fileapi/FileReaderLoader.h" | 38 #include "core/fileapi/FileReaderLoader.h" |
| 39 #include "core/fileapi/FileReaderLoaderClient.h" | 39 #include "core/fileapi/FileReaderLoaderClient.h" |
| 40 #include "heap/Handle.h" |
| 40 #include "wtf/Forward.h" | 41 #include "wtf/Forward.h" |
| 41 #include "wtf/RefCounted.h" | 42 #include "wtf/RefCounted.h" |
| 42 #include "wtf/ThreadSpecific.h" | 43 #include "wtf/ThreadSpecific.h" |
| 43 #include "wtf/text/WTFString.h" | 44 #include "wtf/text/WTFString.h" |
| 44 | 45 |
| 45 namespace WebCore { | 46 namespace WebCore { |
| 46 | 47 |
| 47 class Blob; | 48 class Blob; |
| 48 class ExceptionState; | 49 class ExceptionState; |
| 49 class ExecutionContext; | 50 class ExecutionContext; |
| 50 | 51 |
| 51 class FileReader FINAL : public RefCounted<FileReader>, public ScriptWrappable,
public ActiveDOMObject, public EventTargetWithInlineData, public FileReaderLoade
rClient { | 52 class FileReader FINAL : public RefCountedWillBeRefCountedGarbageCollected<FileR
eader>, public ScriptWrappable, public ActiveDOMObject, public FileReaderLoaderC
lient, public EventTargetWithInlineData { |
| 52 REFCOUNTED_EVENT_TARGET(FileReader); | 53 DECLARE_GC_INFO; |
| 54 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<F
ileReader>); |
| 53 public: | 55 public: |
| 54 static PassRefPtr<FileReader> create(ExecutionContext*); | 56 static PassRefPtrWillBeRawPtr<FileReader> create(ExecutionContext*); |
| 55 | 57 |
| 56 virtual ~FileReader(); | 58 virtual ~FileReader(); |
| 57 | 59 |
| 58 enum ReadyState { | 60 enum ReadyState { |
| 59 EMPTY = 0, | 61 EMPTY = 0, |
| 60 LOADING = 1, | 62 LOADING = 1, |
| 61 DONE = 2 | 63 DONE = 2 |
| 62 }; | 64 }; |
| 63 | 65 |
| 64 void readAsArrayBuffer(Blob*, ExceptionState&); | 66 void readAsArrayBuffer(Blob*, ExceptionState&); |
| 65 void readAsBinaryString(Blob*, ExceptionState&); | 67 void readAsBinaryString(Blob*, ExceptionState&); |
| 66 void readAsText(Blob*, const String& encoding, ExceptionState&); | 68 void readAsText(Blob*, const String& encoding, ExceptionState&); |
| 67 void readAsText(Blob*, ExceptionState&); | 69 void readAsText(Blob*, ExceptionState&); |
| 68 void readAsDataURL(Blob*, ExceptionState&); | 70 void readAsDataURL(Blob*, ExceptionState&); |
| 69 void abort(); | 71 void abort(); |
| 70 | 72 |
| 71 void doAbort(); | 73 void doAbort(); |
| 72 | 74 |
| 73 ReadyState readyState() const { return m_state; } | 75 ReadyState readyState() const { return m_state; } |
| 74 PassRefPtr<FileError> error() { return m_error; } | 76 PassRefPtrWillBeRawPtr<FileError> error() { return m_error; } |
| 75 FileReaderLoader::ReadType readType() const { return m_readType; } | 77 FileReaderLoader::ReadType readType() const { return m_readType; } |
| 76 PassRefPtr<ArrayBuffer> arrayBufferResult() const; | 78 PassRefPtr<ArrayBuffer> arrayBufferResult() const; |
| 77 String stringResult(); | 79 String stringResult(); |
| 78 | 80 |
| 79 // ActiveDOMObject | 81 // ActiveDOMObject |
| 80 virtual void stop() OVERRIDE; | 82 virtual void stop() OVERRIDE; |
| 81 | 83 |
| 82 // EventTarget | 84 // EventTarget |
| 83 virtual const AtomicString& interfaceName() const OVERRIDE; | 85 virtual const AtomicString& interfaceName() const OVERRIDE; |
| 84 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } | 86 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } |
| 85 | 87 |
| 86 // FileReaderLoaderClient | 88 // FileReaderLoaderClient |
| 87 virtual void didStartLoading() OVERRIDE; | 89 virtual void didStartLoading() OVERRIDE; |
| 88 virtual void didReceiveData() OVERRIDE; | 90 virtual void didReceiveData() OVERRIDE; |
| 89 virtual void didFinishLoading() OVERRIDE; | 91 virtual void didFinishLoading() OVERRIDE; |
| 90 virtual void didFail(FileError::ErrorCode) OVERRIDE; | 92 virtual void didFail(FileError::ErrorCode) OVERRIDE; |
| 91 | 93 |
| 92 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart); | 94 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart); |
| 93 DEFINE_ATTRIBUTE_EVENT_LISTENER(progress); | 95 DEFINE_ATTRIBUTE_EVENT_LISTENER(progress); |
| 94 DEFINE_ATTRIBUTE_EVENT_LISTENER(load); | 96 DEFINE_ATTRIBUTE_EVENT_LISTENER(load); |
| 95 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); | 97 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); |
| 96 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 98 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
| 97 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadend); | 99 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadend); |
| 98 | 100 |
| 101 void trace(Visitor*); |
| 102 |
| 99 private: | 103 private: |
| 100 class ThrottlingController; | 104 class ThrottlingController; |
| 101 | 105 |
| 102 FileReader(ExecutionContext*); | 106 FileReader(ExecutionContext*); |
| 103 | 107 |
| 104 void terminate(); | 108 void terminate(); |
| 105 void readInternal(Blob*, FileReaderLoader::ReadType, ExceptionState&); | 109 void readInternal(Blob*, FileReaderLoader::ReadType, ExceptionState&); |
| 106 void fireErrorEvent(int httpStatusCode); | 110 void fireErrorEvent(int httpStatusCode); |
| 107 void fireEvent(const AtomicString& type); | 111 void fireEvent(const AtomicString& type); |
| 108 | 112 |
| 109 static ThreadSpecific<ThrottlingController>& throttlingController(); | 113 static ThreadSpecific<ThrottlingController>& throttlingController(); |
| 110 void executePendingRead(); | 114 void executePendingRead(); |
| 111 | 115 |
| 112 ReadyState m_state; | 116 ReadyState m_state; |
| 113 | 117 |
| 114 // Internal loading state, which could differ from ReadyState as it's | 118 // Internal loading state, which could differ from ReadyState as it's |
| 115 // for script-visible state while this one's for internal state. | 119 // for script-visible state while this one's for internal state. |
| 116 enum LoadingState { | 120 enum LoadingState { |
| 117 LoadingStateNone, | 121 LoadingStateNone, |
| 118 LoadingStatePending, | 122 LoadingStatePending, |
| 119 LoadingStateLoading, | 123 LoadingStateLoading, |
| 120 LoadingStateAborted | 124 LoadingStateAborted |
| 121 }; | 125 }; |
| 122 LoadingState m_loadingState; | 126 LoadingState m_loadingState; |
| 123 | 127 |
| 124 RefPtr<Blob> m_blob; | 128 RefPtrWillBeMember<Blob> m_blob; |
| 125 FileReaderLoader::ReadType m_readType; | 129 FileReaderLoader::ReadType m_readType; |
| 126 String m_encoding; | 130 String m_encoding; |
| 127 | 131 |
| 128 OwnPtr<FileReaderLoader> m_loader; | 132 OwnPtr<FileReaderLoader> m_loader; |
| 129 RefPtr<FileError> m_error; | 133 RefPtrWillBeMember<FileError> m_error; |
| 130 double m_lastProgressNotificationTimeMS; | 134 double m_lastProgressNotificationTimeMS; |
| 131 }; | 135 }; |
| 132 | 136 |
| 133 } // namespace WebCore | 137 } // namespace WebCore |
| 134 | 138 |
| 135 #endif // FileReader_h | 139 #endif // FileReader_h |
| OLD | NEW |