From c35aa15ca3a56d21198a8d20015c586b2a3e37e7 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Fri, 13 Jan 2017 13:54:20 -0500 Subject: [PATCH 01/54] Bug 1330212: Release GraphDrivers outside of StableState runnable to avoid spinning the event queue r=smaug,padenot --- dom/media/MediaStreamGraph.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dom/media/MediaStreamGraph.cpp b/dom/media/MediaStreamGraph.cpp index 507f5d0901f5..7a1ba74838f4 100644 --- a/dom/media/MediaStreamGraph.cpp +++ b/dom/media/MediaStreamGraph.cpp @@ -1717,6 +1717,10 @@ MediaStreamGraphImpl::RunInStableState(bool aSourceIsMSG) RefPtr driver = CurrentDriver(); MonitorAutoUnlock unlock(mMonitor); driver->Start(); + // It's not safe to Shutdown() a thread from StableState, and + // releasing this may shutdown a SystemClockDriver thread. + // Proxy the release to outside of StableState. + NS_ReleaseOnMainThread(driver.forget(), true); // always proxy } } From 1e42cad36c4e5fe900321c5909bec9a0347c451a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Fri, 13 Jan 2017 20:21:53 +0100 Subject: [PATCH 02/54] Bug 1330464 - script-generated removal of additional parameters that don't exist in the interface, r=jaws. --- .../test/tabPrompts/browser_openPromptInBackgroundTab.js | 2 +- browser/components/newtab/aboutNewTabService.js | 4 ++-- browser/modules/test/browser_UsageTelemetry_urlbar.js | 2 +- devtools/client/webconsole/net/test/mochitest/head.js | 4 ++-- services/sync/tests/unit/test_fxa_startOver.js | 2 +- testing/specialpowers/content/SpecialPowersObserverAPI.js | 2 +- toolkit/components/osfile/tests/xpcshell/test_shutdown.js | 2 +- toolkit/content/browser-content.js | 4 ++-- .../mozapps/extensions/test/xpcshell/test_blocklist_regexp.js | 2 +- toolkit/mozapps/extensions/test/xpcshell/test_startup.js | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/browser/base/content/test/tabPrompts/browser_openPromptInBackgroundTab.js b/browser/base/content/test/tabPrompts/browser_openPromptInBackgroundTab.js index 21dbe8d4c60e..ff3cb01fa911 100644 --- a/browser/base/content/test/tabPrompts/browser_openPromptInBackgroundTab.js +++ b/browser/base/content/test/tabPrompts/browser_openPromptInBackgroundTab.js @@ -4,7 +4,7 @@ const ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", let pageWithAlert = ROOT + "openPromptOffTimeout.html"; registerCleanupFunction(function() { - Services.perms.removeAll(makeURI(pageWithAlert)); + Services.perms.removeAll(); }); /* diff --git a/browser/components/newtab/aboutNewTabService.js b/browser/components/newtab/aboutNewTabService.js index 2743eb23e72e..a43c4dc22f0c 100644 --- a/browser/components/newtab/aboutNewTabService.js +++ b/browser/components/newtab/aboutNewTabService.js @@ -172,7 +172,7 @@ AboutNewTabService.prototype = { .replace("%VERSION%", this.remoteVersion) .replace("%LOCALE%", Locale.getLocale()) .replace("%CHANNEL%", releaseName); - let mode = Services.prefs.getCharPref(PREF_REMOTE_MODE, "production"); + let mode = Services.prefs.getCharPref(PREF_REMOTE_MODE); if (!(mode in NewTabRemoteResources.MODE_CHANNEL_MAP)) { mode = "production"; } @@ -229,7 +229,7 @@ AboutNewTabService.prototype = { }, get remoteVersion() { - return Services.prefs.getCharPref(PREF_REMOTE_VERSION, "1"); + return Services.prefs.getCharPref(PREF_REMOTE_VERSION); }, get remoteReleaseName() { diff --git a/browser/modules/test/browser_UsageTelemetry_urlbar.js b/browser/modules/test/browser_UsageTelemetry_urlbar.js index 065bfa196a40..b9f323bcf938 100644 --- a/browser/modules/test/browser_UsageTelemetry_urlbar.js +++ b/browser/modules/test/browser_UsageTelemetry_urlbar.js @@ -89,7 +89,7 @@ add_task(function* setup() { Services.telemetry.canRecordExtended = oldCanRecord; Services.search.currentEngine = originalEngine; Services.search.removeEngine(engine); - Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF, true); + Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF); Services.prefs.clearUserPref(ONEOFF_URLBAR_PREF); yield PlacesTestUtils.clearHistory(); Services.telemetry.setEventRecordingEnabled("navigation", false); diff --git a/devtools/client/webconsole/net/test/mochitest/head.js b/devtools/client/webconsole/net/test/mochitest/head.js index c0120694829b..c9364602993d 100644 --- a/devtools/client/webconsole/net/test/mochitest/head.js +++ b/devtools/client/webconsole/net/test/mochitest/head.js @@ -21,8 +21,8 @@ Services.prefs.setBoolPref(NET_INFO_PREF, true); Services.prefs.setBoolPref(NET_XHR_PREF, true); registerCleanupFunction(() => { - Services.prefs.clearUserPref(NET_INFO_PREF, true); - Services.prefs.clearUserPref(NET_XHR_PREF, true); + Services.prefs.clearUserPref(NET_INFO_PREF); + Services.prefs.clearUserPref(NET_XHR_PREF); }); // Use the old webconsole since the new one doesn't yet support diff --git a/services/sync/tests/unit/test_fxa_startOver.js b/services/sync/tests/unit/test_fxa_startOver.js index 2b12398fc079..739301e82bb2 100644 --- a/services/sync/tests/unit/test_fxa_startOver.js +++ b/services/sync/tests/unit/test_fxa_startOver.js @@ -12,7 +12,7 @@ function run_test() { } add_task(async function test_startover() { - let oldValue = Services.prefs.getBoolPref("services.sync-testing.startOverKeepIdentity", true); + let oldValue = Services.prefs.getBoolPref("services.sync-testing.startOverKeepIdentity"); Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", false); ensureLegacyIdentityManager(); diff --git a/testing/specialpowers/content/SpecialPowersObserverAPI.js b/testing/specialpowers/content/SpecialPowersObserverAPI.js index f649a0623781..a88e46acc57a 100644 --- a/testing/specialpowers/content/SpecialPowersObserverAPI.js +++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js @@ -383,7 +383,7 @@ SpecialPowersObserverAPI.prototype = { let hasPerm = Services.perms.testPermissionFromPrincipal(principal, msg.type); return hasPerm == Ci.nsIPermissionManager.ALLOW_ACTION; case "test": - let testPerm = Services.perms.testPermissionFromPrincipal(principal, msg.type, msg.value); + let testPerm = Services.perms.testPermissionFromPrincipal(principal, msg.type); return testPerm == msg.value; default: throw new SpecialPowersError( diff --git a/toolkit/components/osfile/tests/xpcshell/test_shutdown.js b/toolkit/components/osfile/tests/xpcshell/test_shutdown.js index 667965d9ee0d..baae26839340 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_shutdown.js +++ b/toolkit/components/osfile/tests/xpcshell/test_shutdown.js @@ -67,7 +67,7 @@ add_task(function system_shutdown() { Services.prefs.clearUserPref("toolkit.osfile.log"); Services.prefs.clearUserPref("toolkit.osfile.log.redirect"); Services.prefs.clearUserPref("toolkit.osfile.test.shutdown.observer"); - Services.prefs.clearUserPref("toolkit.async_shutdown.testing", true); + Services.prefs.clearUserPref("toolkit.async_shutdown.testing"); throw new Task.Result(resolved); }); diff --git a/toolkit/content/browser-content.js b/toolkit/content/browser-content.js index 606920cda348..ae5420dc1fc5 100644 --- a/toolkit/content/browser-content.js +++ b/toolkit/content/browser-content.js @@ -422,8 +422,8 @@ var Printing = { }, get shouldSavePrintSettings() { - return Services.prefs.getBoolPref("print.use_global_printsettings", false) && - Services.prefs.getBoolPref("print.save_print_settings", false); + return Services.prefs.getBoolPref("print.use_global_printsettings") && + Services.prefs.getBoolPref("print.save_print_settings"); }, handleEvent(event) { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js index 49e492d9dc2c..9a7f48ccb0e7 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js @@ -67,7 +67,7 @@ function load_blocklist(aFile, aCallback) { // if we're not using the blocklist.xml for certificate blocklist state, // ensure that kinto update is enabled if (!Services.prefs.getBoolPref("security.onecrl.via.amo")) { - ok(Services.prefs.getBoolPref("services.blocklist.update_enabled", false), + ok(Services.prefs.getBoolPref("services.blocklist.update_enabled"), "Kinto update should be enabled"); } blocklist.notify(null); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_startup.js b/toolkit/mozapps/extensions/test/xpcshell/test_startup.js index 003b4983c87e..0d1f2e0384bc 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_startup.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_startup.js @@ -643,7 +643,7 @@ function run_test_8() { // More hiding and revealing function run_test_9() { - Services.prefs.clearUserPref("extensions.enabledScopes", 0); + Services.prefs.clearUserPref("extensions.enabledScopes"); var dest = userDir.clone(); dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org")); From 22d9b7146637c0f423ed675927df39835031b27b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Fri, 13 Jan 2017 20:21:55 +0100 Subject: [PATCH 03/54] Bug 1330464 - make the no-useless-parameters eslint rule detect misuses of the Services.prefs APIs, r=jaws. --- browser/modules/ContentCrashHandlers.jsm | 2 +- .../sync/tps/extensions/tps/resource/tps.jsm | 2 +- .../components/printing/content/printUtils.js | 4 ++-- .../lib/rules/no-useless-parameters.js | 5 +++++ .../eslint/eslint-plugin-mozilla/package.json | 2 +- .../tests/no-useless-parameters.js | 20 +++++++++++++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/browser/modules/ContentCrashHandlers.jsm b/browser/modules/ContentCrashHandlers.jsm index 719696d74ad0..0262b82cf115 100644 --- a/browser/modules/ContentCrashHandlers.jsm +++ b/browser/modules/ContentCrashHandlers.jsm @@ -471,7 +471,7 @@ this.TabCrashHandler = { }; if (emailMe) { - data.email = this.prefs.getCharPref("email", ""); + data.email = this.prefs.getCharPref("email"); } // Make sure to only count once even if there are multiple windows diff --git a/services/sync/tps/extensions/tps/resource/tps.jsm b/services/sync/tps/extensions/tps/resource/tps.jsm index f4cc0214aa21..6ad50b9973ae 100644 --- a/services/sync/tps/extensions/tps/resource/tps.jsm +++ b/services/sync/tps/extensions/tps/resource/tps.jsm @@ -761,7 +761,7 @@ var TPS = { this.quit(); return; } - this.seconds_since_epoch = prefs.getIntPref("tps.seconds_since_epoch", 0); + this.seconds_since_epoch = prefs.getIntPref("tps.seconds_since_epoch"); if (this.seconds_since_epoch) this._usSinceEpoch = this.seconds_since_epoch * 1000 * 1000; else { diff --git a/toolkit/components/printing/content/printUtils.js b/toolkit/components/printing/content/printUtils.js index f15de6dfc7c9..f6b9520a9634 100644 --- a/toolkit/components/printing/content/printUtils.js +++ b/toolkit/components/printing/content/printUtils.js @@ -440,8 +440,8 @@ var PrintUtils = { var pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); if (pref) { - gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings", false); - gSavePrintSettings = pref.getBoolPref("print.save_print_settings", false); + gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings"); + gSavePrintSettings = pref.getBoolPref("print.save_print_settings"); } var printSettings; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js index b4bf3aeb4b32..fb016f5e5262 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-useless-parameters.js @@ -29,6 +29,11 @@ module.exports = function(context) { return; } + if (["getCharPref", "getBoolPref", "getIntPref", "clearUserPref"] + .includes(callee.property.name) && node.arguments.length > 1) { + context.report(node, callee.property.name + " takes only 1 parameter."); + } + if (callee.property.name === "removeObserver" && node.arguments.length === 3) { let arg = node.arguments[2]; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/package.json b/tools/lint/eslint/eslint-plugin-mozilla/package.json index 088f6c2627e0..35b4a4dcccb7 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/package.json +++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-mozilla", - "version": "0.2.8", + "version": "0.2.9", "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.", "keywords": [ "eslint", diff --git a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js index e75e1870fbdf..4e1d360c2451 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-useless-parameters.js @@ -20,11 +20,31 @@ function callError(message) { exports.runTest = function(ruleTester) { ruleTester.run("no-useless-parameters", rule, { valid: [ + "Services.prefs.clearUserPref('browser.search.custom');", + "Services.prefs.getBoolPref('browser.search.custom');", + "Services.prefs.getCharPref('browser.search.custom');", + "Services.prefs.getIntPref('browser.search.custom');", "Services.removeObserver('notification name', {});", "Services.io.newURI('http://example.com');", "Services.io.newURI('http://example.com', 'utf8');", ], invalid: [ + { + code: "Services.prefs.clearUserPref('browser.search.custom', false);", + errors: callError("clearUserPref takes only 1 parameter.") + }, + { + code: "Services.prefs.getBoolPref('browser.search.custom', true);", + errors: callError("getBoolPref takes only 1 parameter.") + }, + { + code: "Services.prefs.getCharPref('browser.search.custom', 'a');", + errors: callError("getCharPref takes only 1 parameter.") + }, + { + code: "Services.prefs.getIntPref('browser.search.custom', 42);", + errors: callError("getIntPref takes only 1 parameter.") + }, { code: "Services.removeObserver('notification name', {}, false);", errors: callError("removeObserver only takes 2 parameters.") From ce83967603eeb4056ed65890c01a81ce1123e19b Mon Sep 17 00:00:00 2001 From: Pawan Sasanka Date: Fri, 13 Jan 2017 15:36:15 +0530 Subject: [PATCH 04/54] Bug 1319551 - Remove leftover chrome://browser/skin/social/share-button*.png files on Linux, r=florian. --- browser/themes/linux/jar.mn | 2 -- .../themes/linux/social/share-button-active.png | Bin 1341 -> 0 bytes browser/themes/linux/social/share-button.png | Bin 1346 -> 0 bytes 3 files changed, 2 deletions(-) delete mode 100644 browser/themes/linux/social/share-button-active.png delete mode 100644 browser/themes/linux/social/share-button.png diff --git a/browser/themes/linux/jar.mn b/browser/themes/linux/jar.mn index 83bde6fd3375..4a34bb52b841 100644 --- a/browser/themes/linux/jar.mn +++ b/browser/themes/linux/jar.mn @@ -79,8 +79,6 @@ browser.jar: skin/classic/browser/preferences/applications.css (preferences/applications.css) skin/classic/browser/social/services-16.png (social/services-16.png) skin/classic/browser/social/services-64.png (social/services-64.png) - skin/classic/browser/social/share-button.png (social/share-button.png) - skin/classic/browser/social/share-button-active.png (social/share-button-active.png) skin/classic/browser/tabbrowser/alltabs.png (tabbrowser/alltabs.png) skin/classic/browser/tabbrowser/alltabs-inverted.png (tabbrowser/alltabs-inverted.png) skin/classic/browser/tabbrowser/newtab.svg (tabbrowser/newtab.svg) diff --git a/browser/themes/linux/social/share-button-active.png b/browser/themes/linux/social/share-button-active.png deleted file mode 100644 index 7df438db014c265c35da304c4a846f5e34c46e4b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1341 zcmeAS@N?(olHy`uVBq!ia0vp@K+MO%1|+}KPrC%9BuiW)N`mv#O3D+9QW+dm@{>{( zJaZG%Q-e|yQz{EjrrIztFso#SM3hAM`dB6B=jtVb)aX^@765fKFxc2v6eK2Rr0UTq__OB&@Hb09I0xZL0)vRD^GUf^&XRs)DJWv2L<~p`n7AnVzAE zshOFfj)IYap^?4;5Si&3npl~dSs9rtK!Fm_wxX0Ys~{IQs9ivwtx`rwNr9EVetCJh zUb(Seeo?xx^|#0uTKVr7^KE~&-IMVSR9nfZANAQKal@=Hr> zm4GgVcp$o0y!L2NKW( z>+top^2{qPNz6-5^>ndS0-B+hnVDkcYHV(5=we~+XlCeWXy|I>TF_a z>Fi8Iua(|ZvxVGDY3eq>-^T<_`P7*cU7 z>Bs;7_RNMe`uqENJJcI)9Lbs>AR=-{MM>$Cz=`V#i3$uqe*Wx@h>TobP+VNkTx8F@ zkww^!mx+lf@y(kzr(0TE{TWRQ8E@Wqe57L`(tIS_(!yeqs;a8^zu(`_Pn$XOr?o(X zZsMUujshzZ1jWU}XEZe(vI-0gj9g%#EiHZ9-_7mVeTi8O^R6;jCF=6?_ivjrEx0}LmejW}`ov@|!*Eq({q`1JGh_Ac19>(-a=@9)G1cgPL0bkFmiEhK(E@ ziTU~RYgezX&i(xCY?s63-la>IroVpq(r~U#<)z<`kM}>?o_~Mc!H!x(LqkPo=H`=D zR#viJUS93#XJ?7BicGKh`f6%~kB^VygtrWvIayDfJju%N_Z63qng6$UcdJD-O87eV zH^i`c2}WF&GGH~3l9o=d`T5CJ`owhi>FgW^40pc2wEga}^9ZOw^K|udS?83{1ORwl B-GKlA diff --git a/browser/themes/linux/social/share-button.png b/browser/themes/linux/social/share-button.png deleted file mode 100644 index c5298c143eaaa74773f5066766f923ef076a74ca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1346 zcmeAS@N?(olHy`uVBq!ia0vp@K+MO%1|+}KPrC%9BuiW)N`mv#O3D+9QW+dm@{>{( zJaZG%Q-e|yQz{EjrrIztFso#SM3hAM`dB6B=jtVb)aX^@765fKFxc2v6eK2Rr0UTq__OB&@Hb09I0xZL0)vRD^GUf^&XRs)DJWv2L<~p`n7AnVzAE zshOFfj)IYap^?4;5Si&3npl~dSs9rtK!Fm_wxX0Ys~{IQs9ivwtx`rwNr9EVetCJh zUb(Seeo?xx^|#0uTKVr7^KE~&-IMVSR9nfZANAQKal@=Hr> zm4GgVcp$o0y!L2NKW( z>+top^2{qPNz6-5^>ndS0-B+hnVDkcYHV(5=we~)XlCeWXy|I>TF_a z>Fi8Iua(|ZvxVgIXp|Am2paf_#mV@SoV zo}m5SOo{4Q$}K%g@f8oN@4v5{_x0@D`O3GuM4zniyRHof=BPWuBozL%r@ zmKU3faD`g*&E9%5$2RtQYrN;ih%>$azP~A}7HTmL;aIsU%c*;>-}1vkXFRGuR@88H ziS{2C=4N3EUm5ah<=s4Qfr~zBmm3mi^a~1ceAb)(T7cPl!M_RTpRfK}ReLaLT^tlyo|Hb=r*)8T!Ir*xzgiolk9~?8px13P+Z(JfQs@xb6^D{2<$fcKGgglBP zP9^V*+2`_#?Ve)AC*``ob2?p`&ZQVh-_0}ctN8T%?{WrahUt6HEZFiP?jWdC^K|ud JS?83{1ORU;@oNA8 From 3b07a04a6b7f6197904ac0e8e09d9fddfed577b5 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Fri, 13 Jan 2017 14:39:27 -0500 Subject: [PATCH 05/54] Bug 1330458 - Queue undipatched events before Gecko is ready; r=snorp To deal with the Java side trying to send events to Gecko before Gecko is ready, make a special exception to queue any undispatched events when Gecko is not ready, so that the events can be redispatched to Gecko later. --- .../org/mozilla/gecko/EventDispatcher.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/EventDispatcher.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/EventDispatcher.java index 47f9a1b181dd..ebffb5de9cdf 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/EventDispatcher.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/EventDispatcher.java @@ -89,11 +89,10 @@ public final class EventDispatcher extends JNIObject { @WrapForJNI(calledFrom = "gecko") private synchronized void setAttachedToGecko(final int state) { if (mAttachedToGecko && state == DETACHED) { - if (GeckoThread.isStateAtLeast(GeckoThread.State.JNI_READY)) { + if (GeckoThread.isRunning()) { disposeNative(); } else { - GeckoThread.queueNativeCallUntil(GeckoThread.State.JNI_READY, - this, "disposeNative"); + GeckoThread.queueNativeCall(this, "disposeNative"); } } mAttachedToGecko = (state == ATTACHED); @@ -407,7 +406,19 @@ public final class EventDispatcher extends JNIObject { } if (jsMessage == null) { - Log.w(LOGTAG, "No listeners for " + type + " in dispatchToThreads"); + Log.w(LOGTAG, "No listeners for " + type); + } + + if (!GeckoThread.isRunning() && jsMessage == null) { + // Usually, we discard an event if there is no listeners for it by the time of + // the dispatch. However, if Gecko is not ready and there is no listener for + // this event that's possibly headed to Gecko, we make a special exception to + // queue this event until Gecko is ready. This way, Gecko can first register + // its listeners, and accept the event when it is ready. + GeckoThread.queueNativeCall(this, "dispatchToGecko", + String.class, type, GeckoBundle.class, bundleMessage, + EventCallback.class, JavaCallbackDelegate.wrap(callback)); + return true; } if (!AppConstants.RELEASE_OR_BETA && jsMessage == null) { @@ -487,8 +498,6 @@ public final class EventDispatcher extends JNIObject { } if (listeners.isEmpty()) { - Log.w(LOGTAG, "No listeners for " + type + " in dispatchToThread"); - // There were native listeners, and they're gone. return false; } @@ -529,8 +538,7 @@ public final class EventDispatcher extends JNIObject { final List listeners = getGeckoListeners(type); if (listeners == null || listeners.isEmpty()) { - Log.w(LOGTAG, "No listeners for " + type + " in dispatchEvent"); - + Log.w(LOGTAG, "No listeners for " + type); return false; } From f48add8fb63412a7407bad55bb0b4236ddc29e16 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Fri, 13 Jan 2017 14:39:27 -0500 Subject: [PATCH 06/54] Bug 1330515 - Try to recover from IME errors; r=esawin Instead of throwing IME exceptions, try to recover from IME errors by flushing the entire text unless we already tried that before. This prevents annoying crashes, and deals with known IME bugs that are too risky to uplift to older releases. --- .../java/org/mozilla/gecko/GeckoEditable.java | 4 +-- widget/android/GeneratedJNIWrappers.h | 4 +-- widget/android/nsWindow.cpp | 36 ++++++++++++++++--- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java index d26dca5e21fe..4be9597d7c95 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java @@ -1135,7 +1135,7 @@ final class GeckoEditable extends JNIObject }); } - @WrapForJNI(calledFrom = "gecko") + @WrapForJNI(calledFrom = "gecko", exceptionMode = "ignore") private void onSelectionChange(final int start, final int end) { if (DEBUG) { // GeckoEditableListener methods should all be called from the Gecko thread @@ -1164,7 +1164,7 @@ final class GeckoEditable extends JNIObject TextUtils.regionMatches(mText.getCurrentText(), start, newText, 0, oldEnd - start); } - @WrapForJNI(calledFrom = "gecko") + @WrapForJNI(calledFrom = "gecko", exceptionMode = "ignore") private void onTextChange(final CharSequence text, final int start, final int unboundedOldEnd, final int unboundedNewEnd) { if (DEBUG) { diff --git a/widget/android/GeneratedJNIWrappers.h b/widget/android/GeneratedJNIWrappers.h index b1c472fc0aef..8fe56900d2d3 100644 --- a/widget/android/GeneratedJNIWrappers.h +++ b/widget/android/GeneratedJNIWrappers.h @@ -2340,7 +2340,7 @@ public: "(II)V"; static const bool isStatic = false; static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; + mozilla::jni::ExceptionMode::IGNORE; static const mozilla::jni::CallingThread callingThread = mozilla::jni::CallingThread::GECKO; static const mozilla::jni::DispatchTarget dispatchTarget = @@ -2363,7 +2363,7 @@ public: "(Ljava/lang/CharSequence;III)V"; static const bool isStatic = false; static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; + mozilla::jni::ExceptionMode::IGNORE; static const mozilla::jni::CallingThread callingThread = mozilla::jni::CallingThread::GECKO; static const mozilla::jni::DispatchTarget dispatchTarget = diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index a330cbc41ebb..1f98da13ad15 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -415,12 +415,16 @@ private: void AddIMETextChange(const IMETextChange& aChange); enum FlushChangesFlag { + // Not retrying. FLUSH_FLAG_NONE, - FLUSH_FLAG_RETRY + // Retrying due to IME text changes during flush. + FLUSH_FLAG_RETRY, + // Retrying due to IME sync exceptions during flush. + FLUSH_FLAG_RECOVER }; void PostFlushIMEChanges(); void FlushIMEChanges(FlushChangesFlag aFlags = FLUSH_FLAG_NONE); - void FlushIMEText(); + void FlushIMEText(FlushChangesFlag aFlags = FLUSH_FLAG_NONE); void AsyncNotifyIME(int32_t aNotification); void UpdateCompositionRects(); @@ -2750,7 +2754,7 @@ nsWindow::GeckoViewSupport::FlushIMEChanges(FlushChangesFlag aFlags) // A query event could have triggered more text changes to come in, as // indicated by our flag. If that happens, try flushing IME changes // again. - if (aFlags != FLUSH_FLAG_RETRY) { + if (aFlags == FLUSH_FLAG_NONE) { FlushIMEChanges(FLUSH_FLAG_RETRY); } else { // Don't retry if already retrying, to avoid infinite loops. @@ -2805,22 +2809,44 @@ nsWindow::GeckoViewSupport::FlushIMEChanges(FlushChangesFlag aFlags) selEnd = int32_t(event.GetSelectionEnd()); } + JNIEnv* const env = jni::GetGeckoThreadEnv(); + auto flushOnException = [=] () -> bool { + if (!env->ExceptionCheck()) { + return false; + } + if (aFlags != FLUSH_FLAG_RECOVER) { + // First time seeing an exception; try flushing text. + env->ExceptionClear(); + __android_log_print(ANDROID_LOG_WARN, "GeckoViewSupport", + "Recovering from IME exception"); + FlushIMEText(FLUSH_FLAG_RECOVER); + } else { + // Give up because we've already tried. + MOZ_CATCH_JNI_EXCEPTION(env); + } + return true; + }; + // Commit the text change and selection change transaction. mIMETextChanges.Clear(); for (const TextRecord& record : textTransaction) { mEditable->OnTextChange(record.text, record.start, record.oldEnd, record.newEnd); + if (flushOnException()) { + return; + } } if (mIMESelectionChanged) { mIMESelectionChanged = false; mEditable->OnSelectionChange(selStart, selEnd); + flushOnException(); } } void -nsWindow::GeckoViewSupport::FlushIMEText() +nsWindow::GeckoViewSupport::FlushIMEText(FlushChangesFlag aFlags) { // Notify Java of the newly focused content mIMETextChanges.Clear(); @@ -2835,7 +2861,7 @@ nsWindow::GeckoViewSupport::FlushIMEText() notification.mTextChangeData.mAddedEndOffset = INT32_MAX / 2; NotifyIME(notification); - FlushIMEChanges(); + FlushIMEChanges(aFlags); } static jni::ObjectArray::LocalRef From a1866340f0f76db5db14ad431931c30d5c33f26b Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Fri, 13 Jan 2017 11:53:58 -0800 Subject: [PATCH 07/54] Bug 1314091 - Backed out changeset 60d0080b95fe (bug 1308407) We won't need this anymore, since there will be a separate light and dark theme definition, so we can update the theme definition to allow the brightness to be inferred automatically by the lightweight theming system. MozReview-Commit-ID: 3GuZ3Qezc1F --- browser/base/content/browser-devedition.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/browser/base/content/browser-devedition.js b/browser/base/content/browser-devedition.js index 4ac6a2818dab..4810fbd3463b 100644 --- a/browser/base/content/browser-devedition.js +++ b/browser/base/content/browser-devedition.js @@ -25,7 +25,6 @@ var DevEdition = { this.initialized = true; Services.prefs.addObserver(this._devtoolsThemePrefName, this, false); Services.obs.addObserver(this, "lightweight-theme-styling-update", false); - Services.obs.addObserver(this, "lightweight-theme-window-updated", false); this._updateDevtoolsThemeAttribute(); if (this.isThemeCurrentlyApplied) { @@ -50,8 +49,6 @@ var DevEdition = { } else { this._toggleStyleSheet(false); } - } else if (topic == "lightweight-theme-window-updated" && subject == window) { - this._updateLWTBrightness(); } if (topic == "nsPref:changed" && data == this._devtoolsThemePrefName) { @@ -70,14 +67,6 @@ var DevEdition = { } }, - _updateLWTBrightness() { - if (this.isThemeCurrentlyApplied) { - let devtoolsTheme = Services.prefs.getCharPref(this._devtoolsThemePrefName); - let textColor = devtoolsTheme == "dark" ? "bright" : "dark"; - document.documentElement.setAttribute("lwthemetextcolor", textColor); - } - }, - _updateDevtoolsThemeAttribute() { // Set an attribute on root element to make it possible // to change colors based on the selected devtools theme. @@ -86,7 +75,6 @@ var DevEdition = { devtoolsTheme = "light"; } document.documentElement.setAttribute("devtoolstheme", devtoolsTheme); - this._updateLWTBrightness(); this._inferBrightness(); }, @@ -125,7 +113,6 @@ var DevEdition = { uninit() { Services.prefs.removeObserver(this._devtoolsThemePrefName, this); Services.obs.removeObserver(this, "lightweight-theme-styling-update"); - Services.obs.removeObserver(this, "lightweight-theme-window-updated"); if (this.styleSheet) { this.styleSheet.removeEventListener("load", this); } From 91605663d0f316c1ae87799a97bcf105ae20ec29 Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Fri, 13 Jan 2017 11:53:58 -0800 Subject: [PATCH 08/54] Bug 1314091 - Rename devedition.* to compacttheme.*;r=Gijs MozReview-Commit-ID: 9y9BTK2TeAr --HG-- rename : browser/base/content/browser-devedition.js => browser/base/content/browser-compacttheme.js rename : browser/base/content/test/general/browser_devedition.js => browser/base/content/test/general/browser_compacttheme.js rename : browser/themes/linux/devedition.css => browser/themes/linux/compacttheme.css rename : browser/themes/osx/devedition.css => browser/themes/osx/compacttheme.css rename : browser/themes/shared/devedition.inc.css => browser/themes/shared/compacttheme.inc.css rename : browser/themes/windows/devedition.css => browser/themes/windows/compacttheme.css --- ...-devedition.js => browser-compacttheme.js} | 14 ++++----- browser/base/content/browser.js | 4 +-- browser/base/content/global-scripts.inc | 2 +- browser/base/content/test/general/browser.ini | 2 +- ..._devedition.js => browser_compacttheme.js} | 30 +++++++++---------- browser/base/jar.mn | 2 +- .../{devedition.css => compacttheme.css} | 2 +- browser/themes/linux/jar.mn | 2 +- .../osx/{devedition.css => compacttheme.css} | 2 +- browser/themes/osx/jar.mn | 2 +- ...evedition.inc.css => compacttheme.inc.css} | 4 +-- browser/themes/windows/browser.css | 2 +- .../{devedition.css => compacttheme.css} | 2 +- browser/themes/windows/jar.mn | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) rename browser/base/content/{browser-devedition.js => browser-compacttheme.js} (90%) rename browser/base/content/test/general/{browser_devedition.js => browser_compacttheme.js} (74%) rename browser/themes/linux/{devedition.css => compacttheme.css} (98%) rename browser/themes/osx/{devedition.css => compacttheme.css} (98%) rename browser/themes/shared/{devedition.inc.css => compacttheme.inc.css} (98%) rename browser/themes/windows/{devedition.css => compacttheme.css} (99%) diff --git a/browser/base/content/browser-devedition.js b/browser/base/content/browser-compacttheme.js similarity index 90% rename from browser/base/content/browser-devedition.js rename to browser/base/content/browser-compacttheme.js index 4810fbd3463b..6e237d8f4389 100644 --- a/browser/base/content/browser-devedition.js +++ b/browser/base/content/browser-compacttheme.js @@ -3,12 +3,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * Listeners for the DevEdition theme. This adds an extra stylesheet + * Listeners for the compact theme. This adds an extra stylesheet * to browser.xul if a pref is set and no other themes are applied. */ -var DevEdition = { +var CompactTheme = { _devtoolsThemePrefName: "devtools.theme", - styleSheetLocation: "chrome://browser/skin/devedition.css", + styleSheetLocation: "chrome://browser/skin/compacttheme.css", styleSheet: null, initialized: false, @@ -120,10 +120,10 @@ var DevEdition = { } }; -// If the DevEdition theme is going to be applied in gBrowserInit.onLoad, +// If the compact theme is going to be applied in gBrowserInit.onLoad, // then preload it now. This prevents a flash of unstyled content where the -// normal theme is applied while the DevEdition stylesheet is loading. +// normal theme is applied while the compact theme stylesheet is loading. if (!AppConstants.RELEASE_OR_BETA && - this != Services.appShell.hiddenDOMWindow && DevEdition.isThemeCurrentlyApplied) { - DevEdition.createStyleSheet(); + this != Services.appShell.hiddenDOMWindow && CompactTheme.isThemeCurrentlyApplied) { + CompactTheme.createStyleSheet(); } diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index ffa091e69a98..f82df438c44c 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -998,7 +998,7 @@ var gBrowserInit = { LanguageDetectionListener.init(); BrowserOnClick.init(); FeedHandler.init(); - DevEdition.init(); + CompactTheme.init(); AboutPrivateBrowsingListener.init(); TrackingProtection.init(); RefreshBlocker.init(); @@ -1515,7 +1515,7 @@ var gBrowserInit = { FeedHandler.uninit(); - DevEdition.uninit(); + CompactTheme.uninit(); TrackingProtection.uninit(); diff --git a/browser/base/content/global-scripts.inc b/browser/base/content/global-scripts.inc index 5b30febfb3fe..8284722a574f 100755 --- a/browser/base/content/global-scripts.inc +++ b/browser/base/content/global-scripts.inc @@ -13,7 +13,7 @@

diff --git a/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js b/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js index 48f6524d2c22..00d3befa2603 100644 --- a/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js +++ b/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js @@ -82,6 +82,21 @@ const TESTCASES = [
`, returnedFieldIDsByFormLike: [["pw1"], []], skipEmptyFields: true, + fieldOverrideRecipe: { + // Ensure a recipe without `notPasswordSelector` doesn't cause a problem. + hosts: ["localhost:8080"], + }, + }, + { + description: "3 password fields outside of a
with 1 linked via @form + skipEmpty", + document: ` +
`, + returnedFieldIDsByFormLike: [["pw3"], ["pw2"]], + skipEmptyFields: true, + fieldOverrideRecipe: { + hosts: ["localhost:8080"], + notPasswordSelector: "#pw1", + }, }, ]; @@ -115,8 +130,10 @@ for (let tc of TESTCASES) { let formLikeIndex = -1; for (let formLikeFromInput of mapRootElementToFormLike.values()) { formLikeIndex++; - let pwFields = LoginManagerContent._getPasswordFields(formLikeFromInput, - testcase.skipEmptyFields); + let pwFields = LoginManagerContent._getPasswordFields(formLikeFromInput, { + fieldOverrideRecipe: testcase.fieldOverrideRecipe, + skipEmptyFields: testcase.skipEmptyFields, + }); if (formLikeFromInput.rootElement instanceof Ci.nsIDOMHTMLFormElement) { let formLikeFromForm = LoginFormFactory.createFromForm(formLikeFromInput.rootElement); From d4abc9557d9b1ed52b3c74a3555b47ab057d680e Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Thu, 12 Jan 2017 17:37:46 -0800 Subject: [PATCH 18/54] Bug 1330810 - Disable password manager on www.united.com/travel/checkin/changefqtv.aspx. r=johannh MozReview-Commit-ID: FCRvgYjm8BI --HG-- extra : rebase_source : 67d1407617c5d9256889fef8740c431b84413649 --- toolkit/components/passwordmgr/content/recipes.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/toolkit/components/passwordmgr/content/recipes.json b/toolkit/components/passwordmgr/content/recipes.json index fc747219b481..e75269c3fe65 100644 --- a/toolkit/components/passwordmgr/content/recipes.json +++ b/toolkit/components/passwordmgr/content/recipes.json @@ -26,6 +26,12 @@ "description": "Username field will be incorrectly captured in the change password form (bug 1243722)", "hosts": ["www.facebook.com"], "notUsernameSelector": "#password_strength" + }, + { + "description": "United uses a useless password field plus one per frequent flyer number during checkin. Don't save any of them (Bug 1330810)", + "hosts": ["www.united.com"], + "notPasswordSelector": "input[type='password']", + "pathRegex": "^\/travel\/checkin\/changefqtv.aspx" } ] } From 5fee7ef72c0b129403c70485eb7a9edb54e2fce5 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Thu, 12 Jan 2017 18:22:28 -0800 Subject: [PATCH 19/54] Bug 1330844 - Add a pwmgr notPasswordSelector:#cardNumber recipe for buy.gogoinflight.com. r=johannh MozReview-Commit-ID: GWG3XNmrU9c --HG-- extra : rebase_source : 385a56126882c0f0d72817ee8c7941cab37f8033 --- toolkit/components/passwordmgr/content/recipes.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/toolkit/components/passwordmgr/content/recipes.json b/toolkit/components/passwordmgr/content/recipes.json index e75269c3fe65..f03fe84327cb 100644 --- a/toolkit/components/passwordmgr/content/recipes.json +++ b/toolkit/components/passwordmgr/content/recipes.json @@ -32,6 +32,11 @@ "hosts": ["www.united.com"], "notPasswordSelector": "input[type='password']", "pathRegex": "^\/travel\/checkin\/changefqtv.aspx" + }, + { + "description": "Gogo In-Flight uses a password field for credit card numbers on the same page as login", + "hosts": ["buy.gogoinflight.com"], + "notPasswordSelector": "#cardNumber" } ] } From b428dc3b24a704ae8ee719bd4e4de884f53a6588 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 30 Nov 2016 18:18:14 -0500 Subject: [PATCH 20/54] Bug 851892 part 1. Make all CSS rules cycle-collected. r=heycam --- layout/style/CSSStyleSheet.cpp | 2 +- layout/style/GroupRule.h | 4 +- layout/style/ImportRule.h | 4 +- layout/style/NameSpaceRule.h | 2 +- layout/style/Rule.h | 3 + layout/style/ServoCSSRuleList.cpp | 2 +- layout/style/ServoStyleRule.cpp | 15 ++-- layout/style/ServoStyleRule.h | 4 +- layout/style/StyleRule.cpp | 25 +++++-- layout/style/StyleRule.h | 7 +- layout/style/nsCSSRules.cpp | 111 ++++++++++++++++-------------- layout/style/nsCSSRules.h | 17 ++--- 12 files changed, 114 insertions(+), 82 deletions(-) diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 9b033e078998..fe2fad398ed0 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -508,7 +508,7 @@ CSSStyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb) const nsCOMArray& rules = mInner->mOrderedRules; for (int32_t i = 0, count = rules.Count(); i < count; ++i) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mOrderedRules[i]"); - cb.NoteXPCOMChild(rules[i]->GetExistingDOMRule()); + cb.NoteXPCOMChild(rules[i]); } } diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index 868086fe8b32..63c6385195da 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -38,8 +38,8 @@ protected: virtual ~GroupRule(); public: - NS_DECL_CYCLE_COLLECTION_CLASS(GroupRule) - NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule, Rule) + NS_DECL_ISUPPORTS_INHERITED // implement part of Rule DECL_STYLE_RULE_INHERIT_NO_DOMRULE diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index a324bc4e71b5..a4e30837dc51 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -34,8 +34,8 @@ private: ImportRule(const ImportRule& aCopy); ~ImportRule(); public: - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ImportRule, mozilla::css::Rule) - NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImportRule, Rule) + NS_DECL_ISUPPORTS_INHERITED DECL_STYLE_RULE_INHERIT diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 92d910cf5dc4..20947112eaf9 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -37,7 +37,7 @@ private: public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_NAMESPACE_RULE_IMPL_CID) - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED // Rule methods DECL_STYLE_RULE_INHERIT diff --git a/layout/style/Rule.h b/layout/style/Rule.h index c07ec1a3d3ed..f00490efe0de 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -52,6 +52,9 @@ protected: public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(Rule) + #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; #endif diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index 59e5ac82f2ff..d1d5cd3d77e5 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -47,7 +47,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoCSSRuleList, dom::CSSRuleList) tmp->EnumerateInstantiatedRules([&](css::Rule* aRule) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]"); - cb.NoteXPCOMChild(aRule->GetExistingDOMRule()); + cb.NoteXPCOMChild(aRule); }); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END diff --git a/layout/style/ServoStyleRule.cpp b/layout/style/ServoStyleRule.cpp index 66a97d9abe06..ec436d0e5b97 100644 --- a/layout/style/ServoStyleRule.cpp +++ b/layout/style/ServoStyleRule.cpp @@ -107,33 +107,32 @@ ServoStyleRule::ServoStyleRule(already_AddRefed aRawRule) } // QueryInterface implementation for ServoStyleRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServoStyleRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(css::Rule) -NS_IMPL_CYCLE_COLLECTING_ADDREF(ServoStyleRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(ServoStyleRule) +NS_IMPL_ADDREF_INHERITED(ServoStyleRule, css::Rule) +NS_IMPL_RELEASE_INHERITED(ServoStyleRule, css::Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(ServoStyleRule) -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ServoStyleRule) +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ServoStyleRule, css::Rule) // Trace the wrapper for our declaration. This just expands out // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use // directly because the wrapper is on the declaration, not on us. tmp->mDecls.TraceWrapper(aCallbacks, aClosure); NS_IMPL_CYCLE_COLLECTION_TRACE_END -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ServoStyleRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ServoStyleRule, css::Rule) // Unlink the wrapper for our declaraton. This just expands out // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use // directly because the wrapper is on the declaration, not on us. tmp->mDecls.ReleaseWrapper(static_cast(p)); NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ServoStyleRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoStyleRule, css::Rule) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END already_AddRefed diff --git a/layout/style/ServoStyleRule.h b/layout/style/ServoStyleRule.h index f6296a032405..40d2a2444e3a 100644 --- a/layout/style/ServoStyleRule.h +++ b/layout/style/ServoStyleRule.h @@ -53,8 +53,8 @@ class ServoStyleRule final : public css::Rule public: explicit ServoStyleRule(already_AddRefed aRawRule); - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(ServoStyleRule, + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ServoStyleRule, css::Rule) NS_DECL_NSIDOMCSSRULE NS_DECL_NSIDOMCSSSTYLERULE diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 7d63388159b8..9e282a3ebbab 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1398,28 +1398,43 @@ StyleRule::StyleRule(const StyleRule& aCopy) StyleRule::~StyleRule() { delete mSelector; + DropReferences(); +} + +void +StyleRule::DropReferences() +{ if (mDOMRule) { mDOMRule->DOMDeclaration()->DropReference(); + mDOMRule = nullptr; } if (mDeclaration) { mDeclaration->SetOwningRule(nullptr); + mDeclaration = nullptr; } } // QueryInterface implementation for StyleRule -NS_INTERFACE_MAP_BEGIN(StyleRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) if (aIID.Equals(NS_GET_IID(mozilla::css::StyleRule))) { *aInstancePtr = this; NS_ADDREF_THIS(); return NS_OK; } else - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) -NS_IMPL_ADDREF(StyleRule) -NS_IMPL_RELEASE(StyleRule) +NS_IMPL_ADDREF_INHERITED(StyleRule, Rule) +NS_IMPL_RELEASE_INHERITED(StyleRule, Rule) + +NS_IMPL_CYCLE_COLLECTION_CLASS(StyleRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(StyleRule, Rule) + tmp->DropReferences(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(StyleRule, Rule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeclaration, mDOMRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END /* virtual */ int32_t StyleRule::GetType() const diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 2b079d30f1f9..0b046f76e807 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -320,7 +320,8 @@ private: public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_RULE_IMPL_CID) - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(StyleRule, Rule) // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -358,6 +359,10 @@ public: private: ~StyleRule(); + // Drop our references to mDeclaration and mRule, and let them know we're + // doing that. + void DropReferences(); + private: nsCSSSelectorList* mSelector; // null for style attribute RefPtr mDeclaration; diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index cdf331b24074..af21220b5762 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -55,6 +55,15 @@ IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) namespace mozilla { namespace css { +NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule) +NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule) + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTION_0(Rule) + /* virtual */ void Rule::SetStyleSheet(StyleSheet* aSheet) { @@ -199,18 +208,17 @@ ImportRule::~ImportRule() } } -NS_IMPL_CYCLE_COLLECTING_ADDREF(ImportRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(ImportRule) +NS_IMPL_ADDREF_INHERITED(ImportRule, Rule) +NS_IMPL_RELEASE_INHERITED(ImportRule, Rule) -NS_IMPL_CYCLE_COLLECTION(ImportRule, mMedia, mChildSheet) +NS_IMPL_CYCLE_COLLECTION_INHERITED(ImportRule, Rule, mMedia, mChildSheet) // QueryInterface implementation for ImportRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ImportRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) IMPL_STYLE_RULE_INHERIT(ImportRule, Rule) @@ -380,11 +388,11 @@ GroupRule::~GroupRule() } } -NS_IMPL_CYCLE_COLLECTING_ADDREF(GroupRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(GroupRule) +NS_IMPL_ADDREF_INHERITED(GroupRule, Rule) +NS_IMPL_RELEASE_INHERITED(GroupRule, Rule) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(Rule) static bool SetStyleSheetReference(Rule* aRule, void* aSheet) @@ -395,7 +403,7 @@ SetStyleSheetReference(Rule* aRule, void* aSheet) NS_IMPL_CYCLE_COLLECTION_CLASS(GroupRule) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(GroupRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GroupRule, Rule) tmp->mRules.EnumerateForwards(SetParentRuleReference, nullptr); // If tmp does not have a stylesheet, neither do its descendants. In that // case, don't try to null out their stylesheet, to avoid O(N^2) behavior in @@ -413,11 +421,11 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(GroupRule) } NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(GroupRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GroupRule, Rule) const nsCOMArray& rules = tmp->mRules; for (int32_t i = 0, count = rules.Count(); i < count; ++i) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]"); - cb.NoteXPCOMChild(rules[i]->GetExistingDOMRule()); + cb.NoteXPCOMChild(rules[i]); } NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleCollection) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -605,15 +613,17 @@ NS_IMPL_ADDREF_INHERITED(MediaRule, GroupRule) NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule) // QueryInterface implementation for MediaRule -NS_INTERFACE_MAP_BEGIN(MediaRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) +NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaRule, GroupRule, + mMedia) + /* virtual */ void MediaRule::SetStyleSheet(StyleSheet* aSheet) { @@ -1085,8 +1095,8 @@ NameSpaceRule::~NameSpaceRule() { } -NS_IMPL_ADDREF(NameSpaceRule) -NS_IMPL_RELEASE(NameSpaceRule) +NS_IMPL_ADDREF_INHERITED(NameSpaceRule, Rule) +NS_IMPL_RELEASE_INHERITED(NameSpaceRule, Rule) // QueryInterface implementation for NameSpaceRule NS_INTERFACE_MAP_BEGIN(NameSpaceRule) @@ -1097,9 +1107,8 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule) } else NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule) @@ -1507,35 +1516,37 @@ nsCSSFontFaceRule::Clone() const return clone.forget(); } -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSFontFaceRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSFontFaceRule) +NS_IMPL_ADDREF_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSFontFaceRule) -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsCSSFontFaceRule) +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsCSSFontFaceRule, + mozilla::css::Rule) // Trace the wrapper for our declaration. This just expands out // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use // directly because the wrapper is on the declaration, not on us. tmp->mDecl.TraceWrapper(aCallbacks, aClosure); NS_IMPL_CYCLE_COLLECTION_TRACE_END -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSFontFaceRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsCSSFontFaceRule, + mozilla::css::Rule) // Unlink the wrapper for our declaraton. This just expands out // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use // directly because the wrapper is on the declaration, not on us. tmp->mDecl.ReleaseWrapper(static_cast(p)); NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSFontFaceRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsCSSFontFaceRule, + mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSFontFaceRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSFontFaceRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule) @@ -1670,16 +1681,15 @@ nsCSSFontFeatureValuesRule::Clone() const return clone.forget(); } -NS_IMPL_ADDREF(nsCSSFontFeatureValuesRule) -NS_IMPL_RELEASE(nsCSSFontFeatureValuesRule) +NS_IMPL_ADDREF_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSFontFeatureValuesRule NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) IMPL_STYLE_RULE_INHERIT(nsCSSFontFeatureValuesRule, Rule) @@ -1994,28 +2004,29 @@ nsCSSKeyframeRule::Clone() const return clone.forget(); } -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSKeyframeRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSKeyframeRule) +NS_IMPL_ADDREF_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSKeyframeRule) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSKeyframeRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsCSSKeyframeRule, + mozilla::css::Rule) if (tmp->mDOMDeclaration) { tmp->mDOMDeclaration->DropReference(); tmp->mDOMDeclaration = nullptr; } NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSKeyframeRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsCSSKeyframeRule, + mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSKeyframeRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSKeyframeRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSKeyframeRule, Rule) @@ -2216,7 +2227,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule) NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframesRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframesRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) @@ -2531,28 +2541,29 @@ nsCSSPageRule::Clone() const return clone.forget(); } -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSPageRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSPageRule) +NS_IMPL_ADDREF_INHERITED(nsCSSPageRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSPageRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSPageRule) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSPageRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsCSSPageRule, + mozilla::css::Rule) if (tmp->mDOMDeclaration) { tmp->mDOMDeclaration->DropReference(); tmp->mDOMDeclaration = nullptr; } NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSPageRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsCSSPageRule, + mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSPageRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSPageRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSPageRule, Rule) @@ -2722,7 +2733,6 @@ NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) @@ -2843,16 +2853,15 @@ nsCSSCounterStyleRule::kGetters[] = { #undef CSS_COUNTER_DESC }; -NS_IMPL_ADDREF(nsCSSCounterStyleRule) -NS_IMPL_RELEASE(nsCSSCounterStyleRule) +NS_IMPL_ADDREF_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSCounterStyleRule NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCounterStyleRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) IMPL_STYLE_RULE_INHERIT(nsCSSCounterStyleRule, css::Rule) diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 1656b713176f..c70f195f65af 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -53,6 +53,7 @@ private: ~MediaRule(); public: + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRule, GroupRule) NS_DECL_ISUPPORTS_INHERITED // Rule methods @@ -248,8 +249,8 @@ public: // copy everything except our reference count : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) {} - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsCSSFontFaceRule, + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) // Rule methods @@ -315,7 +316,7 @@ public: mFamilyList(aCopy.mFamilyList), mFeatureValues(aCopy.mFeatureValues) {} - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED // Rule methods DECL_STYLE_RULE_INHERIT @@ -397,8 +398,8 @@ private: nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy); ~nsCSSKeyframeRule(); public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCSSKeyframeRule, mozilla::css::Rule) + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) // Rule methods DECL_STYLE_RULE_INHERIT @@ -524,8 +525,8 @@ private: nsCSSPageRule(const nsCSSPageRule& aCopy); ~nsCSSPageRule(); public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCSSPageRule, nsIDOMCSSPageRule) + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSPageRule, mozilla::css::Rule) // Rule methods DECL_STYLE_RULE_INHERIT @@ -621,7 +622,7 @@ private: ~nsCSSCounterStyleRule(); public: - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED // Rule methods DECL_STYLE_RULE_INHERIT From ff9df2fc6574d8e7a7622f153bf315bddc04e8ed Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:02 -0500 Subject: [PATCH 21/54] Bug 851892 part 2. Remove the now-unused GetExistingDOMRule method. r=heycam --- layout/style/Rule.h | 6 +----- layout/style/ServoStyleRule.h | 1 - layout/style/StyleRule.cpp | 6 ------ layout/style/StyleRule.h | 2 -- layout/style/nsCSSRules.cpp | 3 --- layout/style/nsCSSRules.h | 16 ---------------- 6 files changed, 1 insertion(+), 33 deletions(-) diff --git a/layout/style/Rule.h b/layout/style/Rule.h index f00490efe0de..6b5af0954b13 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -27,8 +27,7 @@ class GroupRule; #define DECL_STYLE_RULE_INHERIT \ DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ - virtual nsIDOMCSSRule* GetDOMRule() override; \ - virtual nsIDOMCSSRule* GetExistingDOMRule() override; + virtual nsIDOMCSSRule* GetDOMRule() override; class Rule : public nsISupports { protected: @@ -113,9 +112,6 @@ public: // supposed to have a DOM rule representation (and our code wouldn't work). virtual nsIDOMCSSRule* GetDOMRule() = 0; - // Like GetDOMRule(), but won't create one if we don't have one yet - virtual nsIDOMCSSRule* GetExistingDOMRule() = 0; - // to implement methods on nsIDOMCSSRule nsresult GetParentRule(nsIDOMCSSRule** aParentRule); nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet); diff --git a/layout/style/ServoStyleRule.h b/layout/style/ServoStyleRule.h index 40d2a2444e3a..03d8f4d43fe9 100644 --- a/layout/style/ServoStyleRule.h +++ b/layout/style/ServoStyleRule.h @@ -65,7 +65,6 @@ public: int32_t GetType() const final { return css::Rule::STYLE_RULE; } already_AddRefed Clone() const final; nsIDOMCSSRule* GetDOMRule() final { return this; } - nsIDOMCSSRule* GetExistingDOMRule() final { return this; } size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 9e282a3ebbab..d3740f720ba0 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1464,12 +1464,6 @@ StyleRule::GetDOMRule() return mDOMRule; } -/* virtual */ nsIDOMCSSRule* -StyleRule::GetExistingDOMRule() -{ - return mDOMRule; -} - void StyleRule::SetDeclaration(Declaration* aDecl) { diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 0b046f76e807..392164957ac7 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -348,8 +348,6 @@ public: virtual nsIDOMCSSRule* GetDOMRule() override; - virtual nsIDOMCSSRule* GetExistingDOMRule() override; - #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index af21220b5762..1530648e7104 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -43,8 +43,6 @@ using namespace mozilla::dom; #define IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \ /* virtual */ nsIDOMCSSRule* class_::GetDOMRule() \ - { return this; } \ - /* virtual */ nsIDOMCSSRule* class_::GetExistingDOMRule() \ { return this; } #define IMPL_STYLE_RULE_INHERIT(class_, super_) \ @@ -839,7 +837,6 @@ NS_INTERFACE_MAP_BEGIN(DocumentRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index c70f195f65af..9dc792d8f300 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -72,10 +72,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE @@ -127,10 +123,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE @@ -457,10 +449,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE @@ -575,10 +563,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } NS_DECL_ISUPPORTS_INHERITED From 9426a2df7ffebfa05ba8bd40a9b10ae7a38d7680 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:02 -0500 Subject: [PATCH 22/54] Bug 851892 part 3. Give CSS rules a PreCreate hook so we can safely wrappercache them. r=peterv --- dom/base/nsDOMClassInfo.cpp | 93 +++++++++++++++++++++++++++---------- dom/base/nsDOMClassInfo.h | 22 +++++++++ 2 files changed, 91 insertions(+), 24 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 92b170b7ad05..e86f1ff338db 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -190,14 +190,18 @@ static nsDOMClassInfoData sClassInfoData[] = { // Misc Core related classes // CSS classes - NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSNameSpaceRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) + NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) + NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) + NS_DEFINE_CLASSINFO_DATA(CSSNameSpaceRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) // XUL classes #ifdef MOZ_XUL @@ -221,14 +225,17 @@ static nsDOMClassInfoData sClassInfoData[] = { DEFAULT_SCRIPTABLE_FLAGS) #endif - NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSSupportsRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSSupportsRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentFrameMessageManager, nsMessageManagerSH, @@ -246,19 +253,24 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSKeyframeRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSKeyframesRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSKeyframeRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) + NS_DEFINE_CLASSINFO_DATA(CSSKeyframesRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSPageRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSPageRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -1984,6 +1996,39 @@ nsEventTargetSH::PreserveWrapper(nsISupports *aNative) target->PreserveWrapper(aNative); } +// CSS rule helper +NS_IMETHODIMP +nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx, + JSObject *aGlobalObj, JSObject **parentObj) +{ + JS::Rooted globalObj(cx, aGlobalObj); + nsCOMPtr rule = do_QueryInterface(nativeObj); + if (!rule) { + return NS_ERROR_UNEXPECTED; + } + css::Rule* cssRule = rule->GetCSSRule(); + if (!cssRule) { + // A DOMCSSStyleRule whose actual underlying rule has gone away. There + // isn't much a caller can do with this thing anyway, and only chrome code + // can get its hands on it to start with, so just wrap in the current + // global. + *parentObj = globalObj; + return NS_OK; + } + nsIDocument* doc = cssRule->GetDocument(); + if (!doc) { + *parentObj = globalObj; + return NS_OK; + } + + nsIGlobalObject* global = doc->GetScopeObject(); + if (!global) { + return NS_ERROR_UNEXPECTED; + } + *parentObj = global->GetGlobalJSObject(); + return *parentObj ? NS_OK : NS_ERROR_FAILURE; +} + // nsIDOMEventListener::HandleEvent() 'this' converter helper NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator) diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index c63044627bdd..25377cfa2ee5 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -182,6 +182,28 @@ public: virtual void PreserveWrapper(nsISupports *aNative) override; }; +// Makes sure that we always create our wrapper in the right global, so we won't +// cache one from the wrong global. +class nsCSSRuleSH : public nsDOMGenericSH +{ +protected: + explicit nsCSSRuleSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData) + { + } + + virtual ~nsCSSRuleSH() + { + } +public: + NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, + JSObject *globalObj, JSObject **parentObj) override; + + static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) + { + return new nsCSSRuleSH(aData); + } +}; + // A place to hang some static methods that we should really consider // moving to be nsGlobalWindow member methods. See bug 1062418. class nsWindowSH From 56e3ade4f8cb4afb52d48318ad00681bdc301d74 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:02 -0500 Subject: [PATCH 23/54] Bug 851892 part 4. Make css::Rule wrappercached. r=heycam,peterv Note that this increases the size of css::Rule by three words, unfortunately. --- dom/base/nsWrapperCache.h | 31 ++++++++++ layout/style/ImportRule.h | 3 + layout/style/NameSpaceRule.h | 3 + layout/style/Rule.h | 7 ++- layout/style/ServoStyleRule.cpp | 9 +++ layout/style/ServoStyleRule.h | 2 + layout/style/StyleRule.cpp | 10 ++++ layout/style/StyleRule.h | 3 + layout/style/nsCSSRules.cpp | 102 +++++++++++++++++++++++++++++++- layout/style/nsCSSRules.h | 56 ++++++++++++++++-- 10 files changed, 217 insertions(+), 9 deletions(-) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 56cae89edb8f..aa5d63db32eb 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -19,10 +19,25 @@ namespace dom { class TabChildGlobal; class ProcessGlobal; } // namespace dom +namespace css { +class ImportRule; +class NameSpaceRule; +class StyleRule; +class MediaRule; +class DocumentRule; +} // namespace css +class ServoStyleRule; +class CSSSupportsRule; } // namespace mozilla class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; +class nsCSSFontFaceRule; +class nsCSSFontFeatureValuesRule; +class nsCSSKeyframeRule; +class nsCSSKeyframesRule; +class nsCSSPageRule; +class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ { 0x6f3179a1, 0x36f7, 0x4a5c, \ @@ -272,11 +287,27 @@ protected: } private: + // Friend declarations for things that need to be able to call + // SetIsNotDOMBinding(). The goal is to get rid of all of these, and + // SetIsNotDOMBinding() too. friend class mozilla::dom::TabChildGlobal; friend class mozilla::dom::ProcessGlobal; friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; + friend class mozilla::css::ImportRule; + friend class mozilla::css::NameSpaceRule; + friend class mozilla::css::StyleRule; + friend class mozilla::css::MediaRule; + friend class mozilla::css::DocumentRule; + friend class mozilla::ServoStyleRule; + friend class mozilla::CSSSupportsRule; + friend class nsCSSFontFaceRule; + friend class nsCSSFontFeatureValuesRule; + friend class nsCSSKeyframeRule; + friend class nsCSSKeyframesRule; + friend class nsCSSPageRule; + friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() { MOZ_ASSERT(!mWrapper && !(GetWrapperFlags() & ~WRAPPER_IS_NOT_DOM_BINDING), diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index a4e30837dc51..3ad8246c94ba 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -52,6 +52,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 20947112eaf9..406938650ab7 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -54,6 +54,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 6b5af0954b13..8d9c256d0729 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -12,6 +12,7 @@ #include "mozilla/MemoryReporting.h" #include "nsISupports.h" #include "nsIDOMCSSRule.h" +#include "nsWrapperCache.h" class nsIDocument; struct nsRuleData; @@ -29,7 +30,9 @@ class GroupRule; DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ virtual nsIDOMCSSRule* GetDOMRule() override; -class Rule : public nsISupports { +class Rule : public nsISupports + , public nsWrapperCache +{ protected: Rule(uint32_t aLineNumber, uint32_t aColumnNumber) : mSheet(nullptr), @@ -52,7 +55,7 @@ protected: public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(Rule) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Rule) #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; diff --git a/layout/style/ServoStyleRule.cpp b/layout/style/ServoStyleRule.cpp index ec436d0e5b97..81a824eacb8d 100644 --- a/layout/style/ServoStyleRule.cpp +++ b/layout/style/ServoStyleRule.cpp @@ -104,6 +104,7 @@ ServoStyleRule::ServoStyleRule(already_AddRefed aRawRule) , mRawRule(aRawRule) , mDecls(Servo_StyleRule_GetStyle(mRawRule).Consume()) { + SetIsNotDOMBinding(); } // QueryInterface implementation for ServoStyleRule @@ -152,6 +153,14 @@ ServoStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return aMallocSizeOf(this); } +/* virtual */ JSObject* +ServoStyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + #ifdef DEBUG void ServoStyleRule::List(FILE* out, int32_t aIndent) const diff --git a/layout/style/ServoStyleRule.h b/layout/style/ServoStyleRule.h index 03d8f4d43fe9..54ea09538ab9 100644 --- a/layout/style/ServoStyleRule.h +++ b/layout/style/ServoStyleRule.h @@ -66,6 +66,8 @@ public: already_AddRefed Clone() const final; nsIDOMCSSRule* GetDOMRule() final { return this; } size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; #endif diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index d3740f720ba0..97ebcc06ae8e 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1380,6 +1380,7 @@ StyleRule::StyleRule(nsCSSSelectorList* aSelector, mSelector(aSelector), mDeclaration(aDeclaration) { + SetIsNotDOMBinding(); NS_PRECONDITION(aDeclaration, "must have a declaration"); mDeclaration->SetOwningRule(this); @@ -1391,6 +1392,7 @@ StyleRule::StyleRule(const StyleRule& aCopy) mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr), mDeclaration(new Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); // rest is constructed lazily on existing data } @@ -1574,6 +1576,14 @@ StyleRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +StyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + } // namespace css } // namespace mozilla diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 392164957ac7..d654ce7ea237 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -354,6 +354,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: ~StyleRule(); diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 1530648e7104..05f416193cf6 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -57,10 +57,11 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule) NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION_0(Rule) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Rule) /* virtual */ void Rule::SetStyleSheet(StyleSheet* aSheet) @@ -179,6 +180,7 @@ ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, , mURLSpec(aURLSpec) , mMedia(aMedia) { + SetIsNotDOMBinding(); // XXXbz This is really silly.... the mMedia here will be replaced // with itself if we manage to load a sheet. Which should really // never fail nowadays, in sane cases. @@ -188,6 +190,7 @@ ImportRule::ImportRule(const ImportRule& aCopy) : Rule(aCopy), mURLSpec(aCopy.mURLSpec) { + SetIsNotDOMBinding(); // Whether or not an @import rule has a null sheet is a permanent // property of that @import rule, since it is null only if the target // sheet failed security checks. @@ -357,6 +360,14 @@ ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mChildSheet, because it is measured via CSSStyleSheetInner::mSheets } +/* virtual */ JSObject* +ImportRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber) : Rule(aLineNumber, aColumnNumber) { @@ -588,11 +599,13 @@ GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MediaRule::MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber) : GroupRule(aLineNumber, aColumnNumber) { + SetIsNotDOMBinding(); } MediaRule::MediaRule(const MediaRule& aCopy) : GroupRule(aCopy) { + SetIsNotDOMBinding(); if (aCopy.mMedia) { mMedia = aCopy.mMedia->Clone(); // XXXldb This doesn't really make sense. @@ -803,6 +816,14 @@ MediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +MediaRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + void MediaRule::AppendConditionText(nsAString& aOutput) { @@ -816,12 +837,14 @@ MediaRule::AppendConditionText(nsAString& aOutput) DocumentRule::DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber) : GroupRule(aLineNumber, aColumnNumber) { + SetIsNotDOMBinding(); } DocumentRule::DocumentRule(const DocumentRule& aCopy) : GroupRule(aCopy) , mURLs(new URL(*aCopy.mURLs)) { + SetIsNotDOMBinding(); } DocumentRule::~DocumentRule() @@ -1044,6 +1067,14 @@ DocumentRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +DocumentRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + void DocumentRule::AppendConditionText(nsAString& aCssText) { @@ -1079,6 +1110,7 @@ NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec, mPrefix(aPrefix), mURLSpec(aURLSpec) { + SetIsNotDOMBinding(); } NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) @@ -1086,6 +1118,7 @@ NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) mPrefix(aCopy.mPrefix), mURLSpec(aCopy.mURLSpec) { + SetIsNotDOMBinding(); } NameSpaceRule::~NameSpaceRule() @@ -1203,6 +1236,13 @@ NameSpaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mURLSpec } +/* virtual */ JSObject* +NameSpaceRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} } // namespace css } // namespace mozilla @@ -1666,6 +1706,13 @@ nsCSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mDecl } +/* virtual */ JSObject* +nsCSSFontFaceRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} // ----------------------------------- // nsCSSFontFeatureValuesRule @@ -1905,6 +1952,14 @@ nsCSSFontFeatureValuesRule::SizeOfIncludingThis( return aMallocSizeOf(this); } +/* virtual */ JSObject* +nsCSSFontFeatureValuesRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + // ------------------------------------------- // nsCSSKeyframeStyleDeclaration // @@ -1983,6 +2038,7 @@ nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy) , mKeys(aCopy.mKeys) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2192,6 +2248,13 @@ nsCSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mDOMDeclaration } +/* virtual */ JSObject* +nsCSSKeyframeRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} // ------------------------------------------- // nsCSSKeyframesRule @@ -2204,6 +2267,7 @@ nsCSSKeyframesRule::nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy) : GroupRule(aCopy), mName(aCopy.mName) { + SetIsNotDOMBinding(); } nsCSSKeyframesRule::~nsCSSKeyframesRule() @@ -2443,6 +2507,14 @@ nsCSSKeyframesRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +nsCSSKeyframesRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + // ------------------------------------------- // nsCSSPageStyleDeclaration // @@ -2520,6 +2592,7 @@ nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy) : Rule(aCopy) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2661,6 +2734,14 @@ nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return aMallocSizeOf(this); } +/* virtual */ JSObject* +nsCSSPageRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + namespace mozilla { CSSSupportsRule::CSSSupportsRule(bool aConditionMet, @@ -2670,6 +2751,7 @@ CSSSupportsRule::CSSSupportsRule(bool aConditionMet, , mUseGroup(aConditionMet) , mCondition(aCondition) { + SetIsNotDOMBinding(); } CSSSupportsRule::~CSSSupportsRule() @@ -2681,6 +2763,7 @@ CSSSupportsRule::CSSSupportsRule(const CSSSupportsRule& aCopy) mUseGroup(aCopy.mUseGroup), mCondition(aCopy.mCondition) { + SetIsNotDOMBinding(); } #ifdef DEBUG @@ -2816,6 +2899,14 @@ CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +CSSSupportsRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + } // namespace mozilla // ------------------------------------------- @@ -2827,6 +2918,7 @@ nsCSSCounterStyleRule::nsCSSCounterStyleRule(const nsCSSCounterStyleRule& aCopy) , mName(aCopy.mName) , mGeneration(aCopy.mGeneration) { + SetIsNotDOMBinding(); for (size_t i = 0; i < ArrayLength(mValues); ++i) { mValues[i] = aCopy.mValues[i]; } @@ -3275,3 +3367,11 @@ nsCSSCounterStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { return aMallocSizeOf(this); } + +/* virtual */ JSObject* +nsCSSCounterStyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 9dc792d8f300..e2dcfcea5eaa 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -95,6 +95,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: void AppendConditionText(nsAString& aOutput); @@ -169,6 +172,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: void AppendConditionText(nsAString& aOutput); @@ -235,11 +241,17 @@ class nsCSSFontFaceRule final : public mozilla::css::Rule, { public: nsCSSFontFaceRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : mozilla::css::Rule(aLineNumber, aColumnNumber) {} + : mozilla::css::Rule(aLineNumber, aColumnNumber) + { + SetIsNotDOMBinding(); + } nsCSSFontFaceRule(const nsCSSFontFaceRule& aCopy) // copy everything except our reference count - : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) {} + : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) + { + SetIsNotDOMBinding(); + } NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsCSSFontFaceRule, @@ -264,6 +276,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + void GetDescriptors(mozilla::CSSFontFaceDescriptors& aDescriptors) const { aDescriptors = mDecl.mDescriptors; } @@ -300,13 +315,19 @@ class nsCSSFontFeatureValuesRule final : public mozilla::css::Rule, { public: nsCSSFontFeatureValuesRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : mozilla::css::Rule(aLineNumber, aColumnNumber) {} + : mozilla::css::Rule(aLineNumber, aColumnNumber) + { + SetIsNotDOMBinding(); + } nsCSSFontFeatureValuesRule(const nsCSSFontFeatureValuesRule& aCopy) // copy everything except our reference count : mozilla::css::Rule(aCopy), mFamilyList(aCopy.mFamilyList), - mFeatureValues(aCopy.mFeatureValues) {} + mFeatureValues(aCopy.mFeatureValues) + { + SetIsNotDOMBinding(); + } NS_DECL_ISUPPORTS_INHERITED @@ -337,6 +358,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: ~nsCSSFontFeatureValuesRule() {} @@ -384,6 +408,7 @@ public: , mKeys(mozilla::Move(aKeys)) , mDeclaration(mozilla::Move(aDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -414,6 +439,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + void DoGetKeyText(nsAString &aKeyText) const; private: @@ -432,6 +460,7 @@ public: : mozilla::css::GroupRule(aLineNumber, aColumnNumber) , mName(aName) { + SetIsNotDOMBinding(); } private: nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy); @@ -464,6 +493,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: uint32_t FindRuleIndexForKey(const nsAString& aKey); @@ -507,6 +539,7 @@ public: : mozilla::css::Rule(aLineNumber, aColumnNumber) , mDeclaration(aDeclaration) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -535,6 +568,10 @@ public: void ChangeDeclaration(mozilla::css::Declaration* aDeclaration); virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: RefPtr mDeclaration; // lazily created when needed: @@ -543,8 +580,8 @@ private: namespace mozilla { -class CSSSupportsRule : public css::GroupRule, - public nsIDOMCSSSupportsRule +class CSSSupportsRule final : public css::GroupRule, + public nsIDOMCSSSupportsRule { public: CSSSupportsRule(bool aConditionMet, const nsString& aCondition, @@ -580,6 +617,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: virtual ~CSSSupportsRule(); @@ -599,6 +639,7 @@ public: , mName(aName) , mGeneration(0) { + SetIsNotDOMBinding(); } private: @@ -646,6 +687,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: typedef NS_STDCALL_FUNCPROTO(nsresult, Getter, nsCSSCounterStyleRule, GetSymbols, (nsAString&)); From 1bde6ae3c2d7f96f43127c365002dbf6271f4333 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:02 -0500 Subject: [PATCH 24/54] Bug 851892 part 5. Get rid of DOMCSSStyleRule. r=heycam --- layout/style/StyleRule.cpp | 277 +++++++++---------------------------- layout/style/StyleRule.h | 23 +-- 2 files changed, 76 insertions(+), 224 deletions(-) diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 97ebcc06ae8e..1bffb6e5d12b 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -20,7 +20,6 @@ #include "nsIAtom.h" #include "nsString.h" #include "nsStyleUtil.h" -#include "nsICSSStyleRuleDOMWrapper.h" #include "nsDOMCSSDeclaration.h" #include "nsNameSpaceManager.h" #include "nsXMLNameSpaceMap.h" @@ -1047,30 +1046,26 @@ nsCSSSelectorList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) cons // -------------------------------------------------------- -namespace mozilla { -namespace css { -class DOMCSSStyleRule; -} // namespace css -} // namespace mozilla - class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration { protected: + // Needs to be protected so we can use NS_IMPL_ADDREF_USING_AGGREGATOR. virtual ~DOMCSSDeclarationImpl(void); + // But we need to allow UniquePtr to delete us. + friend class mozilla::DefaultDelete; + public: explicit DOMCSSDeclarationImpl(css::StyleRule *aRule); NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override; - void DropReference(void); virtual DeclarationBlock* GetCSSDeclaration(Operation aOperation) override; virtual nsresult SetCSSDeclaration(DeclarationBlock* aDecl) override; virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override; virtual nsIDocument* DocToUpdate() override; - // Override |AddRef| and |Release| for being a member of - // |DOMCSSStyleRule|. Also, we need to forward QI for cycle - // collection things to DOMCSSStyleRule. + // Override |AddRef| and |Release| for being owned by StyleRule. Also, we + // need to forward QI for cycle collection things to StyleRule. NS_DECL_ISUPPORTS_INHERITED virtual nsINode *GetParentObject() override @@ -1078,55 +1073,12 @@ public: return mRule ? mRule->GetDocument() : nullptr; } - friend class css::DOMCSSStyleRule; - protected: - // This reference is not reference-counted. The rule object tells us - // when it's about to go away. + // This reference is not reference-counted. The rule object owns us and we go + // away when it does. css::StyleRule *mRule; - - inline css::DOMCSSStyleRule* DomRule(); - -private: - // NOT TO BE IMPLEMENTED - // This object cannot be allocated on its own. It must be a member of - // DOMCSSStyleRule. - void* operator new(size_t size) CPP_THROW_NEW; }; -namespace mozilla { -namespace css { - -class DOMCSSStyleRule : public nsICSSStyleRuleDOMWrapper -{ -public: - explicit DOMCSSStyleRule(StyleRule *aRule); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMCSSStyleRule) - NS_DECL_NSIDOMCSSRULE - NS_DECL_NSIDOMCSSSTYLERULE - - // nsICSSStyleRuleDOMWrapper - NS_IMETHOD GetCSSStyleRule(StyleRule **aResult) override; - - DOMCSSDeclarationImpl* DOMDeclaration() { return &mDOMDeclaration; } - - friend class ::DOMCSSDeclarationImpl; - -protected: - virtual ~DOMCSSStyleRule(); - - DOMCSSDeclarationImpl mDOMDeclaration; - - StyleRule* Rule() { - return mDOMDeclaration.mRule; - } -}; - -} // namespace css -} // namespace mozilla - DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(css::StyleRule *aRule) : mRule(aRule) { @@ -1134,50 +1086,32 @@ DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(css::StyleRule *aRule) DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl(void) { - NS_ASSERTION(!mRule, "DropReference not called."); } -inline css::DOMCSSStyleRule* DOMCSSDeclarationImpl::DomRule() -{ - return reinterpret_cast - (reinterpret_cast(this) - - offsetof(css::DOMCSSStyleRule, mDOMDeclaration)); -} - -NS_IMPL_ADDREF_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule()) -NS_IMPL_RELEASE_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule()) +NS_IMPL_ADDREF_USING_AGGREGATOR(DOMCSSDeclarationImpl, mRule) +NS_IMPL_RELEASE_USING_AGGREGATOR(DOMCSSDeclarationImpl, mRule) NS_INTERFACE_MAP_BEGIN(DOMCSSDeclarationImpl) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - // We forward the cycle collection interfaces to DomRule(), which is - // never null (in fact, we're part of that object!) + // We forward the cycle collection interfaces to mRule, which is + // never null. if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) || aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { - return DomRule()->QueryInterface(aIID, aInstancePtr); + return mRule->QueryInterface(aIID, aInstancePtr); } else NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration) -void -DOMCSSDeclarationImpl::DropReference(void) -{ - mRule = nullptr; -} - DeclarationBlock* DOMCSSDeclarationImpl::GetCSSDeclaration(Operation aOperation) { - if (mRule) { - if (aOperation != eOperation_Read) { - RefPtr sheet = mRule->GetStyleSheet(); - if (sheet) { - sheet->WillDirty(); - } + if (aOperation != eOperation_Read) { + RefPtr sheet = mRule->GetStyleSheet(); + if (sheet) { + sheet->WillDirty(); } - return mRule->GetDeclaration(); - } else { - return nullptr; } + return mRule->GetDeclaration(); } void @@ -1191,11 +1125,6 @@ DOMCSSDeclarationImpl::GetParentRule(nsIDOMCSSRule **aParent) { NS_ENSURE_ARG_POINTER(aParent); - if (!mRule) { - *aParent = nullptr; - return NS_OK; - } - NS_IF_ADDREF(*aParent = mRule->GetDOMRule()); return NS_OK; } @@ -1232,50 +1161,13 @@ DOMCSSDeclarationImpl::DocToUpdate() return nullptr; } +// -- StyleRule ------------------------------------ + namespace mozilla { namespace css { -DOMCSSStyleRule::DOMCSSStyleRule(StyleRule* aRule) - : mDOMDeclaration(aRule) -{ -} - -DOMCSSStyleRule::~DOMCSSStyleRule() -{ -} - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMCSSStyleRule) - NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY(nsISupports) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) -NS_INTERFACE_MAP_END - -NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMCSSStyleRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMCSSStyleRule) - -NS_IMPL_CYCLE_COLLECTION_CLASS(DOMCSSStyleRule) - -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMCSSStyleRule) - // Trace the wrapper for our declaration. This just expands out - // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use - // directly because the wrapper is on the declaration, not on us. - tmp->DOMDeclaration()->TraceWrapper(aCallbacks, aClosure); -NS_IMPL_CYCLE_COLLECTION_TRACE_END - -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMCSSStyleRule) - // Unlink the wrapper for our declaraton. This just expands out - // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use - // directly because the wrapper is on the declaration, not on us. - tmp->DOMDeclaration()->ReleaseWrapper(static_cast(p)); -NS_IMPL_CYCLE_COLLECTION_UNLINK_END - -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMCSSStyleRule) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - NS_IMETHODIMP -DOMCSSStyleRule::GetType(uint16_t* aType) +StyleRule::GetType(uint16_t* aType) { *aType = nsIDOMCSSRule::STYLE_RULE; @@ -1283,95 +1175,42 @@ DOMCSSStyleRule::GetType(uint16_t* aType) } NS_IMETHODIMP -DOMCSSStyleRule::GetCssText(nsAString& aCssText) +StyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) { - if (!Rule()) { - aCssText.Truncate(); - } else { - Rule()->GetCssText(aCssText); - } - return NS_OK; + return Rule::GetParentStyleSheet(aSheet); } NS_IMETHODIMP -DOMCSSStyleRule::SetCssText(const nsAString& aCssText) +StyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) { - if (Rule()) { - Rule()->SetCssText(aCssText); - } - return NS_OK; -} - -NS_IMETHODIMP -DOMCSSStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - if (!Rule()) { - *aSheet = nullptr; - return NS_OK; - } - return Rule()->GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -DOMCSSStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - if (!Rule()) { - *aParentRule = nullptr; - return NS_OK; - } - return Rule()->GetParentRule(aParentRule); + return Rule::GetParentRule(aParentRule); } css::Rule* -DOMCSSStyleRule::GetCSSRule() +StyleRule::GetCSSRule() { - return Rule(); + return this; } NS_IMETHODIMP -DOMCSSStyleRule::GetSelectorText(nsAString& aSelectorText) +StyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { - if (!Rule()) { - aSelectorText.Truncate(); - } else { - Rule()->GetSelectorText(aSelectorText); + if (!mDOMDeclaration) { + mDOMDeclaration.reset(new DOMCSSDeclarationImpl(this)); } - return NS_OK; -} - -NS_IMETHODIMP -DOMCSSStyleRule::SetSelectorText(const nsAString& aSelectorText) -{ - if (Rule()) { - Rule()->SetSelectorText(aSelectorText); - } - return NS_OK; -} - -NS_IMETHODIMP -DOMCSSStyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) -{ - *aStyle = &mDOMDeclaration; + *aStyle = mDOMDeclaration.get(); NS_ADDREF(*aStyle); return NS_OK; } NS_IMETHODIMP -DOMCSSStyleRule::GetCSSStyleRule(StyleRule **aResult) +StyleRule::GetCSSStyleRule(StyleRule **aResult) { - *aResult = Rule(); - NS_IF_ADDREF(*aResult); + *aResult = this; + NS_ADDREF(*aResult); return NS_OK; } -} // namespace css -} // namespace mozilla - -// -- StyleRule ------------------------------------ - -namespace mozilla { -namespace css { - StyleRule::StyleRule(nsCSSSelectorList* aSelector, Declaration* aDeclaration, uint32_t aLineNumber, @@ -1406,11 +1245,6 @@ StyleRule::~StyleRule() void StyleRule::DropReferences() { - if (mDOMRule) { - mDOMRule->DOMDeclaration()->DropReference(); - mDOMRule = nullptr; - } - if (mDeclaration) { mDeclaration->SetOwningRule(nullptr); mDeclaration = nullptr; @@ -1425,17 +1259,35 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) return NS_OK; } else + NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(Rule) NS_IMPL_ADDREF_INHERITED(StyleRule, Rule) NS_IMPL_RELEASE_INHERITED(StyleRule, Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(StyleRule) +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(StyleRule, Rule) + // Trace the wrapper for our declaration. This just expands out + // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use + // directly because the wrapper is on the declaration, not on us. + if (tmp->mDOMDeclaration) { + tmp->mDOMDeclaration->TraceWrapper(aCallbacks, aClosure); + } +NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(StyleRule, Rule) + // Unlink the wrapper for our declaraton. This just expands out + // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use + // directly because the wrapper is on the declaration, not on us. + if (tmp->mDOMDeclaration) { + tmp->mDOMDeclaration->ReleaseWrapper(static_cast(p)); + } tmp->DropReferences(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(StyleRule, Rule) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeclaration, mDOMRule) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeclaration) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END /* virtual */ int32_t @@ -1454,16 +1306,7 @@ StyleRule::Clone() const /* virtual */ nsIDOMCSSRule* StyleRule::GetDOMRule() { - if (!mDOMRule) { - if (!GetStyleSheet()) { - // Inline style rules aren't supposed to have a DOM rule object, only - // a declaration. But if we do have one already, from a style sheet - // rule that used to be in a document, we still want to return it. - return nullptr; - } - mDOMRule = new DOMCSSStyleRule(this); - } - return mDOMRule; + return this; } void @@ -1520,7 +1363,7 @@ StyleRule::List(FILE* out, int32_t aIndent) const } #endif -void +NS_IMETHODIMP StyleRule::GetCssText(nsAString& aCssText) { if (mSelector) { @@ -1537,29 +1380,33 @@ StyleRule::GetCssText(nsAString& aCssText) } aCssText.Append(char16_t(' ')); aCssText.Append(char16_t('}')); + return NS_OK; } -void +NS_IMETHODIMP StyleRule::SetCssText(const nsAString& aCssText) { // XXX TBI - need to re-parse rule & declaration + return NS_OK; } -void +NS_IMETHODIMP StyleRule::GetSelectorText(nsAString& aSelectorText) { if (mSelector) mSelector->ToString(aSelectorText, GetStyleSheet()); else aSelectorText.Truncate(); + return NS_OK; } -void +NS_IMETHODIMP StyleRule::SetSelectorText(const nsAString& aSelectorText) { // XXX TBI - get a parser and re-parse the selectors, // XXX then need to re-compute the cascade // XXX and dirty sheet + return NS_OK; } /* virtual */ size_t diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index d654ce7ea237..dec28fc624e1 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -13,12 +13,14 @@ #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/UniquePtr.h" #include "mozilla/css/Rule.h" #include "nsString.h" #include "nsCOMPtr.h" #include "nsCSSPseudoElements.h" #include "nsIStyleRule.h" +#include "nsICSSStyleRuleDOMWrapper.h" class nsIAtom; struct nsCSSSelectorList; @@ -302,13 +304,15 @@ private: { 0x464bab7a, 0x2fce, 0x4f30, \ { 0xab, 0x44, 0xb7, 0xa5, 0xf3, 0xaa, 0xe5, 0x7d } } +class DOMCSSDeclarationImpl; + namespace mozilla { namespace css { class Declaration; -class DOMCSSStyleRule; class StyleRule final : public Rule + , public nsICSSStyleRuleDOMWrapper { public: StyleRule(nsCSSSelectorList* aSelector, @@ -321,7 +325,12 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_RULE_IMPL_CID) NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(StyleRule, Rule) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(StyleRule, Rule) + NS_DECL_NSIDOMCSSRULE + NS_DECL_NSIDOMCSSSTYLERULE + + // nsICSSStyleRuleDOMWrapper + NS_IMETHOD GetCSSStyleRule(StyleRule **aResult) override; // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -330,12 +339,6 @@ public: void SetDeclaration(Declaration* aDecl); - // hooks for DOM rule - void GetCssText(nsAString& aCssText); - void SetCssText(const nsAString& aCssText); - void GetSelectorText(nsAString& aSelectorText); - void SetSelectorText(const nsAString& aSelectorText); - virtual int32_t GetType() const override; CSSStyleSheet* GetStyleSheet() const @@ -367,7 +370,9 @@ private: private: nsCSSSelectorList* mSelector; // null for style attribute RefPtr mDeclaration; - RefPtr mDOMRule; + + // We own it, and it aggregates its refcount with us. + UniquePtr mDOMDeclaration; private: StyleRule& operator=(const StyleRule& aCopy) = delete; From f7a5133a06e8785cfb24f95e46f02bb7de2a838a Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:02 -0500 Subject: [PATCH 25/54] Bug 851892 part 6. Make css::Rule inherit from nsIDOMCSSRule. r=heycam --- dom/base/nsDOMClassInfo.cpp | 11 +++++++++++ .../css/nsIDOMCSSCounterStyleRule.idl | 4 ++-- dom/interfaces/css/nsIDOMCSSFontFaceRule.idl | 6 ++++-- .../css/nsIDOMCSSFontFeatureValuesRule.idl | 4 ++-- dom/interfaces/css/nsIDOMCSSGroupingRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSImportRule.idl | 7 +++++-- dom/interfaces/css/nsIDOMCSSKeyframeRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSKeyframesRule.idl | 7 +++++-- dom/interfaces/css/nsIDOMCSSMediaRule.idl | 2 ++ dom/interfaces/css/nsIDOMCSSPageRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSStyleRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSUnknownRule.idl | 4 ++-- layout/inspector/inCSSValueSearch.cpp | 1 + layout/style/NameSpaceRule.h | 3 +-- layout/style/Rule.h | 9 +++++---- layout/style/ServoStyleRule.cpp | 1 - layout/style/StyleRule.cpp | 1 - layout/style/nsCSSRules.cpp | 18 ++++-------------- 18 files changed, 60 insertions(+), 42 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index e86f1ff338db..c6ce77fa91c6 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -525,14 +525,17 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSStyleRule, nsIDOMCSSStyleRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSImportRule, nsIDOMCSSImportRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSImportRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_END @@ -574,14 +577,17 @@ nsDOMClassInfo::Init() #endif DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMozDocumentRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSSupportsRule, nsIDOMCSSSupportsRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSSupportsRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule) DOM_CLASSINFO_MAP_END @@ -616,22 +622,27 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSKeyframeRule, nsIDOMCSSKeyframeRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframeRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSKeyframesRule, nsIDOMCSSKeyframesRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframesRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSCounterStyleRule, nsIDOMCSSCounterStyleRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSPageRule, nsIDOMCSSPageRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSPageRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) DOM_CLASSINFO_MAP_END diff --git a/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl b/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl index 0831b2238d87..412ddfffcc9d 100644 --- a/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl +++ b/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl @@ -4,10 +4,10 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" [scriptable, uuid(9b5e48ce-d84c-4e31-aff5-34e9f4141313)] -interface nsIDOMCSSCounterStyleRule : nsIDOMCSSRule +interface nsIDOMCSSCounterStyleRule : nsISupports { attribute DOMString name; attribute DOMString system; diff --git a/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl b/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl index 18ca669f43f1..06a58bb834c0 100644 --- a/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl +++ b/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl @@ -3,10 +3,12 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(db971017-fe0c-4529-972c-8217f2fee217)] -interface nsIDOMCSSFontFaceRule : nsIDOMCSSRule +interface nsIDOMCSSFontFaceRule : nsISupports { readonly attribute nsIDOMCSSStyleDeclaration style; }; diff --git a/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl b/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl index 1b04dde86f5e..1e782c07db6e 100644 --- a/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl +++ b/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl @@ -3,10 +3,10 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" [scriptable, uuid(a343d27f-1da6-4fc3-9355-d4ca434f958e)] -interface nsIDOMCSSFontFeatureValuesRule : nsIDOMCSSRule +interface nsIDOMCSSFontFeatureValuesRule : nsISupports { attribute DOMString fontFamily; // raises(DOMException) on setting diff --git a/dom/interfaces/css/nsIDOMCSSGroupingRule.idl b/dom/interfaces/css/nsIDOMCSSGroupingRule.idl index 80f072d160cb..593da61524c3 100644 --- a/dom/interfaces/css/nsIDOMCSSGroupingRule.idl +++ b/dom/interfaces/css/nsIDOMCSSGroupingRule.idl @@ -3,13 +3,15 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSRuleList; /** * Interface for at-rules that have child rules in the CSS OM. */ [scriptable, uuid(a0e3324a-f911-4baf-9591-5322c76cbb0d)] -interface nsIDOMCSSGroupingRule : nsIDOMCSSRule +interface nsIDOMCSSGroupingRule : nsISupports { readonly attribute nsIDOMCSSRuleList cssRules; diff --git a/dom/interfaces/css/nsIDOMCSSImportRule.idl b/dom/interfaces/css/nsIDOMCSSImportRule.idl index 0909d92212ba..fc96977d9188 100644 --- a/dom/interfaces/css/nsIDOMCSSImportRule.idl +++ b/dom/interfaces/css/nsIDOMCSSImportRule.idl @@ -3,10 +3,13 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMMediaList; +interface nsIDOMCSSStyleSheet; [scriptable, uuid(d3b2b914-01ef-4663-beda-a6475a26f491)] -interface nsIDOMCSSImportRule : nsIDOMCSSRule +interface nsIDOMCSSImportRule : nsISupports { readonly attribute DOMString href; readonly attribute nsIDOMMediaList media; diff --git a/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl b/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl index 46e7ffbb1004..0027be2d2919 100644 --- a/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl +++ b/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl @@ -3,10 +3,12 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(a281a8b4-eaa2-49a8-8b97-acc2814a57c9)] -interface nsIDOMCSSKeyframeRule : nsIDOMCSSRule +interface nsIDOMCSSKeyframeRule : nsISupports { attribute DOMString keyText; readonly attribute nsIDOMCSSStyleDeclaration style; diff --git a/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl b/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl index acbb657e47d6..0e2d3bc4f2dd 100644 --- a/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl +++ b/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl @@ -3,10 +3,13 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSRuleList; +interface nsIDOMCSSKeyframeRule; [scriptable, uuid(400f4b70-ad0a-4047-aba4-ee8019f6b907)] -interface nsIDOMCSSKeyframesRule : nsIDOMCSSRule +interface nsIDOMCSSKeyframesRule : nsISupports { attribute DOMString name; readonly attribute nsIDOMCSSRuleList cssRules; diff --git a/dom/interfaces/css/nsIDOMCSSMediaRule.idl b/dom/interfaces/css/nsIDOMCSSMediaRule.idl index 9be4ba143a0c..e292e2485fc3 100644 --- a/dom/interfaces/css/nsIDOMCSSMediaRule.idl +++ b/dom/interfaces/css/nsIDOMCSSMediaRule.idl @@ -5,6 +5,8 @@ #include "nsIDOMCSSConditionRule.idl" +interface nsIDOMMediaList; + /** * Interface for @media rules in the CSS OM. */ diff --git a/dom/interfaces/css/nsIDOMCSSPageRule.idl b/dom/interfaces/css/nsIDOMCSSPageRule.idl index e586a0dbb3fc..a7efb5044add 100644 --- a/dom/interfaces/css/nsIDOMCSSPageRule.idl +++ b/dom/interfaces/css/nsIDOMCSSPageRule.idl @@ -3,10 +3,12 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(c119072b-7d2f-4aeb-a90d-e2d6b606c32a)] -interface nsIDOMCSSPageRule : nsIDOMCSSRule +interface nsIDOMCSSPageRule : nsISupports { //attribute DOMString selectorText; // raises(DOMException) on setting diff --git a/dom/interfaces/css/nsIDOMCSSStyleRule.idl b/dom/interfaces/css/nsIDOMCSSStyleRule.idl index d94d22d93e0d..39b3efaf0cb3 100644 --- a/dom/interfaces/css/nsIDOMCSSStyleRule.idl +++ b/dom/interfaces/css/nsIDOMCSSStyleRule.idl @@ -3,10 +3,12 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(b5e9af48-a7c2-4f88-aae3-58307af4b5a5)] -interface nsIDOMCSSStyleRule : nsIDOMCSSRule +interface nsIDOMCSSStyleRule : nsISupports { attribute DOMString selectorText; // raises(DOMException) on setting diff --git a/dom/interfaces/css/nsIDOMCSSUnknownRule.idl b/dom/interfaces/css/nsIDOMCSSUnknownRule.idl index 6dfb5ec69a2e..87546d63b51b 100644 --- a/dom/interfaces/css/nsIDOMCSSUnknownRule.idl +++ b/dom/interfaces/css/nsIDOMCSSUnknownRule.idl @@ -3,9 +3,9 @@ * 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 "nsIDOMCSSRule.idl" +#include "nsISupports.idl" [scriptable, uuid(98f4c27b-fb35-4355-8fd9-546c4697d71a)] -interface nsIDOMCSSUnknownRule : nsIDOMCSSRule +interface nsIDOMCSSUnknownRule : nsISupports { }; diff --git a/layout/inspector/inCSSValueSearch.cpp b/layout/inspector/inCSSValueSearch.cpp index ecde0999381c..5897e1b54265 100644 --- a/layout/inspector/inCSSValueSearch.cpp +++ b/layout/inspector/inCSSValueSearch.cpp @@ -18,6 +18,7 @@ #include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSSupportsRule.h" +#include "nsIDOMCSSRule.h" #include "nsIURI.h" #include "nsIDocument.h" #include "nsNetUtil.h" diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 406938650ab7..c69d996d0cf4 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -24,8 +24,7 @@ class nsIAtom; namespace mozilla { namespace css { -class NameSpaceRule final : public Rule, - public nsIDOMCSSRule +class NameSpaceRule final : public Rule { public: NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec, diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 8d9c256d0729..3f74427e8268 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -30,7 +30,7 @@ class GroupRule; DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ virtual nsIDOMCSSRule* GetDOMRule() override; -class Rule : public nsISupports +class Rule : public nsIDOMCSSRule , public nsWrapperCache { protected: @@ -116,9 +116,10 @@ public: virtual nsIDOMCSSRule* GetDOMRule() = 0; // to implement methods on nsIDOMCSSRule - nsresult GetParentRule(nsIDOMCSSRule** aParentRule); - nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet); - Rule* GetCSSRule(); + NS_IMETHOD GetParentRule(nsIDOMCSSRule** aParentRule) override; + NS_IMETHOD GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) override; + virtual Rule* GetCSSRule() override; + using nsIDOMCSSRule::GetType; // This is pure virtual because all of Rule's data members are non-owning and // thus measured elsewhere. diff --git a/layout/style/ServoStyleRule.cpp b/layout/style/ServoStyleRule.cpp index 81a824eacb8d..110b734d6de4 100644 --- a/layout/style/ServoStyleRule.cpp +++ b/layout/style/ServoStyleRule.cpp @@ -110,7 +110,6 @@ ServoStyleRule::ServoStyleRule(already_AddRefed aRawRule) // QueryInterface implementation for ServoStyleRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(css::Rule) diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 1bffb6e5d12b..ecfb318d17b7 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1261,7 +1261,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) else NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(Rule) diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 05f416193cf6..aabf74e54a38 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -58,6 +58,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END @@ -72,7 +73,7 @@ Rule::SetStyleSheet(StyleSheet* aSheet) mSheet = aSheet; } -nsresult +NS_IMETHODIMP Rule::GetParentRule(nsIDOMCSSRule** aParentRule) { if (mParentRule) { @@ -83,7 +84,7 @@ Rule::GetParentRule(nsIDOMCSSRule** aParentRule) return NS_OK; } -nsresult +NS_IMETHODIMP Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) { NS_ENSURE_ARG_POINTER(aSheet); @@ -92,7 +93,7 @@ Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) return NS_OK; } -css::Rule* +/* virtual */ css::Rule* Rule::GetCSSRule() { return this; @@ -216,7 +217,6 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(ImportRule, Rule, mMedia, mChildSheet) // QueryInterface implementation for ImportRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) NS_INTERFACE_MAP_END_INHERITING(Rule) @@ -625,7 +625,6 @@ NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule) // QueryInterface implementation for MediaRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule) @@ -856,7 +855,6 @@ NS_IMPL_RELEASE_INHERITED(DocumentRule, GroupRule) // QueryInterface implementation for DocumentRule NS_INTERFACE_MAP_BEGIN(DocumentRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule) @@ -1136,7 +1134,6 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule) return NS_OK; } else - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) @@ -1581,7 +1578,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSFontFaceRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) @@ -1731,7 +1727,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSFontFeatureValuesRule NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) @@ -2077,7 +2072,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSKeyframeRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframeRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) @@ -2286,7 +2280,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule) // QueryInterface implementation for nsCSSKeyframesRule NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframesRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframesRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) @@ -2631,7 +2624,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSPageRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) @@ -2809,7 +2801,6 @@ NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::GroupRule) // QueryInterface implementation for CSSSupportsRule NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule) @@ -2947,7 +2938,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSCounterStyleRule NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCounterStyleRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) From 52920d72fc5f2910596a9618c641615239c78fa7 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:02 -0500 Subject: [PATCH 26/54] Bug 851892 part 7. Push the nsIDOMCSSRule implementation up to css::Rule. r=heycam --- layout/style/GroupRule.h | 2 +- layout/style/ImportRule.h | 8 +- layout/style/NameSpaceRule.h | 8 +- layout/style/Rule.h | 13 +- layout/style/ServoStyleRule.cpp | 37 +-- layout/style/ServoStyleRule.h | 6 +- layout/style/StyleRule.cpp | 38 +-- layout/style/StyleRule.h | 6 +- layout/style/nsCSSRules.cpp | 449 +++++++------------------------- layout/style/nsCSSRules.h | 79 +++--- 10 files changed, 180 insertions(+), 466 deletions(-) diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index 63c6385195da..fa9f697e0da7 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -82,7 +82,7 @@ public: protected: // to help implement nsIDOMCSSRule - void AppendRulesToCssText(nsAString& aCssText); + void AppendRulesToCssText(nsAString& aCssText) const; // to implement common methods on nsIDOMCSSMediaRule and // nsIDOMCSSMozDocumentRule diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index 3ad8246c94ba..12e8e148c642 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -46,6 +46,7 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; void SetSheet(CSSStyleSheet*); @@ -55,12 +56,13 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSImportRule interface NS_DECL_NSIDOMCSSIMPORTRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + private: nsString mURLSpec; RefPtr mMedia; diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index c69d996d0cf4..c58cec40a544 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -44,21 +44,23 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; nsIAtom* GetPrefix() const { return mPrefix; } void GetURLSpec(nsString& aURLSpec) const { aURLSpec = mURLSpec; } + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - private: nsCOMPtr mPrefix; nsString mURLSpec; diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 3f74427e8268..0e88397df470 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -57,6 +57,9 @@ public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Rule) + // nsIDOMCSSRule interface + NS_DECL_NSIDOMCSSRULE + #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; #endif @@ -115,17 +118,15 @@ public: // supposed to have a DOM rule representation (and our code wouldn't work). virtual nsIDOMCSSRule* GetDOMRule() = 0; - // to implement methods on nsIDOMCSSRule - NS_IMETHOD GetParentRule(nsIDOMCSSRule** aParentRule) override; - NS_IMETHOD GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) override; - virtual Rule* GetCSSRule() override; - using nsIDOMCSSRule::GetType; - // This is pure virtual because all of Rule's data members are non-owning and // thus measured elsewhere. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const MOZ_MUST_OVERRIDE = 0; + // WebIDL interface, aka helpers for nsIDOMCSSRule implementation. + virtual uint16_t Type() const = 0; + virtual void GetCssTextImpl(nsAString& aCssText) const = 0; + protected: // This is sometimes null (e.g., for style attributes). StyleSheet* mSheet; diff --git a/layout/style/ServoStyleRule.cpp b/layout/style/ServoStyleRule.cpp index 110b734d6de4..6df2b07b2687 100644 --- a/layout/style/ServoStyleRule.cpp +++ b/layout/style/ServoStyleRule.cpp @@ -175,43 +175,16 @@ ServoStyleRule::List(FILE* out, int32_t aIndent) const /* CSSRule implementation */ -NS_IMETHODIMP -ServoStyleRule::GetType(uint16_t* aType) +uint16_t +ServoStyleRule::Type() const { - *aType = nsIDOMCSSRule::STYLE_RULE; - return NS_OK; + return nsIDOMCSSRule::STYLE_RULE; } -NS_IMETHODIMP -ServoStyleRule::GetCssText(nsAString& aCssText) +void +ServoStyleRule::GetCssTextImpl(nsAString& aCssText) const { Servo_StyleRule_GetCssText(mRawRule, &aCssText); - return NS_OK; -} - -NS_IMETHODIMP -ServoStyleRule::SetCssText(const nsAString& aCssText) -{ - return NS_OK; -} - -NS_IMETHODIMP -ServoStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return css::Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -ServoStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - *aParentRule = nullptr; - return NS_ERROR_NOT_IMPLEMENTED; -} - -css::Rule* -ServoStyleRule::GetCSSRule() -{ - return this; } /* CSSStyleRule implementation */ diff --git a/layout/style/ServoStyleRule.h b/layout/style/ServoStyleRule.h index 54ea09538ab9..af39b96371bd 100644 --- a/layout/style/ServoStyleRule.h +++ b/layout/style/ServoStyleRule.h @@ -56,13 +56,17 @@ public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ServoStyleRule, css::Rule) - NS_DECL_NSIDOMCSSRULE NS_DECL_NSIDOMCSSSTYLERULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + RawServoStyleRule* Raw() const { return mRawRule; } // Methods of mozilla::css::Rule int32_t GetType() const final { return css::Rule::STYLE_RULE; } + using Rule::GetType; already_AddRefed Clone() const final; nsIDOMCSSRule* GetDOMRule() final { return this; } size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index ecfb318d17b7..88d934c3efc7 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1166,30 +1166,10 @@ DOMCSSDeclarationImpl::DocToUpdate() namespace mozilla { namespace css { -NS_IMETHODIMP -StyleRule::GetType(uint16_t* aType) +uint16_t +StyleRule::Type() const { - *aType = nsIDOMCSSRule::STYLE_RULE; - - return NS_OK; -} - -NS_IMETHODIMP -StyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -StyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -StyleRule::GetCSSRule() -{ - return this; + return nsIDOMCSSRule::STYLE_RULE; } NS_IMETHODIMP @@ -1362,8 +1342,8 @@ StyleRule::List(FILE* out, int32_t aIndent) const } #endif -NS_IMETHODIMP -StyleRule::GetCssText(nsAString& aCssText) +void +StyleRule::GetCssTextImpl(nsAString& aCssText) const { if (mSelector) { mSelector->ToString(aCssText, GetStyleSheet()); @@ -1379,14 +1359,6 @@ StyleRule::GetCssText(nsAString& aCssText) } aCssText.Append(char16_t(' ')); aCssText.Append(char16_t('}')); - return NS_OK; -} - -NS_IMETHODIMP -StyleRule::SetCssText(const nsAString& aCssText) -{ - // XXX TBI - need to re-parse rule & declaration - return NS_OK; } NS_IMETHODIMP diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index dec28fc624e1..51fbab509a48 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -326,12 +326,15 @@ public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(StyleRule, Rule) - NS_DECL_NSIDOMCSSRULE NS_DECL_NSIDOMCSSSTYLERULE // nsICSSStyleRuleDOMWrapper NS_IMETHOD GetCSSStyleRule(StyleRule **aResult) override; + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -340,6 +343,7 @@ public: void SetDeclaration(Declaration* aDecl); virtual int32_t GetType() const override; + using Rule::GetType; CSSStyleSheet* GetStyleSheet() const { diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index aabf74e54a38..17f3f0c77a56 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -99,6 +99,28 @@ Rule::GetCSSRule() return this; } +NS_IMETHODIMP +Rule::GetType(uint16_t* aType) +{ + *aType = Type(); + return NS_OK; +} + +NS_IMETHODIMP +Rule::SetCssText(const nsAString& aCssText) +{ + // We used to throw for some rule types, but not all. Specifically, we did + // not throw for StyleRule. Let's just always not throw. + return NS_OK; +} + +NS_IMETHODIMP +Rule::GetCssText(nsAString& aCssText) +{ + GetCssTextImpl(aCssText); + return NS_OK; +} + // ------------------------------- // Style Rule List for group rules // @@ -271,16 +293,14 @@ ImportRule::SetSheet(CSSStyleSheet* aSheet) mMedia = mChildSheet->Media(); } -NS_IMETHODIMP -ImportRule::GetType(uint16_t* aType) +uint16_t +ImportRule::Type() const { - NS_ENSURE_ARG_POINTER(aType); - *aType = nsIDOMCSSRule::IMPORT_RULE; - return NS_OK; + return nsIDOMCSSRule::IMPORT_RULE; } -NS_IMETHODIMP -ImportRule::GetCssText(nsAString& aCssText) +void +ImportRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@import url("); nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText); @@ -294,31 +314,6 @@ ImportRule::GetCssText(nsAString& aCssText) } } aCssText.Append(';'); - return NS_OK; -} - -NS_IMETHODIMP -ImportRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -ImportRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -ImportRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -ImportRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -516,7 +511,7 @@ GroupRule::InsertStyleRuleAt(uint32_t aIndex, Rule* aRule) } void -GroupRule::AppendRulesToCssText(nsAString& aCssText) +GroupRule::AppendRulesToCssText(nsAString& aCssText) const { aCssText.AppendLiteral(" {\n"); @@ -697,45 +692,18 @@ MediaRule::SetMedia(nsMediaList* aMedia) return NS_OK; } -// nsIDOMCSSRule methods -NS_IMETHODIMP -MediaRule::GetType(uint16_t* aType) +uint16_t +MediaRule::Type() const { - *aType = nsIDOMCSSRule::MEDIA_RULE; - return NS_OK; + return nsIDOMCSSRule::MEDIA_RULE; } -NS_IMETHODIMP -MediaRule::GetCssText(nsAString& aCssText) +void +MediaRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@media "); AppendConditionText(aCssText); GroupRule::AppendRulesToCssText(aCssText); - return NS_OK; -} - -NS_IMETHODIMP -MediaRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -MediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -MediaRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -MediaRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } // nsIDOMCSSGroupingRule methods @@ -824,7 +792,7 @@ MediaRule::WrapObject(JSContext* aCx, } void -MediaRule::AppendConditionText(nsAString& aOutput) +MediaRule::AppendConditionText(nsAString& aOutput) const { if (mMedia) { nsAutoString mediaText; @@ -914,46 +882,19 @@ DocumentRule::Clone() const return clone.forget(); } -// nsIDOMCSSRule methods -NS_IMETHODIMP -DocumentRule::GetType(uint16_t* aType) +uint16_t +DocumentRule::Type() const { // XXX What should really happen here? - *aType = nsIDOMCSSRule::UNKNOWN_RULE; - return NS_OK; + return nsIDOMCSSRule::UNKNOWN_RULE; } -NS_IMETHODIMP -DocumentRule::GetCssText(nsAString& aCssText) +void +DocumentRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@-moz-document "); AppendConditionText(aCssText); GroupRule::AppendRulesToCssText(aCssText); - return NS_OK; -} - -NS_IMETHODIMP -DocumentRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -DocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -DocumentRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -DocumentRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } // nsIDOMCSSGroupingRule methods @@ -1074,7 +1015,7 @@ DocumentRule::WrapObject(JSContext* aCx, } void -DocumentRule::AppendConditionText(nsAString& aCssText) +DocumentRule::AppendConditionText(nsAString& aCssText) const { for (URL *url = mURLs; url; url = url->next) { switch (url->func) { @@ -1178,15 +1119,14 @@ NameSpaceRule::Clone() const return clone.forget(); } -NS_IMETHODIMP -NameSpaceRule::GetType(uint16_t* aType) +uint16_t +NameSpaceRule::Type() const { - *aType = nsIDOMCSSRule::NAMESPACE_RULE; - return NS_OK; + return nsIDOMCSSRule::NAMESPACE_RULE; } -NS_IMETHODIMP -NameSpaceRule::GetCssText(nsAString& aCssText) +void +NameSpaceRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@namespace "); if (mPrefix) { @@ -1195,31 +1135,6 @@ NameSpaceRule::GetCssText(nsAString& aCssText) aCssText.AppendLiteral("url("); nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText); aCssText.AppendLiteral(");"); - return NS_OK; -} - -NS_IMETHODIMP -NameSpaceRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -NameSpaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -NameSpaceRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -NameSpaceRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } /* virtual */ size_t @@ -1371,6 +1286,13 @@ nsCSSFontFaceStyleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID, NS_IMETHODIMP nsCSSFontFaceStyleDecl::GetCssText(nsAString & aCssText) +{ + GetCssTextImpl(aCssText); + return NS_OK; +} + +void +nsCSSFontFaceStyleDecl::GetCssTextImpl(nsAString& aCssText) const { nsAutoString descStr; @@ -1389,7 +1311,6 @@ nsCSSFontFaceStyleDecl::GetCssText(nsAString & aCssText) aCssText.AppendLiteral(";\n"); } } - return NS_OK; } NS_IMETHODIMP @@ -1619,47 +1540,21 @@ nsCSSFontFaceRule::GetType() const return Rule::FONT_FACE_RULE; } -NS_IMETHODIMP -nsCSSFontFaceRule::GetType(uint16_t* aType) +uint16_t +nsCSSFontFaceRule::Type() const { - *aType = nsIDOMCSSRule::FONT_FACE_RULE; - return NS_OK; + return nsIDOMCSSRule::FONT_FACE_RULE; } -NS_IMETHODIMP -nsCSSFontFaceRule::GetCssText(nsAString& aCssText) +void +nsCSSFontFaceRule::GetCssTextImpl(nsAString& aCssText) const { nsAutoString propText; - mDecl.GetCssText(propText); + mDecl.GetCssTextImpl(propText); aCssText.AssignLiteral("@font-face {\n"); aCssText.Append(propText); aCssText.Append('}'); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSFontFaceRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; // bug 443978 -} - -NS_IMETHODIMP -nsCSSFontFaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSFontFaceRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSFontFaceRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -1820,43 +1715,16 @@ nsCSSFontFeatureValuesRule::GetType() const return Rule::FONT_FEATURE_VALUES_RULE; } -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetType(uint16_t* aType) +uint16_t +nsCSSFontFeatureValuesRule::Type() const { - *aType = nsIDOMCSSRule::FONT_FEATURE_VALUES_RULE; - return NS_OK; + return nsIDOMCSSRule::FONT_FEATURE_VALUES_RULE; } -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetCssText(nsAString& aCssText) +void +nsCSSFontFeatureValuesRule::GetCssTextImpl(nsAString& aCssText) const { FontFeatureValuesRuleToString(mFamilyList, mFeatureValues, aCssText); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSFontFeatureValuesRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -2103,15 +1971,14 @@ nsCSSKeyframeRule::GetType() const return Rule::KEYFRAME_RULE; } -NS_IMETHODIMP -nsCSSKeyframeRule::GetType(uint16_t* aType) +uint16_t +nsCSSKeyframeRule::Type() const { - *aType = nsIDOMCSSRule::KEYFRAME_RULE; - return NS_OK; + return nsIDOMCSSRule::KEYFRAME_RULE; } -NS_IMETHODIMP -nsCSSKeyframeRule::GetCssText(nsAString& aCssText) +void +nsCSSKeyframeRule::GetCssTextImpl(nsAString& aCssText) const { DoGetKeyText(aCssText); aCssText.AppendLiteral(" { "); @@ -2119,32 +1986,6 @@ nsCSSKeyframeRule::GetCssText(nsAString& aCssText) mDeclaration->ToString(tmp); aCssText.Append(tmp); aCssText.AppendLiteral(" }"); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSKeyframeRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSKeyframeRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSKeyframeRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSKeyframeRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -2308,15 +2149,14 @@ nsCSSKeyframesRule::GetType() const return Rule::KEYFRAMES_RULE; } -NS_IMETHODIMP -nsCSSKeyframesRule::GetType(uint16_t* aType) +uint16_t +nsCSSKeyframesRule::Type() const { - *aType = nsIDOMCSSRule::KEYFRAMES_RULE; - return NS_OK; + return nsIDOMCSSRule::KEYFRAMES_RULE; } -NS_IMETHODIMP -nsCSSKeyframesRule::GetCssText(nsAString& aCssText) +void +nsCSSKeyframesRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@keyframes "); aCssText.Append(mName); @@ -2328,32 +2168,6 @@ nsCSSKeyframesRule::GetCssText(nsAString& aCssText) aCssText.Append('\n'); } aCssText.Append('}'); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSKeyframesRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSKeyframesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSKeyframesRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSKeyframesRule::GetCSSRule() -{ - return GroupRule::GetCSSRule(); } NS_IMETHODIMP @@ -2653,47 +2467,20 @@ nsCSSPageRule::GetType() const return Rule::PAGE_RULE; } -NS_IMETHODIMP -nsCSSPageRule::GetType(uint16_t* aType) +uint16_t +nsCSSPageRule::Type() const { - *aType = nsIDOMCSSRule::PAGE_RULE; - return NS_OK; + return nsIDOMCSSRule::PAGE_RULE; } -NS_IMETHODIMP -nsCSSPageRule::GetCssText(nsAString& aCssText) +void +nsCSSPageRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AppendLiteral("@page { "); nsAutoString tmp; mDeclaration->ToString(tmp); aCssText.Append(tmp); aCssText.AppendLiteral(" }"); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSPageRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSPageRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSPageRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSPageRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -2807,45 +2594,18 @@ NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) -// nsIDOMCSSRule methods -NS_IMETHODIMP -CSSSupportsRule::GetType(uint16_t* aType) +uint16_t +CSSSupportsRule::Type() const { - *aType = nsIDOMCSSRule::SUPPORTS_RULE; - return NS_OK; + return nsIDOMCSSRule::SUPPORTS_RULE; } -NS_IMETHODIMP -CSSSupportsRule::GetCssText(nsAString& aCssText) +void +CSSSupportsRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@supports "); aCssText.Append(mCondition); css::GroupRule::AppendRulesToCssText(aCssText); - return NS_OK; -} - -NS_IMETHODIMP -CSSSupportsRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -CSSSupportsRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return css::GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -CSSSupportsRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return css::GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -CSSSupportsRule::GetCSSRule() -{ - return css::GroupRule::GetCSSRule(); } // nsIDOMCSSGroupingRule methods @@ -2969,16 +2729,14 @@ nsCSSCounterStyleRule::GetType() const return Rule::COUNTER_STYLE_RULE; } -// nsIDOMCSSRule methods -NS_IMETHODIMP -nsCSSCounterStyleRule::GetType(uint16_t* aType) +uint16_t +nsCSSCounterStyleRule::Type() const { - *aType = nsIDOMCSSRule::COUNTER_STYLE_RULE; - return NS_OK; + return nsIDOMCSSRule::COUNTER_STYLE_RULE; } -NS_IMETHODIMP -nsCSSCounterStyleRule::GetCssText(nsAString& aCssText) +void +nsCSSCounterStyleRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral(u"@counter-style "); nsStyleUtil::AppendEscapedCSSIdent(mName, aCssText); @@ -2988,7 +2746,10 @@ nsCSSCounterStyleRule::GetCssText(nsAString& aCssText) id = nsCSSCounterDesc(id + 1)) { if (mValues[id].GetUnit() != eCSSUnit_Null) { nsAutoString tmp; - (this->*kGetters[id])(tmp); + // This is annoying. We want to be a const method, but kGetters stores + // XPCOM method pointers, which aren't const methods. The thing is, + // none of those mutate "this". So it's OK to cast away const here. + (const_cast(this)->*kGetters[id])(tmp); aCssText.AppendLiteral(u" "); AppendASCIItoUTF16(nsCSSProps::GetStringValue(id), aCssText); aCssText.AppendLiteral(u": "); @@ -2997,32 +2758,6 @@ nsCSSCounterStyleRule::GetCssText(nsAString& aCssText) } } aCssText.AppendLiteral(u"}"); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSCounterStyleRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSCounterStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSCounterStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSCounterStyleRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } // nsIDOMCSSCounterStyleRule methods diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index e2dcfcea5eaa..f213461287cd 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -67,15 +67,13 @@ public: return sheet ? sheet->AsGecko() : nullptr; } virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual nsIDOMCSSRule* GetDOMRule() override { return this; } - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -91,6 +89,10 @@ public: // @media rule methods nsresult SetMedia(nsMediaList* aMedia); + + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -99,7 +101,7 @@ public: JS::Handle aGivenProto) override; protected: - void AppendConditionText(nsAString& aOutput); + void AppendConditionText(nsAString& aOutput) const; RefPtr mMedia; }; @@ -121,15 +123,13 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual nsIDOMCSSRule* GetDOMRule() override { return this; } - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -169,6 +169,10 @@ public: void SetURLs(URL *aURLs) { mURLs = aURLs; } + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -176,7 +180,7 @@ public: JS::Handle aGivenProto) override; protected: - void AppendConditionText(nsAString& aOutput); + void AppendConditionText(nsAString& aOutput) const; nsAutoPtr mURLs; // linked list of |struct URL| above. }; @@ -229,6 +233,9 @@ protected: mozilla::CSSFontFaceDescriptors mDescriptors; + // The actual implementation of GetCssText, so we can make it const. + void GetCssTextImpl(nsAString& aCssText) const; + private: // NOT TO BE IMPLEMENTED // This object cannot be allocated on its own, only as part of @@ -263,17 +270,19 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSFontFaceRule interface NS_DECL_NSIDOMCSSFONTFACERULE void SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue); void GetDesc(nsCSSFontDesc aDescID, nsCSSValue & aValue); + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; virtual JSObject* WrapObject(JSContext* aCx, @@ -337,14 +346,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSFontFaceRule interface NS_DECL_NSIDOMCSSFONTFEATUREVALUESRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + const mozilla::FontFamilyList& GetFamilyList() { return mFamilyList; } void SetFamilyList(const mozilla::FontFamilyList& aFamilyList); @@ -424,14 +435,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSKeyframeRule interface NS_DECL_NSIDOMCSSKEYFRAMERULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + const nsTArray& GetKeys() const { return mKeys; } mozilla::css::Declaration* Declaration() { return mDeclaration; } @@ -473,18 +486,20 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual nsIDOMCSSRule* GetDOMRule() override { return this; } - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSKeyframesRule interface NS_DECL_NSIDOMCSSKEYFRAMESRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + // rest of GroupRule virtual bool UseForPresentation(nsPresContext* aPresContext, nsMediaQueryResultCacheKey& aKey) override; @@ -555,14 +570,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSPageRule interface NS_DECL_NSIDOMCSSPAGERULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + mozilla::css::Declaration* Declaration() { return mDeclaration; } void ChangeDeclaration(mozilla::css::Declaration* aDeclaration); @@ -593,6 +610,7 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual bool UseForPresentation(nsPresContext* aPresContext, nsMediaQueryResultCacheKey& aKey) override; @@ -603,9 +621,6 @@ public: NS_DECL_ISUPPORTS_INHERITED - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -615,6 +630,10 @@ public: // nsIDOMCSSSupportsRule interface NS_DECL_NSIDOMCSSSUPPORTSRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; virtual JSObject* WrapObject(JSContext* aCx, @@ -655,14 +674,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSCounterStyleRule NS_DECL_NSIDOMCSSCOUNTERSTYLERULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + // This function is only used to check whether a non-empty value, which has // been accepted by parser, is valid for the given system and descriptor. static bool CheckDescValue(int32_t aSystem, From 13b4594e28daf607b9305a4e09b8d8be4b4a6f99 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:03 -0500 Subject: [PATCH 27/54] Bug 851892 part 8. Get rid of css::Rule::GetDOMRule. r=heycam --- dom/base/nsDocument.cpp | 8 +++--- layout/inspector/inDOMUtils.cpp | 10 +++---- layout/style/CSSStyleSheet.cpp | 9 ++----- layout/style/GroupRule.h | 2 -- layout/style/ImportRule.h | 2 -- layout/style/NameSpaceRule.h | 2 -- layout/style/Rule.h | 11 -------- layout/style/ServoCSSRuleList.cpp | 2 +- layout/style/ServoStyleRule.h | 1 - layout/style/StyleRule.cpp | 8 +----- layout/style/StyleRule.h | 2 -- layout/style/nsCSSRules.cpp | 44 ++++++------------------------- layout/style/nsCSSRules.h | 26 ------------------ 13 files changed, 18 insertions(+), 109 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 5f3eb7d8670d..20bef0c3bdac 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -5180,7 +5180,7 @@ nsDocument::StyleRuleChanged(StyleSheet* aSheet, DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent, "StyleRuleChanged", mRule, - aStyleRule ? aStyleRule->GetDOMRule() : nullptr); + aStyleRule); } } @@ -5194,8 +5194,7 @@ nsDocument::StyleRuleAdded(StyleSheet* aSheet, DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent, "StyleRuleAdded", mRule, - aStyleRule ? aStyleRule->GetDOMRule() - : nullptr); + aStyleRule); } } @@ -5209,8 +5208,7 @@ nsDocument::StyleRuleRemoved(StyleSheet* aSheet, DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent, "StyleRuleRemoved", mRule, - aStyleRule ? aStyleRule->GetDOMRule() - : nullptr); + aStyleRule); } } diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index 5e400f8d2fe3..236136827ca4 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -253,13 +253,9 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement, for (nsRuleNode* ruleNode : Reversed(ruleNodes)) { RefPtr decl = do_QueryObject(ruleNode->GetRule()); if (decl) { - RefPtr styleRule = - do_QueryObject(decl->GetOwningRule()); - if (styleRule) { - nsCOMPtr domRule = styleRule->GetDOMRule(); - if (domRule) { - rules->AppendElement(domRule, /*weak =*/ false); - } + css::Rule* owningRule = decl->GetOwningRule(); + if (owningRule) { + rules->AppendElement(owningRule, /*weak =*/ false); } } } diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index fe2fad398ed0..4f26527e252c 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -112,7 +112,7 @@ CSSRuleListImpl::IndexedGetter(uint32_t aIndex, bool& aFound) css::Rule* rule = mStyleSheet->GetStyleRuleAt(aIndex); if (rule) { aFound = true; - return rule->GetDOMRule(); + return rule; } } @@ -878,7 +878,7 @@ CSSStyleSheet::RegisterNamespaceRule(css::Rule* aRule) nsIDOMCSSRule* CSSStyleSheet::GetDOMOwnerRule() const { - return mOwnerRule ? mOwnerRule->GetDOMRule() : nullptr; + return mOwnerRule; } CSSRuleList* @@ -1041,11 +1041,6 @@ CSSStyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv) RefPtr rule = mInner->mOrderedRules.ObjectAt(aIndex); if (rule) { mInner->mOrderedRules.RemoveObjectAt(aIndex); - if (mDocument && mDocument->StyleSheetChangeEventsEnabled()) { - // Force creation of the DOM rule, so that it can be put on the - // StyleRuleRemoved event object. - rule->GetDOMRule(); - } rule->SetStyleSheet(nullptr); DidDirty(); diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index fa9f697e0da7..99a423fe7536 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -41,8 +41,6 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule, Rule) NS_DECL_ISUPPORTS_INHERITED - // implement part of Rule - DECL_STYLE_RULE_INHERIT_NO_DOMRULE #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index 12e8e148c642..f558d1e5cf76 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -37,8 +37,6 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImportRule, Rule) NS_DECL_ISUPPORTS_INHERITED - DECL_STYLE_RULE_INHERIT - using Rule::GetStyleSheet; // unhide since nsIDOMCSSImportRule has its own GetStyleSheet // Rule methods diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index c58cec40a544..92d3fd901b69 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -38,8 +38,6 @@ public: NS_DECL_ISUPPORTS_INHERITED - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 0e88397df470..5ec846794b8c 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -23,13 +23,6 @@ namespace mozilla { namespace css { class GroupRule; -#define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ - /* nothing */ - -#define DECL_STYLE_RULE_INHERIT \ - DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ - virtual nsIDOMCSSRule* GetDOMRule() override; - class Rule : public nsIDOMCSSRule , public nsWrapperCache { @@ -114,10 +107,6 @@ public: */ virtual already_AddRefed Clone() const = 0; - // Note that this returns null for inline style rules since they aren't - // supposed to have a DOM rule representation (and our code wouldn't work). - virtual nsIDOMCSSRule* GetDOMRule() = 0; - // This is pure virtual because all of Rule's data members are non-owning and // thus measured elsewhere. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index d1d5cd3d77e5..42d411b802ac 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -88,7 +88,7 @@ ServoCSSRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) } aFound = true; if (css::Rule* rule = GetRule(aIndex)) { - return rule->GetDOMRule(); + return rule; } return nullptr; } diff --git a/layout/style/ServoStyleRule.h b/layout/style/ServoStyleRule.h index af39b96371bd..79abaf13efb6 100644 --- a/layout/style/ServoStyleRule.h +++ b/layout/style/ServoStyleRule.h @@ -68,7 +68,6 @@ public: int32_t GetType() const final { return css::Rule::STYLE_RULE; } using Rule::GetType; already_AddRefed Clone() const final; - nsIDOMCSSRule* GetDOMRule() final { return this; } size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 88d934c3efc7..67d7c5239146 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1125,7 +1125,7 @@ DOMCSSDeclarationImpl::GetParentRule(nsIDOMCSSRule **aParent) { NS_ENSURE_ARG_POINTER(aParent); - NS_IF_ADDREF(*aParent = mRule->GetDOMRule()); + NS_IF_ADDREF(*aParent = mRule); return NS_OK; } @@ -1282,12 +1282,6 @@ StyleRule::Clone() const return clone.forget(); } -/* virtual */ nsIDOMCSSRule* -StyleRule::GetDOMRule() -{ - return this; -} - void StyleRule::SetDeclaration(Declaration* aDecl) { diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 51fbab509a48..f5bb1cf9e7c7 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -353,8 +353,6 @@ public: virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override; - #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 17f3f0c77a56..35ba9906edee 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -41,13 +41,6 @@ using namespace mozilla; using namespace mozilla::dom; -#define IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \ - /* virtual */ nsIDOMCSSRule* class_::GetDOMRule() \ - { return this; } - -#define IMPL_STYLE_RULE_INHERIT(class_, super_) \ -IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) - // base class for all rule types in a CSS style sheet namespace mozilla { @@ -76,11 +69,7 @@ Rule::SetStyleSheet(StyleSheet* aSheet) NS_IMETHODIMP Rule::GetParentRule(nsIDOMCSSRule** aParentRule) { - if (mParentRule) { - NS_IF_ADDREF(*aParentRule = mParentRule->GetDOMRule()); - } else { - *aParentRule = nullptr; - } + NS_IF_ADDREF(*aParentRule = mParentRule); return NS_OK; } @@ -186,7 +175,7 @@ GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) RefPtr rule = mGroupRule->GetStyleRuleAt(aIndex); if (rule) { aFound = true; - return rule->GetDOMRule(); + return rule; } } @@ -243,8 +232,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) NS_INTERFACE_MAP_END_INHERITING(Rule) -IMPL_STYLE_RULE_INHERIT(ImportRule, Rule) - #ifdef DEBUG /* virtual */ void ImportRule::List(FILE* out, int32_t aIndent) const @@ -518,14 +505,11 @@ GroupRule::AppendRulesToCssText(nsAString& aCssText) const // get all the rules for (int32_t index = 0, count = mRules.Count(); index < count; ++index) { Rule* rule = mRules.ObjectAt(index); - nsIDOMCSSRule* domRule = rule->GetDOMRule(); - if (domRule) { - nsAutoString cssText; - domRule->GetCssText(cssText); - aCssText.AppendLiteral(" "); - aCssText.Append(cssText); - aCssText.Append('\n'); - } + nsAutoString cssText; + rule->GetCssText(cssText); + aCssText.AppendLiteral(" "); + aCssText.Append(cssText); + aCssText.Append('\n'); } aCssText.Append('}'); @@ -1078,8 +1062,6 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) -IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule) - #ifdef DEBUG /* virtual */ void NameSpaceRule::List(FILE* out, int32_t aIndent) const @@ -1427,7 +1409,7 @@ nsCSSFontFaceStyleDecl::IndexedGetter(uint32_t index, bool& aFound, nsAString & NS_IMETHODIMP nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule** aParentRule) { - NS_IF_ADDREF(*aParentRule = ContainingRule()->GetDOMRule()); + NS_IF_ADDREF(*aParentRule = ContainingRule()); return NS_OK; } @@ -1502,8 +1484,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) -IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule) - #ifdef DEBUG void nsCSSFontFaceRule::List(FILE* out, int32_t aIndent) const @@ -1625,8 +1605,6 @@ NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) -IMPL_STYLE_RULE_INHERIT(nsCSSFontFeatureValuesRule, Rule) - static void FeatureValuesToString( const nsTArray& aFeatureValues, @@ -1943,8 +1921,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) -IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSKeyframeRule, Rule) - #ifdef DEBUG void nsCSSKeyframeRule::List(FILE* out, int32_t aIndent) const @@ -2441,8 +2417,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) -IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSPageRule, Rule) - #ifdef DEBUG void nsCSSPageRule::List(FILE* out, int32_t aIndent) const @@ -2702,8 +2676,6 @@ NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) -IMPL_STYLE_RULE_INHERIT(nsCSSCounterStyleRule, css::Rule) - #ifdef DEBUG void nsCSSCounterStyleRule::List(FILE* out, int32_t aIndent) const diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index f213461287cd..fb3ff2c55e16 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -69,10 +69,6 @@ public: virtual int32_t GetType() const override; using Rule::GetType; virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -125,10 +121,6 @@ public: virtual int32_t GetType() const override; using Rule::GetType; virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -264,8 +256,6 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -340,8 +330,6 @@ public: NS_DECL_ISUPPORTS_INHERITED - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -429,8 +417,6 @@ public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -488,10 +474,6 @@ public: virtual int32_t GetType() const override; using Rule::GetType; virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } // nsIDOMCSSKeyframesRule interface NS_DECL_NSIDOMCSSKEYFRAMESRULE @@ -564,8 +546,6 @@ public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSPageRule, mozilla::css::Rule) - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -614,10 +594,6 @@ public: virtual already_AddRefed Clone() const override; virtual bool UseForPresentation(nsPresContext* aPresContext, nsMediaQueryResultCacheKey& aKey) override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } NS_DECL_ISUPPORTS_INHERITED @@ -668,8 +644,6 @@ private: public: NS_DECL_ISUPPORTS_INHERITED - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif From cea6088d4573bef8c95a7b3f750dd07528c2afc4 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:03 -0500 Subject: [PATCH 28/54] Bug 851892 part 9. Add a CSSRule Web IDL interface. r=peterv,heycam Note that this explicitly drops CSSRule.UNKNOWN_RULE. --- dom/bindings/Bindings.conf | 6 ++- dom/webidl/CSSRule.webidl | 52 ++++++++++++++++++++++++++ dom/webidl/CSSStyleDeclaration.webidl | 2 - dom/webidl/CSSStyleSheet.webidl | 2 - dom/webidl/StyleRuleChangeEvent.webidl | 2 - dom/webidl/StyleSheet.webidl | 2 - dom/webidl/moz.build | 1 + layout/style/CSSRuleList.h | 5 ++- layout/style/CSSStyleSheet.cpp | 6 +-- layout/style/CSSStyleSheet.h | 2 +- layout/style/Rule.h | 19 ++++++++++ layout/style/ServoCSSRuleList.cpp | 7 +--- layout/style/ServoCSSRuleList.h | 2 +- layout/style/ServoStyleSheet.cpp | 3 +- layout/style/ServoStyleSheet.h | 3 +- layout/style/StyleSheet.h | 6 ++- layout/style/nsCSSRules.cpp | 31 ++++++++++++++- 17 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 dom/webidl/CSSRule.webidl diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index a30617fdb40b..7f5f27ee2b6c 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -204,6 +204,11 @@ DOMInterfaces = { 'nativeType': 'nsROCSSPrimitiveValue', }, +'CSSRule': { + 'hasXPConnectImpls': True, + 'nativeType': 'mozilla::css::Rule' +}, + 'CSSStyleDeclaration': { 'nativeType': 'nsICSSDeclaration' }, @@ -1660,7 +1665,6 @@ def addExternalIface(iface, nativeType=None, headerFile=None, addExternalIface('ApplicationCache', nativeType='nsIDOMOfflineResourceList') addExternalIface('Counter') -addExternalIface('CSSRule') addExternalIface('RTCDataChannel', nativeType='nsIDOMDataChannel') addExternalIface('HitRegionOptions', nativeType='nsISupports') addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver') diff --git a/dom/webidl/CSSRule.webidl b/dom/webidl/CSSRule.webidl new file mode 100644 index 000000000000..6c4dac2e6280 --- /dev/null +++ b/dom/webidl/CSSRule.webidl @@ -0,0 +1,52 @@ +/* -*- 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://drafts.csswg.org/cssom/#the-cssrule-interface + * https://drafts.csswg.org/css-animations/#interface-cssrule + * https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface + * https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface + * https://drafts.csswg.org/css-fonts-3/#om-fontfeaturevalues + */ + +// https://drafts.csswg.org/cssom/#the-cssrule-interface +interface CSSRule { + + const unsigned short STYLE_RULE = 1; + const unsigned short CHARSET_RULE = 2; // historical + const unsigned short IMPORT_RULE = 3; + const unsigned short MEDIA_RULE = 4; + const unsigned short FONT_FACE_RULE = 5; + const unsigned short PAGE_RULE = 6; + // FIXME: We don't support MARGIN_RULE yet. + // XXXbz Should we expose the constant anyway? + // const unsigned short MARGIN_RULE = 9; + const unsigned short NAMESPACE_RULE = 10; + readonly attribute unsigned short type; + attribute DOMString cssText; + readonly attribute CSSRule? parentRule; + readonly attribute CSSStyleSheet? parentStyleSheet; +}; + +// https://drafts.csswg.org/css-animations/#interface-cssrule +partial interface CSSRule { + const unsigned short KEYFRAMES_RULE = 7; + const unsigned short KEYFRAME_RULE = 8; +}; + +// https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface +partial interface CSSRule { + const unsigned short COUNTER_STYLE_RULE = 11; +}; + +// https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface +partial interface CSSRule { + const unsigned short SUPPORTS_RULE = 12; +}; + +// https://drafts.csswg.org/css-fonts-3/#om-fontfeaturevalues +partial interface CSSRule { + const unsigned short FONT_FEATURE_VALUES_RULE = 14; +}; diff --git a/dom/webidl/CSSStyleDeclaration.webidl b/dom/webidl/CSSStyleDeclaration.webidl index d9b2511ded8c..0c95d6c9f5c3 100644 --- a/dom/webidl/CSSStyleDeclaration.webidl +++ b/dom/webidl/CSSStyleDeclaration.webidl @@ -7,8 +7,6 @@ * http://dev.w3.org/csswg/cssom/ */ -interface CSSRule; - interface CSSStyleDeclaration { [SetterThrows] attribute DOMString cssText; diff --git a/dom/webidl/CSSStyleSheet.webidl b/dom/webidl/CSSStyleSheet.webidl index 48fb89db1252..f51b89cd184f 100644 --- a/dom/webidl/CSSStyleSheet.webidl +++ b/dom/webidl/CSSStyleSheet.webidl @@ -7,8 +7,6 @@ * http://dev.w3.org/csswg/cssom/ */ -interface CSSRule; - enum CSSStyleSheetParsingMode { "author", "user", diff --git a/dom/webidl/StyleRuleChangeEvent.webidl b/dom/webidl/StyleRuleChangeEvent.webidl index 0b783366ba59..ef35bae6486c 100644 --- a/dom/webidl/StyleRuleChangeEvent.webidl +++ b/dom/webidl/StyleRuleChangeEvent.webidl @@ -3,8 +3,6 @@ * 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/. */ -interface CSSRule; - [ChromeOnly, Constructor(DOMString type, optional StyleRuleChangeEventInit eventInitDict)] interface StyleRuleChangeEvent : Event { diff --git a/dom/webidl/StyleSheet.webidl b/dom/webidl/StyleSheet.webidl index 71a8ccd8f470..26c2fbb999bd 100644 --- a/dom/webidl/StyleSheet.webidl +++ b/dom/webidl/StyleSheet.webidl @@ -7,8 +7,6 @@ * http://dev.w3.org/csswg/cssom/ */ -interface CSSRule; - interface StyleSheet { [Constant] readonly attribute DOMString type; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 4238276a6ab3..83ffd095cb26 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -92,6 +92,7 @@ WEBIDL_FILES = [ 'CSSLexer.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', + 'CSSRule.webidl', 'CSSRuleList.webidl', 'CSSStyleDeclaration.webidl', 'CSSStyleSheet.webidl', diff --git a/layout/style/CSSRuleList.h b/layout/style/CSSRuleList.h index f056d111520f..f1001fdb4b9f 100644 --- a/layout/style/CSSRuleList.h +++ b/layout/style/CSSRuleList.h @@ -7,6 +7,7 @@ #define mozilla_dom_CSSRuleList_h #include "mozilla/StyleSheetInlines.h" +#include "mozilla/css/Rule.h" #include "nsIDOMCSSRule.h" #include "nsIDOMCSSRuleList.h" #include "nsWrapperCache.h" @@ -45,13 +46,13 @@ public: } // WebIDL API - nsIDOMCSSRule* Item(uint32_t aIndex) + css::Rule* Item(uint32_t aIndex) { bool unused; return IndexedGetter(aIndex, unused); } - virtual nsIDOMCSSRule* IndexedGetter(uint32_t aIndex, bool& aFound) = 0; + virtual css::Rule* IndexedGetter(uint32_t aIndex, bool& aFound) = 0; virtual uint32_t Length() = 0; protected: diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 4f26527e252c..4af47860b085 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -61,7 +61,7 @@ public: virtual CSSStyleSheet* GetParentObject() override; - virtual nsIDOMCSSRule* + virtual css::Rule* IndexedGetter(uint32_t aIndex, bool& aFound) override; virtual uint32_t Length() override; @@ -101,7 +101,7 @@ CSSRuleListImpl::Length() return AssertedCast(mStyleSheet->StyleRuleCount()); } -nsIDOMCSSRule* +css::Rule* CSSRuleListImpl::IndexedGetter(uint32_t aIndex, bool& aFound) { aFound = false; @@ -875,7 +875,7 @@ CSSStyleSheet::RegisterNamespaceRule(css::Rule* aRule) return NS_OK; } -nsIDOMCSSRule* +css::Rule* CSSStyleSheet::GetDOMOwnerRule() const { return mOwnerRule; diff --git a/layout/style/CSSStyleSheet.h b/layout/style/CSSStyleSheet.h index 4d2b52cbe645..a17f610520b7 100644 --- a/layout/style/CSSStyleSheet.h +++ b/layout/style/CSSStyleSheet.h @@ -194,7 +194,7 @@ public: // Can't be inline because we can't include ImportRule here. And can't be // called GetOwnerRule because that would be ambiguous with the ImportRule // version. - nsIDOMCSSRule* GetDOMOwnerRule() const final; + css::Rule* GetDOMOwnerRule() const final; void WillDirty(); void DidDirty(); diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 5ec846794b8c..37446d6459c8 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -115,6 +115,11 @@ public: // WebIDL interface, aka helpers for nsIDOMCSSRule implementation. virtual uint16_t Type() const = 0; virtual void GetCssTextImpl(nsAString& aCssText) const = 0; + // XPCOM GetCssText is OK, since it never throws. + // XPCOM SetCssText is OK, since it never throws. + Rule* GetParentRule() const; + StyleSheet* GetParentStyleSheet() const { return GetStyleSheet(); } + nsIDocument* GetParentObject() const { return GetDocument(); } protected: // This is sometimes null (e.g., for style attributes). @@ -131,4 +136,18 @@ protected: } // namespace css } // namespace mozilla +// Specialization of the bindings UnwrapArg setup for css::Rule, so we can avoid +// adding an IID to css::Rule. This can go away once all css::Rule subclasses +// are on WebIDL bindings. + +#include "js/TypeDecls.h" + +namespace mozilla { +namespace dom { +template <> +nsresult +UnwrapArg(JS::Handle src, css::Rule** ppArg); +} // namepace dom +} // namespace mozilla + #endif /* mozilla_css_Rule_h___ */ diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index 42d411b802ac..7f7c07a6b481 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -79,7 +79,7 @@ ServoCSSRuleList::GetRule(uint32_t aIndex) return CastToPtr(rule); } -nsIDOMCSSRule* +css::Rule* ServoCSSRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) { if (aIndex >= mRules.Length()) { @@ -87,10 +87,7 @@ ServoCSSRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) return nullptr; } aFound = true; - if (css::Rule* rule = GetRule(aIndex)) { - return rule; - } - return nullptr; + return GetRule(aIndex); } template diff --git a/layout/style/ServoCSSRuleList.h b/layout/style/ServoCSSRuleList.h index 56a8583c4fcf..fcc18190e2e7 100644 --- a/layout/style/ServoCSSRuleList.h +++ b/layout/style/ServoCSSRuleList.h @@ -30,7 +30,7 @@ public: ServoStyleSheet* GetParentObject() final { return mStyleSheet; } - nsIDOMCSSRule* IndexedGetter(uint32_t aIndex, bool& aFound) final; + css::Rule* IndexedGetter(uint32_t aIndex, bool& aFound) final; uint32_t Length() final { return mRules.Length(); } void DropReference(); diff --git a/layout/style/ServoStyleSheet.cpp b/layout/style/ServoStyleSheet.cpp index 7a96485d4b08..61b270e372d1 100644 --- a/layout/style/ServoStyleSheet.cpp +++ b/layout/style/ServoStyleSheet.cpp @@ -145,9 +145,10 @@ ServoStyleSheet::List(FILE* aOut, int32_t aIndex) const } #endif -nsIDOMCSSRule* +css::Rule* ServoStyleSheet::GetDOMOwnerRule() const { + NS_ERROR("stylo: Don't know how to get DOM owner rule for ServoStyleSheet"); return nullptr; } diff --git a/layout/style/ServoStyleSheet.h b/layout/style/ServoStyleSheet.h index 7d82bdcc25f2..ed2bf23b0214 100644 --- a/layout/style/ServoStyleSheet.h +++ b/layout/style/ServoStyleSheet.h @@ -20,6 +20,7 @@ class ServoCSSRuleList; namespace css { class Loader; +class Rule; } /** @@ -73,7 +74,7 @@ public: // Can't be inline because we can't include ImportRule here. And can't be // called GetOwnerRule because that would be ambiguous with the ImportRule // version. - nsIDOMCSSRule* GetDOMOwnerRule() const final; + css::Rule* GetDOMOwnerRule() const final; void WillDirty() {} void DidDirty() {} diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h index b12200c75fd5..d231caf20c2b 100644 --- a/layout/style/StyleSheet.h +++ b/layout/style/StyleSheet.h @@ -33,6 +33,10 @@ class CSSRuleList; class SRIMetadata; } // namespace dom +namespace css { +class Rule; +} + /** * Superclass for data common to CSSStyleSheet and ServoStyleSheet. */ @@ -148,7 +152,7 @@ public: // The XPCOM SetDisabled is fine for WebIDL. // WebIDL CSSStyleSheet API - virtual nsIDOMCSSRule* GetDOMOwnerRule() const = 0; + virtual css::Rule* GetDOMOwnerRule() const = 0; dom::CSSRuleList* GetCssRules(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex, diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 35ba9906edee..b009ea19b660 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -43,6 +43,27 @@ using namespace mozilla::dom; // base class for all rule types in a CSS style sheet +// Temporary code that can go away once all css::Rules are on WebIDL bindings. +#include "xpcpublic.h" +namespace mozilla { +namespace dom { +template<> +nsresult +UnwrapArg(JS::Handle src, css::Rule** ppArg) +{ + MOZ_ASSERT(NS_IsMainThread()); + nsCOMPtr rule = + do_QueryInterface(xpc::UnwrapReflectorToISupports(src)); + if (!rule) { + return NS_NOINTERFACE; + } + *ppArg = rule->GetCSSRule(); + NS_ADDREF(*ppArg); + return NS_OK; +} +} // namespace dom +} // namespace mozilla + namespace mozilla { namespace css { @@ -110,6 +131,12 @@ Rule::GetCssText(nsAString& aCssText) return NS_OK; } +Rule* +Rule::GetParentRule() const +{ + return mParentRule; +} + // ------------------------------- // Style Rule List for group rules // @@ -121,7 +148,7 @@ public: virtual CSSStyleSheet* GetParentObject() override; - virtual nsIDOMCSSRule* + virtual Rule* IndexedGetter(uint32_t aIndex, bool& aFound) override; virtual uint32_t Length() override; @@ -166,7 +193,7 @@ GroupRuleRuleList::Length() return AssertedCast(mGroupRule->StyleRuleCount()); } -nsIDOMCSSRule* +Rule* GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) { aFound = false; From 72579551f8d080fd55c6d23ca0fc0e8866e5d7a5 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:03 -0500 Subject: [PATCH 29/54] Bug 851892 part 10. Convert CSSNamespaceRule to WebIDL. r=peterv,heycam --- dom/base/nsDOMClassInfo.cpp | 7 ------- dom/base/nsDOMClassInfoID.h | 1 - dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/media/webaudio/AudioBuffer.h | 1 + dom/tests/mochitest/general/test_interfaces.html | 2 +- dom/webidl/CSSNamespaceRule.webidl | 16 ++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 7 ++----- 9 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 dom/webidl/CSSNamespaceRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index c6ce77fa91c6..6af55170b22d 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -199,9 +199,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSNameSpaceRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) // XUL classes #ifdef MOZ_XUL @@ -539,10 +536,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(CSSNameSpaceRule, nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_END - #ifdef MOZ_XUL DOM_CLASSINFO_MAP_BEGIN(XULCommandDispatcher, nsIDOMXULCommandDispatcher) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULCommandDispatcher) diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 8a71ae209086..88b7876e03e7 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -23,7 +23,6 @@ enum nsDOMClassInfoID eDOMClassInfo_CSSStyleRule_id, eDOMClassInfo_CSSImportRule_id, eDOMClassInfo_CSSMediaRule_id, - eDOMClassInfo_CSSNameSpaceRule_id, // XUL classes #ifdef MOZ_XUL diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index aa5d63db32eb..5a1f42117d63 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -21,7 +21,6 @@ class ProcessGlobal; } // namespace dom namespace css { class ImportRule; -class NameSpaceRule; class StyleRule; class MediaRule; class DocumentRule; @@ -296,7 +295,6 @@ private: friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; friend class mozilla::css::ImportRule; - friend class mozilla::css::NameSpaceRule; friend class mozilla::css::StyleRule; friend class mozilla::css::MediaRule; friend class mozilla::css::DocumentRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 7f5f27ee2b6c..92376c14d5be 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -200,12 +200,17 @@ DOMInterfaces = { 'wrapperCache': False }, +'CSSNamespaceRule': { + 'nativeType': 'mozilla::css::NameSpaceRule', +}, + 'CSSPrimitiveValue': { 'nativeType': 'nsROCSSPrimitiveValue', }, 'CSSRule': { 'hasXPConnectImpls': True, + 'concrete': False, 'nativeType': 'mozilla::css::Rule' }, diff --git a/dom/media/webaudio/AudioBuffer.h b/dom/media/webaudio/AudioBuffer.h index 35627d7a1cbf..4d6f468e58d6 100644 --- a/dom/media/webaudio/AudioBuffer.h +++ b/dom/media/webaudio/AudioBuffer.h @@ -15,6 +15,7 @@ #include "nsTArray.h" #include "js/TypeDecls.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/dom/TypedArray.h" namespace mozilla { diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 0d51a2e628d2..22115cd6c429 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -249,7 +249,7 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "CSSMozDocumentRule", // IMPORTANT: Do not change this list without review from a DOM peer! - "CSSNameSpaceRule", + "CSSNamespaceRule", // IMPORTANT: Do not change this list without review from a DOM peer! "CSSPageRule", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/CSSNamespaceRule.webidl b/dom/webidl/CSSNamespaceRule.webidl new file mode 100644 index 000000000000..0051c904a72d --- /dev/null +++ b/dom/webidl/CSSNamespaceRule.webidl @@ -0,0 +1,16 @@ +/* -*- 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://drafts.csswg.org/cssom/#cssnamespacerule + */ + +// https://drafts.csswg.org/cssom/#cssnamespacerule +interface CSSNamespaceRule : CSSRule { + // Not implemented yet. . + // readonly attribute DOMString namespaceURI; + // readonly attribute DOMString prefix; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 83ffd095cb26..5816c050250b 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -90,6 +90,7 @@ WEBIDL_FILES = [ 'CSS.webidl', 'CSSAnimation.webidl', 'CSSLexer.webidl', + 'CSSNamespaceRule.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', 'CSSRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index b009ea19b660..8c958f76ba18 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -33,6 +33,7 @@ #include "nsCSSParser.h" #include "nsDOMClassInfoID.h" #include "mozilla/dom/CSSStyleDeclarationBinding.h" +#include "mozilla/dom/CSSNamespaceRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -1060,7 +1061,6 @@ NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec, mPrefix(aPrefix), mURLSpec(aURLSpec) { - SetIsNotDOMBinding(); } NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) @@ -1068,7 +1068,6 @@ NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) mPrefix(aCopy.mPrefix), mURLSpec(aCopy.mURLSpec) { - SetIsNotDOMBinding(); } NameSpaceRule::~NameSpaceRule() @@ -1086,7 +1085,6 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule) return NS_OK; } else - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) #ifdef DEBUG @@ -1161,8 +1159,7 @@ NameSpaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const NameSpaceRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSNamespaceRuleBinding::Wrap(aCx, this, aGivenProto); } } // namespace css From 596effcfffffb013e8955cf0b59a7f446f589c30 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:03 -0500 Subject: [PATCH 30/54] Bug 851892 part 11. Convert CSSImportRule to WebIDL. r=peterv,heycam,mccr8 Note that the .media PutForwards is a new feature coming along for the ride now that we're using the spec IDL. --- dom/base/nsDOMClassInfo.cpp | 9 -------- dom/base/nsDOMClassInfoID.h | 1 - dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 4 ++++ dom/webidl/CSSImportRule.webidl | 17 +++++++++++++++ dom/webidl/moz.build | 1 + js/xpconnect/tests/chrome/test_weakmaps.xul | 24 ++------------------- layout/style/ImportRule.h | 4 ++++ layout/style/nsCSSRules.cpp | 16 ++++++++------ 9 files changed, 38 insertions(+), 40 deletions(-) create mode 100644 dom/webidl/CSSImportRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 6af55170b22d..2ce8b5b88834 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -76,7 +76,6 @@ // includes needed for the prototype chain interfaces #include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" -#include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSMozDocumentRule.h" @@ -193,9 +192,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -526,11 +522,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSImportRule, nsIDOMCSSImportRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSImportRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 88b7876e03e7..70496e2e8d20 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -21,7 +21,6 @@ enum nsDOMClassInfoID // CSS classes eDOMClassInfo_CSSStyleRule_id, - eDOMClassInfo_CSSImportRule_id, eDOMClassInfo_CSSMediaRule_id, // XUL classes diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 5a1f42117d63..abd02eb2df93 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -20,7 +20,6 @@ class TabChildGlobal; class ProcessGlobal; } // namespace dom namespace css { -class ImportRule; class StyleRule; class MediaRule; class DocumentRule; @@ -294,7 +293,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class mozilla::css::ImportRule; friend class mozilla::css::StyleRule; friend class mozilla::css::MediaRule; friend class mozilla::css::DocumentRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 92376c14d5be..645b8f9d654d 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -196,6 +196,10 @@ DOMInterfaces = { 'nativeType': 'nsDOMCSSDeclaration' }, +'CSSImportRule': { + 'nativeType': 'mozilla::css::ImportRule', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/webidl/CSSImportRule.webidl b/dom/webidl/CSSImportRule.webidl new file mode 100644 index 000000000000..7d3f17c79483 --- /dev/null +++ b/dom/webidl/CSSImportRule.webidl @@ -0,0 +1,17 @@ +/* -*- 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://drafts.csswg.org/cssom/#cssimportrule + */ + +// https://drafts.csswg.org/cssom/#cssimportrule +interface CSSImportRule : CSSRule { + readonly attribute DOMString href; + [SameObject, PutForwards=mediaText] readonly attribute MediaList media; + // Per spec, the .styleSheet is never null, but in our implementation it can + // be. See . + [SameObject] readonly attribute CSSStyleSheet? styleSheet; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 5816c050250b..dacbe4d36ae0 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -89,6 +89,7 @@ WEBIDL_FILES = [ 'CSPReport.webidl', 'CSS.webidl', 'CSSAnimation.webidl', + 'CSSImportRule.webidl', 'CSSLexer.webidl', 'CSSNamespaceRule.webidl', 'CSSPrimitiveValue.webidl', diff --git a/js/xpconnect/tests/chrome/test_weakmaps.xul b/js/xpconnect/tests/chrome/test_weakmaps.xul index e741a41c6c38..9301b7b5d431 100644 --- a/js/xpconnect/tests/chrome/test_weakmaps.xul +++ b/js/xpconnect/tests/chrome/test_weakmaps.xul @@ -214,28 +214,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=668855 make_live_map(); - let unpreservable_native_key = function () { - // We only allow natives that support wrapper preservation to be used as weak - // map keys. We should be able to try to add unpreservable natives as keys without - // crashing (bug 711616), but we should throw an error (bug 761620). - - let dummy_test_map = new WeakMap; - - let rule_fail = false; - let got_rule = false; - try { - var rule = document.styleSheets[0].cssRules[0]; - got_rule = true; - dummy_test_map.set(rule, 1); - } catch (e) { - rule_fail = true; - } - ok(got_rule, "Got the CSS rule"); - ok(rule_fail, "Using a CSS rule as a weak map key should produce an exception because it can't be wrapper preserved."); - - } - - unpreservable_native_key(); + // We're out of ideas for unpreservable natives, now that just about + // everything is on webidl, so just don't test those. /* set up for running precise GC/CC then checking the results */ diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index f558d1e5cf76..45949e67e8f2 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -20,6 +20,7 @@ class nsString; namespace mozilla { class CSSStyleSheet; +class StyleSheet; namespace css { @@ -60,6 +61,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetHref is fine, since it never fails. + nsMediaList* Media() const { return mMedia; } + StyleSheet* GetStyleSheet() const; private: nsString mURLSpec; diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 8c958f76ba18..93b8f2e7117a 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -34,6 +34,7 @@ #include "nsDOMClassInfoID.h" #include "mozilla/dom/CSSStyleDeclarationBinding.h" #include "mozilla/dom/CSSNamespaceRuleBinding.h" +#include "mozilla/dom/CSSImportRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -220,7 +221,7 @@ ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, , mURLSpec(aURLSpec) , mMedia(aMedia) { - SetIsNotDOMBinding(); + MOZ_ASSERT(aMedia); // XXXbz This is really silly.... the mMedia here will be replaced // with itself if we manage to load a sheet. Which should really // never fail nowadays, in sane cases. @@ -230,7 +231,6 @@ ImportRule::ImportRule(const ImportRule& aCopy) : Rule(aCopy), mURLSpec(aCopy.mURLSpec) { - SetIsNotDOMBinding(); // Whether or not an @import rule has a null sheet is a permanent // property of that @import rule, since it is null only if the target // sheet failed security checks. @@ -257,7 +257,6 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(ImportRule, Rule, mMedia, mChildSheet) // QueryInterface implementation for ImportRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) NS_INTERFACE_MAP_END_INHERITING(Rule) #ifdef DEBUG @@ -331,6 +330,12 @@ ImportRule::GetCssTextImpl(nsAString& aCssText) const aCssText.Append(';'); } +StyleSheet* +ImportRule::GetStyleSheet() const +{ + return mChildSheet; +} + NS_IMETHODIMP ImportRule::GetHref(nsAString & aHref) { @@ -343,7 +348,7 @@ ImportRule::GetMedia(nsIDOMMediaList * *aMedia) { NS_ENSURE_ARG_POINTER(aMedia); - NS_IF_ADDREF(*aMedia = mMedia); + NS_ADDREF(*aMedia = mMedia); return NS_OK; } @@ -374,8 +379,7 @@ ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const ImportRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSImportRuleBinding::Wrap(aCx, this, aGivenProto); } GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber) From 12d9bfeec4f3358fc700c44ab2181156d09f3760 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:03 -0500 Subject: [PATCH 31/54] Bug 851892 part 12. Convert CSSStyleRule to WebIDL. r=peterv,heycam,mccr8 The .style PutForwards bit is coming along for the ride; I did check that Chrome already implements this, so we're not the only ones. --- dom/base/nsDOMClassInfo.cpp | 18 +----- dom/base/nsDOMClassInfoID.h | 1 - dom/base/nsWrapperCache.h | 4 -- dom/bindings/Bindings.conf | 4 ++ dom/webidl/CSSStyleRule.webidl | 14 +++++ dom/webidl/LegacyQueryInterface.webidl | 1 + dom/webidl/moz.build | 1 + .../file_crosscompartment_weakmap.html | 1 - .../test_crosscompartment_weakmap.html | 8 --- layout/style/BindingStyleRule.cpp | 18 ++++++ layout/style/BindingStyleRule.h | 57 +++++++++++++++++++ layout/style/ServoStyleRule.cpp | 20 +++---- layout/style/ServoStyleRule.h | 7 +-- layout/style/StyleRule.cpp | 29 ++++------ layout/style/StyleRule.h | 8 +-- layout/style/moz.build | 13 ++++- layout/style/nsICSSStyleRuleDOMWrapper.h | 5 ++ 17 files changed, 137 insertions(+), 72 deletions(-) create mode 100644 dom/webidl/CSSStyleRule.webidl create mode 100644 layout/style/BindingStyleRule.cpp create mode 100644 layout/style/BindingStyleRule.h diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 2ce8b5b88834..7ef54c833df8 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -82,7 +82,6 @@ #include "nsIDOMCSSSupportsRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMCSSPageRule.h" -#include "nsIDOMCSSStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" #ifdef MOZ_XUL @@ -189,9 +188,6 @@ static nsDOMClassInfoData sClassInfoData[] = { // Misc Core related classes // CSS classes - NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -517,11 +513,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSStyleRule, nsIDOMCSSStyleRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) @@ -2002,14 +1993,7 @@ nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx, return NS_ERROR_UNEXPECTED; } css::Rule* cssRule = rule->GetCSSRule(); - if (!cssRule) { - // A DOMCSSStyleRule whose actual underlying rule has gone away. There - // isn't much a caller can do with this thing anyway, and only chrome code - // can get its hands on it to start with, so just wrap in the current - // global. - *parentObj = globalObj; - return NS_OK; - } + MOZ_ASSERT(cssRule); nsIDocument* doc = cssRule->GetDocument(); if (!doc) { *parentObj = globalObj; diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 70496e2e8d20..06a9eedfb93c 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -20,7 +20,6 @@ enum nsDOMClassInfoID eDOMClassInfo_DOMConstructor_id, // CSS classes - eDOMClassInfo_CSSStyleRule_id, eDOMClassInfo_CSSMediaRule_id, // XUL classes diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index abd02eb2df93..41886cdcac24 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -20,11 +20,9 @@ class TabChildGlobal; class ProcessGlobal; } // namespace dom namespace css { -class StyleRule; class MediaRule; class DocumentRule; } // namespace css -class ServoStyleRule; class CSSSupportsRule; } // namespace mozilla class SandboxPrivate; @@ -293,10 +291,8 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class mozilla::css::StyleRule; friend class mozilla::css::MediaRule; friend class mozilla::css::DocumentRule; - friend class mozilla::ServoStyleRule; friend class mozilla::CSSSupportsRule; friend class nsCSSFontFaceRule; friend class nsCSSFontFeatureValuesRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 645b8f9d654d..5065959da647 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -222,6 +222,10 @@ DOMInterfaces = { 'nativeType': 'nsICSSDeclaration' }, +'CSSStyleRule': { + 'nativeType': 'mozilla::BindingStyleRule', +}, + 'CSSStyleSheet': { 'nativeType': 'mozilla::StyleSheet', 'binaryNames': { 'ownerRule': 'DOMOwnerRule' }, diff --git a/dom/webidl/CSSStyleRule.webidl b/dom/webidl/CSSStyleRule.webidl new file mode 100644 index 000000000000..571bd6a57feb --- /dev/null +++ b/dom/webidl/CSSStyleRule.webidl @@ -0,0 +1,14 @@ +/* -*- 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://drafts.csswg.org/cssom/#the-cssstylerule-interface + */ + +// https://drafts.csswg.org/cssom/#the-cssstylerule-interface +interface CSSStyleRule : CSSRule { + attribute DOMString selectorText; + [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/LegacyQueryInterface.webidl b/dom/webidl/LegacyQueryInterface.webidl index 96048b03ca4b..41bbd025ff40 100644 --- a/dom/webidl/LegacyQueryInterface.webidl +++ b/dom/webidl/LegacyQueryInterface.webidl @@ -26,6 +26,7 @@ Comment implements LegacyQueryInterface; Crypto implements LegacyQueryInterface; CSSPrimitiveValue implements LegacyQueryInterface; CSSStyleDeclaration implements LegacyQueryInterface; +CSSStyleRule implements LegacyQueryInterface; CSSValueList implements LegacyQueryInterface; DOMImplementation implements LegacyQueryInterface; DOMParser implements LegacyQueryInterface; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index dacbe4d36ae0..0a33d7eb7130 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -97,6 +97,7 @@ WEBIDL_FILES = [ 'CSSRule.webidl', 'CSSRuleList.webidl', 'CSSStyleDeclaration.webidl', + 'CSSStyleRule.webidl', 'CSSStyleSheet.webidl', 'CSSTransition.webidl', 'CSSValue.webidl', diff --git a/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html b/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html index b25cdb2f90e1..127c479ebe0e 100644 --- a/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html +++ b/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html @@ -1,7 +1,6 @@ - Test Cross-Compartment DOM WeakMaps diff --git a/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html b/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html index e50b1f1bd8ca..54658d17bc6d 100644 --- a/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html +++ b/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html @@ -15,14 +15,6 @@ function setup() { var item = window.frames[0].document.querySelector("body"); my_map.set(item, "success_string"); - - var rule_fail = false; - try { - my_map.set(window.frames[0].document.styleSheets[0].cssRules[0], 1); - } catch (e) { - rule_fail = true; - } - ok(rule_fail, "Using rule as a weak map key across compartments should produce an exception because it can't be wrapper preserved."); } function runTest() { diff --git a/layout/style/BindingStyleRule.cpp b/layout/style/BindingStyleRule.cpp new file mode 100644 index 000000000000..9cdbc46cdd72 --- /dev/null +++ b/layout/style/BindingStyleRule.cpp @@ -0,0 +1,18 @@ +/* -*- 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/BindingStyleRule.h" +#include "mozilla/dom/CSSStyleRuleBinding.h" + +namespace mozilla { + +/* virtual */ JSObject* +BindingStyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + return dom::CSSStyleRuleBinding::Wrap(aCx, this, aGivenProto); +} + +} // namespace mozilla diff --git a/layout/style/BindingStyleRule.h b/layout/style/BindingStyleRule.h new file mode 100644 index 000000000000..d2656fd9039a --- /dev/null +++ b/layout/style/BindingStyleRule.h @@ -0,0 +1,57 @@ +/* -*- 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/. */ + +#ifndef mozilla_BindingStyleRule_h__ +#define mozilla_BindingStyleRule_h__ + +#include "nscore.h" +#include "nsStringGlue.h" +#include "mozilla/css/Rule.h" + +/** + * Shared superclass for mozilla::css::StyleRule and mozilla::ServoStyleRule, + * for use from bindings code. + */ + +class nsICSSDeclaration; + +namespace mozilla { + +class BindingStyleRule : public css::Rule +{ +protected: + BindingStyleRule(uint32_t aLineNumber, uint32_t aColumnNumber) + : css::Rule(aLineNumber, aColumnNumber) + { + } + BindingStyleRule(const BindingStyleRule& aCopy) + : css::Rule(aCopy) + { + } + virtual ~BindingStyleRule() {} + +public: + // This is pure virtual because we have no members, and are an abstract class + // to start with. The fact that we have to have this declaration at all is + // kinda dumb. :( + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) + const override MOZ_MUST_OVERRIDE = 0; + + // WebIDL API + // For GetSelectorText/SetSelectorText, we purposefully use a signature that + // matches the nsIDOMCSSStyleRule one for now, so subclasses can just + // implement both at once. The actual implementations must never return + // anything other than NS_OK; + NS_IMETHOD GetSelectorText(nsAString& aSelectorText) = 0; + NS_IMETHOD SetSelectorText(const nsAString& aSelectorText) = 0; + virtual nsICSSDeclaration* Style() = 0; + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; +}; + +} // namespace mozilla + +#endif // mozilla_BindingStyleRule_h__ diff --git a/layout/style/ServoStyleRule.cpp b/layout/style/ServoStyleRule.cpp index 6df2b07b2687..2d5160922281 100644 --- a/layout/style/ServoStyleRule.cpp +++ b/layout/style/ServoStyleRule.cpp @@ -11,8 +11,8 @@ #include "mozilla/DeclarationBlockInlines.h" #include "mozilla/ServoBindings.h" #include "mozilla/ServoDeclarationBlock.h" +#include "mozilla/dom/CSSStyleRuleBinding.h" -#include "nsDOMClassInfoID.h" #include "mozAutoDocUpdate.h" namespace mozilla { @@ -100,17 +100,15 @@ ServoStyleRuleDeclaration::GetCSSParsingEnvironment( // -- ServoStyleRule -------------------------------------------------- ServoStyleRule::ServoStyleRule(already_AddRefed aRawRule) - : css::Rule(0, 0) + : BindingStyleRule(0, 0) , mRawRule(aRawRule) , mDecls(Servo_StyleRule_GetStyle(mRawRule).Consume()) { - SetIsNotDOMBinding(); } // QueryInterface implementation for ServoStyleRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(css::Rule) NS_IMPL_ADDREF_INHERITED(ServoStyleRule, css::Rule) @@ -152,14 +150,6 @@ ServoStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return aMallocSizeOf(this); } -/* virtual */ JSObject* -ServoStyleRule::WrapObject(JSContext* aCx, - JS::Handle aGivenProto) -{ - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; -} - #ifdef DEBUG void ServoStyleRule::List(FILE* out, int32_t aIndent) const @@ -187,6 +177,12 @@ ServoStyleRule::GetCssTextImpl(nsAString& aCssText) const Servo_StyleRule_GetCssText(mRawRule, &aCssText); } +nsICSSDeclaration* +ServoStyleRule::Style() +{ + return &mDecls; +} + /* CSSStyleRule implementation */ NS_IMETHODIMP diff --git a/layout/style/ServoStyleRule.h b/layout/style/ServoStyleRule.h index 79abaf13efb6..5b1511300fd4 100644 --- a/layout/style/ServoStyleRule.h +++ b/layout/style/ServoStyleRule.h @@ -9,7 +9,7 @@ #ifndef mozilla_ServoStyleRule_h #define mozilla_ServoStyleRule_h -#include "mozilla/css/Rule.h" +#include "mozilla/BindingStyleRule.h" #include "mozilla/ServoBindingTypes.h" #include "nsIDOMCSSStyleRule.h" @@ -47,7 +47,7 @@ private: RefPtr mDecls; }; -class ServoStyleRule final : public css::Rule +class ServoStyleRule final : public BindingStyleRule , public nsIDOMCSSStyleRule { public: @@ -61,6 +61,7 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + virtual nsICSSDeclaration* Style() override; RawServoStyleRule* Raw() const { return mRawRule; } @@ -69,8 +70,6 @@ public: using Rule::GetType; already_AddRefed Clone() const final; size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; #endif diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 67d7c5239146..a22f46ede321 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -16,6 +16,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/css/GroupRule.h" #include "mozilla/css/Declaration.h" +#include "mozilla/dom/CSSStyleRuleBinding.h" #include "nsIDocument.h" #include "nsIAtom.h" #include "nsString.h" @@ -26,7 +27,6 @@ #include "nsCSSPseudoClasses.h" #include "nsCSSAnonBoxes.h" #include "nsTArray.h" -#include "nsDOMClassInfoID.h" #include "nsContentUtils.h" #include "nsError.h" #include "mozAutoDocUpdate.h" @@ -1174,13 +1174,18 @@ StyleRule::Type() const NS_IMETHODIMP StyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_ADDREF(*aStyle = Style()); + return NS_OK; +} + +nsICSSDeclaration* +StyleRule::Style() { if (!mDOMDeclaration) { mDOMDeclaration.reset(new DOMCSSDeclarationImpl(this)); } - *aStyle = mDOMDeclaration.get(); - NS_ADDREF(*aStyle); - return NS_OK; + return mDOMDeclaration.get(); } NS_IMETHODIMP @@ -1195,11 +1200,10 @@ StyleRule::StyleRule(nsCSSSelectorList* aSelector, Declaration* aDeclaration, uint32_t aLineNumber, uint32_t aColumnNumber) - : Rule(aLineNumber, aColumnNumber), + : BindingStyleRule(aLineNumber, aColumnNumber), mSelector(aSelector), mDeclaration(aDeclaration) { - SetIsNotDOMBinding(); NS_PRECONDITION(aDeclaration, "must have a declaration"); mDeclaration->SetOwningRule(this); @@ -1207,11 +1211,10 @@ StyleRule::StyleRule(nsCSSSelectorList* aSelector, // for |Clone| StyleRule::StyleRule(const StyleRule& aCopy) - : Rule(aCopy), + : BindingStyleRule(aCopy), mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr), mDeclaration(new Declaration(*aCopy.mDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); // rest is constructed lazily on existing data } @@ -1241,7 +1244,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) else NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(Rule) NS_IMPL_ADDREF_INHERITED(StyleRule, Rule) @@ -1388,14 +1390,5 @@ StyleRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const return n; } -/* virtual */ JSObject* -StyleRule::WrapObject(JSContext* aCx, - JS::Handle aGivenProto) -{ - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; -} - - } // namespace css } // namespace mozilla diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index f5bb1cf9e7c7..f0d6c8ae814e 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -14,7 +14,7 @@ #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" #include "mozilla/UniquePtr.h" -#include "mozilla/css/Rule.h" +#include "mozilla/BindingStyleRule.h" #include "nsString.h" #include "nsCOMPtr.h" @@ -311,7 +311,7 @@ namespace css { class Declaration; -class StyleRule final : public Rule +class StyleRule final : public BindingStyleRule , public nsICSSStyleRuleDOMWrapper { public: @@ -334,6 +334,7 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + virtual nsICSSDeclaration* Style() override; // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -359,9 +360,6 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - private: ~StyleRule(); diff --git a/layout/style/moz.build b/layout/style/moz.build index d7be627a9578..e63290455272 100644 --- a/layout/style/moz.build +++ b/layout/style/moz.build @@ -81,6 +81,7 @@ EXPORTS += [ EXPORTS.mozilla += [ 'AnimationCollection.h', + 'BindingStyleRule.h', 'CSSEnabledState.h', 'CSSStyleSheet.h', 'CSSVariableDeclarations.h', @@ -215,10 +216,18 @@ UNIFIED_SOURCES += [ 'SVGAttrAnimationRuleProcessor.cpp', ] -# nsCSSRuleProcessor.cpp needs to be built separately because it uses plarena.h. -# nsLayoutStylesheetCache.cpp needs to be built separately because it uses +# - BindingStyleRule.cpp doesn't _really_ needs to be built separately, +# except insofar as it shifts unified build boundaries, causing +# Unified_cpp_layout_style4.cpp to include nsStyleCoord.cpp, which +# includes, via nsStyleCoord.h, , which ends up including +# , which fails in much the way described in +# . +# - nsCSSRuleProcessor.cpp needs to be built separately because it uses +# plarena.h. +# - nsLayoutStylesheetCache.cpp needs to be built separately because it uses # nsExceptionHandler.h, which includes windows.h. SOURCES += [ + 'BindingStyleRule.cpp', 'nsCSSRuleProcessor.cpp', 'nsLayoutStylesheetCache.cpp', ] diff --git a/layout/style/nsICSSStyleRuleDOMWrapper.h b/layout/style/nsICSSStyleRuleDOMWrapper.h index 038cca0868bb..f2a3b6ccc92d 100644 --- a/layout/style/nsICSSStyleRuleDOMWrapper.h +++ b/layout/style/nsICSSStyleRuleDOMWrapper.h @@ -18,6 +18,11 @@ #define NS_ICSS_STYLE_RULE_DOM_WRAPPER_IID \ {0xcee1bbb6, 0x0a32, 0x4cf3, {0x8d, 0x42, 0xba, 0x39, 0x38, 0xe9, 0xec, 0xaa}} +namespace mozilla { +namespace css { +class StyleRule; +} // namespace css +} // namespace mozilla class nsICSSStyleRuleDOMWrapper : public nsIDOMCSSStyleRule { public: From 53db7fe2442083fe98365ada974b34e178d68ecd Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:03 -0500 Subject: [PATCH 32/54] Bug 851892 part 13. Convert media, supports, and moz-document rules to WebIDL. r=peterv,heycam --- dom/base/nsDOMClassInfo.cpp | 31 ----- dom/base/nsDOMClassInfoID.h | 6 - dom/base/nsWrapperCache.h | 8 -- dom/bindings/Bindings.conf | 26 ++++ dom/webidl/CSSConditionRule.webidl | 14 ++ dom/webidl/CSSGroupingRule.webidl | 17 +++ dom/webidl/CSSMediaRule.webidl | 17 +++ dom/webidl/CSSMozDocumentRule.webidl | 10 ++ dom/webidl/CSSSupportsRule.webidl | 12 ++ dom/webidl/LegacyQueryInterface.webidl | 1 + dom/webidl/moz.build | 5 + layout/style/GroupRule.h | 29 +++++ layout/style/nsCSSRules.cpp | 172 ++++++++++++++++++------- layout/style/nsCSSRules.h | 18 ++- 14 files changed, 272 insertions(+), 94 deletions(-) create mode 100644 dom/webidl/CSSConditionRule.webidl create mode 100644 dom/webidl/CSSGroupingRule.webidl create mode 100644 dom/webidl/CSSMediaRule.webidl create mode 100644 dom/webidl/CSSMozDocumentRule.webidl create mode 100644 dom/webidl/CSSSupportsRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 7ef54c833df8..0905c88ea0a2 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -76,10 +76,7 @@ // includes needed for the prototype chain interfaces #include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" -#include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSFontFaceRule.h" -#include "nsIDOMCSSMozDocumentRule.h" -#include "nsIDOMCSSSupportsRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMCSSPageRule.h" #include "nsIDOMXULCommandDispatcher.h" @@ -187,11 +184,6 @@ static nsDOMClassInfoData sClassInfoData[] = { // Misc Core related classes - // CSS classes - NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - // XUL classes #ifdef MOZ_XUL NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULCommandDispatcher, nsDOMGenericSH, @@ -214,14 +206,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DEFAULT_SCRIPTABLE_FLAGS) #endif - NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - - NS_DEFINE_CLASSINFO_DATA(CSSSupportsRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -513,11 +497,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) - DOM_CLASSINFO_MAP_END - #ifdef MOZ_XUL DOM_CLASSINFO_MAP_BEGIN(XULCommandDispatcher, nsIDOMXULCommandDispatcher) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULCommandDispatcher) @@ -551,16 +530,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END #endif - DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMozDocumentRule) - DOM_CLASSINFO_MAP_END - - DOM_CLASSINFO_MAP_BEGIN(CSSSupportsRule, nsIDOMCSSSupportsRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSSupportsRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule) diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 06a9eedfb93c..f42004395ffc 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -19,9 +19,6 @@ enum nsDOMClassInfoID eDOMClassInfo_DOMPrototype_id, eDOMClassInfo_DOMConstructor_id, - // CSS classes - eDOMClassInfo_CSSMediaRule_id, - // XUL classes #ifdef MOZ_XUL eDOMClassInfo_XULCommandDispatcher_id, @@ -37,9 +34,6 @@ enum nsDOMClassInfoID eDOMClassInfo_XULTreeBuilder_id, #endif - eDOMClassInfo_CSSMozDocumentRule_id, - eDOMClassInfo_CSSSupportsRule_id, - // @font-face in CSS eDOMClassInfo_CSSFontFaceRule_id, diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 41886cdcac24..67f12286cc52 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -19,11 +19,6 @@ namespace dom { class TabChildGlobal; class ProcessGlobal; } // namespace dom -namespace css { -class MediaRule; -class DocumentRule; -} // namespace css -class CSSSupportsRule; } // namespace mozilla class SandboxPrivate; class nsInProcessTabChildGlobal; @@ -291,9 +286,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class mozilla::css::MediaRule; - friend class mozilla::css::DocumentRule; - friend class mozilla::CSSSupportsRule; friend class nsCSSFontFaceRule; friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 5065959da647..a17e0622e633 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -196,6 +196,17 @@ DOMInterfaces = { 'nativeType': 'nsDOMCSSDeclaration' }, +'CSSConditionRule': { + 'concrete': False, + 'nativeType': 'mozilla::css::ConditionRule', + 'headerFile': 'mozilla/css/GroupRule.h', +}, + +'CSSGroupingRule': { + 'concrete': False, + 'nativeType': 'mozilla::css::GroupRule', +}, + 'CSSImportRule': { 'nativeType': 'mozilla::css::ImportRule', }, @@ -204,6 +215,16 @@ DOMInterfaces = { 'wrapperCache': False }, +'CSSMediaRule': { + 'nativeType': 'mozilla::css::MediaRule', + 'headerFile': 'nsCSSRules.h', +}, + +'CSSMozDocumentRule': { + 'nativeType': 'mozilla::css::DocumentRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSNamespaceRule': { 'nativeType': 'mozilla::css::NameSpaceRule', }, @@ -231,6 +252,11 @@ DOMInterfaces = { 'binaryNames': { 'ownerRule': 'DOMOwnerRule' }, }, +'CSSSupportsRule': { + 'nativeType': 'mozilla::CSSSupportsRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSValue': { 'concrete': False }, diff --git a/dom/webidl/CSSConditionRule.webidl b/dom/webidl/CSSConditionRule.webidl new file mode 100644 index 000000000000..24fae2343c73 --- /dev/null +++ b/dom/webidl/CSSConditionRule.webidl @@ -0,0 +1,14 @@ +/* -*- 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://drafts.csswg.org/css-conditional/#the-cssconditionrule-interface + */ + +// https://drafts.csswg.org/css-conditional/#the-cssconditionrule-interface +interface CSSConditionRule : CSSGroupingRule { + [SetterThrows] + attribute DOMString conditionText; +}; diff --git a/dom/webidl/CSSGroupingRule.webidl b/dom/webidl/CSSGroupingRule.webidl new file mode 100644 index 000000000000..bc1023fe2006 --- /dev/null +++ b/dom/webidl/CSSGroupingRule.webidl @@ -0,0 +1,17 @@ +/* -*- 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://drafts.csswg.org/cssom/#cssgroupingrule + */ + +// https://drafts.csswg.org/cssom/#cssgroupingrule +interface CSSGroupingRule : CSSRule { + [SameObject] readonly attribute CSSRuleList cssRules; + [Throws] + unsigned long insertRule(DOMString rule, unsigned long index); + [Throws] + void deleteRule(unsigned long index); +}; diff --git a/dom/webidl/CSSMediaRule.webidl b/dom/webidl/CSSMediaRule.webidl new file mode 100644 index 000000000000..841a1b6f6b0e --- /dev/null +++ b/dom/webidl/CSSMediaRule.webidl @@ -0,0 +1,17 @@ +/* -*- 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://drafts.csswg.org/cssom/#the-cssmediarule-interface + * https://drafts.csswg.org/css-conditional/#the-cssmediarule-interface + */ + +// https://drafts.csswg.org/cssom/#the-cssmediarule-interface and +// https://drafts.csswg.org/css-conditional/#the-cssmediarule-interface +// except they disagree with each other. We're taking the inheritance from +// css-conditional and the PutForwards behavior from cssom. +interface CSSMediaRule : CSSConditionRule { + [SameObject, PutForwards=mediaText] readonly attribute MediaList media; +}; diff --git a/dom/webidl/CSSMozDocumentRule.webidl b/dom/webidl/CSSMozDocumentRule.webidl new file mode 100644 index 000000000000..27a22d52c73d --- /dev/null +++ b/dom/webidl/CSSMozDocumentRule.webidl @@ -0,0 +1,10 @@ +/* -*- 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/. + */ + +// This is a non-standard interface for @-moz-document rules +interface CSSMozDocumentRule : CSSConditionRule { + // XXX Add access to the URL list. +}; diff --git a/dom/webidl/CSSSupportsRule.webidl b/dom/webidl/CSSSupportsRule.webidl new file mode 100644 index 000000000000..0576e90ebd2b --- /dev/null +++ b/dom/webidl/CSSSupportsRule.webidl @@ -0,0 +1,12 @@ +/* -*- 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://drafts.csswg.org/css-conditional/#the-csssupportsrule-interface + */ + +// https://drafts.csswg.org/css-conditional/#the-csssupportsrule-interface +interface CSSSupportsRule : CSSConditionRule { +}; diff --git a/dom/webidl/LegacyQueryInterface.webidl b/dom/webidl/LegacyQueryInterface.webidl index 41bbd025ff40..a2f7b9dc6411 100644 --- a/dom/webidl/LegacyQueryInterface.webidl +++ b/dom/webidl/LegacyQueryInterface.webidl @@ -24,6 +24,7 @@ BoxObject implements LegacyQueryInterface; CaretPosition implements LegacyQueryInterface; Comment implements LegacyQueryInterface; Crypto implements LegacyQueryInterface; +CSSMozDocumentRule implements LegacyQueryInterface; CSSPrimitiveValue implements LegacyQueryInterface; CSSStyleDeclaration implements LegacyQueryInterface; CSSStyleRule implements LegacyQueryInterface; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 0a33d7eb7130..78ba4a8e75e8 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -89,8 +89,12 @@ WEBIDL_FILES = [ 'CSPReport.webidl', 'CSS.webidl', 'CSSAnimation.webidl', + 'CSSConditionRule.webidl', + 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSLexer.webidl', + 'CSSMediaRule.webidl', + 'CSSMozDocumentRule.webidl', 'CSSNamespaceRule.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', @@ -99,6 +103,7 @@ WEBIDL_FILES = [ 'CSSStyleDeclaration.webidl', 'CSSStyleRule.webidl', 'CSSStyleSheet.webidl', + 'CSSSupportsRule.webidl', 'CSSTransition.webidl', 'CSSValue.webidl', 'CSSValueList.webidl', diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index 99a423fe7536..339320e39087 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -12,6 +12,7 @@ #define mozilla_css_GroupRule_h__ #include "mozilla/Attributes.h" +#include "mozilla/ErrorResult.h" #include "mozilla/IncrementalClearCOMRuleArray.h" #include "mozilla/MemoryReporting.h" #include "mozilla/css/Rule.h" @@ -24,6 +25,10 @@ namespace mozilla { class StyleSheet; +namespace dom { +class CSSRuleList; +} // namespace dom + namespace css { class GroupRuleRuleList; @@ -78,6 +83,12 @@ public: return true; } + // WebIDL API + dom::CSSRuleList* CssRules(); + uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex, + ErrorResult& aRv); + void DeleteRule(uint32_t aIndex, ErrorResult& aRv); + protected: // to help implement nsIDOMCSSRule void AppendRulesToCssText(nsAString& aCssText) const; @@ -93,6 +104,24 @@ protected: RefPtr mRuleCollection; // lazily constructed }; +// Implementation of WebIDL CSSConditionRule. +class ConditionRule : public GroupRule +{ +protected: + ConditionRule(uint32_t aLineNumber, uint32_t aColumnNumber); + ConditionRule(const ConditionRule& aCopy); + virtual ~ConditionRule(); + +public: + + // GetConditionText signature matches nsIDOMCSSConditionRule, so subclasses + // can implement this easily. The implementations should never return + // anything other than NS_OK. + NS_IMETHOD GetConditionText(nsAString& aConditionText) = 0; + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) = 0; +}; + } // namespace css } // namespace mozilla diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 93b8f2e7117a..8a7126b05000 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -35,6 +35,9 @@ #include "mozilla/dom/CSSStyleDeclarationBinding.h" #include "mozilla/dom/CSSNamespaceRuleBinding.h" #include "mozilla/dom/CSSImportRuleBinding.h" +#include "mozilla/dom/CSSMediaRuleBinding.h" +#include "mozilla/dom/CSSSupportsRuleBinding.h" +#include "mozilla/dom/CSSMozDocumentRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -550,43 +553,85 @@ GroupRule::AppendRulesToCssText(nsAString& aCssText) const // nsIDOMCSSMediaRule or nsIDOMCSSMozDocumentRule methods nsresult GroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList) +{ + NS_ADDREF(*aRuleList = CssRules()); + return NS_OK; +} + +CSSRuleList* +GroupRule::CssRules() { if (!mRuleCollection) { mRuleCollection = new css::GroupRuleRuleList(this); } - NS_ADDREF(*aRuleList = mRuleCollection); - return NS_OK; + return mRuleCollection; } nsresult GroupRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval) +{ + ErrorResult rv; + *_retval = InsertRule(aRule, aIndex, rv); + return rv.StealNSResult(); +} + +uint32_t +GroupRule::InsertRule(const nsAString& aRule, uint32_t aIndex, ErrorResult& aRv) { StyleSheet* sheet = GetStyleSheet(); - NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE); - - if (aIndex > uint32_t(mRules.Count())) - return NS_ERROR_DOM_INDEX_SIZE_ERR; + if (NS_WARN_IF(!sheet)) { + aRv.Throw(NS_ERROR_FAILURE); + return 0; + } + + if (aIndex > uint32_t(mRules.Count())) { + aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return 0; + } NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX, "Too many style rules!"); - return sheet->AsGecko()->InsertRuleIntoGroup(aRule, this, aIndex, _retval); + uint32_t retval; + nsresult rv = + sheet->AsGecko()->InsertRuleIntoGroup(aRule, this, aIndex, &retval); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + return 0; + } + return retval; } nsresult GroupRule::DeleteRule(uint32_t aIndex) { - StyleSheet* sheet = GetStyleSheet(); - NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE); + ErrorResult rv; + DeleteRule(aIndex, rv); + return rv.StealNSResult(); +} - if (aIndex >= uint32_t(mRules.Count())) - return NS_ERROR_DOM_INDEX_SIZE_ERR; +void +GroupRule::DeleteRule(uint32_t aIndex, ErrorResult& aRv) +{ + StyleSheet* sheet = GetStyleSheet(); + if (NS_WARN_IF(!sheet)) { + aRv.Throw(NS_ERROR_FAILURE); + return; + } + + if (aIndex >= uint32_t(mRules.Count())) { + aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return; + } NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX, "Too many style rules!"); - return sheet->AsGecko()->DeleteRuleFromGroup(this, aIndex); + nsresult rv = sheet->AsGecko()->DeleteRuleFromGroup(this, aIndex); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + } } /* virtual */ size_t @@ -603,20 +648,31 @@ GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const return n; } +ConditionRule::ConditionRule(uint32_t aLineNumber, uint32_t aColumnNumber) + : GroupRule(aLineNumber, aColumnNumber) +{ +} + +ConditionRule::ConditionRule(const ConditionRule& aCopy) + : GroupRule(aCopy) +{ +} + +ConditionRule::~ConditionRule() +{ +} // ------------------------------------------- // nsICSSMediaRule // MediaRule::MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : GroupRule(aLineNumber, aColumnNumber) + : ConditionRule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } MediaRule::MediaRule(const MediaRule& aCopy) - : GroupRule(aCopy) + : ConditionRule(aCopy) { - SetIsNotDOMBinding(); if (aCopy.mMedia) { mMedia = aCopy.mMedia->Clone(); // XXXldb This doesn't really make sense. @@ -631,18 +687,17 @@ MediaRule::~MediaRule() } } -NS_IMPL_ADDREF_INHERITED(MediaRule, GroupRule) -NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule) +NS_IMPL_ADDREF_INHERITED(MediaRule, ConditionRule) +NS_IMPL_RELEASE_INHERITED(MediaRule, ConditionRule) // QueryInterface implementation for MediaRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule) -NS_INTERFACE_MAP_END_INHERITING(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(ConditionRule) -NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaRule, GroupRule, +NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaRule, ConditionRule, mMedia) /* virtual */ void @@ -714,6 +769,14 @@ MediaRule::Type() const return nsIDOMCSSRule::MEDIA_RULE; } +nsMediaList* +MediaRule::Media() const +{ + // In practice, if we end up being parsed at all, we have non-null mMedia. So + // it's OK to claim we don't return null here. + return mMedia; +} + void MediaRule::GetCssTextImpl(nsAString& aCssText) const { @@ -752,6 +815,15 @@ MediaRule::GetConditionText(nsAString& aConditionText) NS_IMETHODIMP MediaRule::SetConditionText(const nsAString& aConditionText) +{ + ErrorResult rv; + SetConditionText(aConditionText, rv); + return rv.StealNSResult(); +} + +void +MediaRule::SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) { if (!mMedia) { RefPtr media = new nsMediaList(); @@ -759,11 +831,16 @@ MediaRule::SetConditionText(const nsAString& aConditionText) nsresult rv = media->SetMediaText(aConditionText); if (NS_SUCCEEDED(rv)) { mMedia = media; + } else { + aRv.Throw(rv); } - return rv; + return; } - return mMedia->SetMediaText(aConditionText); + nsresult rv = mMedia->SetMediaText(aConditionText); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + } } // nsIDOMCSSMediaRule methods @@ -803,8 +880,7 @@ MediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MediaRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSMediaRuleBinding::Wrap(aCx, this, aGivenProto); } void @@ -818,32 +894,29 @@ MediaRule::AppendConditionText(nsAString& aOutput) const } DocumentRule::DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : GroupRule(aLineNumber, aColumnNumber) + : ConditionRule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } DocumentRule::DocumentRule(const DocumentRule& aCopy) - : GroupRule(aCopy) + : ConditionRule(aCopy) , mURLs(new URL(*aCopy.mURLs)) { - SetIsNotDOMBinding(); } DocumentRule::~DocumentRule() { } -NS_IMPL_ADDREF_INHERITED(DocumentRule, GroupRule) -NS_IMPL_RELEASE_INHERITED(DocumentRule, GroupRule) +NS_IMPL_ADDREF_INHERITED(DocumentRule, ConditionRule) +NS_IMPL_RELEASE_INHERITED(DocumentRule, ConditionRule) // QueryInterface implementation for DocumentRule NS_INTERFACE_MAP_BEGIN(DocumentRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule) -NS_INTERFACE_MAP_END_INHERITING(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(ConditionRule) #ifdef DEBUG /* virtual */ void @@ -947,6 +1020,13 @@ DocumentRule::SetConditionText(const nsAString& aConditionText) return NS_ERROR_NOT_IMPLEMENTED; } +void +DocumentRule::SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + // GroupRule interface /* virtual */ bool DocumentRule::UseForPresentation(nsPresContext* aPresContext, @@ -1026,8 +1106,7 @@ DocumentRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const DocumentRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSMozDocumentRuleBinding::Wrap(aCx, this, aGivenProto); } void @@ -2528,11 +2607,10 @@ namespace mozilla { CSSSupportsRule::CSSSupportsRule(bool aConditionMet, const nsString& aCondition, uint32_t aLineNumber, uint32_t aColumnNumber) - : css::GroupRule(aLineNumber, aColumnNumber) + : css::ConditionRule(aLineNumber, aColumnNumber) , mUseGroup(aConditionMet) , mCondition(aCondition) { - SetIsNotDOMBinding(); } CSSSupportsRule::~CSSSupportsRule() @@ -2540,11 +2618,10 @@ CSSSupportsRule::~CSSSupportsRule() } CSSSupportsRule::CSSSupportsRule(const CSSSupportsRule& aCopy) - : css::GroupRule(aCopy), + : css::ConditionRule(aCopy), mUseGroup(aCopy.mUseGroup), mCondition(aCopy.mCondition) { - SetIsNotDOMBinding(); } #ifdef DEBUG @@ -2585,16 +2662,15 @@ CSSSupportsRule::UseForPresentation(nsPresContext* aPresContext, return mUseGroup; } -NS_IMPL_ADDREF_INHERITED(CSSSupportsRule, css::GroupRule) -NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::GroupRule) +NS_IMPL_ADDREF_INHERITED(CSSSupportsRule, css::ConditionRule) +NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::ConditionRule) // QueryInterface implementation for CSSSupportsRule NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule) -NS_INTERFACE_MAP_END_INHERITING(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(ConditionRule) uint16_t CSSSupportsRule::Type() const @@ -2643,6 +2719,13 @@ CSSSupportsRule::SetConditionText(const nsAString& aConditionText) return NS_ERROR_NOT_IMPLEMENTED; } +void +CSSSupportsRule::SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + /* virtual */ size_t CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { @@ -2656,8 +2739,7 @@ CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const CSSSupportsRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSSupportsRuleBinding::Wrap(aCx, this, aGivenProto); } } // namespace mozilla diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index fb3ff2c55e16..3842ed57b095 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -43,7 +43,7 @@ class ErrorResult; namespace css { -class MediaRule final : public GroupRule, +class MediaRule final : public ConditionRule, public nsIDOMCSSMediaRule { public: @@ -53,7 +53,7 @@ private: ~MediaRule(); public: - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRule, GroupRule) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRule, ConditionRule) NS_DECL_ISUPPORTS_INHERITED // Rule methods @@ -89,6 +89,10 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetConditionText is OK + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) override; + nsMediaList* Media() const; virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -102,7 +106,7 @@ protected: RefPtr mMedia; }; -class DocumentRule final : public GroupRule, +class DocumentRule final : public ConditionRule, public nsIDOMCSSMozDocumentRule { public: @@ -164,6 +168,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetConditionText is OK + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) override; virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -577,7 +584,7 @@ private: namespace mozilla { -class CSSSupportsRule final : public css::GroupRule, +class CSSSupportsRule final : public css::ConditionRule, public nsIDOMCSSSupportsRule { public: @@ -609,6 +616,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetConditionText is OK + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) override; virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; From 34027d6d12c8ace6b19ae41ef436773eb024ddfd Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:04 -0500 Subject: [PATCH 33/54] Bug 851892 part 14. Convert CSSPageRule to WebIDL. r=peterv,heycam The PutForwards bit is a new feature, but easy enough to implement here. --- dom/base/nsDOMClassInfo.cpp | 10 ---------- dom/base/nsDOMClassInfoID.h | 2 -- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSPageRule.webidl | 17 +++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 16 ++++++++++------ layout/style/nsCSSRules.h | 2 +- 8 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 dom/webidl/CSSPageRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 0905c88ea0a2..e0f7d83577d5 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -78,7 +78,6 @@ #include "nsIDOMCSSKeyframesRule.h" #include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSCounterStyleRule.h" -#include "nsIDOMCSSPageRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" #ifdef MOZ_XUL @@ -237,10 +236,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSPageRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -580,11 +575,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSPageRule, nsIDOMCSSPageRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSPageRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index f42004395ffc..b812b10bbf81 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -48,8 +48,6 @@ enum nsDOMClassInfoID // @counter-style in CSS eDOMClassInfo_CSSCounterStyleRule_id, - eDOMClassInfo_CSSPageRule_id, - eDOMClassInfo_CSSFontFeatureValuesRule_id, eDOMClassInfo_XULControlElement_id, diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 67f12286cc52..59ce7d078cc6 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -27,7 +27,6 @@ class nsCSSFontFaceRule; class nsCSSFontFeatureValuesRule; class nsCSSKeyframeRule; class nsCSSKeyframesRule; -class nsCSSPageRule; class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ @@ -290,7 +289,6 @@ private: friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; - friend class nsCSSPageRule; friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() { diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index a17e0622e633..a4307008d081 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -229,6 +229,11 @@ DOMInterfaces = { 'nativeType': 'mozilla::css::NameSpaceRule', }, +'CSSPageRule': { + 'nativeType': 'nsCSSPageRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSPrimitiveValue': { 'nativeType': 'nsROCSSPrimitiveValue', }, diff --git a/dom/webidl/CSSPageRule.webidl b/dom/webidl/CSSPageRule.webidl new file mode 100644 index 000000000000..93e47ef02b9a --- /dev/null +++ b/dom/webidl/CSSPageRule.webidl @@ -0,0 +1,17 @@ +/* -*- 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://drafts.csswg.org/cssom/#the-csspagerule-interface + */ + +// https://drafts.csswg.org/cssom/#the-csspagerule-interface +// Per spec, this should inherit from CSSGroupingRule, but we don't +// implement this yet. +interface CSSPageRule : CSSRule { + // selectorText not implemented yet + // attribute DOMString selectorText; + [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 78ba4a8e75e8..277196bcd689 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -96,6 +96,7 @@ WEBIDL_FILES = [ 'CSSMediaRule.webidl', 'CSSMozDocumentRule.webidl', 'CSSNamespaceRule.webidl', + 'CSSPageRule.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', 'CSSRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 8a7126b05000..a5cdd959ddfc 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -38,6 +38,7 @@ #include "mozilla/dom/CSSMediaRuleBinding.h" #include "mozilla/dom/CSSSupportsRuleBinding.h" #include "mozilla/dom/CSSMozDocumentRuleBinding.h" +#include "mozilla/dom/CSSPageRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2482,7 +2483,6 @@ nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy) : Rule(aCopy) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2521,7 +2521,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSPageRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) #ifdef DEBUG @@ -2566,12 +2565,18 @@ nsCSSPageRule::GetCssTextImpl(nsAString& aCssText) const NS_IMETHODIMP nsCSSPageRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_ADDREF(*aStyle = Style()); + return NS_OK; +} + +nsICSSDeclaration* +nsCSSPageRule::Style() { if (!mDOMDeclaration) { mDOMDeclaration = new nsCSSPageStyleDeclaration(this); } - NS_ADDREF(*aStyle = mDOMDeclaration); - return NS_OK; + return mDOMDeclaration; } void @@ -2598,8 +2603,7 @@ nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSPageRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSPageRuleBinding::Wrap(aCx, this, aGivenProto); } namespace mozilla { diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 3842ed57b095..ba64dd16a9dd 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -543,7 +543,6 @@ public: : mozilla::css::Rule(aLineNumber, aColumnNumber) , mDeclaration(aDeclaration) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -566,6 +565,7 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + nsICSSDeclaration* Style(); mozilla::css::Declaration* Declaration() { return mDeclaration; } From 3cbcb3bbc96567520ea684a4b5eeb2fbd652500c Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:04 -0500 Subject: [PATCH 34/54] Bug 851892 part 15. Convert CSSFontFaceRule to WebIDL. r=peterv,heycam --- dom/base/nsDOMClassInfo.cpp | 10 ---------- dom/base/nsDOMClassInfoID.h | 3 --- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSFontFaceRule.webidl | 15 +++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 11 ++++++++--- layout/style/nsCSSRules.h | 3 +-- 8 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 dom/webidl/CSSFontFaceRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index e0f7d83577d5..f296eb875319 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -76,7 +76,6 @@ // includes needed for the prototype chain interfaces #include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" -#include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" @@ -205,10 +204,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DEFAULT_SCRIPTABLE_FLAGS) #endif - NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentFrameMessageManager, nsMessageManagerSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | @@ -525,11 +520,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END #endif - DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ContentFrameMessageManager, nsISupports) DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager) diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index b812b10bbf81..e16fea514809 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -34,9 +34,6 @@ enum nsDOMClassInfoID eDOMClassInfo_XULTreeBuilder_id, #endif - // @font-face in CSS - eDOMClassInfo_CSSFontFaceRule_id, - eDOMClassInfo_ContentFrameMessageManager_id, eDOMClassInfo_ContentProcessMessageManager_id, eDOMClassInfo_ChromeMessageBroadcaster_id, diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 59ce7d078cc6..3b2de5363ac0 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSFontFaceRule; class nsCSSFontFeatureValuesRule; class nsCSSKeyframeRule; class nsCSSKeyframesRule; @@ -285,7 +284,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSFontFaceRule; friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index a4307008d081..74107817e52c 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -202,6 +202,11 @@ DOMInterfaces = { 'headerFile': 'mozilla/css/GroupRule.h', }, +'CSSFontFaceRule': { + 'nativeType': 'nsCSSFontFaceRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSGroupingRule': { 'concrete': False, 'nativeType': 'mozilla::css::GroupRule', diff --git a/dom/webidl/CSSFontFaceRule.webidl b/dom/webidl/CSSFontFaceRule.webidl new file mode 100644 index 000000000000..221dd26aec20 --- /dev/null +++ b/dom/webidl/CSSFontFaceRule.webidl @@ -0,0 +1,15 @@ +/* -*- 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://drafts.csswg.org/css-fonts/#om-fontface + */ + +// https://drafts.csswg.org/css-fonts/#om-fontface +// But we implement a very old draft, apparently.... +// See bug 1058408 for implementing the current spec. +interface CSSFontFaceRule : CSSRule { + [SameObject] readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 277196bcd689..b58365494ca3 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -90,6 +90,7 @@ WEBIDL_FILES = [ 'CSS.webidl', 'CSSAnimation.webidl', 'CSSConditionRule.webidl', + 'CSSFontFaceRule.webidl', 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSLexer.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index a5cdd959ddfc..29a6fb57328e 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -39,6 +39,7 @@ #include "mozilla/dom/CSSSupportsRuleBinding.h" #include "mozilla/dom/CSSMozDocumentRuleBinding.h" #include "mozilla/dom/CSSPageRuleBinding.h" +#include "mozilla/dom/CSSFontFaceRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -1589,7 +1590,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSFontFaceRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) #ifdef DEBUG @@ -1645,6 +1645,12 @@ nsCSSFontFaceRule::GetCssTextImpl(nsAString& aCssText) const aCssText.Append('}'); } +nsICSSDeclaration* +nsCSSFontFaceRule::Style() +{ + return &mDecl; +} + NS_IMETHODIMP nsCSSFontFaceRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { @@ -1689,8 +1695,7 @@ nsCSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSFontFaceRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSFontFaceRuleBinding::Wrap(aCx, this, aGivenProto); } // ----------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index ba64dd16a9dd..a2b6d4400149 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -249,14 +249,12 @@ public: nsCSSFontFaceRule(uint32_t aLineNumber, uint32_t aColumnNumber) : mozilla::css::Rule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } nsCSSFontFaceRule(const nsCSSFontFaceRule& aCopy) // copy everything except our reference count : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) { - SetIsNotDOMBinding(); } NS_DECL_ISUPPORTS_INHERITED @@ -279,6 +277,7 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + nsICSSDeclaration* Style(); virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; From 04f7e7401b0134277e4415b04ab543326e5c4734 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:04 -0500 Subject: [PATCH 35/54] Bug 851892 part 16. Convert CSSFontFeatureValuesRule to WebIDL. r=peterv,heycam --- dom/base/nsDOMClassInfo.cpp | 9 ------- dom/base/nsDOMClassInfoID.h | 2 -- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 ++++ dom/webidl/CSSFontFeatureValuesRule.webidl | 29 ++++++++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 19 +++++++++++--- layout/style/nsCSSRules.h | 6 +++-- 8 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 dom/webidl/CSSFontFeatureValuesRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index f296eb875319..e994d26f2002 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -231,10 +231,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULLabeledControlElement, nsDOMGenericSH, @@ -565,11 +561,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControlElement, nsIDOMXULControlElement) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULControlElement) DOM_CLASSINFO_MAP_END diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index e16fea514809..3d13480dd2e8 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -45,8 +45,6 @@ enum nsDOMClassInfoID // @counter-style in CSS eDOMClassInfo_CSSCounterStyleRule_id, - eDOMClassInfo_CSSFontFeatureValuesRule_id, - eDOMClassInfo_XULControlElement_id, eDOMClassInfo_XULLabeledControlElement_id, eDOMClassInfo_XULButtonElement_id, diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 3b2de5363ac0..f4422d9adae5 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSFontFeatureValuesRule; class nsCSSKeyframeRule; class nsCSSKeyframesRule; class nsCSSCounterStyleRule; @@ -284,7 +283,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; friend class nsCSSCounterStyleRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 74107817e52c..6f6467985deb 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -207,6 +207,11 @@ DOMInterfaces = { 'headerFile': 'nsCSSRules.h', }, +'CSSFontFeatureValuesRule': { + 'nativeType': 'nsCSSFontFeatureValuesRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSGroupingRule': { 'concrete': False, 'nativeType': 'mozilla::css::GroupRule', diff --git a/dom/webidl/CSSFontFeatureValuesRule.webidl b/dom/webidl/CSSFontFeatureValuesRule.webidl new file mode 100644 index 000000000000..7532938141ea --- /dev/null +++ b/dom/webidl/CSSFontFeatureValuesRule.webidl @@ -0,0 +1,29 @@ +/* -*- 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://drafts.csswg.org/css-fonts/#om-fontfeaturevalues + */ + +// https://drafts.csswg.org/css-fonts/#om-fontfeaturevalues +// but we don't implement anything remotely resembling the spec. +interface CSSFontFeatureValuesRule : CSSRule { + [SetterThrows] + attribute DOMString fontFamily; + + // Not yet implemented + // readonly attribute CSSFontFeatureValuesMap annotation; + // readonly attribute CSSFontFeatureValuesMap ornaments; + // readonly attribute CSSFontFeatureValuesMap stylistic; + // readonly attribute CSSFontFeatureValuesMap swash; + // readonly attribute CSSFontFeatureValuesMap characterVariant; + // readonly attribute CSSFontFeatureValuesMap styleset; +}; + +partial interface CSSFontFeatureValuesRule { + // Gecko addition? + [SetterThrows] + attribute DOMString valueText; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index b58365494ca3..770d65fe227f 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -91,6 +91,7 @@ WEBIDL_FILES = [ 'CSSAnimation.webidl', 'CSSConditionRule.webidl', 'CSSFontFaceRule.webidl', + 'CSSFontFeatureValuesRule.webidl', 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSLexer.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 29a6fb57328e..93efb8c066e9 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -40,6 +40,7 @@ #include "mozilla/dom/CSSMozDocumentRuleBinding.h" #include "mozilla/dom/CSSPageRuleBinding.h" #include "mozilla/dom/CSSFontFaceRuleBinding.h" +#include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -1715,7 +1716,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSFontFeatureValuesRule NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) static void @@ -1818,6 +1818,20 @@ nsCSSFontFeatureValuesRule::GetCssTextImpl(nsAString& aCssText) const FontFeatureValuesRuleToString(mFamilyList, mFeatureValues, aCssText); } +void +nsCSSFontFeatureValuesRule::SetFontFamily(const nsAString& aFamily, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + +void +nsCSSFontFeatureValuesRule::SetValueText(const nsAString& aFamily, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + NS_IMETHODIMP nsCSSFontFeatureValuesRule::GetFontFamily(nsAString& aFamilyListStr) { @@ -1910,8 +1924,7 @@ nsCSSFontFeatureValuesRule::SizeOfIncludingThis( nsCSSFontFeatureValuesRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSFontFeatureValuesRuleBinding::Wrap(aCx, this, aGivenProto); } // ------------------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index a2b6d4400149..ed85caaff5c4 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -322,7 +322,6 @@ public: nsCSSFontFeatureValuesRule(uint32_t aLineNumber, uint32_t aColumnNumber) : mozilla::css::Rule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } nsCSSFontFeatureValuesRule(const nsCSSFontFeatureValuesRule& aCopy) @@ -331,7 +330,6 @@ public: mFamilyList(aCopy.mFamilyList), mFeatureValues(aCopy.mFeatureValues) { - SetIsNotDOMBinding(); } NS_DECL_ISUPPORTS_INHERITED @@ -349,6 +347,10 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetFontFamily is fine + void SetFontFamily(const nsAString& aFamily, mozilla::ErrorResult& aRv); + // The XPCOM GetValueText is fine + void SetValueText(const nsAString& aFamily, mozilla::ErrorResult& aRv); const mozilla::FontFamilyList& GetFamilyList() { return mFamilyList; } void SetFamilyList(const mozilla::FontFamilyList& aFamilyList); From d195e29770789416badc0dd7819ea9aed4e085a7 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:04 -0500 Subject: [PATCH 36/54] Bug 851892 part 17. Convert CSSKeyframeRule to WebIDL. r=peterv,heycam --- dom/base/nsDOMClassInfo.cpp | 9 --------- dom/base/nsDOMClassInfoID.h | 1 - dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSKeyframeRule.webidl | 14 ++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 16 ++++++++++------ layout/style/nsCSSRules.h | 4 +++- 8 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 dom/webidl/CSSKeyframeRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index e994d26f2002..db16032f99e4 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -74,7 +74,6 @@ #include "nsMemory.h" // includes needed for the prototype chain interfaces -#include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" @@ -220,9 +219,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSKeyframeRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSKeyframesRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -546,11 +542,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSKeyframeRule, nsIDOMCSSKeyframeRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframeRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSKeyframesRule, nsIDOMCSSKeyframesRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframesRule) diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 3d13480dd2e8..7ace2927558e 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -39,7 +39,6 @@ enum nsDOMClassInfoID eDOMClassInfo_ChromeMessageBroadcaster_id, eDOMClassInfo_ChromeMessageSender_id, - eDOMClassInfo_CSSKeyframeRule_id, eDOMClassInfo_CSSKeyframesRule_id, // @counter-style in CSS diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index f4422d9adae5..68ab8175f898 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSKeyframeRule; class nsCSSKeyframesRule; class nsCSSCounterStyleRule; @@ -283,7 +282,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 6f6467985deb..a43db41a027b 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -221,6 +221,11 @@ DOMInterfaces = { 'nativeType': 'mozilla::css::ImportRule', }, +'CSSKeyframeRule': { + 'nativeType': 'nsCSSKeyframeRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/webidl/CSSKeyframeRule.webidl b/dom/webidl/CSSKeyframeRule.webidl new file mode 100644 index 000000000000..25d8965f2a5d --- /dev/null +++ b/dom/webidl/CSSKeyframeRule.webidl @@ -0,0 +1,14 @@ +/* -*- 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://drafts.csswg.org/css-animations/#interface-csskeyframerule + */ + +// https://drafts.csswg.org/css-animations/#interface-csskeyframerule +interface CSSKeyframeRule : CSSRule { + attribute DOMString keyText; + readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 770d65fe227f..ab33988c5127 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -94,6 +94,7 @@ WEBIDL_FILES = [ 'CSSFontFeatureValuesRule.webidl', 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', + 'CSSKeyframeRule.webidl', 'CSSLexer.webidl', 'CSSMediaRule.webidl', 'CSSMozDocumentRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 93efb8c066e9..a96d1d1a8502 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -41,6 +41,7 @@ #include "mozilla/dom/CSSPageRuleBinding.h" #include "mozilla/dom/CSSFontFaceRuleBinding.h" #include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" +#include "mozilla/dom/CSSKeyframeRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2005,7 +2006,6 @@ nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy) , mKeys(aCopy.mKeys) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2044,7 +2044,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsCSSKeyframeRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframeRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) #ifdef DEBUG @@ -2142,12 +2141,18 @@ nsCSSKeyframeRule::SetKeyText(const nsAString& aKeyText) NS_IMETHODIMP nsCSSKeyframeRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_ADDREF(*aStyle = Style()); + return NS_OK; +} + +nsICSSDeclaration* +nsCSSKeyframeRule::Style() { if (!mDOMDeclaration) { mDOMDeclaration = new nsCSSKeyframeStyleDeclaration(this); } - NS_ADDREF(*aStyle = mDOMDeclaration); - return NS_OK; + return mDOMDeclaration; } void @@ -2189,8 +2194,7 @@ nsCSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSKeyframeRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSKeyframeRuleBinding::Wrap(aCx, this, aGivenProto); } // ------------------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index ed85caaff5c4..2c38142efbe6 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -415,7 +415,6 @@ public: , mKeys(mozilla::Move(aKeys)) , mDeclaration(mozilla::Move(aDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -438,6 +437,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetKeyText is fine. + // The XPCOM SetKeyText is fine. + nsICSSDeclaration* Style(); const nsTArray& GetKeys() const { return mKeys; } mozilla::css::Declaration* Declaration() { return mDeclaration; } From e5e72465fa5c167bc6b01300c7d6df87ba6755e2 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:04 -0500 Subject: [PATCH 37/54] Bug 851892 part 18. Convert CSSKeyframesRule to WebIDL. r=peterv,heycam --- dom/base/nsDOMClassInfo.cpp | 10 ---------- dom/base/nsDOMClassInfoID.h | 2 -- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSKeyframesRule.webidl | 18 ++++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 19 +++++++++++-------- layout/style/nsCSSRules.h | 7 ++++++- 8 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 dom/webidl/CSSKeyframesRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index db16032f99e4..2d4d85078189 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -74,7 +74,6 @@ #include "nsMemory.h" // includes needed for the prototype chain interfaces -#include "nsIDOMCSSKeyframesRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" @@ -219,10 +218,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSKeyframesRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -542,11 +537,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSKeyframesRule, nsIDOMCSSKeyframesRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframesRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSCounterStyleRule, nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 7ace2927558e..7309126c5394 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -39,8 +39,6 @@ enum nsDOMClassInfoID eDOMClassInfo_ChromeMessageBroadcaster_id, eDOMClassInfo_ChromeMessageSender_id, - eDOMClassInfo_CSSKeyframesRule_id, - // @counter-style in CSS eDOMClassInfo_CSSCounterStyleRule_id, diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 68ab8175f898..7b1de79c82c6 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSKeyframesRule; class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ @@ -282,7 +281,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSKeyframesRule; friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() { diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index a43db41a027b..29a36ab3bb12 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -226,6 +226,11 @@ DOMInterfaces = { 'headerFile': 'nsCSSRules.h', }, +'CSSKeyframesRule': { + 'nativeType': 'nsCSSKeyframesRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/webidl/CSSKeyframesRule.webidl b/dom/webidl/CSSKeyframesRule.webidl new file mode 100644 index 000000000000..d0ea978d0384 --- /dev/null +++ b/dom/webidl/CSSKeyframesRule.webidl @@ -0,0 +1,18 @@ +/* -*- 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://drafts.csswg.org/css-animations/#interface-csskeyframesrule + */ + +// https://drafts.csswg.org/css-animations/#interface-csskeyframesrule +interface CSSKeyframesRule : CSSRule { + attribute DOMString name; + readonly attribute CSSRuleList cssRules; + + void appendRule(DOMString rule); + void deleteRule(DOMString select); + CSSKeyframeRule? findRule(DOMString select); +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index ab33988c5127..f7ff34524e22 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -95,6 +95,7 @@ WEBIDL_FILES = [ 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSKeyframeRule.webidl', + 'CSSKeyframesRule.webidl', 'CSSLexer.webidl', 'CSSMediaRule.webidl', 'CSSMozDocumentRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index a96d1d1a8502..0e7bc3208486 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -42,6 +42,7 @@ #include "mozilla/dom/CSSFontFaceRuleBinding.h" #include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" #include "mozilla/dom/CSSKeyframeRuleBinding.h" +#include "mozilla/dom/CSSKeyframesRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2208,7 +2209,6 @@ nsCSSKeyframesRule::nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy) : GroupRule(aCopy), mName(aCopy.mName) { - SetIsNotDOMBinding(); } nsCSSKeyframesRule::~nsCSSKeyframesRule() @@ -2228,7 +2228,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule) // QueryInterface implementation for nsCSSKeyframesRule NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframesRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframesRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) #ifdef DEBUG @@ -2388,14 +2387,19 @@ nsCSSKeyframesRule::DeleteRule(const nsAString& aKey) NS_IMETHODIMP nsCSSKeyframesRule::FindRule(const nsAString& aKey, nsIDOMCSSKeyframeRule** aResult) +{ + NS_IF_ADDREF(*aResult = FindRule(aKey)); + return NS_OK; +} + +nsCSSKeyframeRule* +nsCSSKeyframesRule::FindRule(const nsAString& aKey) { uint32_t index = FindRuleIndexForKey(aKey); if (index == RULE_NOT_FOUND) { - *aResult = nullptr; - } else { - NS_ADDREF(*aResult = static_cast(mRules[index])); + return nullptr; } - return NS_OK; + return static_cast(mRules[index]); } // GroupRule interface @@ -2424,8 +2428,7 @@ nsCSSKeyframesRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSKeyframesRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSKeyframesRuleBinding::Wrap(aCx, this, aGivenProto); } // ------------------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 2c38142efbe6..969bdbaa117a 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -469,7 +469,6 @@ public: : mozilla::css::GroupRule(aLineNumber, aColumnNumber) , mName(aName) { - SetIsNotDOMBinding(); } private: nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy); @@ -491,6 +490,12 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetName is OK + // The XPCOM SetName is OK + using mozilla::css::GroupRule::CssRules; + // The XPCOM appendRule is OK, since it never throws + // The XPCOM deleteRule is OK, since it never throws + nsCSSKeyframeRule* FindRule(const nsAString& aKey); // rest of GroupRule virtual bool UseForPresentation(nsPresContext* aPresContext, From f035fcf088ecf65c3514aad2e717be8111089239 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:04 -0500 Subject: [PATCH 38/54] Bug 851892 part 19. Convert CSSCounterStyleRule to WebIDL. r=peterv,heycam --- dom/base/nsDOMClassInfo.cpp | 10 ---------- dom/base/nsDOMClassInfoID.h | 3 --- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSCounterStyleRule.webidl | 23 +++++++++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 6 ++---- layout/style/nsCSSRules.h | 23 ++++++++++++++++++++++- 8 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 dom/webidl/CSSCounterStyleRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 2d4d85078189..30cf9d3bc612 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -74,7 +74,6 @@ #include "nsMemory.h" // includes needed for the prototype chain interfaces -#include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" #ifdef MOZ_XUL @@ -218,10 +217,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULLabeledControlElement, nsDOMGenericSH, @@ -537,11 +532,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSCounterStyleRule, nsIDOMCSSCounterStyleRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControlElement, nsIDOMXULControlElement) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULControlElement) DOM_CLASSINFO_MAP_END diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 7309126c5394..654cee2a0b86 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -39,9 +39,6 @@ enum nsDOMClassInfoID eDOMClassInfo_ChromeMessageBroadcaster_id, eDOMClassInfo_ChromeMessageSender_id, - // @counter-style in CSS - eDOMClassInfo_CSSCounterStyleRule_id, - eDOMClassInfo_XULControlElement_id, eDOMClassInfo_XULLabeledControlElement_id, eDOMClassInfo_XULButtonElement_id, diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 7b1de79c82c6..3681fec0640d 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ { 0x6f3179a1, 0x36f7, 0x4a5c, \ @@ -281,7 +280,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() { MOZ_ASSERT(!mWrapper && !(GetWrapperFlags() & ~WRAPPER_IS_NOT_DOM_BINDING), diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 29a36ab3bb12..47c6dce8a00d 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -202,6 +202,11 @@ DOMInterfaces = { 'headerFile': 'mozilla/css/GroupRule.h', }, +'CSSCounterStyleRule': { + 'nativeType': 'nsCSSCounterStyleRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSFontFaceRule': { 'nativeType': 'nsCSSFontFaceRule', 'headerFile': 'nsCSSRules.h', diff --git a/dom/webidl/CSSCounterStyleRule.webidl b/dom/webidl/CSSCounterStyleRule.webidl new file mode 100644 index 000000000000..bb6f7e0e1b8d --- /dev/null +++ b/dom/webidl/CSSCounterStyleRule.webidl @@ -0,0 +1,23 @@ +/* -*- 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://drafts.csswg.org/css-counter-styles-3/#the-csscounterstylerule-interface + */ + +// https://drafts.csswg.org/css-counter-styles-3/#the-csscounterstylerule-interface +interface CSSCounterStyleRule : CSSRule { + attribute DOMString name; + attribute DOMString system; + attribute DOMString symbols; + attribute DOMString additiveSymbols; + attribute DOMString negative; + attribute DOMString prefix; + attribute DOMString suffix; + attribute DOMString range; + attribute DOMString pad; + attribute DOMString speakAs; + attribute DOMString fallback; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index f7ff34524e22..856e4d6c20e7 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -90,6 +90,7 @@ WEBIDL_FILES = [ 'CSS.webidl', 'CSSAnimation.webidl', 'CSSConditionRule.webidl', + 'CSSCounterStyleRule.webidl', 'CSSFontFaceRule.webidl', 'CSSFontFeatureValuesRule.webidl', 'CSSGroupingRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 0e7bc3208486..2a32ac0bff2d 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -43,6 +43,7 @@ #include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" #include "mozilla/dom/CSSKeyframeRuleBinding.h" #include "mozilla/dom/CSSKeyframesRuleBinding.h" +#include "mozilla/dom/CSSCounterStyleRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2782,7 +2783,6 @@ nsCSSCounterStyleRule::nsCSSCounterStyleRule(const nsCSSCounterStyleRule& aCopy) , mName(aCopy.mName) , mGeneration(aCopy.mGeneration) { - SetIsNotDOMBinding(); for (size_t i = 0; i < ArrayLength(mValues); ++i) { mValues[i] = aCopy.mValues[i]; } @@ -2812,7 +2812,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSCounterStyleRule NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCounterStyleRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) #ifdef DEBUG @@ -3208,6 +3207,5 @@ nsCSSCounterStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSCounterStyleRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSCounterStyleRuleBinding::Wrap(aCx, this, aGivenProto); } diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 969bdbaa117a..e82c6661feb8 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -652,7 +652,6 @@ public: , mName(aName) , mGeneration(0) { - SetIsNotDOMBinding(); } private: @@ -675,6 +674,28 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetName is OK + // The XPCOM SetName is OK + // The XPCOM GetSystem is OK + // The XPCOM SetSystem is OK + // The XPCOM GetSymbols is OK + // The XPCOM SetSymbols is OK + // The XPCOM GetAdditiveSymbols is OK + // The XPCOM SetAdditiveSymbols is OK + // The XPCOM GetNegative is OK + // The XPCOM SetNegative is OK + // The XPCOM GetPrefix is OK + // The XPCOM SetPrefix is OK + // The XPCOM GetSuffix is OK + // The XPCOM SetSuffix is OK + // The XPCOM GetRange is OK + // The XPCOM SetRange is OK + // The XPCOM GetPad is OK + // The XPCOM SetPad is OK + // The XPCOM GetSpeakAs is OK + // The XPCOM SetSpeakAs is OK + // The XPCOM GetFallback is OK + // The XPCOM SetFallback is OK // This function is only used to check whether a non-empty value, which has // been accepted by parser, is valid for the given system and descriptor. From 2e450c06d0ee71d8795b8b9fea8362d7dead708d Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Jan 2017 10:41:05 -0500 Subject: [PATCH 39/54] Bug 851892 part 20. Remove the remaining bits we added to support a mix of WebIDL and non-WebIDL rules. r=peterv --- dom/base/nsDOMClassInfo.cpp | 27 --------------------------- dom/base/nsDOMClassInfo.h | 22 ---------------------- dom/bindings/Bindings.conf | 1 - layout/style/Rule.h | 14 -------------- layout/style/nsCSSRules.cpp | 21 --------------------- 5 files changed, 85 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 30cf9d3bc612..1ff1305069e9 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -69,7 +69,6 @@ #include "nsIDOMEventTarget.h" // CSS related includes -#include "nsCSSRules.h" #include "nsIDOMCSSRule.h" #include "nsMemory.h" @@ -1893,32 +1892,6 @@ nsEventTargetSH::PreserveWrapper(nsISupports *aNative) target->PreserveWrapper(aNative); } -// CSS rule helper -NS_IMETHODIMP -nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *aGlobalObj, JSObject **parentObj) -{ - JS::Rooted globalObj(cx, aGlobalObj); - nsCOMPtr rule = do_QueryInterface(nativeObj); - if (!rule) { - return NS_ERROR_UNEXPECTED; - } - css::Rule* cssRule = rule->GetCSSRule(); - MOZ_ASSERT(cssRule); - nsIDocument* doc = cssRule->GetDocument(); - if (!doc) { - *parentObj = globalObj; - return NS_OK; - } - - nsIGlobalObject* global = doc->GetScopeObject(); - if (!global) { - return NS_ERROR_UNEXPECTED; - } - *parentObj = global->GetGlobalJSObject(); - return *parentObj ? NS_OK : NS_ERROR_FAILURE; -} - // nsIDOMEventListener::HandleEvent() 'this' converter helper NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator) diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 25377cfa2ee5..c63044627bdd 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -182,28 +182,6 @@ public: virtual void PreserveWrapper(nsISupports *aNative) override; }; -// Makes sure that we always create our wrapper in the right global, so we won't -// cache one from the wrong global. -class nsCSSRuleSH : public nsDOMGenericSH -{ -protected: - explicit nsCSSRuleSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData) - { - } - - virtual ~nsCSSRuleSH() - { - } -public: - NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *globalObj, JSObject **parentObj) override; - - static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) - { - return new nsCSSRuleSH(aData); - } -}; - // A place to hang some static methods that we should really consider // moving to be nsGlobalWindow member methods. See bug 1062418. class nsWindowSH diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 47c6dce8a00d..6529f5a6ae48 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -264,7 +264,6 @@ DOMInterfaces = { }, 'CSSRule': { - 'hasXPConnectImpls': True, 'concrete': False, 'nativeType': 'mozilla::css::Rule' }, diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 37446d6459c8..1d503fbffad7 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -136,18 +136,4 @@ protected: } // namespace css } // namespace mozilla -// Specialization of the bindings UnwrapArg setup for css::Rule, so we can avoid -// adding an IID to css::Rule. This can go away once all css::Rule subclasses -// are on WebIDL bindings. - -#include "js/TypeDecls.h" - -namespace mozilla { -namespace dom { -template <> -nsresult -UnwrapArg(JS::Handle src, css::Rule** ppArg); -} // namepace dom -} // namespace mozilla - #endif /* mozilla_css_Rule_h___ */ diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 2a32ac0bff2d..1af9664e10b1 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -54,27 +54,6 @@ using namespace mozilla::dom; // base class for all rule types in a CSS style sheet -// Temporary code that can go away once all css::Rules are on WebIDL bindings. -#include "xpcpublic.h" -namespace mozilla { -namespace dom { -template<> -nsresult -UnwrapArg(JS::Handle src, css::Rule** ppArg) -{ - MOZ_ASSERT(NS_IsMainThread()); - nsCOMPtr rule = - do_QueryInterface(xpc::UnwrapReflectorToISupports(src)); - if (!rule) { - return NS_NOINTERFACE; - } - *ppArg = rule->GetCSSRule(); - NS_ADDREF(*ppArg); - return NS_OK; -} -} // namespace dom -} // namespace mozilla - namespace mozilla { namespace css { From a3b8ef75e267274c32768f0a21af6473d3defce4 Mon Sep 17 00:00:00 2001 From: Vedant Sareen Date: Thu, 5 Jan 2017 22:32:01 +0530 Subject: [PATCH 40/54] Bug 1301311 - Cleanly reject pings that are submitted too late in shutdown. r=Dexter Added |_shuttingDown| boolean flag, which is initialized to false and is set to true when Firefox shuts down. This allows rejecting pings sent after shutdown by checking the value of this flag. Also added a new test that shuts down Telemetry using |yield TelemetryController.testShutdown()| and then tries sending a ping to it. --HG-- extra : rebase_source : 9cb901e9aa12560ab8bb1eadc86a45df47b75bca --- toolkit/components/telemetry/TelemetryController.jsm | 11 +++++++++++ .../telemetry/tests/unit/test_TelemetryController.js | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/toolkit/components/telemetry/TelemetryController.jsm b/toolkit/components/telemetry/TelemetryController.jsm index f20b1b48eb83..a25e218978c0 100644 --- a/toolkit/components/telemetry/TelemetryController.jsm +++ b/toolkit/components/telemetry/TelemetryController.jsm @@ -320,6 +320,7 @@ this.TelemetryController = Object.freeze({ var Impl = { _initialized: false, _initStarted: false, // Whether we started setting up TelemetryController. + _shuttingDown: false, // Whether the browser is shutting down. _logger: null, _prevValues: {}, // The previous build ID, if this is the first run with a new build. @@ -493,6 +494,13 @@ var Impl = { submitExternalPing: function send(aType, aPayload, aOptions) { this._log.trace("submitExternalPing - type: " + aType + ", aOptions: " + JSON.stringify(aOptions)); + // Reject pings sent after shutdown. + if (this._shuttingDown) { + const errorMessage = "submitExternalPing - Submission is not allowed after shutdown, discarding ping of type: " + aType; + this._log.error(errorMessage); + return Promise.reject(new Error(errorMessage)); + } + // Enforce the type string to only contain sane characters. const typeUuid = /^[a-z0-9][a-z0-9-]+[a-z0-9]$/i; if (!typeUuid.test(aType)) { @@ -658,6 +666,7 @@ var Impl = { */ setupTelemetry: function setupTelemetry(testing) { this._initStarted = true; + this._shuttingDown = false; this._testMode = testing; this._log.trace("setupTelemetry"); @@ -789,6 +798,7 @@ var Impl = { // Reset state. this._initialized = false; this._initStarted = false; + this._shuttingDown = true; } }), @@ -804,6 +814,7 @@ var Impl = { // This handles 1). if (!this._initStarted) { + this._shuttingDown = true; return Promise.resolve(); } diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryController.js b/toolkit/components/telemetry/tests/unit/test_TelemetryController.js index 1b5a00e1c089..4c85627dd3b8 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetryController.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryController.js @@ -452,6 +452,9 @@ add_task(function* test_telemetryEnabledUnexpectedValue() { yield TelemetryController.testReset(); Assert.equal(Telemetry.canRecordExtended, false, "False must disable Telemetry recording."); + + // Restore the state of the pref. + Preferences.set(PREF_ENABLED, true); }); add_task(function* test_telemetryCleanFHRDatabase() { @@ -502,6 +505,15 @@ add_task(function* test_telemetryCleanFHRDatabase() { } }); +// Testing shutdown and checking that pings sent afterwards are rejected. +add_task(function* test_pingRejection() { + yield TelemetryController.testReset(); + yield TelemetryController.testShutdown(); + yield sendPing(false, false) + .then(() => Assert.ok(false, "Pings submitted after shutdown must be rejected."), + () => Assert.ok(true, "Ping submitted after shutdown correctly rejected.")); +}); + add_task(function* stopServer() { yield PingServer.stop(); }); From e2143638515c2038a53612a53ffe204dc1783665 Mon Sep 17 00:00:00 2001 From: David Parks Date: Tue, 10 Jan 2017 15:17:13 -0800 Subject: [PATCH 41/54] Bug 1312788 - Log to browser console and telemetry if the parent content to a ServiceWorker is a file. r=bkelly Info is useful to sandboxing. Logs when ServiceWorker is registered (i.e. each run), not just when it is installed. --HG-- extra : rebase_source : e21a521a5015c722cfbf2f5a7a23d5cf39a88a18 --- dom/workers/ServiceWorkerManager.cpp | 12 ++++++++++++ toolkit/components/telemetry/Histograms.json | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 336c377a1792..53df99d95f7d 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -36,6 +36,7 @@ #include "mozilla/Telemetry.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/ContentParent.h" +#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/DOMError.h" #include "mozilla/dom/ErrorEvent.h" #include "mozilla/dom/Headers.h" @@ -678,6 +679,17 @@ ServiceWorkerManager::Register(mozIDOMWindow* aWindow, AssertIsOnMainThread(); Telemetry::Accumulate(Telemetry::SERVICE_WORKER_REGISTRATIONS, 1); + ContentChild* contentChild = ContentChild::GetSingleton(); + if (contentChild && + contentChild->GetRemoteType().EqualsLiteral(FILE_REMOTE_TYPE)) { + nsString message(NS_LITERAL_STRING("ServiceWorker registered by document " + "embedded in a file:/// URI. This may " + "result in unexpected behavior.")); + ReportToAllClients(cleanedScope, message, EmptyString(), + EmptyString(), 0, 0, nsIScriptError::warningFlag); + Telemetry::Accumulate(Telemetry::FILE_EMBEDDED_SERVICEWORKERS, 1); + } + promise.forget(aPromise); return NS_OK; } diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index b24a890e2fd0..eec89761468f 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -9631,6 +9631,13 @@ "n_buckets": 20, "description": "Tracking how long a ServiceWorker stays alive after it is spawned. File bugs in Core::DOM in case of a Telemetry regression." }, + "FILE_EMBEDDED_SERVICEWORKERS": { + "alert_emails": ["dparks@mozilla.com"], + "expires_in_version": "58", + "kind": "count", + "bug_numbers": [1312788], + "description": "Count ServiceWorkers that are embedded in pages loading with the file:/// protocol." + }, "GRAPHICS_SANITY_TEST": { "expires_in_version": "never", "alert_emails": ["gfx-telemetry-alerts@mozilla.com","msreckovic@mozilla.com"], From 9c5080bd64b91c6edc1ec78995be34d97e857746 Mon Sep 17 00:00:00 2001 From: sotaro Date: Sat, 14 Jan 2017 07:51:40 +0900 Subject: [PATCH 42/54] Bug 1329432 - Add ImageContainerListener r=nical --- gfx/layers/ImageContainer.cpp | 30 +++++++++++++++++++++++++++++ gfx/layers/ImageContainer.h | 26 +++++++++++++++++++++++++ gfx/layers/ipc/ImageBridgeChild.cpp | 10 +++++++--- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/gfx/layers/ImageContainer.cpp b/gfx/layers/ImageContainer.cpp index d7acfc95df0d..38f40ffba2d5 100644 --- a/gfx/layers/ImageContainer.cpp +++ b/gfx/layers/ImageContainer.cpp @@ -97,6 +97,32 @@ BufferRecycleBin::ClearRecycledBuffers() mRecycledBufferSize = 0; } +ImageContainerListener::ImageContainerListener(ImageContainer* aImageContainer) + : mLock("mozilla.layers.ImageContainerListener.mLock") + , mImageContainer(aImageContainer) +{ +} + +ImageContainerListener::~ImageContainerListener() +{ +} + +void +ImageContainerListener::NotifyComposite(const ImageCompositeNotification& aNotification) +{ + MutexAutoLock lock(mLock); + if (mImageContainer) { + mImageContainer->NotifyComposite(aNotification); + } +} + +void +ImageContainerListener::ClearImageContainer() +{ + MutexAutoLock lock(mLock); + mImageContainer = nullptr; +} + void ImageContainer::EnsureImageClient(bool aCreate) { @@ -111,6 +137,7 @@ ImageContainer::EnsureImageClient(bool aCreate) mImageClient = imageBridge->CreateImageClient(CompositableType::IMAGE, this); if (mImageClient) { mAsyncContainerID = mImageClient->GetAsyncID(); + mNotifyCompositeListener = new ImageContainerListener(this); } } } @@ -146,6 +173,9 @@ ImageContainer::ImageContainer(uint64_t aAsyncContainerID) ImageContainer::~ImageContainer() { + if (mNotifyCompositeListener) { + mNotifyCompositeListener->ClearImageContainer(); + } if (mAsyncContainerID) { if (RefPtr imageBridge = ImageBridgeChild::GetSingleton()) { imageBridge->ForgetImageContainer(mAsyncContainerID); diff --git a/gfx/layers/ImageContainer.h b/gfx/layers/ImageContainer.h index 9b1aa5d20fd9..cdf50f0b2cd0 100644 --- a/gfx/layers/ImageContainer.h +++ b/gfx/layers/ImageContainer.h @@ -145,6 +145,7 @@ namespace layers { class ImageClient; class ImageCompositeNotification; +class ImageContainer; class ImageContainerChild; class PImageContainerChild; class SharedPlanarYCbCrImage; @@ -323,6 +324,24 @@ protected: const gfx::IntSize& aScaleHint, BufferRecycleBin *aRecycleBin); }; + +// Used to notify ImageContainer::NotifyComposite() +class ImageContainerListener final { + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainerListener) + +public: + explicit ImageContainerListener(ImageContainer* aImageContainer); + + void NotifyComposite(const ImageCompositeNotification& aNotification); + void ClearImageContainer(); +private: + typedef mozilla::Mutex Mutex; + + ~ImageContainerListener(); + + Mutex mLock; + ImageContainer* mImageContainer; +}; /** * A class that manages Images for an ImageLayer. The only reason @@ -566,6 +585,11 @@ public: PImageContainerChild* GetPImageContainerChild(); + ImageContainerListener* GetImageContainerListener() + { + return mNotifyCompositeListener; + } + /** * Main thread only. */ @@ -632,6 +656,8 @@ private: // mFrameIDsNotYetComposited ProducerID mCurrentProducerID; + RefPtr mNotifyCompositeListener; + static mozilla::Atomic sGenerationCounter; }; diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index 0bfb47f07bcd..ad5b0c26bdcd 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -1105,13 +1105,17 @@ mozilla::ipc::IPCResult ImageBridgeChild::RecvDidComposite(InfallibleTArray&& aNotifications) { for (auto& n : aNotifications) { - RefPtr imageContainer; + RefPtr listener; { MutexAutoLock lock(mContainerMapLock); + ImageContainer* imageContainer; imageContainer = mImageContainers.Get(n.asyncCompositableID()); + if (imageContainer) { + listener = imageContainer->GetImageContainerListener(); + } } - if (imageContainer) { - imageContainer->NotifyComposite(n); + if (listener) { + listener->NotifyComposite(n); } } return IPC_OK(); From 3e71edcc8a82ce0b8ca7c78f27e02f7b887e7e7a Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Sat, 14 Jan 2017 00:12:43 +0100 Subject: [PATCH 43/54] Bug 1331058 - Fix analysis check in IonBuilder::initEnvironmentChain. r=shu --- js/src/jit/IonBuilder.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/src/jit/IonBuilder.cpp b/js/src/jit/IonBuilder.cpp index 8944fe487c45..c9c4c25ac884 100644 --- a/js/src/jit/IonBuilder.cpp +++ b/js/src/jit/IonBuilder.cpp @@ -1141,9 +1141,11 @@ IonBuilder::initEnvironmentChain(MDefinition* callee) current->add(env); // This reproduce what is done in CallObject::createForFunction. Skip - // this for analyses, as the script might not have a baseline script - // with template objects yet. - if (fun->needsSomeEnvironmentObject() && !info().isAnalysis()) { + // this for the arguments analysis, as the script might not have a + // baseline script with template objects yet. + if (fun->needsSomeEnvironmentObject() && + info().analysisMode() != Analysis_ArgumentsUsage) + { if (fun->needsNamedLambdaEnvironment()) env = createNamedLambdaObject(callee, env); From a3cd53c12c5529668c3db8a27464c2c928f96286 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Sat, 14 Jan 2017 01:05:52 +0100 Subject: [PATCH 44/54] Bug 1330380 part 1 - Rename a couple of variables. r=dholbert --- layout/generic/nsGridContainerFrame.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index a4bdae922666..35717dfbd99f 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -3748,8 +3748,8 @@ ContentContribution(const GridItemInfo& aGridItem, if (size == NS_INTRINSIC_WIDTH_UNKNOWN) { // We need to reflow the child to find its BSize contribution. // XXX this will give mostly correct results for now (until bug 1174569). - nscoord cbISize = INFINITE_ISIZE_COORD; - nscoord cbBSize = NS_UNCONSTRAINEDSIZE; + nscoord availISize = INFINITE_ISIZE_COORD; + nscoord availBSize = NS_UNCONSTRAINEDSIZE; auto childWM = child->GetWritingMode(); const bool isOrthogonal = childWM.IsOrthogonalTo(aCBWM); // The next two variables are MinSizeClamp values in the child's axes. @@ -3758,12 +3758,12 @@ ContentContribution(const GridItemInfo& aGridItem, if (aState.mCols.mCanResolveLineRangeSize) { nscoord sz = aState.mCols.ResolveSize(aGridItem.mArea.mCols); if (isOrthogonal) { - cbBSize = sz; + availBSize = sz; if (aGridItem.mState[aAxis] & ItemState::eClampMarginBoxMinSize) { bMinSizeClamp = sz; } } else { - cbISize = sz; + availISize = sz; if (aGridItem.mState[aAxis] & ItemState::eClampMarginBoxMinSize) { iMinSizeClamp = sz; } @@ -3774,7 +3774,7 @@ ContentContribution(const GridItemInfo& aGridItem, } else { iMinSizeClamp = aMinSizeClamp; } - LogicalSize availableSize(childWM, cbISize, cbBSize); + LogicalSize availableSize(childWM, availISize, availBSize); size = ::MeasuringReflow(child, aState.mReflowInput, aRC, availableSize, iMinSizeClamp, bMinSizeClamp); nsIFrame::IntrinsicISizeOffsetData offsets = child->IntrinsicBSizeOffsets(); From 6944ddd80020161b0cb139225eb50a115b2d6314 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Sat, 14 Jan 2017 01:05:52 +0100 Subject: [PATCH 45/54] Bug 1330380 part 2 - We must always pass along a CB size when reflowing grid items, also in MeasuringReflow. r=dholbert --- layout/generic/nsGridContainerFrame.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index 35717dfbd99f..fee51225b62d 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -3678,6 +3678,7 @@ MeasuringReflow(nsIFrame* aChild, const ReflowInput* aReflowInput, nsRenderingContext* aRC, const LogicalSize& aAvailableSize, + const LogicalSize& aCBSize, nscoord aIMinSizeClamp = NS_MAXSIZE, nscoord aBMinSizeClamp = NS_MAXSIZE) { @@ -3710,7 +3711,7 @@ MeasuringReflow(nsIFrame* aChild, } else { aChild->Properties().Delete(nsIFrame::BClampMarginBoxMinSizeProperty()); } - ReflowInput childRI(pc, *rs, aChild, aAvailableSize, nullptr, riFlags); + ReflowInput childRI(pc, *rs, aChild, aAvailableSize, &aCBSize, riFlags); ReflowOutput childSize(childRI); nsReflowStatus childStatus; const uint32_t flags = NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_SIZE_VIEW; @@ -3755,15 +3756,18 @@ ContentContribution(const GridItemInfo& aGridItem, // The next two variables are MinSizeClamp values in the child's axes. nscoord iMinSizeClamp = NS_MAXSIZE; nscoord bMinSizeClamp = NS_MAXSIZE; + LogicalSize cbSize(childWM, 0, 0); if (aState.mCols.mCanResolveLineRangeSize) { nscoord sz = aState.mCols.ResolveSize(aGridItem.mArea.mCols); if (isOrthogonal) { availBSize = sz; + cbSize.BSize(childWM) = sz; if (aGridItem.mState[aAxis] & ItemState::eClampMarginBoxMinSize) { bMinSizeClamp = sz; } } else { availISize = sz; + cbSize.ISize(childWM) = sz; if (aGridItem.mState[aAxis] & ItemState::eClampMarginBoxMinSize) { iMinSizeClamp = sz; } @@ -3776,14 +3780,13 @@ ContentContribution(const GridItemInfo& aGridItem, } LogicalSize availableSize(childWM, availISize, availBSize); size = ::MeasuringReflow(child, aState.mReflowInput, aRC, availableSize, - iMinSizeClamp, bMinSizeClamp); + cbSize, iMinSizeClamp, bMinSizeClamp); nsIFrame::IntrinsicISizeOffsetData offsets = child->IntrinsicBSizeOffsets(); size += offsets.hMargin; auto percent = offsets.hPctMargin; - if (!aState.mReflowInput) { - // We always want to add in percent padding too, but during Reflow we - // always have a definite percentage basis (the grid area) so any percent - // padding is already resolved and baked in to 'size' at this point. + if (availBSize == NS_UNCONSTRAINEDSIZE) { + // We always want to add in percent padding too, unless we already did so + // using a resolved column size above. percent += offsets.hPctPadding; } size = nsLayoutUtils::AddPercents(size, percent); @@ -4199,7 +4202,15 @@ nsGridContainerFrame::Tracks::InitializeItemBaselines( auto* rc = &aState.mRenderingContext; // XXX figure out if we can avoid/merge this reflow with the main reflow. // XXX (after bug 1174569 is sorted out) - ::MeasuringReflow(child, aState.mReflowInput, rc, avail); + // + // XXX How should we handle percentage padding here? (bug 1330866) + // XXX (see ::ContentContribution and how it deals with percentages) + // XXX What if the true baseline after line-breaking differs from this + // XXX hypothetical baseline based on an infinite inline size? + // XXX Maybe we should just call ::ContentContribution here instead? + // XXX For now we just pass a zero-sized CB: + LogicalSize cbSize(childWM, 0, 0); + ::MeasuringReflow(child, aState.mReflowInput, rc, avail, cbSize); nscoord baseline; nsGridContainerFrame* grid = do_QueryFrame(child); if (state & ItemState::eFirstBaseline) { From 31135bdfca97bbe2a018d02e7c64499277aa9e6b Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Sat, 14 Jan 2017 01:05:53 +0100 Subject: [PATCH 46/54] Bug 1330380 part 3 - Add more reftests using percentages in various properties. --- .../grid-item-sizing-percent-002-ref.html | 136 +++++++++++++++++ .../grid-item-sizing-percent-002.html | 138 +++++++++++++++++ .../grid-item-sizing-percent-003-ref.html | 137 +++++++++++++++++ .../grid-item-sizing-percent-003.html | 139 +++++++++++++++++ .../grid-item-sizing-percent-004-ref.html | 134 +++++++++++++++++ .../grid-item-sizing-percent-004.html | 142 ++++++++++++++++++ layout/reftests/css-grid/reftest.list | 3 + 7 files changed, 829 insertions(+) create mode 100644 layout/reftests/css-grid/grid-item-sizing-percent-002-ref.html create mode 100644 layout/reftests/css-grid/grid-item-sizing-percent-002.html create mode 100644 layout/reftests/css-grid/grid-item-sizing-percent-003-ref.html create mode 100644 layout/reftests/css-grid/grid-item-sizing-percent-003.html create mode 100644 layout/reftests/css-grid/grid-item-sizing-percent-004-ref.html create mode 100644 layout/reftests/css-grid/grid-item-sizing-percent-004.html diff --git a/layout/reftests/css-grid/grid-item-sizing-percent-002-ref.html b/layout/reftests/css-grid/grid-item-sizing-percent-002-ref.html new file mode 100644 index 000000000000..11faf4f6c0dc --- /dev/null +++ b/layout/reftests/css-grid/grid-item-sizing-percent-002-ref.html @@ -0,0 +1,136 @@ + + + + Reference: Testing grid item percent sizes + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + diff --git a/layout/reftests/css-grid/grid-item-sizing-percent-002.html b/layout/reftests/css-grid/grid-item-sizing-percent-002.html new file mode 100644 index 000000000000..be1d1e4cd31e --- /dev/null +++ b/layout/reftests/css-grid/grid-item-sizing-percent-002.html @@ -0,0 +1,138 @@ + + + + CSS Test: Testing grid item percent sizes + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + + diff --git a/layout/reftests/css-grid/grid-item-sizing-percent-003-ref.html b/layout/reftests/css-grid/grid-item-sizing-percent-003-ref.html new file mode 100644 index 000000000000..fb4d15ff834d --- /dev/null +++ b/layout/reftests/css-grid/grid-item-sizing-percent-003-ref.html @@ -0,0 +1,137 @@ + + + + Reference: Testing grid item percent sizes + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + diff --git a/layout/reftests/css-grid/grid-item-sizing-percent-003.html b/layout/reftests/css-grid/grid-item-sizing-percent-003.html new file mode 100644 index 000000000000..fb32d3d27633 --- /dev/null +++ b/layout/reftests/css-grid/grid-item-sizing-percent-003.html @@ -0,0 +1,139 @@ + + + + CSS Test: Testing grid item percent sizes + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + + diff --git a/layout/reftests/css-grid/grid-item-sizing-percent-004-ref.html b/layout/reftests/css-grid/grid-item-sizing-percent-004-ref.html new file mode 100644 index 000000000000..51f71e662843 --- /dev/null +++ b/layout/reftests/css-grid/grid-item-sizing-percent-004-ref.html @@ -0,0 +1,134 @@ + + + + Reference: Testing grid item percent sizes + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + diff --git a/layout/reftests/css-grid/grid-item-sizing-percent-004.html b/layout/reftests/css-grid/grid-item-sizing-percent-004.html new file mode 100644 index 000000000000..f7ea9c1270e0 --- /dev/null +++ b/layout/reftests/css-grid/grid-item-sizing-percent-004.html @@ -0,0 +1,142 @@ + + + + CSS Test: Testing grid item percent sizes + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + + diff --git a/layout/reftests/css-grid/reftest.list b/layout/reftests/css-grid/reftest.list index e473150852e7..d85eefbd0179 100644 --- a/layout/reftests/css-grid/reftest.list +++ b/layout/reftests/css-grid/reftest.list @@ -45,6 +45,9 @@ skip-if(Android) fuzzy-if(winWidget,1,32) == grid-placement-auto-implicit-001.ht == vrl-grid-placement-auto-row-sparse-001.html vrl-grid-placement-auto-row-sparse-001-ref.html == grid-relpos-items-001.html grid-relpos-items-001-ref.html == grid-item-sizing-percent-001.html grid-item-sizing-percent-001-ref.html +== grid-item-sizing-percent-002.html grid-item-sizing-percent-002-ref.html +== grid-item-sizing-percent-003.html grid-item-sizing-percent-003-ref.html +== grid-item-sizing-percent-004.html grid-item-sizing-percent-004-ref.html == grid-item-sizing-px-001.html grid-item-sizing-percent-001-ref.html == grid-item-dir-001.html grid-item-dir-001-ref.html fuzzy-if(winWidget,70,130) fuzzy-if(cocoaWidget,85,180) == grid-col-max-sizing-max-content-001.html grid-col-max-sizing-max-content-001-ref.html From a88cba74f6568c21120d7d329018025c27c7f4ec Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Fri, 13 Jan 2017 16:51:00 -0800 Subject: [PATCH 47/54] Bug 1317374 - Don't do Annex B lexical function behavior when redeclaring a parameter name. (r=Waldo) --- js/src/frontend/Parser.cpp | 6 ++++++ .../block-scoped-functions-annex-b-parameter.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 35cf8f8744fb..cecbb100960a 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -1177,6 +1177,12 @@ Parser::tryDeclareVar(HandlePropertyName name, DeclarationKind kin *redeclaredKind = Some(declaredKind); return true; } + } else if (kind == DeclarationKind::VarForAnnexBLexicalFunction) { + MOZ_ASSERT(DeclarationKindIsParameter(declaredKind)); + + // Annex B.3.3.1 disallows redeclaring parameter names. + *redeclaredKind = Some(declaredKind); + return true; } } else { if (!scope->addDeclaredName(pc, p, name, kind)) diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js new file mode 100644 index 000000000000..f0adedf7d84e --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js @@ -0,0 +1,16 @@ +// Annex B.3.3.1 disallows Annex B lexical function behavior when redeclaring a +// parameter. + +(function(f) { + if (true) function f() { } + assertEq(f, 123); +}(123)); + +(function(f) { + { function f() { } } + assertEq(f, 123); +}(123)); + + +if (typeof reportCompare === "function") + reportCompare(true, true); From 64affe9854eec72c9d7ec98416437fdd5c5a5cf7 Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Fri, 13 Jan 2017 17:02:57 -0800 Subject: [PATCH 48/54] Backed out changeset 4dc794806128 (bug 1317374) for spidermonkey bustage a=backout MozReview-Commit-ID: EJDwWWtrHTb --- js/src/frontend/Parser.cpp | 6 ------ .../block-scoped-functions-annex-b-parameter.js | 16 ---------------- 2 files changed, 22 deletions(-) delete mode 100644 js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index cecbb100960a..35cf8f8744fb 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -1177,12 +1177,6 @@ Parser::tryDeclareVar(HandlePropertyName name, DeclarationKind kin *redeclaredKind = Some(declaredKind); return true; } - } else if (kind == DeclarationKind::VarForAnnexBLexicalFunction) { - MOZ_ASSERT(DeclarationKindIsParameter(declaredKind)); - - // Annex B.3.3.1 disallows redeclaring parameter names. - *redeclaredKind = Some(declaredKind); - return true; } } else { if (!scope->addDeclaredName(pc, p, name, kind)) diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js deleted file mode 100644 index f0adedf7d84e..000000000000 --- a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-parameter.js +++ /dev/null @@ -1,16 +0,0 @@ -// Annex B.3.3.1 disallows Annex B lexical function behavior when redeclaring a -// parameter. - -(function(f) { - if (true) function f() { } - assertEq(f, 123); -}(123)); - -(function(f) { - { function f() { } } - assertEq(f, 123); -}(123)); - - -if (typeof reportCompare === "function") - reportCompare(true, true); From 10f39e4fd96d560b7d4a551b6001ae735f056da0 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Fri, 13 Jan 2017 17:11:01 -0800 Subject: [PATCH 49/54] Bug 1331038 Make nsPipe handle OOM conditions gracefully. r=froydnj --- xpcom/io/nsPipe3.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xpcom/io/nsPipe3.cpp b/xpcom/io/nsPipe3.cpp index d7b9883ac3a9..56932adfc8d2 100644 --- a/xpcom/io/nsPipe3.cpp +++ b/xpcom/io/nsPipe3.cpp @@ -870,7 +870,9 @@ nsPipe::GetWriteSegment(char*& aSegment, uint32_t& aSegmentLen) // The nsSegmentedBuffer is configured to be "infinite", so this // should never return nullptr here. char* seg = mBuffer.AppendNewSegment(); - MOZ_DIAGNOSTIC_ASSERT(seg); + if (!seg) { + return NS_ERROR_OUT_OF_MEMORY; + } LOG(("OOO appended new segment\n")); mWriteCursor = seg; From a4cf573971b8c51c1801b26af34b08bbfe7cd78d Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sat, 14 Jan 2017 15:02:14 +0900 Subject: [PATCH 50/54] Bug 1330824 - Add truncate for nsAString and nsACString. r=mystor MozReview-Commit-ID: 2ND5ra3buxI --- xpcom/rust/nsstring/src/lib.rs | 14 ++++++++++++++ xpcom/string/nsSubstring.cpp | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/xpcom/rust/nsstring/src/lib.rs b/xpcom/rust/nsstring/src/lib.rs index 270c17488486..cc61fa1beac8 100644 --- a/xpcom/rust/nsstring/src/lib.rs +++ b/xpcom/rust/nsstring/src/lib.rs @@ -601,6 +601,12 @@ impl nsACString { pub unsafe fn as_str_unchecked(&self) -> &str { str::from_utf8_unchecked(self) } + + pub fn truncate(&mut self) { + unsafe { + Gecko_TruncateCString(self); + } + } } impl<'a> From<&'a str> for nsCString<'a> { @@ -704,6 +710,12 @@ impl nsAString { Gecko_AppendUTF8toString(self, &*s); } } + + pub fn truncate(&mut self) { + unsafe { + Gecko_TruncateString(self); + } + } } // NOTE: The From impl for a string slice for nsString produces a <'static> @@ -757,10 +769,12 @@ extern "C" { fn Gecko_FinalizeCString(this: *mut nsACString); fn Gecko_AssignCString(this: *mut nsACString, other: *const nsACString); fn Gecko_AppendCString(this: *mut nsACString, other: *const nsACString); + fn Gecko_TruncateCString(this: *mut nsACString); fn Gecko_FinalizeString(this: *mut nsAString); fn Gecko_AssignString(this: *mut nsAString, other: *const nsAString); fn Gecko_AppendString(this: *mut nsAString, other: *const nsAString); + fn Gecko_TruncateString(this: *mut nsAString); // Gecko implementation in nsReadableUtils.cpp fn Gecko_AppendUTF16toCString(this: *mut nsACString, other: *const nsAString); diff --git a/xpcom/string/nsSubstring.cpp b/xpcom/string/nsSubstring.cpp index d7b987d06f6e..2aab81c0370b 100644 --- a/xpcom/string/nsSubstring.cpp +++ b/xpcom/string/nsSubstring.cpp @@ -368,6 +368,11 @@ void Gecko_AppendCString(nsACString* aThis, const nsACString* aOther) aThis->Append(*aOther); } +void Gecko_TruncateCString(nsACString* aThis) +{ + aThis->Truncate(); +} + void Gecko_FinalizeString(nsAString* aThis) { aThis->~nsAString(); @@ -383,4 +388,9 @@ void Gecko_AppendString(nsAString* aThis, const nsAString* aOther) aThis->Append(*aOther); } +void Gecko_TruncateString(nsAString* aThis) +{ + aThis->Truncate(); +} + } // extern "C" From 66779abf27a81c764c77fec722510bc0a328247f Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sat, 14 Jan 2017 15:03:47 +0900 Subject: [PATCH 51/54] Bug 1330824 - Drop skip-if from test cases that failed due to animation property handling for stylo. r=heycam These test cases will not crash once the below PR gets merged into stylo tree. https://github.com/servo/servo/pull/15022 MozReview-Commit-ID: LwU3RfhfVfH --- layout/style/test/mochitest.ini | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/layout/style/test/mochitest.ini b/layout/style/test/mochitest.ini index 9d08c431efa2..78a385dd1e20 100644 --- a/layout/style/test/mochitest.ini +++ b/layout/style/test/mochitest.ini @@ -160,7 +160,7 @@ support-files = file_bug1089417_iframe.html [test_change_hint_optimizations.html] [test_clip-path_polygon.html] [test_compute_data_with_start_struct.html] -skip-if = toolkit == 'android' || stylo # bug 1330824 for stylo +skip-if = toolkit == 'android' [test_computed_style.html] [test_computed_style_min_size_auto.html] [test_computed_style_no_pseudo.html] @@ -272,7 +272,6 @@ skip-if = stylo # timeout bug 1328499 [test_transitions_cancel_near_end.html] skip-if = stylo # timeout bug 1328499 [test_transitions_computed_values.html] -skip-if = stylo # bug 1330825 [test_transitions_computed_value_combinations.html] [test_transitions_events.html] skip-if = stylo # timeout bug 1328499 @@ -302,11 +301,10 @@ support-files = unprefixing_service_iframe.html unprefixing_service_utils.js [test_unprefixing_service_prefs.html] support-files = unprefixing_service_iframe.html unprefixing_service_utils.js [test_value_cloning.html] -skip-if = toolkit == 'android' || stylo # bug 775227 for android, bug 1330824 for stylo +skip-if = toolkit == 'android' # bug 775227 for android [test_value_computation.html] -skip-if = toolkit == 'android' || stylo # bug 1330824 for stylo +skip-if = toolkit == 'android' [test_value_storage.html] -skip-if = stylo # bug 1330824 [test_variable_serialization_computed.html] [test_variable_serialization_specified.html] [test_variables.html] From 4d95c4db20572bb926e112185db14e0bb29aac08 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Tue, 10 Jan 2017 23:50:16 -0800 Subject: [PATCH 52/54] Bug 1330496 - Part 1: Remove MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA support for inheriting stdout/stderr handles on XP. r=bobowen MozReview-Commit-ID: B7qJdK2sjv5 --HG-- extra : rebase_source : 4053054009359c0a775dae5ad5e24ba74b4c7c7b extra : amend_source : 3231886a86fd03ac52f3717e22f33a7b4dc41f54 extra : histedit_source : 4533b894f9894bf5c883943bc53b260faa2ae8b1 --- ipc/chromium/src/base/process_util_win.cc | 62 +++++++------------ .../sandbox/win/src/broker_services.cc | 8 --- ...romium-to-reapply-after-upstream-merge.txt | 1 - 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/ipc/chromium/src/base/process_util_win.cc b/ipc/chromium/src/base/process_util_win.cc index a97a2c663b8e..fcac62efc6b2 100644 --- a/ipc/chromium/src/base/process_util_win.cc +++ b/ipc/chromium/src/base/process_util_win.cc @@ -19,9 +19,6 @@ #include "base/win_util.h" #include -#include "prenv.h" - -#include "mozilla/WindowsVersion.h" namespace { @@ -280,13 +277,11 @@ bool LaunchApp(const std::wstring& cmdline, // We want to inherit the std handles so dump() statements and assertion // messages in the child process can be seen - but we *do not* want to // blindly have all handles inherited. Vista and later has a technique - // where only specified handles are inherited - so we use this technique if - // we can. If that technique isn't available (or it fails), we just don't - // inherit anything. This can cause us a problem for Windows XP testing, - // because we sometimes need the handles to get inherited for test logging to - // work. So we also inherit when a specific environment variable is set. + // where only specified handles are inherited - so we use this technique. + // If that fails we just don't inherit anything. DWORD dwCreationFlags = 0; BOOL bInheritHandles = FALSE; + // We use a STARTUPINFOEX, but if we can't do the thread attribute thing, we // just pass the size of a STARTUPINFO. STARTUPINFOEX startup_info_ex; @@ -302,40 +297,29 @@ bool LaunchApp(const std::wstring& cmdline, HANDLE handlesToInherit[2]; int handleCount = 0; - // Don't even bother trying pre-Vista... - if (mozilla::IsVistaOrLater()) { - // setup our handle array first - if we end up with no handles that can - // be inherited we can avoid trying to do the ThreadAttributeList dance... - HANDLE stdOut = ::GetStdHandle(STD_OUTPUT_HANDLE); - HANDLE stdErr = ::GetStdHandle(STD_ERROR_HANDLE); + // setup our handle array first - if we end up with no handles that can + // be inherited we can avoid trying to do the ThreadAttributeList dance... + HANDLE stdOut = ::GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE stdErr = ::GetStdHandle(STD_ERROR_HANDLE); - if (IsInheritableHandle(stdOut)) - handlesToInherit[handleCount++] = stdOut; - if (stdErr != stdOut && IsInheritableHandle(stdErr)) - handlesToInherit[handleCount++] = stdErr; + if (IsInheritableHandle(stdOut)) + handlesToInherit[handleCount++] = stdOut; + if (stdErr != stdOut && IsInheritableHandle(stdErr)) + handlesToInherit[handleCount++] = stdErr; - if (handleCount) { - lpAttributeList = CreateThreadAttributeList(handlesToInherit, handleCount); - if (lpAttributeList) { - // it's safe to inherit handles, so arrange for that... - startup_info.cb = sizeof(startup_info_ex); - startup_info.dwFlags |= STARTF_USESTDHANDLES; - startup_info.hStdOutput = stdOut; - startup_info.hStdError = stdErr; - startup_info.hStdInput = INVALID_HANDLE_VALUE; - startup_info_ex.lpAttributeList = lpAttributeList; - dwCreationFlags |= EXTENDED_STARTUPINFO_PRESENT; - bInheritHandles = TRUE; - } + if (handleCount) { + lpAttributeList = CreateThreadAttributeList(handlesToInherit, handleCount); + if (lpAttributeList) { + // it's safe to inherit handles, so arrange for that... + startup_info.cb = sizeof(startup_info_ex); + startup_info.dwFlags |= STARTF_USESTDHANDLES; + startup_info.hStdOutput = stdOut; + startup_info.hStdError = stdErr; + startup_info.hStdInput = INVALID_HANDLE_VALUE; + startup_info_ex.lpAttributeList = lpAttributeList; + dwCreationFlags |= EXTENDED_STARTUPINFO_PRESENT; + bInheritHandles = TRUE; } - } else if (PR_GetEnv("MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA")) { - // Even if we can't limit what gets inherited, we sometimes want to inherit - // stdout/err for testing purposes. - startup_info.dwFlags |= STARTF_USESTDHANDLES; - startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE); - startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE); - startup_info.hStdInput = INVALID_HANDLE_VALUE; - bInheritHandles = TRUE; } PROCESS_INFORMATION process_info; diff --git a/security/sandbox/chromium/sandbox/win/src/broker_services.cc b/security/sandbox/chromium/sandbox/win/src/broker_services.cc index d6acb66fdd79..c3df2efc96c4 100644 --- a/security/sandbox/chromium/sandbox/win/src/broker_services.cc +++ b/security/sandbox/chromium/sandbox/win/src/broker_services.cc @@ -409,14 +409,6 @@ ResultCode BrokerServicesBase::SpawnTarget(const wchar_t* exe_path, // have limited which handles will be inherited. inherit_handles = true; } - } else if (getenv("MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA")) { - // On pre-Vista versions even if we can't limit what gets inherited, we - // sometimes want to inherit stdout/err for testing purposes. - startup_info.startup_info()->dwFlags |= STARTF_USESTDHANDLES; - startup_info.startup_info()->hStdInput = INVALID_HANDLE_VALUE; - startup_info.startup_info()->hStdOutput = policy_base->GetStdoutHandle(); - startup_info.startup_info()->hStdError = policy_base->GetStderrHandle(); - inherit_handles = true; } // Construct the thread pool here in case it is expensive. diff --git a/security/sandbox/modifications-to-chromium-to-reapply-after-upstream-merge.txt b/security/sandbox/modifications-to-chromium-to-reapply-after-upstream-merge.txt index 62c2dac0b28f..baf6caf2edec 100644 --- a/security/sandbox/modifications-to-chromium-to-reapply-after-upstream-merge.txt +++ b/security/sandbox/modifications-to-chromium-to-reapply-after-upstream-merge.txt @@ -1,7 +1,6 @@ Please add a link to the bugzilla bug and patch name that should be re-applied. Also, please update any existing links to their actual mozilla-central changeset. -https://bugzilla.mozilla.org/show_bug.cgi?id=1287426 bug1287426part4.patch https://bugzilla.mozilla.org/show_bug.cgi?id=1287426 bug1287426part5.patch https://hg.mozilla.org/mozilla-central/rev/7df8d6639971 https://bugzilla.mozilla.org/show_bug.cgi?id=1287426 bug1287426part7.patch From cab8e99bea9ca44bbe8588bf4592d642aa82ed08 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Tue, 10 Jan 2017 23:47:32 -0800 Subject: [PATCH 53/54] Bug 1330496 - Part 2: Remove mochitest use of MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA. r=jmaher MozReview-Commit-ID: LX8F53hVySp --HG-- extra : rebase_source : 6bb8d549e3d90c210b0a1895ccbfe9a24e5345bf extra : histedit_source : 494c4537776bb1f79c6a7654a48ab901a78ee1f8 --- testing/mochitest/runrobocop.py | 2 -- testing/mochitest/runtests.py | 8 -------- testing/mochitest/runtestsremote.py | 2 -- testing/talos/talos/ffsetup.py | 3 --- 4 files changed, 15 deletions(-) diff --git a/testing/mochitest/runrobocop.py b/testing/mochitest/runrobocop.py index 94b6add8a995..d263bbc50f6f 100644 --- a/testing/mochitest/runrobocop.py +++ b/testing/mochitest/runrobocop.py @@ -396,8 +396,6 @@ class RobocopTestRunner(MochitestDesktop): xrePath=None, debugger=None) # remove desktop environment not used on device - if "MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA" in browserEnv: - del browserEnv["MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA"] if "XPCOM_MEM_BLOAT_LOG" in browserEnv: del browserEnv["XPCOM_MEM_BLOAT_LOG"] browserEnv["MOZ_LOG_FILE"] = os.path.join( diff --git a/testing/mochitest/runtests.py b/testing/mochitest/runtests.py index 3c29945f7e99..c61e9c209e3d 100644 --- a/testing/mochitest/runtests.py +++ b/testing/mochitest/runtests.py @@ -1483,14 +1483,6 @@ toolbar#nav-bar { # via the commandline at your own risk. browserEnv["XPCOM_DEBUG_BREAK"] = "stack" - # When creating child processes on Windows pre-Vista (e.g. Windows XP) we - # don't normally inherit stdout/err handles, because you can only do it by - # inheriting all other inheritable handles as well. - # We need to inherit them for plain mochitests for test logging purposes, so - # we do so on the basis of a specific environment variable. - if options.flavor == 'plain': - browserEnv["MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA"] = "1" - # interpolate environment passed with options try: browserEnv.update( diff --git a/testing/mochitest/runtestsremote.py b/testing/mochitest/runtestsremote.py index 8010703e94a1..51ed683f72d9 100644 --- a/testing/mochitest/runtestsremote.py +++ b/testing/mochitest/runtestsremote.py @@ -266,8 +266,6 @@ class MochiRemote(MochitestDesktop): options, debugger=debugger) # remove desktop environment not used on device - if "MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA" in browserEnv: - del browserEnv["MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA"] if "XPCOM_MEM_BLOAT_LOG" in browserEnv: del browserEnv["XPCOM_MEM_BLOAT_LOG"] # override mozLogs to avoid processing in MochitestDesktop base class diff --git a/testing/talos/talos/ffsetup.py b/testing/talos/talos/ffsetup.py index 22a9dea07f3a..45c43a6c3bbd 100644 --- a/testing/talos/talos/ffsetup.py +++ b/testing/talos/talos/ffsetup.py @@ -64,9 +64,6 @@ class FFSetup(object): for k, v in self.browser_config['env'].iteritems(): self.env[k] = str(v) self.env['MOZ_CRASHREPORTER_NO_REPORT'] = '1' - # for winxp e10s logging: - # https://bugzilla.mozilla.org/show_bug.cgi?id=1037445 - self.env['MOZ_WIN_INHERIT_STD_HANDLES_PRE_VISTA'] = '1' if self.browser_config['symbols_path']: self.env['MOZ_CRASHREPORTER'] = '1' else: From 971f368adf9a306806622867a096aaf99c984f06 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Mon, 9 Jan 2017 21:03:57 -0800 Subject: [PATCH 54/54] Bug 1330496 - Part 3: Remove other ipc checks for Windows Vista or 7+. r=aklotz MozReview-Commit-ID: 9z5LKw71Veg --HG-- extra : rebase_source : 34e4edb7f5dd92cdca0ca638398705ded48bd3bc extra : histedit_source : 06350bb2aa8baf386431e634d63819d87cd18fe1 --- ipc/glue/WindowsMessageLoop.cpp | 3 +-- ipc/mscom/MainThreadRuntime.cpp | 17 ++--------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/ipc/glue/WindowsMessageLoop.cpp b/ipc/glue/WindowsMessageLoop.cpp index 7854a507158c..642504b70ad8 100644 --- a/ipc/glue/WindowsMessageLoop.cpp +++ b/ipc/glue/WindowsMessageLoop.cpp @@ -19,7 +19,6 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/ipc/ProtocolUtils.h" #include "mozilla/PaintTracker.h" -#include "mozilla/WindowsVersion.h" using namespace mozilla; using namespace mozilla::ipc; @@ -1022,7 +1021,7 @@ MessageChannel::WaitForSyncNotify(bool aHandleWindowsMessages) MOZ_ASSERT(gUIThreadId, "InitUIThread was not called!"); #if defined(ACCESSIBILITY) - if (IsVistaOrLater() && (mFlags & REQUIRE_A11Y_REENTRY)) { + if ((mFlags & REQUIRE_A11Y_REENTRY)) { MOZ_ASSERT(!(mFlags & REQUIRE_DEFERRED_MESSAGE_PROTECTION)); return WaitForSyncNotifyWithA11yReentry(); } diff --git a/ipc/mscom/MainThreadRuntime.cpp b/ipc/mscom/MainThreadRuntime.cpp index d863179667d7..3563eb874924 100644 --- a/ipc/mscom/MainThreadRuntime.cpp +++ b/ipc/mscom/MainThreadRuntime.cpp @@ -10,7 +10,6 @@ #include "mozilla/Assertions.h" #include "mozilla/RefPtr.h" #include "mozilla/UniquePtr.h" -#include "mozilla/WindowsVersion.h" #include "nsDebug.h" #include "nsWindowsHelpers.h" @@ -44,13 +43,6 @@ MainThreadRuntime::MainThreadRuntime() return; } - // Windows XP doesn't support setting of the COM exception policy, so we'll - // just stop here in that case. - if (!IsVistaOrLater()) { - mInitResult = S_OK; - return; - } - // We are required to initialize security in order to configure global options. mInitResult = InitializeSecurity(); MOZ_ASSERT(SUCCEEDED(mInitResult)); @@ -67,12 +59,8 @@ MainThreadRuntime::MainThreadRuntime() return; } - // Windows 7 has a policy that is even more strict. We should use that one - // whenever possible. - ULONG_PTR exceptionSetting = IsWin7OrLater() ? - COMGLB_EXCEPTION_DONOT_HANDLE_ANY : - COMGLB_EXCEPTION_DONOT_HANDLE; - mInitResult = globalOpts->Set(COMGLB_EXCEPTION_HANDLING, exceptionSetting); + mInitResult = globalOpts->Set(COMGLB_EXCEPTION_HANDLING, + COMGLB_EXCEPTION_DONOT_HANDLE_ANY); MOZ_ASSERT(SUCCEEDED(mInitResult)); } @@ -177,4 +165,3 @@ MainThreadRuntime::InitializeSecurity() } // namespace mscom } // namespace mozilla -