23:09 MIME-Type を得る

nsIMIMEService

getFromTypeAndExtension(/*string*/aMimeType,/*string*/aFileExt)
return nsIMIMEInfo
getPrimaryExtension(/*string*/aMIMEType,/*string*/aFileExt)
return mimeTypeString
getTypeFromExtension(/*string*/aFileExt)
return mimeTypeString
getTypeFromFile(/*nsIFile*/aFile)
なんか使えない
getTypeFromURI(/*nsIURI*/ aURI)
return mimeTypeString

Example

var fileName = "foo.tar.gz";
var mts = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
var mimeType = mts.getFileFromExtension(fileName);
// "application/x-compressed-tar"
var mimeInfo = mts.getFromTypeAndExtension(mimeType, fileName);
/*
[xpconnect wrapped nsIMIMEInfo]::
MIMEType: "[xpconnect wrapped nsimimeservice]"
QueryInterface: function QueryInterface() { ... }
alwaysAsk: 1
alwaysAskBeforeHandling: true
appendExtension: function appendExtension() { ... }
defaultDescription: "平文テキストドキュメント"
description: "平文テキストドキュメント"
equals: function equals() { ... }
extensionExists: function extensionExists() { ... }
getFileExtensions: function getFileExtensions() { ... }
handleInternally: 3
hasDefaultHandler: false
launchWithFile: function launchWithFile() { ... }
launchWithURI: function launchWithURI() { ... }
macCreator: <no value>
macType: <no value>
possibleApplicationHandlers: [xpconnect wrapped nsIMutableArray]
possibleLocalHandlers: <no value>
preferredAction: 4
preferredApplicationHandler: null
primaryExtension: <no value>
saveToDisk: 0
setFileExtensions: function setFileExtensions() { ... }
type: "[xpconnect wrapped nsimimeservice]"
useHelperApp: 2
useSystemDefault: 4
*/

13:21 HTML DocumentFragmentの生成

var htmlString = "<p>hoge<br>hoge</p>";
var rootElm = document.createElementNS("http://www.w3.org/1999/xhtml","div");
var uhService = Cc["@mozilla.org/feed-unescapehtml;1"]
                    .getService(Ci.nsIScriptableUnescapeHTML);
var htmlFragment = uhService.parseFragment(htmlString, false, null, rootElm); //DocumentFragment

12:09 Firefox3 OpenSearchのsuggest機能

const Cc = Components.classes;
const Ci = Components.interfaces;
const responseType = 'application/x-suggestion+json';
var searchWord = 'hogehoge'
var ss = Cc['@mozilla.org/browser/search-searvice;1']
         .getService(Ci.nsIBrowserSearchService);
var googleSE = ss.getEngineByAlias('google'); //nsISearchEngine
if (googleSE.supportsResponseType(responseType)) {
    var submission = googleSE.getSubmission(searchWord, responseType); //nsISearchSubmission
    var uri = submission.uri; //nsIURI
    var uri_spec = uri.asciiSpec; //'http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=ja&qu=hogehoge
    // ....;
}

06:32 XPCOM OS のシステム情報を得る

Class
@mozilla.org/system-info;1
Interface
nsIPropertyBag2
const Cc = Components.classes;
const Ci = Components.interfaces;
var sysInfo = Cc['@mozilla.org/system-info;1'].getService(Ci.nsIPropertyBag2);
var pratform = sysInfo.getProperty('name');

Properties and Example

  • name
    • Windows_NT
    • Mac OS X
    • Linux
  • version
    • 5.1
  • arch
    • x86
  • host
    • femo

06:01 XPCOM OS の環境変数を得る/設定する

Class
@mozilla.org/process/environment;1
Interface
nsIEnvironment
const Cc = Components.classes;
const Ci = Components.interfaces;
var env = Cc['@mozilla.org/process/environment;1'].getService(Ci.nsIEnvironment);
var path = env.get('path');

Method

Boolean exists (String aName)
Check the existence of an environment variable.
環境変数が存在するかどうか判定する
String get (String aName)
returns the value of the env varible. An empty string will be returned when hte env variable dose not exist or when the value itself is an empty string - please use exists() to probe whether the env variable exists or not.
環境変数の値を返す。環境変数が存在しない、または、空文字列の場合、空文字列が返る。exists()メソッドを使って事前に判定してください。
String set (String aName, String aValue)
Set the value of an environment variable.
環境変数を設定する

< 1 2 3 >