OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(WorkerGlobalSc
ope* worker, const String& url, PassRefPtr<EntryCallback> successCallback, PassR
efPtr<ErrorCallback> errorCallback) | 89 void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(WorkerGlobalSc
ope* worker, const String& url, PassRefPtr<EntryCallback> successCallback, PassR
efPtr<ErrorCallback> errorCallback) |
90 { | 90 { |
91 KURL completedURL = worker->completeURL(url); | 91 KURL completedURL = worker->completeURL(url); |
92 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); | 92 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); |
93 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { | 93 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { |
94 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::SECURITY_ERR)); | 94 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::SECURITY_ERR)); |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 FileSystemType type; | 98 if (!completedURL.isValid()) { |
99 String filePath; | |
100 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple
tedURL, type, filePath)) { | |
101 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::ENCODING_ERR)); | 99 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::ENCODING_ERR)); |
102 return; | 100 return; |
103 } | 101 } |
104 | 102 |
105 WorkerLocalFileSystem::from(worker)->readFileSystem(worker, type, ResolveURI
Callbacks::create(successCallback, errorCallback, worker, type, filePath)); | 103 WorkerLocalFileSystem::from(worker)->resolveURL(worker, completedURL, Resolv
eURICallbacks::create(successCallback, errorCallback, worker)); |
106 } | 104 } |
107 | 105 |
108 PassRefPtr<EntrySync> WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemS
yncURL(WorkerGlobalScope* worker, const String& url, ExceptionState& es) | 106 PassRefPtr<EntrySync> WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemS
yncURL(WorkerGlobalScope* worker, const String& url, ExceptionState& es) |
109 { | 107 { |
110 KURL completedURL = worker->completeURL(url); | 108 KURL completedURL = worker->completeURL(url); |
111 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); | 109 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); |
112 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { | 110 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { |
113 es.throwSecurityError(ExceptionMessages::failedToExecute("webkitResolveL
ocalFileSystemSyncURL", "WorkerGlobalScopeFileSystem", FileError::securityErrorM
essage)); | 111 es.throwSecurityError(ExceptionMessages::failedToExecute("webkitResolveL
ocalFileSystemSyncURL", "WorkerGlobalScopeFileSystem", FileError::securityErrorM
essage)); |
114 return 0; | 112 return 0; |
115 } | 113 } |
116 | 114 |
117 FileSystemType type; | 115 if (!completedURL.isValid()) { |
118 String filePath; | |
119 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple
tedURL, type, filePath)) { | |
120 es.throwDOMException(EncodingError, ExceptionMessages::failedToExecute("
webkitResolveLocalFileSystemSyncURL", "WorkerGlobalScopeFileSystem", "the URL '"
+ url + "' is invalid.")); | 116 es.throwDOMException(EncodingError, ExceptionMessages::failedToExecute("
webkitResolveLocalFileSystemSyncURL", "WorkerGlobalScopeFileSystem", "the URL '"
+ url + "' is invalid.")); |
121 return 0; | 117 return 0; |
122 } | 118 } |
123 | 119 |
124 FileSystemSyncCallbackHelper readFileSystemHelper; | 120 EntrySyncCallbackHelper resolveURLHelper; |
125 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileSystemCallbacks::create(rea
dFileSystemHelper.successCallback(), readFileSystemHelper.errorCallback(), worke
r, type); | 121 OwnPtr<AsyncFileSystemCallbacks> callbacks = ResolveURICallbacks::create(res
olveURLHelper.successCallback(), resolveURLHelper.errorCallback(), worker); |
126 callbacks->setShouldBlockUntilCompletion(true); | 122 callbacks->setShouldBlockUntilCompletion(true); |
127 | 123 |
128 WorkerLocalFileSystem::from(worker)->readFileSystem(worker, type, callbacks.
release()); | 124 WorkerLocalFileSystem::from(worker)->resolveURL(worker, completedURL, callba
cks.release()); |
129 RefPtr<DOMFileSystemSync> fileSystem = readFileSystemHelper.getResult(es); | 125 |
130 if (!fileSystem) | 126 RefPtr<EntrySync> entry = resolveURLHelper.getResult(es); |
| 127 if (!entry) |
131 return 0; | 128 return 0; |
132 | |
133 RefPtr<EntrySync> entry = fileSystem->root()->getDirectory(filePath, Diction
ary(), es); | |
134 if (es.code() == TypeMismatchError) { | |
135 es.clearException(); | |
136 return fileSystem->root()->getFile(filePath, Dictionary(), es); | |
137 } | |
138 | |
139 return entry.release(); | 129 return entry.release(); |
140 } | 130 } |
141 | 131 |
142 COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::TEMPORARY) == stati
c_cast<int>(FileSystemTypeTemporary), enum_mismatch); | 132 COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::TEMPORARY) == stati
c_cast<int>(FileSystemTypeTemporary), enum_mismatch); |
143 COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::PERSISTENT) == stat
ic_cast<int>(FileSystemTypePersistent), enum_mismatch); | 133 COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::PERSISTENT) == stat
ic_cast<int>(FileSystemTypePersistent), enum_mismatch); |
144 | 134 |
145 } // namespace WebCore | 135 } // namespace WebCore |
OLD | NEW |