Merge m-c to fig

This commit is contained in:
Lucas Rocha 2013-08-20 11:50:04 +01:00
commit ac5d380df7
131 changed files with 4458 additions and 1636 deletions

View File

@ -328,6 +328,11 @@ function getApplicationAccessible()
QueryInterface(nsIAccessibleApplication);
}
/**
* Flags used for testAccessibleTree
*/
const kSkipTreeFullCheck = 1;
/**
* Compare expected and actual accessibles trees.
*
@ -339,8 +344,9 @@ function getApplicationAccessible()
* children of accessible
* states - an object having states and extraStates
* fields
* @param aFlags [in, optional] flags, see constants above
*/
function testAccessibleTree(aAccOrElmOrID, aAccTree)
function testAccessibleTree(aAccOrElmOrID, aAccTree, aFlags)
{
var acc = getAccessible(aAccOrElmOrID);
if (!acc)
@ -361,30 +367,101 @@ function testAccessibleTree(aAccOrElmOrID, aAccTree)
// Test accessible properties.
for (var prop in accTree) {
var msg = "Wrong value of property '" + prop + "' for " + prettyName(acc) + ".";
if (prop == "role") {
is(roleToString(acc[prop]), roleToString(accTree[prop]), msg);
} else if (prop == "states") {
var statesObj = accTree[prop];
testStates(acc, statesObj.states, statesObj.extraStates,
statesObj.absentStates, statesObj.absentExtraStates);
switch (prop) {
case "actions": {
var actions = (typeof accTree.actions == "string") ?
[ accTree.actions ] : (accTree.actions || []);
is(acc.actionCount, actions.length, "Wong number of actions.");
for (var i = 0; i < actions.length; i++ )
is(acc.getActionName(i), actions[i], "Wrong action name at " + i + " index.");
break;
}
} else if (prop == "tagName") {
case "attributes":
testAttrs(acc, accTree[prop], true);
break;
case "absentAttributes":
testAbsentAttrs(acc, accTree[prop]);
break;
case "interfaces": {
var ifaces = (accTree[prop] instanceof Array) ?
accTree[prop] : [ accTree[prop] ];
for (var i = 0; i < ifaces.length; i++) {
ok((acc instanceof ifaces[i]),
"No " + ifaces[i] + " interface on " + prettyName(acc));
}
break;
}
case "relations": {
for (var rel in accTree[prop])
testRelation(acc, window[rel], accTree[prop][rel]);
break;
}
case "role":
isRole(acc, accTree[prop], msg);
break;
case "states":
case "extraStates":
case "absentStates":
case "absentExtraStates": {
testStates(acc, accTree["states"], accTree["extraStates"],
accTree["absentStates"], accTree["absentExtraStates"]);
break;
}
case "tagName":
is(accTree[prop], acc.DOMNode.tagName, msg);
break;
} else if (prop != "children") {
is(acc[prop], accTree[prop], msg);
case "textAttrs": {
var prevOffset = -1;
for (var offset in accTree[prop]) {
if (prevOffset !=- 1) {
var attrs = accTree[prop][prevOffset];
testTextAttrs(acc, prevOffset, attrs, { }, prevOffset, offset, true);
}
prevOffset = offset;
}
if (prevOffset != -1) {
var charCount = getAccessible(acc, [nsIAccessibleText]).characterCount;
var attrs = accTree[prop][prevOffset];
testTextAttrs(acc, prevOffset, attrs, { }, prevOffset, charCount, true);
}
break;
}
default:
if (prop.indexOf("todo_") == 0)
todo(false, msg);
else if (prop != "children")
is(acc[prop], accTree[prop], msg);
}
}
// Test children.
if ("children" in accTree && accTree["children"] instanceof Array) {
var children = acc.children;
is(children.length, accTree.children.length,
var childCount = children.length;
is(childCount, accTree.children.length,
"Different amount of expected children of " + prettyName(acc) + ".");
if (accTree.children.length == children.length) {
var childCount = children.length;
if (accTree.children.length == childCount) {
if (aFlags & kSkipTreeFullCheck) {
for (var i = 0; i < childCount; i++) {
var child = children.queryElementAt(i, nsIAccessible);
testAccessibleTree(child, accTree.children[i], aFlags);
}
return;
}
// nsIAccessible::firstChild
var expectedFirstChild = childCount > 0 ?
@ -402,7 +479,7 @@ function testAccessibleTree(aAccOrElmOrID, aAccTree)
is(lastChild, expectedLastChild,
"Wrong last child of " + prettyName(acc));
for (var i = 0; i < children.length; i++) {
for (var i = 0; i < childCount; i++) {
var child = children.queryElementAt(i, nsIAccessible);
// nsIAccessible::parent
@ -433,7 +510,7 @@ function testAccessibleTree(aAccOrElmOrID, aAccTree)
"Wrong previous sibling of " + prettyName(child));
// Go down through subtree
testAccessibleTree(child, accTree.children[i]);
testAccessibleTree(child, accTree.children[i], aFlags);
}
}
}

View File

@ -13,6 +13,7 @@ include $(DEPTH)/config/autoconf.mk
MOCHITEST_A11Y_FILES =\
test_figure.html \
test_HTMLSpec.html \
test_listbox.xul \
test_nsApplicationAcc.html \
test_plugin.html \

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@ const ROLE_DIALOG = nsIAccessibleRole.ROLE_DIALOG;
const ROLE_DOCUMENT = nsIAccessibleRole.ROLE_DOCUMENT;
const ROLE_EMBEDDED_OBJECT = nsIAccessibleRole.ROLE_EMBEDDED_OBJECT;
const ROLE_ENTRY = nsIAccessibleRole.ROLE_ENTRY;
const ROLE_EQUATION = nsIAccessibleRole.ROLE_EQUATION;
const ROLE_FIGURE = nsIAccessibleRole.ROLE_FIGURE;
const ROLE_FOOTER = nsIAccessibleRole.ROLE_FOOTER;
const ROLE_FLAT_EQUATION = nsIAccessibleRole.ROLE_FLAT_EQUATION;

View File

@ -78,8 +78,10 @@ function testStates(aAccOrElmOrID, aState, aExtraState, aAbsentState,
var id = prettyName(aAccOrElmOrID) + (aTestName ? " [" + aTestName + "]": "");
// Primary test.
isState(state & aState, aState, false,
"wrong state bits for " + id + "!");
if (aState) {
isState(state & aState, aState, false,
"wrong state bits for " + id + "!");
}
if (aExtraState)
isState(extraState & aExtraState, aExtraState, true,

View File

@ -11,6 +11,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>

View File

@ -20,6 +20,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>

View File

@ -10,6 +10,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>

View File

@ -10,6 +10,8 @@
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../events.js"></script>

View File

@ -1,4 +1,4 @@
{
"revision": "78decf03b39ded18b914d57f4f3152d6f1b4c56a",
"revision": "f98ec5e292dffd144f0a6520cc18ff5cb7762d09",
"repo_path": "/integration/gaia-central"
}

View File

@ -336,7 +336,7 @@ pref("browser.download.manager.scanWhenDone", true);
pref("browser.download.manager.resumeOnWakeDelay", 10000);
// Enables the asynchronous Downloads API in the Downloads Panel.
pref("browser.download.useJSTransfer", false);
pref("browser.download.useJSTransfer", true);
// This allows disabling the Downloads Panel in favor of the old interface.
pref("browser.download.useToolkitUI", false);

View File

@ -170,6 +170,10 @@ window.addEventListener("pageshow", function () {
window.gObserver.observe(document.documentElement, { attributes: true });
fitToWidth();
window.addEventListener("resize", fitToWidth);
// Ask chrome to update snippets.
var event = new CustomEvent("AboutHomeLoad", {bubbles:true});
document.dispatchEvent(event);
});
window.addEventListener("pagehide", function() {

View File

@ -84,9 +84,6 @@ this.__defineSetter__("PluralForm", function (val) {
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
"resource://gre/modules/TelemetryStopwatch.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AboutHomeUtils",
"resource:///modules/AboutHomeUtils.jsm");
#ifdef MOZ_SERVICES_SYNC
XPCOMUtils.defineLazyModuleGetter(this, "Weave",
"resource://services-sync/main.js");
@ -1284,6 +1281,7 @@ var gBrowserInit = {
// Bug 862519 - Backspace doesn't work in electrolysis builds.
// We bypass the problem by disabling the backspace-to-go-back command.
document.getElementById("cmd_handleBackspace").setAttribute("disabled", true);
document.getElementById("key_delete").setAttribute("disabled", true);
}
SessionStore.promiseInitialized.then(() => {
@ -2314,64 +2312,6 @@ function PageProxyClickHandler(aEvent)
middleMousePaste(aEvent);
}
/**
* Handle load of some pages (about:*) so that we can make modifications
* to the DOM for unprivileged pages.
*/
function BrowserOnAboutPageLoad(doc) {
if (doc.documentURI.toLowerCase() == "about:home") {
// XXX bug 738646 - when Marketplace is launched, remove this statement and
// the hidden attribute set on the apps button in aboutHome.xhtml
if (getBoolPref("browser.aboutHome.apps", false))
doc.getElementById("apps").removeAttribute("hidden");
let ss = Components.classes["@mozilla.org/browser/sessionstore;1"].
getService(Components.interfaces.nsISessionStore);
if (ss.canRestoreLastSession &&
!PrivateBrowsingUtils.isWindowPrivate(window))
doc.getElementById("launcher").setAttribute("session", "true");
// Inject search engine and snippets URL.
let docElt = doc.documentElement;
// set the following attributes BEFORE searchEngineURL, which triggers to
// show the snippets when it's set.
docElt.setAttribute("snippetsURL", AboutHomeUtils.snippetsURL);
if (AboutHomeUtils.showKnowYourRights) {
docElt.setAttribute("showKnowYourRights", "true");
// Set pref to indicate we've shown the notification.
let currentVersion = Services.prefs.getIntPref("browser.rights.version");
Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
}
docElt.setAttribute("snippetsVersion", AboutHomeUtils.snippetsVersion);
let updateSearchEngine = function() {
let engine = AboutHomeUtils.defaultSearchEngine;
docElt.setAttribute("searchEngineName", engine.name);
docElt.setAttribute("searchEnginePostData", engine.postDataString || "");
// Again, keep the searchEngineURL as the last attribute, because the
// mutation observer in aboutHome.js is counting on that.
docElt.setAttribute("searchEngineURL", engine.searchURL);
};
updateSearchEngine();
// Listen for the event that's triggered when the user changes search engine.
// At this point we simply reload about:home to reflect the change.
Services.obs.addObserver(updateSearchEngine, "browser-search-engine-modified", false);
// Remove the observer when the page is reloaded or closed.
doc.defaultView.addEventListener("pagehide", function removeObserver() {
doc.defaultView.removeEventListener("pagehide", removeObserver);
Services.obs.removeObserver(updateSearchEngine, "browser-search-engine-modified");
}, false);
#ifdef MOZ_SERVICES_HEALTHREPORT
doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
BrowserSearch.recordSearchInHealthReport(e.detail, "abouthome");
}, true, true);
#endif
}
}
/**
* Handle command events bubbling up from error page content
*/
@ -2396,9 +2336,6 @@ let BrowserOnClick = {
else if (ownerDoc.documentURI.startsWith("about:neterror")) {
this.onAboutNetError(originalTarget, ownerDoc);
}
else if (ownerDoc.documentURI.toLowerCase() == "about:home") {
this.onAboutHome(originalTarget, ownerDoc);
}
},
onAboutCertError: function BrowserOnClick_onAboutCertError(aTargetElm, aOwnerDoc) {
@ -2575,49 +2512,6 @@ let BrowserOnClick = {
return;
Services.io.offline = false;
},
onAboutHome: function BrowserOnClick_onAboutHome(aTargetElm, aOwnerDoc) {
let elmId = aTargetElm.getAttribute("id");
switch (elmId) {
case "restorePreviousSession":
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
if (ss.canRestoreLastSession) {
ss.restoreLastSession();
}
aOwnerDoc.getElementById("launcher").removeAttribute("session");
break;
case "downloads":
BrowserDownloadsUI();
break;
case "bookmarks":
PlacesCommandHook.showPlacesOrganizer("AllBookmarks");
break;
case "history":
PlacesCommandHook.showPlacesOrganizer("History");
break;
case "apps":
openUILinkIn("https://marketplace.mozilla.org/", "tab");
break;
case "addons":
BrowserOpenAddonsMgr();
break;
case "sync":
openPreferences("paneSync");
break;
case "settings":
openPreferences();
break;
}
},
};
/**
@ -4297,6 +4191,7 @@ var TabsProgressListener = {
Components.isSuccessCode(aStatus) &&
doc.documentURI.startsWith("about:") &&
!doc.documentURI.toLowerCase().startsWith("about:blank") &&
!doc.documentURI.toLowerCase().startsWith("about:home") &&
!doc.documentElement.hasAttribute("hasBrowserHandlers")) {
// STATE_STOP may be received twice for documents, thus store an
// attribute to ensure handling it just once.
@ -4310,9 +4205,6 @@ var TabsProgressListener = {
if (event.target.documentElement)
event.target.documentElement.removeAttribute("hasBrowserHandlers");
}, true);
// We also want to make changes to page UI for unprivileged about pages.
BrowserOnAboutPageLoad(doc);
}
},

View File

@ -13,6 +13,8 @@ XPCOMUtils.defineLazyModuleGetter(this,
"LoginManagerContent", "resource://gre/modules/LoginManagerContent.jsm");
XPCOMUtils.defineLazyModuleGetter(this,
"InsecurePasswordUtils", "resource://gre/modules/InsecurePasswordUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
// Bug 671101 - directly using webNavigation in this context
// causes docshells to leak
@ -55,6 +57,135 @@ if (Services.prefs.getBoolPref("browser.tabs.remote")) {
});
}
let AboutHomeListener = {
init: function(chromeGlobal) {
let self = this;
chromeGlobal.addEventListener('AboutHomeLoad', function(e) { self.onPageLoad(); }, false, true);
},
handleEvent: function(aEvent) {
switch (aEvent.type) {
case "AboutHomeLoad":
this.onPageLoad();
break;
}
},
receiveMessage: function(aMessage) {
switch (aMessage.name) {
case "AboutHome:Update":
this.onUpdate(aMessage.data);
break;
}
},
onUpdate: function(aData) {
let doc = content.document;
if (doc.documentURI.toLowerCase() != "about:home")
return;
if (aData.showRestoreLastSession && !PrivateBrowsingUtils.isWindowPrivate(content))
doc.getElementById("launcher").setAttribute("session", "true");
// Inject search engine and snippets URL.
let docElt = doc.documentElement;
// set the following attributes BEFORE searchEngineURL, which triggers to
// show the snippets when it's set.
docElt.setAttribute("snippetsURL", aData.snippetsURL);
if (aData.showKnowYourRights)
docElt.setAttribute("showKnowYourRights", "true");
docElt.setAttribute("snippetsVersion", aData.snippetsVersion);
let engine = aData.defaultSearchEngine;
docElt.setAttribute("searchEngineName", engine.name);
docElt.setAttribute("searchEnginePostData", engine.postDataString || "");
// Again, keep the searchEngineURL as the last attribute, because the
// mutation observer in aboutHome.js is counting on that.
docElt.setAttribute("searchEngineURL", engine.searchURL);
},
onPageLoad: function() {
let doc = content.document;
if (doc.documentURI.toLowerCase() != "about:home" ||
doc.documentElement.hasAttribute("hasBrowserHandlers")) {
return;
}
doc.documentElement.setAttribute("hasBrowserHandlers", "true");
let updateListener = this;
addMessageListener("AboutHome:Update", updateListener);
addEventListener("click", this.onClick, true);
addEventListener("pagehide", function onPageHide(event) {
if (event.target.defaultView.frameElement)
return;
removeMessageListener("AboutHome:Update", updateListener);
removeEventListener("click", this.onClick, true);
removeEventListener("pagehide", onPageHide, true);
if (event.target.documentElement)
event.target.documentElement.removeAttribute("hasBrowserHandlers");
}, true);
// XXX bug 738646 - when Marketplace is launched, remove this statement and
// the hidden attribute set on the apps button in aboutHome.xhtml
if (Services.prefs.getPrefType("browser.aboutHome.apps") == Services.prefs.PREF_BOOL &&
Services.prefs.getBoolPref("browser.aboutHome.apps"))
doc.getElementById("apps").removeAttribute("hidden");
sendAsyncMessage("AboutHome:RequestUpdate");
doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
sendAsyncMessage("AboutHome:Search", { engineName: e.detail });
}, true, true);
},
onClick: function(aEvent) {
if (!aEvent.isTrusted || // Don't trust synthetic events
aEvent.button == 2 || aEvent.target.localName != "button") {
return;
}
let originalTarget = aEvent.originalTarget;
let ownerDoc = originalTarget.ownerDocument;
let elmId = originalTarget.getAttribute("id");
switch (elmId) {
case "restorePreviousSession":
sendAsyncMessage("AboutHome:RestorePreviousSession");
ownerDoc.getElementById("launcher").removeAttribute("session");
break;
case "downloads":
sendAsyncMessage("AboutHome:Downloads");
break;
case "bookmarks":
sendAsyncMessage("AboutHome:Bookmarks");
break;
case "history":
sendAsyncMessage("AboutHome:History");
break;
case "apps":
sendAsyncMessage("AboutHome:Apps");
break;
case "addons":
sendAsyncMessage("AboutHome:Addons");
break;
case "sync":
sendAsyncMessage("AboutHome:Sync");
break;
case "settings":
sendAsyncMessage("AboutHome:Settings");
break;
}
},
};
AboutHomeListener.init(this);
var global = this;

View File

@ -87,7 +87,8 @@ Sanitizer.prototype = {
item.clear();
} catch(er) {
seenError = true;
Cu.reportError("Error sanitizing " + itemName + ": " + er + "\n");
Components.utils.reportError("Error sanitizing " + itemName +
": " + er + "\n");
}
onItemComplete();
};
@ -321,7 +322,7 @@ Sanitizer.prototype = {
let privateList = yield Downloads.getPrivateDownloadList();
privateList.removeFinished(filterByTime);
}.bind(this)).then(null, Cu.reportError);
}.bind(this)).then(null, Components.utils.reportError);
}
else {
var dlMgr = Components.classes["@mozilla.org/download-manager;1"]

View File

@ -7,7 +7,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise",
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AboutHomeUtils",
"resource:///modules/AboutHomeUtils.jsm");
"resource:///modules/AboutHome.jsm");
let gRightsVersion = Services.prefs.getIntPref("browser.rights.version");
@ -106,14 +106,17 @@ let gTests = [
let doc = gBrowser.contentDocument;
let engineName = doc.documentElement.getAttribute("searchEngineName");
// We rely on the listener in browser.js being installed and fired before
// this one. If this ever changes, we should add an executeSoon() or similar.
doc.addEventListener("AboutHomeSearchEvent", function onSearch(e) {
is(e.detail, engineName, "Detail is search engine name");
getNumberOfSearches(engineName).then(num => {
is(num, numSearchesBefore + 1, "One more search recorded.");
deferred.resolve();
// We use executeSoon() to ensure that this code runs after the
// count has been updated in browser.js, since it uses the same
// event.
executeSoon(function () {
getNumberOfSearches(engineName).then(num => {
is(num, numSearchesBefore + 1, "One more search recorded.");
deferred.resolve();
});
});
}, true, true);
@ -275,19 +278,35 @@ let gTests = [
if (engine.name != "POST Search")
return;
Services.search.defaultEngine = engine;
registerCleanupFunction(function() {
Services.search.removeEngine(engine);
Services.search.defaultEngine = currEngine;
});
// Ready to execute the tests!
let needle = "Search for something awesome.";
let document = gBrowser.selectedTab.linkedBrowser.contentDocument;
let searchText = document.getElementById("searchText");
// We're about to change the search engine. Once the change has
// propagated to the about:home content, we want to perform a search.
let mutationObserver = new MutationObserver(function (mutations) {
for (let mutation of mutations) {
if (mutation.attributeName == "searchEngineURL") {
searchText.value = needle;
searchText.focus();
EventUtils.synthesizeKey("VK_RETURN", {});
}
}
});
mutationObserver.observe(document.documentElement, { attributes: true });
// Change the search engine, triggering the observer above.
Services.search.defaultEngine = engine;
registerCleanupFunction(function() {
mutationObserver.disconnect();
Services.search.removeEngine(engine);
Services.search.defaultEngine = currEngine;
});
// When the search results load, check them for correctness.
waitForLoad(function() {
let loadedText = gBrowser.contentDocument.body.textContent;
ok(loadedText, "search page loaded");
@ -295,10 +314,6 @@ let gTests = [
"Search text should arrive correctly");
deferred.resolve();
});
searchText.value = needle;
searchText.focus();
EventUtils.synthesizeKey("VK_RETURN", {});
};
Services.obs.addObserver(searchObserver, "browser-search-engine-modified", false);
registerCleanupFunction(function () {

View File

@ -4,8 +4,6 @@ Cu.import("resource://gre/modules/Services.jsm");
// Bug 453440 - Test the timespan-based logic of the sanitizer code
var now_uSec = Date.now() * 1000;
const dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
const kUsecPerMin = 60 * 1000000;
let tempScope = {};
@ -14,6 +12,7 @@ Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
let Sanitizer = tempScope.Sanitizer;
let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory;
let Downloads = (Components.utils.import("resource://gre/modules/Downloads.jsm", {})).Downloads;
function promiseFormHistoryRemoved() {
let deferred = Promise.defer();
@ -24,11 +23,26 @@ function promiseFormHistoryRemoved() {
return deferred.promise;
}
function promiseDownloadRemoved(list) {
let deferred = Promise.defer();
let view = {
onDownloadRemoved: function(download) {
list.removeView(view);
deferred.resolve();
}
};
list.addView(view);
return deferred.promise;
}
function test() {
waitForExplicitFinish();
Task.spawn(function() {
setupDownloads();
yield setupDownloads();
yield setupFormHistory();
yield setupHistory();
yield onHistoryReady();
@ -80,12 +94,16 @@ function onHistoryReady() {
itemPrefs.setBoolPref("sessions", false);
itemPrefs.setBoolPref("siteSettings", false);
let publicList = yield Downloads.getPublicDownloadList();
let downloadPromise = promiseDownloadRemoved(publicList);
// Clear 10 minutes ago
s.range = [now_uSec - 10*60*1000000, now_uSec];
s.sanitize();
s.range = null;
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://10minutes.com"))),
"Pretend visit to 10minutes.com should now be deleted");
@ -122,23 +140,27 @@ function onHistoryReady() {
yield countEntries("today", "today form entry should still exist", checkOne);
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(!downloadExists(5555555), "10 minute download should now be deleted");
ok(downloadExists(5555551), "<1 hour download should still be present");
ok(downloadExists(5555556), "1 hour 10 minute download should still be present");
ok(downloadExists(5555550), "Year old download should still be present");
ok(downloadExists(5555552), "<2 hour old download should still be present");
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
ok(downloadExists(5555553), "<4 hour old download should still be present");
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
let downloads = yield publicList.getAll();
ok(!(yield downloadExists(publicList, "fakefile-10-minutes")), "10 minute download should now be deleted");
ok((yield downloadExists(publicList, "fakefile-1-hour")), "<1 hour download should still be present");
ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
if (minutesSinceMidnight > 10)
ok(downloadExists(5555554), "'Today' download should still be present");
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Clear 1 hour
Sanitizer.prefs.setIntPref("timeSpan", 1);
s.sanitize();
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://1hour.com"))),
"Pretend visit to 1hour.com should now be deleted");
@ -169,23 +191,26 @@ function onHistoryReady() {
yield countEntries("today", "today form entry should still exist", checkOne);
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(!downloadExists(5555551), "<1 hour download should now be deleted");
ok(downloadExists(5555556), "1 hour 10 minute download should still be present");
ok(downloadExists(5555550), "Year old download should still be present");
ok(downloadExists(5555552), "<2 hour old download should still be present");
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
ok(downloadExists(5555553), "<4 hour old download should still be present");
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
ok(!(yield downloadExists(publicList, "fakefile-1-hour")), "<1 hour download should now be deleted");
ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
if (hoursSinceMidnight > 1)
ok(downloadExists(5555554), "'Today' download should still be present");
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Clear 1 hour 10 minutes
s.range = [now_uSec - 70*60*1000000, now_uSec];
s.sanitize();
s.range = null;
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://1hour10minutes.com"))),
"Pretend visit to 1hour10minutes.com should now be deleted");
@ -213,20 +238,23 @@ function onHistoryReady() {
yield countEntries("today", "today form entry should still exist", checkOne);
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(!downloadExists(5555556), "1 hour 10 minute old download should now be deleted");
ok(downloadExists(5555550), "Year old download should still be present");
ok(downloadExists(5555552), "<2 hour old download should still be present");
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
ok(downloadExists(5555553), "<4 hour old download should still be present");
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
ok(!(yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute old download should now be deleted");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
if (minutesSinceMidnight > 70)
ok(downloadExists(5555554), "'Today' download should still be present");
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Clear 2 hours
Sanitizer.prefs.setIntPref("timeSpan", 2);
s.sanitize();
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://2hour.com"))),
"Pretend visit to 2hour.com should now be deleted");
@ -251,20 +279,23 @@ function onHistoryReady() {
yield countEntries("today", "today form entry should still exist", checkOne);
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(!downloadExists(5555552), "<2 hour old download should now be deleted");
ok(downloadExists(5555550), "Year old download should still be present");
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
ok(downloadExists(5555553), "<4 hour old download should still be present");
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
ok(!(yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should now be deleted");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
if (hoursSinceMidnight > 2)
ok(downloadExists(5555554), "'Today' download should still be present");
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Clear 2 hours 10 minutes
s.range = [now_uSec - 130*60*1000000, now_uSec];
s.sanitize();
s.range = null;
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))),
"Pretend visit to 2hour10minutes.com should now be deleted");
@ -286,18 +317,21 @@ function onHistoryReady() {
yield countEntries("today", "today form entry should still exist", checkOne);
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(!downloadExists(5555557), "2 hour 10 minute old download should now be deleted");
ok(downloadExists(5555553), "<4 hour old download should still be present");
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
ok(downloadExists(5555550), "Year old download should still be present");
ok(!(yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute old download should now be deleted");
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
if (minutesSinceMidnight > 130)
ok(downloadExists(5555554), "'Today' download should still be present");
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Clear 4 hours
Sanitizer.prefs.setIntPref("timeSpan", 3);
s.sanitize();
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://4hour.com"))),
"Pretend visit to 4hour.com should now be deleted");
@ -316,11 +350,13 @@ function onHistoryReady() {
yield countEntries("today", "today form entry should still exist", checkOne);
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(!downloadExists(5555553), "<4 hour old download should now be deleted");
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
ok(downloadExists(5555550), "Year old download should still be present");
ok(!(yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should now be deleted");
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
if (hoursSinceMidnight > 4)
ok(downloadExists(5555554), "'Today' download should still be present");
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Clear 4 hours 10 minutes
s.range = [now_uSec - 250*60*1000000, now_uSec];
@ -328,6 +364,7 @@ function onHistoryReady() {
s.range = null;
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))),
"Pretend visit to 4hour10minutes.com should now be deleted");
@ -343,16 +380,19 @@ function onHistoryReady() {
yield countEntries("today", "today form entry should still exist", checkOne);
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(!downloadExists(5555558), "4 hour 10 minute download should now be deleted");
ok(downloadExists(5555550), "Year old download should still be present");
ok(!(yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should now be deleted");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
if (minutesSinceMidnight > 250)
ok(downloadExists(5555554), "'Today' download should still be present");
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Clear Today
Sanitizer.prefs.setIntPref("timeSpan", 4);
s.sanitize();
yield promiseFormHistoryRemoved();
yield downloadPromise;
// Be careful. If we add our objectss just before midnight, and sanitize
// runs immediately after, they won't be expired. This is expected, but
@ -365,26 +405,29 @@ function onHistoryReady() {
"Pretend visit to today.com should now be deleted");
yield countEntries("today", "today form entry should be deleted", checkZero);
ok(!downloadExists(5555554), "'Today' download should now be deleted");
ok(!(yield downloadExists(publicList, "fakefile-today")), "'Today' download should now be deleted");
}
ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))),
"Pretend visit to before-today.com should still exist");
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
ok(downloadExists(5555550), "Year old download should still be present");
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
downloadPromise = promiseDownloadRemoved(publicList);
// Choose everything
Sanitizer.prefs.setIntPref("timeSpan", 0);
s.sanitize();
yield promiseFormHistoryRemoved();
yield downloadPromise;
ok(!(yield promiseIsURIVisited(makeURI("http://before-today.com"))),
"Pretend visit to before-today.com should now be deleted");
yield countEntries("b4today", "b4today form entry should be deleted", checkZero);
ok(!downloadExists(5555550), "Year old download should now be deleted");
ok(!(yield downloadExists(publicList, "fakefile-old")), "Year old download should now be deleted");
}
function setupHistory() {
@ -562,227 +605,103 @@ function setupFormHistory() {
function setupDownloads() {
// Add 10-minutes download to DB
let data = {
id: "5555555",
name: "fakefile-10-minutes",
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
target: "fakefile-10-minutes",
startTime: now_uSec - 10 * kUsecPerMin, // 10 minutes ago, in uSec
endTime: now_uSec - 11 * kUsecPerMin, // 1 minute later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "a1bcD23eF4g5"
};
let publicList = yield Downloads.getPublicDownloadList();
let db = dm.DBConnection;
let stmt = db.createStatement(
"INSERT INTO moz_downloads (id, name, source, target, startTime, endTime, " +
"state, currBytes, maxBytes, preferredAction, autoResume, guid) " +
"VALUES (:id, :name, :source, :target, :startTime, :endTime, :state, " +
":currBytes, :maxBytes, :preferredAction, :autoResume, :guid)");
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
// Add within-1-hour download to DB
data = {
id: "5555551",
name: "fakefile-1-hour",
let download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
target: "fakefile-10-minutes"
});
download.startTime = new Date(now_uSec - 10 * kUsecPerMin), // 10 minutes ago, in uSec
download.canceled = true;
publicList.add(download);
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
target: "fakefile-1-hour",
startTime: now_uSec - 45 * kUsecPerMin, // 45 minutes ago, in uSec
endTime: now_uSec - 44 * kUsecPerMin, // 1 minute later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "1bcD23eF4g5a"
};
target: "fakefile-1-hour"
});
download.startTime = new Date(now_uSec - 45 * kUsecPerMin), // 45 minutes ago, in uSec
download.canceled = true;
publicList.add(download);
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
// Add 1-hour-10-minutes download to DB
data = {
id: "5555556",
name: "fakefile-1-hour-10-minutes",
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
target: "fakefile-1-hour-10-minutes",
startTime: now_uSec - 70 * kUsecPerMin, // 70 minutes ago, in uSec
endTime: now_uSec - 71 * kUsecPerMin, // 1 minute later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "a1cbD23e4Fg5"
};
target: "fakefile-1-hour-10-minutes"
});
download.startTime = new Date(now_uSec - 70 * kUsecPerMin), // 70 minutes ago, in uSec
download.canceled = true;
publicList.add(download);
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
// Add within-2-hour download
data = {
id: "5555552",
name: "fakefile-2-hour",
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
target: "fakefile-2-hour",
startTime: now_uSec - 90 * kUsecPerMin, // 90 minutes ago, in uSec
endTime: now_uSec - 89 * kUsecPerMin, // 1 minute later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "b1aDc23eFg54"
};
target: "fakefile-2-hour"
});
download.startTime = new Date(now_uSec - 90 * kUsecPerMin), // 90 minutes ago, in uSec
download.canceled = true;
publicList.add(download);
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
// Add 2-hour-10-minutes download
data = {
id: "5555557",
name: "fakefile-2-hour-10-minutes",
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
target: "fakefile-2-hour-10-minutes",
startTime: now_uSec - 130 * kUsecPerMin, // 130 minutes ago, in uSec
endTime: now_uSec - 131 * kUsecPerMin, // 1 minute later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "z1bcD23eF4g5"
};
target: "fakefile-2-hour-10-minutes"
});
download.startTime = new Date(now_uSec - 130 * kUsecPerMin), // 130 minutes ago, in uSec
download.canceled = true;
publicList.add(download);
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
// Add within-4-hour download
data = {
id: "5555553",
name: "fakefile-4-hour",
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
target: "fakefile-4-hour",
startTime: now_uSec - 180 * kUsecPerMin, // 180 minutes ago, in uSec
endTime: now_uSec - 179 * kUsecPerMin, // 1 minute later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "zzzcD23eF4g5"
};
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
// Add 4-hour-10-minutes download
data = {
id: "5555558",
name: "fakefile-4-hour-10-minutes",
target: "fakefile-4-hour"
});
download.startTime = new Date(now_uSec - 180 * kUsecPerMin), // 180 minutes ago, in uSec
download.canceled = true;
publicList.add(download);
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
target: "fakefile-4-hour-10-minutes",
startTime: now_uSec - 250 * kUsecPerMin, // 250 minutes ago, in uSec
endTime: now_uSec - 251 * kUsecPerMin, // 1 minute later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "z1bzz23eF4gz"
};
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
target: "fakefile-4-hour-10-minutes"
});
download.startTime = new Date(now_uSec - 250 * kUsecPerMin), // 250 minutes ago, in uSec
download.canceled = true;
publicList.add(download);
// Add "today" download
let today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(1);
data = {
id: "5555554",
name: "fakefile-today",
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
target: "fakefile-today",
startTime: today.getTime() * 1000, // 12:00:30am this morning, in uSec
endTime: (today.getTime() + 1000) * 1000, // 1 second later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "ffffD23eF4g5"
};
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.reset();
}
target: "fakefile-today"
});
download.startTime = new Date(today.getTime() * 1000), // 12:00:30am this morning, in uSec
download.canceled = true;
publicList.add(download);
// Add "before today" download
let lastYear = new Date();
lastYear.setFullYear(lastYear.getFullYear() - 1);
data = {
id: "5555550",
name: "fakefile-old",
download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
target: "fakefile-old",
startTime: lastYear.getTime() * 1000, // 1 year ago, in uSec
endTime: (lastYear.getTime() + 1000) * 1000, // 1 second later
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
guid: "ggggg23eF4g5"
};
try {
for (let prop in data)
stmt.params[prop] = data[prop];
stmt.execute();
}
finally {
stmt.finalize();
}
target: "fakefile-old"
});
download.startTime = new Date(lastYear.getTime() * 1000), // 1 year ago, in uSec
download.canceled = true;
publicList.add(download);
// Confirm everything worked
ok(downloadExists(5555550), "Pretend download for everything case should exist");
ok(downloadExists(5555555), "Pretend download for 10-minutes case should exist");
ok(downloadExists(5555551), "Pretend download for 1-hour case should exist");
ok(downloadExists(5555556), "Pretend download for 1-hour-10-minutes case should exist");
ok(downloadExists(5555552), "Pretend download for 2-hour case should exist");
ok(downloadExists(5555557), "Pretend download for 2-hour-10-minutes case should exist");
ok(downloadExists(5555553), "Pretend download for 4-hour case should exist");
ok(downloadExists(5555558), "Pretend download for 4-hour-10-minutes case should exist");
ok(downloadExists(5555554), "Pretend download for Today case should exist");
let downloads = yield publicList.getAll();
is(downloads.length, 9, "9 Pretend downloads added");
ok((yield downloadExists(publicList, "fakefile-old")), "Pretend download for everything case should exist");
ok((yield downloadExists(publicList, "fakefile-10-minutes")), "Pretend download for 10-minutes case should exist");
ok((yield downloadExists(publicList, "fakefile-1-hour")), "Pretend download for 1-hour case should exist");
ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "Pretend download for 1-hour-10-minutes case should exist");
ok((yield downloadExists(publicList, "fakefile-2-hour")), "Pretend download for 2-hour case should exist");
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "Pretend download for 2-hour-10-minutes case should exist");
ok((yield downloadExists(publicList, "fakefile-4-hour")), "Pretend download for 4-hour case should exist");
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "Pretend download for 4-hour-10-minutes case should exist");
ok((yield downloadExists(publicList, "fakefile-today")), "Pretend download for Today case should exist");
}
/**
@ -791,18 +710,12 @@ function setupDownloads() {
* @param aID
* The ids of the downloads to check.
*/
function downloadExists(aID)
function downloadExists(list, path)
{
let db = dm.DBConnection;
let stmt = db.createStatement(
"SELECT * " +
"FROM moz_downloads " +
"WHERE id = :id"
);
stmt.params.id = aID;
var rows = stmt.executeStep();
stmt.finalize();
return rows;
return Task.spawn(function() {
let listArray = yield list.getAll();
throw new Task.Result(listArray.some(i => i.target.path == path));
});
}
function isToday(aDate) {

View File

@ -21,18 +21,17 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
"resource://gre/modules/FormHistory.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
"resource://gre/modules/Downloads.jsm");
let tempScope = {};
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
.loadSubScript("chrome://browser/content/sanitize.js", tempScope);
let Sanitizer = tempScope.Sanitizer;
const dm = Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager);
const kUsecPerMin = 60 * 1000000;
let formEntries;
let formEntries, downloadIDs, olderDownloadIDs;
// Add tests here. Each is a function that's called by doNextTest().
var gAllTests = [
@ -92,6 +91,23 @@ var gAllTests = [
});
},
function () {
// Add downloads (within the past hour).
Task.spawn(function () {
downloadIDs = [];
for (let i = 0; i < 5; i++) {
yield addDownloadWithMinutesAgo(downloadIDs, i);
}
// Add downloads (over an hour ago).
olderDownloadIDs = [];
for (let i = 0; i < 5; i++) {
yield addDownloadWithMinutesAgo(olderDownloadIDs, 61 + i);
}
doNextTest();
}).then(null, Components.utils.reportError);
},
/**
* Ensures that the combined history-downloads checkbox clears both history
* visits and downloads when checked; the dialog respects simple timespan.
@ -115,16 +131,6 @@ var gAllTests = [
}
addVisits(places, function() {
// Add downloads (within the past hour).
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
// Add downloads (over an hour ago).
let olderDownloadIDs = [];
for (let i = 0; i < 5; i++) {
olderDownloadIDs.push(addDownloadWithMinutesAgo(61 + i));
}
let totalHistoryVisits = uris.length + olderURIs.length;
let wh = new WindowHelper();
@ -146,16 +152,16 @@ var gAllTests = [
wh.onunload = function () {
// History visits and downloads within one hour should be cleared.
yield promiseHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
yield ensureDownloadsClearedState(downloadIDs, true);
// Visits and downloads > 1 hour should still exist.
yield promiseHistoryClearedState(olderURIs, false);
ensureDownloadsClearedState(olderDownloadIDs, false);
yield ensureDownloadsClearedState(olderDownloadIDs, false);
// OK, done, cleanup after ourselves.
yield blankSlate();
yield promiseHistoryClearedState(olderURIs, true);
ensureDownloadsClearedState(olderDownloadIDs, true);
yield ensureDownloadsClearedState(olderDownloadIDs, true);
};
wh.open();
});
@ -178,6 +184,18 @@ var gAllTests = [
iter.next();
},
function () {
// Add downloads (within the past hour).
Task.spawn(function () {
downloadIDs = [];
for (let i = 0; i < 5; i++) {
yield addDownloadWithMinutesAgo(downloadIDs, i);
}
doNextTest();
}).then(null, Components.utils.reportError);
},
/**
* Ensures that the combined history-downloads checkbox removes neither
* history visits nor downloads when not checked.
@ -194,11 +212,6 @@ var gAllTests = [
}
addVisits(places, function() {
let downloadIDs = [];
for (let i = 0; i < 5; i++) {
downloadIDs.push(addDownloadWithMinutesAgo(i));
}
let wh = new WindowHelper();
wh.onload = function () {
is(this.isWarningPanelVisible(), false,
@ -224,7 +237,7 @@ var gAllTests = [
wh.onunload = function () {
// Of the three only form entries should be cleared.
yield promiseHistoryClearedState(uris, false);
ensureDownloadsClearedState(downloadIDs, false);
yield ensureDownloadsClearedState(downloadIDs, false);
formEntries.forEach(function (entry) {
let exists = yield formNameExists(entry);
@ -234,7 +247,7 @@ var gAllTests = [
// OK, done, cleanup after ourselves.
yield blankSlate();
yield promiseHistoryClearedState(uris, true);
ensureDownloadsClearedState(downloadIDs, true);
yield ensureDownloadsClearedState(downloadIDs, true);
};
wh.open();
});
@ -639,10 +652,6 @@ var gAllTests = [
}
];
// Used as the download database ID for a new download. Incremented for each
// new download. See addDownloadWithMinutesAgo().
var gDownloadId = 5555551;
// Index in gAllTests of the test currently being run. Incremented for each
// test run. See doNextTest().
var gCurrTest = 0;
@ -847,7 +856,7 @@ WindowHelper.prototype = {
if (wh.onunload) {
Task.spawn(wh.onunload).then(function() {
waitForAsyncUpdates(doNextTest);
});
}).then(null, Components.utils.reportError);
} else {
waitForAsyncUpdates(doNextTest);
}
@ -900,40 +909,23 @@ WindowHelper.prototype = {
* @param aMinutesAgo
* The download will be downloaded this many minutes ago
*/
function addDownloadWithMinutesAgo(aMinutesAgo) {
function addDownloadWithMinutesAgo(aExpectedPathList, aMinutesAgo) {
let publicList = yield Downloads.getPublicDownloadList();
let name = "fakefile-" + aMinutesAgo + "-minutes-ago";
let data = {
id: gDownloadId,
name: name,
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
target: name,
startTime: now_uSec - (aMinutesAgo * kUsecPerMin),
endTime: now_uSec - ((aMinutesAgo + 1) * kUsecPerMin),
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0
};
let download = yield Downloads.createDownload({
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
target: name
});
download.startTime = now_uSec - (aMinutesAgo * kUsecPerMin);
download.canceled = true;
publicList.add(download);
let db = dm.DBConnection;
let stmt = db.createStatement(
"INSERT INTO moz_downloads (id, name, source, target, startTime, endTime, " +
"state, currBytes, maxBytes, preferredAction, autoResume) " +
"VALUES (:id, :name, :source, :target, :startTime, :endTime, :state, " +
":currBytes, :maxBytes, :preferredAction, :autoResume)");
try {
for (let prop in data) {
stmt.params[prop] = data[prop];
}
stmt.execute();
}
finally {
stmt.reset();
}
is(downloadExists(gDownloadId), true,
"Sanity check: download " + gDownloadId +
ok((yield downloadExists(name)),
"Sanity check: download " + name +
" should exist after creating it");
return gDownloadId++;
aExpectedPathList.push(name);
}
/**
@ -984,15 +976,37 @@ function formNameExists(name)
*/
function blankSlate() {
PlacesUtils.bhistory.removeAllPages();
dm.cleanUp();
// The promise is resolved only when removing both downloads and form history are done.
let deferred = Promise.defer();
let formHistoryDone = false, downloadsDone = false;
Task.spawn(function deleteAllDownloads() {
let publicList = yield Downloads.getPublicDownloadList();
let downloads = yield publicList.getAll();
for (let download of downloads) {
publicList.remove(download);
yield download.finalize(true);
}
downloadsDone = true;
if (formHistoryDone) {
deferred.resolve();
}
}).then(null, Components.utils.reportError);
FormHistory.update({ op: "remove" },
{ handleError: function (error) {
do_throw("Error occurred updating form history: " + error);
deferred.reject(error);
},
handleCompletion: function (reason) { if (!reason) deferred.resolve(); }
handleCompletion: function (reason) {
if (!reason) {
formHistoryDone = true;
if (downloadsDone) {
deferred.resolve();
}
}
}
});
return deferred.promise;
}
@ -1012,24 +1026,19 @@ function boolPrefIs(aPrefName, aExpectedVal, aMsg) {
}
/**
* Checks to see if the download with the specified ID exists.
* Checks to see if the download with the specified path exists.
*
* @param aID
* The ID of the download to check
* @param aPath
* The path of the download to check
* @return True if the download exists, false otherwise
*/
function downloadExists(aID)
function downloadExists(aPath)
{
let db = dm.DBConnection;
let stmt = db.createStatement(
"SELECT * " +
"FROM moz_downloads " +
"WHERE id = :id"
);
stmt.params.id = aID;
let rows = stmt.executeStep();
stmt.finalize();
return !!rows;
return Task.spawn(function() {
let publicList = yield Downloads.getPublicDownloadList();
let listArray = yield publicList.getAll();
throw new Task.Result(listArray.some(i => i.target.path == aPath));
});
}
/**
@ -1059,7 +1068,7 @@ function doNextTest() {
function ensureDownloadsClearedState(aDownloadIDs, aShouldBeCleared) {
let niceStr = aShouldBeCleared ? "no longer" : "still";
aDownloadIDs.forEach(function (id) {
is(downloadExists(id), !aShouldBeCleared,
is((yield downloadExists(id)), !aShouldBeCleared,
"download " + id + " should " + niceStr + " exist");
});
}

View File

@ -7,39 +7,33 @@
* Make sure the downloads panel can display items in the right order and
* contains the expected data.
*/
function gen_test()
function test_task()
{
// Display one of each download state.
const DownloadData = [
{ endTime: 1180493839859239, state: nsIDM.DOWNLOAD_NOTSTARTED },
{ endTime: 1180493839859238, state: nsIDM.DOWNLOAD_DOWNLOADING },
{ endTime: 1180493839859237, state: nsIDM.DOWNLOAD_PAUSED },
{ endTime: 1180493839859236, state: nsIDM.DOWNLOAD_SCANNING },
{ endTime: 1180493839859235, state: nsIDM.DOWNLOAD_QUEUED },
{ endTime: 1180493839859234, state: nsIDM.DOWNLOAD_FINISHED },
{ endTime: 1180493839859233, state: nsIDM.DOWNLOAD_FAILED },
{ endTime: 1180493839859232, state: nsIDM.DOWNLOAD_CANCELED },
{ endTime: 1180493839859231, state: nsIDM.DOWNLOAD_BLOCKED_PARENTAL },
{ endTime: 1180493839859230, state: nsIDM.DOWNLOAD_DIRTY },
{ endTime: 1180493839859229, state: nsIDM.DOWNLOAD_BLOCKED_POLICY },
{ state: nsIDM.DOWNLOAD_NOTSTARTED },
{ state: nsIDM.DOWNLOAD_PAUSED },
{ state: nsIDM.DOWNLOAD_FINISHED },
{ state: nsIDM.DOWNLOAD_FAILED },
{ state: nsIDM.DOWNLOAD_CANCELED },
];
// For testing purposes, show all the download items at once.
var originalCountLimit = DownloadsView.kItemCountLimit;
DownloadsView.kItemCountLimit = DownloadData.length;
registerCleanupFunction(function () {
DownloadsView.kItemCountLimit = originalCountLimit;
});
try {
// Ensure that state is reset in case previous tests didn't finish.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
yield task_resetState();
// For testing purposes, show all the download items at once.
var originalCountLimit = DownloadsView.kItemCountLimit;
DownloadsView.kItemCountLimit = DownloadData.length;
registerCleanupFunction(function () {
DownloadsView.kItemCountLimit = originalCountLimit;
});
// Populate the downloads database with the data required by this test.
for (let yy in gen_addDownloadRows(DownloadData)) yield undefined;
yield task_addDownloads(DownloadData);
// Open the user interface and wait for data to be fully loaded.
for (let yy in gen_openPanel(DownloadsCommon.getData(window))) yield undefined;
yield task_openPanel();
// Test item data and count. This also tests the ordering of the display.
let richlistbox = document.getElementById("downloadsListBox");
@ -47,16 +41,14 @@ function gen_test()
is(richlistbox.children.length, DownloadData.length,
"There is the correct number of richlistitems");
*/
for (let i = 0; i < richlistbox.children.length; i++) {
let element = richlistbox.children[i];
let itemCount = richlistbox.children.length;
for (let i = 0; i < itemCount; i++) {
let element = richlistbox.children[itemCount - i - 1];
let dataItem = new DownloadsViewItemController(element).dataItem;
is(dataItem.target, DownloadData[i].name, "Download names match up");
is(dataItem.state, DownloadData[i].state, "Download states match up");
is(dataItem.file, DownloadData[i].target, "Download targets match up");
is(dataItem.uri, DownloadData[i].source, "Download sources match up");
}
} finally {
// Clean up when the test finishes.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
yield task_resetState();
}
}

View File

@ -8,19 +8,19 @@
* download it notices. All subsequent downloads, even across sessions, should
* not open the panel automatically.
*/
function gen_test()
function test_task()
{
try {
// Ensure that state is reset in case previous tests didn't finish.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
yield task_resetState();
// With this set to false, we should automatically open the panel
// the first time a download is started.
// With this set to false, we should automatically open the panel the first
// time a download is started.
DownloadsCommon.getData(window).panelHasShownBefore = false;
prepareForPanelOpen();
let promise = promisePanelOpened();
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
yield undefined;
yield promise;
// If we got here, that means the panel opened.
DownloadsPanel.hidePanel();
@ -28,29 +28,26 @@ function gen_test()
ok(DownloadsCommon.getData(window).panelHasShownBefore,
"Should have recorded that the panel was opened on a download.")
// Next, make sure that if we start another download, we don't open
// the panel automatically.
panelShouldNotOpen();
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
yield waitFor(2);
} catch(e) {
ok(false, e);
// Next, make sure that if we start another download, we don't open the
// panel automatically.
let originalOnPopupShown = DownloadsPanel.onPopupShown;
DownloadsPanel.onPopupShown = function () {
originalOnPopupShown.apply(this, arguments);
ok(false, "Should not have opened the downloads panel.");
};
try {
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
// Wait 2 seconds to ensure that the panel does not open.
let deferTimeout = Promise.defer();
setTimeout(deferTimeout.resolve, 2000);
yield deferTimeout.promise;
} finally {
DownloadsPanel.onPopupShown = originalOnPopupShown;
}
} finally {
// Clean up when the test finishes.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
yield task_resetState();
}
}
/**
* Call this to record a test failure for the next time the downloads panel
* opens.
*/
function panelShouldNotOpen()
{
// Hook to wait until the test data has been loaded.
let originalOnViewLoadCompleted = DownloadsPanel.onViewLoadCompleted;
DownloadsPanel.onViewLoadCompleted = function () {
DownloadsPanel.onViewLoadCompleted = originalOnViewLoadCompleted;
ok(false, "Should not have opened the downloads panel.");
};
}

View File

@ -10,10 +10,16 @@
////////////////////////////////////////////////////////////////////////////////
//// Globals
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
"resource://gre/modules/Downloads.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
"resource:///modules/DownloadsCommon.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
const nsIDM = Ci.nsIDownloadManager;
let gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]);
@ -22,253 +28,85 @@ registerCleanupFunction(function () {
gTestTargetFile.remove(false);
});
/**
* This objects contains a property for each column in the downloads table.
*/
let gDownloadRowTemplate = {
name: "test-download.txt",
source: "http://www.example.com/test-download.txt",
target: NetUtil.newURI(gTestTargetFile).spec,
startTime: 1180493839859230,
endTime: 1180493839859234,
state: nsIDM.DOWNLOAD_FINISHED,
currBytes: 0,
maxBytes: -1,
preferredAction: 0,
autoResume: 0
};
////////////////////////////////////////////////////////////////////////////////
//// Infrastructure
// All test are run through the test runner.
function test()
{
testRunner.runTest(this.gen_test);
waitForExplicitFinish();
Task.spawn(test_task).then(null, ex => ok(false, ex)).then(finish);
}
/**
* Runs a browser-chrome test defined through a generator function.
*
* This object is a singleton, initialized automatically when this script is
* included. Every browser-chrome test file includes a new copy of this object.
*/
var testRunner = {
_testIterator: null,
_lastEventResult: undefined,
_testRunning: false,
_eventRaised: false,
// --- Main test runner ---
/**
* Runs the test described by the provided generator function asynchronously.
*
* Calling yield in the generator will cause it to wait until continueTest is
* called. The parameter provided to continueTest will be the return value of
* the yield operator.
*
* @param aGenerator
* Test generator function. The function will be called with no
* arguments to retrieve its iterator.
*/
runTest: function TR_runTest(aGenerator) {
waitForExplicitFinish();
testRunner._testIterator = aGenerator();
testRunner.continueTest();
},
/**
* Continues the currently running test.
*
* @param aEventResult
* This will be the return value of the yield operator in the test.
*/
continueTest: function TR_continueTest(aEventResult) {
// Store the last event result, or set it to undefined.
testRunner._lastEventResult = aEventResult;
// Never reenter the main loop, but notify that the event has been raised.
if (testRunner._testRunning) {
testRunner._eventRaised = true;
return;
}
// Enter the main iteration loop.
testRunner._testRunning = true;
try {
do {
// Call the iterator, but don't leave the loop if the expected event is
// raised during the execution of the generator.
testRunner._eventRaised = false;
testRunner._testIterator.send(testRunner._lastEventResult);
} while (testRunner._eventRaised);
}
catch (e) {
// This block catches exceptions raised by the generator, including the
// normal StopIteration exception. Unexpected exceptions are reported as
// test failures.
if (!(e instanceof StopIteration))
ok(false, e);
// In any case, stop the tests in this file.
finish();
}
// Wait for the next event or finish.
testRunner._testRunning = false;
}
};
////////////////////////////////////////////////////////////////////////////////
//// Asynchronous generator-based support subroutines
//// Asynchronous support subroutines
//
// The following functions are all generators that can be used inside the main
// test generator to perform specific tasks asynchronously. To invoke these
// subroutines correctly, an iteration syntax should be used:
//
// for (let yy in gen_example("Parameter")) yield undefined;
//
function gen_resetState(aData)
function promiseFocus()
{
let statement = Services.downloads.DBConnection.createAsyncStatement(
"DELETE FROM moz_downloads");
try {
statement.executeAsync({
handleResult: function(aResultSet) { },
handleError: function(aError)
{
Cu.reportError(aError);
},
handleCompletion: function(aReason)
{
testRunner.continueTest();
}
});
yield undefined;
} finally {
statement.finalize();
let deferred = Promise.defer();
waitForFocus(deferred.resolve);
return deferred.promise;
}
function promisePanelOpened()
{
let deferred = Promise.defer();
// Hook to wait until the panel is shown.
let originalOnPopupShown = DownloadsPanel.onPopupShown;
DownloadsPanel.onPopupShown = function () {
DownloadsPanel.onPopupShown = originalOnPopupShown;
originalOnPopupShown.apply(this, arguments);
// Defer to the next tick of the event loop so that we don't continue
// processing during the DOM event handler itself.
setTimeout(deferred.resolve, 0);
};
return deferred.promise;
}
function task_resetState()
{
// Remove all downloads.
let publicList = yield Downloads.getPublicDownloadList();
let downloads = yield publicList.getAll();
for (let download of downloads) {
publicList.remove(download);
yield download.finalize(true);
}
// Reset any prefs that might have been changed.
Services.prefs.clearUserPref("browser.download.panel.shown");
// Ensure that the panel is closed and data is unloaded.
aData.clear();
aData._loadState = aData.kLoadNone;
DownloadsPanel.hidePanel();
// Wait for focus on the main window.
waitForFocus(testRunner.continueTest);
yield undefined;
yield promiseFocus();
}
function gen_addDownloadRows(aDataRows)
function task_addDownloads(aItems)
{
let columnNames = Object.keys(gDownloadRowTemplate).join(", ");
let parameterNames = Object.keys(gDownloadRowTemplate)
.map(function(n) ":" + n)
.join(", ");
let statement = Services.downloads.DBConnection.createAsyncStatement(
"INSERT INTO moz_downloads (" + columnNames +
", guid) VALUES(" + parameterNames + ", GENERATE_GUID())");
try {
// Execute the statement for each of the provided downloads in reverse.
for (let i = aDataRows.length - 1; i >= 0; i--) {
let dataRow = aDataRows[i];
let startTimeMs = Date.now();
// Populate insert parameters from the provided data.
for (let columnName in gDownloadRowTemplate) {
if (!(columnName in dataRow)) {
// Update the provided row object with data from the global template,
// for columns whose value is not provided explicitly.
dataRow[columnName] = gDownloadRowTemplate[columnName];
}
statement.params[columnName] = dataRow[columnName];
}
// Run the statement asynchronously and wait.
statement.executeAsync({
handleResult: function(aResultSet) { },
handleError: function(aError)
{
Cu.reportError(aError.message + " (Result = " + aError.result + ")");
},
handleCompletion: function(aReason)
{
testRunner.continueTest();
}
});
yield undefined;
// At each iteration, ensure that the start and end time in the global
// template is distinct, as these column are used to sort each download
// in its category.
gDownloadRowTemplate.startTime++;
gDownloadRowTemplate.endTime++;
}
} finally {
statement.finalize();
let publicList = yield Downloads.getPublicDownloadList();
for (let item of aItems) {
publicList.add(yield Downloads.createDownload({
source: "http://www.example.com/test-download.txt",
target: gTestTargetFile,
succeeded: item.state == nsIDM.DOWNLOAD_FINISHED,
canceled: item.state == nsIDM.DOWNLOAD_CANCELED ||
item.state == nsIDM.DOWNLOAD_PAUSED,
error: item.state == nsIDM.DOWNLOAD_FAILED ? new Error("Failed.") : null,
hasPartialData: item.state == nsIDM.DOWNLOAD_PAUSED,
startTime: new Date(startTimeMs++),
}));
}
}
function gen_openPanel(aData)
function task_openPanel()
{
// Hook to wait until the test data has been loaded.
let originalOnViewLoadCompleted = DownloadsPanel.onViewLoadCompleted;
DownloadsPanel.onViewLoadCompleted = function () {
DownloadsPanel.onViewLoadCompleted = originalOnViewLoadCompleted;
originalOnViewLoadCompleted.apply(this);
testRunner.continueTest();
};
yield promiseFocus();
// Start loading all the downloads from the database asynchronously.
aData.ensurePersistentDataLoaded(false);
// Wait for focus on the main window.
waitForFocus(testRunner.continueTest);
yield undefined;
// Open the downloads panel, waiting until loading is completed.
let promise = promisePanelOpened();
DownloadsPanel.showPanel();
yield undefined;
}
/**
* Spin the event loop for aSeconds seconds, and then signal the test to
* continue.
*
* @param aSeconds the number of seconds to wait.
* @note This helper should _only_ be used when there's no valid event to
* listen to and one can't be made.
*/
function waitFor(aSeconds)
{
setTimeout(function() {
testRunner.continueTest();
}, aSeconds * 1000);
}
/**
* Make it so that the next time the downloads panel opens, we signal to
* continue the test. This function needs to be called each time you want
* to wait for the panel to open.
*
* Example usage:
*
* prepareForPanelOpen();
* // Do something to open the panel
* yield undefined;
* // We can assume the panel is open now.
*/
function prepareForPanelOpen()
{
// Hook to wait until the test data has been loaded.
let originalOnPopupShown = DownloadsPanel.onPopupShown;
DownloadsPanel.onPopupShown = function (aEvent) {
DownloadsPanel.onPopupShown = originalOnPopupShown;
DownloadsPanel.onPopupShown.apply(this, [aEvent]);
testRunner.continueTest();
};
yield promise;
}

View File

@ -14,6 +14,9 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource:///modules/SignInToWebsite.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AboutHome",
"resource:///modules/AboutHome.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
@ -465,6 +468,7 @@ BrowserGlue.prototype = {
SignInToWebsiteUX.init();
PdfJs.init();
webrtcUI.init();
AboutHome.init();
if (Services.prefs.getBoolPref("browser.tabs.remote"))
ContentClick.init();

View File

@ -9,16 +9,9 @@
# Buttons (like with contextAppbar2.pin.topSites) refer to actions against
# the specific on-screen sets with similarly-named headings.
# Default search engine
browser.search.defaultenginename=Bing
# Search engine order (order displayed in the search bar dropdown)s
browser.search.order.1=Bing
browser.search.order.2=Google
browser.search.order.3=Yahoo
# LOCALIZATION NOTE (browser.search.contextTextSearchLabel2): search context
# menu item text will be: |Search (browser.search.defaultenginename) for "string"|
# browser.search.defaultenginename is defined in region.properties
browser.search.contextTextSearchLabel2=Search %S for "%S"
# Contextual Appbar - Button Labels

View File

@ -0,0 +1,19 @@
# 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/.
# LOCALIZATION NOTE: REVIEW_REQUIRED
# For all locales: please do not commit any changes to this file without a
# review from the l10n-drivers team. In order to get one, please file a bug,
# add the "productization" keyword and CC l10n@mozilla.com.
# en-US: if you're changing this file, please CC l10n@mozilla.com in the
# associated bug to help us determine if these changes are relevant for other
# locales and how to localize them.
# Default search engine
browser.search.defaultenginename=Bing
# Search engine order (order displayed in the search bar dropdown)
browser.search.order.1=Bing
browser.search.order.2=Google
browser.search.order.3=Yahoo

View File

@ -12,6 +12,7 @@
locale/browser/aboutCertError.dtd (%chrome/aboutCertError.dtd)
locale/browser/browser.dtd (%chrome/browser.dtd)
locale/browser/browser.properties (%chrome/browser.properties)
locale/browser/region.properties (%chrome/region.properties)
locale/browser/config.dtd (%chrome/config.dtd)
locale/browser/preferences.dtd (%chrome/preferences.dtd)
locale/browser/aboutPanel.dtd (%chrome/aboutPanel.dtd)
@ -34,7 +35,6 @@
@AB_CD@.jar:
relativesrcdir browser/locales:
locale/browser/syncBrand.dtd (%chrome/browser/syncBrand.dtd)
locale/browser/region.properties (%chrome/browser-region/region.properties)
locale/browser/netError.dtd (%chrome/overrides/netError.dtd)
% override chrome://global/locale/netError.dtd chrome://browser/locale/netError.dtd
locale/browser/appstrings.properties (%chrome/overrides/appstrings.properties)

View File

@ -231,7 +231,7 @@ pref("accessibility.browsewithcaret", false);
pref("app.update.showInstalledUI", false);
// pointer to the default engine name
pref("browser.search.defaultenginename", "chrome://browser/locale/browser.properties");
pref("browser.search.defaultenginename", "chrome://browser/locale/region.properties");
// SSL error page behaviour
pref("browser.ssl_override_behavior", 2);
@ -241,9 +241,9 @@ pref("browser.xul.error_pages.expert_bad_cert", false);
pref("browser.search.log", false);
// ordering of search engines in the engine list.
pref("browser.search.order.1", "chrome://browser/locale/browser.properties");
pref("browser.search.order.2", "chrome://browser/locale/browser.properties");
pref("browser.search.order.3", "chrome://browser/locale/browser.properties");
pref("browser.search.order.1", "chrome://browser/locale/region.properties");
pref("browser.search.order.2", "chrome://browser/locale/region.properties");
pref("browser.search.order.3", "chrome://browser/locale/region.properties");
// send ping to the server to update
pref("browser.search.update", true);

View File

@ -0,0 +1,209 @@
/* 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";
let Cc = Components.classes;
let Ci = Components.interfaces;
let Cu = Components.utils;
this.EXPORTED_SYMBOLS = [ "AboutHomeUtils", "AboutHome" ];
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
// Url to fetch snippets, in the urlFormatter service format.
const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl";
// Should be bumped up if the snippets content format changes.
const STARTPAGE_VERSION = 4;
this.AboutHomeUtils = {
get snippetsVersion() STARTPAGE_VERSION,
/**
* Returns an object containing the name and searchURL of the original default
* search engine.
*/
get defaultSearchEngine() {
let defaultEngine = Services.search.defaultEngine;
let submission = defaultEngine.getSubmission("_searchTerms_", null, "homepage");
return Object.freeze({
name: defaultEngine.name,
searchURL: submission.uri.spec,
postDataString: submission.postDataString
});
},
/*
* showKnowYourRights - Determines if the user should be shown the
* about:rights notification. The notification should *not* be shown if
* we've already shown the current version, or if the override pref says to
* never show it. The notification *should* be shown if it's never been seen
* before, if a newer version is available, or if the override pref says to
* always show it.
*/
get showKnowYourRights() {
// Look for an unconditional override pref. If set, do what it says.
// (true --> never show, false --> always show)
try {
return !Services.prefs.getBoolPref("browser.rights.override");
} catch (e) { }
// Ditto, for the legacy EULA pref.
try {
return !Services.prefs.getBoolPref("browser.EULA.override");
} catch (e) { }
#ifndef MOZILLA_OFFICIAL
// Non-official builds shouldn't show the notification.
return false;
#endif
// Look to see if the user has seen the current version or not.
var currentVersion = Services.prefs.getIntPref("browser.rights.version");
try {
return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
} catch (e) { }
// Legacy: If the user accepted a EULA, we won't annoy them with the
// equivalent about:rights page until the version changes.
try {
return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
} catch (e) { }
// We haven't shown the notification before, so do so now.
return true;
}
};
/**
* Returns the URL to fetch snippets from, in the urlFormatter service format.
*/
XPCOMUtils.defineLazyGetter(AboutHomeUtils, "snippetsURL", function() {
let updateURL = Services.prefs
.getCharPref(SNIPPETS_URL_PREF)
.replace("%STARTPAGE_VERSION%", STARTPAGE_VERSION);
return Services.urlFormatter.formatURL(updateURL);
});
/**
* This code provides services to the about:home page. Whenever
* about:home needs to do something chrome-privileged, it sends a
* message that's handled here.
*/
let AboutHome = {
MESSAGES: [
"AboutHome:RestorePreviousSession",
"AboutHome:Downloads",
"AboutHome:Bookmarks",
"AboutHome:History",
"AboutHome:Apps",
"AboutHome:Addons",
"AboutHome:Sync",
"AboutHome:Settings",
"AboutHome:RequestUpdate",
"AboutHome:Search",
],
init: function() {
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
for (let msg of this.MESSAGES) {
mm.addMessageListener(msg, this);
}
Services.obs.addObserver(this, "browser-search-engine-modified", false);
},
observe: function(aEngine, aTopic, aVerb) {
switch (aTopic) {
case "browser-search-engine-modified":
this.sendAboutHomeData(null);
break;
}
},
receiveMessage: function(aMessage) {
let window = aMessage.target.ownerDocument.defaultView;
switch (aMessage.name) {
case "AboutHome:RestorePreviousSession":
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
if (ss.canRestoreLastSession) {
ss.restoreLastSession();
}
break;
case "AboutHome:Downloads":
window.BrowserDownloadsUI();
break;
case "AboutHome:Bookmarks":
window.PlacesCommandHook.showPlacesOrganizer("AllBookmarks");
break;
case "AboutHome:History":
window.PlacesCommandHook.showPlacesOrganizer("History");
break;
case "AboutHome:Apps":
window.openUILinkIn("https://marketplace.mozilla.org/", "tab");
break;
case "AboutHome:Addons":
window.BrowserOpenAddonsMgr();
break;
case "AboutHome:Sync":
window.openPreferences("paneSync");
break;
case "AboutHome:Settings":
window.openPreferences();
break;
case "AboutHome:RequestUpdate":
this.sendAboutHomeData(aMessage.target);
break;
case "AboutHome:Search":
#ifdef MOZ_SERVICES_HEALTHREPORT
window.BrowserSearch.recordSearchInHealthReport(aMessage.data.engineName, "abouthome");
#endif
break;
}
},
// Send all the chrome-privileged data needed by about:home. This
// gets re-sent when the search engine changes.
sendAboutHomeData: function(target) {
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
let data = {
showRestoreLastSession: ss.canRestoreLastSession,
snippetsURL: AboutHomeUtils.snippetsURL,
showKnowYourRights: AboutHomeUtils.showKnowYourRights,
snippetsVersion: AboutHomeUtils.snippetsVersion,
defaultSearchEngine: AboutHomeUtils.defaultSearchEngine
};
if (AboutHomeUtils.showKnowYourRights) {
// Set pref to indicate we've shown the notification.
let currentVersion = Services.prefs.getIntPref("browser.rights.version");
Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
}
if (target) {
target.messageManager.sendAsyncMessage("AboutHome:Update", data);
} else {
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
mm.broadcastAsyncMessage("AboutHome:Update", data);
}
},
};

View File

@ -1,85 +0,0 @@
/* 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";
this.EXPORTED_SYMBOLS = [ "AboutHomeUtils" ];
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
// Url to fetch snippets, in the urlFormatter service format.
const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl";
// Should be bumped up if the snippets content format changes.
const STARTPAGE_VERSION = 4;
this.AboutHomeUtils = {
get snippetsVersion() STARTPAGE_VERSION,
/**
* Returns an object containing the name and searchURL of the original default
* search engine.
*/
get defaultSearchEngine() {
let defaultEngine = Services.search.defaultEngine;
let submission = defaultEngine.getSubmission("_searchTerms_", null, "homepage");
return Object.freeze({
name: defaultEngine.name,
searchURL: submission.uri.spec,
postDataString: submission.postDataString
});
},
/*
* showKnowYourRights - Determines if the user should be shown the
* about:rights notification. The notification should *not* be shown if
* we've already shown the current version, or if the override pref says to
* never show it. The notification *should* be shown if it's never been seen
* before, if a newer version is available, or if the override pref says to
* always show it.
*/
get showKnowYourRights() {
// Look for an unconditional override pref. If set, do what it says.
// (true --> never show, false --> always show)
try {
return !Services.prefs.getBoolPref("browser.rights.override");
} catch (e) { }
// Ditto, for the legacy EULA pref.
try {
return !Services.prefs.getBoolPref("browser.EULA.override");
} catch (e) { }
#ifndef MOZILLA_OFFICIAL
// Non-official builds shouldn't show the notification.
return false;
#endif
// Look to see if the user has seen the current version or not.
var currentVersion = Services.prefs.getIntPref("browser.rights.version");
try {
return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
} catch (e) { }
// Legacy: If the user accepted a EULA, we won't annoy them with the
// equivalent about:rights page until the version changes.
try {
return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
} catch (e) { }
// We haven't shown the notification before, so do so now.
return true;
}
};
/**
* Returns the URL to fetch snippets from, in the urlFormatter service format.
*/
XPCOMUtils.defineLazyGetter(AboutHomeUtils, "snippetsURL", function() {
let updateURL = Services.prefs
.getCharPref(SNIPPETS_URL_PREF)
.replace("%STARTPAGE_VERSION%", STARTPAGE_VERSION);
return Services.urlFormatter.formatURL(updateURL);
});

View File

@ -27,7 +27,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
]
EXTRA_PP_JS_MODULES += [
'AboutHomeUtils.jsm',
'AboutHome.jsm',
'RecentWindow.jsm',
]

View File

@ -19,13 +19,17 @@ def InvokeClWithDependencyGeneration(cmdline):
if target == None:
print >>sys.stderr, "No target set" and sys.exit(1)
# Assume the source file is the last argument
source = cmdline[-1]
assert not source.startswith('-')
# The deps target lives here
depstarget = os.path.basename(target) + ".pp"
cmdline += ['-showIncludes']
cl = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
deps = set()
deps = set([os.path.normcase(source).replace(os.sep, '/')])
for line in cl.stdout:
# cl -showIncludes prefixes every header with "Note: including file:"
# and an indentation corresponding to the depth (which we don't need)
@ -34,8 +38,8 @@ def InvokeClWithDependencyGeneration(cmdline):
# We can't handle pathes with spaces properly in mddepend.pl, but
# we can assume that anything in a path with spaces is a system
# header and throw it away.
if dep.find(' ') == -1:
deps.add(dep)
if ' ' not in dep:
deps.add(os.path.normcase(dep).replace(os.sep, '/'))
else:
sys.stdout.write(line) # Make sure we preserve the relevant output
# from cl
@ -54,10 +58,13 @@ def InvokeClWithDependencyGeneration(cmdline):
# cost of masking failure to create the directory. We'll just
# die on the next line though, so it's not that much of a loss.
f = open(depstarget, "w")
for dep in sorted(deps):
print >>f, "%s: %s" % (target, dep)
print >>f, "%s:" % dep
with open(depstarget, "w") as f:
f.write("%s: %s" % (target, source))
for dep in sorted(deps):
f.write(" \\\n%s" % dep)
f.write('\n')
for dep in sorted(deps):
f.write("%s:\n" % dep)
if __name__ == "__main__":
InvokeClWithDependencyGeneration(sys.argv[1:])

View File

@ -23,3 +23,9 @@ ifeq (1_a,$(.PYMAKE)_$(firstword a$(subst /, ,$(srcdir))))
$(error MSYS-style srcdir being used with Pymake. Did you mean to run GNU Make instead? [see-also: https://developer.mozilla.org/ en/Gmake_vs._Pymake])
endif
endif # WINNT
ifdef .PYMAKE
include_deps = $(eval -includedeps $(1))
else
include_deps = $(eval -include $(1))
endif

View File

@ -76,10 +76,6 @@ xpidl:: $(linked_xpt_files) $(dist_headers)
$(linked_xpt_files): $(process_py) $(call mkdir_deps,$(idl_deps_dir) $(idl_headers_dir) $(idl_xpt_dir))
ifdef .PYMAKE
-includedeps $(depends_files)
else
-include $(depends_files)
endif
$(call include_deps,$(depends_files))
.PHONY: xpidl

View File

@ -1621,11 +1621,7 @@ ifneq (,$(filter-out all chrome default export realchrome tools clean clobber cl
MDDEPEND_FILES := $(strip $(wildcard $(foreach file,$(sort $(OBJS) $(PROGOBJS) $(HOST_OBJS) $(HOST_PROGOBJS) $(TARGETS)),$(MDDEPDIR)/$(notdir $(file)).pp) $(addprefix $(MDDEPDIR)/,$(EXTRA_MDDEPEND_FILES))))
ifneq (,$(MDDEPEND_FILES))
ifdef .PYMAKE
includedeps $(MDDEPEND_FILES)
else
include $(MDDEPEND_FILES)
endif
$(call include_deps,$(MDDEPEND_FILES))
endif
endif
@ -1635,11 +1631,7 @@ ifneq (,$(filter export,$(MAKECMDGOALS)))
MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(EXTRA_EXPORT_MDDEPEND_FILES))))
ifneq (,$(MDDEPEND_FILES))
ifdef .PYMAKE
includedeps $(MDDEPEND_FILES)
else
include $(MDDEPEND_FILES)
endif
$(call include_deps,$(MDDEPEND_FILES))
endif
endif

View File

@ -216,6 +216,10 @@ if test -n "$gonkdir" ; then
;;
18)
GONK_INCLUDES="-I$gonkdir/frameworks/native/include"
if test -d "$gonkdir/external/bluetooth/bluez"; then
GONK_INCLUDES+=" -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib"
MOZ_B2G_BT=1
fi
;;
*)
AC_MSG_ERROR([Unsupported platform version: $ANDROID_VERSION])

View File

@ -34,7 +34,6 @@
#include "mozilla/css/ImageLoader.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIScriptRuntime.h"
#include "nsCOMArray.h"
#include "nsDOMClassInfo.h"
#include "nsCxPusher.h"

View File

@ -19,7 +19,6 @@
#include "nsNetUtil.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIScriptRuntime.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
#include "nsJSPrincipals.h"

View File

@ -20,7 +20,6 @@
#include "nsPIDOMWindow.h"
#include "nsIJSEventListener.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptRuntime.h"
#include "nsLayoutUtils.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"

View File

@ -909,9 +909,6 @@ protected:
nsMediaNetworkState mNetworkState;
nsMediaReadyState mReadyState;
// Last value passed from codec or stream source to UpdateReadyStateForData.
NextFrameStatus mLastNextFrameStatus;
enum LoadAlgorithmState {
// No load algorithm instance is waiting for a source to be added to the
// media in order to continue loading.
@ -1124,9 +1121,6 @@ protected:
// True if the media has an audio track
bool mHasAudio;
// True if the media has a video track
bool mHasVideo;
// True if the media's channel's download has been suspended.
bool mDownloadSuspendedByCache;

View File

@ -68,8 +68,6 @@
#include "nsHostObjectProtocolHandler.h"
#include "mozilla/dom/MediaSource.h"
#include "MediaMetadataManager.h"
#include "AudioStreamTrack.h"
#include "VideoStreamTrack.h"
#include "AudioChannelService.h"
@ -623,10 +621,7 @@ void HTMLMediaElement::AbortExistingLoads()
mHaveQueuedSelectResource = false;
mSuspendedForPreloadNone = false;
mDownloadSuspendedByCache = false;
mHasAudio = false;
mHasVideo = false;
mSourcePointer = nullptr;
mLastNextFrameStatus = NEXT_FRAME_UNINITIALIZED;
mChannels = 0;
mRate = 0;
@ -1911,7 +1906,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
mCurrentLoadID(0),
mNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY),
mReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING),
mLastNextFrameStatus(NEXT_FRAME_UNINITIALIZED),
mLoadWaitStatus(NOT_WAITING),
mVolume(1.0),
mChannels(0),
@ -1952,7 +1946,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
mMediaSecurityVerified(false),
mCORSMode(CORS_NONE),
mHasAudio(false),
mHasVideo(false),
mDownloadSuspendedByCache(false),
mAudioChannelType(AUDIO_CHANNEL_NORMAL),
mPlayingThroughTheAudioChannel(false)
@ -2704,19 +2697,6 @@ void HTMLMediaElement::SetupSrcMediaStreamPlayback(DOMMediaStream* aStream)
if (mPausedForInactiveDocumentOrChannel) {
GetSrcMediaStream()->ChangeExplicitBlockerCount(1);
}
nsAutoTArray<nsRefPtr<AudioStreamTrack>,1> audioTracks;
aStream->GetAudioTracks(audioTracks);
nsAutoTArray<nsRefPtr<VideoStreamTrack>,1> videoTracks;
aStream->GetVideoTracks(videoTracks);
// Clear aChannels, aRate and aTags, but set mHasAudio and mHasVideo
MetadataLoaded(0, 0,
!audioTracks.IsEmpty(), !videoTracks.IsEmpty(),
nullptr);
DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
ChangeDelayLoadStatus(false);
GetSrcMediaStream()->AddAudioOutput(this);
GetSrcMediaStream()->SetAudioOutputVolume(this, float(mMuted ? 0.0 : mVolume));
@ -2724,7 +2704,11 @@ void HTMLMediaElement::SetupSrcMediaStreamPlayback(DOMMediaStream* aStream)
if (container) {
GetSrcMediaStream()->AddVideoOutput(container);
}
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
DispatchAsyncEvent(NS_LITERAL_STRING("loadedmetadata"));
DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
AddRemoveSelfReference();
// FirstFrameLoaded(false) will be called when the stream has current data,
// to complete the setup by entering the HAVE_CURRENT_DATA state.
@ -2781,7 +2765,6 @@ void HTMLMediaElement::MetadataLoaded(int aChannels,
mChannels = aChannels;
mRate = aRate;
mHasAudio = aHasAudio;
mHasVideo = aHasVideo;
mTags = aTags;
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
@ -2801,8 +2784,10 @@ void HTMLMediaElement::MetadataLoaded(int aChannels,
void HTMLMediaElement::FirstFrameLoaded(bool aResourceFullyLoaded)
{
ChangeReadyState(aResourceFullyLoaded ?
nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA :
nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
ChangeDelayLoadStatus(false);
UpdateReadyStateForData(NEXT_FRAME_UNAVAILABLE);
NS_ASSERTION(!mSuspendedAfterFirstFrame, "Should not have already suspended");
@ -2989,8 +2974,6 @@ bool HTMLMediaElement::ShouldCheckAllowOrigin()
void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatus aNextFrame)
{
mLastNextFrameStatus = aNextFrame;
if (mReadyState < nsIDOMHTMLMediaElement::HAVE_METADATA) {
// aNextFrame might have a next frame because the decoder can advance
// on its own thread before ResourceLoaded or MetadataLoaded gets
@ -3014,14 +2997,6 @@ void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatu
return;
}
if (mReadyState < nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA && mHasVideo) {
VideoFrameContainer* container = GetVideoFrameContainer();
if (container && mMediaSize == nsIntSize(-1,-1)) {
// No frame has been set yet. Don't advance.
return;
}
}
if (aNextFrame != MediaDecoderOwner::NEXT_FRAME_AVAILABLE) {
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
if (!mWaitingFired && aNextFrame == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING) {
@ -3156,21 +3131,26 @@ void HTMLMediaElement::CheckAutoplayDataReady()
VideoFrameContainer* HTMLMediaElement::GetVideoFrameContainer()
{
if (mVideoFrameContainer) {
return mVideoFrameContainer;
// If we have loaded the metadata, and the size of the video is still
// (-1, -1), the media has no video. Don't go a create a video frame
// container.
if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_METADATA &&
mMediaSize == nsIntSize(-1, -1)) {
return nullptr;
}
if (mVideoFrameContainer)
return mVideoFrameContainer;
// If we have a print surface, this is just a static image so
// no image container is required
if (mPrintSurface) {
if (mPrintSurface)
return nullptr;
}
// Only video frames need an image container.
nsCOMPtr<nsIDOMHTMLVideoElement> video = do_QueryObject(this);
if (!video) {
if (!video)
return nullptr;
}
mVideoFrameContainer =
new VideoFrameContainer(this, LayerManager::CreateAsynchronousImageContainer());
@ -3300,7 +3280,6 @@ void HTMLMediaElement::NotifyDecoderPrincipalChanged()
void HTMLMediaElement::UpdateMediaSize(nsIntSize size)
{
mMediaSize = size;
UpdateReadyStateForData(mLastNextFrameStatus);
}
void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement, bool aSuspendEvents)

View File

@ -30,6 +30,7 @@
#include "WaveShaperNode.h"
#include "PeriodicWave.h"
#include "ConvolverNode.h"
#include "OscillatorNode.h"
#include "nsNetUtil.h"
namespace mozilla {
@ -64,6 +65,7 @@ AudioContext::AudioContext(nsPIDOMWindow* aWindow,
mPannerNodes.Init();
mAudioBufferSourceNodes.Init();
mOscillatorNodes.Init();
mScriptProcessorNodes.Init();
}
@ -369,6 +371,15 @@ AudioContext::CreateBiquadFilter()
return filterNode.forget();
}
already_AddRefed<OscillatorNode>
AudioContext::CreateOscillator()
{
nsRefPtr<OscillatorNode> oscillatorNode =
new OscillatorNode(this);
mOscillatorNodes.PutEntry(oscillatorNode);
return oscillatorNode.forget();
}
already_AddRefed<PeriodicWave>
AudioContext::CreatePeriodicWave(const Float32Array& aRealData,
const Float32Array& aImagData,
@ -443,6 +454,12 @@ AudioContext::UnregisterPannerNode(PannerNode* aNode)
}
}
void
AudioContext::UnregisterOscillatorNode(OscillatorNode* aNode)
{
mOscillatorNodes.RemoveEntry(aNode);
}
void
AudioContext::UnregisterScriptProcessorNode(ScriptProcessorNode* aNode)
{
@ -534,6 +551,14 @@ AudioContext::Shutdown()
ErrorResult rv;
sourceNodes[i]->Stop(0.0, rv, true);
}
// Stop all Oscillator nodes to make sure they release their
// playing reference.
nsTArray<OscillatorNode*> oscNodes;
GetHashtableElements(mOscillatorNodes, oscNodes);
for (uint32_t i = 0; i < oscNodes.Length(); ++i) {
ErrorResult rv;
oscNodes[i]->Stop(0.0, rv);
}
// Stop all script processor nodes, to make sure that they release
// their self-references.
nsTArray<ScriptProcessorNode*> spNodes;

View File

@ -54,6 +54,7 @@ class HTMLMediaElement;
class MediaElementAudioSourceNode;
class MediaStreamAudioDestinationNode;
class MediaStreamAudioSourceNode;
class OscillatorNode;
class PannerNode;
class ScriptProcessorNode;
class WaveShaperNode;
@ -193,6 +194,9 @@ public:
already_AddRefed<BiquadFilterNode>
CreateBiquadFilter();
already_AddRefed<OscillatorNode>
CreateOscillator();
already_AddRefed<PeriodicWave>
CreatePeriodicWave(const Float32Array& aRealData, const Float32Array& aImagData,
ErrorResult& aRv);
@ -211,6 +215,7 @@ public:
MediaStream* DestinationStream() const;
void UnregisterAudioBufferSourceNode(AudioBufferSourceNode* aNode);
void UnregisterPannerNode(PannerNode* aNode);
void UnregisterOscillatorNode(OscillatorNode* aNode);
void UnregisterScriptProcessorNode(ScriptProcessorNode* aNode);
void UpdatePannerSource();
@ -240,6 +245,7 @@ private:
// These are all weak pointers.
nsTHashtable<nsPtrHashKey<PannerNode> > mPannerNodes;
nsTHashtable<nsPtrHashKey<AudioBufferSourceNode> > mAudioBufferSourceNodes;
nsTHashtable<nsPtrHashKey<OscillatorNode> > mOscillatorNodes;
// Hashset containing all ScriptProcessorNodes in order to stop them.
// These are all weak pointers.
nsTHashtable<nsPtrHashKey<ScriptProcessorNode> > mScriptProcessorNodes;

View File

@ -0,0 +1,435 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "OscillatorNode.h"
#include "AudioNodeEngine.h"
#include "AudioNodeStream.h"
#include "AudioDestinationNode.h"
#include "WebAudioUtils.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(OscillatorNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(OscillatorNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPeriodicWave)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrequency)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDetune)
if (tmp->Context()) {
tmp->Context()->UnregisterOscillatorNode(tmp);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(AudioNode);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(OscillatorNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPeriodicWave)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrequency)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDetune)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(OscillatorNode)
NS_INTERFACE_MAP_END_INHERITING(AudioNode)
NS_IMPL_ADDREF_INHERITED(OscillatorNode, AudioNode)
NS_IMPL_RELEASE_INHERITED(OscillatorNode, AudioNode)
class OscillatorNodeEngine : public AudioNodeEngine
{
public:
OscillatorNodeEngine(AudioNode* aNode, AudioDestinationNode* aDestination)
: AudioNodeEngine(aNode)
, mSource(nullptr)
, mDestination(static_cast<AudioNodeStream*> (aDestination->Stream()))
, mStart(0)
, mStop(TRACK_TICKS_MAX)
// Keep the default values in sync with OscillatorNode::OscillatorNode.
, mFrequency(440.f)
, mDetune(0.f)
, mType(OscillatorType::Sine)
, mPhase(0.)
{
}
void SetSourceStream(AudioNodeStream* aSource)
{
mSource = aSource;
}
enum Parameters {
FREQUENCY,
DETUNE,
TYPE,
PERIODICWAVE,
START,
STOP,
};
void SetTimelineParameter(uint32_t aIndex,
const AudioParamTimeline& aValue,
TrackRate aSampleRate) MOZ_OVERRIDE
{
switch (aIndex) {
case FREQUENCY:
MOZ_ASSERT(mSource && mDestination);
mFrequency = aValue;
WebAudioUtils::ConvertAudioParamToTicks(mFrequency, mSource, mDestination);
break;
case DETUNE:
MOZ_ASSERT(mSource && mDestination);
mDetune = aValue;
WebAudioUtils::ConvertAudioParamToTicks(mDetune, mSource, mDestination);
break;
default:
NS_ERROR("Bad OscillatorNodeEngine TimelineParameter");
}
}
virtual void SetStreamTimeParameter(uint32_t aIndex, TrackTicks aParam)
{
switch (aIndex) {
case START: mStart = aParam; break;
case STOP: mStop = aParam; break;
default:
NS_ERROR("Bad OscillatorNodeEngine StreamTimeParameter");
}
}
virtual void SetInt32Parameter(uint32_t aIndex, int32_t aParam)
{
switch (aIndex) {
case TYPE: mType = static_cast<OscillatorType>(aParam); break;
default:
NS_ERROR("Bad OscillatorNodeEngine Int32Parameter");
}
}
double ComputeFrequency(TrackTicks ticks, size_t count)
{
double frequency, detune;
if (mFrequency.HasSimpleValue()) {
frequency = mFrequency.GetValue();
} else {
frequency = mFrequency.GetValueAtTime(ticks, count);
}
if (mDetune.HasSimpleValue()) {
detune = mDetune.GetValue();
} else {
detune = mDetune.GetValueAtTime(ticks, count);
}
return frequency * pow(2., detune / 1200.);
}
void FillBounds(float* output, TrackTicks ticks,
uint32_t& start, uint32_t& end)
{
MOZ_ASSERT(output);
static_assert(TrackTicks(WEBAUDIO_BLOCK_SIZE) < UINT_MAX,
"WEBAUDIO_BLOCK_SIZE overflows interator bounds.");
start = 0;
if (ticks < mStart) {
start = mStart - ticks;
for (uint32_t i = 0; i < start; ++i) {
output[i] = 0.0;
}
}
end = WEBAUDIO_BLOCK_SIZE;
if (ticks + end > mStop) {
end = mStop - ticks;
for (uint32_t i = end; i < WEBAUDIO_BLOCK_SIZE; ++i) {
output[i] = 0.0;
}
}
}
void ComputeSine(AudioChunk *aOutput)
{
AllocateAudioBlock(1, aOutput);
float* output = static_cast<float*>(const_cast<void*>(aOutput->mChannelData[0]));
TrackTicks ticks = mSource->GetCurrentPosition();
uint32_t start, end;
FillBounds(output, ticks, start, end);
double rate = 2.*M_PI / mSource->SampleRate();
double phase = mPhase;
for (uint32_t i = start; i < end; ++i) {
phase += ComputeFrequency(ticks, i) * rate;
output[i] = sin(phase);
}
mPhase = phase;
while (mPhase > 2.0*M_PI) {
// Rescale to avoid precision reductions on long runs.
mPhase -= 2.0*M_PI;
}
}
void ComputeSquare(AudioChunk *aOutput)
{
AllocateAudioBlock(1, aOutput);
float* output = static_cast<float*>(const_cast<void*>(aOutput->mChannelData[0]));
TrackTicks ticks = mSource->GetCurrentPosition();
uint32_t start, end;
FillBounds(output, ticks, start, end);
double rate = 1.0 / mSource->SampleRate();
double phase = mPhase;
for (uint32_t i = start; i < end; ++i) {
phase += ComputeFrequency(ticks, i) * rate;
if (phase > 1.0) {
phase -= 1.0;
}
output[i] = phase < 0.5 ? 1.0 : -1.0;
}
mPhase = phase;
}
void ComputeSawtooth(AudioChunk *aOutput)
{
AllocateAudioBlock(1, aOutput);
float* output = static_cast<float*>(const_cast<void*>(aOutput->mChannelData[0]));
TrackTicks ticks = mSource->GetCurrentPosition();
uint32_t start, end;
FillBounds(output, ticks, start, end);
double rate = 1.0 / mSource->SampleRate();
double phase = mPhase;
for (uint32_t i = start; i < end; ++i) {
phase += ComputeFrequency(ticks, i) * rate;
if (phase > 1.0) {
phase -= 1.0;
}
output[i] = phase < 0.5 ? 2.0*phase : 2.0*(phase - 1.0);
}
mPhase = phase;
}
void ComputeTriangle(AudioChunk *aOutput)
{
AllocateAudioBlock(1, aOutput);
float* output = static_cast<float*>(const_cast<void*>(aOutput->mChannelData[0]));
TrackTicks ticks = mSource->GetCurrentPosition();
uint32_t start, end;
FillBounds(output, ticks, start, end);
double rate = 1.0 / mSource->SampleRate();
double phase = mPhase;
for (uint32_t i = start; i < end; ++i) {
phase += ComputeFrequency(ticks, i) * rate;
if (phase > 1.0) {
phase -= 1.0;
}
if (phase < 0.25) {
output[i] = 4.0*phase;
} else if (phase < 0.75) {
output[i] = 1.0 - 4.0*(phase - 0.25);
} else {
output[i] = 4.0*(phase - 0.75) - 1.0;
}
}
mPhase = phase;
}
void ComputeSilence(AudioChunk *aOutput)
{
aOutput->SetNull(WEBAUDIO_BLOCK_SIZE);
}
virtual void ProduceAudioBlock(AudioNodeStream* aStream,
const AudioChunk& aInput,
AudioChunk* aOutput,
bool* aFinished) MOZ_OVERRIDE
{
MOZ_ASSERT(mSource == aStream, "Invalid source stream");
TrackTicks ticks = aStream->GetCurrentPosition();
if (ticks + WEBAUDIO_BLOCK_SIZE < mStart) {
// We're not playing yet.
ComputeSilence(aOutput);
return;
}
if (ticks >= mStop) {
// We've finished playing.
ComputeSilence(aOutput);
*aFinished = true;
return;
}
// Synthesize the correct waveform.
switch (mType) {
case OscillatorType::Sine:
ComputeSine(aOutput);
break;
case OscillatorType::Square:
ComputeSquare(aOutput);
break;
case OscillatorType::Sawtooth:
ComputeSawtooth(aOutput);
break;
case OscillatorType::Triangle:
ComputeTriangle(aOutput);
break;
default:
ComputeSilence(aOutput);
}
}
AudioNodeStream* mSource;
AudioNodeStream* mDestination;
TrackTicks mStart;
TrackTicks mStop;
AudioParamTimeline mFrequency;
AudioParamTimeline mDetune;
OscillatorType mType;
double mPhase;
};
OscillatorNode::OscillatorNode(AudioContext* aContext)
: AudioNode(aContext,
2,
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mType(OscillatorType::Sine)
, mFrequency(new AudioParam(MOZ_THIS_IN_INITIALIZER_LIST(),
SendFrequencyToStream, 440.0f))
, mDetune(new AudioParam(MOZ_THIS_IN_INITIALIZER_LIST(),
SendDetuneToStream, 0.0f))
, mStartCalled(false)
, mStopped(false)
{
OscillatorNodeEngine* engine = new OscillatorNodeEngine(this, aContext->Destination());
mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::SOURCE_STREAM);
engine->SetSourceStream(static_cast<AudioNodeStream*> (mStream.get()));
}
OscillatorNode::~OscillatorNode()
{
if (Context()) {
Context()->UnregisterOscillatorNode(this);
}
}
JSObject*
OscillatorNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return OscillatorNodeBinding::Wrap(aCx, aScope, this);
}
void
OscillatorNode::SendFrequencyToStream(AudioNode* aNode)
{
OscillatorNode* This = static_cast<OscillatorNode*>(aNode);
SendTimelineParameterToStream(This, OscillatorNodeEngine::FREQUENCY, *This->mFrequency);
}
void
OscillatorNode::SendDetuneToStream(AudioNode* aNode)
{
OscillatorNode* This = static_cast<OscillatorNode*>(aNode);
SendTimelineParameterToStream(This, OscillatorNodeEngine::DETUNE, *This->mDetune);
}
void
OscillatorNode::SendTypeToStream()
{
SendInt32ParameterToStream(OscillatorNodeEngine::TYPE, static_cast<int32_t>(mType));
if (mType == OscillatorType::Custom) {
// TODO: Send the custom wave table somehow
}
}
void
OscillatorNode::Start(double aWhen, ErrorResult& aRv)
{
if (!WebAudioUtils::IsTimeValid(aWhen)) {
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
if (mStartCalled) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mStartCalled = true;
AudioNodeStream* ns = static_cast<AudioNodeStream*>(mStream.get());
if (!ns) {
// Nothing to play, or we're already dead for some reason
return;
}
// TODO: Perhaps we need to do more here.
ns->SetStreamTimeParameter(OscillatorNodeEngine::START,
Context()->DestinationStream(),
aWhen);
MOZ_ASSERT(!mPlayingRef, "We can only accept a successful start() call once");
mPlayingRef.Take(this);
}
void
OscillatorNode::Stop(double aWhen, ErrorResult& aRv)
{
if (!WebAudioUtils::IsTimeValid(aWhen)) {
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
if (!mStartCalled) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mPlayingRef.Drop(this);
AudioNodeStream* ns = static_cast<AudioNodeStream*>(mStream.get());
if (!ns || !Context()) {
// We've already stopped and had our stream shut down
return;
}
// TODO: Perhaps we need to do more here.
ns->SetStreamTimeParameter(OscillatorNodeEngine::STOP,
Context()->DestinationStream(),
std::max(0.0, aWhen));
}
void
OscillatorNode::NotifyMainThreadStateChanged()
{
if (mStream->IsFinished()) {
class EndedEventDispatcher : public nsRunnable
{
public:
explicit EndedEventDispatcher(OscillatorNode* aNode)
: mNode(aNode) {}
NS_IMETHODIMP Run()
{
// If it's not safe to run scripts right now, schedule this to run later
if (!nsContentUtils::IsSafeToRunScript()) {
nsContentUtils::AddScriptRunner(this);
return NS_OK;
}
mNode->DispatchTrustedEvent(NS_LITERAL_STRING("ended"));
return NS_OK;
}
private:
nsRefPtr<OscillatorNode> mNode;
};
if (!mStopped) {
// Only dispatch the ended event once
NS_DispatchToMainThread(new EndedEventDispatcher(this));
mStopped = true;
}
// Drop the playing reference
// Warning: The below line might delete this.
mPlayingRef.Drop(this);
}
}
}
}

View File

@ -0,0 +1,138 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#ifndef OscillatorNode_h_
#define OscillatorNode_h_
#include "AudioNode.h"
#include "AudioParam.h"
#include "PeriodicWave.h"
#include "mozilla/dom/OscillatorNodeBinding.h"
#include "mozilla/Preferences.h"
namespace mozilla {
namespace dom {
class AudioContext;
class OscillatorNode : public AudioNode,
public MainThreadMediaStreamListener
{
public:
explicit OscillatorNode(AudioContext* aContext);
virtual ~OscillatorNode();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OscillatorNode, AudioNode)
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
virtual void DestroyMediaStream() MOZ_OVERRIDE
{
if (mStream) {
mStream->RemoveMainThreadListener(this);
}
AudioNode::DestroyMediaStream();
}
virtual uint16_t NumberOfInputs() const MOZ_FINAL MOZ_OVERRIDE
{
return 0;
}
OscillatorType Type() const
{
return mType;
}
void SetType(OscillatorType aType, ErrorResult& aRv)
{
if (!Preferences::GetBool("media.webaudio.legacy.OscillatorNode")) {
// Do not accept the alternate enum values unless the legacy pref
// has been turned on.
switch (aType) {
case OscillatorType::_0:
case OscillatorType::_1:
case OscillatorType::_2:
case OscillatorType::_3:
case OscillatorType::_4:
// Do nothing in order to emulate setting an invalid enum value.
return;
default:
// Shut up the compiler warning
break;
}
}
// Handle the alternate enum values
switch (aType) {
case OscillatorType::_0: aType = OscillatorType::Sine; break;
case OscillatorType::_1: aType = OscillatorType::Square; break;
case OscillatorType::_2: aType = OscillatorType::Sawtooth; break;
case OscillatorType::_3: aType = OscillatorType::Triangle; break;
case OscillatorType::_4: aType = OscillatorType::Custom; break;
default:
// Shut up the compiler warning
break;
}
if (aType == OscillatorType::Custom) {
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
mType = aType;
SendTypeToStream();
}
AudioParam* Frequency() const
{
return mFrequency;
}
AudioParam* Detune() const
{
return mDetune;
}
void Start(double aWhen, ErrorResult& aRv);
void NoteOn(double aWhen, ErrorResult& aRv)
{
Start(aWhen, aRv);
}
void Stop(double aWhen, ErrorResult& aRv);
void NoteOff(double aWhen, ErrorResult& aRv)
{
Stop(aWhen, aRv);
}
void SetPeriodicWave(PeriodicWave& aPeriodicWave)
{
mPeriodicWave = &aPeriodicWave;
mType = OscillatorType::Custom;
SendTypeToStream();
}
IMPL_EVENT_HANDLER(ended)
virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE;
private:
static void SendFrequencyToStream(AudioNode* aNode);
static void SendDetuneToStream(AudioNode* aNode);
void SendTypeToStream();
private:
OscillatorType mType;
nsRefPtr<PeriodicWave> mPeriodicWave;
nsRefPtr<AudioParam> mFrequency;
nsRefPtr<AudioParam> mDetune;
SelfReference<OscillatorNode> mPlayingRef;
bool mStartCalled;
bool mStopped;
};
}
}
#endif

View File

@ -43,6 +43,7 @@ EXPORTS.mozilla.dom += [
'MediaStreamAudioDestinationNode.h',
'MediaStreamAudioSourceNode.h',
'OfflineAudioCompletionEvent.h',
'OscillatorNode.h',
'PannerNode.h',
'PeriodicWave.h',
'ScriptProcessorNode.h',
@ -74,6 +75,7 @@ CPP_SOURCES += [
'MediaStreamAudioDestinationNode.cpp',
'MediaStreamAudioSourceNode.cpp',
'OfflineAudioCompletionEvent.cpp',
'OscillatorNode.cpp',
'PannerNode.cpp',
'PeriodicWave.cpp',
'ScriptProcessorNode.cpp',

View File

@ -77,6 +77,7 @@ MOCHITEST_FILES := \
test_OfflineAudioContext.html \
test_offlineDestinationChannelCountLess.html \
test_offlineDestinationChannelCountMore.html \
test_oscillatorNode.html \
test_pannerNode.html \
test_pannerNode_equalPower.html \
test_periodicWave.html \

View File

@ -0,0 +1,52 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test the OscillatorNode interface</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
var context = new AudioContext();
var osc = context.createOscillator();
is(osc.channelCount, 2, "Oscillator node has 2 input channels by default");
is(osc.channelCountMode, "max", "Correct channelCountMode for the Oscillator node");
is(osc.channelInterpretation, "speakers", "Correct channelCountInterpretation for the Oscillator node");
is(osc.type, "sine", "Correct default type");
expectException(function() {
osc.type = "custom";
}, DOMException.NOT_SUPPORTED_ERR);
expectException(function() {
osc.type = osc.CUSTOM;
}, DOMException.NOT_SUPPORTED_ERR);
is(osc.type, "sine", "Cannot set the type to custom");
is(osc.frequency.value, 440, "Correct default frequency value");
is(osc.detune.value, 0, "Correct default detine value");
// Make sure that we can set all of the valid type values
var types = [
"sine",
"square",
"sawtooth",
"triangle",
];
for (var i = 0; i < types.length; ++i) {
osc.type = osc[types[i].toUpperCase()];
is(osc.type, types[i], "Correct alternname type enum value");
osc.type = types[i];
}
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>

View File

@ -13,7 +13,6 @@
#include "nsIScriptObjectPrincipal.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIScriptRuntime.h"
#include "nsIDOMScriptObjectFactory.h"
#include "jsapi.h"
#include "jsfriendapi.h"

View File

@ -37,6 +37,7 @@
#include "nsEventStateManager.h"
#include "nsFocusManager.h"
#include "nsHTMLStyleSheet.h"
#include "nsIJSRuntimeService.h"
#include "nsINameSpaceManager.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
@ -46,8 +47,6 @@
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIScriptContext.h"
#include "nsIScriptRuntime.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "mozilla/css/StyleRule.h"
@ -1991,7 +1990,7 @@ nsXULPrototypeAttribute::~nsXULPrototypeAttribute()
nsresult
nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsresult rv;
@ -2053,7 +2052,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
case eType_Element:
case eType_Text:
case eType_PI:
tmp = child->Serialize(aStream, aGlobal, aNodeInfos);
tmp = child->Serialize(aStream, aProtoDoc, aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2070,7 +2069,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
rv = tmp;
}
if (! script->mOutOfLine) {
tmp = script->Serialize(aStream, aGlobal, aNodeInfos);
tmp = script->Serialize(aStream, aProtoDoc, aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2088,7 +2087,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
// muxed document is already there (written by a prior
// session, or by an earlier cache episode during this
// session).
tmp = script->SerializeOutOfLine(aStream, aGlobal);
tmp = script->SerializeOutOfLine(aStream, aProtoDoc);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2103,7 +2102,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
@ -2177,7 +2176,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2189,7 +2188,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2201,7 +2200,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2220,7 +2219,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
rv = tmp;
}
if (! script->mOutOfLine) {
tmp = script->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2231,7 +2230,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
rv = tmp;
}
tmp = script->DeserializeOutOfLine(aStream, aGlobal);
tmp = script->DeserializeOutOfLine(aStream, aProtoDoc);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2371,10 +2370,14 @@ nsXULPrototypeScript::~nsXULPrototypeScript()
nsresult
nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsIScriptContext *context = aGlobal->GetScriptContext();
AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, aProtoDoc->GetCompilationGlobal());
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
JSAutoCompartment ac(cx, global);
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
!mScriptObject,
"script source still loading when serializing?!");
@ -2388,22 +2391,20 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
rv = aStream->Write32(mLangVersion);
if (NS_FAILED(rv)) return rv;
// And delegate the writing to the nsIScriptContext.
//
// Calling fromMarkedLocation() is safe because we trace mScriptObject in
// TraceScriptObject() and because its value is never changed after it has
// been set.
JS::Handle<JSScript*> script =
JS::Handle<JSScript*>::fromMarkedLocation(mScriptObject.address());
rv = context->Serialize(aStream, script);
if (NS_FAILED(rv)) return rv;
return NS_OK;
MOZ_ASSERT(!strcmp(JS_GetClass(JS::CurrentGlobalOrNull(cx))->name,
"nsXULPrototypeScript compilation scope"));
return nsContentUtils::XPConnect()->WriteScript(aStream, cx,
xpc_UnmarkGrayScript(script));
}
nsresult
nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal)
nsXULPrototypeDocument* aProtoDoc)
{
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
@ -2433,7 +2434,7 @@ nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
rv = cache->GetOutputStream(mSrcURI, getter_AddRefs(oos));
NS_ENSURE_SUCCESS(rv, rv);
nsresult tmp = Serialize(oos, aGlobal, nullptr);
nsresult tmp = Serialize(oos, aProtoDoc, nullptr);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2450,12 +2451,10 @@ nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsresult rv;
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
!mScriptObject,
"prototype script not well-initialized when deserializing?!");
@ -2464,16 +2463,17 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
aStream->Read32(&mLineNo);
aStream->Read32(&mLangVersion);
nsIScriptContext *context = aGlobal->GetScriptContext();
NS_ASSERTION(context != nullptr, "Have no context for deserialization");
NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
JSAutoRequest ar(context->GetNativeContext());
JS::Rooted<JSScript*> newScriptObject(context->GetNativeContext());
rv = context->Deserialize(aStream, &newScriptObject);
if (NS_FAILED(rv)) {
NS_WARNING("Language deseralization failed");
return rv;
}
AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, aProtoDoc->GetCompilationGlobal());
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
JSAutoCompartment ac(cx, global);
JS::Rooted<JSScript*> newScriptObject(cx);
MOZ_ASSERT(!strcmp(JS_GetClass(JS::CurrentGlobalOrNull(cx))->name,
"nsXULPrototypeScript compilation scope"));
nsresult rv = nsContentUtils::XPConnect()->ReadScript(aStream, cx,
newScriptObject.address());
NS_ENSURE_SUCCESS(rv, rv);
Set(newScriptObject);
return NS_OK;
}
@ -2481,7 +2481,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
nsresult
nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
nsIScriptGlobalObject* aGlobal)
nsXULPrototypeDocument* aProtoDoc)
{
// Keep track of failure via rv, so we can
// AbortCaching if things look bad.
@ -2525,7 +2525,7 @@ nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
// We're better off slow-loading than bailing out due to a
// error.
if (NS_SUCCEEDED(rv))
rv = Deserialize(objectInput, aGlobal, nullptr, nullptr);
rv = Deserialize(objectInput, aProtoDoc, nullptr, nullptr);
if (NS_SUCCEEDED(rv)) {
if (useXULCache && mSrcURI) {
@ -2573,7 +2573,12 @@ NotifyOffThreadScriptCompletedRunnable::Run()
// Note: this unroots mScript so that it is available to be collected by the
// JS GC. The receiver needs to root the script before performing a call that
// could GC.
JS::FinishOffThreadScript(nsJSRuntime::sRuntime, mScript);
nsCOMPtr<nsIJSRuntimeService> svc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(svc, NS_ERROR_FAILURE);
JSRuntime *rt;
svc->GetRuntime(&rt);
NS_ENSURE_TRUE(svc, NS_ERROR_FAILURE);
JS::FinishOffThreadScript(rt, mScript);
return mReceiver->OnScriptCompileComplete(mScript, mScript ? NS_OK : NS_ERROR_FAILURE);
}
@ -2596,7 +2601,7 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
nsIURI* aURI,
uint32_t aLineNo,
nsIDocument* aDocument,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIOffThreadScriptReceiver *aOffThreadReceiver /* = nullptr */)
{
// We'll compile the script using the prototype document's special
@ -2609,33 +2614,16 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
// our script object would reference the first document, and the
// first document would indirectly reference the prototype document
// because it keeps the prototype cache alive. Circularity!
NS_ASSERTION(aGlobal, "prototype doc has no script global");
if (!aGlobal) {
return NS_ERROR_UNEXPECTED;
}
// Use the prototype document's special context
nsIScriptContext *context = aGlobal->GetScriptContext();
NS_ASSERTION(context, "no context for script global");
if (! context) {
return NS_ERROR_UNEXPECTED;
}
MOZ_ASSERT(aProtoDoc);
NS_ENSURE_TRUE(aProtoDoc->GetCompilationGlobal(), NS_ERROR_UNEXPECTED);
AutoSafeJSContext cx;
JSAutoCompartment ac(cx, aProtoDoc->GetCompilationGlobal());
nsAutoCString urlspec;
nsContentUtils::GetWrapperSafeScriptFilename(aDocument, aURI, urlspec);
// Ok, compile it to create a prototype script object!
JSContext* cx = context->GetNativeContext();
AutoCxPusher pusher(cx);
bool ok = false;
nsresult rv = nsContentUtils::GetSecurityManager()->
CanExecuteScripts(cx, aDocument->NodePrincipal(), &ok);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(ok, NS_OK);
NS_ENSURE_TRUE(JSVersion(mLangVersion) != JSVERSION_UNKNOWN, NS_OK);
JS::CompileOptions options(cx);
options.setPrincipals(nsJSPrincipals::get(aDocument->NodePrincipal()))
.setFileAndLine(urlspec.get(), aLineNo)
@ -2697,7 +2685,7 @@ nsXULPrototypeScript::Set(JSScript* aObject)
nsresult
nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsresult rv;
@ -2715,7 +2703,7 @@ nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
@ -2733,7 +2721,7 @@ nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
nsresult
nsXULPrototypePI::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsresult rv;
@ -2755,7 +2743,7 @@ nsXULPrototypePI::Serialize(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypePI::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{

View File

@ -40,10 +40,10 @@
class nsIDocument;
class nsString;
class nsIDocShell;
class nsXULPrototypeDocument;
class nsIObjectInputStream;
class nsIObjectOutputStream;
class nsIScriptGlobalObject;
class nsXULPrototypeNode;
typedef nsTArray<nsRefPtr<nsXULPrototypeNode> > nsPrototypeArray;
@ -110,10 +110,10 @@ public:
virtual ~nsXULPrototypeNode() {}
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) = 0;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) = 0;
@ -174,10 +174,10 @@ public:
}
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
@ -217,21 +217,21 @@ public:
#endif
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
nsresult SerializeOutOfLine(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal);
nsXULPrototypeDocument* aProtoDoc);
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
nsresult DeserializeOutOfLine(nsIObjectInputStream* aInput,
nsIScriptGlobalObject* aGlobal);
nsXULPrototypeDocument* aProtoDoc);
nsresult Compile(const PRUnichar* aText, int32_t aTextLength,
nsIURI* aURI, uint32_t aLineNo,
nsIDocument* aDocument,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIOffThreadScriptReceiver *aOffThreadReceiver = nullptr);
void UnlinkJSObjects();
@ -292,10 +292,10 @@ public:
#endif
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
@ -320,10 +320,10 @@ public:
#endif
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;

View File

@ -65,8 +65,6 @@
#include "nsIObjectOutputStream.h"
#include "nsContentList.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptRuntime.h"
#include "nsIScriptSecurityManager.h"
#include "nsNodeInfoManager.h"
#include "nsContentCreatorFunctions.h"
@ -3525,7 +3523,7 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
rv = mCurrentScriptProto->Compile(mOffThreadCompileString.get(),
mOffThreadCompileString.Length(),
uri, 1, this,
mCurrentPrototype->GetScriptGlobalObject(),
mCurrentPrototype,
this);
if (NS_SUCCEEDED(rv) && !mCurrentScriptProto->GetScriptObject()) {
// We will be notified via OnOffThreadCompileComplete when the
@ -3615,20 +3613,8 @@ XULDocument::OnScriptCompileComplete(JSScript* aScript, nsresult aStatus)
// Ignore the return value, as we don't need to propagate
// a failure to write to the FastLoad file, because this
// method aborts that whole process on error.
nsIScriptGlobalObject* global =
mCurrentPrototype->GetScriptGlobalObject();
NS_ASSERTION(global != nullptr, "master prototype w/o global?!");
if (global) {
nsIScriptContext *scriptContext =
global->GetScriptContext();
NS_ASSERTION(scriptContext != nullptr,
"Failed to get script context for language");
if (scriptContext)
scriptProto->SerializeOutOfLine(nullptr, global);
}
scriptProto->SerializeOutOfLine(nullptr, mCurrentPrototype);
}
// ignore any evaluation errors
}

View File

@ -30,7 +30,6 @@
#include "nsINodeInfo.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptRuntime.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsParserBase.h"
@ -567,8 +566,7 @@ XULContentSinkImpl::HandleEndElement(const PRUnichar *aName)
script->mOutOfLine = false;
if (doc)
script->Compile(mText, mTextLength, mDocumentURL,
script->mLineNo, doc,
mPrototype->GetScriptGlobalObject());
script->mLineNo, doc, mPrototype);
}
FlushText(false);
@ -986,8 +984,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
// file right away. Otherwise we'll end up reloading the script and
// corrupting the FastLoad file trying to serialize it, in the case
// where it's already there.
if (globalObject)
script->DeserializeOutOfLine(nullptr, globalObject);
script->DeserializeOutOfLine(nullptr, mPrototype);
}
nsPrototypeArray* children = nullptr;

View File

@ -8,7 +8,6 @@
#include "plstr.h"
#include "nsXULPrototypeDocument.h"
#include "nsCSSStyleSheet.h"
#include "nsIScriptRuntime.h"
#include "nsIServiceManager.h"
#include "nsIURI.h"

View File

@ -15,7 +15,6 @@
#include "nsIScriptGlobalObject.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIScriptSecurityManager.h"
#include "nsIScriptRuntime.h"
#include "nsIServiceManager.h"
#include "nsIArray.h"
#include "nsIURI.h"
@ -36,48 +35,35 @@
using mozilla::dom::DestroyProtoAndIfaceCache;
using mozilla::AutoPushJSContext;
using mozilla::AutoSafeJSContext;
using mozilla::dom::XULDocument;
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
class nsXULPDGlobalObject : public nsIScriptGlobalObject
class nsXULPDGlobalObject : public nsISupports
{
public:
nsXULPDGlobalObject(nsXULPrototypeDocument* owner);
// nsISupports interface
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsXULPDGlobalObject)
// nsIGlobalJSObjectHolder methods
virtual JSObject* GetGlobalJSObject();
// nsIScriptGlobalObject methods
virtual void OnFinalize(JSObject* aObject);
virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts);
virtual nsresult EnsureScriptEnvironment();
virtual nsIScriptContext *GetScriptContext();
// nsIScriptObjectPrincipal methods
virtual nsIPrincipal* GetPrincipal();
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPDGlobalObject,
nsIScriptGlobalObject)
JSObject* GetCompilationGlobal();
void UnmarkCompilationGlobal() { xpc_UnmarkGrayObject(mJSObject); }
void Destroy();
nsIPrincipal* GetPrincipal();
void ClearGlobalObjectOwner();
protected:
virtual ~nsXULPDGlobalObject();
nsXULPrototypeDocument* mGlobalObjectOwner; // weak reference
nsCOMPtr<nsIScriptContext> mContext;
JSObject* mJSObject;
nsCOMPtr<nsIPrincipal> mCachedPrincipal;
nsXULPrototypeDocument* mGlobalObjectOwner; // weak reference
JS::Heap<JSObject*> mJSObject;
bool mDestroyed; // Probably not necessary, but let's be safe.
static JSClass gSharedGlobalClass;
};
@ -91,7 +77,7 @@ void
nsXULPDGlobalObject_finalize(JSFreeOp *fop, JSObject *obj)
{
nsXULPDGlobalObject* nativeThis = static_cast<nsXULPDGlobalObject*>(JS_GetPrivate(obj));
nativeThis->OnFinalize(obj);
nativeThis->Destroy();
// The addref was part of JSObject construction
nsContentUtils::DeferredFinalize(nativeThis);
@ -169,8 +155,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeDocument)
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mGlobalObject");
cb.NoteXPCOMChild(static_cast<nsIScriptGlobalObject*>(tmp->mGlobalObject));
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobalObject)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNodeInfoManager)
for (uint32_t i = 0; i < tmp->mPrototypeWaiters.Length(); ++i) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mPrototypeWaiters[i]");
@ -179,9 +164,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPrototypeDocument)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsISerializable)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULPrototypeDocument)
@ -208,8 +192,7 @@ NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult)
// Helper method that shares a system global among all prototype documents
// that have the system principal as their security principal. Called by
// nsXULPrototypeDocument::Read and
// nsXULPrototypeDocument::GetScriptGlobalObject.
// nsXULPrototypeDocument::Read and nsXULPrototypeDocument::GetCompilationGlobal.
// This method greatly reduces the number of nsXULPDGlobalObjects and their
// nsIScriptContexts in apps that load many XUL documents via chrome: URLs.
@ -349,7 +332,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
break;
}
tmp = pi->Deserialize(aStream, mGlobalObject, mURI, &nodeInfos);
tmp = pi->Deserialize(aStream, this, mURI, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -358,7 +341,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
rv = tmp;
}
} else if ((nsXULPrototypeNode::Type)type == nsXULPrototypeNode::eType_Element) {
tmp = mRoot->Deserialize(aStream, mGlobalObject, mURI, &nodeInfos);
tmp = mRoot->Deserialize(aStream, this, mURI, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -508,20 +491,17 @@ nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream)
}
// Now serialize the document contents
nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED);
count = mProcessingInstructions.Length();
for (i = 0; i < count; ++i) {
nsXULPrototypePI* pi = mProcessingInstructions[i];
tmp = pi->Serialize(aStream, globalObject, &nodeInfos);
tmp = pi->Serialize(aStream, this, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
}
if (mRoot) {
tmp = mRoot->Serialize(aStream, globalObject, &nodeInfos);
tmp = mRoot->Serialize(aStream, this, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -629,6 +609,24 @@ nsXULPrototypeDocument::SetDocumentPrincipal(nsIPrincipal* aPrincipal)
mNodeInfoManager->SetDocumentPrincipal(aPrincipal);
}
JSObject*
nsXULPrototypeDocument::GetCompilationGlobal()
{
if (!mGlobalObject) {
mGlobalObject = NewXULPDGlobalObject();
}
return mGlobalObject->GetCompilationGlobal();
}
void
nsXULPrototypeDocument::MarkInCCGeneration(uint32_t aCCGeneration)
{
mCCGeneration = aCCGeneration;
if (mGlobalObject) {
mGlobalObject->UnmarkCompilationGlobal();
}
}
nsNodeInfoManager*
nsXULPrototypeDocument::GetNodeInfoManager()
{
@ -690,20 +688,6 @@ nsXULPrototypeDocument::TraceProtos(JSTracer* aTrc, uint32_t aGCNumber)
}
}
//----------------------------------------------------------------------
//
// nsIScriptGlobalObjectOwner methods
//
nsIScriptGlobalObject*
nsXULPrototypeDocument::GetScriptGlobalObject()
{
if (!mGlobalObject)
mGlobalObject = NewXULPDGlobalObject();
return mGlobalObject;
}
//----------------------------------------------------------------------
//
// nsXULPDGlobalObject
@ -712,115 +696,69 @@ nsXULPrototypeDocument::GetScriptGlobalObject()
nsXULPDGlobalObject::nsXULPDGlobalObject(nsXULPrototypeDocument* owner)
: mGlobalObjectOwner(owner)
, mJSObject(nullptr)
, mDestroyed(false)
{
}
nsXULPDGlobalObject::~nsXULPDGlobalObject()
{
MOZ_ASSERT(!mJSObject);
}
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPDGlobalObject)
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULPDGlobalObject)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXULPDGlobalObject)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mJSObject)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPDGlobalObject)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContext)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPDGlobalObject)
tmp->Destroy();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPDGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULPDGlobalObject)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULPDGlobalObject)
//----------------------------------------------------------------------
//
// nsIScriptGlobalObject methods
//
nsresult
nsXULPDGlobalObject::EnsureScriptEnvironment()
JSObject *
nsXULPDGlobalObject::GetCompilationGlobal()
{
if (mContext) {
return NS_OK;
}
NS_ASSERTION(!mJSObject, "Have global without context?");
nsCOMPtr<nsIScriptRuntime> languageRuntime;
nsresult rv = NS_GetJSRuntime(getter_AddRefs(languageRuntime));
NS_ENSURE_SUCCESS(rv, NS_OK);
nsCOMPtr<nsIScriptContext> ctxNew = languageRuntime->CreateContext(false, nullptr);
MOZ_ASSERT(ctxNew);
// We have to setup a special global object. We do this then
// attach it as the global for this context. Then, we
// will re-fetch the global and set it up in our language globals array.
{
AutoPushJSContext cx(ctxNew->GetNativeContext());
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setInvisibleToDebugger(true);
JS::Rooted<JSObject*> newGlob(cx,
JS_NewGlobalObject(cx, &gSharedGlobalClass,
nsJSPrincipals::get(GetPrincipal()), JS::DontFireOnNewGlobalHook,
options));
if (!newGlob)
return NS_OK;
js::SetDefaultObjectForContext(cx, newGlob);
// Add an owning reference from JS back to us. This'll be
// released when the JSObject is finalized.
::JS_SetPrivate(newGlob, this);
NS_ADDREF(this);
if (mJSObject || mDestroyed) {
// We've been initialized before. This is what we get.
return xpc_UnmarkGrayObject(mJSObject);
}
// should probably assert the context is clean???
ctxNew->WillInitializeContext();
rv = ctxNew->InitContext();
NS_ENSURE_SUCCESS(rv, NS_OK);
AutoSafeJSContext cx;
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setInvisibleToDebugger(true);
mJSObject = JS_NewGlobalObject(cx, &gSharedGlobalClass,
nsJSPrincipals::get(GetPrincipal()),
JS::DontFireOnNewGlobalHook, options);
NS_ENSURE_TRUE(mJSObject, nullptr);
ctxNew->DidInitializeContext();
NS_HOLD_JS_OBJECTS(this, nsXULPDGlobalObject);
JSObject* global = ctxNew->GetNativeGlobal();
NS_ASSERTION(global, "GetNativeGlobal returned nullptr!");
mContext = ctxNew;
mJSObject = global;
// Add an owning reference from JS back to us. This'll be
// released when the JSObject is finalized.
JS_SetPrivate(mJSObject, this);
NS_ADDREF(this);
// Set the location information for the new global, so that tools like
// about:memory may use that information
nsIURI *ownerURI = mGlobalObjectOwner->GetURI();
xpc::SetLocationForGlobal(mJSObject, ownerURI);
return NS_OK;
return mJSObject;
}
nsIScriptContext*
nsXULPDGlobalObject::GetScriptContext()
{
// This global object creates a context on demand - do that now.
nsresult rv = EnsureScriptEnvironment();
if (NS_FAILED(rv)) {
NS_ERROR("Failed to setup script language");
return nullptr;
}
return mContext;
}
JSObject*
nsXULPDGlobalObject::GetGlobalJSObject()
{
return xpc_UnmarkGrayObject(mJSObject);
}
void
nsXULPDGlobalObject::ClearGlobalObjectOwner()
{
@ -830,28 +768,20 @@ nsXULPDGlobalObject::ClearGlobalObjectOwner()
if (this != nsXULPrototypeDocument::gSystemGlobal)
mCachedPrincipal = mGlobalObjectOwner->DocumentPrincipal();
mContext = nullptr;
mGlobalObjectOwner = nullptr;
}
void
nsXULPDGlobalObject::OnFinalize(JSObject* aObject)
nsXULPDGlobalObject::Destroy()
{
mDestroyed = true;
if (!mJSObject) {
return;
}
mJSObject = nullptr;
NS_DROP_JS_OBJECTS(this, nsXULPDGlobalObject);
}
void
nsXULPDGlobalObject::SetScriptsEnabled(bool aEnabled, bool aFireTimeouts)
{
// We don't care...
}
//----------------------------------------------------------------------
//
// nsIScriptObjectPrincipal methods
//
nsIPrincipal*
nsXULPDGlobalObject::GetPrincipal()
{

View File

@ -11,7 +11,6 @@
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsISerializable.h"
#include "nsCycleCollectionParticipant.h"
@ -37,8 +36,7 @@ class XULDocument;
* objects, from which the real DOM tree is built later in
* XULDocument::ResumeWalk.
*/
class nsXULPrototypeDocument : public nsIScriptGlobalObjectOwner,
public nsISerializable
class nsXULPrototypeDocument : public nsISerializable
{
public:
static nsresult
@ -114,16 +112,11 @@ public:
nsNodeInfoManager *GetNodeInfoManager();
// nsIScriptGlobalObjectOwner methods
virtual nsIScriptGlobalObject* GetScriptGlobalObject() MOZ_OVERRIDE;
JSObject* GetCompilationGlobal();
void MarkInCCGeneration(uint32_t aCCGeneration)
{
mCCGeneration = aCCGeneration;
}
void MarkInCCGeneration(uint32_t aCCGeneration);
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPrototypeDocument,
nsIScriptGlobalObjectOwner)
NS_DECL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument)
void TraceProtos(JSTracer* aTrc, uint32_t aGCNumber);

View File

@ -1452,8 +1452,7 @@ Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
return true;
}
nsScriptNameSpaceManager* nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager* nameSpaceManager = GetNameSpaceManager();
if (!nameSpaceManager) {
return Throw<true>(aCx, NS_ERROR_NOT_INITIALIZED);
}
@ -1567,8 +1566,7 @@ void
Navigator::GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames,
ErrorResult& aRv)
{
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
if (!nameSpaceManager) {
NS_ERROR("Can't get namespace manager.");
aRv.Throw(NS_ERROR_UNEXPECTED);

View File

@ -37,7 +37,6 @@ EXPORTS += [
'nsIScriptGlobalObjectOwner.h',
'nsIScriptNameSpaceManager.h',
'nsIScriptObjectPrincipal.h',
'nsIScriptRuntime.h',
'nsIScriptTimeoutHandler.h',
'nsJSEnvironment.h',
'nsJSUtils.h',

View File

@ -911,8 +911,7 @@ CutPrefix(const char *aName) {
nsresult
nsDOMClassInfo::RegisterClassProtos(int32_t aClassInfoID)
{
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
bool found_old;
@ -964,8 +963,7 @@ nsDOMClassInfo::RegisterClassProtos(int32_t aClassInfoID)
nsresult
nsDOMClassInfo::RegisterExternalClasses()
{
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIComponentRegistrar> registrar;
@ -1097,7 +1095,7 @@ nsDOMClassInfo::Init()
NS_ENSURE_TRUE(!sIsInitialized, NS_ERROR_ALREADY_INITIALIZED);
nsScriptNameSpaceManager *nameSpaceManager = nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
nsresult rv = CallGetService(nsIXPConnect::GetCID(), &sXPConnect);
@ -2072,8 +2070,7 @@ nsDOMClassInfo::PostCreatePrototype(JSContext * cx, JSObject * aProto)
return NS_ERROR_FAILURE;
}
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, NS_OK);
bool unused;
@ -2271,8 +2268,7 @@ nsWindowSH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
// Now resolve everything from the namespace manager
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
if (!nameSpaceManager) {
NS_ERROR("Can't get namespace manager.");
return NS_ERROR_UNEXPECTED;
@ -2556,8 +2552,7 @@ private:
{
*aNameStruct = nullptr;
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
if (!nameSpaceManager) {
NS_ERROR("Can't get namespace manager.");
return NS_ERROR_UNEXPECTED;
@ -2764,8 +2759,7 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
}
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ASSERTION(nameSpaceManager, "Can't get namespace manager?");
const nsIID *class_iid;
@ -3158,8 +3152,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
{
*did_resolve = false;
nsScriptNameSpaceManager *nameSpaceManager =
nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
nsDependentJSString name(id);

View File

@ -31,7 +31,7 @@
#endif
#include "nsThreadUtils.h"
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
using mozilla::dom::GetNameSpaceManager;
nsIExceptionProvider* gExceptionProvider = nullptr;
@ -57,9 +57,6 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory()
NS_ASSERTION(!gExceptionProvider, "Registered twice?!");
provider.swap(gExceptionProvider);
// And pre-create the javascript language.
NS_CreateJSRuntime(getter_AddRefs(mJSRuntime));
}
NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory)
@ -81,7 +78,7 @@ nsDOMScriptObjectFactory::GetClassInfoInstance(nsDOMClassInfoID aID)
NS_IMETHODIMP_(nsISupports *)
nsDOMScriptObjectFactory::GetExternalClassInfoInstance(const nsAString& aName)
{
nsScriptNameSpaceManager *nameSpaceManager = nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, nullptr);
const nsGlobalNameStruct *globalStruct = nameSpaceManager->LookupName(aName);
@ -158,7 +155,7 @@ nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName,
bool aHasClassInterface,
const nsCID *aConstructorCID)
{
nsScriptNameSpaceManager *nameSpaceManager = nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
return nameSpaceManager->RegisterDOMCIData(aName,
@ -170,42 +167,6 @@ nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName,
aConstructorCID);
}
// Factories
nsresult
NS_GetJSRuntime(nsIScriptRuntime** aLanguage)
{
nsCOMPtr<nsIDOMScriptObjectFactory> factory =
do_GetService(kDOMScriptObjectFactoryCID);
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
NS_IF_ADDREF(*aLanguage = factory->GetJSRuntime());
return NS_OK;
}
nsresult NS_GetScriptRuntime(const nsAString &aLanguageName,
nsIScriptRuntime **aLanguage)
{
*aLanguage = NULL;
NS_ENSURE_TRUE(aLanguageName.EqualsLiteral("application/javascript"),
NS_ERROR_FAILURE);
return NS_GetJSRuntime(aLanguage);
}
nsresult NS_GetScriptRuntimeByID(uint32_t aScriptTypeID,
nsIScriptRuntime **aLanguage)
{
*aLanguage = NULL;
NS_ENSURE_TRUE(aScriptTypeID == nsIProgrammingLanguage::JAVASCRIPT,
NS_ERROR_FAILURE);
return NS_GetJSRuntime(aLanguage);
}
NS_IMPL_ISUPPORTS1(nsDOMExceptionProvider, nsIExceptionProvider)
NS_IMETHODIMP

View File

@ -156,7 +156,6 @@
#include "nsWindowRoot.h"
#include "nsNetCID.h"
#include "nsIArray.h"
#include "nsIScriptRuntime.h"
// XXX An unfortunate dependency exists here (two XUL files).
#include "nsIDOMXULDocument.h"
@ -1786,22 +1785,17 @@ nsGlobalWindow::EnsureScriptEnvironment()
NS_ASSERTION(!GetCurrentInnerWindowInternal(),
"mJSObject is null, but we have an inner window?");
nsCOMPtr<nsIScriptRuntime> scriptRuntime;
nsresult rv = NS_GetJSRuntime(getter_AddRefs(scriptRuntime));
NS_ENSURE_SUCCESS(rv, rv);
// If this window is a [i]frame, don't bother GC'ing when the frame's context
// is destroyed since a GC will happen when the frameset or host document is
// destroyed anyway.
nsCOMPtr<nsIScriptContext> context =
scriptRuntime->CreateContext(!IsFrame(), this);
nsCOMPtr<nsIScriptContext> context = new nsJSContext(!IsFrame(), this);
NS_ASSERTION(!mContext, "Will overwrite mContext!");
// should probably assert the context is clean???
context->WillInitializeContext();
rv = context->InitContext();
nsresult rv = context->InitContext();
NS_ENSURE_SUCCESS(rv, rv);
mContext = context;

View File

@ -9,7 +9,6 @@
#include "nsISupports.h"
#include "nsIDOMClassInfo.h"
#include "nsStringGlue.h"
#include "nsIScriptRuntime.h"
#define NS_IDOM_SCRIPT_OBJECT_FACTORY_IID \
{ 0x2a50e17c, 0x46ff, 0x4150, \
@ -41,14 +40,6 @@ public:
uint32_t aScriptableFlags,
bool aHasClassInterface,
const nsCID *aConstructorCID) = 0;
nsIScriptRuntime* GetJSRuntime()
{
return mJSRuntime;
}
protected:
nsCOMPtr<nsIScriptRuntime> mJSRuntime;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMScriptObjectFactory,

View File

@ -28,8 +28,8 @@ class nsIDOMWindow;
class nsIURI;
#define NS_ISCRIPTCONTEXT_IID \
{ 0x6219173f, 0x4a61, 0x4c99, \
{ 0xb1, 0xfd, 0x8e, 0x7a, 0xf0, 0xdc, 0xe0, 0x56 } }
{ 0x1d931a17, 0x453a, 0x47fb, \
{ 0x94, 0x66, 0x2d, 0x3e, 0xd1, 0xef, 0x7a, 0xc5 } }
/* This MUST match JSVERSION_DEFAULT. This version stuff if we don't
know what language we have is a little silly... */
@ -132,14 +132,6 @@ public:
*/
virtual void GC(JS::gcreason::Reason aReason) = 0;
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
JS::Handle<JSScript*> aScriptObject) = 0;
/* Deserialize a script from a stream.
*/
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
JS::MutableHandle<JSScript*> aResult) = 0;
/**
* Called to disable/enable script execution in this context.
*/

View File

@ -1,41 +0,0 @@
/* 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/. */
#ifndef nsIScriptRuntime_h__
#define nsIScriptRuntime_h__
#include "nsIScriptContext.h"
#define NS_ISCRIPTRUNTIME_IID \
{ 0x86c6b54a, 0xf067, 0x4878, \
{ 0xb2, 0x77, 0x4e, 0xee, 0x95, 0xda, 0x8f, 0x76 } }
/**
* A singleton language environment for an application. Responsible for
* initializing and cleaning up the global language environment, and a factory
* for language contexts
*/
class nsIScriptRuntime : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTRUNTIME_IID)
/* Factory for a new context for this language */
virtual already_AddRefed<nsIScriptContext>
CreateContext(bool aGCOnDestruction,
nsIScriptGlobalObject* aGlobalObject) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptRuntime, NS_ISCRIPTRUNTIME_IID)
/* helper functions */
nsresult NS_GetJSRuntime(nsIScriptRuntime** aLanguage);
nsresult NS_GetScriptRuntime(const nsAString &aLanguageName,
nsIScriptRuntime **aRuntime);
nsresult NS_GetScriptRuntimeByID(uint32_t aLanguageID,
nsIScriptRuntime **aRuntime);
#endif // nsIScriptRuntime_h__

View File

@ -135,7 +135,7 @@ static PRLogModuleInfo* gJSDiagnostics;
#define NS_MAJOR_FORGET_SKIPPABLE_CALLS 2
// if you add statics here, add them to the list in nsJSRuntime::Startup
// if you add statics here, add them to the list in StartupJSEnvironment
static nsITimer *sGCTimer;
static nsITimer *sShrinkGCBuffersTimer;
@ -179,13 +179,14 @@ static nsJSContext *sContextList = nullptr;
static nsScriptNameSpaceManager *gNameSpaceManager;
static nsIJSRuntimeService *sRuntimeService;
JSRuntime *nsJSRuntime::sRuntime;
static const char kJSRuntimeServiceContractID[] =
"@mozilla.org/js/xpc/RuntimeService;1";
static PRTime sFirstCollectionTime;
static JSRuntime *sRuntime;
static bool sIsInitialized;
static bool sDidShutdown;
static bool sShuttingDown;
@ -809,11 +810,13 @@ nsJSContext::JSOptionChangedCallback(const char *pref, void *data)
return 0;
}
nsJSContext::nsJSContext(JSRuntime *aRuntime, bool aGCOnDestruction,
nsJSContext::nsJSContext(bool aGCOnDestruction,
nsIScriptGlobalObject* aGlobalObject)
: mGCOnDestruction(aGCOnDestruction)
, mGlobalObjectRef(aGlobalObject)
{
EnsureStatics();
mNext = sContextList;
mPrev = &sContextList;
if (sContextList) {
@ -825,7 +828,7 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime, bool aGCOnDestruction,
mDefaultJSOptions = JSOPTION_PRIVATE_IS_NSISUPPORTS;
mContext = ::JS_NewContext(aRuntime, gStackSize);
mContext = ::JS_NewContext(sRuntime, gStackSize);
if (mContext) {
::JS_SetContextPrivate(mContext, static_cast<nsIScriptContext *>(this));
@ -1065,33 +1068,6 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget,
return rv;
}
// serialization
nsresult
nsJSContext::Serialize(nsIObjectOutputStream* aStream,
JS::Handle<JSScript*> aScriptObject)
{
if (!aScriptObject)
return NS_ERROR_FAILURE;
AutoPushJSContext cx(mContext);
return nsContentUtils::XPConnect()->WriteScript(aStream, cx,
xpc_UnmarkGrayScript(aScriptObject));
}
nsresult
nsJSContext::Deserialize(nsIObjectInputStream* aStream,
JS::MutableHandle<JSScript*> aResult)
{
AutoPushJSContext cx(mContext);
JS::Rooted<JSScript*> script(cx);
nsresult rv = nsContentUtils::XPConnect()->ReadScript(aStream, cx,
script.address());
if (NS_FAILED(rv)) return rv;
aResult.set(script);
return NS_OK;
}
nsIScriptGlobalObject *
nsJSContext::GetGlobalObject()
{
@ -1177,7 +1153,7 @@ nsJSContext::InitContext()
nsresult
nsJSContext::InitializeExternalClasses()
{
nsScriptNameSpaceManager *nameSpaceManager = nsJSRuntime::GetNameSpaceManager();
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
return nameSpaceManager->InitForContext(this);
@ -1952,22 +1928,22 @@ nsJSContext::GarbageCollectNow(JS::gcreason::Reason aReason,
sPendingLoadCount = 0;
sLoadingInProgress = false;
if (!nsContentUtils::XPConnect() || !nsJSRuntime::sRuntime) {
if (!nsContentUtils::XPConnect() || !sRuntime) {
return;
}
if (sCCLockedOut && aIncremental == IncrementalGC) {
// We're in the middle of incremental GC. Do another slice.
JS::PrepareForIncrementalGC(nsJSRuntime::sRuntime);
JS::IncrementalGC(nsJSRuntime::sRuntime, aReason, aSliceMillis);
JS::PrepareForIncrementalGC(sRuntime);
JS::IncrementalGC(sRuntime, aReason, aSliceMillis);
return;
}
JS::PrepareForFullGC(nsJSRuntime::sRuntime);
JS::PrepareForFullGC(sRuntime);
if (aIncremental == IncrementalGC) {
JS::IncrementalGC(nsJSRuntime::sRuntime, aReason, aSliceMillis);
JS::IncrementalGC(sRuntime, aReason, aSliceMillis);
} else {
JS::GCForReason(nsJSRuntime::sRuntime, aReason);
JS::GCForReason(sRuntime, aReason);
}
}
@ -1979,7 +1955,7 @@ nsJSContext::ShrinkGCBuffersNow()
KillShrinkGCBuffersTimer();
JS::ShrinkGCBuffers(nsJSRuntime::sRuntime);
JS::ShrinkGCBuffers(sRuntime);
}
static void
@ -1987,8 +1963,8 @@ FinishAnyIncrementalGC()
{
if (sCCLockedOut) {
// We're in the middle of an incremental GC, so finish it.
JS::PrepareForIncrementalGC(nsJSRuntime::sRuntime);
JS::FinishIncrementalGC(nsJSRuntime::sRuntime, JS::gcreason::CC_FORCED);
JS::PrepareForIncrementalGC(sRuntime);
JS::FinishIncrementalGC(sRuntime, JS::gcreason::CC_FORCED);
}
}
@ -2588,31 +2564,8 @@ nsJSContext::LikelyShortLivingObjectCreated()
++sLikelyShortLivingObjectsNeedingGC;
}
/**********************************************************************
* nsJSRuntime implementation
*********************************************************************/
// QueryInterface implementation for nsJSRuntime
NS_INTERFACE_MAP_BEGIN(nsJSRuntime)
NS_INTERFACE_MAP_ENTRY(nsIScriptRuntime)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsJSRuntime)
NS_IMPL_RELEASE(nsJSRuntime)
already_AddRefed<nsIScriptContext>
nsJSRuntime::CreateContext(bool aGCOnDestruction,
nsIScriptGlobalObject* aGlobalObject)
{
nsCOMPtr<nsIScriptContext> scriptContext =
new nsJSContext(sRuntime, aGCOnDestruction, aGlobalObject);
return scriptContext.forget();
}
//static
void
nsJSRuntime::Startup()
mozilla::dom::StartupJSEnvironment()
{
// initialize all our statics, so that we can restart XPCOM
sGCTimer = sFullGCTimer = sCCTimer = nullptr;
@ -2649,7 +2602,7 @@ SetMemoryHighWaterMarkPrefChangedCallback(const char* aPrefName, void* aClosure)
{
int32_t highwatermark = Preferences::GetInt(aPrefName, 128);
JS_SetGCParameter(nsJSRuntime::sRuntime, JSGC_MAX_MALLOC_BYTES,
JS_SetGCParameter(sRuntime, JSGC_MAX_MALLOC_BYTES,
highwatermark * 1024L * 1024L);
return 0;
}
@ -2660,7 +2613,7 @@ SetMemoryMaxPrefChangedCallback(const char* aPrefName, void* aClosure)
int32_t pref = Preferences::GetInt(aPrefName, -1);
// handle overflow and negative pref values
uint32_t max = (pref <= 0 || pref >= 0x1000) ? -1 : (uint32_t)pref * 1024 * 1024;
JS_SetGCParameter(nsJSRuntime::sRuntime, JSGC_MAX_BYTES, max);
JS_SetGCParameter(sRuntime, JSGC_MAX_BYTES, max);
return 0;
}
@ -2677,7 +2630,7 @@ SetMemoryGCModePrefChangedCallback(const char* aPrefName, void* aClosure)
} else {
mode = JSGC_MODE_GLOBAL;
}
JS_SetGCParameter(nsJSRuntime::sRuntime, JSGC_MODE, mode);
JS_SetGCParameter(sRuntime, JSGC_MODE, mode);
return 0;
}
@ -2687,7 +2640,7 @@ SetMemoryGCSliceTimePrefChangedCallback(const char* aPrefName, void* aClosure)
int32_t pref = Preferences::GetInt(aPrefName, -1);
// handle overflow and negative pref values
if (pref > 0 && pref < 100000)
JS_SetGCParameter(nsJSRuntime::sRuntime, JSGC_SLICE_TIME_BUDGET, pref);
JS_SetGCParameter(sRuntime, JSGC_SLICE_TIME_BUDGET, pref);
return 0;
}
@ -2697,7 +2650,7 @@ SetMemoryGCPrefChangedCallback(const char* aPrefName, void* aClosure)
int32_t pref = Preferences::GetInt(aPrefName, -1);
// handle overflow and negative pref values
if (pref >= 0 && pref < 10000)
JS_SetGCParameter(nsJSRuntime::sRuntime, (JSGCParamKey)(intptr_t)aClosure, pref);
JS_SetGCParameter(sRuntime, (JSGCParamKey)(intptr_t)aClosure, pref);
return 0;
}
@ -2705,7 +2658,7 @@ static int
SetMemoryGCDynamicHeapGrowthPrefChangedCallback(const char* aPrefName, void* aClosure)
{
bool pref = Preferences::GetBool(aPrefName);
JS_SetGCParameter(nsJSRuntime::sRuntime, JSGC_DYNAMIC_HEAP_GROWTH, pref);
JS_SetGCParameter(sRuntime, JSGC_DYNAMIC_HEAP_GROWTH, pref);
return 0;
}
@ -2713,7 +2666,7 @@ static int
SetMemoryGCDynamicMarkSlicePrefChangedCallback(const char* aPrefName, void* aClosure)
{
bool pref = Preferences::GetBool(aPrefName);
JS_SetGCParameter(nsJSRuntime::sRuntime, JSGC_DYNAMIC_MARK_SLICE, pref);
JS_SetGCParameter(sRuntime, JSGC_DYNAMIC_MARK_SLICE, pref);
return 0;
}
@ -2784,30 +2737,36 @@ NS_DOMStructuredCloneError(JSContext* cx,
xpc::Throw(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
}
//static
nsresult
nsJSRuntime::Init()
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
void
nsJSContext::EnsureStatics()
{
if (sIsInitialized) {
if (!nsContentUtils::XPConnect())
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
if (!nsContentUtils::XPConnect()) {
MOZ_CRASH();
}
return;
}
nsresult rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID,
&sSecurityManager);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
MOZ_CRASH();
}
rv = CallGetService(kJSRuntimeServiceContractID, &sRuntimeService);
// get the JSRuntime from the runtime svc, if possible
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
MOZ_CRASH();
}
rv = sRuntimeService->GetRuntime(&sRuntime);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
MOZ_CRASH();
}
// Let's make sure that our main thread is the same as the xpcom main thread.
NS_ASSERTION(NS_IsMainThread(), "bad");
MOZ_ASSERT(NS_IsMainThread());
sPrevGCSliceCallback = JS::SetGCSliceCallback(sRuntime, DOMGCSliceCallback);
@ -2882,8 +2841,9 @@ nsJSRuntime::Init()
(void *)JSGC_DECOMMIT_THRESHOLD);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (!obs)
return NS_ERROR_FAILURE;
if (!obs) {
MOZ_CRASH();
}
Preferences::AddBoolVarCache(&sGCOnMemoryPressure,
"javascript.options.gc_on_memory_pressure",
@ -2893,14 +2853,20 @@ nsJSRuntime::Init()
obs->AddObserver(observer, "memory-pressure", false);
obs->AddObserver(observer, "quit-application", false);
sIsInitialized = true;
// We need to explicitly get the nsIDOMScriptObjectFactory service in order
// to force its constructor to run, which registers various exceptions
// providers and other things. It would be nice to make this more explicit
// and less side-effect-y.
nsCOMPtr<nsIDOMScriptObjectFactory> factory = do_GetService(kDOMScriptObjectFactoryCID);
if (!factory) {
MOZ_CRASH();
}
return NS_OK;
sIsInitialized = true;
}
//static
nsScriptNameSpaceManager*
nsJSRuntime::GetNameSpaceManager()
mozilla::dom::GetNameSpaceManager()
{
if (sDidShutdown)
return nullptr;
@ -2916,9 +2882,8 @@ nsJSRuntime::GetNameSpaceManager()
return gNameSpaceManager;
}
/* static */
void
nsJSRuntime::Shutdown()
mozilla::dom::ShutdownJSEnvironment()
{
KillTimers();
@ -2936,19 +2901,6 @@ nsJSRuntime::Shutdown()
sDidShutdown = true;
}
// A factory for the runtime.
nsresult NS_CreateJSRuntime(nsIScriptRuntime **aRuntime)
{
nsresult rv = nsJSRuntime::Init();
NS_ENSURE_SUCCESS(rv, rv);
*aRuntime = new nsJSRuntime();
if (*aRuntime == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
NS_IF_ADDREF(*aRuntime);
return NS_OK;
}
// A fast-array class for JS. This class supports both nsIJSScriptArray and
// nsIArray. If it is JS itself providing and consuming this class, all work
// can be done via nsIJSScriptArray, and avoid the conversion of elements

View File

@ -6,7 +6,6 @@
#define nsJSEnvironment_h
#include "nsIScriptContext.h"
#include "nsIScriptRuntime.h"
#include "nsIScriptGlobalObject.h"
#include "nsCOMPtr.h"
#include "jsapi.h"
@ -34,8 +33,7 @@ template <class> class Maybe;
class nsJSContext : public nsIScriptContext
{
public:
nsJSContext(JSRuntime* aRuntime, bool aGCOnDestruction,
nsIScriptGlobalObject* aGlobalObject);
nsJSContext(bool aGCOnDestruction, nsIScriptGlobalObject* aGlobalObject);
virtual ~nsJSContext();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -74,11 +72,6 @@ public:
virtual void WillInitializeContext() MOZ_OVERRIDE;
virtual void DidInitializeContext() MOZ_OVERRIDE;
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
JS::Handle<JSScript*> aScriptObject) MOZ_OVERRIDE;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
JS::MutableHandle<JSScript*> aResult) MOZ_OVERRIDE;
static void LoadStart();
static void LoadEnd();
@ -97,6 +90,9 @@ public:
NonIncrementalGC
};
// Setup all the statics etc - safe to call multiple times after Startup().
void EnsureStatics();
static void GarbageCollectNow(JS::gcreason::Reason reason,
IsIncremental aIncremental = NonIncrementalGC,
IsCompartment aCompartment = NonCompartmentGC,
@ -188,27 +184,17 @@ private:
class nsIJSRuntimeService;
class nsJSRuntime MOZ_FINAL : public nsIScriptRuntime
{
public:
// let people who can see us use our runtime for convenience.
static JSRuntime *sRuntime;
namespace mozilla {
namespace dom {
public:
// nsISupports
NS_DECL_ISUPPORTS
void StartupJSEnvironment();
void ShutdownJSEnvironment();
virtual already_AddRefed<nsIScriptContext>
CreateContext(bool aGCOnDestruction,
nsIScriptGlobalObject* aGlobalObject) MOZ_OVERRIDE;
// Get the NameSpaceManager, creating if necessary
nsScriptNameSpaceManager* GetNameSpaceManager();
static void Startup();
static void Shutdown();
// Setup all the statics etc - safe to call multiple times after Startup()
static nsresult Init();
// Get the NameSpaceManager, creating if necessary
static nsScriptNameSpaceManager* GetNameSpaceManager();
};
} // namespace dom
} // namespace mozilla
// An interface for fast and native conversion to/from nsIArray. If an object
// supports this interface, JS can reach directly in for the argv, and avoid
@ -230,9 +216,6 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(nsIJSArgArray, NS_IJSARGARRAY_IID)
/* factory functions */
nsresult NS_CreateJSRuntime(nsIScriptRuntime **aRuntime);
/* prototypes */
void NS_ScriptErrorReporter(JSContext *cx, const char *message, JSErrorReport *report);

View File

@ -821,6 +821,10 @@ DOMInterfaces = {
'nativeType': 'nsDOMOfflineResourceList',
},
'OscillatorNode': {
'resultNotAddRefed': [ 'frequency', 'detune' ],
},
'PaintRequest': {
'nativeType': 'nsPaintRequest',
},

View File

@ -9,7 +9,6 @@
#include "nsIScriptSecurityManager.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptRuntime.h"
#include "nsIXPConnect.h"
#include "nsGUIEvent.h"
#include "nsContentUtils.h"

View File

@ -67,6 +67,8 @@ interface AudioContext : EventTarget {
[Creator]
DynamicsCompressorNode createDynamicsCompressor();
[Creator]
OscillatorNode createOscillator();
[Creator, Throws]
PeriodicWave createPeriodicWave(Float32Array real, Float32Array imag);

View File

@ -0,0 +1,68 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
enum OscillatorType {
// Hack: Use numbers to support alternate enum values
"0", "1", "2", "3", "4",
"sine",
"square",
"sawtooth",
"triangle",
"custom"
};
[PrefControlled]
interface OscillatorNode : AudioNode {
[SetterThrows]
attribute OscillatorType type;
readonly attribute AudioParam frequency; // in Hertz
readonly attribute AudioParam detune; // in Cents
[Throws]
void start(double when);
[Throws]
void stop(double when);
void setPeriodicWave(PeriodicWave periodicWave);
[SetterThrows]
attribute EventHandler onended;
};
/*
* The origin of this IDL file is
* https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#AlternateNames
*/
partial interface OscillatorNode {
// Same as start()
[Throws,Pref="media.webaudio.legacy.OscillatorNode"]
void noteOn(double when);
// Same as stop()
[Throws,Pref="media.webaudio.legacy.OscillatorNode"]
void noteOff(double when);
[Pref="media.webaudio.legacy.OscillatorNode"]
const unsigned short SINE = 0;
[Pref="media.webaudio.legacy.OscillatorNode"]
const unsigned short SQUARE = 1;
[Pref="media.webaudio.legacy.OscillatorNode"]
const unsigned short SAWTOOTH = 2;
[Pref="media.webaudio.legacy.OscillatorNode"]
const unsigned short TRIANGLE = 3;
[Pref="media.webaudio.legacy.OscillatorNode"]
const unsigned short CUSTOM = 4;
};

View File

@ -216,6 +216,7 @@ webidl_files = \
OfflineAudioCompletionEvent.webidl \
OfflineAudioContext.webidl \
OfflineResourceList.webidl \
OscillatorNode.webidl \
PaintRequest.webidl \
PaintRequestList.webidl \
PannerNode.webidl \

View File

@ -45,6 +45,7 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
mBuffer = nullptr;
}
bool bufferCreated = false;
if (!mBuffer) {
bool isOpaque = (aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE);
gfxASurface::gfxContentType contentType = isOpaque
@ -56,7 +57,7 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
MOZ_ASSERT(mBuffer->AsTextureClientSurface());
mBuffer->AsTextureClientSurface()->AllocateForSurface(aSize);
AddTextureClient(mBuffer);
bufferCreated = true;
}
if (!mBuffer->Lock(OPEN_READ_WRITE)) {
@ -70,6 +71,10 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
mBuffer->Unlock();
if (bufferCreated) {
AddTextureClient(mBuffer);
}
if (surface) {
GetForwarder()->UpdatedTexture(this, mBuffer, nullptr);
GetForwarder()->UseTexture(this, mBuffer);
@ -128,17 +133,13 @@ DeprecatedCanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
void
DeprecatedCanvasClientSurfaceStream::Updated()
{
if (mNeedsUpdate) {
mForwarder->UpdateTextureNoSwap(this, 1, mDeprecatedTextureClient->GetDescriptor());
mNeedsUpdate = false;
}
mForwarder->UpdateTextureNoSwap(this, 1, mDeprecatedTextureClient->GetDescriptor());
}
DeprecatedCanvasClientSurfaceStream::DeprecatedCanvasClientSurfaceStream(CompositableForwarder* aFwd,
TextureFlags aFlags)
: CanvasClient(aFwd, aFlags)
, mNeedsUpdate(false)
{
mTextureInfo.mCompositableType = BUFFER_IMAGE_SINGLE;
}
@ -180,7 +181,6 @@ DeprecatedCanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLaye
printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!");
MOZ_ASSERT(false);
#endif
mNeedsUpdate = true;
} else {
SurfaceStreamHandle handle = stream->GetShareHandle();
SurfaceDescriptor *desc = mDeprecatedTextureClient->GetDescriptor();
@ -193,7 +193,6 @@ DeprecatedCanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLaye
// Ref this so the SurfaceStream doesn't disappear unexpectedly. The
// Compositor will need to unref it when finished.
aLayer->mGLContext->AddRef();
mNeedsUpdate = true;
}
}

View File

@ -132,7 +132,6 @@ public:
private:
RefPtr<DeprecatedTextureClient> mDeprecatedTextureClient;
bool mNeedsUpdate;
};
}

View File

@ -86,13 +86,13 @@ ClientCanvasLayer::RenderLayer()
flags |= TEXTURE_NEEDS_Y_FLIP;
}
bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
//Append TEXTURE_DEALLOCATE_CLIENT flag for streaming buffer under OOPC case
if (isCrossProcess && mGLContext) {
GLScreenBuffer* screen = mGLContext->Screen();
if (screen && screen->Stream()) {
flags |= TEXTURE_DEALLOCATE_CLIENT;
}
if (!mGLContext) {
// GLContext's SurfaceStream handles ownership itself,
// and doesn't require layers to do any deallocation.
flags |= TEXTURE_DEALLOCATE_HOST;
// We don't support locking for buffer surfaces currently
flags |= TEXTURE_IMMEDIATE_UPLOAD;
}
mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(),
ClientManager(), flags);

View File

@ -126,11 +126,13 @@ ClientImageLayer::RenderLayer()
if (type == BUFFER_UNKNOWN) {
return;
}
TextureFlags flags = TEXTURE_FLAGS_DEFAULT;
if (mDisallowBigImage) {
flags |= TEXTURE_DISALLOW_BIGIMAGE;
}
mImageClient = ImageClient::CreateImageClient(type,
ClientManager(),
mDisallowBigImage
? TEXTURE_DISALLOW_BIGIMAGE
: 0);
flags);
if (type == BUFFER_BRIDGE) {
static_cast<ImageClientBridge*>(mImageClient.get())->SetLayer(this);
}

View File

@ -115,6 +115,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
mFrontBuffer = nullptr;
}
bool bufferCreated = false;
if (!mFrontBuffer) {
mFrontBuffer = CreateBufferTextureClient(gfx::FORMAT_YUV);
gfx::IntSize ySize(data->mYSize.width, data->mYSize.height);
@ -123,7 +124,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
mFrontBuffer = nullptr;
return false;
}
AddTextureClient(mFrontBuffer);
bufferCreated = true;
}
if (!mFrontBuffer->Lock(OPEN_READ_WRITE)) {
@ -132,6 +133,10 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
bool status = mFrontBuffer->AsTextureClientYCbCr()->UpdateYCbCr(*data);
mFrontBuffer->Unlock();
if (bufferCreated) {
AddTextureClient(mFrontBuffer);
}
if (status) {
GetForwarder()->UpdatedTexture(this, mFrontBuffer, nullptr);
GetForwarder()->UseTexture(this, mFrontBuffer);
@ -152,6 +157,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
mFrontBuffer = nullptr;
}
bool bufferCreated = false;
if (!mFrontBuffer) {
gfxASurface::gfxImageFormat format
= gfxPlatform::GetPlatform()->OptimalFormatForContent(surface->GetContentType());
@ -159,7 +165,7 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
MOZ_ASSERT(mFrontBuffer->AsTextureClientSurface());
mFrontBuffer->AsTextureClientSurface()->AllocateForSurface(size);
AddTextureClient(mFrontBuffer);
bufferCreated = true;
}
if (!mFrontBuffer->Lock(OPEN_READ_WRITE)) {
@ -167,6 +173,11 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer,
}
bool status = mFrontBuffer->AsTextureClientSurface()->UpdateSurface(surface);
mFrontBuffer->Unlock();
if (bufferCreated) {
AddTextureClient(mFrontBuffer);
}
if (status) {
GetForwarder()->UpdatedTexture(this, mFrontBuffer, nullptr);
GetForwarder()->UseTexture(this, mFrontBuffer);

View File

@ -164,6 +164,7 @@ bool
BufferTextureClient::UpdateSurface(gfxASurface* aSurface)
{
MOZ_ASSERT(aSurface);
MOZ_ASSERT(!IsImmutable());
ImageDataSerializer serializer(GetBuffer());
if (!serializer.IsValid()) {

View File

@ -226,7 +226,8 @@ BufferTextureHost::Updated(const nsIntRegion* aRegion)
mPartialUpdate = false;
}
if (GetFlags() & TEXTURE_IMMEDIATE_UPLOAD) {
MaybeUpload(mPartialUpdate ? &mMaybeUpdatedRegion : nullptr);
DebugOnly<bool> result = MaybeUpload(mPartialUpdate ? &mMaybeUpdatedRegion : nullptr);
MOZ_ASSERT(result);
}
}
@ -380,6 +381,9 @@ BufferTextureHost::Upload(nsIntRegion *aRegion)
}
RefPtr<gfx::DataSourceSurface> surf = deserializer.GetAsSurface();
if (!surf) {
return false;
}
if (!mFirstSource->Update(surf.get(), mFlags, aRegion)) {
NS_WARNING("failed to update the DataTextureSource");

View File

@ -382,6 +382,7 @@ ShadowLayerForwarder::AddTexture(CompositableClient* aCompositable,
NS_WARNING("Failed to serialize a TextureClient");
return;
}
MOZ_ASSERT(aTexture->GetFlags() != 0);
mTxn->AddEdit(OpAddTexture(nullptr, aCompositable->GetIPDLActor(),
aTexture->GetID(),
descriptor,

View File

@ -618,7 +618,11 @@ SurfaceStreamHostOGL::UpdateImpl(const SurfaceDescriptor& aImage,
const SurfaceStreamDescriptor& streamDesc =
aImage.get_SurfaceStreamDescriptor();
mStream = SurfaceStream::FromHandle(streamDesc.handle());
SurfaceStream *stream = SurfaceStream::FromHandle(streamDesc.handle());
if (stream == mStream) {
return;
}
mStream = stream;
MOZ_ASSERT(mStream);
mStreamGL = dont_AddRef(mStream->GLContext());
}

View File

@ -0,0 +1,83 @@
diff --git a/gfx/skia/src/opts/SkBlitRow_opts_arm.cpp b/gfx/skia/src/opts/SkBlitRow_opts_arm.cpp
--- a/gfx/skia/src/opts/SkBlitRow_opts_arm.cpp
+++ b/gfx/skia/src/opts/SkBlitRow_opts_arm.cpp
@@ -26,66 +26,78 @@ static void S32A_D565_Opaque(uint16_t* S
asm volatile (
"1: \n\t"
"ldr r3, [%[src]], #4 \n\t"
"cmp r3, #0xff000000 \n\t"
"blo 2f \n\t"
"and r4, r3, #0x0000f8 \n\t"
"and r5, r3, #0x00fc00 \n\t"
"and r6, r3, #0xf80000 \n\t"
+#ifdef SK_ARM_HAS_EDSP
"pld [r1, #32] \n\t"
+#endif
"lsl r3, r4, #8 \n\t"
"orr r3, r3, r5, lsr #5 \n\t"
"orr r3, r3, r6, lsr #19 \n\t"
"subs %[count], %[count], #1 \n\t"
"strh r3, [%[dst]], #2 \n\t"
"bne 1b \n\t"
"b 4f \n\t"
"2: \n\t"
"lsrs r7, r3, #24 \n\t"
"beq 3f \n\t"
"ldrh r4, [%[dst]] \n\t"
"rsb r7, r7, #255 \n\t"
"and r6, r4, #0x001f \n\t"
-#if SK_ARM_ARCH == 6
+#if SK_ARM_ARCH <= 6
"lsl r5, r4, #21 \n\t"
"lsr r5, r5, #26 \n\t"
#else
"ubfx r5, r4, #5, #6 \n\t"
#endif
+#ifdef SK_ARM_HAS_EDSP
"pld [r0, #16] \n\t"
+#endif
"lsr r4, r4, #11 \n\t"
#ifdef SK_ARM_HAS_EDSP
"smulbb r6, r6, r7 \n\t"
"smulbb r5, r5, r7 \n\t"
"smulbb r4, r4, r7 \n\t"
#else
"mul r6, r6, r7 \n\t"
"mul r5, r5, r7 \n\t"
"mul r4, r4, r7 \n\t"
#endif
+#if SK_ARM_ARCH >= 6
"uxtb r7, r3, ROR #16 \n\t"
"uxtb ip, r3, ROR #8 \n\t"
+#else
+ "mov ip, #0xff \n\t"
+ "and r7, ip, r3, ROR #16 \n\t"
+ "and ip, ip, r3, ROR #8 \n\t"
+#endif
"and r3, r3, #0xff \n\t"
"add r6, r6, #16 \n\t"
"add r5, r5, #32 \n\t"
"add r4, r4, #16 \n\t"
"add r6, r6, r6, lsr #5 \n\t"
"add r5, r5, r5, lsr #6 \n\t"
"add r4, r4, r4, lsr #5 \n\t"
"add r6, r7, r6, lsr #5 \n\t"
"add r5, ip, r5, lsr #6 \n\t"
"add r4, r3, r4, lsr #5 \n\t"
"lsr r6, r6, #3 \n\t"
"and r5, r5, #0xfc \n\t"
"and r4, r4, #0xf8 \n\t"
"orr r6, r6, r5, lsl #3 \n\t"
"orr r4, r6, r4, lsl #8 \n\t"
"strh r4, [%[dst]], #2 \n\t"
+#ifdef SK_ARM_HAS_EDSP
"pld [r1, #32] \n\t"
+#endif
"subs %[count], %[count], #1 \n\t"
"bne 1b \n\t"
"b 4f \n\t"
"3: \n\t"
"subs %[count], %[count], #1 \n\t"
"add %[dst], %[dst], #2 \n\t"
"bne 1b \n\t"
"4: \n\t"

View File

@ -31,7 +31,9 @@ static void S32A_D565_Opaque(uint16_t* SK_RESTRICT dst,
"and r4, r3, #0x0000f8 \n\t"
"and r5, r3, #0x00fc00 \n\t"
"and r6, r3, #0xf80000 \n\t"
#ifdef SK_ARM_HAS_EDSP
"pld [r1, #32] \n\t"
#endif
"lsl r3, r4, #8 \n\t"
"orr r3, r3, r5, lsr #5 \n\t"
"orr r3, r3, r6, lsr #19 \n\t"
@ -45,13 +47,15 @@ static void S32A_D565_Opaque(uint16_t* SK_RESTRICT dst,
"ldrh r4, [%[dst]] \n\t"
"rsb r7, r7, #255 \n\t"
"and r6, r4, #0x001f \n\t"
#if SK_ARM_ARCH == 6
#if SK_ARM_ARCH <= 6
"lsl r5, r4, #21 \n\t"
"lsr r5, r5, #26 \n\t"
#else
"ubfx r5, r4, #5, #6 \n\t"
#endif
#ifdef SK_ARM_HAS_EDSP
"pld [r0, #16] \n\t"
#endif
"lsr r4, r4, #11 \n\t"
#ifdef SK_ARM_HAS_EDSP
"smulbb r6, r6, r7 \n\t"
@ -62,8 +66,14 @@ static void S32A_D565_Opaque(uint16_t* SK_RESTRICT dst,
"mul r5, r5, r7 \n\t"
"mul r4, r4, r7 \n\t"
#endif
#if SK_ARM_ARCH >= 6
"uxtb r7, r3, ROR #16 \n\t"
"uxtb ip, r3, ROR #8 \n\t"
#else
"mov ip, #0xff \n\t"
"and r7, ip, r3, ROR #16 \n\t"
"and ip, ip, r3, ROR #8 \n\t"
#endif
"and r3, r3, #0xff \n\t"
"add r6, r6, #16 \n\t"
"add r5, r5, #32 \n\t"
@ -80,7 +90,9 @@ static void S32A_D565_Opaque(uint16_t* SK_RESTRICT dst,
"orr r6, r6, r5, lsl #3 \n\t"
"orr r4, r6, r4, lsl #8 \n\t"
"strh r4, [%[dst]], #2 \n\t"
#ifdef SK_ARM_HAS_EDSP
"pld [r1, #32] \n\t"
#endif
"subs %[count], %[count], #1 \n\t"
"bne 1b \n\t"
"b 4f \n\t"

View File

@ -19,13 +19,17 @@ def InvokeClWithDependencyGeneration(cmdline):
if target == None:
print >>sys.stderr, "No target set" and sys.exit(1)
# Assume the source file is the last argument
source = cmdline[-1]
assert not source.startswith('-')
# The deps target lives here
depstarget = os.path.basename(target) + ".pp"
cmdline += ['-showIncludes']
cl = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
deps = set()
deps = set([os.path.normcase(source).replace(os.sep, '/')])
for line in cl.stdout:
# cl -showIncludes prefixes every header with "Note: including file:"
# and an indentation corresponding to the depth (which we don't need)
@ -34,8 +38,8 @@ def InvokeClWithDependencyGeneration(cmdline):
# We can't handle pathes with spaces properly in mddepend.pl, but
# we can assume that anything in a path with spaces is a system
# header and throw it away.
if dep.find(' ') == -1:
deps.add(dep)
if ' ' not in dep:
deps.add(os.path.normcase(dep).replace(os.sep, '/'))
else:
sys.stdout.write(line) # Make sure we preserve the relevant output
# from cl
@ -54,10 +58,13 @@ def InvokeClWithDependencyGeneration(cmdline):
# cost of masking failure to create the directory. We'll just
# die on the next line though, so it's not that much of a loss.
f = open(depstarget, "w")
for dep in sorted(deps):
print >>f, "%s: %s" % (target, dep)
print >>f, "%s:" % dep
with open(depstarget, "w") as f:
f.write("%s: %s" % (target, source))
for dep in sorted(deps):
f.write(" \\\n%s" % dep)
f.write('\n')
for dep in sorted(deps):
f.write("%s:\n" % dep)
if __name__ == "__main__":
InvokeClWithDependencyGeneration(sys.argv[1:])

View File

@ -928,15 +928,19 @@ js::testingFunc_inParallelSection(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
static JSObject *objectMetadataFunction = NULL;
static const char *ObjectMetadataPropertyName = "__objectMetadataFunction__";
static bool
ShellObjectMetadataCallback(JSContext *cx, JSObject **pmetadata)
{
Value thisv = UndefinedValue();
RootedValue fun(cx);
if (!JS_GetProperty(cx, cx->global(), ObjectMetadataPropertyName, &fun))
return false;
RootedValue rval(cx);
if (!Invoke(cx, thisv, ObjectValue(*objectMetadataFunction), 0, NULL, &rval))
if (!Invoke(cx, thisv, fun, 0, NULL, &rval))
return false;
if (rval.isObject())
@ -953,17 +957,15 @@ SetObjectMetadataCallback(JSContext *cx, unsigned argc, jsval *vp)
args.rval().setUndefined();
if (argc == 0 || !args[0].isObject() || !args[0].toObject().is<JSFunction>()) {
if (objectMetadataFunction)
JS_RemoveObjectRoot(cx, &objectMetadataFunction);
objectMetadataFunction = NULL;
if (!JS_DeleteProperty(cx, cx->global(), ObjectMetadataPropertyName))
return false;
js::SetObjectMetadataCallback(cx, NULL);
return true;
}
if (!objectMetadataFunction && !JS_AddObjectRoot(cx, &objectMetadataFunction))
if (!JS_DefineProperty(cx, cx->global(), ObjectMetadataPropertyName, args[0], NULL, NULL, 0))
return false;
objectMetadataFunction = &args[0].toObject();
js::SetObjectMetadataCallback(cx, ShellObjectMetadataCallback);
return true;
}

View File

@ -26,3 +26,9 @@ ifeq (1_a,$(.PYMAKE)_$(firstword a$(subst /, ,$(srcdir))))
$(error MSYS-style srcdir being used with Pymake. Did you mean to run GNU Make instead? [see-also: https://developer.mozilla.org/ en/Gmake_vs._Pymake])
endif
endif # WINNT
ifdef .PYMAKE
include_deps = $(eval -includedeps $(1))
else
include_deps = $(eval -include $(1))
endif

View File

@ -1621,11 +1621,7 @@ ifneq (,$(filter-out all chrome default export realchrome tools clean clobber cl
MDDEPEND_FILES := $(strip $(wildcard $(foreach file,$(sort $(OBJS) $(PROGOBJS) $(HOST_OBJS) $(HOST_PROGOBJS) $(TARGETS)),$(MDDEPDIR)/$(notdir $(file)).pp) $(addprefix $(MDDEPDIR)/,$(EXTRA_MDDEPEND_FILES))))
ifneq (,$(MDDEPEND_FILES))
ifdef .PYMAKE
includedeps $(MDDEPEND_FILES)
else
include $(MDDEPEND_FILES)
endif
$(call include_deps,$(MDDEPEND_FILES))
endif
endif
@ -1635,11 +1631,7 @@ ifneq (,$(filter export,$(MAKECMDGOALS)))
MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(EXTRA_EXPORT_MDDEPEND_FILES))))
ifneq (,$(MDDEPEND_FILES))
ifdef .PYMAKE
includedeps $(MDDEPEND_FILES)
else
include $(MDDEPEND_FILES)
endif
$(call include_deps,$(MDDEPEND_FILES))
endif
endif

View File

@ -0,0 +1,5 @@
ParallelArray([57], function() {
return (Math.max(2207764374, (function() {
return 1
})()))
})

View File

@ -695,8 +695,8 @@ Range::abs(const Range *op)
Range *
Range::min(const Range *lhs, const Range *rhs)
{
// If either operand is NaN (implied by isInfinite here), the result is NaN.
if (lhs->isInfinite() || rhs->isInfinite())
// If either operand is NaN, the result is NaN.
if (!lhs->isInt32() || !rhs->isInt32())
return new Range();
return new Range(Min(lhs->lower(), rhs->lower()),
@ -708,8 +708,8 @@ Range::min(const Range *lhs, const Range *rhs)
Range *
Range::max(const Range *lhs, const Range *rhs)
{
// If either operand is NaN (implied by isInfinite here), the result is NaN.
if (lhs->isInfinite() || rhs->isInfinite())
// If either operand is NaN, the result is NaN.
if (!lhs->isInt32() || !rhs->isInt32())
return new Range();
return new Range(Max(lhs->lower(), rhs->lower()),
@ -1061,7 +1061,7 @@ MMod::computeRange()
// If either operand is a NaN, the result is NaN. This also conservatively
// handles Infinity cases.
if (lhs.isInfinite() || rhs.isInfinite())
if (!lhs.isInt32() || !rhs.isInt32())
return;
// If RHS can be zero, the result can be NaN.

View File

@ -449,11 +449,7 @@ class TypedRegisterSet
return bits_;
}
uint32_t size() const {
uint32_t sum2 = (bits_ & 0x55555555) + ((bits_ & 0xaaaaaaaa) >> 1);
uint32_t sum4 = (sum2 & 0x33333333) + ((sum2 & 0xcccccccc) >> 2);
uint32_t sum8 = (sum4 & 0x0f0f0f0f) + ((sum4 & 0xf0f0f0f0) >> 4);
uint32_t sum16 = (sum8 & 0x00ff00ff) + ((sum8 & 0xff00ff00) >> 8);
return sum16;
return mozilla::CountPopulation32(bits_);
}
bool operator ==(const TypedRegisterSet<T> &other) const {
return other.bits_ == bits_;

View File

@ -149,7 +149,7 @@ nsLayoutStatics::Initialize()
nsColorNames::AddRefTable();
nsGkAtoms::AddRefAtoms();
nsJSRuntime::Startup();
StartupJSEnvironment();
rv = nsRegion::InitStatic();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsRegion");
@ -334,7 +334,7 @@ nsLayoutStatics::Shutdown()
nsLayoutStylesheetCache::Shutdown();
NS_NameSpaceManagerShutdown();
nsJSRuntime::Shutdown();
ShutdownJSEnvironment();
nsGlobalWindow::ShutDown();
nsDOMClassInfo::ShutDown();
nsListControlFrame::Shutdown();

View File

@ -411,7 +411,7 @@ public:
const nsSize& aAvailableSpace,
uint32_t aFlags = 0);
// Initialize a reflow state for a child frames reflow. Some state
// Initialize a reflow state for a child frame's reflow. Some state
// is copied from the parent reflow state; the remaining state is
// computed.
nsHTMLReflowState(nsPresContext* aPresContext,

View File

@ -1405,12 +1405,14 @@ static int vcmRxStartICE_m(cc_mcapid_t mcap_id,
return VCM_ERROR;
}
mozilla::RefPtr<TransportFlow> rtcp_flow =
vcmCreateTransportFlow(pc.impl(), level, true,
fingerprint_alg, fingerprint);
if (!rtcp_flow) {
CSFLogError( logTag, "Could not create RTCP flow");
return VCM_ERROR;
mozilla::RefPtr<TransportFlow> rtcp_flow = nullptr;
if(!attrs->rtcp_mux) {
rtcp_flow = vcmCreateTransportFlow(pc.impl(), level, true,
fingerprint_alg, fingerprint);
if (!rtcp_flow) {
CSFLogError( logTag, "Could not create RTCP flow");
return VCM_ERROR;
}
}
if (CC_IS_AUDIO(mcap_id)) {
@ -2046,12 +2048,14 @@ static int vcmTxStartICE_m(cc_mcapid_t mcap_id,
CSFLogError( logTag, "Could not create RTP flow");
return VCM_ERROR;
}
mozilla::RefPtr<TransportFlow> rtcp_flow =
vcmCreateTransportFlow(pc.impl(), level, true,
fingerprint_alg, fingerprint);
if (!rtcp_flow) {
mozilla::RefPtr<TransportFlow> rtcp_flow = nullptr;
if(!attrs->rtcp_mux) {
rtcp_flow = vcmCreateTransportFlow(pc.impl(), level, true,
fingerprint_alg, fingerprint);
if (!rtcp_flow) {
CSFLogError( logTag, "Could not create RTCP flow");
return VCM_ERROR;
}
}
if (CC_IS_AUDIO(mcap_id)) {

View File

@ -122,6 +122,10 @@ class MediaPipeline : public sigslot::has_slots<> {
virtual Direction direction() const { return direction_; }
bool IsDoingRtcpMux() const {
return (rtp_transport_ == rtcp_transport_);
}
int rtp_packets_sent() const { return rtp_packets_sent_; }
int rtcp_packets_sent() const { return rtcp_packets_sent_; }
int rtp_packets_received() const { return rtp_packets_received_; }

View File

@ -443,6 +443,20 @@ PeerConnectionMedia::IceStreamReady(NrIceMediaStream *aStream)
CSFLogDebug(logTag, "%s: %s", __FUNCTION__, aStream->name().c_str());
}
// This method exists for the unittests.
// It allows visibility into the pipelines and flows.
// It returns NULL if no pipeline exists for this track number.
mozilla::RefPtr<mozilla::MediaPipeline>
SourceStreamInfo::GetPipeline(int aTrack) {
std::map<int, mozilla::RefPtr<mozilla::MediaPipeline> >::iterator it =
mPipelines.find(aTrack);
if (it == mPipelines.end()) {
return NULL;
}
return it->second;
}
void
LocalSourceStreamInfo::StorePipeline(int aTrack,

View File

@ -162,17 +162,42 @@ class Fake_VideoGenerator {
#endif
// TODO(ekr@rtfm.com): Refactor {Local,Remote}SourceStreamInfo
// bug 837539.
class LocalSourceStreamInfo {
class SourceStreamInfo {
public:
typedef mozilla::DOMMediaStream DOMMediaStream;
LocalSourceStreamInfo(DOMMediaStream* aMediaStream, PeerConnectionMedia *aParent)
: mMediaStream(aMediaStream), mParent(aParent) {
MOZ_ASSERT(aMediaStream);
SourceStreamInfo(DOMMediaStream* aMediaStream,
PeerConnectionMedia *aParent)
: mMediaStream(aMediaStream),
mParent(aParent) {
MOZ_ASSERT(mMediaStream);
}
SourceStreamInfo(already_AddRefed<DOMMediaStream> aMediaStream,
PeerConnectionMedia *aParent)
: mMediaStream(aMediaStream),
mParent(aParent) {
MOZ_ASSERT(mMediaStream);
}
mozilla::RefPtr<mozilla::MediaPipeline> GetPipeline(int aTrack);
protected:
std::map<int, mozilla::RefPtr<mozilla::MediaPipeline> > mPipelines;
nsRefPtr<DOMMediaStream> mMediaStream;
PeerConnectionMedia *mParent;
};
// TODO(ekr@rtfm.com): Refactor {Local,Remote}SourceStreamInfo
// bug 837539.
class LocalSourceStreamInfo : public SourceStreamInfo {
public:
typedef mozilla::DOMMediaStream DOMMediaStream;
LocalSourceStreamInfo(DOMMediaStream *aMediaStream,
PeerConnectionMedia *aParent)
: SourceStreamInfo(aMediaStream, aParent) {}
~LocalSourceStreamInfo() {
mMediaStream = NULL;
}
@ -191,25 +216,18 @@ public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(LocalSourceStreamInfo)
private:
std::map<int, mozilla::RefPtr<mozilla::MediaPipeline> > mPipelines;
nsRefPtr<DOMMediaStream> mMediaStream;
nsTArray<mozilla::TrackID> mAudioTracks;
nsTArray<mozilla::TrackID> mVideoTracks;
PeerConnectionMedia *mParent;
};
class RemoteSourceStreamInfo {
class RemoteSourceStreamInfo : public SourceStreamInfo {
public:
typedef mozilla::DOMMediaStream DOMMediaStream;
RemoteSourceStreamInfo(already_AddRefed<DOMMediaStream> aMediaStream,
PeerConnectionMedia *aParent)
: mTrackTypeHints(0),
mMediaStream(aMediaStream),
mPipelines(),
mParent(aParent) {
MOZ_ASSERT(mMediaStream);
}
RemoteSourceStreamInfo(already_AddRefed<DOMMediaStream> aMediaStream,
PeerConnectionMedia *aParent)
: SourceStreamInfo(aMediaStream, aParent),
mTrackTypeHints(0) {}
DOMMediaStream* GetMediaStream() {
return mMediaStream;
@ -225,10 +243,7 @@ RemoteSourceStreamInfo(already_AddRefed<DOMMediaStream> aMediaStream,
public:
DOMMediaStream::TrackTypeHints mTrackTypeHints;
private:
nsRefPtr<DOMMediaStream> mMediaStream;
std::map<int, mozilla::RefPtr<mozilla::MediaPipeline> > mPipelines;
std::map<int, bool> mTypes;
PeerConnectionMedia *mParent;
};
class PeerConnectionMedia : public sigslot::has_slots<> {

View File

@ -4734,12 +4734,14 @@ gsmsdp_negotiate_media_lines (fsm_fcb_t *fcb_p, cc_sdp_t *sdp_p, boolean initial
/*
* Negotiate rtcp-mux
*/
if(SDP_MEDIA_APPLICATION != media_type) {
sdp_res = sdp_attr_get_rtcp_mux_attribute(sdp_p->dest_sdp, i,
0, SDP_ATTR_RTCP_MUX,
1, &rtcp_mux);
sdp_res = sdp_attr_get_rtcp_mux_attribute (sdp_p->dest_sdp, i,
0, SDP_ATTR_RTCP_MUX, 1, &rtcp_mux);
if (SDP_SUCCESS == sdp_res) {
media->rtcp_mux = TRUE;
if (SDP_SUCCESS == sdp_res) {
media->rtcp_mux = TRUE;
}
}
if (!unsupported_line) {
@ -4753,8 +4755,10 @@ gsmsdp_negotiate_media_lines (fsm_fcb_t *fcb_p, cc_sdp_t *sdp_p, boolean initial
sdp_p->src_sdp, media->candidatesp[j]);
}
/* Set RTCPMux if we have it turned on in our config
and the other side requests it */
config_get_value(CFGID_RTCPMUX, &rtcpmux, sizeof(rtcpmux));
if (rtcpmux) {
if (rtcpmux && media->rtcp_mux) {
gsmsdp_set_rtcp_mux_attribute (SDP_ATTR_RTCP_MUX, media->level,
sdp_p->src_sdp, TRUE);
}
@ -5275,7 +5279,7 @@ gsmsdp_add_media_line (fsmdef_dcb_t *dcb_p, const cc_media_cap_t *media_cap,
}
config_get_value(CFGID_RTCPMUX, &rtcpmux, sizeof(rtcpmux));
if (rtcpmux) {
if (SDP_MEDIA_APPLICATION != media_cap->type && rtcpmux) {
gsmsdp_set_rtcp_mux_attribute (SDP_ATTR_RTCP_MUX, level, dcb_p->sdp->src_sdp, TRUE);
}

View File

@ -984,6 +984,7 @@ lsm_rx_start (lsm_lcb_t *lcb, const char *fname, fsmdef_media_t *media)
media->src_port = open_rcv.port;
}
attrs.rtcp_mux = media->rtcp_mux;
if ( media->cap_index == CC_VIDEO_1 ) {
attrs.video.opaque = media->video;
} else {
@ -1220,6 +1221,8 @@ lsm_tx_start (lsm_lcb_t *lcb, const char *fname, fsmdef_media_t *media)
media->xmit_chan = TRUE;
attrs.mute = FALSE;
attrs.rtcp_mux = media->rtcp_mux;
if ( CC_IS_VIDEO(media->cap_index)) {
attrs.video.opaque = media->video;
if (lcb->vid_mute) {

View File

@ -179,7 +179,7 @@ static const int gDscpCallControl = 1;
static const int gSpeakerEnabled = 1;
static const char gExternalNumberMask[] = "";
static const char gVersion[] = "0.1";
static const boolean gRTCPMUX = FALSE;
static const boolean gRTCPMUX = TRUE;
static boolean gRTPSAVPF = TRUE; /* TRUE = RTP/SAVPF , FALSE = RTP/SAVP */
static const boolean gMAXAVBITRATE = FALSE; /* Following six are OPUS fmtp options */
static const boolean gMAXCODEDAUDIOBW = FALSE;

View File

@ -331,6 +331,7 @@ typedef struct vcm_audioAttrs_t_ {
typedef struct vcm_attrs_t_ {
cc_boolean mute;
cc_boolean is_video;
cc_boolean rtcp_mux;
vcm_audioAttrs_t audio; /**< audio line attribs */
vcm_videoAttrs_t video; /**< Video Atrribs */
} vcm_mediaAttrs_t;

View File

@ -137,6 +137,15 @@ enum offerAnswerFlags
ANSWER_AV = ANSWER_AUDIO | ANSWER_VIDEO
};
enum mediaPipelineFlags
{
PIPELINE_LOCAL = (1<<0),
PIPELINE_RTCP_MUX = (1<<1),
PIPELINE_SEND = (1<<2),
PIPELINE_VIDEO = (1<<3)
};
static bool SetupGlobalThread() {
if (!gThread) {
nsIThread *thread;
@ -455,7 +464,14 @@ class ParsedSDP {
Parse();
}
void DeleteLine(std::string objType)
{
ReplaceLine(objType, "");
}
// Replaces the first instance of objType in the SDP with
// a new string.
// If content is an empty string then the line will be removed
void ReplaceLine(std::string objType, std::string content)
{
std::multimap<std::string, SdpLine>::iterator it;
@ -464,6 +480,9 @@ class ParsedSDP {
SdpLine sdp_line_pair = (*it).second;
int line_no = sdp_line_pair.first;
sdp_map_.erase(it);
if(content.empty()) {
return;
}
std::string value = content.substr(objType.length());
sdp_map_.insert(std::pair<std::string, SdpLine>(objType,
std::make_pair(line_no,value)));
@ -752,7 +771,7 @@ void CreateAnswer(sipcc::MediaConstraints& constraints, std::string offer,
DONT_CHECK_VIDEO|
DONT_CHECK_DATA,
sipcc::PeerConnectionImpl::SignalingState endState =
sipcc::PeerConnectionImpl::kSignalingHaveRemoteOffer) {
sipcc::PeerConnectionImpl::kSignalingHaveRemoteOffer) {
uint32_t aHintContents = 0;
if (offerAnswerFlags & ANSWER_AUDIO) {
@ -935,6 +954,42 @@ void CreateAnswer(sipcc::MediaConstraints& constraints, std::string offer,
}
}
mozilla::RefPtr<mozilla::MediaPipeline> GetMediaPipeline(
bool local, int stream, int track) {
sipcc::SourceStreamInfo *streamInfo;
if (local) {
streamInfo = pc->media()->GetLocalStream(stream);
} else {
streamInfo = pc->media()->GetRemoteStream(stream);
}
if (!streamInfo) {
return nullptr;
}
return streamInfo->GetPipeline(track);
}
void CheckMediaPipeline(int stream, int track, uint32_t flags) {
mozilla::RefPtr<mozilla::MediaPipeline> pipeline =
GetMediaPipeline((flags & PIPELINE_LOCAL), stream, track);
ASSERT_TRUE(pipeline);
ASSERT_EQ(pipeline->IsDoingRtcpMux(), !!(flags & PIPELINE_RTCP_MUX));
// We cannot yet test send/recv with video.
if (!(flags & PIPELINE_VIDEO)) {
if (flags & PIPELINE_SEND) {
ASSERT_GE(pipeline->rtp_packets_sent(), 40);
ASSERT_GE(pipeline->rtcp_packets_received(), 1);
} else {
ASSERT_GE(pipeline->rtp_packets_received(), 40);
ASSERT_GE(pipeline->rtcp_packets_sent(), 1);
}
}
}
public:
mozilla::RefPtr<sipcc::PeerConnectionImpl> pc;
nsRefPtr<TestObserver> pObserver;
@ -1624,6 +1679,15 @@ TEST_F(SignalingTest, FullCall)
//ASSERT_GE(a2_.GetPacketsSent(0), 40);
//ASSERT_GE(a1_.GetPacketsReceived(0), 40);
ASSERT_GE(a2_.GetPacketsReceived(0), 40);
// Check the low-level media pipeline
// for RTP and RTCP flows
// The first Local pipeline gets stored at 0
a1_.CheckMediaPipeline(0, 0,
PIPELINE_LOCAL | PIPELINE_RTCP_MUX | PIPELINE_SEND);
// The first Remote pipeline gets stored at 1
a2_.CheckMediaPipeline(0, 1, PIPELINE_RTCP_MUX);
}
TEST_F(SignalingTest, FullCallAudioOnly)
@ -2284,11 +2348,99 @@ TEST_F(SignalingTest, missingUfrag)
a1_.CreateOffer(constraints, OFFER_AV, SHOULD_SENDRECV_AV);
a1_.SetLocal(TestObserver::OFFER, offer, true);
// We now detect the missing ICE parameters at SetRemoteDescription
a2_.SetRemote(TestObserver::OFFER, offer, true,
a2_.SetRemote(TestObserver::OFFER, offer, true,
sipcc::PeerConnectionImpl::kSignalingStable);
ASSERT_TRUE(a2_.pObserver->state == TestObserver::stateError);
}
TEST_F(SignalingTest, AudioOnlyCalleeNoRtcpMux)
{
sipcc::MediaConstraints constraints;
a1_.CreateOffer(constraints, OFFER_AUDIO, SHOULD_SENDRECV_AUDIO);
a1_.SetLocal(TestObserver::OFFER, a1_.offer(), false);
ParsedSDP sdpWrapper(a1_.offer());
sdpWrapper.DeleteLine("a=rtcp-mux");
std::cout << "Modified SDP " << std::endl
<< indent(sdpWrapper.getSdp()) << std::endl;
a2_.SetRemote(TestObserver::OFFER, sdpWrapper.getSdp(), false);
a2_.CreateAnswer(constraints, sdpWrapper.getSdp(),
OFFER_AUDIO | ANSWER_AUDIO);
a2_.SetLocal(TestObserver::ANSWER, a2_.answer(), false);
a1_.SetRemote(TestObserver::ANSWER, a2_.answer(), false);
// Answer should not have a=rtcp-mux
ASSERT_EQ(a2_.getLocalDescription().find("\r\na=rtcp-mux"),
std::string::npos);
ASSERT_TRUE_WAIT(a1_.IceCompleted() == true, kDefaultTimeout);
ASSERT_TRUE_WAIT(a2_.IceCompleted() == true, kDefaultTimeout);
PR_Sleep(kDefaultTimeout * 2); // Wait for some data to get written
a1_.CloseSendStreams();
a2_.CloseReceiveStreams();
ASSERT_GE(a1_.GetPacketsSent(0), 40);
ASSERT_GE(a2_.GetPacketsReceived(0), 40);
// Check the low-level media pipeline
// for RTP and RTCP flows
// The first Local pipeline gets stored at 0
a1_.CheckMediaPipeline(0, 0, PIPELINE_LOCAL | PIPELINE_SEND);
// The first Remote pipeline gets stored at 1
a2_.CheckMediaPipeline(0, 1, 0);
}
TEST_F(SignalingTest, FullCallAudioNoMuxVideoMux)
{
sipcc::MediaConstraints constraints;
a1_.CreateOffer(constraints, OFFER_AV, SHOULD_SENDRECV_AV);
a1_.SetLocal(TestObserver::OFFER, a1_.offer(), false);
ParsedSDP sdpWrapper(a1_.offer());
sdpWrapper.DeleteLine("a=rtcp-mux");
std::cout << "Modified SDP " << std::endl
<< indent(sdpWrapper.getSdp()) << std::endl;
a2_.SetRemote(TestObserver::OFFER, sdpWrapper.getSdp(), false);
a2_.CreateAnswer(constraints, sdpWrapper.getSdp(), OFFER_AV | ANSWER_AV);
a2_.SetLocal(TestObserver::ANSWER, a2_.answer(), false);
a1_.SetRemote(TestObserver::ANSWER, a2_.answer(), false);
// Answer should have only one a=rtcp-mux line
size_t match = a2_.getLocalDescription().find("\r\na=rtcp-mux");
ASSERT_NE(match, std::string::npos);
match = a2_.getLocalDescription().find("\r\na=rtcp-mux", match + 1);
ASSERT_EQ(match, std::string::npos);
ASSERT_TRUE_WAIT(a1_.IceCompleted() == true, kDefaultTimeout);
ASSERT_TRUE_WAIT(a2_.IceCompleted() == true, kDefaultTimeout);
PR_Sleep(kDefaultTimeout * 2); // Wait for some data to get written
a1_.CloseSendStreams();
a2_.CloseReceiveStreams();
ASSERT_GE(a1_.GetPacketsSent(0), 40);
ASSERT_GE(a2_.GetPacketsReceived(0), 40);
// Check the low-level media pipeline
// for RTP and RTCP flows
// The first Local pipeline gets stored at 0
a1_.CheckMediaPipeline(0, 0, PIPELINE_LOCAL | PIPELINE_SEND);
// Now check video mux.
a1_.CheckMediaPipeline(0, 1,
PIPELINE_LOCAL | PIPELINE_RTCP_MUX | PIPELINE_SEND | PIPELINE_VIDEO);
// The first Remote pipeline gets stored at 1
a2_.CheckMediaPipeline(0, 1, 0);
// Now check video mux.
a2_.CheckMediaPipeline(0, 2, PIPELINE_RTCP_MUX | PIPELINE_VIDEO);
}
} // End namespace test.
bool is_color_terminal(const char *terminal) {

View File

@ -186,6 +186,16 @@ namespace detail {
return uint_fast8_t(index);
}
inline uint_fast8_t
CountPopulation32(uint32_t u)
{
uint32_t sum2 = (u & 0x55555555) + ((u & 0xaaaaaaaa) >> 1);
uint32_t sum4 = (sum2 & 0x33333333) + ((sum2 & 0xcccccccc) >> 2);
uint32_t sum8 = (sum4 & 0x0f0f0f0f) + ((sum4 & 0xf0f0f0f0) >> 4);
uint32_t sum16 = (sum8 & 0x00ff00ff) + ((sum8 & 0xff00ff00) >> 8);
return sum16;
}
inline uint_fast8_t
CountLeadingZeroes64(uint64_t u)
{
@ -242,6 +252,12 @@ namespace detail {
return __builtin_ctz(u);
}
inline uint_fast8_t
CountPopulation32(uint32_t u)
{
return __builtin_popcount(u);
}
inline uint_fast8_t
CountLeadingZeroes64(uint64_t u)
{
@ -258,6 +274,7 @@ namespace detail {
# error "Implement these!"
inline uint_fast8_t CountLeadingZeroes32(uint32_t u) MOZ_DELETE;
inline uint_fast8_t CountTrailingZeroes32(uint32_t u) MOZ_DELETE;
inline uint_fast8_t CountPopulation32(uint32_t u) MOZ_DELETE;
inline uint_fast8_t CountLeadingZeroes64(uint64_t u) MOZ_DELETE;
inline uint_fast8_t CountTrailingZeroes64(uint64_t u) MOZ_DELETE;
#endif
@ -300,6 +317,15 @@ CountTrailingZeroes32(uint32_t u)
return detail::CountTrailingZeroes32(u);
}
/**
* Compute the number of one bits in the number |u|,
*/
inline uint_fast8_t
CountPopulation32(uint32_t u)
{
return detail::CountPopulation32(u);
}
/** Analogous to CountLeadingZeroes32, but for 64-bit numbers. */
inline uint_fast8_t
CountLeadingZeroes64(uint64_t u)

View File

@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "mozilla/MathAlgorithms.h"
using mozilla::CountPopulation32;
static void
TestCountPopulation32()
{
MOZ_ASSERT(CountPopulation32(0xFFFFFFFF) == 32);
MOZ_ASSERT(CountPopulation32(0xF0FF1000) == 13);
MOZ_ASSERT(CountPopulation32(0x7F8F0001) == 13);
MOZ_ASSERT(CountPopulation32(0x3FFF0100) == 15);
MOZ_ASSERT(CountPopulation32(0x1FF50010) == 12);
MOZ_ASSERT(CountPopulation32(0x00800000) == 1);
MOZ_ASSERT(CountPopulation32(0x00400000) == 1);
MOZ_ASSERT(CountPopulation32(0x00008000) == 1);
MOZ_ASSERT(CountPopulation32(0x00004000) == 1);
MOZ_ASSERT(CountPopulation32(0x00000080) == 1);
MOZ_ASSERT(CountPopulation32(0x00000040) == 1);
MOZ_ASSERT(CountPopulation32(0x00000001) == 1);
MOZ_ASSERT(CountPopulation32(0x00000000) == 0);
}
int main()
{
TestCountPopulation32();
return 0;
}

Some files were not shown because too many files have changed in this diff Show More