Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1983)

Unified Diff: Source/devtools/front_end/common/ResourceType.js

Issue 1264133002: Devtools: [WIP] Implement enhanced devtools extension language APIs Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Small cleanups - prefer URIs to contentURLs, revert protocol unifications, remove lambdas Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/cm/simple.js ('k') | Source/devtools/front_end/common/TextUtils.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..9a9480f9ce12a788fcde7986ef5ea5c824886920 100644
--- a/Source/devtools/front_end/common/ResourceType.js
+++ b/Source/devtools/front_end/common/ResourceType.js
@@ -136,7 +136,41 @@ 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)
+{
+ var name = WebInspector.TextUtils.fileName(url);
+ if (WebInspector.ResourceType.mimeTypeByName[name]) {
+ return WebInspector.ResourceType.mimeTypeByName[name];
+ }
+ var ext = WebInspector.TextUtils.extension(url).toLowerCase();
+ return WebInspector.ResourceType.mimeTypeByExtension[ext];
+}
+
+/**
+ * @param {string} extensionOrName
+ * @param {string} mime
+ * @param {boolean=} byName
+ */
+WebInspector.ResourceType.newMimeType = function(extensionOrName, mime, byName)
+{
+ var matches = WebInspector.ResourceType.mimeTypeByExtension;
+ if (byName) {
+ matches = WebInspector.ResourceType.mimeTypeByName;
+ }
+
+ matches[extensionOrName] = mime;
+}
+
+WebInspector.ResourceType.mimeTypeByName = {
+ // CoffeeScript
+ "Cakefile": "text/x-coffeescript"
+}
+
+WebInspector.ResourceType.mimeTypeByExtension = {
// Web extensions
"js": "text/javascript",
"css": "text/css",
@@ -166,6 +200,7 @@ WebInspector.ResourceType.mimeTypesForExtensions = {
// TypeScript
"ts": "text/typescript",
+ "tsx": "text/typescript",
// JSON
"json": "application/json",
@@ -197,3 +232,20 @@ 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().uri());
+ } catch (e) {
+ return "text/javascript";
+ }
+ } else {
+ return "text/javascript";
+ }
+}
« no previous file with comments | « Source/devtools/front_end/cm/simple.js ('k') | Source/devtools/front_end/common/TextUtils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698