2013-02-12 12:51:25 -08:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
// This stays here because otherwise it's hard to tell if there's a parsing error
|
|
|
|
dump("### Content.js loaded\n");
|
|
|
|
|
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
let Cu = Components.utils;
|
|
|
|
let Cr = Components.results;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "Services", function() {
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
return Services;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "Rect", function() {
|
|
|
|
Cu.import("resource://gre/modules/Geometry.jsm");
|
|
|
|
return Rect;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "Point", function() {
|
|
|
|
Cu.import("resource://gre/modules/Geometry.jsm");
|
|
|
|
return Point;
|
|
|
|
});
|
|
|
|
|
2013-06-19 16:30:53 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerContent",
|
|
|
|
"resource://gre/modules/LoginManagerContent.jsm");
|
|
|
|
|
2013-02-12 12:51:25 -08:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gFocusManager",
|
|
|
|
"@mozilla.org/focus-manager;1", "nsIFocusManager");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gDOMUtils",
|
|
|
|
"@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
|
|
|
|
2013-12-03 19:44:28 -08:00
|
|
|
let XULDocument = Ci.nsIDOMXULDocument;
|
|
|
|
let HTMLHtmlElement = Ci.nsIDOMHTMLHtmlElement;
|
|
|
|
let HTMLIFrameElement = Ci.nsIDOMHTMLIFrameElement;
|
|
|
|
let HTMLFrameElement = Ci.nsIDOMHTMLFrameElement;
|
|
|
|
let HTMLFrameSetElement = Ci.nsIDOMHTMLFrameSetElement;
|
|
|
|
let HTMLSelectElement = Ci.nsIDOMHTMLSelectElement;
|
|
|
|
let HTMLOptionElement = Ci.nsIDOMHTMLOptionElement;
|
2013-02-12 12:51:25 -08:00
|
|
|
|
|
|
|
const kReferenceDpi = 240; // standard "pixel" size used in some preferences
|
|
|
|
|
|
|
|
const kStateActive = 0x00000001; // :active pseudoclass for elements
|
|
|
|
|
2013-11-21 17:40:54 -08:00
|
|
|
const kZoomToElementMargin = 16; // in px
|
|
|
|
|
2013-02-12 12:51:25 -08:00
|
|
|
/*
|
|
|
|
* getBoundingContentRect
|
|
|
|
*
|
|
|
|
* @param aElement
|
|
|
|
* @return Bounding content rect adjusted for scroll and frame offsets.
|
|
|
|
*/
|
|
|
|
function getBoundingContentRect(aElement) {
|
|
|
|
if (!aElement)
|
|
|
|
return new Rect(0, 0, 0, 0);
|
|
|
|
|
|
|
|
let document = aElement.ownerDocument;
|
|
|
|
while(document.defaultView.frameElement)
|
|
|
|
document = document.defaultView.frameElement.ownerDocument;
|
|
|
|
|
|
|
|
let offset = ContentScroll.getScrollOffset(content);
|
|
|
|
offset = new Point(offset.x, offset.y);
|
|
|
|
|
|
|
|
let r = aElement.getBoundingClientRect();
|
|
|
|
|
|
|
|
// step out of iframes and frames, offsetting scroll values
|
|
|
|
let view = aElement.ownerDocument.defaultView;
|
|
|
|
for (let frame = view; frame != content; frame = frame.parent) {
|
|
|
|
// adjust client coordinates' origin to be top left of iframe viewport
|
|
|
|
let rect = frame.frameElement.getBoundingClientRect();
|
|
|
|
let left = frame.getComputedStyle(frame.frameElement, "").borderLeftWidth;
|
|
|
|
let top = frame.getComputedStyle(frame.frameElement, "").borderTopWidth;
|
|
|
|
offset.add(rect.left + parseInt(left), rect.top + parseInt(top));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Rect(r.left + offset.x, r.top + offset.y, r.width, r.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getOverflowContentBoundingRect
|
|
|
|
*
|
|
|
|
* @param aElement
|
|
|
|
* @return Bounding content rect adjusted for scroll and frame offsets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getOverflowContentBoundingRect(aElement) {
|
|
|
|
let r = getBoundingContentRect(aElement);
|
|
|
|
|
|
|
|
// If the overflow is hidden don't bother calculating it
|
|
|
|
let computedStyle = aElement.ownerDocument.defaultView.getComputedStyle(aElement);
|
|
|
|
let blockDisplays = ["block", "inline-block", "list-item"];
|
|
|
|
if ((blockDisplays.indexOf(computedStyle.getPropertyValue("display")) != -1 &&
|
|
|
|
computedStyle.getPropertyValue("overflow") == "hidden") ||
|
|
|
|
aElement instanceof HTMLSelectElement) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < aElement.childElementCount; i++) {
|
|
|
|
r = r.union(getBoundingContentRect(aElement.children[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Content
|
|
|
|
*
|
|
|
|
* Browser event receiver for content.
|
|
|
|
*/
|
|
|
|
let Content = {
|
|
|
|
_debugEvents: false,
|
|
|
|
|
|
|
|
get formAssistant() {
|
|
|
|
delete this.formAssistant;
|
|
|
|
return this.formAssistant = new FormAssistant();
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function init() {
|
|
|
|
// Asyncronous messages sent from the browser
|
|
|
|
addMessageListener("Browser:Blur", this);
|
|
|
|
addMessageListener("Browser:SaveAs", this);
|
|
|
|
addMessageListener("Browser:MozApplicationCache:Fetch", this);
|
|
|
|
addMessageListener("Browser:SetCharset", this);
|
|
|
|
addMessageListener("Browser:CanUnload", this);
|
|
|
|
addMessageListener("Browser:PanBegin", this);
|
2013-11-22 15:20:05 -08:00
|
|
|
addMessageListener("Gesture:SingleTap", this);
|
|
|
|
addMessageListener("Gesture:DoubleTap", this);
|
2013-02-12 12:51:25 -08:00
|
|
|
|
|
|
|
addEventListener("touchstart", this, false);
|
|
|
|
addEventListener("click", this, true);
|
|
|
|
addEventListener("keydown", this);
|
|
|
|
addEventListener("keyup", this);
|
|
|
|
|
|
|
|
// Synchronous events caught during the bubbling phase
|
|
|
|
addEventListener("MozApplicationManifest", this, false);
|
|
|
|
addEventListener("DOMContentLoaded", this, false);
|
2013-06-19 16:30:53 -07:00
|
|
|
addEventListener("DOMAutoComplete", this, false);
|
2013-08-23 20:28:11 -07:00
|
|
|
addEventListener("DOMFormHasPassword", this, false);
|
2013-06-19 16:30:53 -07:00
|
|
|
addEventListener("blur", this, false);
|
2013-02-12 12:51:25 -08:00
|
|
|
// Attach a listener to watch for "click" events bubbling up from error
|
|
|
|
// pages and other similar page. This lets us fix bugs like 401575 which
|
|
|
|
// require error page UI to do privileged things, without letting error
|
|
|
|
// pages have any privilege themselves.
|
|
|
|
addEventListener("click", this, false);
|
|
|
|
|
2013-06-14 08:42:19 -07:00
|
|
|
docShell.useGlobalHistory = true;
|
2013-02-12 12:51:25 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* Events
|
|
|
|
*/
|
|
|
|
|
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
if (this._debugEvents) Util.dumpLn("Content:", aEvent.type);
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "MozApplicationManifest": {
|
|
|
|
let doc = aEvent.originalTarget;
|
|
|
|
sendAsyncMessage("Browser:MozApplicationManifest", {
|
|
|
|
location: doc.documentURIObject.spec,
|
|
|
|
manifest: doc.documentElement.getAttribute("manifest"),
|
|
|
|
charset: doc.characterSet
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "keyup":
|
|
|
|
// If after a key is pressed we still have no input, then close
|
2013-10-16 14:41:42 -07:00
|
|
|
// the autocomplete. Perhaps the user used backspace or delete.
|
|
|
|
// Allow down arrow to trigger autofill popup on empty input.
|
|
|
|
if ((!aEvent.target.value && aEvent.keyCode != aEvent.DOM_VK_DOWN)
|
|
|
|
|| aEvent.keyCode == aEvent.DOM_VK_ESCAPE)
|
2013-02-12 12:51:25 -08:00
|
|
|
this.formAssistant.close();
|
|
|
|
else
|
2013-10-16 14:41:42 -07:00
|
|
|
this.formAssistant.open(aEvent.target, aEvent);
|
2013-02-12 12:51:25 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "click":
|
2013-10-21 10:02:02 -07:00
|
|
|
// Workaround for bug 925457: we sometimes don't recognize the
|
|
|
|
// correct tap target or are unable to identify if it's editable.
|
|
|
|
// Instead always save tap co-ordinates for the keyboard to look for
|
|
|
|
// when it is up.
|
|
|
|
SelectionHandler.onClickCoords(aEvent.clientX, aEvent.clientY);
|
|
|
|
|
2013-02-12 12:51:25 -08:00
|
|
|
if (aEvent.eventPhase == aEvent.BUBBLING_PHASE)
|
2013-03-17 07:55:37 -07:00
|
|
|
this._onClickBubble(aEvent);
|
2013-02-12 12:51:25 -08:00
|
|
|
else
|
2013-03-17 07:55:37 -07:00
|
|
|
this._onClickCapture(aEvent);
|
2013-02-12 12:51:25 -08:00
|
|
|
break;
|
2013-06-19 16:30:53 -07:00
|
|
|
|
2013-08-23 20:28:11 -07:00
|
|
|
case "DOMFormHasPassword":
|
|
|
|
LoginManagerContent.onFormPassword(aEvent);
|
|
|
|
break;
|
|
|
|
|
2013-02-12 12:51:25 -08:00
|
|
|
case "DOMContentLoaded":
|
2013-06-19 16:30:53 -07:00
|
|
|
LoginManagerContent.onContentLoaded(aEvent);
|
2013-03-17 07:55:37 -07:00
|
|
|
this._maybeNotifyErrorPage();
|
2013-02-12 12:51:25 -08:00
|
|
|
break;
|
|
|
|
|
2013-06-19 16:30:53 -07:00
|
|
|
case "DOMAutoComplete":
|
|
|
|
case "blur":
|
|
|
|
LoginManagerContent.onUsernameInput(aEvent);
|
|
|
|
break;
|
|
|
|
|
2013-02-12 12:51:25 -08:00
|
|
|
case "touchstart":
|
2013-04-23 06:51:02 -07:00
|
|
|
this._onTouchStart(aEvent);
|
2013-02-12 12:51:25 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
|
|
|
if (this._debugEvents) Util.dumpLn("Content:", aMessage.name);
|
|
|
|
let json = aMessage.json;
|
|
|
|
let x = json.x;
|
|
|
|
let y = json.y;
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Browser:Blur":
|
|
|
|
gFocusManager.clearFocus(content);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Browser:CanUnload":
|
|
|
|
let canUnload = docShell.contentViewer.permitUnload();
|
|
|
|
sendSyncMessage("Browser:CanUnload:Return", { permit: canUnload });
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Browser:SaveAs":
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Browser:MozApplicationCache:Fetch": {
|
|
|
|
let currentURI = Services.io.newURI(json.location, json.charset, null);
|
|
|
|
let manifestURI = Services.io.newURI(json.manifest, json.charset, currentURI);
|
|
|
|
let updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"]
|
|
|
|
.getService(Ci.nsIOfflineCacheUpdateService);
|
|
|
|
updateService.scheduleUpdate(manifestURI, currentURI, content);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Browser:SetCharset": {
|
2013-03-06 07:27:45 -08:00
|
|
|
docShell.gatherCharsetMenuTelemetry();
|
2013-02-12 12:51:25 -08:00
|
|
|
docShell.charset = json.charset;
|
|
|
|
|
|
|
|
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
webNav.reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Browser:PanBegin":
|
|
|
|
this._cancelTapHighlight();
|
|
|
|
break;
|
2013-11-22 15:20:05 -08:00
|
|
|
|
|
|
|
case "Gesture:SingleTap":
|
2013-11-25 20:30:26 -08:00
|
|
|
this._onSingleTap(json.x, json.y, json.modifiers);
|
2013-11-22 15:20:05 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Gesture:DoubleTap":
|
|
|
|
this._onDoubleTap(json.x, json.y);
|
|
|
|
break;
|
2013-02-12 12:51:25 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/******************************************************
|
2013-03-17 07:55:37 -07:00
|
|
|
* Event handlers
|
2013-02-12 12:51:25 -08:00
|
|
|
*/
|
|
|
|
|
2013-04-23 06:51:02 -07:00
|
|
|
_onTouchStart: function _onTouchStart(aEvent) {
|
|
|
|
let element = aEvent.target;
|
2013-02-12 12:51:25 -08:00
|
|
|
|
|
|
|
// There is no need to have a feedback for disabled element
|
|
|
|
let isDisabled = element instanceof HTMLOptionElement ?
|
|
|
|
(element.disabled || element.parentNode.disabled) : element.disabled;
|
|
|
|
if (isDisabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Set the target element to active
|
|
|
|
this._doTapHighlight(element);
|
|
|
|
},
|
|
|
|
|
2013-03-17 07:55:37 -07:00
|
|
|
_onClickCapture: function _onClickCapture(aEvent) {
|
2013-04-23 06:51:02 -07:00
|
|
|
let element = aEvent.target;
|
2013-02-12 12:51:25 -08:00
|
|
|
|
2013-04-23 06:51:02 -07:00
|
|
|
ContextMenuHandler.reset();
|
2013-02-12 12:51:25 -08:00
|
|
|
|
|
|
|
// Only show autocomplete after the item is clicked
|
|
|
|
if (!this.lastClickElement || this.lastClickElement != element) {
|
|
|
|
this.lastClickElement = element;
|
|
|
|
if (aEvent.mozInputSource == Ci.nsIDOMMouseEvent.MOZ_SOURCE_MOUSE &&
|
|
|
|
!(element instanceof HTMLSelectElement)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.formAssistant.focusSync = true;
|
2013-03-14 14:30:10 -07:00
|
|
|
this.formAssistant.open(element, aEvent);
|
2013-02-12 12:51:25 -08:00
|
|
|
this._cancelTapHighlight();
|
|
|
|
this.formAssistant.focusSync = false;
|
2013-03-20 07:40:05 -07:00
|
|
|
|
|
|
|
// A tap on a form input triggers touch input caret selection
|
2013-07-08 13:45:04 -07:00
|
|
|
if (Util.isEditable(element) &&
|
2013-03-20 07:40:05 -07:00
|
|
|
aEvent.mozInputSource == Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH) {
|
2013-04-23 06:51:03 -07:00
|
|
|
let { offsetX, offsetY } = Util.translateToTopLevelWindow(element);
|
2013-03-20 07:40:05 -07:00
|
|
|
sendAsyncMessage("Content:SelectionCaret", {
|
2013-04-23 06:51:03 -07:00
|
|
|
xPos: aEvent.clientX + offsetX,
|
|
|
|
yPos: aEvent.clientY + offsetY
|
2013-03-20 07:40:05 -07:00
|
|
|
});
|
2013-08-01 05:31:34 -07:00
|
|
|
} else {
|
|
|
|
SelectionHandler.closeSelection();
|
2013-03-20 07:40:05 -07:00
|
|
|
}
|
2013-02-12 12:51:25 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// Checks clicks we care about - events bubbling up from about pages.
|
2013-03-17 07:55:37 -07:00
|
|
|
_onClickBubble: function _onClickBubble(aEvent) {
|
2013-02-12 12:51:25 -08:00
|
|
|
// Don't trust synthetic events
|
|
|
|
if (!aEvent.isTrusted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let ot = aEvent.originalTarget;
|
|
|
|
let errorDoc = ot.ownerDocument;
|
|
|
|
if (!errorDoc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the event came from an ssl error page, it is probably either
|
|
|
|
// "Add Exception…" or "Get me out of here!" button.
|
|
|
|
if (/^about:certerror\?e=nssBadCert/.test(errorDoc.documentURI)) {
|
|
|
|
let perm = errorDoc.getElementById("permanentExceptionButton");
|
|
|
|
let temp = errorDoc.getElementById("temporaryExceptionButton");
|
|
|
|
if (ot == temp || ot == perm) {
|
|
|
|
let action = (ot == perm ? "permanent" : "temporary");
|
|
|
|
sendAsyncMessage("Browser:CertException",
|
|
|
|
{ url: errorDoc.location.href, action: action });
|
|
|
|
} else if (ot == errorDoc.getElementById("getMeOutOfHereButton")) {
|
|
|
|
sendAsyncMessage("Browser:CertException",
|
|
|
|
{ url: errorDoc.location.href, action: "leave" });
|
|
|
|
}
|
|
|
|
} else if (/^about:blocked/.test(errorDoc.documentURI)) {
|
|
|
|
// The event came from a button on a malware/phishing block page
|
|
|
|
// First check whether it's malware or phishing, so that we can
|
|
|
|
// use the right strings/links.
|
|
|
|
let isMalware = /e=malwareBlocked/.test(errorDoc.documentURI);
|
|
|
|
|
|
|
|
if (ot == errorDoc.getElementById("getMeOutButton")) {
|
|
|
|
sendAsyncMessage("Browser:BlockedSite",
|
|
|
|
{ url: errorDoc.location.href, action: "leave" });
|
|
|
|
} else if (ot == errorDoc.getElementById("reportButton")) {
|
|
|
|
// This is the "Why is this site blocked" button. For malware,
|
|
|
|
// we can fetch a site-specific report, for phishing, we redirect
|
|
|
|
// to the generic page describing phishing protection.
|
2013-02-27 13:45:55 -08:00
|
|
|
let action = isMalware ? "report-malware" : "report-phishing";
|
2013-02-12 12:51:25 -08:00
|
|
|
sendAsyncMessage("Browser:BlockedSite",
|
|
|
|
{ url: errorDoc.location.href, action: action });
|
|
|
|
} else if (ot == errorDoc.getElementById("ignoreWarningButton")) {
|
|
|
|
// Allow users to override and continue through to the site,
|
|
|
|
// but add a notify bar as a reminder, so that they don't lose
|
|
|
|
// track after, e.g., tab switching.
|
|
|
|
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
webNav.loadURI(content.location,
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CLASSIFIER,
|
|
|
|
null, null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-25 20:30:26 -08:00
|
|
|
_onSingleTap: function (aX, aY, aModifiers) {
|
2013-11-22 15:20:05 -08:00
|
|
|
let utils = Util.getWindowUtils(content);
|
|
|
|
for (let type of ["mousemove", "mousedown", "mouseup"]) {
|
2013-11-25 20:30:26 -08:00
|
|
|
utils.sendMouseEventToWindow(type, aX, aY, 0, 1, aModifiers, true, 1.0,
|
|
|
|
Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH);
|
2013-11-22 15:20:05 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDoubleTap: function (aX, aY) {
|
|
|
|
let { element } = Content.getCurrentWindowAndOffset(aX, aY);
|
|
|
|
while (element && !this._shouldZoomToElement(element)) {
|
|
|
|
element = element.parentNode;
|
2013-11-18 23:13:05 -08:00
|
|
|
}
|
|
|
|
|
2013-11-22 15:20:05 -08:00
|
|
|
if (!element) {
|
2013-11-18 23:13:05 -08:00
|
|
|
this._zoomOut();
|
|
|
|
} else {
|
2013-11-22 15:20:05 -08:00
|
|
|
this._zoomToElement(element);
|
2013-11-18 23:13:05 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* Zoom utilities
|
|
|
|
*/
|
|
|
|
_zoomOut: function() {
|
2013-11-21 17:39:30 -08:00
|
|
|
let rect = new Rect(0,0,0,0);
|
|
|
|
this._zoomToRect(rect);
|
2013-11-18 23:13:05 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_zoomToElement: function(aElement) {
|
|
|
|
let rect = getBoundingContentRect(aElement);
|
2013-11-21 17:40:54 -08:00
|
|
|
this._inflateRect(rect, kZoomToElementMargin);
|
2013-11-21 17:39:30 -08:00
|
|
|
this._zoomToRect(rect);
|
|
|
|
},
|
|
|
|
|
2013-11-21 17:40:54 -08:00
|
|
|
_inflateRect: function(aRect, aMargin) {
|
|
|
|
aRect.left -= aMargin;
|
|
|
|
aRect.top -= aMargin;
|
|
|
|
aRect.bottom += aMargin;
|
|
|
|
aRect.right += aMargin;
|
|
|
|
},
|
|
|
|
|
2013-11-21 17:39:30 -08:00
|
|
|
_zoomToRect: function (aRect) {
|
2013-11-18 23:13:05 -08:00
|
|
|
let utils = Util.getWindowUtils(content);
|
|
|
|
let viewId = utils.getViewId(content.document.documentElement);
|
|
|
|
let presShellId = {};
|
|
|
|
utils.getPresShellId(presShellId);
|
2013-12-03 09:47:37 -08:00
|
|
|
sendAsyncMessage("Content:ZoomToRect", {
|
|
|
|
rect: aRect,
|
|
|
|
presShellId: presShellId.value,
|
|
|
|
viewId: viewId,
|
|
|
|
});
|
2013-11-18 23:13:05 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_shouldZoomToElement: function(aElement) {
|
|
|
|
let win = aElement.ownerDocument.defaultView;
|
|
|
|
if (win.getComputedStyle(aElement, null).display == "inline") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (aElement instanceof Ci.nsIDOMHTMLLIElement) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (aElement instanceof Ci.nsIDOMHTMLQuoteElement) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-12 12:51:25 -08:00
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* General utilities
|
|
|
|
*/
|
|
|
|
|
2013-11-22 15:20:05 -08:00
|
|
|
/*
|
|
|
|
* Retrieve the total offset from the window's origin to the sub frame
|
|
|
|
* element including frame and scroll offsets. The resulting offset is
|
|
|
|
* such that:
|
|
|
|
* sub frame coords + offset = root frame position
|
|
|
|
*/
|
|
|
|
getCurrentWindowAndOffset: function(x, y) {
|
|
|
|
// If the element at the given point belongs to another document (such
|
|
|
|
// as an iframe's subdocument), the element in the calling document's
|
|
|
|
// DOM (e.g. the iframe) is returned.
|
|
|
|
let utils = Util.getWindowUtils(content);
|
|
|
|
let element = utils.elementFromPoint(x, y, true, false);
|
|
|
|
let offset = { x:0, y:0 };
|
|
|
|
|
|
|
|
while (element && (element instanceof HTMLIFrameElement ||
|
|
|
|
element instanceof HTMLFrameElement)) {
|
|
|
|
// get the child frame position in client coordinates
|
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
|
|
|
|
// calculate offsets for digging down into sub frames
|
|
|
|
// using elementFromPoint:
|
|
|
|
|
|
|
|
// Get the content scroll offset in the child frame
|
|
|
|
scrollOffset = ContentScroll.getScrollOffset(element.contentDocument.defaultView);
|
|
|
|
// subtract frame and scroll offset from our elementFromPoint coordinates
|
|
|
|
x -= rect.left + scrollOffset.x;
|
|
|
|
y -= rect.top + scrollOffset.y;
|
|
|
|
|
|
|
|
// calculate offsets we'll use to translate to client coords:
|
|
|
|
|
|
|
|
// add frame client offset to our total offset result
|
|
|
|
offset.x += rect.left;
|
|
|
|
offset.y += rect.top;
|
2013-02-12 12:51:25 -08:00
|
|
|
|
2013-11-22 15:20:05 -08:00
|
|
|
// get the frame's nsIDOMWindowUtils
|
|
|
|
utils = element.contentDocument
|
|
|
|
.defaultView
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
|
|
|
|
// retrieve the target element in the sub frame at x, y
|
|
|
|
element = utils.elementFromPoint(x, y, true, false);
|
2013-02-12 12:51:25 -08:00
|
|
|
}
|
2013-11-22 15:20:05 -08:00
|
|
|
|
|
|
|
if (!element)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
element: element,
|
|
|
|
contentWindow: element.ownerDocument.defaultView,
|
|
|
|
offset: offset,
|
|
|
|
utils: utils
|
|
|
|
};
|
2013-02-12 12:51:25 -08:00
|
|
|
},
|
|
|
|
|
2013-11-22 15:20:05 -08:00
|
|
|
|
2013-03-17 07:55:37 -07:00
|
|
|
_maybeNotifyErrorPage: function _maybeNotifyErrorPage() {
|
2013-02-12 12:51:25 -08:00
|
|
|
// Notify browser that an error page is being shown instead
|
|
|
|
// of the target location. Necessary to get proper thumbnail
|
|
|
|
// updates on chrome for error pages.
|
|
|
|
if (content.location.href !== content.document.documentURI)
|
|
|
|
sendAsyncMessage("Browser:ErrorPage", null);
|
|
|
|
},
|
|
|
|
|
|
|
|
_highlightElement: null,
|
|
|
|
|
|
|
|
_doTapHighlight: function _doTapHighlight(aElement) {
|
|
|
|
gDOMUtils.setContentState(aElement, kStateActive);
|
|
|
|
this._highlightElement = aElement;
|
|
|
|
},
|
|
|
|
|
|
|
|
_cancelTapHighlight: function _cancelTapHighlight(aElement) {
|
|
|
|
gDOMUtils.setContentState(content.document.documentElement, kStateActive);
|
|
|
|
this._highlightElement = null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Content.init();
|
|
|
|
|
|
|
|
var FormSubmitObserver = {
|
|
|
|
init: function init(){
|
|
|
|
addMessageListener("Browser:TabOpen", this);
|
|
|
|
addMessageListener("Browser:TabClose", this);
|
|
|
|
|
|
|
|
addEventListener("pageshow", this, false);
|
|
|
|
|
|
|
|
Services.obs.addObserver(this, "invalidformsubmit", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
let target = aEvent.originalTarget;
|
|
|
|
let isRootDocument = (target == content.document || target.ownerDocument == content.document);
|
|
|
|
if (!isRootDocument)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Reset invalid submit state on each pageshow
|
|
|
|
if (aEvent.type == "pageshow")
|
|
|
|
Content.formAssistant.invalidSubmit = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
|
|
|
let json = aMessage.json;
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Browser:TabOpen":
|
|
|
|
Services.obs.addObserver(this, "formsubmit", false);
|
|
|
|
break;
|
|
|
|
case "Browser:TabClose":
|
2013-04-06 11:46:35 -07:00
|
|
|
Services.obs.removeObserver(this, "formsubmit");
|
2013-02-12 12:51:25 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
notify: function notify(aFormElement, aWindow, aActionURI, aCancelSubmit) {
|
|
|
|
// Do not notify unless this is the window where the submit occurred
|
|
|
|
if (aWindow == content)
|
|
|
|
// We don't need to send any data along
|
|
|
|
sendAsyncMessage("Browser:FormSubmit", {});
|
|
|
|
},
|
|
|
|
|
|
|
|
notifyInvalidSubmit: function notifyInvalidSubmit(aFormElement, aInvalidElements) {
|
|
|
|
if (!aInvalidElements.length)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let element = aInvalidElements.queryElementAt(0, Ci.nsISupports);
|
|
|
|
if (!(element instanceof HTMLInputElement ||
|
|
|
|
element instanceof HTMLTextAreaElement ||
|
|
|
|
element instanceof HTMLSelectElement ||
|
|
|
|
element instanceof HTMLButtonElement)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Content.formAssistant.invalidSubmit = true;
|
|
|
|
Content.formAssistant.open(element);
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface : function(aIID) {
|
|
|
|
if (!aIID.equals(Ci.nsIFormSubmitObserver) &&
|
|
|
|
!aIID.equals(Ci.nsISupportsWeakReference) &&
|
|
|
|
!aIID.equals(Ci.nsISupports))
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
FormSubmitObserver.init();
|