Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: third_party/WebKit/Source/core/fileapi/FileReaderSync.cpp

Issue 2811863002: Move ScriptState::GetExecutionContext (Part 4) (Closed)
Patch Set: Fix Document.cpp Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/fileapi/FileReaderSync.h" 31 #include "core/fileapi/FileReaderSync.h"
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "bindings/core/v8/ScriptState.h" 34 #include "bindings/core/v8/ScriptState.h"
35 #include "core/dom/DOMArrayBuffer.h" 35 #include "core/dom/DOMArrayBuffer.h"
36 #include "core/dom/ExecutionContext.h"
36 #include "core/fileapi/Blob.h" 37 #include "core/fileapi/Blob.h"
37 #include "core/fileapi/FileError.h" 38 #include "core/fileapi/FileError.h"
38 #include "core/fileapi/FileReaderLoader.h" 39 #include "core/fileapi/FileReaderLoader.h"
39 #include "platform/Histogram.h" 40 #include "platform/Histogram.h"
40 41
41 namespace blink { 42 namespace blink {
42 43
43 namespace { 44 namespace {
44 // These values are written to logs. New enum values can be added, but existing 45 // These values are written to logs. New enum values can be added, but existing
45 // enums must never be renumbered or deleted and reused. 46 // enums must never be renumbered or deleted and reused.
(...skipping 22 matching lines...) Expand all
68 } 69 }
69 70
70 DOMArrayBuffer* FileReaderSync::readAsArrayBuffer( 71 DOMArrayBuffer* FileReaderSync::readAsArrayBuffer(
71 ScriptState* script_state, 72 ScriptState* script_state,
72 Blob* blob, 73 Blob* blob,
73 ExceptionState& exception_state) { 74 ExceptionState& exception_state) {
74 DCHECK(blob); 75 DCHECK(blob);
75 76
76 std::unique_ptr<FileReaderLoader> loader = 77 std::unique_ptr<FileReaderLoader> loader =
77 FileReaderLoader::Create(FileReaderLoader::kReadAsArrayBuffer, nullptr); 78 FileReaderLoader::Create(FileReaderLoader::kReadAsArrayBuffer, nullptr);
78 StartLoading(script_state->GetExecutionContext(), *loader, *blob, 79 StartLoading(ExecutionContext::From(script_state), *loader, *blob,
79 exception_state); 80 exception_state);
80 81
81 return loader->ArrayBufferResult(); 82 return loader->ArrayBufferResult();
82 } 83 }
83 84
84 String FileReaderSync::readAsBinaryString(ScriptState* script_state, 85 String FileReaderSync::readAsBinaryString(ScriptState* script_state,
85 Blob* blob, 86 Blob* blob,
86 ExceptionState& exception_state) { 87 ExceptionState& exception_state) {
87 DCHECK(blob); 88 DCHECK(blob);
88 89
89 std::unique_ptr<FileReaderLoader> loader = 90 std::unique_ptr<FileReaderLoader> loader =
90 FileReaderLoader::Create(FileReaderLoader::kReadAsBinaryString, nullptr); 91 FileReaderLoader::Create(FileReaderLoader::kReadAsBinaryString, nullptr);
91 StartLoading(script_state->GetExecutionContext(), *loader, *blob, 92 StartLoading(ExecutionContext::From(script_state), *loader, *blob,
92 exception_state); 93 exception_state);
93 return loader->StringResult(); 94 return loader->StringResult();
94 } 95 }
95 96
96 String FileReaderSync::readAsText(ScriptState* script_state, 97 String FileReaderSync::readAsText(ScriptState* script_state,
97 Blob* blob, 98 Blob* blob,
98 const String& encoding, 99 const String& encoding,
99 ExceptionState& exception_state) { 100 ExceptionState& exception_state) {
100 DCHECK(blob); 101 DCHECK(blob);
101 102
102 std::unique_ptr<FileReaderLoader> loader = 103 std::unique_ptr<FileReaderLoader> loader =
103 FileReaderLoader::Create(FileReaderLoader::kReadAsText, nullptr); 104 FileReaderLoader::Create(FileReaderLoader::kReadAsText, nullptr);
104 loader->SetEncoding(encoding); 105 loader->SetEncoding(encoding);
105 StartLoading(script_state->GetExecutionContext(), *loader, *blob, 106 StartLoading(ExecutionContext::From(script_state), *loader, *blob,
106 exception_state); 107 exception_state);
107 return loader->StringResult(); 108 return loader->StringResult();
108 } 109 }
109 110
110 String FileReaderSync::readAsDataURL(ScriptState* script_state, 111 String FileReaderSync::readAsDataURL(ScriptState* script_state,
111 Blob* blob, 112 Blob* blob,
112 ExceptionState& exception_state) { 113 ExceptionState& exception_state) {
113 DCHECK(blob); 114 DCHECK(blob);
114 115
115 std::unique_ptr<FileReaderLoader> loader = 116 std::unique_ptr<FileReaderLoader> loader =
116 FileReaderLoader::Create(FileReaderLoader::kReadAsDataURL, nullptr); 117 FileReaderLoader::Create(FileReaderLoader::kReadAsDataURL, nullptr);
117 loader->SetDataType(blob->type()); 118 loader->SetDataType(blob->type());
118 StartLoading(script_state->GetExecutionContext(), *loader, *blob, 119 StartLoading(ExecutionContext::From(script_state), *loader, *blob,
119 exception_state); 120 exception_state);
120 return loader->StringResult(); 121 return loader->StringResult();
121 } 122 }
122 123
123 void FileReaderSync::StartLoading(ExecutionContext* execution_context, 124 void FileReaderSync::StartLoading(ExecutionContext* execution_context,
124 FileReaderLoader& loader, 125 FileReaderLoader& loader,
125 const Blob& blob, 126 const Blob& blob,
126 ExceptionState& exception_state) { 127 ExceptionState& exception_state) {
127 loader.Start(execution_context, blob.GetBlobDataHandle()); 128 loader.Start(execution_context, blob.GetBlobDataHandle());
128 if (loader.GetErrorCode()) 129 if (loader.GetErrorCode())
129 FileError::ThrowDOMException(exception_state, loader.GetErrorCode()); 130 FileError::ThrowDOMException(exception_state, loader.GetErrorCode());
130 } 131 }
131 132
132 } // namespace blink 133 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/Blob.cpp ('k') | third_party/WebKit/Source/core/fileapi/URLFileAPI.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698