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

Side by Side Diff: Source/core/fileapi/FileReaderLoader.cpp

Issue 23992003: blob hacking webcore style (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 { 71 {
72 } 72 }
73 73
74 FileReaderLoader::~FileReaderLoader() 74 FileReaderLoader::~FileReaderLoader()
75 { 75 {
76 terminate(); 76 terminate();
77 if (!m_urlForReading.isEmpty()) { 77 if (!m_urlForReading.isEmpty()) {
78 if (m_urlForReadingIsStream) 78 if (m_urlForReadingIsStream)
79 BlobRegistry::unregisterStreamURL(m_urlForReading); 79 BlobRegistry::unregisterStreamURL(m_urlForReading);
80 else 80 else
81 BlobRegistry::unregisterBlobURL(m_urlForReading); 81 BlobRegistry::revokePublicBlobURL(m_urlForReading);
82 } 82 }
83 } 83 }
84 84
85 void FileReaderLoader::startForURL(ScriptExecutionContext* scriptExecutionContex t, const KURL& url) 85 void FileReaderLoader::startInternal(ScriptExecutionContext* scriptExecutionCont ext, const Stream* stream, PassRefPtr<BlobDataHandle> blobData)
86 { 86 {
87 // The blob is read by routing through the request handling layer given a te mporary public url. 87 // The blob is read by routing through the request handling layer given a te mporary public url.
88 m_urlForReading = BlobURL::createPublicURL(scriptExecutionContext->securityO rigin()); 88 m_urlForReading = BlobURL::createPublicURL(scriptExecutionContext->securityO rigin());
89 if (m_urlForReading.isEmpty()) { 89 if (m_urlForReading.isEmpty()) {
90 failed(FileError::SECURITY_ERR); 90 failed(FileError::SECURITY_ERR);
91 return; 91 return;
92 } 92 }
93 93
94 if (m_urlForReadingIsStream) 94 if (blobData) {
95 BlobRegistry::registerStreamURL(scriptExecutionContext->securityOrigin() , m_urlForReading, url); 95 ASSERT(!stream);
96 else 96 BlobRegistry::registerPublicBlobURL(scriptExecutionContext->securityOrig in(), m_urlForReading, blobData);
97 BlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), m_urlForReading, url); 97 } else {
98 ASSERT(stream);
99 BlobRegistry::registerStreamURL(scriptExecutionContext->securityOrigin() , m_urlForReading, stream->url());
100 }
98 101
99 // Construct and load the request. 102 // Construct and load the request.
100 ResourceRequest request(m_urlForReading); 103 ResourceRequest request(m_urlForReading);
101 request.setHTTPMethod("GET"); 104 request.setHTTPMethod("GET");
102 if (m_hasRange) 105 if (m_hasRange)
103 request.setHTTPHeaderField("Range", String::format("bytes=%d-%d", m_rang eStart, m_rangeEnd)); 106 request.setHTTPHeaderField("Range", String::format("bytes=%d-%d", m_rang eStart, m_rangeEnd));
104 107
105 ThreadableLoaderOptions options; 108 ThreadableLoaderOptions options;
106 options.sendLoadCallbacks = SendCallbacks; 109 options.sendLoadCallbacks = SendCallbacks;
107 options.sniffContent = DoNotSniffContent; 110 options.sniffContent = DoNotSniffContent;
108 options.preflightPolicy = ConsiderPreflight; 111 options.preflightPolicy = ConsiderPreflight;
109 options.allowCredentials = AllowStoredCredentials; 112 options.allowCredentials = AllowStoredCredentials;
110 options.crossOriginRequestPolicy = DenyCrossOriginRequests; 113 options.crossOriginRequestPolicy = DenyCrossOriginRequests;
111 // FIXME: Is there a directive to which this load should be subject? 114 // FIXME: Is there a directive to which this load should be subject?
112 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy ; 115 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy ;
113 116
114 if (m_client) 117 if (m_client)
115 m_loader = ThreadableLoader::create(scriptExecutionContext, this, reques t, options); 118 m_loader = ThreadableLoader::create(scriptExecutionContext, this, reques t, options);
116 else 119 else
117 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext, requ est, *this, options); 120 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext, requ est, *this, options);
118 } 121 }
119 122
120 void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, con st Blob& blob) 123 void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Pas sRefPtr<BlobDataHandle> blobData)
121 { 124 {
122 m_urlForReadingIsStream = false; 125 m_urlForReadingIsStream = false;
123 startForURL(scriptExecutionContext, blob.url()); 126 startInternal(scriptExecutionContext, 0, blobData);
124 } 127 }
125 128
126 void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, con st Stream& stream, unsigned readSize) 129 void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, con st Stream& stream, unsigned readSize)
127 { 130 {
128 if (readSize > 0) { 131 if (readSize > 0) {
129 m_hasRange = true; 132 m_hasRange = true;
130 m_rangeStart = 0; 133 m_rangeStart = 0;
131 m_rangeEnd = readSize - 1; // End is inclusive so (0,0) is a 1-byte read . 134 m_rangeEnd = readSize - 1; // End is inclusive so (0,0) is a 1-byte read .
132 } 135 }
133 136
134 m_urlForReadingIsStream = true; 137 m_urlForReadingIsStream = true;
135 startForURL(scriptExecutionContext, stream.url()); 138 startInternal(scriptExecutionContext, &stream, 0);
136 } 139 }
137 140
138 void FileReaderLoader::cancel() 141 void FileReaderLoader::cancel()
139 { 142 {
140 m_errorCode = FileError::ABORT_ERR; 143 m_errorCode = FileError::ABORT_ERR;
141 terminate(); 144 terminate();
142 } 145 }
143 146
144 void FileReaderLoader::terminate() 147 void FileReaderLoader::terminate()
145 { 148 {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 return m_bytesLoaded == m_totalBytes; 404 return m_bytesLoaded == m_totalBytes;
402 } 405 }
403 406
404 void FileReaderLoader::setEncoding(const String& encoding) 407 void FileReaderLoader::setEncoding(const String& encoding)
405 { 408 {
406 if (!encoding.isEmpty()) 409 if (!encoding.isEmpty())
407 m_encoding = WTF::TextEncoding(encoding); 410 m_encoding = WTF::TextEncoding(encoding);
408 } 411 }
409 412
410 } // namespace WebCore 413 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698