Changeset 121676 in webkit
- Timestamp:
- Jul 2, 2012 7:12:04 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r121675 r121676 1 2012-07-02 Taiju Tsuiki <tzik@chromium.org> 2 3 Web Inspector: Add requestFileContent command and fileContentReceived event 4 https://bugs.webkit.org/show_bug.cgi?id=89642 5 6 Reviewed by Vsevolod Vlasov. 7 8 * http/tests/inspector/filesystem/read-file-expected.txt: Added. 9 * http/tests/inspector/filesystem/read-file.html: Added. 10 1 11 2012-07-02 Taiju Tsuiki <tzik@chromium.org> 2 12 -
trunk/Source/WebCore/ChangeLog
r121675 r121676 1 2012-07-02 Taiju Tsuiki <tzik@chromium.org> 2 3 Web Inspector: Add requestFileContent command and fileContentReceived event 4 https://bugs.webkit.org/show_bug.cgi?id=89642 5 6 Reviewed by Vsevolod Vlasov. 7 8 Test: http/tests/inspector/filesystem/read-file.html 9 10 * inspector/Inspector.json: 11 * inspector/InspectorFileSystemAgent.cpp: 12 (WebCore): 13 (WebCore::InspectorFileSystemAgent::requestFileContent): 14 * inspector/InspectorFileSystemAgent.h: 15 (InspectorFileSystemAgent): 16 * inspector/front-end/FileSystemModel.js: 17 (WebInspector.FileSystemModel.prototype.requestMetadata): 18 (WebInspector.FileSystemModel.prototype.requestFileContent): 19 (WebInspector.FileSystemModel.File.prototype.get resourceType): 20 (WebInspector.FileSystemModel.File.prototype.requestFileContent): 21 (WebInspector.FileSystemRequestManager): 22 (WebInspector.FileSystemRequestManager.prototype._metadataReceived): 23 (WebInspector.FileSystemRequestManager.prototype.requestFileContent.requestAccepted): 24 (WebInspector.FileSystemRequestManager.prototype.requestFileContent): 25 (WebInspector.FileSystemRequestManager.prototype._fileContentReceived): 26 (WebInspector.FileSystemDispatcher.prototype.metadataReceived): 27 (WebInspector.FileSystemDispatcher.prototype.fileContentReceived): 28 1 29 2012-07-02 Taiju Tsuiki <tzik@chromium.org> 2 30 -
trunk/Source/WebCore/inspector/Inspector.json
r121549 r121676 1472 1472 ], 1473 1473 "description": "Returns metadata of the entry as metadataReceived event." 1474 }, 1475 { 1476 "name": "requestFileContent", 1477 "parameters": [ 1478 { "name": "url", "type": "string", "description": "URL of the file that the frontend is requesting to read from." }, 1479 { "name": "start", "type": "integer", "optional": true, "description": "Specifies the start of range to read." }, 1480 { "name": "end", "type": "integer", "optional": true, "description": "Specifies the end of range to read exclusively." } 1481 ], 1482 "returns": [ 1483 { "name": "requestId", "$ref": "RequestId", "description": "Request identifier. Corresponding fileContentReceived event should have same requestId with this." } 1484 ], 1485 "description": "Returns content of the file as fileContentReceived event. Result should be sliced into [start, end)." 1474 1486 } 1475 1487 ], … … 1496 1508 "name": "metadataReceived", 1497 1509 "parameters": [ 1498 { "name": "requestId", "type": "integer", "description": "Request Identifier that was returned in response to the corresponding getMetadata request." },1510 { "name": "requestId", "type": "integer", "description": "Request Identifier that was returned in response to the corresponding requestMetadata command." }, 1499 1511 { "name": "errorCode", "type": "integer", "description": "0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value." }, 1500 1512 { "name": "metadata", "$ref": "FileSystem.Metadata", "optional": true, "description": "Contains metadata of the entry if the command completed successfully." } 1501 1513 ], 1502 "description": "Completion event of getMetadata command." 1514 "description": "Completion event of requestMetadata command." 1515 }, 1516 { 1517 "name": "fileContentReceived", 1518 "parameters": [ 1519 { "name": "requestId", "type": "integer", "description": "Request Identifier that was returned in response to the corresponding requestFileContent command." }, 1520 { "name": "errorCode", "type": "integer", "description": "0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value." }, 1521 { "name": "content", "type": "string", "optional": true, "description": "Contains content of the file as base64 encoded string." } 1522 ], 1523 "description": "Completion event of requestFileContent command." 1503 1524 } 1504 1525 ] -
trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp
r121251 r121676 35 35 #include "InspectorFileSystemAgent.h" 36 36 37 #include "Base64.h" 37 38 #include "DOMFileSystem.h" 38 39 #include "DirectoryEntry.h" … … 40 41 #include "Document.h" 41 42 #include "EntriesCallback.h" 43 #include "Entry.h" 42 44 #include "EntryArray.h" 43 45 #include "EntryCallback.h" 44 46 #include "ErrorCallback.h" 47 #include "FileCallback.h" 48 #include "FileEntry.h" 45 49 #include "FileError.h" 50 #include "FileReader.h" 46 51 #include "FileSystemCallback.h" 47 52 #include "FileSystemCallbacks.h" … … 55 60 #include "Metadata.h" 56 61 #include "MetadataCallback.h" 62 #include "ScriptExecutionContext.h" 57 63 #include "SecurityOrigin.h" 58 64 … … 401 407 } 402 408 409 class ReadFileTask : public EventListener { 410 WTF_MAKE_NONCOPYABLE(ReadFileTask); 411 public: 412 static PassRefPtr<ReadFileTask> create(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url, long long start, long long end) 413 { 414 return adoptRef(new ReadFileTask(frontendProvider, requestId, url, start, end)); 415 } 416 417 virtual ~ReadFileTask() 418 { 419 reportResult(FileError::ABORT_ERR, 0); 420 } 421 422 void start(ScriptExecutionContext*); 423 424 425 virtual bool operator==(const EventListener& other) OVERRIDE 426 { 427 return this == &other; 428 } 429 430 virtual void handleEvent(ScriptExecutionContext*, Event* event) OVERRIDE 431 { 432 if (event->type() == eventNames().loadEvent) 433 didRead(); 434 else if (event->type() == eventNames().errorEvent) 435 didHitError(m_reader->error().get()); 436 } 437 438 private: 439 bool didHitError(FileError* error) 440 { 441 reportResult(error->code(), 0); 442 return true; 443 } 444 445 bool didGetEntry(Entry*); 446 bool didGetFile(File*); 447 void didRead(); 448 449 void reportResult(FileError::ErrorCode errorCode, const String* result) 450 { 451 if (!m_frontendProvider || !m_frontendProvider->frontend()) 452 return; 453 m_frontendProvider->frontend()->fileContentReceived(m_requestId, static_cast<int>(errorCode), result); 454 m_frontendProvider = 0; 455 } 456 457 ReadFileTask(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url, long long start, long long end) 458 : EventListener(EventListener::CPPEventListenerType) 459 , m_frontendProvider(frontendProvider) 460 , m_requestId(requestId) 461 , m_url(ParsedURLString, url) 462 , m_start(start) 463 , m_end(end) 464 , m_current(start) { } 465 466 RefPtr<FrontendProvider> m_frontendProvider; 467 int m_requestId; 468 KURL m_url; 469 int m_start; 470 long long m_end; 471 long long m_current; 472 473 RefPtr<FileReader> m_reader; 474 }; 475 476 void ReadFileTask::start(ScriptExecutionContext* scriptExecutionContext) 477 { 478 ASSERT(scriptExecutionContext); 479 480 FileSystemType type; 481 String path; 482 if (!DOMFileSystemBase::crackFileSystemURL(m_url, type, path)) { 483 reportResult(FileError::SYNTAX_ERR, 0); 484 return; 485 } 486 487 RefPtr<EntryCallback> successCallback = CallbackDispatcherFactory<EntryCallback>::create(this, &ReadFileTask::didGetEntry); 488 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallback>::create(this, &ReadFileTask::didHitError); 489 OwnPtr<ResolveURICallbacks> fileSystemCallbacks = ResolveURICallbacks::create(successCallback, errorCallback, scriptExecutionContext, type, path); 490 491 LocalFileSystem::localFileSystem().readFileSystem(scriptExecutionContext, type, fileSystemCallbacks.release()); 492 } 493 494 bool ReadFileTask::didGetEntry(Entry* entry) 495 { 496 if (entry->isDirectory()) { 497 reportResult(FileError::TYPE_MISMATCH_ERR, 0); 498 return true; 499 } 500 501 if (!entry->filesystem()->scriptExecutionContext()) { 502 reportResult(FileError::ABORT_ERR, 0); 503 return true; 504 } 505 506 RefPtr<FileCallback> successCallback = CallbackDispatcherFactory<FileCallback>::create(this, &ReadFileTask::didGetFile); 507 RefPtr<ErrorCallback> errorCallback = CallbackDispatcherFactory<ErrorCallback>::create(this, &ReadFileTask::didHitError); 508 static_cast<FileEntry*>(entry)->file(successCallback, errorCallback); 509 510 m_reader = FileReader::create(entry->filesystem()->scriptExecutionContext()); 511 return true; 512 } 513 514 bool ReadFileTask::didGetFile(File* file) 515 { 516 RefPtr<Blob> blob = file->slice(m_start, m_end); 517 m_reader->setOnload(this); 518 m_reader->setOnerror(this); 519 520 ExceptionCode ec = 0; 521 m_reader->readAsArrayBuffer(blob.get(), ec); 522 return true; 523 } 524 525 void ReadFileTask::didRead() 526 { 527 RefPtr<ArrayBuffer> result = m_reader->arrayBufferResult(); 528 String encodedResult = base64Encode(static_cast<char*>(result->data()), result->byteLength()); 529 reportResult(static_cast<FileError::ErrorCode>(0), &encodedResult); 530 } 531 403 532 } 404 533 … … 479 608 } 480 609 610 void InspectorFileSystemAgent::requestFileContent(ErrorString* error, const String& url, const int* start, const int* end, int* requestId) 611 { 612 if (!m_enabled || !m_frontendProvider) { 613 *error = "FileSystem agent is not enabled"; 614 return; 615 } 616 ASSERT(m_frontendProvider->frontend()); 617 618 *requestId = m_nextRequestId++; 619 620 if (ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextForOrigin(SecurityOrigin::createFromString(url).get())) 621 ReadFileTask::create(m_frontendProvider, *requestId, url, start ? *start : 0, end ? *end : std::numeric_limits<long long>::max())->start(scriptExecutionContext); 622 else 623 m_frontendProvider->frontend()->fileContentReceived(*requestId, static_cast<int>(FileError::ABORT_ERR), 0); 624 } 625 481 626 void InspectorFileSystemAgent::setFrontend(InspectorFrontend* frontend) 482 627 { -
trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h
r121251 r121676 63 63 virtual void requestDirectoryContent(ErrorString*, const String& url, int* requestId) OVERRIDE; 64 64 virtual void requestMetadata(ErrorString*, const String& url, int* requestId) OVERRIDE; 65 virtual void requestFileContent(ErrorString*, const String& url, const int* start, const int* end, int* requestId) OVERRIDE; 65 66 66 67 virtual void setFrontend(InspectorFrontend*) OVERRIDE; -
trunk/Source/WebCore/inspector/front-end/FileSystemModel.js
r121542 r121676 238 238 }, 239 239 240 /** 241 * @param {WebInspector.FileSystemModel.Entry} entry 242 * @param {function(number, FileSystemAgent.Metadata=)} callback 243 */ 240 244 requestMetadata: function(entry, callback) 241 245 { 242 246 this._agentWrapper.requestMetadata(entry.url, callback); 247 }, 248 249 /** 250 * @param {WebInspector.FileSystemModel.File} file 251 * @param {number} start 252 * @param {number} end 253 * @param {function(number, string=)} callback 254 */ 255 requestFileContent: function(file, start, end, callback) 256 { 257 this._agentWrapper.requestFileContent(file.url, start, end, callback); 243 258 } 244 259 } … … 408 423 { 409 424 return this._resourceType; 425 }, 426 427 /** 428 * @param {number} start 429 * @param {number} end 430 * @param {function(number, string=)} callback 431 */ 432 requestFileContent: function(start, end, callback) 433 { 434 this.fileSystemModel.requestFileContent(this, start, end, callback); 410 435 } 411 436 } … … 421 446 this._pendingDirectoryContentRequests = {}; 422 447 this._pendingMetadataRequests = {}; 448 this._pendingFileContentRequests = {}; 423 449 424 450 InspectorBackend.registerFileSystemDispatcher(new WebInspector.FileSystemDispatcher(this)); … … 511 537 delete this._pendingMetadataRequests[requestId]; 512 538 callback(errorCode, metadata); 539 }, 540 541 /** 542 * @param {string} url 543 * @param {number} start 544 * @param {number} end 545 * @param {function(number, string)} callback 546 */ 547 requestFileContent: function(url, start, end, callback) 548 { 549 var store = this._pendingFileContentRequests; 550 FileSystemAgent.requestFileContent(url, start, end, requestAccepted); 551 552 function requestAccepted(error, requestId) 553 { 554 if (!error) 555 store[requestId] = callback; 556 } 557 }, 558 559 /** 560 * @param {number} requestId 561 * @param {number} errorCode 562 * @param {string=} content 563 */ 564 _fileContentReceived: function(requestId, errorCode, content) 565 { 566 var callback = /** @type {function(number, string=)} */ this._pendingFileContentRequests[requestId]; 567 if (!callback) 568 return; 569 delete this._pendingFileContentRequests[requestId]; 570 callback(errorCode, content); 513 571 } 514 572 } … … 553 611 { 554 612 this._agentWrapper._metadataReceived(requestId, errorCode, metadata); 613 }, 614 615 /** 616 * @param {number} requestId 617 * @param {number} errorCode 618 * @param {string=} content 619 */ 620 fileContentReceived: function(requestId, errorCode, content) 621 { 622 this._agentWrapper._fileContentReceived(requestId, errorCode, content); 555 623 } 556 624 }
Note: See TracChangeset
for help on using the changeset viewer.