Changeset 121251 in webkit
- Timestamp:
- Jun 26, 2012 3:26:26 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r121246 r121251 1 2012-06-26 Taiju Tsuiki <tzik@chromium.org> 2 3 Web Inspector: Add requestMetadata command and metadataReceived event to FileSystem 4 https://bugs.webkit.org/show_bug.cgi?id=87856 5 6 Reviewed by Yury Semikhatsky. 7 8 * http/tests/inspector/filesystem/filesystem-test.js: 9 (initialize_FileSystemTest.InspectorTest.writeFile): 10 (initialize_FileSystemTest.InspectorTest.dumpMetadataRequestResult): 11 (initialize_FileSystemTest): 12 (writeFile.didGetFileSystem): 13 (writeFile): 14 (writeFile.didGetWriter.writer.onwrite): 15 (writeFile.didGetWriter): 16 * http/tests/inspector/filesystem/get-metadata-expected.txt: Added. 17 * http/tests/inspector/filesystem/get-metadata.html: Added. 18 1 19 2012-06-26 Philip Rogers <pdr@google.com> 2 20 -
trunk/LayoutTests/http/tests/inspector/filesystem/filesystem-test.js
r120906 r121251 30 30 }; 31 31 32 InspectorTest.writeFile = function(path, content, callback) 33 { 34 InspectorTest.evaluateInPage("writeFile(unescape(\"" + escape(path) + "\"), unescape(\"" + escape(content) + "\"), " + InspectorTest.registerCallback(callback) + ")"); 35 }; 36 32 37 InspectorTest.clearFileSystem = function(callback) 33 38 { … … 51 56 } 52 57 }; 58 59 InspectorTest.dumpMetadataRequestResult = function(errorCode, metadata) 60 { 61 InspectorTest.addResult("errorCode: " + errorCode); 62 if (metadata) { 63 InspectorTest.addResult("metadata:"); 64 InspectorTest.addResult(" modificationTime: " + ("modificationTime" in metadata ? "(exists)" : "(null)")); 65 InspectorTest.addResult(" size: " + ("size" in metadata ? metadata.size : "(null)")); 66 } else { 67 InspectorTest.addResult("metadata: (null)"); 68 } 69 }; 53 70 } 54 71 … … 61 78 function createDirectory(path, callback) 62 79 { 63 webkitRequestFileSystem(TEMPORARY, 1, gotFileSystem);80 webkitRequestFileSystem(TEMPORARY, 1, didGetFileSystem); 64 81 65 function gotFileSystem(fileSystem)82 function didGetFileSystem(fileSystem) 66 83 { 67 84 fileSystem.root.getDirectory(path, {create:true}, function(entry) { … … 73 90 function createFile(path, callback) 74 91 { 75 webkitRequestFileSystem(TEMPORARY, 1, gotFileSystem);92 webkitRequestFileSystem(TEMPORARY, 1, didGetFileSystem); 76 93 77 function gotFileSystem(fileSystem)94 function didGetFileSystem(fileSystem) 78 95 { 79 96 fileSystem.root.getFile(path, {create:true}, function(entry) { … … 83 100 } 84 101 102 function writeFile(path, content, callback) 103 { 104 webkitRequestFileSystem(TEMPORARY, 1, didGetFileSystem); 105 106 function didGetFileSystem(fileSystem) 107 { 108 fileSystem.root.getFile(path, {create:true}, didGetFileEntry); 109 } 110 111 function didGetFileEntry(fileEntry) 112 { 113 fileEntry.createWriter(didGetWriter); 114 } 115 116 function didGetWriter(writer) 117 { 118 writer.write(new Blob([content])); 119 writer.onwrite = function() { 120 if (writer.readyState === writer.DONE) 121 callback(); 122 }; 123 } 124 } 125 85 126 function clearFileSystem(callback) 86 127 { 87 webkitResolveLocalFileSystemURL("filesystem:" + location.origin + "/temporary/", gotRoot, onError);128 webkitResolveLocalFileSystemURL("filesystem:" + location.origin + "/temporary/", didGetRoot, onError); 88 129 89 function gotRoot(root)130 function didGetRoot(root) 90 131 { 91 132 var reader = root.createReader(); -
trunk/Source/WebCore/ChangeLog
r121250 r121251 1 2012-06-26 Taiju Tsuiki <tzik@chromium.org> 2 3 Web Inspector: Add requestMetadata command and metadataReceived event to FileSystem 4 https://bugs.webkit.org/show_bug.cgi?id=87856 5 6 Reviewed by Yury Semikhatsky. 7 8 Test: http/tests/inspector/filesystem/get-metadata.html 9 10 * inspector/Inspector.json: 11 * inspector/InspectorFileSystemAgent.cpp: 12 (WebCore): 13 (WebCore::InspectorFileSystemAgent::requestFileSystemRoot): 14 (WebCore::InspectorFileSystemAgent::requestDirectoryContent): 15 (WebCore::InspectorFileSystemAgent::requestMetadata): 16 * inspector/InspectorFileSystemAgent.h: 17 (InspectorFileSystemAgent): 18 * inspector/front-end/FileSystemModel.js: 19 (WebInspector.FileSystemModel.prototype._directoryContentReceived): 20 (WebInspector.FileSystemModel.prototype.requestMetadata): 21 (WebInspector.FileSystemModel.Entry.prototype.get isDirectory): 22 (WebInspector.FileSystemModel.Entry.prototype.requestMetadata): 23 (WebInspector.FileSystemRequestManager): 24 (WebInspector.FileSystemRequestManager.prototype._directoryContentReceived): 25 (WebInspector.FileSystemRequestManager.prototype.requestMetadata.requestAccepted): 26 (WebInspector.FileSystemRequestManager.prototype.requestMetadata): 27 (WebInspector.FileSystemRequestManager.prototype._metadataReceived): 28 (WebInspector.FileSystemDispatcher.prototype.directoryContentReceived): 29 (WebInspector.FileSystemDispatcher.prototype.metadataReceived): 30 1 31 2012-06-25 Jocelyn Turcotte <turcotte.j@gmail.com> 2 32 -
trunk/Source/WebCore/inspector/Inspector.json
r121014 r121251 1421 1421 ], 1422 1422 "description": "Represents a browser side file or directory." 1423 }, 1424 { 1425 "id": "Metadata", 1426 "type": "object", 1427 "properties": [ 1428 { "name": "modificationTime", "type": "number", "description": "Modification time." }, 1429 { "name": "size", "type": "number", "optional": true, "description": "File size. This field is available only for a file." } 1430 ], 1431 "description": "Represents metadata of a file or entry." 1423 1432 } 1424 1433 ], … … 1452 1461 ], 1453 1462 "description": "Returns content of the directory as directoryContentReceived event." 1463 }, 1464 { 1465 "name": "requestMetadata", 1466 "parameters": [ 1467 { "name": "url", "type": "string", "description": "URL of the entry that the frontend is requesting to get metadata from." } 1468 ], 1469 "returns": [ 1470 { "name": "requestId", "$ref": "RequestId", "description": "Request identifier. Corresponding metadataReceived event should have same requestId with this." } 1471 ], 1472 "description": "Returns metadata of the entry as metadataReceived event." 1454 1473 } 1455 1474 ], … … 1472 1491 ], 1473 1492 "description": "Completion event of requestDirectoryContent command." 1493 }, 1494 { 1495 "name": "metadataReceived", 1496 "parameters": [ 1497 { "name": "requestId", "type": "integer", "description": "Request Identifier that was returned in response to the corresponding getMetadata request." }, 1498 { "name": "errorCode", "type": "integer", "description": "0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value." }, 1499 { "name": "metadata", "$ref": "FileSystem.Metadata", "optional": true, "description": "Contains metadata of the entry if the command completed successfully." } 1500 ], 1501 "description": "Completion event of getMetadata command." 1474 1502 } 1475 1503 ] -
trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp
r120926 r121251 53 53 #include "LocalFileSystem.h" 54 54 #include "MIMETypeRegistry.h" 55 #include "Metadata.h" 56 #include "MetadataCallback.h" 55 57 #include "SecurityOrigin.h" 56 58 … … 143 145 private: 144 146 bool didHitError(FileError*); 145 bool gotEntry(Entry*);147 bool didGetEntry(Entry*); 146 148 147 149 void reportResult(FileError::ErrorCode errorCode, PassRefPtr<TypeBuilder::FileSystem::Entry> entry) … … 181 183 } 182 184 183 RefPtr<EntryCallback> successCallback = CallbackDispatcherFactory<EntryCallback>::create(this, &GetFileSystemRootTask:: gotEntry);185 RefPtr<EntryCallback> successCallback = CallbackDispatcherFactory<EntryCallback>::create(this, &GetFileSystemRootTask::didGetEntry); 184 186 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallback>::create(this, &GetFileSystemRootTask::didHitError); 185 187 OwnPtr<ResolveURICallbacks> fileSystemCallbacks = ResolveURICallbacks::create(successCallback, errorCallback, scriptExecutionContext, type, "/"); … … 188 190 } 189 191 190 bool GetFileSystemRootTask:: gotEntry(Entry* entry)192 bool GetFileSystemRootTask::didGetEntry(Entry* entry) 191 193 { 192 194 RefPtr<TypeBuilder::FileSystem::Entry> result(TypeBuilder::FileSystem::Entry::create().setUrl(entry->toURL()).setName("/").setIsDirectory(true)); … … 217 219 } 218 220 219 bool gotEntry(Entry*);221 bool didGetEntry(Entry*); 220 222 bool didReadDirectoryEntries(EntryArray*); 221 223 … … 253 255 } 254 256 255 RefPtr<EntryCallback> successCallback = CallbackDispatcherFactory<EntryCallback>::create(this, &ReadDirectoryTask:: gotEntry);257 RefPtr<EntryCallback> successCallback = CallbackDispatcherFactory<EntryCallback>::create(this, &ReadDirectoryTask::didGetEntry); 256 258 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallback>::create(this, &ReadDirectoryTask::didHitError); 257 259 OwnPtr<ResolveURICallbacks> fileSystemCallbacks = ResolveURICallbacks::create(successCallback, errorCallback, scriptExecutionContext, type, path); … … 260 262 } 261 263 262 bool ReadDirectoryTask:: gotEntry(Entry* entry)264 bool ReadDirectoryTask::didGetEntry(Entry* entry) 263 265 { 264 266 if (!entry->isDirectory()) { … … 319 321 } 320 322 323 class GetMetadataTask : public RefCounted<GetMetadataTask> { 324 WTF_MAKE_NONCOPYABLE(GetMetadataTask); 325 public: 326 static PassRefPtr<GetMetadataTask> create(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url) 327 { 328 return adoptRef(new GetMetadataTask(frontendProvider, requestId, url)); 329 } 330 331 virtual ~GetMetadataTask() 332 { 333 reportResult(FileError::ABORT_ERR, 0); 334 } 335 336 bool didHitError(FileError* error) 337 { 338 reportResult(error->code(), 0); 339 return true; 340 } 341 342 void start(ScriptExecutionContext*); 343 bool didGetEntry(Entry*); 344 bool didGetMetadata(Metadata*); 345 346 void reportResult(FileError::ErrorCode errorCode, PassRefPtr<TypeBuilder::FileSystem::Metadata> metadata) 347 { 348 if (!m_frontendProvider || !m_frontendProvider->frontend()) 349 return; 350 m_frontendProvider->frontend()->metadataReceived(m_requestId, static_cast<int>(errorCode), metadata); 351 m_frontendProvider = 0; 352 } 353 354 private: 355 GetMetadataTask(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url) 356 : m_frontendProvider(frontendProvider) 357 , m_requestId(requestId) 358 , m_url(ParsedURLString, url) { } 359 360 RefPtr<FrontendProvider> m_frontendProvider; 361 int m_requestId; 362 KURL m_url; 363 String m_path; 364 bool m_isDirectory; 365 }; 366 367 void GetMetadataTask::start(ScriptExecutionContext* scriptExecutionContext) 368 { 369 FileSystemType type; 370 DOMFileSystemBase::crackFileSystemURL(m_url, type, m_path); 371 372 RefPtr<EntryCallback> successCallback = CallbackDispatcherFactory<EntryCallback>::create(this, &GetMetadataTask::didGetEntry); 373 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallback>::create(this, &GetMetadataTask::didHitError); 374 375 OwnPtr<ResolveURICallbacks> fileSystemCallbacks = ResolveURICallbacks::create(successCallback, errorCallback, scriptExecutionContext, type, m_path); 376 LocalFileSystem::localFileSystem().readFileSystem(scriptExecutionContext, type, fileSystemCallbacks.release()); 377 } 378 379 bool GetMetadataTask::didGetEntry(Entry* entry) 380 { 381 if (!entry->filesystem()->scriptExecutionContext()) { 382 reportResult(FileError::ABORT_ERR, 0); 383 return true; 384 } 385 386 RefPtr<MetadataCallback> successCallback = CallbackDispatcherFactory<MetadataCallback>::create(this, &GetMetadataTask::didGetMetadata); 387 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallback>::create(this, &GetMetadataTask::didHitError); 388 entry->getMetadata(successCallback, errorCallback); 389 m_isDirectory = entry->isDirectory(); 390 return true; 391 } 392 393 bool GetMetadataTask::didGetMetadata(Metadata* metadata) 394 { 395 using TypeBuilder::FileSystem::Metadata; 396 RefPtr<Metadata> result = Metadata::create().setModificationTime(metadata->modificationTime()); 397 if (!m_isDirectory) 398 result->setSize(metadata->size()); 399 reportResult(static_cast<FileError::ErrorCode>(0), result); 400 return true; 401 } 402 321 403 } 322 404 … … 352 434 void InspectorFileSystemAgent::requestFileSystemRoot(ErrorString* error, const String& origin, const String& type, int* requestId) 353 435 { 354 if (!m_enabled || !m_frontendProvider) 355 return; 436 if (!m_enabled || !m_frontendProvider) { 437 *error = "FileSystem agent is not enabled"; 438 return; 439 } 356 440 ASSERT(m_frontendProvider->frontend()); 357 441 … … 363 447 } 364 448 365 void InspectorFileSystemAgent::requestDirectoryContent(ErrorString*, const String& url, int* requestId) 366 { 367 if (!m_enabled || !m_frontendProvider) 368 return; 449 void InspectorFileSystemAgent::requestDirectoryContent(ErrorString* error, const String& url, int* requestId) 450 { 451 if (!m_enabled || !m_frontendProvider) { 452 *error = "FileSystem agent is not enabled"; 453 return; 454 } 369 455 ASSERT(m_frontendProvider->frontend()); 370 456 … … 375 461 else 376 462 m_frontendProvider->frontend()->directoryContentReceived(*requestId, static_cast<int>(FileError::ABORT_ERR), 0); 463 } 464 465 void InspectorFileSystemAgent::requestMetadata(ErrorString* error, const String& url, int* requestId) 466 { 467 if (!m_enabled || !m_frontendProvider) { 468 *error = "FileSystem agent is not enabled"; 469 return; 470 } 471 ASSERT(m_frontendProvider->frontend()); 472 473 *requestId = m_nextRequestId++; 474 475 if (ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextForOrigin(SecurityOrigin::createFromString(url).get())) 476 GetMetadataTask::create(m_frontendProvider, *requestId, url)->start(scriptExecutionContext); 477 else 478 m_frontendProvider->frontend()->metadataReceived(*requestId, static_cast<int>(FileError::ABORT_ERR), 0); 377 479 } 378 480 -
trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h
r120906 r121251 62 62 virtual void requestFileSystemRoot(ErrorString*, const String& origin, const String& type, int* requestId) OVERRIDE; 63 63 virtual void requestDirectoryContent(ErrorString*, const String& url, int* requestId) OVERRIDE; 64 virtual void requestMetadata(ErrorString*, const String& url, int* requestId) OVERRIDE; 64 65 65 66 virtual void setFrontend(InspectorFrontend*) OVERRIDE; -
trunk/Source/WebCore/inspector/front-end/FileSystemModel.js
r121017 r121251 236 236 237 237 callback(errorCode, entries); 238 }, 239 240 requestMetadata: function(entry, callback) 241 { 242 this._agentWrapper.requestMetadata(entry.url, callback); 238 243 } 239 244 } … … 326 331 { 327 332 return this._isDirectory; 333 }, 334 335 /** 336 * @param {function(number, FileSystemAgent.Metadata)} callback 337 */ 338 requestMetadata: function(callback) 339 { 340 this.fileSystemModel.requestMetadata(this, callback); 328 341 } 329 342 } … … 395 408 this._pendingFileSystemRootRequests = {}; 396 409 this._pendingDirectoryContentRequests = {}; 410 this._pendingMetadataRequests = {}; 397 411 398 412 InspectorBackend.registerFileSystemDispatcher(new WebInspector.FileSystemDispatcher(this)); … … 460 474 delete this._pendingDirectoryContentRequests[requestId]; 461 475 callback(errorCode, backendEntries); 476 }, 477 478 /** 479 * @param {string} url 480 * @param {function(number, FileSystemAgent.Metadata=)} callback 481 */ 482 requestMetadata: function(url, callback) 483 { 484 var store = this._pendingMetadataRequests; 485 FileSystemAgent.requestMetadata(url, requestAccepted); 486 487 function requestAccepted(error, requestId) 488 { 489 if (!error) 490 store[requestId] = callback; 491 } 492 }, 493 494 _metadataReceived: function(requestId, errorCode, metadata) 495 { 496 var callback = this._pendingMetadataRequests[requestId]; 497 if (!callback) 498 return; 499 delete this._pendingMetadataRequests[requestId]; 500 callback(errorCode, metadata); 462 501 } 463 502 } … … 492 531 { 493 532 this._agentWrapper._directoryContentReceived(requestId, errorCode, backendEntries); 494 } 495 } 533 }, 534 535 /** 536 * @param {number} requestId 537 * @param {number} errorCode 538 * @param {FileSystemAgent.Metadata=} metadata 539 */ 540 metadataReceived: function(requestId, errorCode, metadata) 541 { 542 this._agentWrapper._metadataReceived(requestId, errorCode, metadata); 543 } 544 }
Note: See TracChangeset
for help on using the changeset viewer.