Index: Source/devtools/front_end/common/ResourceType.js |
diff --git a/Source/devtools/front_end/common/ResourceType.js b/Source/devtools/front_end/common/ResourceType.js |
index 88ec23b8698646a6bf537be5dd7353925e637e67..7b002727d23b563e8ad89c46746241d7cfc7a6e6 100644 |
--- a/Source/devtools/front_end/common/ResourceType.js |
+++ b/Source/devtools/front_end/common/ResourceType.js |
@@ -136,7 +136,39 @@ WebInspector.resourceTypes = { |
Other: new WebInspector.ResourceType("other", "Other", "Other", "Other", "rgb(186,186,186)", false) |
} |
-WebInspector.ResourceType.mimeTypesForExtensions = { |
+/** |
+ * @param {string} url |
+ * @return {string} |
+ */ |
+WebInspector.ResourceType.mimeFromUrl = function(url) { |
pfeldman
2015/08/13 21:15:46
mimeFromURL would be all caps
we place { on the ne
wes
2015/08/14 00:55:04
Acknowledged.
|
+ var name = WebInspector.TextUtils.fileName(url); |
+ if (WebInspector.ResourceType.mimeTypeNameMatches[name]) { |
+ return WebInspector.ResourceType.mimeTypeNameMatches[name]; |
+ } |
+ var ext = WebInspector.TextUtils.extension(url).toLowerCase(); |
+ return WebInspector.ResourceType.mimeTypeExtensionMatches[ext]; |
+} |
+ |
+/** |
+ * @param {string} match |
+ * @param {string} mime |
+ * @param {boolean=} matchName |
+ */ |
+WebInspector.ResourceType.registerMimeRecognizer = function(match, mime, matchName) { |
pfeldman
2015/08/13 21:15:46
This signature and the method logic are very confu
wes
2015/08/14 00:55:04
Does it need better argument names? Ie:
+/**
+ *
pfeldman
2015/08/17 21:15:51
Well, registerRecognizer suggests that it'll be a
|
+ var matches = WebInspector.ResourceType.mimeTypeExtensionMatches; |
+ if (matchName) { |
+ matches = WebInspector.ResourceType.mimeTypeNameMatches; |
+ } |
+ |
+ matches[match] = mime; |
+} |
+ |
+WebInspector.ResourceType.mimeTypeNameMatches = { |
+ // CoffeeScript |
+ "Cakefile": "text/x-coffeescript" |
+} |
+ |
+WebInspector.ResourceType.mimeTypeExtensionMatches = { |
// Web extensions |
"js": "text/javascript", |
"css": "text/css", |
@@ -166,6 +198,7 @@ WebInspector.ResourceType.mimeTypesForExtensions = { |
// TypeScript |
"ts": "text/typescript", |
+ "tsx": "text/typescript", |
// JSON |
"json": "application/json", |
@@ -197,3 +230,19 @@ WebInspector.ResourceType.mimeTypesForExtensions = { |
// Video Text Tracks. |
"vtt": "text/vtt" |
} |
+ |
+/** |
+ * @return {string} |
+ * @suppress {missingProperties} |
+ */ |
+WebInspector.ResourceType.fromActivePanel = function() { |
+ if (self.runtime.moduleIsLoaded("sources")) { |
+ try { |
+ return WebInspector.ResourceType.mimeFromUrl(WebInspector.SourcesPanel.instance().sourcesView().currentUISourceCode().contentURL()); |
pfeldman
2015/08/13 21:15:46
You should never reach out to the module you don't
wes
2015/08/14 00:55:04
I mean, it does compile (and run) thanks to the
*
wes
2015/08/14 01:25:50
But if I did that then the module the extension wa
pfeldman
2015/08/17 21:15:51
We have plenty of DI and context to handle this. Y
wes
2015/08/25 18:13:18
But... the contexts in which we'd like to know thi
|
+ } catch (e) { |
+ return "text/javascript"; |
+ } |
+ } else { |
+ return "text/javascript"; |
+ } |
+} |