1
function getOriginFromUri(uri) {
2
var parts = uri.split("://", 2);
3
if (parts[0] == "file") {
4
// Local file URI, we just trim it to directory in which the file is
5
return uri.substring(0, uri.lastIndexOf('/') + 1);
7
// HTTP(S), FTP or any other URI, we only take up to the domain name
8
return parts[0] + "://" + parts[1].split("/")[0] + "/";
12
function getManifestationFromUri(uri) {
13
var parts = uri.split("://", 2);
14
if (parts[0] == "file") {
15
return "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#FileDataObject";
16
} else if (parts[0] == "http" || parts[0] == "https") {
17
return "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#WebDataObject";
19
// May be FTP or something else
20
return "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#RemoteDataObject";
25
function isDebugEnabled() {
26
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
27
.getService(Components.interfaces.nsIPrefBranch);
28
return prefs.getBoolPref("extensions.zeitgeist.log");
32
function isPrivateBrowsing() {
33
var pbs = Components.classes["@mozilla.org/privatebrowsing;1"]
34
.getService(Components.interfaces.nsIPrivateBrowsingService);
35
return pbs.privateBrowsingEnabled;
1
38
var ZeitgeistProgressListener = {
2
39
onStateChange: function(aBrowser, aProgress, aRequest, aStateFlags) {
4
//Don't do anything if Private Browsing is enabled
5
var pbs = Components.classes["@mozilla.org/privatebrowsing;1"]
6
.getService(Components.interfaces.nsIPrivateBrowsingService);
7
if (pbs.privateBrowsingEnabled) return;
40
// Don't do anything if Private Browsing is enabled
41
if (isPrivateBrowsing()) return;
9
43
if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) {
10
44
let uri = aBrowser.currentURI.spec;
11
//Ignore pages without titles (generally redirect pages)
45
// Ignore pages without titles (generally redirect pages)
12
46
if (aBrowser.contentTitle == "") return;
14
48
let mimetype = aBrowser.contentDocument.contentType;
15
49
if (aRequest.name == uri && !this.ignore_uri(uri)) {
17
var parts = uri.split("://", 2);
18
if (parts[0] == "file") {
19
// Local file URI, we just trim it to directory in which the file is
20
origin = uri.substring(0, uri.lastIndexOf('/') + 1);
22
// HTTP(S), FTP or any other URI, we only take up to the domain name
23
origin = parts[0] + "://" + parts[1].split("/")[0] + "/";
26
let subject = libzeitgeist.zeitgeist_subject_new_full( uri,
50
let origin = getOriginFromUri(uri);
51
let subject_manifestation = getManifestationFromUri(uri);
53
let subject = libzeitgeist.zeitgeist_subject_new_full(uri,
27
54
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Website",
28
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#RemoteDataObject",
55
subject_manifestation,
31
58
aBrowser.contentTitle,
40
67
libzeitgeist.zeitgeist_log_insert_events_no_reply(libzeitgeist.log, event, null);
42
//Log event in Firefox's error console if logging pref is true
43
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
44
.getService(Components.interfaces.nsIPrefBranch);
45
if (prefs.getBoolPref("extensions.zeitgeist.log")) {
70
if (isDebugEnabled()) {
46
71
zeitgeist.debug("Event added to zeitgeist:" +
47
72
"\n\t\tevent interpretation: EVENT_INTERPRETATION.ACCESS_EVENT" +
48
73
"\n\t\tEvent manifestation: EVENT_MANIFESTATION.USER_ACTIVITY" +
129
var ZeitgeistDownloadManagerListener = {
130
onDownloadStateChange: function(state, dl) {
131
// FIXME: DOWNLOAD_FINISHED would probably be more awesome, but
132
// it doesn't seem to be sent correctly :(
133
if (state != 0 /*DOWNLOAD_DOWNLOADING*/) return;
134
if (isPrivateBrowsing()) return;
136
let uri = 'file://' + dl.targetFile.path;
137
let subject = libzeitgeist.zeitgeist_subject_new_full(
139
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Website",
140
"", // empty manifestation, Bluebird Alpha 2+ will figure it out
141
"", // FIXME: not working: dl.MIMEInfo.type
142
getOriginFromUri(uri),
144
"" // figure our storage (in case of saving to usb/sftp/etc)
147
// FIXME: libzeitgeist is missing event origin!
148
// FIXME: where do we put the original download URI? event origin
149
// is already supposed to be the page where you clicked
150
// the download link...
151
let event_ = libzeitgeist.zeitgeist_event_new_full(
152
"http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#CreateEvent",
153
"http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#UserActivity",
154
"application://firefox.desktop",
159
libzeitgeist.zeitgeist_log_insert_events_no_reply(libzeitgeist.log, event_, null);
162
onSecurityChange: function() {},
163
onProgressChange: function() {},
164
onStateChange: function() {}
103
167
var zeitgeist = {
104
168
init: function() {
105
169
ZeitgeistPrefObserver.register();
171
// Listen to tab changes
106
172
gBrowser.addTabsProgressListener(ZeitgeistProgressListener);
174
// Listen to downloads
175
var downloadManager = Components.classes["@mozilla.org/download-manager;1"]
176
.getService(Components.interfaces.nsIDownloadManager);
177
downloadManager.addListener(ZeitgeistDownloadManagerListener);
107
179
libzeitgeist.init();