2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-08-29 23:31:46 -07:00
|
|
|
|
|
|
|
const LAST_URL_PREF = "general.open_location.last_url";
|
|
|
|
const nsISupportsString = Components.interfaces.nsISupportsString;
|
2012-06-27 14:41:24 -07:00
|
|
|
const Ci = Components.interfaces;
|
2009-08-29 23:31:46 -07:00
|
|
|
|
2012-10-05 16:25:52 -07:00
|
|
|
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = [ "OpenLocationLastURL" ];
|
2009-08-29 23:31:46 -07:00
|
|
|
|
|
|
|
let prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2012-06-27 14:41:24 -07:00
|
|
|
let gOpenLocationLastURLData = "";
|
2009-08-29 23:31:46 -07:00
|
|
|
|
|
|
|
let observer = {
|
|
|
|
QueryInterface: function (aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIObserver) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupportsWeakReference))
|
|
|
|
return this;
|
|
|
|
throw Components.results.NS_NOINTERFACE;
|
|
|
|
},
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
2009-11-16 17:14:28 -08:00
|
|
|
switch (aTopic) {
|
2012-06-27 14:41:24 -07:00
|
|
|
case "last-pb-context-exited":
|
2009-11-16 17:14:28 -08:00
|
|
|
gOpenLocationLastURLData = "";
|
|
|
|
break;
|
|
|
|
case "browser:purge-session-history":
|
2012-06-27 14:41:24 -07:00
|
|
|
prefSvc.clearUserPref(LAST_URL_PREF);
|
|
|
|
gOpenLocationLastURLData = "";
|
2009-11-16 17:14:28 -08:00
|
|
|
break;
|
|
|
|
}
|
2009-08-29 23:31:46 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-16 17:14:28 -08:00
|
|
|
let os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
2012-06-27 14:41:24 -07:00
|
|
|
os.addObserver(observer, "last-pb-context-exited", true);
|
2009-11-16 17:14:28 -08:00
|
|
|
os.addObserver(observer, "browser:purge-session-history", true);
|
2009-08-29 23:31:46 -07:00
|
|
|
|
2012-06-27 14:41:24 -07:00
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.OpenLocationLastURL = function OpenLocationLastURL(aWindow) {
|
2012-06-27 14:41:24 -07:00
|
|
|
this.window = aWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenLocationLastURL.prototype = {
|
|
|
|
isPrivate: function OpenLocationLastURL_isPrivate() {
|
|
|
|
// Assume not in private browsing mode, unless the browser window is
|
|
|
|
// in private mode.
|
2012-10-05 16:25:52 -07:00
|
|
|
if (!this.window)
|
2012-06-27 14:41:24 -07:00
|
|
|
return false;
|
2012-10-05 16:25:52 -07:00
|
|
|
|
|
|
|
return PrivateBrowsingUtils.isWindowPrivate(this.window);
|
2012-06-27 14:41:24 -07:00
|
|
|
},
|
2009-08-29 23:31:46 -07:00
|
|
|
get value() {
|
2012-06-27 14:41:24 -07:00
|
|
|
if (this.isPrivate())
|
2009-08-29 23:31:46 -07:00
|
|
|
return gOpenLocationLastURLData;
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
return prefSvc.getComplexValue(LAST_URL_PREF, nsISupportsString).data;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set value(val) {
|
|
|
|
if (typeof val != "string")
|
|
|
|
val = "";
|
2012-06-27 14:41:24 -07:00
|
|
|
if (this.isPrivate())
|
2009-08-29 23:31:46 -07:00
|
|
|
gOpenLocationLastURLData = val;
|
|
|
|
else {
|
|
|
|
let str = Components.classes["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsString);
|
|
|
|
str.data = val;
|
|
|
|
prefSvc.setComplexValue(LAST_URL_PREF, nsISupportsString, str);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
reset: function() {
|
2011-04-17 12:53:25 -07:00
|
|
|
prefSvc.clearUserPref(LAST_URL_PREF);
|
2009-08-29 23:31:46 -07:00
|
|
|
gOpenLocationLastURLData = "";
|
|
|
|
}
|
|
|
|
};
|