- Revision
- 156209
- Author
- [email protected]
- Date
- 2013-09-20 16:45:22 -0700 (Fri, 20 Sep 2013)
Log Message
Parse MIME-types and strip them down to the base type when needed.
The use of charset in a MIME-type interferes with our type maps,
preventing the right syntax highlighting mode and pretty printing.
https://bugs.webkit.org/show_bug.cgi?id=121723
Reviewed by Joseph Pecoraro.
* UserInterface/ConsolePrompt.js:
(WebInspector.ConsolePrompt):
* UserInterface/FontResourceContentView.js:
* UserInterface/Resource.js:
(WebInspector.Resource.Type.fromMIMEType):
(WebInspector.Resource.prototype.get mimeTypeComponents):
(WebInspector.Resource.prototype.get syntheticMIMEType):
(WebInspector.Resource.prototype.get contentURL):
(WebInspector.Resource.prototype.updateForResponse):
* UserInterface/ResourceDetailsSidebarPanel.js:
(WebInspector.ResourceDetailsSidebarPanel.prototype._refreshRequestDataSection):
* UserInterface/SourceMapResource.js:
(WebInspector.SourceMapResource.prototype.requestContentFromBackend):
* UserInterface/SyntaxHighlightingSupport.js:
(WebInspector.syntaxHighlightStringAsDocumentFragment):
* UserInterface/TextEditor.js:
(WebInspector.TextEditor.prototype.set mimeType):
* UserInterface/Utilities.js:
(parseMIMEType): Added.
Modified Paths
Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (156208 => 156209)
--- trunk/Source/WebInspectorUI/ChangeLog 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/ChangeLog 2013-09-20 23:45:22 UTC (rev 156209)
@@ -1,3 +1,34 @@
+2013-09-20 Timothy Hatcher <[email protected]>
+
+ Parse MIME-types and strip them down to the base type when needed.
+
+ The use of charset in a MIME-type interferes with our type maps,
+ preventing the right syntax highlighting mode and pretty printing.
+
+ https://bugs.webkit.org/show_bug.cgi?id=121723
+
+ Reviewed by Joseph Pecoraro.
+
+ * UserInterface/ConsolePrompt.js:
+ (WebInspector.ConsolePrompt):
+ * UserInterface/FontResourceContentView.js:
+ * UserInterface/Resource.js:
+ (WebInspector.Resource.Type.fromMIMEType):
+ (WebInspector.Resource.prototype.get mimeTypeComponents):
+ (WebInspector.Resource.prototype.get syntheticMIMEType):
+ (WebInspector.Resource.prototype.get contentURL):
+ (WebInspector.Resource.prototype.updateForResponse):
+ * UserInterface/ResourceDetailsSidebarPanel.js:
+ (WebInspector.ResourceDetailsSidebarPanel.prototype._refreshRequestDataSection):
+ * UserInterface/SourceMapResource.js:
+ (WebInspector.SourceMapResource.prototype.requestContentFromBackend):
+ * UserInterface/SyntaxHighlightingSupport.js:
+ (WebInspector.syntaxHighlightStringAsDocumentFragment):
+ * UserInterface/TextEditor.js:
+ (WebInspector.TextEditor.prototype.set mimeType):
+ * UserInterface/Utilities.js:
+ (parseMIMEType): Added.
+
2013-09-20 Marcelo Morais <[email protected]>
Web Inspector: Fix keyboard shortcuts for other platforms
Modified: trunk/Source/WebInspectorUI/UserInterface/ConsolePrompt.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/ConsolePrompt.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/ConsolePrompt.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -27,6 +27,8 @@
{
WebInspector.Object.call(this);
+ mimeType = parseMIMEType(mimeType).type;
+
this._element = element || document.createElement("div");
this._element.classList.add(WebInspector.ConsolePrompt.StyleClassName);
this._element.classList.add(WebInspector.SyntaxHighlightedStyleClassName);
Modified: trunk/Source/WebInspectorUI/UserInterface/FontResourceContentView.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/FontResourceContentView.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/FontResourceContentView.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -80,7 +80,7 @@
var format = "";
// We need to specify a format when loading SVG fonts to make them work.
- if (this.resource.mimeType === "image/svg+xml")
+ if (this.resource.mimeTypeComponents.type === "image/svg+xml")
format = " format(\"svg\")";
if (this._styleElement && this._styleElement.parentNode)
Modified: trunk/Source/WebInspectorUI/UserInterface/Resource.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/Resource.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/Resource.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -126,6 +126,8 @@
if (!mimeType)
return WebInspector.Resource.Type.Other;
+ mimeType = parseMIMEType(mimeType).type;
+
if (mimeType in WebInspector.Resource.Type._mimeTypeMap)
return WebInspector.Resource.Type._mimeTypeMap[mimeType];
@@ -209,6 +211,13 @@
return this._mimeType;
},
+ get mimeTypeComponents()
+ {
+ if (!this._mimeTypeComponents)
+ this._mimeTypeComponents = parseMIMEType(this._mimeType);
+ return this._mimeTypeComponents;
+ },
+
get syntheticMIMEType()
{
// Resources are often transferred with a MIME-type that doesn't match the purpose the
@@ -243,7 +252,7 @@
if (content === null || content.length > maximumDataURLSize)
return this._url;
- return "data:" + this._mimeType + (this.contentIsBase64Encoded ? ";base64," + content : "," + encodeURIComponent(content));
+ return "data:" + this.mimeTypeComponents.type + (this.contentIsBase64Encoded ? ";base64," + content : "," + encodeURIComponent(content));
},
isMainResource: function()
@@ -498,8 +507,12 @@
this.dispatchEventToListeners(WebInspector.Resource.Event.URLDidChange, {oldURL: oldURL});
}
- if (oldMIMEType !== mimeType)
+ if (oldMIMEType !== mimeType) {
+ // Delete the MIME-type components so the MIME-type is re-parsed the next time it is requested.
+ delete this._mimeTypeComponents;
+
this.dispatchEventToListeners(WebInspector.Resource.Event.MIMETypeDidChange, {oldMIMEType: oldMIMEType});
+ }
if (oldType !== type)
this.dispatchEventToListeners(WebInspector.Resource.Event.TypeDidChange, {oldType: oldType});
Modified: trunk/Source/WebInspectorUI/UserInterface/ResourceDetailsSidebarPanel.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/ResourceDetailsSidebarPanel.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/ResourceDetailsSidebarPanel.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -427,24 +427,12 @@
// Not simple form data, so we can really only show the size and type here.
// FIXME: Add a go-to arrow here to show the data in the content browser.
- var typeParts = requestDataContentType.split(/\s*;\s*/);
- console.assert(typeParts.length >= 1);
+ var mimeTypeComponents = parseMIMEType(requestDataContentType);
- var mimeType = typeParts[0];
- var boundary = null;
- var encoding = null;
+ var mimeType = mimeTypeComponents.type;
+ var boundary = mimeTypeComponents.boundary;
+ var encoding = mimeTypeComponents.encoding;
- for (var i = 1; i < typeParts.length; ++i) {
- var subparts = typeParts[i].split(/\s*=\s*/);
- if (subparts.length !== 2)
- continue;
-
- if (subparts[0].toLowerCase() === "boundary")
- boundary = subparts[1];
- else if (subparts[0].toLowerCase() === "charset")
- encoding = subparts[1].replace("^\"|\"$", ""); // Trim quotes.
- }
-
var rows = [];
var mimeTypeRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("MIME Type"));
Modified: trunk/Source/WebInspectorUI/UserInterface/SourceMapResource.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/SourceMapResource.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/SourceMapResource.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -81,8 +81,12 @@
this._mimeType = mimeType;
this._type = WebInspector.Resource.Type.fromMIMEType(this._mimeType);
- if (oldMIMEType !== mimeType)
+ if (oldMIMEType !== mimeType) {
+ // Delete the MIME-type components so the MIME-type is re-parsed the next time it is requested.
+ delete this._mimeTypeComponents;
+
this.dispatchEventToListeners(WebInspector.Resource.Event.MIMETypeDidChange, {oldMIMEType: oldMIMEType});
+ }
if (oldType !== this._type)
this.dispatchEventToListeners(WebInspector.Resource.Event.TypeDidChange, {oldType: oldType});
Modified: trunk/Source/WebInspectorUI/UserInterface/SyntaxHighlightingSupport.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/SyntaxHighlightingSupport.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/SyntaxHighlightingSupport.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -43,6 +43,8 @@
resultFragment.appendChild(span);
}
+ mimeType = parseMIMEType(mimeType).type;
+
CodeMirror.runMode(string, mimeType, appendText);
return resultFragment;
Modified: trunk/Source/WebInspectorUI/UserInterface/TextEditor.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/TextEditor.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/TextEditor.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -218,6 +218,8 @@
set mimeType(newMIMEType)
{
+ newMIMEType = parseMIMEType(newMIMEType).type;
+
this._mimeType = newMIMEType;
this._codeMirror.setOption("mode", newMIMEType);
},
Modified: trunk/Source/WebInspectorUI/UserInterface/Utilities.js (156208 => 156209)
--- trunk/Source/WebInspectorUI/UserInterface/Utilities.js 2013-09-20 23:01:37 UTC (rev 156208)
+++ trunk/Source/WebInspectorUI/UserInterface/Utilities.js 2013-09-20 23:45:22 UTC (rev 156209)
@@ -1124,6 +1124,32 @@
return baseURLPrefix + resolveDotsInPath(basePath + partialURL);
}
+function parseMIMEType(fullMimeType)
+{
+ if (!fullMimeType)
+ return {type: fullMimeType, boundary: null, encoding: null};
+
+ var typeParts = fullMimeType.split(/\s*;\s*/);
+ console.assert(typeParts.length >= 1);
+
+ var type = typeParts[0];
+ var boundary = null;
+ var encoding = null;
+
+ for (var i = 1; i < typeParts.length; ++i) {
+ var subparts = typeParts[i].split(/\s*=\s*/);
+ if (subparts.length !== 2)
+ continue;
+
+ if (subparts[0].toLowerCase() === "boundary")
+ boundary = subparts[1];
+ else if (subparts[0].toLowerCase() === "charset")
+ encoding = subparts[1].replace("^\"|\"$", ""); // Trim quotes.
+ }
+
+ return {type: type, boundary: boundary || null, encoding: encoding || null};
+}
+
function simpleGlobStringToRegExp(globString, regExpFlags)
{
// Only supports "*" globs.