home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Minami 83
/
MINAMI83.iso
/
Extra
/
DivXInstaller.exe
/
$PLUGINSDIR
/
GoogleToolbarFirefox.msi
/
xpi
/
amulet-jslib
/
phishing-afterload-displayer.js
< prev
next >
Wrap
Text File
|
2006-08-07
|
13KB
|
339 lines
function PROT_PhishMsgDisplayer(msgDesc, browser, doc, url) {
return new PROT_PhishMsgDisplayerCanvas(msgDesc, browser, doc, url);
}
function PROT_PhishMsgDisplayerBase(msgDesc, browser, doc, url) {
this.debugZone = "phisdisplayer";
this.msgDesc_ = msgDesc; // currently unused
this.browser_ = browser;
this.doc_ = doc;
this.url_ = url;
this.messageId_ = "amulet-palm-message";
this.messageTailId_ = "amulet-palm-message-tail-container";
this.messageContentId_ = "amulet-palm-message-content";
this.extendedMessageId_ = "amulet-palm-extended-message";
this.showmoreLinkId_ = "amulet-palm-showmore-link";
this.urlbarIconId_ = "amulet-urlbar-icon";
this.refElementId_ = this.urlbarIconId_;
this.reporter_ = new PROT_Reporter();
this.commandHandlers_ = {
"amulet-palm-showmore":
BindToObject(this.showMore_, this),
"amulet-palm-phishingorg":
BindToObject(this.showURL_, this, PROT_globalStore.getAntiPhishingURL()),
"amulet-palm-phishingfaq":
BindToObject(this.showURL_, this, PROT_globalStore.getPhishingFaqURL()),
"amulet-palm-fraudpage" :
BindToObject(this.showURL_, this, PROT_globalStore.getHomePageURL()),
"amulet-palm-falsepositive":
BindToObject(this.onUserSubmitFalsePositive, this),
"amulet-submit-blacklist" :
BindToObject(this.onUserSubmitToBlacklist, this),
"amulet-submit-generic-phishing" :
BindToObject(this.onUserSubmitToGenericPhish, this),
};
this.windowWatcher_ =
Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
}
PROT_PhishMsgDisplayerBase.prototype.getBackgroundColor_ = function() {
var pref = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
return pref.getCharPref("browser.display.background_color");
}
PROT_PhishMsgDisplayerBase.prototype.declineAction = function() {
G_Debug(this, "User declined warning.");
G_Assert(this, this.started_, "Decline on a non-active displayer?");
this.reporter_.report("phishdecline", this.url_);
this.messageShouldShow_ = false;
if (this.messageShowing_)
this.hideMessage_();
}
PROT_PhishMsgDisplayerBase.prototype.acceptAction = function() {
G_Assert(this, this.started_, "Accept on an unstarted displayer?");
G_Assert(this, this.done_, "Accept on a finished displayer?");
G_Debug(this, "User accepted warning.");
this.reporter_.report("phishaccept", this.url_);
var url = PROT_globalStore.getGetMeOutOfHereURL();
this.browser_.loadURI(url);
}
PROT_PhishMsgDisplayerBase.prototype.onBrowserResized_ = function(event) {
G_Debug(this, "Got resize for " + event.target.nodeName);
if (event.target == this.doc_) {
G_Debug(this, "User resized browser.");
if (this.messageShowing_) {
this.hideMessage_();
this.showMessage_();
}
}
}
PROT_PhishMsgDisplayerBase.prototype.browserSelected = function() {
G_Assert(this, this.started_, "Displayer selected before being started???");
if (this.messageShowing_ === undefined) {
this.messageShouldShow_ = true;
this.ensureNavBarShowing_();
}
this.hideLockIcon_(); // Comes back when we are unselected or unloaded
this.addWarningInUrlbar_(); // Goes away when we are unselected or unloaded
if (this.messageShouldShow_)
this.showMessage_();
}
PROT_PhishMsgDisplayerBase.prototype.explicitShow = function() {
this.messageShouldShow_ = true;
if (!this.messageShowing_)
this.showMessage_();
}
PROT_PhishMsgDisplayerBase.prototype.browserUnselected = function() {
this.removeWarningInUrlbar_();
this.unhideLockIcon_();
if (this.messageShowing_)
this.hideMessage_();
}
PROT_PhishMsgDisplayerBase.prototype.start = function() {
G_Assert(this, this.started_ == undefined, "Displayer started twice?");
this.started_ = true;
this.commandController_ = new PROT_CommandController(this.commandHandlers_);
this.doc_.defaultView.controllers.appendController(this.commandController_);
this.resizeHandler_ = BindToObject(this.onBrowserResized_, this);
this.doc_.defaultView.addEventListener("resize",
this.resizeHandler_,
true);
}
PROT_PhishMsgDisplayerBase.prototype.isActive = function() {
return !!this.started_;
}
PROT_PhishMsgDisplayerBase.prototype.done = function() {
G_Assert(this, !this.done_, "Called done more than once?");
this.done_ = true;
if (this.started_) {
this.removeWarningInUrlbar_();
this.unhideLockIcon_();
if (this.messageShowing_)
this.hideMessage_();
if (this.resizeHandler_) {
this.doc_.defaultView.removeEventListener("resize",
this.resizeHandler_,
true);
this.resizeHandler_ = null;
}
var win = this.doc_.defaultView;
win.controllers.removeController(this.commandController_);
this.commandController_ = null;
}
}
PROT_PhishMsgDisplayerBase.prototype.removeIfExists_ = function(orig,
toRemove) {
var pos = orig.indexOf(toRemove);
if (pos != -1)
orig = orig.substring(0, pos) + orig.substring(pos + toRemove.length);
return orig;
}
PROT_PhishMsgDisplayerBase.prototype.ensureNavBarShowing_ = function() {
var navbar = this.doc_.getElementById("nav-bar");
navbar.setAttribute("collapsed", false);
var win = this.doc_.getElementById("main-window");
var hidden = win.getAttribute("chromehidden");
G_Debug(this, "Old chromehidden string: " + hidden);
var newHidden = this.removeIfExists_(hidden, "toolbar");
newHidden = this.removeIfExists_(newHidden, "location");
if (newHidden != hidden) {
G_Debug(this, "New chromehidden string: " + newHidden);
win.setAttribute("chromehidden", newHidden);
var urlbar = this.doc_.getElementById("urlbar");
urlbar.value = this.doc_.getElementById("content")
.contentDocument.location.href;
}
}
PROT_PhishMsgDisplayerBase.prototype.hideLockIcon_ = function() {
var lockIcon = this.doc_.getElementById("lock-icon");
lockIcon.hidden = true;
}
PROT_PhishMsgDisplayerBase.prototype.unhideLockIcon_ = function() {
var lockIcon = this.doc_.getElementById("lock-icon");
lockIcon.hidden = false;
}
PROT_PhishMsgDisplayerBase.prototype.addWarningInUrlbar_ = function() {
var urlbarIcon = this.doc_.getElementById(this.urlbarIconId_);
urlbarIcon.style.display = "";
}
PROT_PhishMsgDisplayerBase.prototype.removeWarningInUrlbar_ = function() {
var urlbarIcon = this.doc_.getElementById(this.urlbarIconId_);
urlbarIcon.style.display = "none";
}
PROT_PhishMsgDisplayerBase.prototype.showMessage_ = function() { };
PROT_PhishMsgDisplayerBase.prototype.hideMessage_ = function() { };
PROT_PhishMsgDisplayerBase.prototype.adjustLocation_ = function(message,
tail,
refElement) {
var refX = refElement.boxObject.x;
var refY = refElement.boxObject.y;
var refHeight = refElement.boxObject.height;
var refWidth = refElement.boxObject.width;
G_Debug(this, "Ref element is at [window-relative] (" + refX + ", " +
refY + ")");
var pixelsIntoRefY = -2;
var tailY = refY + refHeight - pixelsIntoRefY;
var tailPixelsLeftOfRefX = tail.boxObject.width;
var tailPixelsIntoRefX = Math.round(refWidth / 2);
var tailX = refX - tailPixelsLeftOfRefX + tailPixelsIntoRefX;
var messageY = tailY + tail.boxObject.height + 3;
var messagePixelsLeftOfRefX = 375;
var messageX = refX - messagePixelsLeftOfRefX;
G_Debug(this, "Message is at [window-relative] (" + messageX + ", " +
messageY + ")");
G_Debug(this, "Tail is at [window-relative] (" + tailX + ", " +
tailY + ")");
tail.style.top = tailY + "px";
tail.style.left = tailX + "px";
message.style.top = messageY + "px";
message.style.left = messageX + "px";
}
PROT_PhishMsgDisplayerBase.prototype.showMore_ = function() {
this.doc_.getElementById(this.extendedMessageId_).hidden = false;
this.doc_.getElementById(this.showmoreLinkId_).style.display = "none";
}
PROT_PhishMsgDisplayerBase.prototype.showURL_ = function(url) {
this.windowWatcher_.openWindow(this.windowWatcher_.activeWindow,
url,
"_blank",
null,
null);
}
PROT_PhishMsgDisplayerBase.prototype.onUserSubmitFalsePositive = function() {
var badUrl = this.url_;
G_Debug(this, "User wants to submit as false positive: " + badUrl);
var url = PROT_globalStore.getFalsePositiveURL();
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 */);
}
PROT_PhishMsgDisplayerBase.prototype.onUserSubmitToBlacklist = function() {
var badUrl = this.url_;
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_PhishMsgDisplayerBase.prototype.onUserSubmitToGenericPhish = function() {
var badUrl = this.url_;
G_Debug(this, "User wants to submit something about: " + badUrl);
var url = PROT_globalStore.getGenericPhishSubmitURL();
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;
}
function PROT_PhishMsgDisplayerCanvas(msgDesc, browser, doc, url) {
PROT_PhishMsgDisplayerBase.call(this, msgDesc, browser, doc, url);
this.dimAreaId_ = "amulet-dim-area-canvas";
this.contentStackId_ = "amulet-content-stack";
this.pageCanvasId_ = "amulet-page-canvas";
this.xhtmlNS_ = "http://www.w3.org/1999/xhtml"; // we create html:canvas
}
PROT_PhishMsgDisplayerCanvas.inherits(PROT_PhishMsgDisplayerBase);
PROT_PhishMsgDisplayerCanvas.prototype.showMessage_ = function() {
G_Debug(this, "Showing message.");
this.messageShowing_ = true;
var pageCanvas = this.doc_.createElementNS(this.xhtmlNS_, "html:canvas");
pageCanvas.id = this.pageCanvasId_;
pageCanvas.hidden = "true";
var contentStack = this.doc_.getElementById(this.contentStackId_);
contentStack.insertBefore(pageCanvas, contentStack.firstChild);
contentStack.hidden = false;
var w = this.browser_.boxObject.width;
G_Debug(this, "browser w=" + w);
var h = this.browser_.boxObject.height;
G_Debug(this, "browser h=" + h);
var win = this.browser_.contentWindow;
var scrollX = win.scrollX;
G_Debug(this, "win scrollx=" + scrollX);
var scrollY = win.scrollY;
G_Debug(this, "win scrolly=" + scrollY);
var dimarea = this.doc_.getElementById(this.dimAreaId_);
dimarea.hidden = false;
this.browser_.parentNode.collapsed = true; // And now hide the browser
pageCanvas.setAttribute("width", w);
pageCanvas.setAttribute("height", h);
var bgcolor = this.getBackgroundColor_();
var cx = pageCanvas.getContext("2d");
cx.drawWindow(win, scrollX, scrollY, w, h, bgcolor);
var debZone = this.debugZone;
function repaint() {
G_Debug(debZone, "Repainting canvas...");
cx.drawWindow(win, scrollX, scrollY, w, h, bgcolor);
};
this.repainter_ = new PROT_PhishMsgCanvasRepainter(repaint);
var refElement = this.doc_.getElementById(this.refElementId_);
var message = this.doc_.getElementById(this.messageId_);
var tail = this.doc_.getElementById(this.messageTailId_);
message.hidden = false;
message.style.display = "block";
tail.hidden = false;
tail.style.display = "block";
this.adjustLocation_(message, tail, refElement);
}
PROT_PhishMsgDisplayerCanvas.prototype.hideMessage_ = function() {
G_Debug(this, "Hiding phishing warning.");
G_Assert(this, this.messageShowing_, "Hide message called but not showing?");
this.messageShowing_ = false;
this.repainter_.cancel();
this.repainter_ = null;
var message = this.doc_.getElementById(this.messageId_);
message.hidden = true;
message.style.display = "none";
var tail = this.doc_.getElementById(this.messageTailId_);
tail.hidden = true;
tail.style.display = "none";
this.browser_.parentNode.collapsed = false;
var contentStack = this.doc_.getElementById(this.contentStackId_);
contentStack.hidden = true;
var dimarea = this.doc_.getElementById(this.dimAreaId_);
dimarea.hidden = true;
var pageCanvas = this.doc_.getElementById(this.pageCanvasId_);
contentStack.removeChild(pageCanvas);
}
function PROT_PhishMsgCanvasRepainter(repaintFunc) {
this.count_ = 0;
this.repaintFunc_ = repaintFunc;
this.initPeriodMS_ = 500; // Initially repaint every 500ms
this.steadyStateAtMS_ = 10 * 1000; // Go slowly after 10 seconds,
this.steadyStatePeriodMS_ = 3 * 1000; // repainting every 3 seconds, and
this.quitAtMS_ = 20 * 1000; // stop after 20 seconds
this.startMS_ = (new Date).getTime();
this.alarm_ = new G_Alarm(BindToObject(this.repaint, this),
this.initPeriodMS_);
}
PROT_PhishMsgCanvasRepainter.prototype.repaint = function() {
this.repaintFunc_();
var nextRepaint;
if ((new Date).getTime() - this.startMS_ > this.steadyStateAtMS_)
nextRepaint = this.steadyStatePeriodMS_;
else
nextRepaint = this.initPeriodMS_;
if (!((new Date).getTime() - this.startMS_ > this.quitAtMS_))
this.alarm_ = new G_Alarm(BindToObject(this.repaint, this), nextRepaint);
}
PROT_PhishMsgCanvasRepainter.prototype.cancel = function() {
if (this.alarm_) {
this.alarm_.cancel();
this.alarm_ = null;
}
this.repaintFunc_ = null;
}