2013-01-31 02:22:54 +04: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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var Cu = Components.utils;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Cr = Components.results;
|
2013-01-31 02:22:54 +04:00
|
|
|
|
|
|
|
/* BrowserElementParent injects script to listen for certain events in the
|
|
|
|
* child. We then listen to messages from the child script and take
|
|
|
|
* appropriate action here in the parent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/BrowserElementPromptService.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "DOMApplicationRegistry", function () {
|
|
|
|
Cu.import("resource://gre/modules/Webapps.jsm");
|
|
|
|
return DOMApplicationRegistry;
|
|
|
|
});
|
|
|
|
|
|
|
|
function debug(msg) {
|
2014-11-21 13:56:27 +03:00
|
|
|
//dump("BrowserElementParent - " + msg + "\n");
|
2013-01-31 02:22:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getIntPref(prefName, def) {
|
|
|
|
try {
|
|
|
|
return Services.prefs.getIntPref(prefName);
|
|
|
|
}
|
|
|
|
catch(err) {
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-20 07:22:20 +03:00
|
|
|
function handleWindowEvent(e) {
|
|
|
|
if (this._browserElementParents) {
|
|
|
|
let beps = Cu.nondeterministicGetWeakMapKeys(this._browserElementParents);
|
|
|
|
beps.forEach(bep => bep._handleOwnerEvent(e));
|
2013-07-18 01:31:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
function defineNoReturnMethod(fn) {
|
|
|
|
return function method() {
|
|
|
|
if (!this._domRequestReady) {
|
|
|
|
// Remote browser haven't been created, we just queue the API call.
|
|
|
|
let args = Array.slice(arguments);
|
|
|
|
args.unshift(this);
|
|
|
|
this._pendingAPICalls.push(method.bind.apply(fn, args));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._isAlive()) {
|
|
|
|
fn.apply(this, arguments);
|
|
|
|
}
|
|
|
|
};
|
2014-11-12 14:27:31 +03:00
|
|
|
}
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
function defineDOMRequestMethod(msgName) {
|
|
|
|
return function() {
|
|
|
|
return this._sendDOMRequest(msgName);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function BrowserElementParent() {
|
|
|
|
debug("Creating new BrowserElementParent object");
|
2013-01-31 02:22:54 +04:00
|
|
|
this._domRequestCounter = 0;
|
2014-08-20 15:24:47 +04:00
|
|
|
this._domRequestReady = false;
|
|
|
|
this._pendingAPICalls = [];
|
2013-01-31 02:22:54 +04:00
|
|
|
this._pendingDOMRequests = {};
|
2014-05-19 13:34:55 +04:00
|
|
|
this._pendingSetInputMethodActive = [];
|
2013-01-31 02:22:54 +04:00
|
|
|
this._nextPaintListeners = [];
|
2015-06-10 14:13:12 +03:00
|
|
|
this._pendingDOMFullscreen = false;
|
2013-01-31 02:22:54 +04:00
|
|
|
|
|
|
|
Services.obs.addObserver(this, 'oop-frameloader-crashed', /* ownsWeak = */ true);
|
2014-09-23 08:10:00 +04:00
|
|
|
Services.obs.addObserver(this, 'copypaste-docommand', /* ownsWeak = */ true);
|
2015-05-28 08:57:00 +03:00
|
|
|
Services.obs.addObserver(this, 'ask-children-to-execute-copypaste-command', /* ownsWeak = */ true);
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
BrowserElementParent.prototype = {
|
2014-11-18 09:44:09 +03:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
classDescription: "BrowserElementAPI implementation",
|
|
|
|
classID: Components.ID("{9f171ac4-0939-4ef8-b360-3408aedc3060}"),
|
|
|
|
contractID: "@mozilla.org/dom/browser-element-api;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserElementAPI,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference]),
|
2014-11-18 09:44:09 +03:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
setFrameLoader: function(frameLoader) {
|
|
|
|
this._frameLoader = frameLoader;
|
|
|
|
this._frameElement = frameLoader.QueryInterface(Ci.nsIFrameLoader).ownerElement;
|
|
|
|
if (!this._frameElement) {
|
|
|
|
debug("No frame element?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Listen to visibilitychange on the iframe's owner window, and forward
|
|
|
|
// changes down to the child. We want to do this while registering as few
|
|
|
|
// visibilitychange listeners on _window as possible, because such a listener
|
|
|
|
// may live longer than this BrowserElementParent object.
|
|
|
|
//
|
|
|
|
// To accomplish this, we register just one listener on the window, and have
|
|
|
|
// it reference a WeakMap whose keys are all the BrowserElementParent objects
|
|
|
|
// on the window. Then when the listener fires, we iterate over the
|
|
|
|
// WeakMap's keys (which we can do, because we're chrome) to notify the
|
|
|
|
// BrowserElementParents.
|
|
|
|
if (!this._window._browserElementParents) {
|
|
|
|
this._window._browserElementParents = new WeakMap();
|
2015-07-20 07:22:20 +03:00
|
|
|
let handler = handleWindowEvent.bind(this._window);
|
|
|
|
let windowEvents = ['visibilitychange', 'mozfullscreenchange'];
|
|
|
|
let els = Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService);
|
|
|
|
for (let event of windowEvents) {
|
|
|
|
els.addSystemEventListener(this._window, event, handler,
|
|
|
|
/* useCapture = */ true);
|
|
|
|
}
|
2014-11-21 13:56:27 +03:00
|
|
|
}
|
2013-07-18 01:31:11 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
this._window._browserElementParents.set(this, null);
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
// Insert ourself into the prompt service.
|
|
|
|
BrowserElementPromptService.mapFrameToBrowserElementParent(this._frameElement, this);
|
2014-01-15 23:05:00 +04:00
|
|
|
this._setupMessageListener();
|
|
|
|
this._registerAppManifest();
|
2014-11-21 13:56:27 +03:00
|
|
|
},
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-01-15 23:05:00 +04:00
|
|
|
_runPendingAPICall: function() {
|
|
|
|
if (!this._pendingAPICalls) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < this._pendingAPICalls.length; i++) {
|
|
|
|
try {
|
|
|
|
this._pendingAPICalls[i]();
|
|
|
|
} catch (e) {
|
|
|
|
// throw the expections from pending functions.
|
|
|
|
debug('Exception when running pending API call: ' + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete this._pendingAPICalls;
|
|
|
|
},
|
|
|
|
|
|
|
|
_registerAppManifest: function() {
|
|
|
|
// If this browser represents an app then let the Webapps module register for
|
|
|
|
// any messages that it needs.
|
|
|
|
let appManifestURL =
|
|
|
|
this._frameElement.QueryInterface(Ci.nsIMozBrowserFrame).appManifestURL;
|
|
|
|
if (appManifestURL) {
|
2014-09-24 10:14:54 +04:00
|
|
|
let inParent = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Ci.nsIXULRuntime)
|
|
|
|
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
|
|
if (inParent) {
|
|
|
|
DOMApplicationRegistry.registerBrowserElementParentForApp(
|
|
|
|
{ manifestURL: appManifestURL }, this._mm);
|
|
|
|
} else {
|
|
|
|
this._mm.sendAsyncMessage("Webapps:RegisterBEP",
|
|
|
|
{ manifestURL: appManifestURL });
|
2014-01-15 23:05:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_setupMessageListener: function() {
|
|
|
|
this._mm = this._frameLoader.messageManager;
|
2015-08-31 13:21:40 +03:00
|
|
|
this._isWidget = this._frameLoader
|
|
|
|
.QueryInterface(Ci.nsIFrameLoader)
|
|
|
|
.ownerIsWidget;
|
|
|
|
this._mm.addMessageListener('browser-element-api:call', this);
|
|
|
|
this._mm.loadFrameScript("chrome://global/content/extensions.js", true);
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMsg) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-15 23:05:00 +04:00
|
|
|
|
|
|
|
// Messages we receive are handed to functions which take a (data) argument,
|
|
|
|
// where |data| is the message manager's data object.
|
|
|
|
// We use a single message and dispatch to various function based
|
|
|
|
// on data.msg_name
|
|
|
|
let mmCalls = {
|
|
|
|
"hello": this._recvHello,
|
2014-05-06 00:41:00 +04:00
|
|
|
"loadstart": this._fireProfiledEventFromMsg,
|
|
|
|
"loadend": this._fireProfiledEventFromMsg,
|
2014-01-15 23:05:00 +04:00
|
|
|
"close": this._fireEventFromMsg,
|
|
|
|
"error": this._fireEventFromMsg,
|
2014-05-06 00:41:00 +04:00
|
|
|
"firstpaint": this._fireProfiledEventFromMsg,
|
|
|
|
"documentfirstpaint": this._fireProfiledEventFromMsg,
|
2014-01-15 23:05:00 +04:00
|
|
|
"nextpaint": this._recvNextPaint,
|
|
|
|
"got-purge-history": this._gotDOMRequestResult,
|
|
|
|
"got-screenshot": this._gotDOMRequestResult,
|
2014-09-03 19:20:21 +04:00
|
|
|
"got-contentdimensions": this._gotDOMRequestResult,
|
2014-01-15 23:05:00 +04:00
|
|
|
"got-can-go-back": this._gotDOMRequestResult,
|
|
|
|
"got-can-go-forward": this._gotDOMRequestResult,
|
2015-07-31 20:21:18 +03:00
|
|
|
"got-muted": this._gotDOMRequestResult,
|
|
|
|
"got-volume": this._gotDOMRequestResult,
|
2015-06-10 14:13:12 +03:00
|
|
|
"requested-dom-fullscreen": this._requestedDOMFullscreen,
|
2015-05-21 00:52:26 +03:00
|
|
|
"fullscreen-origin-change": this._fullscreenOriginChange,
|
2015-06-12 04:24:45 +03:00
|
|
|
"exit-dom-fullscreen": this._exitDomFullscreen,
|
2014-01-15 23:05:00 +04:00
|
|
|
"got-visible": this._gotDOMRequestResult,
|
|
|
|
"visibilitychange": this._childVisibilityChange,
|
2014-07-28 03:21:00 +04:00
|
|
|
"got-set-input-method-active": this._gotDOMRequestResult,
|
2014-11-27 20:55:00 +03:00
|
|
|
"selectionstatechanged": this._handleSelectionStateChanged,
|
2014-10-13 01:44:00 +04:00
|
|
|
"scrollviewchange": this._handleScrollViewChange,
|
2015-05-28 08:57:00 +03:00
|
|
|
"caretstatechanged": this._handleCaretStateChanged,
|
2015-07-10 19:38:44 +03:00
|
|
|
"findchange": this._handleFindChange,
|
2015-07-16 10:56:00 +03:00
|
|
|
"execute-script-done": this._gotDOMRequestResult,
|
2015-07-10 19:38:44 +03:00
|
|
|
"got-audio-channel-volume": this._gotDOMRequestResult,
|
|
|
|
"got-set-audio-channel-volume": this._gotDOMRequestResult,
|
|
|
|
"got-audio-channel-muted": this._gotDOMRequestResult,
|
|
|
|
"got-set-audio-channel-muted": this._gotDOMRequestResult,
|
2015-09-23 09:02:10 +03:00
|
|
|
"got-is-audio-channel-active": this._gotDOMRequestResult,
|
|
|
|
"got-structured-data": this._gotDOMRequestResult
|
2014-01-15 23:05:00 +04:00
|
|
|
};
|
|
|
|
|
2014-08-19 18:14:22 +04:00
|
|
|
let mmSecuritySensitiveCalls = {
|
2015-08-01 18:48:52 +03:00
|
|
|
"audioplaybackchange": this._fireEventFromMsg,
|
2014-08-19 18:14:22 +04:00
|
|
|
"showmodalprompt": this._handleShowModalPrompt,
|
|
|
|
"contextmenu": this._fireCtxMenuEvent,
|
|
|
|
"securitychange": this._fireEventFromMsg,
|
|
|
|
"locationchange": this._fireEventFromMsg,
|
|
|
|
"iconchange": this._fireEventFromMsg,
|
2014-09-03 19:20:21 +04:00
|
|
|
"scrollareachanged": this._fireEventFromMsg,
|
2014-08-19 18:14:22 +04:00
|
|
|
"titlechange": this._fireProfiledEventFromMsg,
|
|
|
|
"opensearch": this._fireEventFromMsg,
|
|
|
|
"manifestchange": this._fireEventFromMsg,
|
|
|
|
"metachange": this._fireEventFromMsg,
|
|
|
|
"resize": this._fireEventFromMsg,
|
|
|
|
"activitydone": this._fireEventFromMsg,
|
2015-04-03 06:45:00 +03:00
|
|
|
"scroll": this._fireEventFromMsg,
|
|
|
|
"opentab": this._fireEventFromMsg
|
2014-08-19 18:14:22 +04:00
|
|
|
};
|
|
|
|
|
2015-08-31 13:21:40 +03:00
|
|
|
if (aMsg.data.msg_name in mmCalls) {
|
|
|
|
return mmCalls[aMsg.data.msg_name].apply(this, arguments);
|
|
|
|
} else if (!this._isWidget && aMsg.data.msg_name in mmSecuritySensitiveCalls) {
|
|
|
|
return mmSecuritySensitiveCalls[aMsg.data.msg_name].apply(this, arguments);
|
|
|
|
}
|
|
|
|
},
|
2015-08-15 02:55:09 +03:00
|
|
|
|
2015-08-31 13:21:40 +03:00
|
|
|
_removeMessageListener: function() {
|
|
|
|
this._mm.removeMessageListener('browser-element-api:call', this);
|
2014-01-15 23:05:00 +04:00
|
|
|
},
|
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
/**
|
|
|
|
* You shouldn't touch this._frameElement or this._window if _isAlive is
|
|
|
|
* false. (You'll likely get an exception if you do.)
|
|
|
|
*/
|
|
|
|
_isAlive: function() {
|
|
|
|
return !Cu.isDeadWrapper(this._frameElement) &&
|
|
|
|
!Cu.isDeadWrapper(this._frameElement.ownerDocument) &&
|
|
|
|
!Cu.isDeadWrapper(this._frameElement.ownerDocument.defaultView);
|
|
|
|
},
|
|
|
|
|
|
|
|
get _window() {
|
|
|
|
return this._frameElement.ownerDocument.defaultView;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _windowUtils() {
|
|
|
|
return this._window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
},
|
|
|
|
|
|
|
|
promptAuth: function(authDetail, callback) {
|
|
|
|
let evt;
|
|
|
|
let self = this;
|
|
|
|
let callbackCalled = false;
|
|
|
|
let cancelCallback = function() {
|
|
|
|
if (!callbackCalled) {
|
|
|
|
callbackCalled = true;
|
|
|
|
callback(false, null, null);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-19 18:14:22 +04:00
|
|
|
// 1. We don't handle password-only prompts.
|
|
|
|
// 2. We don't handle for widget case because of security concern.
|
|
|
|
if (authDetail.isOnlyPassword ||
|
|
|
|
this._frameLoader.QueryInterface(Ci.nsIFrameLoader).ownerIsWidget) {
|
2013-01-31 02:22:54 +04:00
|
|
|
cancelCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-19 18:14:22 +04:00
|
|
|
/* username and password */
|
|
|
|
let detail = {
|
|
|
|
host: authDetail.host,
|
2015-03-26 13:49:16 +03:00
|
|
|
realm: authDetail.realm,
|
|
|
|
isProxy: authDetail.isProxy
|
2014-08-19 18:14:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
evt = this._createEvent('usernameandpasswordrequired', detail,
|
|
|
|
/* cancelable */ true);
|
|
|
|
Cu.exportFunction(function(username, password) {
|
|
|
|
if (callbackCalled)
|
|
|
|
return;
|
|
|
|
callbackCalled = true;
|
|
|
|
callback(true, username, password);
|
|
|
|
}, evt.detail, { defineAs: 'authenticate' });
|
|
|
|
|
2014-06-06 09:32:37 +04:00
|
|
|
Cu.exportFunction(cancelCallback, evt.detail, { defineAs: 'cancel' });
|
2013-01-31 02:22:54 +04:00
|
|
|
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
|
|
|
|
if (!evt.defaultPrevented) {
|
|
|
|
cancelCallback();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_sendAsyncMsg: function(msg, data) {
|
|
|
|
try {
|
|
|
|
if (!data) {
|
|
|
|
data = { };
|
|
|
|
}
|
|
|
|
|
|
|
|
data.msg_name = msg;
|
|
|
|
this._mm.sendAsyncMessage('browser-element-api:call', data);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2014-04-02 16:51:46 +04:00
|
|
|
_recvHello: function() {
|
2013-01-31 02:22:54 +04:00
|
|
|
debug("recvHello");
|
|
|
|
|
|
|
|
// Inform our child if our owner element's document is invisible. Note
|
|
|
|
// that we must do so here, rather than in the BrowserElementParent
|
|
|
|
// constructor, because the BrowserElementChild may not be initialized when
|
|
|
|
// we run our constructor.
|
|
|
|
if (this._window.document.hidden) {
|
|
|
|
this._ownerVisibilityChange();
|
|
|
|
}
|
|
|
|
|
2014-08-20 15:24:47 +04:00
|
|
|
if (!this._domRequestReady) {
|
|
|
|
// At least, one message listener such as for hello is registered.
|
|
|
|
// So we can use sendAsyncMessage now.
|
|
|
|
this._domRequestReady = true;
|
|
|
|
this._runPendingAPICall();
|
|
|
|
}
|
2013-01-31 02:22:54 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_fireCtxMenuEvent: function(data) {
|
|
|
|
let detail = data.json;
|
|
|
|
let evtName = detail.msg_name;
|
|
|
|
|
|
|
|
debug('fireCtxMenuEventFromMsg: ' + evtName + ' ' + detail);
|
2013-05-23 19:52:06 +04:00
|
|
|
let evt = this._createEvent(evtName, detail, /* cancellable */ true);
|
2013-01-31 02:22:54 +04:00
|
|
|
|
|
|
|
if (detail.contextmenu) {
|
|
|
|
var self = this;
|
2014-06-06 09:32:37 +04:00
|
|
|
Cu.exportFunction(function(id) {
|
2013-01-31 02:22:54 +04:00
|
|
|
self._sendAsyncMsg('fire-ctx-callback', {menuitem: id});
|
2014-06-06 09:32:37 +04:00
|
|
|
}, evt.detail, { defineAs: 'contextMenuItemSelected' });
|
2013-01-31 02:22:54 +04:00
|
|
|
}
|
2013-05-23 19:52:06 +04:00
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
// The embedder may have default actions on context menu events, so
|
|
|
|
// we fire a context menu event even if the child didn't define a
|
|
|
|
// custom context menu
|
2013-05-23 19:52:06 +04:00
|
|
|
return !this._frameElement.dispatchEvent(evt);
|
2013-01-31 02:22:54 +04:00
|
|
|
},
|
|
|
|
|
2014-05-06 00:41:00 +04:00
|
|
|
/**
|
|
|
|
* add profiler marker for each event fired.
|
|
|
|
*/
|
|
|
|
_fireProfiledEventFromMsg: function(data) {
|
|
|
|
if (Services.profiler !== undefined) {
|
|
|
|
Services.profiler.AddMarker(data.json.msg_name);
|
|
|
|
}
|
|
|
|
this._fireEventFromMsg(data);
|
|
|
|
},
|
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
/**
|
|
|
|
* Fire either a vanilla or a custom event, depending on the contents of
|
|
|
|
* |data|.
|
|
|
|
*/
|
|
|
|
_fireEventFromMsg: function(data) {
|
|
|
|
let detail = data.json;
|
|
|
|
let name = detail.msg_name;
|
|
|
|
|
|
|
|
// For events that send a "_payload_" property, we just want to transmit
|
|
|
|
// this in the event.
|
2013-02-08 01:43:57 +04:00
|
|
|
if ("_payload_" in detail) {
|
2013-01-31 02:22:54 +04:00
|
|
|
detail = detail._payload_;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('fireEventFromMsg: ' + name + ', ' + JSON.stringify(detail));
|
|
|
|
let evt = this._createEvent(name, detail,
|
|
|
|
/* cancelable = */ false);
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
|
|
|
_handleShowModalPrompt: function(data) {
|
|
|
|
// Fire a showmodalprmopt event on the iframe. When this method is called,
|
|
|
|
// the child is spinning in a nested event loop waiting for an
|
|
|
|
// unblock-modal-prompt message.
|
|
|
|
//
|
|
|
|
// If the embedder calls preventDefault() on the showmodalprompt event,
|
|
|
|
// we'll block the child until event.detail.unblock() is called.
|
|
|
|
//
|
|
|
|
// Otherwise, if preventDefault() is not called, we'll send the
|
|
|
|
// unblock-modal-prompt message to the child as soon as the event is done
|
|
|
|
// dispatching.
|
|
|
|
|
|
|
|
let detail = data.json;
|
|
|
|
debug('handleShowPrompt ' + JSON.stringify(detail));
|
|
|
|
|
|
|
|
// Strip off the windowID property from the object we send along in the
|
|
|
|
// event.
|
|
|
|
let windowID = detail.windowID;
|
|
|
|
delete detail.windowID;
|
|
|
|
debug("Event will have detail: " + JSON.stringify(detail));
|
|
|
|
let evt = this._createEvent('showmodalprompt', detail,
|
|
|
|
/* cancelable = */ true);
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
let unblockMsgSent = false;
|
|
|
|
function sendUnblockMsg() {
|
|
|
|
if (unblockMsgSent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unblockMsgSent = true;
|
|
|
|
|
|
|
|
// We don't need to sanitize evt.detail.returnValue (e.g. converting the
|
|
|
|
// return value of confirm() to a boolean); Gecko does that for us.
|
|
|
|
|
|
|
|
let data = { windowID: windowID,
|
|
|
|
returnValue: evt.detail.returnValue };
|
|
|
|
self._sendAsyncMsg('unblock-modal-prompt', data);
|
|
|
|
}
|
|
|
|
|
2014-06-06 09:32:37 +04:00
|
|
|
Cu.exportFunction(sendUnblockMsg, evt.detail, { defineAs: 'unblock' });
|
2013-01-31 02:22:54 +04:00
|
|
|
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
|
|
|
|
if (!evt.defaultPrevented) {
|
|
|
|
// Unblock the inner frame immediately. Otherwise we'll unblock upon
|
|
|
|
// evt.detail.unblock().
|
|
|
|
sendUnblockMsg();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-11-27 20:55:00 +03:00
|
|
|
_handleSelectionStateChanged: function(data) {
|
|
|
|
let evt = this._createEvent('selectionstatechanged', data.json,
|
2014-07-28 03:21:00 +04:00
|
|
|
/* cancelable = */ false);
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2015-05-28 08:57:00 +03:00
|
|
|
// Called when state of accessible caret in child has changed.
|
|
|
|
// The fields of data is as following:
|
|
|
|
// - rect: Contains bounding rectangle of selection, Include width, height,
|
|
|
|
// top, bottom, left and right.
|
|
|
|
// - commands: Describe what commands can be executed in child. Include canSelectAll,
|
|
|
|
// canCut, canCopy and canPaste. For example: if we want to check if cut
|
|
|
|
// command is available, using following code, if (data.commands.canCut) {}.
|
|
|
|
// - zoomFactor: Current zoom factor in child frame.
|
|
|
|
// - reason: The reason causes the state changed. Include "visibilitychange",
|
|
|
|
// "updateposition", "longpressonemptycontent", "taponcaret", "presscaret",
|
|
|
|
// "releasecaret".
|
|
|
|
// - collapsed: Indicate current selection is collapsed or not.
|
|
|
|
// - caretVisible: Indicate the caret visiibility.
|
|
|
|
// - selectionVisible: Indicate current selection is visible or not.
|
2015-07-30 23:34:00 +03:00
|
|
|
// - selectionEditable: Indicate current selection is editable or not.
|
2015-09-16 12:58:14 +03:00
|
|
|
// - selectedTextContent: Contains current selected text content, which is
|
|
|
|
// equivalent to the string returned by Selection.toString().
|
2015-05-28 08:57:00 +03:00
|
|
|
_handleCaretStateChanged: function(data) {
|
|
|
|
let evt = this._createEvent('caretstatechanged', data.json,
|
|
|
|
/* cancelable = */ false);
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
function sendDoCommandMsg(cmd) {
|
|
|
|
let data = { command: cmd };
|
|
|
|
self._sendAsyncMsg('copypaste-do-command', data);
|
|
|
|
}
|
|
|
|
Cu.exportFunction(sendDoCommandMsg, evt.detail, { defineAs: 'sendDoCommandMsg' });
|
|
|
|
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2014-09-22 10:43:00 +04:00
|
|
|
_handleScrollViewChange: function(data) {
|
|
|
|
let evt = this._createEvent("scrollviewchange", data.json,
|
|
|
|
/* cancelable = */ false);
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2015-06-10 03:04:00 +03:00
|
|
|
_handleFindChange: function(data) {
|
|
|
|
let evt = this._createEvent("findchange", data.json,
|
|
|
|
/* cancelable = */ false);
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
_createEvent: function(evtName, detail, cancelable) {
|
|
|
|
// This will have to change if we ever want to send a CustomEvent with null
|
|
|
|
// detail. For now, it's OK.
|
|
|
|
if (detail !== undefined && detail !== null) {
|
2014-06-04 16:21:08 +04:00
|
|
|
detail = Cu.cloneInto(detail, this._window);
|
2013-01-31 02:22:54 +04:00
|
|
|
return new this._window.CustomEvent('mozbrowser' + evtName,
|
|
|
|
{ bubbles: true,
|
|
|
|
cancelable: cancelable,
|
|
|
|
detail: detail });
|
|
|
|
}
|
|
|
|
|
|
|
|
return new this._window.Event('mozbrowser' + evtName,
|
|
|
|
{ bubbles: true,
|
|
|
|
cancelable: cancelable });
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kick off a DOMRequest in the child process.
|
|
|
|
*
|
|
|
|
* We'll fire an event called |msgName| on the child process, passing along
|
|
|
|
* an object with two fields:
|
|
|
|
*
|
|
|
|
* - id: the ID of this request.
|
|
|
|
* - arg: arguments to pass to the child along with this request.
|
|
|
|
*
|
|
|
|
* We expect the child to pass the ID back to us upon completion of the
|
|
|
|
* request. See _gotDOMRequestResult.
|
|
|
|
*/
|
|
|
|
_sendDOMRequest: function(msgName, args) {
|
|
|
|
let id = 'req_' + this._domRequestCounter++;
|
|
|
|
let req = Services.DOMRequest.createRequest(this._window);
|
2014-06-20 20:48:49 +04:00
|
|
|
let self = this;
|
|
|
|
let send = function() {
|
|
|
|
if (!self._isAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (self._sendAsyncMsg(msgName, {id: id, args: args})) {
|
|
|
|
self._pendingDOMRequests[id] = req;
|
|
|
|
} else {
|
|
|
|
Services.DOMRequest.fireErrorAsync(req, "fail");
|
|
|
|
}
|
|
|
|
};
|
2014-08-20 15:24:47 +04:00
|
|
|
if (this._domRequestReady) {
|
2014-06-20 20:48:49 +04:00
|
|
|
send();
|
2013-01-31 02:22:54 +04:00
|
|
|
} else {
|
2014-06-20 20:48:49 +04:00
|
|
|
// Child haven't been loaded.
|
|
|
|
this._pendingAPICalls.push(send);
|
2013-01-31 02:22:54 +04:00
|
|
|
}
|
|
|
|
return req;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the child process finishes handling a DOMRequest. data.json
|
|
|
|
* must have the fields [id, successRv], if the DOMRequest was successful, or
|
|
|
|
* [id, errorMsg], if the request was not successful.
|
|
|
|
*
|
|
|
|
* The fields have the following meanings:
|
|
|
|
*
|
|
|
|
* - id: the ID of the DOM request (see _sendDOMRequest)
|
|
|
|
* - successRv: the request's return value, if the request succeeded
|
|
|
|
* - errorMsg: the message to pass to DOMRequest.fireError(), if the request
|
|
|
|
* failed.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
_gotDOMRequestResult: function(data) {
|
|
|
|
let req = this._pendingDOMRequests[data.json.id];
|
|
|
|
delete this._pendingDOMRequests[data.json.id];
|
|
|
|
|
|
|
|
if ('successRv' in data.json) {
|
|
|
|
debug("Successful gotDOMRequestResult.");
|
2014-09-03 19:20:21 +04:00
|
|
|
let clientObj = Cu.cloneInto(data.json.successRv, this._window);
|
|
|
|
Services.DOMRequest.fireSuccess(req, clientObj);
|
2013-01-31 02:22:54 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
debug("Got error in gotDOMRequestResult.");
|
2014-10-08 20:15:22 +04:00
|
|
|
Services.DOMRequest.fireErrorAsync(req,
|
|
|
|
Cu.cloneInto(data.json.errorMsg, this._window));
|
2013-01-31 02:22:54 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
setVisible: defineNoReturnMethod(function(visible) {
|
2013-01-31 02:22:54 +04:00
|
|
|
this._sendAsyncMsg('set-visible', {visible: visible});
|
2013-04-26 04:53:26 +04:00
|
|
|
this._frameLoader.visible = visible;
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
getVisible: defineDOMRequestMethod('get-visible'),
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
setActive: defineNoReturnMethod(function(active) {
|
2014-10-06 16:32:55 +04:00
|
|
|
this._frameLoader.visible = active;
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
getActive: function() {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
throw Components.Exception("Dead content process",
|
|
|
|
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2014-10-06 16:32:55 +04:00
|
|
|
|
|
|
|
return this._frameLoader.visible;
|
|
|
|
},
|
|
|
|
|
2015-02-17 05:41:49 +03:00
|
|
|
getChildProcessOffset: function() {
|
|
|
|
let offset = { x: 0, y: 0 };
|
|
|
|
let tabParent = this._frameLoader.tabParent;
|
|
|
|
if (tabParent) {
|
|
|
|
let offsetX = {};
|
|
|
|
let offsetY = {};
|
|
|
|
tabParent.getChildProcessOffset(offsetX, offsetY);
|
|
|
|
offset.x = offsetX.value;
|
|
|
|
offset.y = offsetY.value;
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
},
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
sendMouseEvent: defineNoReturnMethod(function(type, x, y, button, clickCount, modifiers) {
|
2015-02-17 05:41:49 +03:00
|
|
|
let offset = this.getChildProcessOffset();
|
|
|
|
x += offset.x;
|
|
|
|
y += offset.y;
|
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
this._sendAsyncMsg("send-mouse-event", {
|
|
|
|
"type": type,
|
|
|
|
"x": x,
|
|
|
|
"y": y,
|
|
|
|
"button": button,
|
|
|
|
"clickCount": clickCount,
|
|
|
|
"modifiers": modifiers
|
|
|
|
});
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
sendTouchEvent: defineNoReturnMethod(function(type, identifiers, touchesX, touchesY,
|
|
|
|
radiisX, radiisY, rotationAngles, forces,
|
|
|
|
count, modifiers) {
|
2014-01-24 13:02:23 +04:00
|
|
|
|
|
|
|
let tabParent = this._frameLoader.tabParent;
|
|
|
|
if (tabParent && tabParent.useAsyncPanZoom) {
|
|
|
|
tabParent.injectTouchEvent(type,
|
|
|
|
identifiers,
|
|
|
|
touchesX,
|
|
|
|
touchesY,
|
|
|
|
radiisX,
|
|
|
|
radiisY,
|
|
|
|
rotationAngles,
|
|
|
|
forces,
|
|
|
|
count,
|
|
|
|
modifiers);
|
|
|
|
} else {
|
2015-02-17 05:41:49 +03:00
|
|
|
let offset = this.getChildProcessOffset();
|
|
|
|
for (var i = 0; i < touchesX.length; i++) {
|
|
|
|
touchesX[i] += offset.x;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < touchesY.length; i++) {
|
|
|
|
touchesY[i] += offset.y;
|
|
|
|
}
|
2014-01-24 13:02:23 +04:00
|
|
|
this._sendAsyncMsg("send-touch-event", {
|
|
|
|
"type": type,
|
|
|
|
"identifiers": identifiers,
|
|
|
|
"touchesX": touchesX,
|
|
|
|
"touchesY": touchesY,
|
|
|
|
"radiisX": radiisX,
|
|
|
|
"radiisY": radiisY,
|
|
|
|
"rotationAngles": rotationAngles,
|
|
|
|
"forces": forces,
|
|
|
|
"count": count,
|
|
|
|
"modifiers": modifiers
|
|
|
|
});
|
|
|
|
}
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
getCanGoBack: defineDOMRequestMethod('get-can-go-back'),
|
|
|
|
getCanGoForward: defineDOMRequestMethod('get-can-go-forward'),
|
|
|
|
getContentDimensions: defineDOMRequestMethod('get-contentdimensions'),
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2015-06-10 03:04:00 +03:00
|
|
|
findAll: defineNoReturnMethod(function(searchString, caseSensitivity) {
|
|
|
|
return this._sendAsyncMsg('find-all', {
|
|
|
|
searchString,
|
|
|
|
caseSensitive: caseSensitivity == Ci.nsIBrowserElementAPI.FIND_CASE_SENSITIVE
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
findNext: defineNoReturnMethod(function(direction) {
|
|
|
|
return this._sendAsyncMsg('find-next', {
|
|
|
|
backward: direction == Ci.nsIBrowserElementAPI.FIND_BACKWARD
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
clearMatch: defineNoReturnMethod(function() {
|
|
|
|
return this._sendAsyncMsg('clear-match');
|
|
|
|
}),
|
|
|
|
|
2015-07-31 20:21:18 +03:00
|
|
|
mute: defineNoReturnMethod(function() {
|
|
|
|
this._sendAsyncMsg('mute');
|
|
|
|
}),
|
|
|
|
|
|
|
|
unmute: defineNoReturnMethod(function() {
|
|
|
|
this._sendAsyncMsg('unmute');
|
|
|
|
}),
|
|
|
|
|
|
|
|
getMuted: defineDOMRequestMethod('get-muted'),
|
|
|
|
|
|
|
|
getVolume: defineDOMRequestMethod('get-volume'),
|
|
|
|
|
|
|
|
setVolume: defineNoReturnMethod(function(volume) {
|
|
|
|
this._sendAsyncMsg('set-volume', {volume});
|
|
|
|
}),
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
goBack: defineNoReturnMethod(function() {
|
2013-01-31 02:22:54 +04:00
|
|
|
this._sendAsyncMsg('go-back');
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
goForward: defineNoReturnMethod(function() {
|
2013-01-31 02:22:54 +04:00
|
|
|
this._sendAsyncMsg('go-forward');
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
reload: defineNoReturnMethod(function(hardReload) {
|
2013-01-31 02:22:54 +04:00
|
|
|
this._sendAsyncMsg('reload', {hardReload: hardReload});
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
stop: defineNoReturnMethod(function() {
|
2013-01-31 02:22:54 +04:00
|
|
|
this._sendAsyncMsg('stop');
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2015-07-16 10:56:00 +03:00
|
|
|
executeScript: function(script, options) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
throw Components.Exception("Dead content process",
|
|
|
|
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enforcing options.url or options.origin
|
|
|
|
if (!options.url && !options.origin) {
|
|
|
|
throw Components.Exception("Invalid argument", Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
return this._sendDOMRequest('execute-script', {script, options});
|
|
|
|
},
|
|
|
|
|
2014-07-26 17:57:37 +04:00
|
|
|
/*
|
|
|
|
* The valid range of zoom scale is defined in preference "zoom.maxPercent" and "zoom.minPercent".
|
|
|
|
*/
|
2014-11-21 13:56:27 +03:00
|
|
|
zoom: defineNoReturnMethod(function(zoom) {
|
2014-07-26 17:57:37 +04:00
|
|
|
zoom *= 100;
|
|
|
|
zoom = Math.min(getIntPref("zoom.maxPercent", 300), zoom);
|
|
|
|
zoom = Math.max(getIntPref("zoom.minPercent", 50), zoom);
|
|
|
|
this._sendAsyncMsg('zoom', {zoom: zoom / 100.0});
|
2014-11-21 13:56:27 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
purgeHistory: defineDOMRequestMethod('purge-history'),
|
2014-11-12 14:27:31 +03:00
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
|
|
|
|
download: function(_url, _options) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-02-24 01:11:23 +03:00
|
|
|
|
|
|
|
let uri = Services.io.newURI(_url, null, null);
|
2014-06-09 21:51:25 +04:00
|
|
|
let url = uri.QueryInterface(Ci.nsIURL);
|
|
|
|
|
2015-02-24 01:11:23 +03:00
|
|
|
debug('original _options = ' + uneval(_options));
|
|
|
|
|
2014-06-09 21:51:25 +04:00
|
|
|
// Ensure we have _options, we always use it to send the filename.
|
|
|
|
_options = _options || {};
|
|
|
|
if (!_options.filename) {
|
|
|
|
_options.filename = url.fileName;
|
|
|
|
}
|
|
|
|
|
2015-02-24 01:11:23 +03:00
|
|
|
debug('final _options = ' + uneval(_options));
|
2014-06-09 21:51:25 +04:00
|
|
|
|
|
|
|
// Ensure we have a filename.
|
|
|
|
if (!_options.filename) {
|
|
|
|
throw Components.Exception("Invalid argument", Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
|
|
|
let interfaceRequestor =
|
|
|
|
this._frameLoader.loadContext.QueryInterface(Ci.nsIInterfaceRequestor);
|
|
|
|
let req = Services.DOMRequest.createRequest(this._window);
|
|
|
|
|
|
|
|
function DownloadListener() {
|
|
|
|
debug('DownloadListener Constructor');
|
|
|
|
}
|
|
|
|
DownloadListener.prototype = {
|
|
|
|
extListener: null,
|
|
|
|
onStartRequest: function(aRequest, aContext) {
|
|
|
|
debug('DownloadListener - onStartRequest');
|
|
|
|
let extHelperAppSvc =
|
|
|
|
Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
|
|
|
|
getService(Ci.nsIExternalHelperAppService);
|
|
|
|
let channel = aRequest.QueryInterface(Ci.nsIChannel);
|
|
|
|
|
2014-07-15 14:05:44 +04:00
|
|
|
// First, we'll ensure the filename doesn't have any leading
|
|
|
|
// periods. We have to do it here to avoid ending up with a filename
|
|
|
|
// that's only an extension with no extension (e.g. Sending in
|
|
|
|
// '.jpeg' without stripping the '.' would result in a filename of
|
|
|
|
// 'jpeg' where we want 'jpeg.jpeg'.
|
|
|
|
_options.filename = _options.filename.replace(/^\.+/, "");
|
|
|
|
|
|
|
|
let ext = null;
|
|
|
|
let mimeSvc = extHelperAppSvc.QueryInterface(Ci.nsIMIMEService);
|
|
|
|
try {
|
|
|
|
ext = '.' + mimeSvc.getPrimaryExtension(channel.contentType, '');
|
|
|
|
} catch (e) { ext = null; }
|
|
|
|
|
|
|
|
// Check if we need to add an extension to the filename.
|
|
|
|
if (ext && !_options.filename.endsWith(ext)) {
|
|
|
|
_options.filename += ext;
|
|
|
|
}
|
|
|
|
// Set the filename to use when saving to disk.
|
|
|
|
channel.contentDispositionFilename = _options.filename;
|
|
|
|
|
2014-06-09 21:51:25 +04:00
|
|
|
this.extListener =
|
|
|
|
extHelperAppSvc.doContent(
|
|
|
|
channel.contentType,
|
|
|
|
aRequest,
|
|
|
|
interfaceRequestor,
|
|
|
|
true);
|
|
|
|
this.extListener.onStartRequest(aRequest, aContext);
|
|
|
|
},
|
|
|
|
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
|
|
|
debug('DownloadListener - onStopRequest (aStatusCode = ' +
|
|
|
|
aStatusCode + ')');
|
|
|
|
if (aStatusCode == Cr.NS_OK) {
|
|
|
|
// Everything looks great.
|
|
|
|
debug('DownloadListener - Download Successful.');
|
2014-06-20 14:17:34 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, aStatusCode);
|
2014-06-09 21:51:25 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// In case of failure, we'll simply return the failure status code.
|
|
|
|
debug('DownloadListener - Download Failed!');
|
2014-06-20 14:17:34 +04:00
|
|
|
Services.DOMRequest.fireError(req, aStatusCode);
|
2014-06-09 21:51:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.extListener) {
|
|
|
|
this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onDataAvailable: function(aRequest, aContext, aInputStream,
|
|
|
|
aOffset, aCount) {
|
|
|
|
this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
|
|
|
|
aOffset, aCount);
|
|
|
|
},
|
2014-11-21 13:56:28 +03:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamListener,
|
2014-06-09 21:51:25 +04:00
|
|
|
Ci.nsIRequestObserver])
|
|
|
|
};
|
|
|
|
|
2015-02-24 01:11:23 +03:00
|
|
|
// If we have a URI we'll use it to get the triggering principal to use,
|
|
|
|
// if not available a null principal is acceptable.
|
|
|
|
let referrer = null;
|
|
|
|
let principal = null;
|
|
|
|
if (_options.referrer) {
|
|
|
|
// newURI can throw on malformed URIs.
|
|
|
|
try {
|
|
|
|
referrer = Services.io.newURI(_options.referrer, null, null);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
debug('Malformed referrer -- ' + e);
|
|
|
|
}
|
2015-08-17 12:03:19 +03:00
|
|
|
|
2015-02-24 01:11:23 +03:00
|
|
|
// This simply returns null if there is no principal available
|
|
|
|
// for the requested uri. This is an acceptable fallback when
|
|
|
|
// calling newChannelFromURI2.
|
2015-08-17 12:03:19 +03:00
|
|
|
principal =
|
|
|
|
Services.scriptSecurityManager.createCodebasePrincipal(
|
2015-09-23 11:10:21 +03:00
|
|
|
referrer, this._frameLoader.loadContext.originAttributes);
|
2015-02-24 01:11:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
debug('Using principal? ' + !!principal);
|
|
|
|
|
|
|
|
let channel =
|
|
|
|
Services.io.newChannelFromURI2(url,
|
|
|
|
null, // No document.
|
|
|
|
principal, // Loading principal
|
|
|
|
principal, // Triggering principal
|
|
|
|
Ci.nsILoadInfo.SEC_NORMAL,
|
|
|
|
Ci.nsIContentPolicy.TYPE_OTHER);
|
2014-06-09 21:51:25 +04:00
|
|
|
|
|
|
|
// XXX We would set private browsing information prior to calling this.
|
|
|
|
channel.notificationCallbacks = interfaceRequestor;
|
|
|
|
|
|
|
|
// Since we're downloading our own local copy we'll want to bypass the
|
|
|
|
// cache and local cache if the channel let's us specify this.
|
|
|
|
let flags = Ci.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS |
|
|
|
|
Ci.nsIChannel.LOAD_BYPASS_CACHE;
|
|
|
|
if (channel instanceof Ci.nsICachingChannel) {
|
|
|
|
debug('This is a caching channel. Forcing bypass.');
|
|
|
|
flags |= Ci.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.loadFlags |= flags;
|
|
|
|
|
|
|
|
if (channel instanceof Ci.nsIHttpChannel) {
|
2015-02-24 01:11:23 +03:00
|
|
|
debug('Setting HTTP referrer = ' + (referrer && referrer.spec));
|
|
|
|
channel.referrer = referrer;
|
2014-06-09 21:51:25 +04:00
|
|
|
if (channel instanceof Ci.nsIHttpChannelInternal) {
|
|
|
|
channel.forceAllowThirdPartyCookie = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set-up complete, let's get things started.
|
|
|
|
channel.asyncOpen(new DownloadListener(), null);
|
|
|
|
|
|
|
|
return req;
|
|
|
|
},
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
getScreenshot: function(_width, _height, _mimeType) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
throw Components.Exception("Dead content process",
|
|
|
|
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
let width = parseInt(_width);
|
|
|
|
let height = parseInt(_height);
|
2013-12-11 13:03:54 +04:00
|
|
|
let mimeType = (typeof _mimeType === 'string') ?
|
|
|
|
_mimeType.trim().toLowerCase() : 'image/jpeg';
|
2013-01-31 02:22:54 +04:00
|
|
|
if (isNaN(width) || isNaN(height) || width < 0 || height < 0) {
|
|
|
|
throw Components.Exception("Invalid argument",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._sendDOMRequest('get-screenshot',
|
2013-12-11 13:03:54 +04:00
|
|
|
{width: width, height: height,
|
|
|
|
mimeType: mimeType});
|
2013-01-31 02:22:54 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_recvNextPaint: function(data) {
|
|
|
|
let listeners = this._nextPaintListeners;
|
|
|
|
this._nextPaintListeners = [];
|
|
|
|
for (let listener of listeners) {
|
|
|
|
try {
|
2014-11-21 13:56:27 +03:00
|
|
|
listener.recvNextPaint();
|
2013-01-31 02:22:54 +04:00
|
|
|
} catch (e) {
|
|
|
|
// If a listener throws we'll continue.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
addNextPaintListener: function(listener) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
throw Components.Exception("Dead content process",
|
|
|
|
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-01-15 23:05:00 +04:00
|
|
|
let self = this;
|
|
|
|
let run = function() {
|
|
|
|
if (self._nextPaintListeners.push(listener) == 1)
|
|
|
|
self._sendAsyncMsg('activate-next-paint-listener');
|
|
|
|
};
|
2014-08-20 15:24:47 +04:00
|
|
|
if (!this._domRequestReady) {
|
2014-01-15 23:05:00 +04:00
|
|
|
this._pendingAPICalls.push(run);
|
|
|
|
} else {
|
|
|
|
run();
|
|
|
|
}
|
2013-01-31 02:22:54 +04:00
|
|
|
},
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
removeNextPaintListener: function(listener) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
throw Components.Exception("Dead content process",
|
|
|
|
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2013-01-31 02:22:54 +04:00
|
|
|
|
2014-01-15 23:05:00 +04:00
|
|
|
let self = this;
|
|
|
|
let run = function() {
|
|
|
|
for (let i = self._nextPaintListeners.length - 1; i >= 0; i--) {
|
|
|
|
if (self._nextPaintListeners[i] == listener) {
|
|
|
|
self._nextPaintListeners.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-31 02:22:54 +04:00
|
|
|
}
|
|
|
|
|
2014-01-15 23:05:00 +04:00
|
|
|
if (self._nextPaintListeners.length == 0)
|
|
|
|
self._sendAsyncMsg('deactivate-next-paint-listener');
|
|
|
|
};
|
2014-08-20 15:24:47 +04:00
|
|
|
if (!this._domRequestReady) {
|
2014-01-15 23:05:00 +04:00
|
|
|
this._pendingAPICalls.push(run);
|
|
|
|
} else {
|
|
|
|
run();
|
|
|
|
}
|
2013-01-31 02:22:54 +04:00
|
|
|
},
|
|
|
|
|
2014-11-21 13:56:27 +03:00
|
|
|
setInputMethodActive: function(isActive) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
throw Components.Exception("Dead content process",
|
|
|
|
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
|
|
|
|
2013-09-23 17:40:59 +04:00
|
|
|
if (typeof isActive !== 'boolean') {
|
|
|
|
throw Components.Exception("Invalid argument",
|
|
|
|
Cr.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
2014-06-20 20:48:49 +04:00
|
|
|
return this._sendDOMRequest('set-input-method-active',
|
|
|
|
{isActive: isActive});
|
2013-09-23 17:40:59 +04:00
|
|
|
},
|
|
|
|
|
2015-01-22 12:40:17 +03:00
|
|
|
setNFCFocus: function(isFocus) {
|
|
|
|
if (!this._isAlive()) {
|
|
|
|
throw Components.Exception("Dead content process",
|
|
|
|
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For now, we use tab id as an identifier to let NFC module know
|
|
|
|
// which app is in foreground. But this approach will not work in
|
|
|
|
// in-process mode because tab id doesn't exist. Fix bug 1116449
|
|
|
|
// if we are going to support in-process mode.
|
|
|
|
try {
|
|
|
|
var tabId = this._frameLoader.QueryInterface(Ci.nsIFrameLoader)
|
|
|
|
.tabParent
|
|
|
|
.tabId;
|
|
|
|
} catch(e) {
|
|
|
|
debug("SetNFCFocus for in-process mode is not yet supported");
|
|
|
|
throw Components.Exception("SetNFCFocus for in-process mode is not yet supported",
|
|
|
|
Cr.NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let nfcContentHelper =
|
|
|
|
Cc["@mozilla.org/nfc/content-helper;1"].getService(Ci.nsINfcBrowserAPI);
|
|
|
|
nfcContentHelper.setFocusApp(tabId, isFocus);
|
|
|
|
} catch(e) {
|
|
|
|
// Not all platforms support NFC
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-07-10 19:38:44 +03:00
|
|
|
getAudioChannelVolume: function(aAudioChannel) {
|
|
|
|
return this._sendDOMRequest('get-audio-channel-volume',
|
|
|
|
{audioChannel: aAudioChannel});
|
|
|
|
},
|
|
|
|
|
|
|
|
setAudioChannelVolume: function(aAudioChannel, aVolume) {
|
|
|
|
return this._sendDOMRequest('set-audio-channel-volume',
|
|
|
|
{audioChannel: aAudioChannel,
|
|
|
|
volume: aVolume});
|
|
|
|
},
|
|
|
|
|
|
|
|
getAudioChannelMuted: function(aAudioChannel) {
|
|
|
|
return this._sendDOMRequest('get-audio-channel-muted',
|
|
|
|
{audioChannel: aAudioChannel});
|
|
|
|
},
|
|
|
|
|
|
|
|
setAudioChannelMuted: function(aAudioChannel, aMuted) {
|
|
|
|
return this._sendDOMRequest('set-audio-channel-muted',
|
|
|
|
{audioChannel: aAudioChannel,
|
|
|
|
muted: aMuted});
|
|
|
|
},
|
|
|
|
|
|
|
|
isAudioChannelActive: function(aAudioChannel) {
|
|
|
|
return this._sendDOMRequest('get-is-audio-channel-active',
|
|
|
|
{audioChannel: aAudioChannel});
|
|
|
|
},
|
|
|
|
|
2015-09-23 09:02:10 +03:00
|
|
|
getStructuredData: defineDOMRequestMethod('get-structured-data'),
|
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
/**
|
|
|
|
* Called when the visibility of the window which owns this iframe changes.
|
|
|
|
*/
|
|
|
|
_ownerVisibilityChange: function() {
|
|
|
|
this._sendAsyncMsg('owner-visibility-change',
|
|
|
|
{visible: !this._window.document.hidden});
|
|
|
|
},
|
|
|
|
|
2013-04-26 04:53:26 +04:00
|
|
|
/*
|
|
|
|
* Called when the child notices that its visibility has changed.
|
|
|
|
*
|
|
|
|
* This is sometimes redundant; for example, the child's visibility may
|
|
|
|
* change in response to a setVisible request that we made here! But it's
|
|
|
|
* not always redundant; for example, the child's visibility may change in
|
|
|
|
* response to its parent docshell being hidden.
|
|
|
|
*/
|
|
|
|
_childVisibilityChange: function(data) {
|
|
|
|
debug("_childVisibilityChange(" + data.json.visible + ")");
|
|
|
|
this._frameLoader.visible = data.json.visible;
|
2013-05-24 13:33:46 +04:00
|
|
|
|
|
|
|
this._fireEventFromMsg(data);
|
2013-04-26 04:53:26 +04:00
|
|
|
},
|
|
|
|
|
2015-06-10 14:13:12 +03:00
|
|
|
_requestedDOMFullscreen: function() {
|
|
|
|
this._pendingDOMFullscreen = true;
|
2015-05-21 00:52:26 +03:00
|
|
|
this._windowUtils.remoteFrameFullscreenChanged(this._frameElement);
|
|
|
|
},
|
|
|
|
|
|
|
|
_fullscreenOriginChange: function(data) {
|
|
|
|
Services.obs.notifyObservers(
|
2015-05-26 22:46:09 +03:00
|
|
|
this._frameElement, "fullscreen-origin-change", data.json.originNoSuffix);
|
2013-01-31 02:22:54 +04:00
|
|
|
},
|
|
|
|
|
2015-06-12 04:24:45 +03:00
|
|
|
_exitDomFullscreen: function(data) {
|
2013-01-31 02:22:54 +04:00
|
|
|
this._windowUtils.remoteFrameFullscreenReverted();
|
|
|
|
},
|
|
|
|
|
2015-07-20 07:22:20 +03:00
|
|
|
_handleOwnerEvent: function(evt) {
|
|
|
|
switch (evt.type) {
|
|
|
|
case 'visibilitychange':
|
|
|
|
this._ownerVisibilityChange();
|
|
|
|
break;
|
|
|
|
case 'mozfullscreenchange':
|
|
|
|
if (!this._window.document.mozFullScreen) {
|
|
|
|
this._sendAsyncMsg('exit-fullscreen');
|
|
|
|
} else if (this._pendingDOMFullscreen) {
|
|
|
|
this._pendingDOMFullscreen = false;
|
|
|
|
this._sendAsyncMsg('entered-fullscreen');
|
|
|
|
}
|
|
|
|
break;
|
2015-05-21 00:52:26 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-01-31 02:22:54 +04:00
|
|
|
_fireFatalError: function() {
|
|
|
|
let evt = this._createEvent('error', {type: 'fatal'},
|
|
|
|
/* cancelable = */ false);
|
|
|
|
this._frameElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(subject, topic, data) {
|
|
|
|
switch(topic) {
|
|
|
|
case 'oop-frameloader-crashed':
|
|
|
|
if (this._isAlive() && subject == this._frameLoader) {
|
|
|
|
this._fireFatalError();
|
|
|
|
}
|
|
|
|
break;
|
2014-09-23 08:10:00 +04:00
|
|
|
case 'copypaste-docommand':
|
|
|
|
if (this._isAlive() && this._frameElement.isEqualNode(subject.wrappedJSObject)) {
|
|
|
|
this._sendAsyncMsg('do-command', { command: data });
|
2014-08-26 01:02:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2015-05-28 08:57:00 +03:00
|
|
|
case 'ask-children-to-execute-copypaste-command':
|
|
|
|
if (this._isAlive() && this._frameElement == subject.wrappedJSObject) {
|
|
|
|
this._sendAsyncMsg('copypaste-do-command', { command: data });
|
|
|
|
}
|
|
|
|
break;
|
2013-01-31 02:22:54 +04:00
|
|
|
default:
|
|
|
|
debug('Unknown topic: ' + topic);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
2014-11-21 13:56:28 +03:00
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([BrowserElementParent]);
|