Use the name in the returned CoontentObject to get the MIME type and make getContentTypeAndCharset scan the components.
diff --git a/js/ccnxProtocol/components/ccnxProtocolService.js b/js/ccnxProtocol/components/ccnxProtocolService.js
index b77d5c6..12da336 100644
--- a/js/ccnxProtocol/components/ccnxProtocolService.js
+++ b/js/ccnxProtocol/components/ccnxProtocolService.js
@@ -39,7 +39,13 @@
var mostRecentWindow = wm.getMostRecentWindow("navigator:browser");
var requestContent = function(contentListener) {
- var name = aURI.spec.split(":")[1];
+ // Set nameString to the URI without the protocol.
+ var nameString = aURI.spec;
+ var colonIndex = nameString.indexOf(':');
+ if (colonIndex >= 0)
+ nameString = nameString.substr(colonIndex + 1, nameString.length - colonIndex - 1);
+
+ var name = new Name(nameString);
// 131.179.141.18 is lioncub.metwi.ucla.edu .
var ndn = new NDN('131.179.141.18');
@@ -60,20 +66,18 @@
}
var content = DataUtils.toString(contentObject.content);
- // TODO: Should look at the returned Name to get contentType. For now,
- // just look at the original name.
- var contentTypeAndCharset = getContentTypeAndCharset(name);
+ var contentTypeEtc = getContentTypeAndCharset(contentObject.name);
contentListener.onReceivedContent(content,
- contentTypeAndCharset.contentType, contentTypeAndCharset.contentCharset);
+ contentTypeEtc.contentType, contentTypeEtc.contentCharset);
// Assume that onReceivedContent sends all the content immediately and that
- // the URLBar is updated if the content is for the main window.
+ // the gURLBar is updated if the content is for the main window.
var urlBar = mostRecentWindow.gURLBar;
return Closure.RESULT_OK;
};
- ndn.expressInterest(new Name(name), new ContentClosure());
+ ndn.expressInterest(name, new ContentClosure());
};
return new ContentChannel(aURI, requestContent);
@@ -94,36 +98,34 @@
var NSGetModule = XPCOMUtils.generateNSGetModule([CcnxProtocol]);
/*
- * Based on name, return and object with properties contentType and charset.
+ * Scan the name from the last component to the first (skipping special CCNx components)
+ * for a recognized file name extension, and return an object with properties contentType and charset.
*/
function getContentTypeAndCharset(name) {
- // Set up defaults.
- var contentType = "text/html";
- var charset = "utf-8";
-
- var nameLowerCase = name.toLowerCase();
- if (nameLowerCase.indexOf(".gif") >= 0) {
- contentType = "image/gif";
- charset = "ISO-8859-1";
- }
- else if (nameLowerCase.indexOf(".jpg") >= 0 ||
- nameLowerCase.indexOf(".jpeg") >= 0) {
- contentType = "image/jpeg";
- charset = "ISO-8859-1";
- }
- else if (nameLowerCase.indexOf(".png") >= 0) {
- contentType = "image/png";
- charset = "ISO-8859-1";
- }
- else if (nameLowerCase.indexOf(".bmp") >= 0) {
- contentType = "image/bmp";
- charset = "ISO-8859-1";
- }
- else if (nameLowerCase.indexOf(".css") >= 0)
- contentType = "text/css";
+ for (var i = name.components.length - 1; i >= 0; --i) {
+ var component = name.components[i];
+ if (component.length <= 0)
+ continue;
+
+ // Skip special components which just may have ".gif", etc.
+ if (component[0] == 0 || component[0] == 0xC0 || component[0] == 0xC1 ||
+ (component[0] >= 0xF5 && component[0] <= 0xFF))
+ continue;
+
+ var str = DataUtils.toString(component).toLowerCase();
+ if (str.indexOf(".gif") >= 0)
+ return { contentType: "image/gif", charset: "ISO-8859-1" }
+ else if (str.indexOf(".jpg") >= 0 ||
+ str.indexOf(".jpeg") >= 0)
+ return { contentType: "image/jpeg", charset: "ISO-8859-1" }
+ else if (str.indexOf(".png") >= 0)
+ return { contentType: "image/png", charset: "ISO-8859-1" }
+ else if (str.indexOf(".bmp") >= 0)
+ return { contentType: "image/bmp", charset: "ISO-8859-1" }
+ else if (str.indexOf(".css") >= 0)
+ return { contentType: "text/css", charset: "utf-8" }
+ }
- return {
- contentType: contentType,
- charset: charset
- };
+ // default
+ return { contentType: "text/html", charset: "utf-8" };
}