2011-03-16 08:23:53 -07:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
2010-06-07 19:44:06 -07:00
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
|
2011-05-02 10:43:28 -07:00
|
|
|
dump("!! remote browser loaded\n");
|
2010-06-07 19:44:06 -07:00
|
|
|
|
|
|
|
let WebProgressListener = {
|
2010-12-15 10:24:13 -08:00
|
|
|
_lastLocation: null,
|
2010-07-26 17:48:46 -07:00
|
|
|
|
|
|
|
init: function() {
|
2011-01-10 20:53:20 -08:00
|
|
|
let flags = Ci.nsIWebProgress.NOTIFY_LOCATION |
|
|
|
|
Ci.nsIWebProgress.NOTIFY_SECURITY |
|
2011-02-07 10:46:01 -08:00
|
|
|
Ci.nsIWebProgress.NOTIFY_STATE_NETWORK | Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT;
|
2010-07-26 17:48:46 -07:00
|
|
|
|
2011-01-10 20:53:20 -08:00
|
|
|
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress);
|
|
|
|
webProgress.addProgressListener(this, flags);
|
2010-07-26 17:48:46 -07:00
|
|
|
},
|
|
|
|
|
2010-06-07 19:44:06 -07:00
|
|
|
onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
2011-01-10 20:53:20 -08:00
|
|
|
if (content != aWebProgress.DOMWindow)
|
|
|
|
return;
|
2010-06-07 19:44:06 -07:00
|
|
|
|
|
|
|
let json = {
|
2010-12-09 07:36:52 -08:00
|
|
|
contentWindowId: content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID,
|
2010-06-07 19:44:06 -07:00
|
|
|
stateFlags: aStateFlags,
|
2011-01-10 20:53:20 -08:00
|
|
|
status: aStatus
|
2010-06-07 19:44:06 -07:00
|
|
|
};
|
2010-07-26 17:48:46 -07:00
|
|
|
|
2011-01-10 20:53:20 -08:00
|
|
|
sendAsyncMessage("Content:StateChange", json);
|
2010-06-07 19:44:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
|
|
|
|
},
|
|
|
|
|
|
|
|
onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI) {
|
2011-01-10 20:53:20 -08:00
|
|
|
if (content != aWebProgress.DOMWindow)
|
|
|
|
return;
|
|
|
|
|
2010-12-15 10:24:13 -08:00
|
|
|
let spec = aLocationURI ? aLocationURI.spec : "";
|
|
|
|
let location = spec.split("#")[0];
|
|
|
|
|
2011-02-18 11:48:50 -08:00
|
|
|
let charset = content.document.characterSet;
|
|
|
|
|
2010-06-07 19:44:06 -07:00
|
|
|
let json = {
|
2010-12-09 07:36:52 -08:00
|
|
|
contentWindowId: content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID,
|
2011-02-18 11:48:50 -08:00
|
|
|
documentURI: aWebProgress.DOMWindow.document.documentURIObject.spec,
|
|
|
|
location: spec,
|
|
|
|
canGoBack: docShell.canGoBack,
|
|
|
|
canGoForward: docShell.canGoForward,
|
|
|
|
charset: charset.toString()
|
2010-06-07 19:44:06 -07:00
|
|
|
};
|
2011-01-10 20:53:20 -08:00
|
|
|
|
|
|
|
sendAsyncMessage("Content:LocationChange", json);
|
2010-12-15 10:24:13 -08:00
|
|
|
|
|
|
|
// Keep track of hash changes
|
|
|
|
this.hashChanged = (location == this._lastLocation);
|
|
|
|
this._lastLocation = location;
|
2011-03-01 15:18:46 -08:00
|
|
|
|
|
|
|
// When a new page is loaded fire a message for the first paint
|
|
|
|
addEventListener("MozAfterPaint", function(aEvent) {
|
|
|
|
removeEventListener("MozAfterPaint", arguments.callee, true);
|
2011-03-03 16:55:42 -08:00
|
|
|
|
|
|
|
let scrollOffset = ContentScroll.getScrollOffset(content);
|
|
|
|
sendAsyncMessage("Browser:FirstPaint", scrollOffset);
|
2011-03-01 15:18:46 -08:00
|
|
|
}, true);
|
2010-06-07 19:44:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
|
|
|
|
},
|
|
|
|
|
|
|
|
onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) {
|
2011-01-10 20:53:20 -08:00
|
|
|
if (content != aWebProgress.DOMWindow)
|
|
|
|
return;
|
|
|
|
|
2010-10-26 06:57:59 -07:00
|
|
|
let serialization = SecurityUI.getSSLStatusAsString();
|
2010-06-16 06:53:29 -07:00
|
|
|
|
2010-06-07 19:44:06 -07:00
|
|
|
let json = {
|
2010-12-09 07:36:52 -08:00
|
|
|
contentWindowId: content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID,
|
2010-10-26 06:57:59 -07:00
|
|
|
SSLStatusAsString: serialization,
|
2010-06-07 19:44:06 -07:00
|
|
|
state: aState
|
|
|
|
};
|
|
|
|
|
2011-01-10 20:53:20 -08:00
|
|
|
sendAsyncMessage("Content:SecurityChange", json);
|
2010-07-26 17:48:46 -07:00
|
|
|
},
|
|
|
|
|
2010-06-07 19:44:06 -07:00
|
|
|
QueryInterface: function QueryInterface(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsIWebProgressListener) ||
|
|
|
|
aIID.equals(Ci.nsISupportsWeakReference) ||
|
|
|
|
aIID.equals(Ci.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
2010-06-16 06:53:29 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-26 17:48:46 -07:00
|
|
|
WebProgressListener.init();
|
|
|
|
|
2010-06-07 19:44:06 -07:00
|
|
|
|
2010-06-16 06:53:29 -07:00
|
|
|
let SecurityUI = {
|
2010-10-26 06:57:59 -07:00
|
|
|
getSSLStatusAsString: function() {
|
2010-06-07 19:44:06 -07:00
|
|
|
let status = docShell.securityUI.QueryInterface(Ci.nsISSLStatusProvider).SSLStatus;
|
|
|
|
|
|
|
|
if (status) {
|
2010-10-26 06:57:59 -07:00
|
|
|
let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
|
|
|
|
.getService(Ci.nsISerializationHelper);
|
|
|
|
|
|
|
|
status.QueryInterface(Ci.nsISerializable);
|
|
|
|
return serhelper.serializeToString(status);
|
2010-06-07 19:44:06 -07:00
|
|
|
}
|
|
|
|
|
2010-10-26 06:57:59 -07:00
|
|
|
return null;
|
2010-06-07 19:44:06 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let WebNavigation = {
|
|
|
|
_webNavigation: docShell.QueryInterface(Ci.nsIWebNavigation),
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
addMessageListener("WebNavigation:GoBack", this);
|
|
|
|
addMessageListener("WebNavigation:GoForward", this);
|
|
|
|
addMessageListener("WebNavigation:GotoIndex", this);
|
|
|
|
addMessageListener("WebNavigation:LoadURI", this);
|
|
|
|
addMessageListener("WebNavigation:Reload", this);
|
|
|
|
addMessageListener("WebNavigation:Stop", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(message) {
|
|
|
|
switch (message.name) {
|
|
|
|
case "WebNavigation:GoBack":
|
|
|
|
this.goBack(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GoForward":
|
|
|
|
this.goForward(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GotoIndex":
|
|
|
|
this.gotoIndex(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:LoadURI":
|
|
|
|
this.loadURI(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:Reload":
|
|
|
|
this.reload(message);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:Stop":
|
|
|
|
this.stop(message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
goBack: function() {
|
|
|
|
this._webNavigation.goBack();
|
|
|
|
},
|
|
|
|
|
|
|
|
goForward: function() {
|
|
|
|
this._webNavigation.goForward();
|
|
|
|
},
|
|
|
|
|
|
|
|
gotoIndex: function(message) {
|
|
|
|
this._webNavigation.gotoIndex(message.index);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadURI: function(message) {
|
|
|
|
let flags = message.json.flags || this._webNavigation.LOAD_FLAGS_NONE;
|
|
|
|
this._webNavigation.loadURI(message.json.uri, flags, null, null, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
reload: function(message) {
|
|
|
|
let flags = message.json.flags || this._webNavigation.LOAD_FLAGS_NONE;
|
|
|
|
this._webNavigation.reload(flags);
|
|
|
|
},
|
|
|
|
|
|
|
|
stop: function(message) {
|
|
|
|
let flags = message.json.flags || this._webNavigation.STOP_ALL;
|
|
|
|
this._webNavigation.stop(flags);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WebNavigation.init();
|
|
|
|
|
|
|
|
|
|
|
|
let DOMEvents = {
|
|
|
|
init: function() {
|
|
|
|
addEventListener("DOMContentLoaded", this, false);
|
|
|
|
addEventListener("DOMTitleChanged", this, false);
|
|
|
|
addEventListener("DOMLinkAdded", this, false);
|
|
|
|
addEventListener("DOMWillOpenModalDialog", this, false);
|
2010-08-24 01:53:22 -07:00
|
|
|
addEventListener("DOMModalDialogClosed", this, true);
|
2010-06-07 19:44:06 -07:00
|
|
|
addEventListener("DOMWindowClose", this, false);
|
2010-06-08 08:22:20 -07:00
|
|
|
addEventListener("DOMPopupBlocked", this, false);
|
|
|
|
addEventListener("pageshow", this, false);
|
|
|
|
addEventListener("pagehide", this, false);
|
2010-06-07 19:44:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
2010-06-08 08:22:20 -07:00
|
|
|
let document = content.document;
|
2010-06-07 19:44:06 -07:00
|
|
|
switch (aEvent.type) {
|
|
|
|
case "DOMContentLoaded":
|
2010-06-08 08:22:20 -07:00
|
|
|
if (document.documentURIObject.spec == "about:blank")
|
2010-06-07 19:44:06 -07:00
|
|
|
return;
|
|
|
|
|
2010-06-25 21:28:39 -07:00
|
|
|
sendAsyncMessage("DOMContentLoaded", { });
|
2010-06-07 19:44:06 -07:00
|
|
|
break;
|
2010-06-08 08:22:20 -07:00
|
|
|
|
|
|
|
case "pageshow":
|
|
|
|
case "pagehide": {
|
2011-01-19 10:03:05 -08:00
|
|
|
if (aEvent.target.defaultView != content)
|
|
|
|
break;
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
let util = aEvent.target.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
|
|
|
|
let json = {
|
2011-03-14 10:37:07 -07:00
|
|
|
contentWindowWidth: content.innerWidth,
|
|
|
|
contentWindowHeight: content.innerHeight,
|
2010-06-08 08:22:20 -07:00
|
|
|
windowId: util.outerWindowID,
|
|
|
|
persisted: aEvent.persisted
|
|
|
|
};
|
|
|
|
|
2010-11-18 07:15:00 -08:00
|
|
|
// Clear onload focus to prevent the VKB to be shown unexpectingly
|
2010-12-15 10:24:13 -08:00
|
|
|
// but only if the location has really changed and not only the
|
|
|
|
// fragment identifier
|
2010-12-22 09:55:45 -08:00
|
|
|
let contentWindowID = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
|
|
|
|
if (!WebProgressListener.hashChanged && contentWindowID == util.currentInnerWindowID) {
|
2010-12-15 10:24:13 -08:00
|
|
|
let focusManager = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
|
|
|
|
focusManager.clearFocus(content);
|
|
|
|
}
|
2010-11-18 07:15:00 -08:00
|
|
|
|
2010-06-25 21:28:39 -07:00
|
|
|
sendAsyncMessage(aEvent.type, json);
|
2010-06-07 19:44:06 -07:00
|
|
|
break;
|
2010-06-08 08:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case "DOMPopupBlocked": {
|
|
|
|
let util = aEvent.requestingWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
let json = {
|
|
|
|
windowId: util.outerWindowID,
|
|
|
|
popupWindowURI: {
|
|
|
|
spec: aEvent.popupWindowURI.spec,
|
|
|
|
charset: aEvent.popupWindowURI.originCharset
|
|
|
|
},
|
|
|
|
popupWindowFeatures: aEvent.popupWindowFeatures,
|
|
|
|
popupWindowName: aEvent.popupWindowName
|
|
|
|
};
|
|
|
|
|
2010-06-25 21:28:39 -07:00
|
|
|
sendAsyncMessage("DOMPopupBlocked", json);
|
2010-06-07 19:44:06 -07:00
|
|
|
break;
|
2010-06-08 08:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case "DOMTitleChanged":
|
2010-06-25 21:28:39 -07:00
|
|
|
sendAsyncMessage("DOMTitleChanged", { title: document.title });
|
2010-06-07 19:44:06 -07:00
|
|
|
break;
|
2010-06-08 08:22:20 -07:00
|
|
|
|
2010-06-07 19:44:06 -07:00
|
|
|
case "DOMLinkAdded":
|
2010-06-08 08:22:20 -07:00
|
|
|
let target = aEvent.originalTarget;
|
|
|
|
if (!target.href || target.disabled)
|
2010-06-07 19:44:06 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
let json = {
|
2010-06-21 13:18:42 -07:00
|
|
|
windowId: target.ownerDocument.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID,
|
2010-06-08 08:22:20 -07:00
|
|
|
href: target.href,
|
|
|
|
charset: document.characterSet,
|
|
|
|
title: target.title,
|
|
|
|
rel: target.rel,
|
|
|
|
type: target.type
|
2010-06-07 19:44:06 -07:00
|
|
|
};
|
|
|
|
|
2010-06-25 21:28:39 -07:00
|
|
|
sendAsyncMessage("DOMLinkAdded", json);
|
2010-06-07 19:44:06 -07:00
|
|
|
break;
|
2010-06-08 08:22:20 -07:00
|
|
|
|
|
|
|
case "DOMWillOpenModalDialog":
|
2010-08-24 01:53:22 -07:00
|
|
|
case "DOMModalDialogClosed":
|
2010-06-08 08:22:20 -07:00
|
|
|
case "DOMWindowClose":
|
2010-07-15 07:46:34 -07:00
|
|
|
let retvals = sendSyncMessage(aEvent.type, { });
|
2011-03-18 15:05:20 -07:00
|
|
|
for (let i in retvals) {
|
|
|
|
if (retvals[i].preventDefault) {
|
2010-06-08 08:22:20 -07:00
|
|
|
aEvent.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-06-07 19:44:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DOMEvents.init();
|
2010-06-22 06:24:02 -07:00
|
|
|
|
|
|
|
let ContentScroll = {
|
2011-02-15 17:37:30 -08:00
|
|
|
_scrollOffset: { x: 0, y: 0 },
|
2011-01-19 08:45:11 -08:00
|
|
|
|
2010-06-22 06:24:02 -07:00
|
|
|
init: function() {
|
2010-09-01 13:35:05 -07:00
|
|
|
addMessageListener("Content:SetCacheViewport", this);
|
2010-09-15 23:55:42 -07:00
|
|
|
addMessageListener("Content:SetWindowSize", this);
|
2010-08-30 14:11:49 -07:00
|
|
|
|
|
|
|
addEventListener("scroll", this, false);
|
2011-03-17 09:49:00 -07:00
|
|
|
addEventListener("pagehide", this, false);
|
2010-08-30 14:11:49 -07:00
|
|
|
addEventListener("MozScrolledAreaChanged", this, false);
|
2010-06-22 06:24:02 -07:00
|
|
|
},
|
|
|
|
|
2011-02-08 14:46:24 -08:00
|
|
|
getScrollOffset: function(aWindow) {
|
|
|
|
let cwu = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
let scrollX = {}, scrollY = {};
|
|
|
|
cwu.getScrollXY(false, scrollX, scrollY);
|
|
|
|
return { x: scrollX.value, y: scrollY.value };
|
|
|
|
},
|
|
|
|
|
2011-02-15 17:37:30 -08:00
|
|
|
getScrollOffsetForElement: function(aElement) {
|
2011-03-15 16:22:10 -07:00
|
|
|
if (aElement.parentNode == aElement.ownerDocument)
|
|
|
|
return this.getScrollOffset(aElement.ownerDocument.defaultView);
|
|
|
|
return { x: aElement.scrollLeft, y: aElement.scrollTop };
|
2011-02-15 17:37:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
setScrollOffsetForElement: function(aElement, aLeft, aTop) {
|
2011-03-15 16:22:10 -07:00
|
|
|
if (aElement.parentNode == aElement.ownerDocument) {
|
|
|
|
aElement.ownerDocument.defaultView.scrollTo(aLeft, aTop);
|
|
|
|
} else {
|
|
|
|
aElement.scrollLeft = aLeft;
|
|
|
|
aElement.scrollTop = aTop;
|
|
|
|
}
|
2011-02-15 17:37:30 -08:00
|
|
|
},
|
|
|
|
|
2010-06-22 06:24:02 -07:00
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let json = aMessage.json;
|
|
|
|
switch (aMessage.name) {
|
2010-09-01 13:35:05 -07:00
|
|
|
case "Content:SetCacheViewport": {
|
2011-02-15 17:37:30 -08:00
|
|
|
// Set resolution for root view
|
2011-02-08 14:46:24 -08:00
|
|
|
let rootCwu = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
2011-01-13 09:46:38 -08:00
|
|
|
if (json.id == 1)
|
|
|
|
rootCwu.setResolution(json.scale, json.scale);
|
|
|
|
|
2011-01-18 14:00:36 -08:00
|
|
|
let displayport = new Rect(json.x, json.y, json.w, json.h);
|
|
|
|
if (displayport.isEmpty())
|
|
|
|
break;
|
|
|
|
|
2011-02-15 17:37:30 -08:00
|
|
|
// Map ID to element
|
2011-03-24 11:44:07 -07:00
|
|
|
let element = rootCwu.findElementWithViewId(json.id);
|
2011-01-13 09:46:38 -08:00
|
|
|
if (!element)
|
2010-08-30 14:11:49 -07:00
|
|
|
break;
|
|
|
|
|
2011-02-15 17:37:30 -08:00
|
|
|
// Set the scroll offset for this element if specified
|
|
|
|
if (json.scrollX >= 0 && json.scrollY >= 0) {
|
|
|
|
this.setScrollOffsetForElement(element, json.scrollX, json.scrollY)
|
|
|
|
if (json.id == 1)
|
|
|
|
this._scrollOffset = this.getScrollOffset(content);
|
2011-01-13 09:46:38 -08:00
|
|
|
}
|
|
|
|
|
2011-02-15 17:37:30 -08:00
|
|
|
// Set displayport. We want to set this after setting the scroll offset, because
|
|
|
|
// it is calculated based on the scroll offset.
|
|
|
|
let scrollOffset = this.getScrollOffsetForElement(element);
|
2011-03-02 16:33:57 -08:00
|
|
|
let x = displayport.x - scrollOffset.x;
|
|
|
|
let y = displayport.y - scrollOffset.y;
|
|
|
|
|
|
|
|
if (json.id == 1) {
|
|
|
|
x = Math.round(x * json.scale) / json.scale;
|
|
|
|
y = Math.round(y * json.scale) / json.scale;
|
|
|
|
}
|
|
|
|
|
2011-02-15 17:37:30 -08:00
|
|
|
let win = element.ownerDocument.defaultView;
|
2011-02-08 14:46:24 -08:00
|
|
|
let winCwu = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
2011-03-24 11:44:07 -07:00
|
|
|
winCwu.setDisplayPortForElement(x, y, displayport.width, displayport.height, element);
|
2011-01-13 09:46:38 -08:00
|
|
|
|
2011-03-09 10:41:18 -08:00
|
|
|
// XXX If we scrolled during this displayport update, then it is the
|
|
|
|
// end of a pan. Due to bug 637852, there may be seaming issues
|
|
|
|
// with the visible content, so we need to redraw.
|
|
|
|
if (json.id == 1 && json.scrollX >= 0 && json.scrollY >= 0)
|
2011-03-16 08:23:53 -07:00
|
|
|
win.setTimeout(
|
|
|
|
function() {
|
2011-03-24 11:44:07 -07:00
|
|
|
winCwu.redraw();
|
2011-03-16 08:23:53 -07:00
|
|
|
}, 0);
|
2011-03-09 10:41:18 -08:00
|
|
|
|
2010-08-27 12:12:48 -07:00
|
|
|
break;
|
2010-08-27 15:01:32 -07:00
|
|
|
}
|
|
|
|
|
2010-09-15 23:55:42 -07:00
|
|
|
case "Content:SetWindowSize": {
|
2011-02-08 14:46:24 -08:00
|
|
|
let cwu = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
2010-08-27 15:01:32 -07:00
|
|
|
cwu.setCSSViewport(json.width, json.height);
|
2010-08-30 14:11:49 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
switch (aEvent.type) {
|
2011-03-17 09:49:00 -07:00
|
|
|
case "pagehide":
|
|
|
|
this._scrollOffset = { x: 0, y: 0 };
|
|
|
|
break;
|
|
|
|
|
2011-01-13 09:46:38 -08:00
|
|
|
case "scroll": {
|
|
|
|
let doc = aEvent.target;
|
|
|
|
if (doc != content.document)
|
2011-02-15 17:37:30 -08:00
|
|
|
break;
|
2011-01-13 09:46:38 -08:00
|
|
|
|
2011-03-01 09:11:18 -08:00
|
|
|
this.sendScroll();
|
2010-08-30 14:11:49 -07:00
|
|
|
break;
|
2011-01-13 09:46:38 -08:00
|
|
|
}
|
2010-08-30 14:11:49 -07:00
|
|
|
|
|
|
|
case "MozScrolledAreaChanged": {
|
|
|
|
let doc = aEvent.originalTarget;
|
2010-09-15 15:05:50 -07:00
|
|
|
if (content != doc.defaultView) // We are only interested in root scroll pane changes
|
2010-08-30 14:11:49 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Adjust width and height from the incoming event properties so that we
|
|
|
|
// ignore changes to width and height contributed by growth in page
|
|
|
|
// quadrants other than x > 0 && y > 0.
|
2011-02-08 14:46:24 -08:00
|
|
|
let scrollOffset = this.getScrollOffset(content);
|
2010-08-30 14:11:49 -07:00
|
|
|
let x = aEvent.x + scrollOffset.x;
|
|
|
|
let y = aEvent.y + scrollOffset.y;
|
|
|
|
let width = aEvent.width + (x < 0 ? x : 0);
|
|
|
|
let height = aEvent.height + (y < 0 ? y : 0);
|
|
|
|
|
|
|
|
sendAsyncMessage("MozScrolledAreaChanged", {
|
|
|
|
width: width,
|
2010-11-22 19:48:55 -08:00
|
|
|
height: height
|
2010-08-30 14:11:49 -07:00
|
|
|
});
|
|
|
|
|
2010-08-27 15:01:32 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-06-22 06:24:02 -07:00
|
|
|
}
|
2011-03-01 09:11:18 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
sendScroll: function sendScroll() {
|
|
|
|
let scrollOffset = this.getScrollOffset(content);
|
|
|
|
if (this._scrollOffset.x == scrollOffset.x && this._scrollOffset.y == scrollOffset.y)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._scrollOffset = scrollOffset;
|
|
|
|
sendAsyncMessage("scroll", scrollOffset);
|
2010-06-22 06:24:02 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ContentScroll.init();
|
2010-07-28 14:37:24 -07:00
|
|
|
|
2010-11-17 12:01:00 -08:00
|
|
|
let ContentActive = {
|
|
|
|
init: function() {
|
|
|
|
addMessageListener("Content:Activate", this);
|
|
|
|
addMessageListener("Content:Deactivate", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let json = aMessage.json;
|
|
|
|
switch (aMessage.name) {
|
2010-11-22 07:56:00 -08:00
|
|
|
case "Content:Deactivate":
|
2010-11-17 12:01:00 -08:00
|
|
|
docShell.isActive = false;
|
2011-02-08 14:46:24 -08:00
|
|
|
let cwu = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
2011-03-24 11:44:07 -07:00
|
|
|
cwu.setDisplayPortForElement(0,0,0,0,content.document.documentElement);
|
2010-11-17 12:01:00 -08:00
|
|
|
break;
|
|
|
|
|
2010-11-22 07:56:00 -08:00
|
|
|
case "Content:Activate":
|
2010-11-17 12:01:00 -08:00
|
|
|
docShell.isActive = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ContentActive.init();
|
2011-04-29 16:46:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class for IndexedDB, child part. Listens using
|
|
|
|
* the observer service for events regarding IndexedDB
|
|
|
|
* prompts, and sends messages to the parent to actually
|
|
|
|
* show the prompts.
|
|
|
|
*/
|
|
|
|
let IndexedDB = {
|
|
|
|
_permissionsPrompt: "indexedDB-permissions-prompt",
|
|
|
|
_permissionsResponse: "indexedDB-permissions-response",
|
|
|
|
|
|
|
|
_quotaPrompt: "indexedDB-quota-prompt",
|
|
|
|
_quotaResponse: "indexedDB-quota-response",
|
|
|
|
_quotaCancel: "indexedDB-quota-cancel",
|
|
|
|
|
|
|
|
waitingObservers: [],
|
|
|
|
|
|
|
|
init: function IndexedDBPromptHelper_init() {
|
|
|
|
let os = Services.obs;
|
|
|
|
os.addObserver(this, this._permissionsPrompt, false);
|
|
|
|
os.addObserver(this, this._quotaPrompt, false);
|
|
|
|
os.addObserver(this, this._quotaCancel, false);
|
|
|
|
addMessageListener("IndexedDB:Response", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function IndexedDBPromptHelper_observe(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic != this._permissionsPrompt && aTopic != this._quotaPrompt && aTopic != this._quotaCancel) {
|
|
|
|
throw new Error("Unexpected topic!");
|
|
|
|
}
|
|
|
|
|
|
|
|
let requestor = aSubject.QueryInterface(Ci.nsIInterfaceRequestor);
|
|
|
|
let observer = requestor.getInterface(Ci.nsIObserver);
|
|
|
|
|
|
|
|
let contentWindow = requestor.getInterface(Ci.nsIDOMWindow);
|
|
|
|
let contentDocument = contentWindow.document;
|
|
|
|
|
|
|
|
if (aTopic == this._quotaCancel) {
|
|
|
|
observer.observe(null, this._quotaResponse, Ci.nsIPermissionManager.UNKNOWN_ACTION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remote to parent
|
|
|
|
sendAsyncMessage("IndexedDB:Prompt", {
|
|
|
|
topic: aTopic,
|
|
|
|
host: contentDocument.documentURIObject.asciiHost,
|
|
|
|
location: contentDocument.location.toString(),
|
|
|
|
data: aData,
|
|
|
|
observerId: this.addWaitingObserver(observer),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let payload = aMessage.json;
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "IndexedDB:Response":
|
|
|
|
let observer = this.getAndRemoveWaitingObserver(payload.observerId);
|
|
|
|
observer.observe(null, payload.responseTopic, payload.permission);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addWaitingObserver: function(aObserver) {
|
|
|
|
let observerId = 0;
|
|
|
|
while (observerId in this.waitingObservers)
|
|
|
|
observerId++;
|
|
|
|
this.waitingObservers[observerId] = aObserver;
|
|
|
|
return observerId;
|
|
|
|
},
|
|
|
|
|
|
|
|
getAndRemoveWaitingObserver: function(aObserverId) {
|
|
|
|
let observer = this.waitingObservers[aObserverId];
|
|
|
|
delete this.waitingObservers[aObserverId];
|
|
|
|
return observer;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
IndexedDB.init();
|
|
|
|
|