Diff
Modified: trunk/Source/WebCore/ChangeLog (89367 => 89368)
--- trunk/Source/WebCore/ChangeLog 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/ChangeLog 2011-06-21 18:16:35 UTC (rev 89368)
@@ -1,3 +1,28 @@
+2011-06-21 Vsevolod Vlasov <[email protected]>
+
+ Reviewed by Pavel Feldman.
+
+ Web Inspector: Move logic for deciding whether resource content should be base64 encoded on backend.
+ https://bugs.webkit.org/show_bug.cgi?id=63069
+
+ * inspector/Inspector.json:
+ * inspector/InspectorPageAgent.cpp:
+ (WebCore::InspectorPageAgent::cachedResourceContent):
+ (WebCore::InspectorPageAgent::resourceContent):
+ (WebCore::InspectorPageAgent::getResourceContent):
+ (WebCore::InspectorPageAgent::searchInResources):
+ * inspector/InspectorPageAgent.h:
+ * inspector/InspectorResourceAgent.cpp:
+ (WebCore::InspectorResourceAgent::getResourceContent):
+ * inspector/InspectorResourceAgent.h:
+ * inspector/InspectorStyleSheet.cpp:
+ (WebCore::InspectorStyleSheet::resourceStyleSheetText):
+ * inspector/front-end/NetworkManager.js:
+ (WebInspector.NetworkManager.prototype.requestContent):
+ * inspector/front-end/Resource.js:
+ (WebInspector.Resource.prototype._innerRequestContent.onResourceContent):
+ (WebInspector.Resource.prototype._innerRequestContent):
+
2011-06-21 Dirk Schulze <[email protected]>
Reviewed by Rob Buis.
Modified: trunk/Source/WebCore/inspector/Inspector.json (89367 => 89368)
--- trunk/Source/WebCore/inspector/Inspector.json 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/Inspector.json 2011-06-21 18:16:35 UTC (rev 89368)
@@ -161,11 +161,11 @@
"description": "Returns content of the given resource.",
"parameters": [
{ "name": "frameId", "type": "string", "description": "Frame id to get resource for." },
- { "name": "url", "type": "string", "description": "URL of the resource to get content for." },
- { "name": "base64Encode", "type": "boolean", "optional": true, "description": "Requests that resource content is served as base64." }
+ { "name": "url", "type": "string", "description": "URL of the resource to get content for." }
],
"returns": [
- { "name": "content", "type": "string", "description": "Resource content." }
+ { "name": "content", "type": "string", "description": "Resource content." },
+ { "name": "base64Encoded", "type": "boolean", "description": "True, if content was served as base64." }
]
},
{
@@ -490,11 +490,11 @@
"name": "getResourceContent",
"description": "Returns content of the given resource.",
"parameters": [
- { "name": "identifier", "type": "integer", "description": "Identifier of the resource to get content for." },
- { "name": "base64Encode", "type": "boolean", "optional": true, "description": "Requests that resource content is served as base64." }
+ { "name": "identifier", "type": "integer", "description": "Identifier of the resource to get content for." }
],
"returns": [
- { "name": "content", "type": "string", "description": "Resource content." }
+ { "name": "content", "type": "string", "description": "Resource content." },
+ { "name": "base64Encoded", "type": "boolean", "description": "True, if content was served as base64." }
]
}
],
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (89367 => 89368)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2011-06-21 18:16:35 UTC (rev 89368)
@@ -110,14 +110,17 @@
return true;
}
-bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, bool withBase64Encode, String* result)
+bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, String* result, bool* base64Encoded)
{
+ ResourceType type = cachedResourceType(*cachedResource);
+ *base64Encoded = type != StylesheetResource && type != ScriptResource;
+
bool hasZeroSize;
bool prepared = prepareCachedResourceBuffer(cachedResource, &hasZeroSize);
if (!prepared)
return false;
- if (withBase64Encode) {
+ if (*base64Encoded) {
RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->data();
if (!buffer)
@@ -173,7 +176,7 @@
}
// static
-void InspectorPageAgent::resourceContent(ErrorString* errorString, Frame* frame, const KURL& url, bool base64Encode, String* result)
+void InspectorPageAgent::resourceContent(ErrorString* errorString, Frame* frame, const KURL& url, String* result, bool* base64Encoded)
{
if (!frame) {
*errorString = "No frame to get resource content for";
@@ -190,10 +193,13 @@
RefPtr<SharedBuffer> buffer;
bool success = false;
- if (equalIgnoringFragmentIdentifier(url, loader->url()))
- success = mainResourceContent(frame, base64Encode, result);
+ if (equalIgnoringFragmentIdentifier(url, loader->url())) {
+ *base64Encoded = false;
+ success = mainResourceContent(frame, *base64Encoded, result);
+ }
+
if (!success)
- success = cachedResourceContent(cachedResource(frame, url), base64Encode, result);
+ success = cachedResourceContent(cachedResource(frame, url), result, base64Encoded);
if (!success)
*errorString = "No resource with given URL found";
@@ -414,15 +420,14 @@
*object = buildObjectForFrameTree(m_page->mainFrame());
}
-void InspectorPageAgent::getResourceContent(ErrorString* errorString, const String& frameId, const String& url, const bool* const optionalBase64Encode, String* content)
+void InspectorPageAgent::getResourceContent(ErrorString* errorString, const String& frameId, const String& url, String* content, bool* base64Encoded)
{
Frame* frame = frameForId(frameId);
if (!frame) {
*errorString = "No frame for given id found";
return;
}
- bool base64Encode = optionalBase64Encode ? *optionalBase64Encode : false;
- resourceContent(errorString, frame, KURL(ParsedURLString, url), base64Encode, content);
+ resourceContent(errorString, frame, KURL(ParsedURLString, url), content, base64Encoded);
}
static String createSearchRegexSource(const String& text)
@@ -478,13 +483,15 @@
for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext(m_page->mainFrame())) {
String content;
+ bool base64Encoded;
Vector<CachedResource*> allResources = cachedResourcesForFrame(frame);
for (Vector<CachedResource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) {
CachedResource* cachedResource = *it;
switch (InspectorPageAgent::cachedResourceType(*cachedResource)) {
case InspectorPageAgent::StylesheetResource:
case InspectorPageAgent::ScriptResource:
- if (cachedResourceContent(cachedResource, false, &content)) {
+ if (cachedResourceContent(cachedResource, &content, &base64Encoded)) {
+ ASSERT(!base64Encoded);
int matchesCount = countRegularExpressionMatches(regex, content);
if (matchesCount)
result->pushValue(buildObjectForSearchMatch(frameId(frame), cachedResource->url(), matchesCount));
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.h (89367 => 89368)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.h 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.h 2011-06-21 18:16:35 UTC (rev 89368)
@@ -75,9 +75,9 @@
static PassOwnPtr<InspectorPageAgent> create(InstrumentingAgents*, Page*, InjectedScriptManager*);
- static bool cachedResourceContent(CachedResource*, bool withBase64Encode, String* result);
+ static bool cachedResourceContent(CachedResource*, String* result, bool* base64Encoded);
static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result);
- static void resourceContent(ErrorString*, Frame*, const KURL&, bool base64Encode, String* result);
+ static void resourceContent(ErrorString*, Frame*, const KURL&, String* result, bool* base64Encoded);
static PassRefPtr<SharedBuffer> resourceData(Frame*, const KURL&, String* textEncodingName);
static CachedResource* cachedResource(Frame*, const KURL&);
@@ -93,7 +93,7 @@
void getCookies(ErrorString*, RefPtr<InspectorArray>* cookies, WTF::String* cookiesString);
void deleteCookie(ErrorString*, const String& cookieName, const String& domain);
void getResourceTree(ErrorString*, RefPtr<InspectorObject>*);
- void getResourceContent(ErrorString*, const String& frameId, const String& url, const bool* const base64Encode, String* content);
+ void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded);
void searchInResources(ErrorString*, const String&, const bool* const caseSensitive, const bool* const isRegex, RefPtr<InspectorArray>*);
// InspectorInstrumentation API
Modified: trunk/Source/WebCore/inspector/InspectorResourceAgent.cpp (89367 => 89368)
--- trunk/Source/WebCore/inspector/InspectorResourceAgent.cpp 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/InspectorResourceAgent.cpp 2011-06-21 18:16:35 UTC (rev 89368)
@@ -434,7 +434,7 @@
m_mockFrontend = adoptPtr(new InspectorFrontend::Network(m_inspectorFrontendProxy.get()));
}
-void InspectorResourceAgent::getResourceContent(ErrorString* errorString, unsigned long identifier, const bool* const optionalBase64Encode, String* content)
+void InspectorResourceAgent::getResourceContent(ErrorString* errorString, unsigned long identifier, String* content, bool* base64Encoded)
{
NetworkResourcesData::ResourceData* resourceData = m_resourcesData->data(identifier);
if (!resourceData) {
@@ -442,20 +442,20 @@
return;
}
- bool base64Encode = optionalBase64Encode ? *optionalBase64Encode : false;
-
if (resourceData->hasContent()) {
+ *base64Encoded = false;
*content = resourceData->content();
return;
}
if (resourceData->buffer() && !resourceData->textEncodingName().isNull()) {
- if (InspectorPageAgent::sharedBufferContent(resourceData->buffer(), resourceData->textEncodingName(), base64Encode, content))
+ *base64Encoded = false;
+ if (InspectorPageAgent::sharedBufferContent(resourceData->buffer(), resourceData->textEncodingName(), *base64Encoded, content))
return;
}
if (resourceData->cachedResource()) {
- if (InspectorPageAgent::cachedResourceContent(resourceData->cachedResource(), base64Encode, content))
+ if (InspectorPageAgent::cachedResourceContent(resourceData->cachedResource(), content, base64Encoded))
return;
}
Modified: trunk/Source/WebCore/inspector/InspectorResourceAgent.h (89367 => 89368)
--- trunk/Source/WebCore/inspector/InspectorResourceAgent.h 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/InspectorResourceAgent.h 2011-06-21 18:16:35 UTC (rev 89368)
@@ -118,7 +118,7 @@
void disable(ErrorString*);
void setUserAgentOverride(ErrorString*, const String& userAgent);
void setExtraHeaders(ErrorString*, PassRefPtr<InspectorObject>);
- void getResourceContent(ErrorString*, unsigned long identifier, const bool* const base64Encode, String* content);
+ void getResourceContent(ErrorString*, unsigned long identifier, String* content, bool* base64Encoded);
void clearCache(ErrorString*, const String* const optionalPreservedLoaderId);
private:
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (89367 => 89368)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2011-06-21 18:16:35 UTC (rev 89368)
@@ -1069,8 +1069,9 @@
return false;
String error;
- InspectorPageAgent::resourceContent(&error, ownerDocument()->frame(), m_pageStyleSheet->finalURL(), false, result);
- return error.isEmpty();
+ bool base64Encoded;
+ InspectorPageAgent::resourceContent(&error, ownerDocument()->frame(), m_pageStyleSheet->finalURL(), result, &base64Encoded);
+ return error.isEmpty() && !base64Encoded;
}
bool InspectorStyleSheet::inlineStyleSheetText(String* result) const
Modified: trunk/Source/WebCore/inspector/front-end/NetworkManager.js (89367 => 89368)
--- trunk/Source/WebCore/inspector/front-end/NetworkManager.js 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/front-end/NetworkManager.js 2011-06-21 18:16:35 UTC (rev 89368)
@@ -42,18 +42,18 @@
}
WebInspector.NetworkManager.prototype = {
- requestContent: function(resource, base64Encode, callback)
+ requestContent: function(resource, callback)
{
- function callbackWrapper(error, content)
+ function callbackWrapper(error, content, contentEncoded)
{
- callback(!error ? content : null);
+ callback(!error ? content : null, contentEncoded);
}
// FIXME: https://bugs.webkit.org/show_bug.cgi?id=61363 We should separate NetworkResource (NetworkPanel resource)
// from ResourceRevision (ResourcesPanel/ScriptsPanel resource) and request content accordingly.
if (resource.identifier)
- NetworkAgent.getResourceContent(resource.identifier, base64Encode, callbackWrapper);
+ NetworkAgent.getResourceContent(resource.identifier, callbackWrapper);
else
- PageAgent.getResourceContent(resource.frameId, resource.url, base64Encode, callbackWrapper);
+ PageAgent.getResourceContent(resource.frameId, resource.url, callbackWrapper);
},
inflightResourceForURL: function(url)
Modified: trunk/Source/WebCore/inspector/front-end/Resource.js (89367 => 89368)
--- trunk/Source/WebCore/inspector/front-end/Resource.js 2011-06-21 18:14:12 UTC (rev 89367)
+++ trunk/Source/WebCore/inspector/front-end/Resource.js 2011-06-21 18:16:35 UTC (rev 89368)
@@ -912,10 +912,10 @@
if (this._contentRequested)
return;
this._contentRequested = true;
- this._contentEncoded = !WebInspector.Resource.Type.isTextType(this.type);
- function onResourceContent(data)
+ function onResourceContent(data, contentEncoded)
{
+ this._contentEncoded = contentEncoded;
this._content = data;
this._originalContent = data;
var callbacks = this._pendingContentCallbacks.slice();
@@ -924,7 +924,7 @@
this._pendingContentCallbacks.length = 0;
delete this._contentRequested;
}
- WebInspector.networkManager.requestContent(this, this._contentEncoded, onResourceContent.bind(this));
+ WebInspector.networkManager.requestContent(this, onResourceContent.bind(this));
}
}