Diff
Modified: trunk/LayoutTests/ChangeLog (122100 => 122101)
--- trunk/LayoutTests/ChangeLog 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/LayoutTests/ChangeLog 2012-07-09 10:52:12 UTC (rev 122101)
@@ -1,3 +1,14 @@
+2012-07-09 Taiju Tsuiki <[email protected]>
+
+ Web Inspector: Add text file support for FileSystemAgent::requestFileContent
+ https://bugs.webkit.org/show_bug.cgi?id=90439
+
+ Reviewed by Vsevolod Vlasov.
+
+ * http/tests/inspector/filesystem/read-directory-expected.txt:
+ * http/tests/inspector/filesystem/read-file-expected.txt:
+ * http/tests/inspector/filesystem/read-file.html:
+
2012-07-09 Zan Dobersek <[email protected]>
Unreviewed, unskipping CSS Exclusions tests for the Gtk port.
Modified: trunk/LayoutTests/http/tests/inspector/filesystem/read-directory-expected.txt (122100 => 122101)
--- trunk/LayoutTests/http/tests/inspector/filesystem/read-directory-expected.txt 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/read-directory-expected.txt 2012-07-09 10:52:12 UTC (rev 122101)
@@ -6,6 +6,7 @@
url: filesystem:http://127.0.0.1:8000/temporary/hoge/piyo.html
name: piyo.html
isDirectory: false
+ isTextFile: true
mimeType: text/html
resourceType: Document
1:
Modified: trunk/LayoutTests/http/tests/inspector/filesystem/read-file-expected.txt (122100 => 122101)
--- trunk/LayoutTests/http/tests/inspector/filesystem/read-file-expected.txt 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/read-file-expected.txt 2012-07-09 10:52:12 UTC (rev 122101)
@@ -1,5 +1,6 @@
-Tests readFile.
+Tests requestFileContent.
errorCode = 0
-content = "UEFTUw==" [PASS]
+content = "PASS"
+charset = UTF-8
Modified: trunk/LayoutTests/http/tests/inspector/filesystem/read-file.html (122100 => 122101)
--- trunk/LayoutTests/http/tests/inspector/filesystem/read-file.html 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/read-file.html 2012-07-09 10:52:12 UTC (rev 122101)
@@ -18,22 +18,27 @@
function step2()
{
- InspectorTest.writeFile("/hoge/fuga", "piPASSyo", step3);
+ InspectorTest.writeFile("/hoge/fuga.txt", "piPASSyo", step3);
}
function step3()
{
- requestManager.requestFileContent("filesystem:http://127.0.0.1:8000/temporary/hoge/fuga", 2, 6, step4);
+ requestManager.requestFileContent("filesystem:http://127.0.0.1:8000/temporary/hoge/fuga.txt", true, 2, 6, "UTF-8", step4);
}
- function step4(errorCode, content)
+ function step4(errorCode, content, charset)
{
InspectorTest.addResult("errorCode = " + errorCode);
if (content)
- InspectorTest.addResult("content = \"" + content + "\" [" + atob(content) + "]");
+ InspectorTest.addResult("content = \"" + content + "\"");
else
InspectorTest.addResult("content = (null)");
+ if (charset)
+ InspectorTest.addResult("charset = " + charset);
+ else
+ InspectorTest.addResult("charset = (null)");
+
InspectorTest.clearFileSystem(step5);
}
@@ -45,6 +50,6 @@
</script>
</head>
<body>
-<p>Tests readFile.</p>
+<p>Tests requestFileContent.</p>
</body>
</html>
Modified: trunk/Source/WebCore/ChangeLog (122100 => 122101)
--- trunk/Source/WebCore/ChangeLog 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/Source/WebCore/ChangeLog 2012-07-09 10:52:12 UTC (rev 122101)
@@ -1,3 +1,22 @@
+2012-07-09 Taiju Tsuiki <[email protected]>
+
+ Web Inspector: Add text file support for FileSystemAgent::requestFileContent
+ https://bugs.webkit.org/show_bug.cgi?id=90439
+
+ Reviewed by Vsevolod Vlasov.
+
+ * inspector/Inspector.json:
+ * inspector/InspectorFileSystemAgent.cpp:
+ (WebCore):
+ (WebCore::InspectorFileSystemAgent::requestFileContent):
+ * inspector/InspectorFileSystemAgent.h:
+ (InspectorFileSystemAgent):
+ * inspector/front-end/FileSystemModel.js:
+ (WebInspector.FileSystemModel.prototype.requestFileContent):
+ (WebInspector.FileSystemModel.File.prototype.requestFileContent):
+ (WebInspector.FileSystemRequestManager.prototype._fileContentReceived):
+ (WebInspector.FileSystemDispatcher.prototype.fileContentReceived):
+
2012-07-09 MORITA Hajime <[email protected]>
[Chromium] ContextFeaturesClient::isEnabled is slow
Modified: trunk/Source/WebCore/inspector/Inspector.json (122100 => 122101)
--- trunk/Source/WebCore/inspector/Inspector.json 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/Source/WebCore/inspector/Inspector.json 2012-07-09 10:52:12 UTC (rev 122101)
@@ -1418,7 +1418,8 @@
{ "name": "name", "type": "string", "description": "The name of the file or directory." },
{ "name": "isDirectory", "type": "boolean", "description": "True if the entry is a directory." },
{ "name": "mimeType", "type": "string", "optional": true, "description": "MIME type of the entry, available for a file only." },
- { "name": "resourceType", "$ref": "Page.ResourceType", "optional": true, "description": "ResourceType of the entry, available for a file only." }
+ { "name": "resourceType", "$ref": "Page.ResourceType", "optional": true, "description": "ResourceType of the entry, available for a file only." },
+ { "name": "isTextFile", "type": "boolean", "optional": true, "description": "True if the entry is a text file." }
],
"description": "Represents a browser side file or directory."
},
@@ -1476,8 +1477,10 @@
"name": "requestFileContent",
"parameters": [
{ "name": "url", "type": "string", "description": "URL of the file that the frontend is requesting to read from." },
+ { "name": "readAsText", "type": "boolean", "description": "True if the content should be read as text, otherwise the result will be returned as base64 encoded text." },
{ "name": "start", "type": "integer", "optional": true, "description": "Specifies the start of range to read." },
- { "name": "end", "type": "integer", "optional": true, "description": "Specifies the end of range to read exclusively." }
+ { "name": "end", "type": "integer", "optional": true, "description": "Specifies the end of range to read exclusively." },
+ { "name": "charset", "type": "string", "optional": true, "description": "Overrides charset of the content when content is served as text." }
],
"returns": [
{ "name": "requestId", "$ref": "RequestId", "description": "Request identifier. Corresponding fileContentReceived event should have same requestId with this." }
@@ -1518,7 +1521,8 @@
"parameters": [
{ "name": "requestId", "type": "integer", "description": "Request Identifier that was returned in response to the corresponding requestFileContent command." },
{ "name": "errorCode", "type": "integer", "description": "0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value." },
- { "name": "content", "type": "string", "optional": true, "description": "Contains content of the file as base64 encoded string." }
+ { "name": "content", "type": "string", "optional": true, "description": "Content of the file." },
+ { "name": "charset", "type": "string", "optional": true, "description": "Charset of the content if it is served as text." }
],
"description": "Completion event of requestFileContent command."
}
Modified: trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp (122100 => 122101)
--- trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp 2012-07-09 10:52:12 UTC (rev 122101)
@@ -36,6 +36,7 @@
#include "Base64.h"
#include "DOMFileSystem.h"
+#include "DOMImplementation.h"
#include "DirectoryEntry.h"
#include "DirectoryReader.h"
#include "Document.h"
@@ -61,6 +62,8 @@
#include "MetadataCallback.h"
#include "ScriptExecutionContext.h"
#include "SecurityOrigin.h"
+#include "TextEncoding.h"
+#include "TextResourceDecoder.h"
using WebCore::TypeBuilder::Array;
@@ -307,14 +310,19 @@
if (!entry->isDirectory()) {
String mimeType = MIMETypeRegistry::getMIMETypeForPath(entry->name());
ResourceType::Enum resourceType;
- if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
+ if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType)) {
resourceType = ResourceType::Image;
- else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType))
+ entryForFrontend->setIsTextFile(false);
+ } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)) {
resourceType = ResourceType::Script;
- else if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
+ entryForFrontend->setIsTextFile(true);
+ } else if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType)) {
resourceType = ResourceType::Document;
- else
+ entryForFrontend->setIsTextFile(true);
+ } else {
resourceType = ResourceType::Other;
+ entryForFrontend->setIsTextFile(DOMImplementation::isXMLMIMEType(mimeType) || DOMImplementation::isTextMIMEType(mimeType));
+ }
entryForFrontend->setMimeType(mimeType);
entryForFrontend->setResourceType(resourceType);
@@ -407,14 +415,14 @@
class ReadFileTask : public EventListener {
WTF_MAKE_NONCOPYABLE(ReadFileTask);
public:
- static PassRefPtr<ReadFileTask> create(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url, long long start, long long end)
+ static PassRefPtr<ReadFileTask> create(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url, bool readAsText, long long start, long long end, const String& charset)
{
- return adoptRef(new ReadFileTask(frontendProvider, requestId, url, start, end));
+ return adoptRef(new ReadFileTask(frontendProvider, requestId, url, readAsText, start, end, charset));
}
virtual ~ReadFileTask()
{
- reportResult(FileError::ABORT_ERR, 0);
+ reportResult(FileError::ABORT_ERR, 0, 0);
}
void start(ScriptExecutionContext*);
@@ -436,7 +444,7 @@
private:
bool didHitError(FileError* error)
{
- reportResult(error->code(), 0);
+ reportResult(error->code(), 0, 0);
return true;
}
@@ -444,27 +452,32 @@
bool didGetFile(File*);
void didRead();
- void reportResult(FileError::ErrorCode errorCode, const String* result)
+ void reportResult(FileError::ErrorCode errorCode, const String* result, const String* charset)
{
if (!m_frontendProvider || !m_frontendProvider->frontend())
return;
- m_frontendProvider->frontend()->fileContentReceived(m_requestId, static_cast<int>(errorCode), result);
+ m_frontendProvider->frontend()->fileContentReceived(m_requestId, static_cast<int>(errorCode), result, charset);
m_frontendProvider = 0;
}
- ReadFileTask(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url, long long start, long long end)
+ ReadFileTask(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url, bool readAsText, long long start, long long end, const String& charset)
: EventListener(EventListener::CPPEventListenerType)
, m_frontendProvider(frontendProvider)
, m_requestId(requestId)
, m_url(ParsedURLString, url)
+ , m_readAsText(readAsText)
, m_start(start)
- , m_end(end) { }
+ , m_end(end)
+ , m_charset(charset) { }
RefPtr<FrontendProvider> m_frontendProvider;
int m_requestId;
KURL m_url;
+ bool m_readAsText;
int m_start;
long long m_end;
+ String m_mimeType;
+ String m_charset;
RefPtr<FileReader> m_reader;
};
@@ -476,7 +489,7 @@
FileSystemType type;
String path;
if (!DOMFileSystemBase::crackFileSystemURL(m_url, type, path)) {
- reportResult(FileError::SYNTAX_ERR, 0);
+ reportResult(FileError::SYNTAX_ERR, 0, 0);
return;
}
@@ -490,12 +503,12 @@
bool ReadFileTask::didGetEntry(Entry* entry)
{
if (entry->isDirectory()) {
- reportResult(FileError::TYPE_MISMATCH_ERR, 0);
+ reportResult(FileError::TYPE_MISMATCH_ERR, 0, 0);
return true;
}
if (!entry->filesystem()->scriptExecutionContext()) {
- reportResult(FileError::ABORT_ERR, 0);
+ reportResult(FileError::ABORT_ERR, 0, 0);
return true;
}
@@ -504,6 +517,8 @@
static_cast<FileEntry*>(entry)->file(successCallback, errorCallback);
m_reader = FileReader::create(entry->filesystem()->scriptExecutionContext());
+ m_mimeType = MIMETypeRegistry::getMIMETypeForPath(entry->name());
+
return true;
}
@@ -520,9 +535,19 @@
void ReadFileTask::didRead()
{
- RefPtr<ArrayBuffer> result = m_reader->arrayBufferResult();
- String encodedResult = base64Encode(static_cast<char*>(result->data()), result->byteLength());
- reportResult(static_cast<FileError::ErrorCode>(0), &encodedResult);
+ RefPtr<ArrayBuffer> buffer = m_reader->arrayBufferResult();
+
+ if (!m_readAsText) {
+ String result = base64Encode(static_cast<char*>(buffer->data()), buffer->byteLength());
+ reportResult(static_cast<FileError::ErrorCode>(0), &result, 0);
+ return;
+ }
+
+ RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create(m_mimeType, m_charset, true);
+ String result = decoder->decode(static_cast<char*>(buffer->data()), buffer->byteLength());
+ result += decoder->flush();
+ m_charset = decoder->encoding().domName();
+ reportResult(static_cast<FileError::ErrorCode>(0), &result, &m_charset);
}
}
@@ -603,7 +628,7 @@
m_frontendProvider->frontend()->metadataReceived(*requestId, static_cast<int>(FileError::ABORT_ERR), 0);
}
-void InspectorFileSystemAgent::requestFileContent(ErrorString* error, const String& url, const int* start, const int* end, int* requestId)
+void InspectorFileSystemAgent::requestFileContent(ErrorString* error, const String& url, bool readAsText, const int* start, const int* end, const String* charset, int* requestId)
{
if (!m_enabled || !m_frontendProvider) {
*error = "FileSystem agent is not enabled";
@@ -614,9 +639,9 @@
*requestId = m_nextRequestId++;
if (ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextForOrigin(SecurityOrigin::createFromString(url).get()))
- ReadFileTask::create(m_frontendProvider, *requestId, url, start ? *start : 0, end ? *end : std::numeric_limits<long long>::max())->start(scriptExecutionContext);
+ ReadFileTask::create(m_frontendProvider, *requestId, url, readAsText, start ? *start : 0, end ? *end : std::numeric_limits<long long>::max(), charset ? *charset : "")->start(scriptExecutionContext);
else
- m_frontendProvider->frontend()->fileContentReceived(*requestId, static_cast<int>(FileError::ABORT_ERR), 0);
+ m_frontendProvider->frontend()->fileContentReceived(*requestId, static_cast<int>(FileError::ABORT_ERR), 0, 0);
}
void InspectorFileSystemAgent::setFrontend(InspectorFrontend* frontend)
Modified: trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h (122100 => 122101)
--- trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h 2012-07-09 10:52:12 UTC (rev 122101)
@@ -62,7 +62,7 @@
virtual void requestFileSystemRoot(ErrorString*, const String& origin, const String& type, int* requestId) OVERRIDE;
virtual void requestDirectoryContent(ErrorString*, const String& url, int* requestId) OVERRIDE;
virtual void requestMetadata(ErrorString*, const String& url, int* requestId) OVERRIDE;
- virtual void requestFileContent(ErrorString*, const String& url, const int* start, const int* end, int* requestId) OVERRIDE;
+ virtual void requestFileContent(ErrorString*, const String& url, bool readAsText, const int* start, const int* end, const String* charset, int* requestId) OVERRIDE;
virtual void setFrontend(InspectorFrontend*) OVERRIDE;
virtual void clearFrontend() OVERRIDE;
Modified: trunk/Source/WebCore/inspector/front-end/FileSystemModel.js (122100 => 122101)
--- trunk/Source/WebCore/inspector/front-end/FileSystemModel.js 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/Source/WebCore/inspector/front-end/FileSystemModel.js 2012-07-09 10:52:12 UTC (rev 122101)
@@ -248,13 +248,15 @@
/**
* @param {WebInspector.FileSystemModel.File} file
- * @param {number} start
- * @param {number} end
- * @param {function(number, string=)} callback
+ * @param {boolean} readAsText
+ * @param {number=} start
+ * @param {number=} end
+ * @param {string=} charset
+ * @param {function(number, string=, string=)=} callback
*/
- requestFileContent: function(file, start, end, callback)
+ requestFileContent: function(file, readAsText, start, end, charset, callback)
{
- this._agentWrapper.requestFileContent(file.url, start, end, callback);
+ this._agentWrapper.requestFileContent(file.url, readAsText, start, end, charset, callback);
}
}
@@ -405,6 +407,7 @@
this._mimeType = backendEntry.mimeType;
this._resourceType = WebInspector.resourceTypes[backendEntry.resourceType];
+ this._isTextFile = backendEntry.isTextFile;
}
WebInspector.FileSystemModel.File.prototype = {
@@ -425,13 +428,23 @@
},
/**
- * @param {number} start
- * @param {number} end
- * @param {function(number, string=)} callback
+ * @type {boolean}
*/
- requestFileContent: function(start, end, callback)
+ get isTextFile()
{
- this.fileSystemModel.requestFileContent(this, start, end, callback);
+ return this._isTextFile;
+ },
+
+ /**
+ * @param {boolean} readAsText
+ * @param {number=} start
+ * @param {number=} end
+ * @param {string=} charset
+ * @param {function(number, string=)=} callback
+ */
+ requestFileContent: function(readAsText, start, end, charset, callback)
+ {
+ this.fileSystemModel.requestFileContent(this, readAsText, start, end, charset, callback);
}
}
@@ -455,7 +468,7 @@
/**
* @param {string} origin
* @param {string} type
- * @param {function(number, FileSystemAgent.Entry)} callback
+ * @param {function(number, FileSystemAgent.Entry)=} callback
*/
requestFileSystemRoot: function(origin, type, callback)
{
@@ -465,7 +478,7 @@
function requestAccepted(error, requestId)
{
if (!error)
- store[requestId] = callback;
+ store[requestId] = callback || function() {};
}
},
@@ -485,7 +498,7 @@
/**
* @param {string} url
- * @param {function(number, Array.<FileSystemAgent.Entry>=)} callback
+ * @param {function(number, Array.<FileSystemAgent.Entry>=)=} callback
*/
requestDirectoryContent: function(url, callback)
{
@@ -495,7 +508,7 @@
function requestAccepted(error, requestId)
{
if (!error)
- store[requestId] = callback;
+ store[requestId] = callback || function() {};
}
},
@@ -515,7 +528,7 @@
/**
* @param {string} url
- * @param {function(number, FileSystemAgent.Metadata=)} callback
+ * @param {function(number, FileSystemAgent.Metadata=)=} callback
*/
requestMetadata: function(url, callback)
{
@@ -525,7 +538,7 @@
function requestAccepted(error, requestId)
{
if (!error)
- store[requestId] = callback;
+ store[requestId] = callback || function() {};
}
},
@@ -540,19 +553,21 @@
/**
* @param {string} url
- * @param {number} start
- * @param {number} end
- * @param {function(number, string)} callback
+ * @param {boolean} readAsText
+ * @param {number=} start
+ * @param {number=} end
+ * @param {string=} charset
+ * @param {function(number, string=, string=)=} callback
*/
- requestFileContent: function(url, start, end, callback)
+ requestFileContent: function(url, readAsText, start, end, charset, callback)
{
var store = this._pendingFileContentRequests;
- FileSystemAgent.requestFileContent(url, start, end, requestAccepted);
+ FileSystemAgent.requestFileContent(url, readAsText, start, end, charset, requestAccepted);
function requestAccepted(error, requestId)
{
if (!error)
- store[requestId] = callback;
+ store[requestId] = callback || function() {};
}
},
@@ -560,14 +575,15 @@
* @param {number} requestId
* @param {number} errorCode
* @param {string=} content
+ * @param {string=} charset
*/
- _fileContentReceived: function(requestId, errorCode, content)
+ _fileContentReceived: function(requestId, errorCode, content, charset)
{
- var callback = /** @type {function(number, string=)} */ this._pendingFileContentRequests[requestId];
+ var callback = /** @type {function(number, string=, string=)} */ this._pendingFileContentRequests[requestId];
if (!callback)
return;
delete this._pendingFileContentRequests[requestId];
- callback(errorCode, content);
+ callback(errorCode, content, charset);
}
}
@@ -616,9 +632,10 @@
* @param {number} requestId
* @param {number} errorCode
* @param {string=} content
+ * @param {string=} charset
*/
- fileContentReceived: function(requestId, errorCode, content)
+ fileContentReceived: function(requestId, errorCode, content, charset)
{
- this._agentWrapper._fileContentReceived(requestId, errorCode, content);
+ this._agentWrapper._fileContentReceived(requestId, errorCode, content, charset);
}
}
Modified: trunk/Source/WebCore/inspector/front-end/FileSystemView.js (122100 => 122101)
--- trunk/Source/WebCore/inspector/front-end/FileSystemView.js 2012-07-09 09:33:27 UTC (rev 122100)
+++ trunk/Source/WebCore/inspector/front-end/FileSystemView.js 2012-07-09 10:52:12 UTC (rev 122101)
@@ -56,6 +56,9 @@
}
WebInspector.FileSystemView.prototype = {
+ /**
+ * @type {Array.<Element>}
+ */
get statusBarItems()
{
return [this._refreshButton.element];