root / src / pithos / content / moz.js @ 46:f16f6e0e5b69
History | View | Annotate | Download (4 kB)
1 |
// The Pithos File Manager Firefox Extension is funded by GRNET S.A.
|
---|---|
2 |
// (http://www.grnet.gr)
|
3 |
//
|
4 |
// Copyright (c) 2009, Christos KK Loverdos, Vassilios Karakoidas.
|
5 |
// All rights reserved.
|
6 |
//
|
7 |
// Redistribution and use in source and binary forms, with or without
|
8 |
// modification, are permitted provided that the following conditions are
|
9 |
// met:
|
10 |
//
|
11 |
// - Redistributions of source code must retain the above copyright
|
12 |
// notice, this list of conditions and the following disclaimer.
|
13 |
// - Redistributions in binary form must reproduce the above
|
14 |
// copyright notice, this list of conditions and the following
|
15 |
// disclaimer in the documentation and/or other materials provided
|
16 |
// with the distribution.
|
17 |
// - Neither the name of GRNET S.A. nor the names of its contributors
|
18 |
// may be used to endorse or promote products derived from this
|
19 |
// software without specific prior written permission.
|
20 |
//
|
21 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25 |
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
27 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
28 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
29 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
30 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
31 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
33 |
// Provides a handful of utilities related to Mozilla internal API
|
34 |
|
35 |
function Mozilla() { |
36 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
37 |
var mozThis = this; |
38 |
|
39 |
this.classes = Components.classes;
|
40 |
this.interfaces = Components.interfaces;
|
41 |
|
42 |
this.newComponent = function(name, interf) { |
43 |
return this.classes[name].createInstance(interf); |
44 |
} |
45 |
|
46 |
// Just for convenience
|
47 |
this.getComponent = this.newComponent; |
48 |
|
49 |
this.getService = function(name, interf) { |
50 |
return this.classes[name].getService(interf); |
51 |
} |
52 |
|
53 |
this.getConsoleService = function() { |
54 |
return this.getService('@mozilla.org/consoleservice;1', this.interfaces.nsIConsoleService); |
55 |
} |
56 |
|
57 |
this.windowMediator = this.getService("@mozilla.org/appshell/window-mediator;1", this.interfaces.nsIWindowMediator); |
58 |
this.mainWindow = this.windowMediator.getMostRecentWindow("navigator:browser"); |
59 |
this.mainWindowBrowser = this.mainWindow.getBrowser(); |
60 |
|
61 |
this.newBrowserTab = function(label, url, activate) { |
62 |
var browser = this.mainWindowBrowser; |
63 |
var tab = browser.addTab(url);
|
64 |
tab.label = label; |
65 |
if (activate) {
|
66 |
browser.selectedTab = tab; |
67 |
//browser.focus();
|
68 |
} |
69 |
setTimeout( function() {
|
70 |
browser.setIcon(tab, "chrome://pithos/skin/pithos.png");
|
71 |
}, 500);
|
72 |
return tab;
|
73 |
} |
74 |
|
75 |
this.newLocalFile = function(path) { |
76 |
var file = this.newComponent("@mozilla.org/file/local;1", this.interfaces.nsILocalFile); |
77 |
if (path != undefined) { |
78 |
file.initWithPath(path) |
79 |
} |
80 |
return file;
|
81 |
} |
82 |
|
83 |
this.getCookieManager = function() { |
84 |
return this.getService("@mozilla.org/cookiemanager;1", this.interfaces.nsICookieManager); |
85 |
} |
86 |
|
87 |
this.findCookieByHostAndName = function(host, name) { |
88 |
var menum = this.getCookieManager().enumerator; |
89 |
|
90 |
while (menum.hasMoreElements()) {
|
91 |
var cookie = menum.getNext().QueryInterface(Components.interfaces.nsICookie);
|
92 |
if ( (cookie.host == host) && (cookie.name == name) ) {
|
93 |
return cookie;
|
94 |
} |
95 |
} |
96 |
|
97 |
return undefined; |
98 |
} |
99 |
|
100 |
this.hasCookieByHostAndName = function(host, name) { |
101 |
return this.findCookieByHostAndName(host, name) != undefined; |
102 |
} |
103 |
|
104 |
this.log = function() { |
105 |
try {
|
106 |
var console = this.getConsoleService(); |
107 |
var buf = ''; |
108 |
for(var i=0; i<arguments.length; i++) { |
109 |
buf += arguments[i];
|
110 |
} |
111 |
console.logStringMessage(buf); |
112 |
} catch(error) {
|
113 |
// no big deal if this fails
|
114 |
} |
115 |
} |
116 |
} |
117 |
|
118 |
moz = new Mozilla();
|