home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Minami 83
/
MINAMI83.iso
/
Extra
/
DivXInstaller.exe
/
$PLUGINSDIR
/
GoogleToolbarFirefox.msi
/
xpi
/
amulet-jslib
/
controller.js
< prev
next >
Wrap
Text File
|
2006-08-07
|
7KB
|
185 lines
function PROT_Controller(win,
tabWatcher,
listManager,
phishingWarden,
contentAnalyzer) {
this.debugZone = "controller";
this.win_ = win;
this.listManager_ = listManager;
this.phishingWarden_ = phishingWarden;
this.contentAnalyzer_ = contentAnalyzer;
this.prefs_ = new G_Preferences();
this.checkRemotePrefName_ = PROT_globalStore.getServerCheckEnabledPrefName();
this.checkRemote_ = this.prefs_.getPref(this.checkRemotePrefName_, null);
this.checkRemotePrefObserver = BindToObject(this.onCheckRemotePrefChanged,
this);
this.prefs_.addObserver(this.checkRemotePrefName_,
this.checkRemotePrefObserver);
this.phishWardenPrefName_ = PROT_globalStore.getPhishWardenEnabledPrefName();
this.phishWardenEnabled_ = this.prefs_.getPref(this.phishWardenPrefName_,
null);
this.phishWardenPrefObserver =
BindToObject(this.onPhishWardenEnabledPrefChanged, this);
this.prefs_.addObserver(this.phishWardenPrefName_,
this.phishWardenPrefObserver);
this.tabWatcher_ = tabWatcher;
this.onShutdown_ = BindToObject(this.shutdown, this);
this.win_.addEventListener("unload", this.onShutdown_, false);
this.onTabSwitchCallback_ = BindToObject(this.onTabSwitch, this);
this.tabWatcher_.registerListener("tabswitch",
this.onTabSwitchCallback_);
this.onLoadCallback_ = BindToObject(this.onLoad, this);
this.tabWatcher_.registerListener("domcontentloaded",
this.onLoadCallback_);
var commandHandlers = {
"amulet-show-warning" :
BindToObject(this.onUserShowWarning, this),
"amulet-accept-warning" :
BindToObject(this.onUserAcceptWarning, this),
"amulet-decline-warning" :
BindToObject(this.onUserDeclineWarning, this),
"amulet-submit-blacklist-urlbar" :
BindToObject(this.onUserSubmitToBlacklist, this),
"amulet-preferences" :
BindToObject(this.onUserPreferences, this),
"amulet-test-link" :
BindToObject(this.showURL_, this, PROT_globalStore.getLocalizedTestURL()),
"amulet-preferences-home-link":
BindToObject(this.showURL_, this, PROT_globalStore.getHomePageURL()),
"amulet-preferences-policy-link":
BindToObject(this.showURL_, this, PROT_globalStore.getPolicyURL()),
"amulet-preferences-home-link-nochrome":
BindToObject(this.showURL_, this, PROT_globalStore.getHomePageURL(),
true /* chromeless */),
"amulet-preferences-policy-link-nochrome":
BindToObject(this.showURL_, this, PROT_globalStore.getPolicyURL(),
true /* chromeless */),
};
this.commandController_ = new PROT_CommandController(commandHandlers);
this.win_.controllers.appendController(this.commandController_);
this.browserView_ = new PROT_BrowserView(this.tabWatcher_,
this.win_.document);
this.phishingWarden_.addBrowserView(this.browserView_);
this.windowWatcher_ =
Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
G_Debug(this, "Controller initialized.");
}
PROT_Controller.prototype.shutdown = function(e) {
G_Debug(this, "Browser window closing. Shutting controller down.");
this.phishingWarden_.removeBrowserView(this.browserView_);
this.win_.controllers.removeController(this.commandController_);
this.commandController_ = null;
this.browserView_ = null;
this.prefs_.removeObserver(this.checkRemotePrefName_,
this.checkRemotePrefObserver);
this.prefs_.removeObserver(this.phishWardenPrefName_,
this.phishWardenPrefObserver);
this.tabWatcher_.removeListener("load",
this.onLoadCallback_);
this.tabWatcher_.removeListener("tabswitch",
this.onTabSwitchCallback_);
this.win_.removeEventListener("unload", this.onShutdown_, false);
this.prefs_ = null;
this.windowWatcher_ = null;
G_Debug(this, "Controller shut down.");
}
PROT_Controller.prototype.onCheckRemotePrefChanged = function(prefName) {
this.checkRemote_ = this.prefs_.getBoolPrefOrDefault(prefName,
this.checkRemote_);
}
PROT_Controller.prototype.onPhishWardenEnabledPrefChanged = function(
prefName) {
this.phishWardenEnabled_ =
this.prefs_.getBoolPrefOrDefault(prefName, this.phishWardenEnabled_);
}
PROT_Controller.prototype.onUserShowWarning = function() {
var browser = this.tabWatcher_.getCurrentBrowser();
this.browserView_.explicitShow(browser);
}
PROT_Controller.prototype.onUserPreferences = function() {
G_Debug(this, "User wants preferences.");
var features = "chrome,titlebar,toolbar,centerscreen,modal";
this.windowWatcher_.openWindow(
this.win_,
"chrome://amulet-of-protection/content/protection-preferences.xul",
"amulet-prefs-dialog",
features,
null /* args */);
return true;
}
PROT_Controller.prototype.showURL_ = function(url, opt_chromeless) {
var features = opt_chromeless ? "status,scrollbars=yes,resizable=yes" : null;
this.windowWatcher_.openWindow(this.win_,
url,
"_blank",
features,
null);
}
PROT_Controller.prototype.onUserSubmitToBlacklist = function() {
var current_window = this.tabWatcher_.getCurrentWindow();
var badUrl = current_window.location.href;
G_Debug(this, "User wants to submit to blacklist: " + badUrl);
var url = PROT_globalStore.getSubmitUrl();
url.query += "&url=" + encodeURIComponent(badUrl);
this.windowWatcher_.openWindow(
this.windowWatcher_.activeWindow /* parent */,
url.asciiSpec,
"_blank",
"height=400em,width=800,scrollbars=yes,resizable=yes," +
"menubar,toolbar,location,directories,personalbar,status",
null /* args */);
return true;
}
PROT_Controller.prototype.onUserAcceptWarning = function() {
G_Debug(this, "User accepted warning.");
var browser = this.tabWatcher_.getCurrentBrowser();
G_Assert(this, !!browser, "Couldn't get current browser?!?");
G_Assert(this, this.browserView_.hasProblem(browser),
"User accept fired, but browser doesn't have warning showing?!?");
this.browserView_.acceptAction(browser);
this.browserView_.problemResolved(browser);
}
PROT_Controller.prototype.onUserDeclineWarning = function() {
G_Debug(this, "User declined warning.");
var browser = this.tabWatcher_.getCurrentBrowser();
G_Assert(this, this.browserView_.hasProblem(browser),
"User decline fired, but browser doesn't have warning showing?!?");
this.browserView_.declineAction(browser);
}
PROT_Controller.prototype.onTabSwitch = function(e) {
if (this.browserView_.hasProblem(e.fromBrowser))
this.browserView_.problemBrowserUnselected(e.fromBrowser);
if (this.browserView_.hasProblem(e.toBrowser))
this.browserView_.problemBrowserSelected(e.toBrowser);
}
PROT_Controller.prototype.onLoad = function(e) {
if (e.doc)
this.contentAnalyzer_.maybeAnalyzeDoc(e.doc);
}
PROT_Controller.prototype.maybeShowOptDialog = function() {
if (this.checkRemote_ === null && !PROT_application.opting) {
PROT_application.opting = true; // Reset in protection-opt.xul
this.showOptDialog();
}
}
PROT_Controller.prototype.loadURI = function(browser, url) {
browser.loadURI(url, null, null);
}
PROT_Controller.prototype.reloadPage = function(browser) {
var normalReload = browser.webNavigation.LOAD_FLAGS_NORMAL;
browser.reload(normalReload);
}
PROT_Controller.prototype.showOptDialog = function() {
while (this.checkRemote_ === null)
this.win_.openDialog(
"chrome://amulet-of-protection/content/protection-opt.xul",
"amulet-opt-dialog",
"chrome,modal=yes,centerscreen,resizable=no",
this.win_);
if (this.optChecker_) {
this.tabWatcher_.removeListener("load", this.optChecker_);
this.optChecker_ = null;
}
}