OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 30 matching lines...) Expand all Loading... |
41 #include "core/html/VoidCallback.h" | 41 #include "core/html/VoidCallback.h" |
42 #include "core/inspector/InspectorPageAgent.h" | 42 #include "core/inspector/InspectorPageAgent.h" |
43 #include "core/inspector/InspectorState.h" | 43 #include "core/inspector/InspectorState.h" |
44 #include "core/loader/TextResourceDecoder.h" | 44 #include "core/loader/TextResourceDecoder.h" |
45 #include "core/page/Frame.h" | 45 #include "core/page/Frame.h" |
46 #include "core/platform/MIMETypeRegistry.h" | 46 #include "core/platform/MIMETypeRegistry.h" |
47 #include "modules/filesystem/DOMFileSystem.h" | 47 #include "modules/filesystem/DOMFileSystem.h" |
48 #include "modules/filesystem/DirectoryEntry.h" | 48 #include "modules/filesystem/DirectoryEntry.h" |
49 #include "modules/filesystem/DirectoryReader.h" | 49 #include "modules/filesystem/DirectoryReader.h" |
50 #include "modules/filesystem/EntriesCallback.h" | 50 #include "modules/filesystem/EntriesCallback.h" |
51 #include "modules/filesystem/EntryArray.h" | 51 #include "modules/filesystem/Entry.h" |
52 #include "modules/filesystem/EntryCallback.h" | 52 #include "modules/filesystem/EntryCallback.h" |
53 #include "modules/filesystem/ErrorCallback.h" | 53 #include "modules/filesystem/ErrorCallback.h" |
54 #include "modules/filesystem/FileCallback.h" | 54 #include "modules/filesystem/FileCallback.h" |
55 #include "modules/filesystem/FileEntry.h" | 55 #include "modules/filesystem/FileEntry.h" |
56 #include "modules/filesystem/FileSystemCallbacks.h" | 56 #include "modules/filesystem/FileSystemCallbacks.h" |
57 #include "modules/filesystem/LocalFileSystem.h" | 57 #include "modules/filesystem/LocalFileSystem.h" |
58 #include "modules/filesystem/Metadata.h" | 58 #include "modules/filesystem/Metadata.h" |
59 #include "modules/filesystem/MetadataCallback.h" | 59 #include "modules/filesystem/MetadataCallback.h" |
60 #include "weborigin/KURL.h" | 60 #include "weborigin/KURL.h" |
61 #include "weborigin/SecurityOrigin.h" | 61 #include "weborigin/SecurityOrigin.h" |
(...skipping 13 matching lines...) Expand all Loading... |
75 | 75 |
76 namespace FileSystemAgentState { | 76 namespace FileSystemAgentState { |
77 static const char fileSystemAgentEnabled[] = "fileSystemAgentEnabled"; | 77 static const char fileSystemAgentEnabled[] = "fileSystemAgentEnabled"; |
78 } | 78 } |
79 | 79 |
80 namespace { | 80 namespace { |
81 | 81 |
82 template<typename BaseCallback, typename Handler, typename Argument> | 82 template<typename BaseCallback, typename Handler, typename Argument> |
83 class CallbackDispatcher : public BaseCallback { | 83 class CallbackDispatcher : public BaseCallback { |
84 public: | 84 public: |
85 typedef bool (Handler::*HandlingMethod)(Argument*); | 85 typedef bool (Handler::*HandlingMethod)(Argument); |
86 | 86 |
87 static PassRefPtr<CallbackDispatcher> create(PassRefPtr<Handler> handler, Ha
ndlingMethod handlingMethod) | 87 static PassRefPtr<CallbackDispatcher> create(PassRefPtr<Handler> handler, Ha
ndlingMethod handlingMethod) |
88 { | 88 { |
89 return adoptRef(new CallbackDispatcher(handler, handlingMethod)); | 89 return adoptRef(new CallbackDispatcher(handler, handlingMethod)); |
90 } | 90 } |
91 | 91 |
92 virtual bool handleEvent(Argument* argument) OVERRIDE | 92 virtual bool handleEvent(Argument argument) OVERRIDE |
93 { | 93 { |
94 return (m_handler.get()->*m_handlingMethod)(argument); | 94 return (m_handler.get()->*m_handlingMethod)(argument); |
95 } | 95 } |
96 | 96 |
97 private: | 97 private: |
98 CallbackDispatcher(PassRefPtr<Handler> handler, HandlingMethod handlingMetho
d) | 98 CallbackDispatcher(PassRefPtr<Handler> handler, HandlingMethod handlingMetho
d) |
99 : m_handler(handler) | 99 : m_handler(handler) |
100 , m_handlingMethod(handlingMethod) { } | 100 , m_handlingMethod(handlingMethod) { } |
101 | 101 |
102 RefPtr<Handler> m_handler; | 102 RefPtr<Handler> m_handler; |
103 HandlingMethod m_handlingMethod; | 103 HandlingMethod m_handlingMethod; |
104 }; | 104 }; |
105 | 105 |
106 template<typename BaseCallback> | 106 template<typename BaseCallback> |
107 class CallbackDispatcherFactory { | 107 class CallbackDispatcherFactory { |
108 public: | 108 public: |
109 template<typename Handler, typename Argument> | 109 template<typename Handler, typename Argument> |
110 static PassRefPtr<CallbackDispatcher<BaseCallback, Handler, Argument> > crea
te(Handler* handler, bool (Handler::*handlingMethod)(Argument*)) | 110 static PassRefPtr<CallbackDispatcher<BaseCallback, Handler, Argument> > crea
te(Handler* handler, bool (Handler::*handlingMethod)(Argument)) |
111 { | 111 { |
112 return CallbackDispatcher<BaseCallback, Handler, Argument>::create(PassR
efPtr<Handler>(handler), handlingMethod); | 112 return CallbackDispatcher<BaseCallback, Handler, Argument>::create(PassR
efPtr<Handler>(handler), handlingMethod); |
113 } | 113 } |
114 }; | 114 }; |
115 | 115 |
116 class FileSystemRootRequest : public RefCounted<FileSystemRootRequest> { | 116 class FileSystemRootRequest : public RefCounted<FileSystemRootRequest> { |
117 WTF_MAKE_NONCOPYABLE(FileSystemRootRequest); | 117 WTF_MAKE_NONCOPYABLE(FileSystemRootRequest); |
118 public: | 118 public: |
119 static PassRefPtr<FileSystemRootRequest> create(PassRefPtr<RequestFileSystem
RootCallback> requestCallback, const String& type) | 119 static PassRefPtr<FileSystemRootRequest> create(PassRefPtr<RequestFileSystem
RootCallback> requestCallback, const String& type) |
120 { | 120 { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 void start(ScriptExecutionContext*); | 192 void start(ScriptExecutionContext*); |
193 | 193 |
194 private: | 194 private: |
195 bool didHitError(FileError* error) | 195 bool didHitError(FileError* error) |
196 { | 196 { |
197 reportResult(error->code()); | 197 reportResult(error->code()); |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 bool didGetEntry(Entry*); | 201 bool didGetEntry(Entry*); |
202 bool didReadDirectoryEntries(EntryArray*); | 202 bool didReadDirectoryEntries(const EntryVector&); |
203 | 203 |
204 void reportResult(FileError::ErrorCode errorCode, PassRefPtr<Array<TypeBuild
er::FileSystem::Entry> > entries = 0) | 204 void reportResult(FileError::ErrorCode errorCode, PassRefPtr<Array<TypeBuild
er::FileSystem::Entry> > entries = 0) |
205 { | 205 { |
206 m_requestCallback->sendSuccess(static_cast<int>(errorCode), entries); | 206 m_requestCallback->sendSuccess(static_cast<int>(errorCode), entries); |
207 } | 207 } |
208 | 208 |
209 DirectoryContentRequest(PassRefPtr<RequestDirectoryContentCallback> requestC
allback, const String& url) | 209 DirectoryContentRequest(PassRefPtr<RequestDirectoryContentCallback> requestC
allback, const String& url) |
210 : m_requestCallback(requestCallback) | 210 : m_requestCallback(requestCallback) |
211 , m_url(ParsedURLString, url) { } | 211 , m_url(ParsedURLString, url) { } |
212 | 212 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 if (!m_directoryReader->filesystem()->scriptExecutionContext()) { | 254 if (!m_directoryReader->filesystem()->scriptExecutionContext()) { |
255 reportResult(FileError::ABORT_ERR); | 255 reportResult(FileError::ABORT_ERR); |
256 return; | 256 return; |
257 } | 257 } |
258 | 258 |
259 RefPtr<EntriesCallback> successCallback = CallbackDispatcherFactory<EntriesC
allback>::create(this, &DirectoryContentRequest::didReadDirectoryEntries); | 259 RefPtr<EntriesCallback> successCallback = CallbackDispatcherFactory<EntriesC
allback>::create(this, &DirectoryContentRequest::didReadDirectoryEntries); |
260 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallbac
k>::create(this, &DirectoryContentRequest::didHitError); | 260 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallbac
k>::create(this, &DirectoryContentRequest::didHitError); |
261 m_directoryReader->readEntries(successCallback, errorCallback); | 261 m_directoryReader->readEntries(successCallback, errorCallback); |
262 } | 262 } |
263 | 263 |
264 bool DirectoryContentRequest::didReadDirectoryEntries(EntryArray* entries) | 264 bool DirectoryContentRequest::didReadDirectoryEntries(const EntryVector& entries
) |
265 { | 265 { |
266 if (!entries->length()) { | 266 if (entries.isEmpty()) { |
267 reportResult(static_cast<FileError::ErrorCode>(0), m_entries); | 267 reportResult(static_cast<FileError::ErrorCode>(0), m_entries); |
268 return true; | 268 return true; |
269 } | 269 } |
270 | 270 |
271 for (unsigned i = 0; i < entries->length(); ++i) { | 271 for (size_t i = 0; i < entries.size(); ++i) { |
272 Entry* entry = entries->item(i); | 272 RefPtr<Entry> entry = entries[i]; |
273 RefPtr<TypeBuilder::FileSystem::Entry> entryForFrontend = TypeBuilder::F
ileSystem::Entry::create() | 273 RefPtr<TypeBuilder::FileSystem::Entry> entryForFrontend = TypeBuilder::F
ileSystem::Entry::create() |
274 .setUrl(entry->toURL()) | 274 .setUrl(entry->toURL()) |
275 .setName(entry->name()) | 275 .setName(entry->name()) |
276 .setIsDirectory(entry->isDirectory()); | 276 .setIsDirectory(entry->isDirectory()); |
277 | 277 |
278 using TypeBuilder::Page::ResourceType; | 278 using TypeBuilder::Page::ResourceType; |
279 if (!entry->isDirectory()) { | 279 if (!entry->isDirectory()) { |
280 String mimeType = MIMETypeRegistry::getMIMETypeForPath(entry->name()
); | 280 String mimeType = MIMETypeRegistry::getMIMETypeForPath(entry->name()
); |
281 ResourceType::Enum resourceType; | 281 ResourceType::Enum resourceType; |
282 if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType)) { | 282 if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType)) { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 for (Frame* frame = m_pageAgent->mainFrame(); frame; frame = frame->tree()->
traverseNext()) { | 725 for (Frame* frame = m_pageAgent->mainFrame(); frame; frame = frame->tree()->
traverseNext()) { |
726 if (frame->document() && frame->document()->securityOrigin()->isSameSche
meHostPort(origin)) | 726 if (frame->document() && frame->document()->securityOrigin()->isSameSche
meHostPort(origin)) |
727 return frame->document(); | 727 return frame->document(); |
728 } | 728 } |
729 | 729 |
730 *error = "No frame is available for the request"; | 730 *error = "No frame is available for the request"; |
731 return 0; | 731 return 0; |
732 } | 732 } |
733 | 733 |
734 } // namespace WebCore | 734 } // namespace WebCore |
OLD | NEW |