From a725bdfb6b39b2eee602a891e5ec417bbdbd240e Mon Sep 17 00:00:00 2001 From: cku Date: Thu, 23 Feb 2017 17:08:17 +0800 Subject: [PATCH 001/102] Bug 1224207 - (followup) remove an unused local var. r=me MozReview-Commit-ID: B7MJkHS1S88 --- layout/svg/nsFilterInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layout/svg/nsFilterInstance.cpp b/layout/svg/nsFilterInstance.cpp index 6a061183625e..2de01a7896fc 100644 --- a/layout/svg/nsFilterInstance.cpp +++ b/layout/svg/nsFilterInstance.cpp @@ -264,7 +264,6 @@ nsFilterInstance::ComputeTargetBBoxInFilterSpace() bool nsFilterInstance::ComputeUserSpaceToFilterSpaceScale() { - gfxMatrix canvasTransform; if (mTargetFrame) { mUserSpaceToFilterSpaceScale = mPaintTransform.ScaleFactors(true); if (mUserSpaceToFilterSpaceScale.width <= 0.0f || @@ -279,6 +278,7 @@ nsFilterInstance::ComputeUserSpaceToFilterSpaceScale() mFilterSpaceToUserSpaceScale = gfxSize(1.0f / mUserSpaceToFilterSpaceScale.width, 1.0f / mUserSpaceToFilterSpaceScale.height); + return true; } From c3b73ba038e39dee105cd3ead3df83d4973e7ece Mon Sep 17 00:00:00 2001 From: Ethan Lin Date: Thu, 23 Feb 2017 17:34:14 +0800 Subject: [PATCH 002/102] Bug 1340082 - Convert nsDisplayOutline to WebRenderDisplayItemLayer. r=mattwoodrow --- gfx/thebes/gfxPrefs.h | 1 + layout/painting/moz.build | 1 + layout/painting/nsCSSRendering.cpp | 54 ++++++++++++++------ layout/painting/nsCSSRendering.h | 7 +++ layout/painting/nsCSSRenderingBorders.h | 3 +- layout/painting/nsDisplayList.cpp | 67 +++++++++++++++++++++++++ layout/painting/nsDisplayList.h | 11 ++++ 7 files changed, 127 insertions(+), 17 deletions(-) diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index e8bc5cce5f52..354df182153f 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -461,6 +461,7 @@ private: DECL_GFX_PREF(Live, "layers.advanced.bullet-layers", LayersAllowBulletLayers, bool, false); DECL_GFX_PREF(Live, "layers.advanced.caret-layers", LayersAllowCaretLayers, bool, false); DECL_GFX_PREF(Live, "layers.advanced.boxshadow-outer-layers", LayersAllowOuterBoxShadow, bool, false); + DECL_GFX_PREF(Live, "layers.advanced.outline-layers", LayersAllowOutlineLayers, bool, false); DECL_GFX_PREF(Once, "layers.allow-d3d9-fallback", LayersAllowD3D9Fallback, bool, false); DECL_GFX_PREF(Once, "layers.amd-switchable-gfx.enabled", LayersAMDSwitchableGfxEnabled, bool, false); DECL_GFX_PREF(Once, "layers.async-pan-zoom.enabled", AsyncPanZoomEnabledDoNotUseDirectly, bool, true); diff --git a/layout/painting/moz.build b/layout/painting/moz.build index 508e8d95edbf..932bc6d3256b 100644 --- a/layout/painting/moz.build +++ b/layout/painting/moz.build @@ -15,6 +15,7 @@ EXPORTS += [ 'DisplayListClipState.h', 'FrameLayerBuilder.h', 'LayerState.h', + 'nsCSSRenderingBorders.h', 'nsDisplayItemTypes.h', 'nsDisplayItemTypesList.h', 'nsDisplayList.h', diff --git a/layout/painting/nsCSSRendering.cpp b/layout/painting/nsCSSRendering.cpp index 9a3a86bd2418..e222cd7b4f50 100644 --- a/layout/painting/nsCSSRendering.cpp +++ b/layout/painting/nsCSSRendering.cpp @@ -948,13 +948,13 @@ GetOutlineInnerRect(nsIFrame* aFrame) return nsRect(nsPoint(0, 0), aFrame->GetSize()); } -void -nsCSSRendering::PaintOutline(nsPresContext* aPresContext, - nsRenderingContext& aRenderingContext, - nsIFrame* aForFrame, - const nsRect& aDirtyRect, - const nsRect& aBorderArea, - nsStyleContext* aStyleContext) +Maybe +nsCSSRendering::CreateBorderRendererForOutline(nsPresContext* aPresContext, + nsRenderingContext* aRenderingContext, + nsIFrame* aForFrame, + const nsRect& aDirtyRect, + const nsRect& aBorderArea, + nsStyleContext* aStyleContext) { nscoord twipsRadii[8]; @@ -968,7 +968,7 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext, if (width == 0 && outlineStyle != NS_STYLE_BORDER_STYLE_AUTO) { // Empty outline - return; + return Nothing(); } nsIFrame* bgFrame = nsCSSRendering::FindNonTransparentBackgroundFrame @@ -997,7 +997,7 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext, // encroach into the content area. A safer calculation would be to // shorten insideRect by the radius one each side before performing this test. if (innerRect.Contains(aDirtyRect)) - return; + return Nothing(); nsRect outerRect = innerRect; outerRect.Inflate(width, width); @@ -1022,14 +1022,14 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext, nsITheme* theme = aPresContext->GetTheme(); if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, NS_THEME_FOCUS_OUTLINE)) { - theme->DrawWidgetBackground(&aRenderingContext, aForFrame, + theme->DrawWidgetBackground(aRenderingContext, aForFrame, NS_THEME_FOCUS_OUTLINE, innerRect, aDirtyRect); - return; + return Nothing(); } } if (width == 0) { - return; // empty outline + return Nothing(); // empty outline } // http://dev.w3.org/csswg/css-ui/#outline // "User agents may treat 'auto' as 'solid'." @@ -1061,11 +1061,10 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext, document = content->OwnerDoc(); } - // start drawing - + DrawTarget* dt = aRenderingContext ? aRenderingContext->GetDrawTarget() : nullptr; nsCSSBorderRenderer br(aPresContext, document, - aRenderingContext.GetDrawTarget(), + dt, dirtyRect, oRect, outlineStyles, @@ -1074,7 +1073,30 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext, outlineColors, nullptr, bgColor); - br.DrawBorders(); + + return Some(br); +} + +void +nsCSSRendering::PaintOutline(nsPresContext* aPresContext, + nsRenderingContext& aRenderingContext, + nsIFrame* aForFrame, + const nsRect& aDirtyRect, + const nsRect& aBorderArea, + nsStyleContext* aStyleContext) +{ + Maybe br = CreateBorderRendererForOutline(aPresContext, + &aRenderingContext, + aForFrame, + aDirtyRect, + aBorderArea, + aStyleContext); + if (!br) { + return; + } + + // start drawing + br->DrawBorders(); PrintAsStringNewline(); } diff --git a/layout/painting/nsCSSRendering.h b/layout/painting/nsCSSRendering.h index 55dc35d8d770..82438ec305ef 100644 --- a/layout/painting/nsCSSRendering.h +++ b/layout/painting/nsCSSRendering.h @@ -438,6 +438,13 @@ struct nsCSSRendering { nsStyleContext* aStyleContext, Sides aSkipSides = Sides()); + static mozilla::Maybe + CreateBorderRendererForOutline(nsPresContext* aPresContext, + nsRenderingContext* aRenderingContext, + nsIFrame* aForFrame, + const nsRect& aDirtyRect, + const nsRect& aBorderArea, + nsStyleContext* aStyleContext); /** * Render the outline for an element using css rendering rules diff --git a/layout/painting/nsCSSRenderingBorders.h b/layout/painting/nsCSSRenderingBorders.h index 65a25f8e72d8..26c96b35c1ad 100644 --- a/layout/painting/nsCSSRenderingBorders.h +++ b/layout/painting/nsCSSRenderingBorders.h @@ -78,6 +78,7 @@ class nsCSSBorderRenderer final typedef mozilla::gfx::StrokeOptions StrokeOptions; friend class nsDisplayBorder; + friend class nsDisplayOutline; public: @@ -121,7 +122,7 @@ private: // destination DrawTarget and dirty rect DrawTarget* mDrawTarget; - const Rect mDirtyRect; + Rect mDirtyRect; // the rectangle of the outside and the inside of the border Rect mOuterRect; diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 91434a0737d3..91f0e63783cf 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -85,6 +85,7 @@ #include "mozilla/layers/WebRenderLayerManager.h" #include "mozilla/layers/WebRenderDisplayItemLayer.h" #include "mozilla/layers/WebRenderMessages.h" +#include "mozilla/layers/WebRenderDisplayItemLayer.h" // GetCurrentTime is defined in winbase.h as zero argument macro forwarding to // GetTickCount(). @@ -4090,6 +4091,72 @@ nsDisplayOutline::Paint(nsDisplayListBuilder* aBuilder, mFrame->StyleContext()); } +LayerState +nsDisplayOutline::GetLayerState(nsDisplayListBuilder* aBuilder, + LayerManager* aManager, + const ContainerLayerParameters& aParameters) +{ + if (!gfxPrefs::LayersAllowOutlineLayers()) { + return LAYER_NONE; + } + + uint8_t outlineStyle = mFrame->StyleContext()->StyleOutline()->mOutlineStyle; + if (outlineStyle == NS_STYLE_BORDER_STYLE_AUTO && nsLayoutUtils::IsOutlineStyleAutoEnabled()) { + nsITheme* theme = mFrame->PresContext()->GetTheme(); + if (theme && theme->ThemeSupportsWidget(mFrame->PresContext(), mFrame, + NS_THEME_FOCUS_OUTLINE)) { + return LAYER_NONE; + } + } + + nsPoint offset = ToReferenceFrame(); + Maybe br = + nsCSSRendering::CreateBorderRendererForOutline(mFrame->PresContext(), + nullptr, mFrame, + mVisibleRect, + nsRect(offset, mFrame->GetSize()), + mFrame->StyleContext()); + + if (!br) { + return LAYER_NONE; + } + + mBorderRenderer = br; + + return LAYER_ACTIVE; +} + +already_AddRefed +nsDisplayOutline::BuildLayer(nsDisplayListBuilder* aBuilder, + LayerManager* aManager, + const ContainerLayerParameters& aContainerParameters) +{ + return BuildDisplayItemLayer(aBuilder, aManager, aContainerParameters); +} + +void +nsDisplayOutline::CreateWebRenderCommands(nsTArray& aCommands, + WebRenderDisplayItemLayer* aLayer) +{ + MOZ_ASSERT(mBorderRenderer.isSome()); + + Rect outlineTransformedRect = aLayer->RelativeToParent(mBorderRenderer->mOuterRect); + + nsCSSBorderRenderer* br = mBorderRenderer.ptr(); + WrBorderSide side[4]; + NS_FOR_CSS_SIDES(i) { + side[i] = wr::ToWrBorderSide(br->mBorderWidths[i], ToDeviceColor(br->mBorderColors[i]), br->mBorderStyles[i]); + } + WrBorderRadius borderRadius = wr::ToWrBorderRadius(LayerSize(br->mBorderRadii[0].width, br->mBorderRadii[0].height), + LayerSize(br->mBorderRadii[1].width, br->mBorderRadii[1].height), + LayerSize(br->mBorderRadii[3].width, br->mBorderRadii[3].height), + LayerSize(br->mBorderRadii[2].width, br->mBorderRadii[2].height)); + aCommands.AppendElement(OpDPPushBorder(wr::ToWrRect(outlineTransformedRect), + wr::ToWrRect(outlineTransformedRect), + side[0], side[1], side[2], side[3], + borderRadius)); +} + bool nsDisplayOutline::IsInvisibleInRect(const nsRect& aRect) { diff --git a/layout/painting/nsDisplayList.h b/layout/painting/nsDisplayList.h index bdc5a7154fef..80e6eb00b495 100644 --- a/layout/painting/nsDisplayList.h +++ b/layout/painting/nsDisplayList.h @@ -34,6 +34,7 @@ #include "mozilla/UniquePtr.h" #include "mozilla/TimeStamp.h" #include "mozilla/gfx/UserData.h" +#include "nsCSSRenderingBorders.h" #include #include "nsTHashtable.h" @@ -3453,10 +3454,20 @@ public: } #endif + virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, + LayerManager* aManager, + const ContainerLayerParameters& aParameters) override; + virtual already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, + LayerManager* aManager, + const ContainerLayerParameters& aContainerParameters) override; + virtual void CreateWebRenderCommands(nsTArray& aCommands, + mozilla::layers::WebRenderDisplayItemLayer* aLayer) override; virtual bool IsInvisibleInRect(const nsRect& aRect) override; virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override; virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override; NS_DISPLAY_DECL_NAME("Outline", TYPE_OUTLINE) + + mozilla::Maybe mBorderRenderer; }; /** From acaca693becc47e5e02b4af89d59d76ae419c9f7 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 23 Feb 2017 10:51:52 +0100 Subject: [PATCH 003/102] Bug 1340450 - When containers are disabled, it should not be possible to reopen container tabs, r=mdeboer --- .../preferences/in-content/privacy.js | 2 + .../components/sessionstore/SessionStore.jsm | 36 ++++++++- .../components/sessionstore/test/browser.ini | 2 + .../test/browser_disable_containers.js | 76 +++++++++++++++++++ .../ContextualIdentityService.jsm | 7 ++ 5 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 browser/components/sessionstore/test/browser_disable_containers.js diff --git a/browser/components/preferences/in-content/privacy.js b/browser/components/preferences/in-content/privacy.js index 6d557b80eae6..7a9d5b6f6dd5 100644 --- a/browser/components/preferences/in-content/privacy.js +++ b/browser/components/preferences/in-content/privacy.js @@ -85,6 +85,7 @@ var gPrivacyPane = { let count = ContextualIdentityService.countContainerTabs(); if (count == 0) { + ContextualIdentityService.disableContainers(); Services.prefs.setBoolPref("privacy.userContext.enabled", false); return; } @@ -105,6 +106,7 @@ var gPrivacyPane = { okButton, cancelButton, null, null, {}); if (rv == 0) { ContextualIdentityService.closeContainerTabs(); + ContextualIdentityService.disableContainers(); Services.prefs.setBoolPref("privacy.userContext.enabled", false); return; } diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm index c4b680e0d92f..2fc7cd098b5a 100644 --- a/browser/components/sessionstore/SessionStore.jsm +++ b/browser/components/sessionstore/SessionStore.jsm @@ -45,7 +45,7 @@ const OBSERVING = [ "quit-application-granted", "browser-lastwindow-close-granted", "quit-application", "browser:purge-session-history", "browser:purge-domain-data", - "idle-daily", + "idle-daily", "clear-origin-attributes-data" ]; // XUL Window properties to (re)store @@ -748,6 +748,13 @@ var SessionStoreInternal = { this.onIdleDaily(); this._notifyOfClosedObjectsChange(); break; + case "clear-origin-attributes-data": + let userContextId = 0; + try { + userContextId = JSON.parse(aData).userContextId; + } catch(e) {} + if (userContextId) + this._forgetTabsWithUserContextId(userContextId); } }, @@ -2582,6 +2589,33 @@ var SessionStoreInternal = { return undefined; }, + // This method deletes all the closedTabs matching userContextId. + _forgetTabsWithUserContextId(userContextId) { + let windowsEnum = Services.wm.getEnumerator("navigator:browser"); + while (windowsEnum.hasMoreElements()) { + let window = windowsEnum.getNext(); + let windowState = this._windows[window.__SSi]; + if (windowState) { + // In order to remove the tabs in the correct order, we store the + // indexes, into an array, then we revert the array and remove closed + // data from the last one going backward. + let indexes = []; + windowState._closedTabs.forEach((closedTab, index) => { + if (closedTab.state.userContextId == userContextId) { + indexes.push(index); + } + }); + + for (let index of indexes.reverse()) { + this.removeClosedTabData(windowState._closedTabs, index); + } + } + } + + // Notify of changes to closed objects. + this._notifyOfClosedObjectsChange(); + }, + /** * Restores the session state stored in LastSession. This will attempt * to merge data into the current session. If a window was opened at startup diff --git a/browser/components/sessionstore/test/browser.ini b/browser/components/sessionstore/test/browser.ini index 4566f3a0c605..8ac1ffec7c1a 100644 --- a/browser/components/sessionstore/test/browser.ini +++ b/browser/components/sessionstore/test/browser.ini @@ -243,3 +243,5 @@ skip-if = !e10s # GroupedSHistory is e10s-only [browser_closed_objects_changed_notifications_tabs.js] [browser_closed_objects_changed_notifications_windows.js] + +[browser_disable_containers.js] diff --git a/browser/components/sessionstore/test/browser_disable_containers.js b/browser/components/sessionstore/test/browser_disable_containers.js new file mode 100644 index 000000000000..c07297170c90 --- /dev/null +++ b/browser/components/sessionstore/test/browser_disable_containers.js @@ -0,0 +1,76 @@ +"use strict"; + +/** + * This test is to see if tabs can be reopened when containers are disabled. + */ + +async function openAndCloseTab(window, userContextId, url) { + let tab = window.gBrowser.addTab(url, { userContextId }); + await promiseBrowserLoaded(tab.linkedBrowser, true, url); + await TabStateFlusher.flush(tab.linkedBrowser); + await promiseRemoveTab(tab); +} + +async function openTab(window, userContextId, url) { + let tab = window.gBrowser.addTab(url, { userContextId }); + await promiseBrowserLoaded(tab.linkedBrowser, true, url); + await TabStateFlusher.flush(tab.linkedBrowser); +} + +async function openWindow(url) { + let win = await promiseNewWindowLoaded(); + let flags = Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY; + win.gBrowser.selectedBrowser.loadURIWithFlags(url, flags); + await promiseBrowserLoaded(win.gBrowser.selectedBrowser, true, url); + return win; +} + +add_task(function* test_undoCloseById() { + // Clear the lists of closed windows and tabs. + forgetClosedWindows(); + while (SessionStore.getClosedTabCount(window)) { + SessionStore.forgetClosedTab(window, 0); + } + + // Open a new window. + let win = yield openWindow("about:robots"); + + // Open and close a tab. + yield openAndCloseTab(win, 0, "about:mozilla"); + is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab"); + + // Open and close a container tab. + yield openAndCloseTab(win, 3, "about:about"); + is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab"); + + // Restore the last closed tab. + let tab = SessionStore.undoCloseTab(win, 0); + yield promiseBrowserLoaded(tab.linkedBrowser); + is(tab.linkedBrowser.currentURI.spec, "about:about", "The expected tab was re-opened"); + is(tab.getAttribute("usercontextid"), 3, "Expected the tab userContextId to match"); + + // Open a few container tabs. + yield openTab(win, 1, "about:config"); + yield openTab(win, 1, "about:preferences"); + yield openTab(win, 2, "about:support"); + + // Let's simulate the disabling of containers. + ContextualIdentityService.closeContainerTabs(); + ContextualIdentityService.disableContainers(); + yield TabStateFlusher.flushWindow(win); + + // Let's check we don't have container tab opened. + for (let i = 0; i < win.gBrowser.tabContainer.childNodes.length; ++i) { + let tab = win.gBrowser.tabContainer.childNodes[i]; + ok(!tab.hasAttribute("usercontextid"), "No userContextId for this tab"); + } + + // Restore the last closed tab (we don't want the container tabs). + tab = SessionStore.undoCloseTab(win, 0); + yield promiseBrowserLoaded(tab.linkedBrowser); + is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "The expected tab was re-opened"); + ok(!tab.hasAttribute("usercontextid"), "No userContextId for this tab"); + + // Close the window again. + yield BrowserTestUtils.closeWindow(win); +}); diff --git a/toolkit/components/contextualidentity/ContextualIdentityService.jsm b/toolkit/components/contextualidentity/ContextualIdentityService.jsm index 6bd4081326d8..dd7a6d8d98d9 100644 --- a/toolkit/components/contextualidentity/ContextualIdentityService.jsm +++ b/toolkit/components/contextualidentity/ContextualIdentityService.jsm @@ -298,6 +298,13 @@ _ContextualIdentityService.prototype = { }, userContextId); }, + disableContainers() { + for (let identity of this._identities) { + Services.obs.notifyObservers(null, "clear-origin-attributes-data", + JSON.stringify({ userContextId: identity.userContextId })); + } + }, + _forEachContainerTab(callback, userContextId = 0) { let windowList = Services.wm.getEnumerator("navigator:browser"); while (windowList.hasMoreElements()) { From 911e4b5b82e8a461f3da82b4ec7644a62a387c75 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 22 Feb 2017 18:37:49 +0100 Subject: [PATCH 004/102] Bug 1341650: A few drive-by nits fixing in WasmBaselineCompile.cpp; r=lth MozReview-Commit-ID: 9SpdNG8sL9y --- js/src/jit/MacroAssembler.cpp | 2 +- js/src/wasm/WasmBaselineCompile.cpp | 50 +++++++++++++++-------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/js/src/jit/MacroAssembler.cpp b/js/src/jit/MacroAssembler.cpp index b0ad34e14e24..58c801af07a6 100644 --- a/js/src/jit/MacroAssembler.cpp +++ b/js/src/jit/MacroAssembler.cpp @@ -2807,7 +2807,7 @@ MacroAssembler::wasmCallBuiltinInstanceMethod(const ABIArg& instanceArg, if (instanceArg.kind() == ABIArg::GPR) { loadPtr(Address(WasmTlsReg, offsetof(wasm::TlsData, instance)), instanceArg.gpr()); } else if (instanceArg.kind() == ABIArg::Stack) { - // Safe to use ABINonArgReg0 since its the last thing before the call + // Safe to use ABINonArgReg0 since it's the last thing before the call. Register scratch = ABINonArgReg0; loadPtr(Address(WasmTlsReg, offsetof(wasm::TlsData, instance)), scratch); storePtr(scratch, Address(getStackPointer(), instanceArg.offsetFromArgBase())); diff --git a/js/src/wasm/WasmBaselineCompile.cpp b/js/src/wasm/WasmBaselineCompile.cpp index 8de489e1f87e..1ff8637aadd8 100644 --- a/js/src/wasm/WasmBaselineCompile.cpp +++ b/js/src/wasm/WasmBaselineCompile.cpp @@ -2046,31 +2046,31 @@ class BaseCompiler AllocatableGeneralRegisterSet knownGPR_ = availGPR_; AllocatableFloatRegisterSet knownFPU_ = availFPU_; for (size_t i = 0 ; i < stk_.length() ; i++) { - Stk& item = stk_[i]; - switch (item.kind_) { - case Stk::RegisterI32: - knownGPR_.add(item.i32reg()); - break; - case Stk::RegisterI64: + Stk& item = stk_[i]; + switch (item.kind_) { + case Stk::RegisterI32: + knownGPR_.add(item.i32reg()); + break; + case Stk::RegisterI64: #ifdef JS_PUNBOX64 - knownGPR_.add(item.i64reg().reg); + knownGPR_.add(item.i64reg().reg); #else - knownGPR_.add(item.i64reg().high); - knownGPR_.add(item.i64reg().low); + knownGPR_.add(item.i64reg().high); + knownGPR_.add(item.i64reg().low); #endif - break; - case Stk::RegisterF32: - knownFPU_.add(item.f32reg()); - break; - case Stk::RegisterF64: - knownFPU_.add(item.f64reg()); - break; - default: - break; - } - } - MOZ_ASSERT(knownGPR_.bits() == allGPR_.bits()); - MOZ_ASSERT(knownFPU_.bits() == allFPU_.bits()); + break; + case Stk::RegisterF32: + knownFPU_.add(item.f32reg()); + break; + case Stk::RegisterF64: + knownFPU_.add(item.f64reg()); + break; + default: + break; + } + } + MOZ_ASSERT(knownGPR_.bits() == allGPR_.bits()); + MOZ_ASSERT(knownFPU_.bits() == allFPU_.bits()); } #endif @@ -2908,7 +2908,8 @@ class BaseCompiler // movl clears the high bits if the two registers are the same. masm.movl(src.reg, dest); #elif defined(JS_NUNBOX32) - masm.move32(src.low, dest); + if (src.low != dest) + masm.move32(src.low, dest); #else MOZ_CRASH("BaseCompiler platform hook: wrapI64ToI32"); #endif @@ -2947,7 +2948,8 @@ class BaseCompiler #if defined(JS_CODEGEN_X64) masm.movl(src, dest.reg); #elif defined(JS_NUNBOX32) - masm.move32(src, dest.low); + if (src != dest.low) + masm.move32(src, dest.low); masm.move32(Imm32(0), dest.high); #else MOZ_CRASH("BaseCompiler platform hook: extendU32ToI64"); From 1ea806c25a00b6204c0157872314cf10923f3726 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 22 Feb 2017 18:44:34 +0100 Subject: [PATCH 005/102] Bug 1341650: Pass TLS when calling wasm current_memory in the Ion backend; r=luke MozReview-Commit-ID: 2mLxEqdvGtK --- js/src/wasm/WasmIonCompile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/wasm/WasmIonCompile.cpp b/js/src/wasm/WasmIonCompile.cpp index 3953dbd46e67..5c7d41d962bc 100644 --- a/js/src/wasm/WasmIonCompile.cpp +++ b/js/src/wasm/WasmIonCompile.cpp @@ -2997,7 +2997,7 @@ EmitCurrentMemory(FunctionCompiler& f) if (!f.passInstance(&args)) return false; - f.finishCall(&args, TlsUsage::Unused); + f.finishCall(&args, TlsUsage::Need); MDefinition* ret; if (!f.builtinInstanceMethodCall(SymbolicAddress::CurrentMemory, args, ValType::I32, &ret)) From 9f3c149846b80b0d6912d0ca491a96f1895b2dcb Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 22 Feb 2017 18:39:39 +0100 Subject: [PATCH 006/102] Bug 1341650: Don't clobber the last stack slot when calling into CurrentMemory/GrowMemory in the wasm baseline; r=lth MozReview-Commit-ID: 4BxLPKakvdV --- .../tests/wasm/regress/current-memory-tls.js | 97 +++++++++++++++++++ js/src/wasm/WasmBaselineCompile.cpp | 10 +- 2 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 js/src/jit-test/tests/wasm/regress/current-memory-tls.js diff --git a/js/src/jit-test/tests/wasm/regress/current-memory-tls.js b/js/src/jit-test/tests/wasm/regress/current-memory-tls.js new file mode 100644 index 000000000000..b252d1ef3080 --- /dev/null +++ b/js/src/jit-test/tests/wasm/regress/current-memory-tls.js @@ -0,0 +1,97 @@ +load(libdir + "wasm.js"); + +// Bug 1341650: +// - when compiled with Ion, pass the TLS register to current_memory; +// - when compiled with Baseline, don't clobber the last stack slot when +// calling into current_memory/grow_memory; + +// This toy module starts with an empty memory, then tries to set values at different +// indexes, automatically growing memory when that would trigger an out of +// bounds access, for the exact right amount of pages. Note it's not made for +// efficiency, but optimizing it doesn't trigger the bugs mentioned above. + +let i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(` +(module + (memory $mem (export "mem") 0 65535) + + (func (export "cur_mem") (result i32) (current_memory)) + + (func $maybeGrow (param $i i32) (local $smem i32) + ;; get current_memory in number of bytes, not pages. + current_memory + i64.extend_u/i32 + i64.const 65536 + i64.mul + + ;; get the last byte index accessed by an int32 access. + get_local $i + i32.const 3 + i32.add + tee_local $i + i64.extend_u/i32 + + ;; if the memory is too small, grow it. + i64.le_u + if + ;; get the floor of the accessed *page* index. + get_local $i + i64.extend_u/i32 + i64.const 65536 + i64.div_u + + ;; subtract to that the size of the current memory in pages; + ;; that's the amount of pages we want to grow, minus one. + current_memory + i64.extend_u/i32 + + i64.sub + + ;; add 1 to that amount. + i64.const 1 + i64.add + + ;; get back to i32 and grow memory. + i32.wrap/i64 + grow_memory + drop + end + ) + + (func (export "set") (param $i i32) (param $v i32) + get_local $i + call $maybeGrow + get_local $i + get_local $v + i32.store + ) + + (func (export "get") (param $i i32) (result i32) + get_local $i + i32.load + ) +) +`))).exports; + +assertEq(i.cur_mem(), 0); + +i.set(0, 1); +assertEq(i.get(0), 1); + +assertEq(i.cur_mem(), 1); + +i.set(1234, 1); +assertEq(i.get(1234), 1); + +assertEq(i.cur_mem(), 1); + +i.set(65532, 1); +assertEq(i.get(65532), 1); + +assertErrorMessage(() => i.get(65533), WebAssembly.RuntimeError, /index out of bounds/); + +assertEq(i.cur_mem(), 1); + +i.set(65533, 1); +assertEq(i.get(65533), 1); + +assertEq(i.cur_mem(), 2); diff --git a/js/src/wasm/WasmBaselineCompile.cpp b/js/src/wasm/WasmBaselineCompile.cpp index 1ff8637aadd8..ebadecb1e5ed 100644 --- a/js/src/wasm/WasmBaselineCompile.cpp +++ b/js/src/wasm/WasmBaselineCompile.cpp @@ -2389,7 +2389,10 @@ class BaseCompiler void startCallArgs(FunctionCall& call, size_t stackArgAreaSize) { - call.stackArgAreaSize = stackArgAreaSize; + // It's possible the TLS pointer may have implicitly used stack before. + MOZ_ASSERT(call.stackArgAreaSize == 0 || call.stackArgAreaSize == sizeof(void*)); + + call.stackArgAreaSize += stackArgAreaSize; size_t adjustment = call.stackArgAreaSize + call.frameAlignAdjustment; if (adjustment) @@ -2397,7 +2400,10 @@ class BaseCompiler } const ABIArg reservePointerArgument(FunctionCall& call) { - return call.abi.next(MIRType::Pointer); + ABIArg ret = call.abi.next(MIRType::Pointer); + if (ret.kind() == ABIArg::Stack) + call.stackArgAreaSize += sizeof(void*); + return ret; } // TODO / OPTIMIZE (Bug 1316821): Note passArg is used only in one place. From f663ec22f821b4fdc11787b48c2ed5b8a0ce5a1f Mon Sep 17 00:00:00 2001 From: Deepa Date: Wed, 22 Feb 2017 23:08:48 +0530 Subject: [PATCH 007/102] Bug 1341056 - Stop setting a border for .button-box on Linux. r=dao --- toolkit/themes/linux/global/button.css | 7 ------- 1 file changed, 7 deletions(-) diff --git a/toolkit/themes/linux/global/button.css b/toolkit/themes/linux/global/button.css index cdcc66c53945..6ed09c94ca0b 100644 --- a/toolkit/themes/linux/global/button.css +++ b/toolkit/themes/linux/global/button.css @@ -20,7 +20,6 @@ button { .button-box { -moz-appearance: button-focus; - border: 1px solid transparent; padding-top: 1px; padding-bottom: 2px; padding-inline-start: 3px; @@ -36,12 +35,6 @@ button { text-align: center; } -/* .......... focused state .......... */ - -button:focus > .button-box { - border: 1px dotted ThreeDDarkShadow; -} - /* .......... hover state .......... */ button:hover { From 6348856fb36c118d7f76814556a8e57f67a188af Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 21 Feb 2017 16:09:07 +0100 Subject: [PATCH 008/102] Bug 1341090: Refactor malloc counters in Zone and GCRuntime; r=jonco MozReview-Commit-ID: K52KzVc4zSV --- js/src/gc/GCRuntime.h | 75 ++++++++++++++++++++++++++++++++----------- js/src/gc/Zone.cpp | 30 ----------------- js/src/gc/Zone.h | 43 +++++++++---------------- js/src/jsgc.cpp | 41 ++++++----------------- 4 files changed, 81 insertions(+), 108 deletions(-) diff --git a/js/src/gc/GCRuntime.h b/js/src/gc/GCRuntime.h index b82c4d1d244a..0aa34dcb4637 100644 --- a/js/src/gc/GCRuntime.h +++ b/js/src/gc/GCRuntime.h @@ -596,6 +596,56 @@ typedef HashMap, SystemAllocPolicy> R using AllocKinds = mozilla::EnumSet; +template +class MemoryCounter +{ + // Bytes counter to measure memory pressure for GC scheduling. It runs + // from maxBytes down to zero. + mozilla::Atomic bytes_; + + // GC trigger threshold for memory allocations. + js::ActiveThreadData maxBytes_; + + // Whether a GC has been triggered as a result of bytes falling below + // zero. + // + // This should be a bool, but Atomic only supports 32-bit and pointer-sized + // types. + mozilla::Atomic triggered_; + + public: + MemoryCounter() + : bytes_(0), + maxBytes_(0), + triggered_(false) + { } + + void reset() { + bytes_ = maxBytes_; + triggered_ = false; + } + + void setMax(size_t newMax) { + // For compatibility treat any value that exceeds PTRDIFF_T_MAX to + // mean that value. + maxBytes_ = (ptrdiff_t(newMax) >= 0) ? newMax : size_t(-1) >> 1; + reset(); + } + + bool update(T* owner, size_t bytes) { + bytes_ -= ptrdiff_t(bytes); + if (MOZ_UNLIKELY(isTooMuchMalloc())) { + if (!triggered_) + triggered_ = owner->triggerGCForTooMuchMalloc(); + } + return triggered_; + } + + ptrdiff_t bytes() const { return bytes_; } + size_t maxBytes() const { return maxBytes_; } + bool isTooMuchMalloc() const { return bytes_ <= 0; } +}; + class GCRuntime { public: @@ -667,8 +717,6 @@ class GCRuntime void setDeterministic(bool enable); #endif - size_t maxMallocBytesAllocated() { return maxMallocBytes; } - uint64_t nextCellUniqueId() { MOZ_ASSERT(nextCellUniqueId_ > 0); uint64_t uid = ++nextCellUniqueId_; @@ -725,12 +773,13 @@ class GCRuntime MOZ_MUST_USE bool addBlackRootsTracer(JSTraceDataOp traceOp, void* data); void removeBlackRootsTracer(JSTraceDataOp traceOp, void* data); + bool triggerGCForTooMuchMalloc() { return triggerGC(JS::gcreason::TOO_MUCH_MALLOC); } + int32_t getMallocBytes() const { return mallocCounter.bytes(); } + size_t maxMallocBytesAllocated() const { return mallocCounter.maxBytes(); } + bool isTooMuchMalloc() const { return mallocCounter.isTooMuchMalloc(); } + void resetMallocBytes() { mallocCounter.reset(); } void setMaxMallocBytes(size_t value); - int32_t getMallocBytes() const { return mallocBytesUntilGC; } - void resetMallocBytes(); - bool isTooMuchMalloc() const { return mallocBytesUntilGC <= 0; } void updateMallocCounter(JS::Zone* zone, size_t nbytes); - void onTooMuchMalloc(); void setGCCallback(JSGCCallback callback, void* data); void callGCCallback(JSGCStatus status) const; @@ -1031,8 +1080,6 @@ class GCRuntime ActiveThreadData rootsHash; - ActiveThreadData maxMallocBytes; - // An incrementing id used to assign unique ids to cells that require one. mozilla::Atomic nextCellUniqueId_; @@ -1248,17 +1295,7 @@ class GCRuntime CallbackVector updateWeakPointerZoneGroupCallbacks; CallbackVector updateWeakPointerCompartmentCallbacks; - /* - * Malloc counter to measure memory pressure for GC scheduling. It runs - * from maxMallocBytes down to zero. - */ - mozilla::Atomic mallocBytesUntilGC; - - /* - * Whether a GC has been triggered as a result of mallocBytesUntilGC - * falling below zero. - */ - mozilla::Atomic mallocGCTriggered; + MemoryCounter mallocCounter; /* * The trace operations to trace embedding-specific GC roots. One is for diff --git a/js/src/gc/Zone.cpp b/js/src/gc/Zone.cpp index abbbe78f0381..d136bf89dde3 100644 --- a/js/src/gc/Zone.cpp +++ b/js/src/gc/Zone.cpp @@ -39,9 +39,6 @@ JS::Zone::Zone(JSRuntime* rt, ZoneGroup* group) gcWeakKeys_(group, SystemAllocPolicy(), rt->randomHashCodeScrambler()), gcZoneGroupEdges_(group), typeDescrObjects_(group, this, SystemAllocPolicy()), - gcMallocBytes(0), - gcMaxMallocBytes(0), - gcMallocGCTriggered(false), markedAtoms_(group), usage(&rt->gc.usage), threshold(), @@ -110,33 +107,6 @@ Zone::setNeedsIncrementalBarrier(bool needs, ShouldUpdateJit updateJit) needsIncrementalBarrier_ = needs; } -void -Zone::resetGCMallocBytes() -{ - gcMallocBytes = ptrdiff_t(gcMaxMallocBytes); - gcMallocGCTriggered = false; -} - -void -Zone::setGCMaxMallocBytes(size_t value) -{ - /* - * For compatibility treat any value that exceeds PTRDIFF_T_MAX to - * mean that value. - */ - gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1; - resetGCMallocBytes(); -} - -void -Zone::onTooMuchMalloc() -{ - if (!gcMallocGCTriggered) { - GCRuntime& gc = runtimeFromAnyThread()->gc; - gcMallocGCTriggered = gc.triggerZoneGC(this, JS::gcreason::TOO_MUCH_MALLOC); - } -} - void Zone::beginSweepTypes(FreeOp* fop, bool releaseTypes) { diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index 9bd09c1e0f57..00dc62dd3126 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -166,16 +166,6 @@ struct Zone : public JS::shadow::Zone, size_t* shapeTables, size_t* atomsMarkBitmaps); - void resetGCMallocBytes(); - void setGCMaxMallocBytes(size_t value); - void updateMallocCounter(size_t nbytes) { - // Note: this code may be run from worker threads. We tolerate any - // thread races when updating gcMallocBytes. - gcMallocBytes -= ptrdiff_t(nbytes); - if (MOZ_UNLIKELY(isTooMuchMalloc())) - onTooMuchMalloc(); - } - // Iterate over all cells in the zone. See the definition of ZoneCellIter // in jsgcinlines.h for the possible arguments and documentation. template @@ -183,11 +173,8 @@ struct Zone : public JS::shadow::Zone, return js::gc::ZoneCellIter(const_cast(this), mozilla::Forward(args)...); } - bool isTooMuchMalloc() const { return gcMallocBytes <= 0; } - void onTooMuchMalloc(); - MOZ_MUST_USE void* onOutOfMemory(js::AllocFunction allocFunc, size_t nbytes, - void* reallocPtr = nullptr) { + void* reallocPtr = nullptr) { if (!js::CurrentThreadCanAccessRuntime(runtime_)) return nullptr; return runtimeFromActiveCooperatingThread()->onOutOfMemory(allocFunc, nbytes, reallocPtr); @@ -399,25 +386,27 @@ struct Zone : public JS::shadow::Zone, js::SystemAllocPolicy>; private: js::ZoneGroupData> typeDescrObjects_; + + // Malloc counter to measure memory pressure for GC scheduling. This + // counter should be used only when it's not possible to know the size of + // a free. + js::gc::MemoryCounter gcMallocCounter; + public: JS::WeakCache& typeDescrObjects() { return typeDescrObjects_.ref(); } bool addTypeDescrObject(JSContext* cx, HandleObject obj); - // Malloc counter to measure memory pressure for GC scheduling. It runs from - // gcMaxMallocBytes down to zero. This counter should be used only when it's - // not possible to know the size of a free. - mozilla::Atomic gcMallocBytes; + bool triggerGCForTooMuchMalloc() { + return runtimeFromAnyThread()->gc.triggerZoneGC(this, JS::gcreason::TOO_MUCH_MALLOC); + } - // GC trigger threshold for allocations on the C heap. - js::ActiveThreadData gcMaxMallocBytes; - - // Whether a GC has been triggered as a result of gcMallocBytes falling - // below zero. - // - // This should be a bool, but Atomic only supports 32-bit and pointer-sized - // types. - mozilla::Atomic gcMallocGCTriggered; + void resetGCMallocBytes() { gcMallocCounter.reset(); } + void setGCMaxMallocBytes(size_t value) { gcMallocCounter.setMax(value); } + void updateMallocCounter(size_t nbytes) { gcMallocCounter.update(this, nbytes); } + size_t GCMaxMallocBytes() const { return gcMallocCounter.maxBytes(); } + size_t GCMallocBytes() const { return gcMallocCounter.bytes(); } + bool isTooMuchMalloc() const { return gcMallocCounter.isTooMuchMalloc(); } private: // Bitmap of atoms marked by this zone. diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 48fb02e2f72d..561a78d6d848 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -816,7 +816,6 @@ GCRuntime::GCRuntime(JSRuntime* rt) : marker(rt), usage(nullptr), mMemProfiler(rt), - maxMallocBytes(0), nextCellUniqueId_(LargestTaggedNullCellPointer + 1), // Ensure disjoint from null tagged pointers. numArenasFreeCommitted(0), verifyPreData(nullptr), @@ -864,8 +863,6 @@ GCRuntime::GCRuntime(JSRuntime* rt) : incrementalLimit(0), #endif fullCompartmentChecks(false), - mallocBytesUntilGC(0), - mallocGCTriggered(false), alwaysPreserveCode(false), #ifdef DEBUG arenasEmptyAtShutdown(true), @@ -1259,7 +1256,7 @@ GCRuntime::getParameter(JSGCParamKey key, const AutoLockGC& lock) case JSGC_MAX_BYTES: return uint32_t(tunables.gcMaxBytes()); case JSGC_MAX_MALLOC_BYTES: - return maxMallocBytes; + return mallocCounter.maxBytes(); case JSGC_BYTES: return uint32_t(usage.gcBytes()); case JSGC_MODE: @@ -1539,40 +1536,19 @@ js::RemoveRawValueRoot(JSContext* cx, Value* vp) void GCRuntime::setMaxMallocBytes(size_t value) { - /* - * For compatibility treat any value that exceeds PTRDIFF_T_MAX to - * mean that value. - */ - maxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1; - resetMallocBytes(); + mallocCounter.setMax(value); for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) zone->setGCMaxMallocBytes(value); } -void -GCRuntime::resetMallocBytes() -{ - mallocBytesUntilGC = ptrdiff_t(maxMallocBytes); - mallocGCTriggered = false; -} - void GCRuntime::updateMallocCounter(JS::Zone* zone, size_t nbytes) { - mallocBytesUntilGC -= ptrdiff_t(nbytes); - if (MOZ_UNLIKELY(isTooMuchMalloc())) - onTooMuchMalloc(); - else if (zone) + bool triggered = mallocCounter.update(this, nbytes); + if (!triggered && zone) zone->updateMallocCounter(nbytes); } -void -GCRuntime::onTooMuchMalloc() -{ - if (!mallocGCTriggered) - mallocGCTriggered = triggerGC(JS::gcreason::TOO_MUCH_MALLOC); -} - double ZoneHeapThreshold::allocTrigger(bool highFrequencyGC) const { @@ -4186,7 +4162,7 @@ js::gc::MarkingValidator::nonIncrementalMark(AutoLockForExclusiveAccess& lock) /* Save existing mark bits. */ for (auto chunk = gc->allNonEmptyChunks(); !chunk.done(); chunk.next()) { ChunkBitmap* bitmap = &chunk->bitmap; - ChunkBitmap* entry = js_new(); + ChunkBitmap* entry = js_new(); if (!entry) return; @@ -7621,7 +7597,8 @@ static bool ZoneGCAllocTriggerGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); - args.rval().setNumber(double(cx->zone()->threshold.allocTrigger(cx->runtime()->gc.schedulingState.inHighFrequencyGCMode()))); + bool highFrequency = cx->runtime()->gc.schedulingState.inHighFrequencyGCMode(); + args.rval().setNumber(double(cx->zone()->threshold.allocTrigger(highFrequency))); return true; } @@ -7629,7 +7606,7 @@ static bool ZoneMallocBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); - args.rval().setNumber(double(cx->zone()->gcMallocBytes)); + args.rval().setNumber(double(cx->zone()->GCMallocBytes())); return true; } @@ -7637,7 +7614,7 @@ static bool ZoneMaxMallocGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); - args.rval().setNumber(double(cx->zone()->gcMaxMallocBytes)); + args.rval().setNumber(double(cx->zone()->GCMaxMallocBytes())); return true; } From ce5ee84fd49daeb64a514f43f5a7890f080e4773 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 21 Feb 2017 19:02:31 +0100 Subject: [PATCH 009/102] Bug 1341090: Implement a JIT code counter; r=jonco, r=jandem MozReview-Commit-ID: Hq8g3qmEsjG --- js/src/gc/Zone.cpp | 1 + js/src/gc/Zone.h | 17 ++++++++++++++++- js/src/gdb/tests/test-ExecutableAllocator.cpp | 6 +++--- js/src/jit/ExecutableAllocator.cpp | 5 ++++- js/src/jit/ExecutableAllocator.h | 2 +- js/src/jit/Linker.cpp | 7 ++++--- js/src/jit/ProcessExecutableMemory.cpp | 8 -------- js/src/jit/ProcessExecutableMemory.h | 8 ++++++++ js/src/jsgc.cpp | 2 +- js/src/wasm/WasmCode.cpp | 4 ++-- 10 files changed, 40 insertions(+), 20 deletions(-) diff --git a/js/src/gc/Zone.cpp b/js/src/gc/Zone.cpp index d136bf89dde3..556bf7be5c1d 100644 --- a/js/src/gc/Zone.cpp +++ b/js/src/gc/Zone.cpp @@ -66,6 +66,7 @@ JS::Zone::Zone(JSRuntime* rt, ZoneGroup* group) AutoLockGC lock(rt); threshold.updateAfterGC(8192, GC_NORMAL, rt->gc.tunables, rt->gc.schedulingState, lock); setGCMaxMallocBytes(rt->gc.maxMallocBytesAllocated() * 0.9); + jitCodeCounter.setMax(jit::MaxCodeBytesPerProcess * 0.8); } Zone::~Zone() diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index 00dc62dd3126..6c61ec332cc9 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -392,6 +392,10 @@ struct Zone : public JS::shadow::Zone, // a free. js::gc::MemoryCounter gcMallocCounter; + // Counter of JIT code executable memory for GC scheduling. Also imprecise, + // since wasm can generate code that outlives a zone. + js::gc::MemoryCounter jitCodeCounter; + public: JS::WeakCache& typeDescrObjects() { return typeDescrObjects_.ref(); } @@ -406,7 +410,18 @@ struct Zone : public JS::shadow::Zone, void updateMallocCounter(size_t nbytes) { gcMallocCounter.update(this, nbytes); } size_t GCMaxMallocBytes() const { return gcMallocCounter.maxBytes(); } size_t GCMallocBytes() const { return gcMallocCounter.bytes(); } - bool isTooMuchMalloc() const { return gcMallocCounter.isTooMuchMalloc(); } + + void updateJitCodeMallocBytes(size_t size) { jitCodeCounter.update(this, size); } + + // Resets all the memory counters. + void resetAllMallocBytes() { + resetGCMallocBytes(); + jitCodeCounter.reset(); + } + bool isTooMuchMalloc() const { + return gcMallocCounter.isTooMuchMalloc() || + jitCodeCounter.isTooMuchMalloc(); + } private: // Bitmap of atoms marked by this zone. diff --git a/js/src/gdb/tests/test-ExecutableAllocator.cpp b/js/src/gdb/tests/test-ExecutableAllocator.cpp index 7cb7ad364ca4..c9636312a47c 100644 --- a/js/src/gdb/tests/test-ExecutableAllocator.cpp +++ b/js/src/gdb/tests/test-ExecutableAllocator.cpp @@ -18,7 +18,7 @@ FRAGMENT(ExecutableAllocator, onepool) { using namespace js::jit; ExecutablePool* pool = nullptr; ExecutableAllocator execAlloc(cx->runtime()); - execAlloc.alloc(16 * 1024, &pool, BASELINE_CODE); + execAlloc.alloc(cx, 16 * 1024, &pool, BASELINE_CODE); breakpoint(); @@ -32,10 +32,10 @@ FRAGMENT(ExecutableAllocator, twopools) { ExecutablePool* pool = nullptr; ExecutableAllocator execAlloc(cx->runtime()); - execAlloc.alloc(16 * 1024, &init, BASELINE_CODE); + execAlloc.alloc(cx, 16 * 1024, &init, BASELINE_CODE); do { // Keep allocating until we get a second pool. - execAlloc.alloc(32 * 1024, &pool, ION_CODE); + execAlloc.alloc(cx, 32 * 1024, &pool, ION_CODE); } while (pool == init); breakpoint(); diff --git a/js/src/jit/ExecutableAllocator.cpp b/js/src/jit/ExecutableAllocator.cpp index 808c87a9bde0..e53c5fcfef29 100644 --- a/js/src/jit/ExecutableAllocator.cpp +++ b/js/src/jit/ExecutableAllocator.cpp @@ -238,7 +238,7 @@ ExecutableAllocator::createPool(size_t n) } void* -ExecutableAllocator::alloc(size_t n, ExecutablePool** poolp, CodeKind type) +ExecutableAllocator::alloc(JSContext* cx, size_t n, ExecutablePool** poolp, CodeKind type) { // Don't race with reprotectAll called from the signal handler. JitRuntime::AutoPreventBackedgePatching apbp(rt_); @@ -261,6 +261,9 @@ ExecutableAllocator::alloc(size_t n, ExecutablePool** poolp, CodeKind type) // (found, or created if necessary) a pool that had enough space. void* result = (*poolp)->alloc(n, type); MOZ_ASSERT(result); + + cx->zone()->updateJitCodeMallocBytes(n); + return result; } diff --git a/js/src/jit/ExecutableAllocator.h b/js/src/jit/ExecutableAllocator.h index c6e90e8fb561..3a42918142ef 100644 --- a/js/src/jit/ExecutableAllocator.h +++ b/js/src/jit/ExecutableAllocator.h @@ -177,7 +177,7 @@ class ExecutableAllocator // alloc() returns a pointer to some memory, and also (by reference) a // pointer to reference-counted pool. The caller owns a reference to the // pool; i.e. alloc() increments the count before returning the object. - void* alloc(size_t n, ExecutablePool** poolp, CodeKind type); + void* alloc(JSContext* cx, size_t n, ExecutablePool** poolp, CodeKind type); void releasePoolPages(ExecutablePool* pool); diff --git a/js/src/jit/Linker.cpp b/js/src/jit/Linker.cpp index 674f7a5b5fff..6038687f7d47 100644 --- a/js/src/jit/Linker.cpp +++ b/js/src/jit/Linker.cpp @@ -31,9 +31,10 @@ Linker::newCode(JSContext* cx, CodeKind kind, bool hasPatchableBackedges /* = fa bytesNeeded = AlignBytes(bytesNeeded, sizeof(void*)); ExecutableAllocator& execAlloc = hasPatchableBackedges - ? cx->runtime()->jitRuntime()->backedgeExecAlloc() - : cx->runtime()->jitRuntime()->execAlloc(); - uint8_t* result = (uint8_t*)execAlloc.alloc(bytesNeeded, &pool, kind); + ? cx->runtime()->jitRuntime()->backedgeExecAlloc() + : cx->runtime()->jitRuntime()->execAlloc(); + + uint8_t* result = (uint8_t*)execAlloc.alloc(cx, bytesNeeded, &pool, kind); if (!result) return fail(cx); diff --git a/js/src/jit/ProcessExecutableMemory.cpp b/js/src/jit/ProcessExecutableMemory.cpp index 9a66b042c2f9..d43f2e5915a9 100644 --- a/js/src/jit/ProcessExecutableMemory.cpp +++ b/js/src/jit/ProcessExecutableMemory.cpp @@ -405,14 +405,6 @@ class PageBitSet #endif }; -// Limit on the number of bytes of executable memory to prevent JIT spraying -// attacks. -#if JS_BITS_PER_WORD == 32 -static const size_t MaxCodeBytesPerProcess = 128 * 1024 * 1024; -#else -static const size_t MaxCodeBytesPerProcess = 640 * 1024 * 1024; -#endif - // Per-process executable memory allocator. It reserves a block of memory of // MaxCodeBytesPerProcess bytes, then allocates/deallocates pages from that. // diff --git a/js/src/jit/ProcessExecutableMemory.h b/js/src/jit/ProcessExecutableMemory.h index 078ce7cb75fc..df810ff16554 100644 --- a/js/src/jit/ProcessExecutableMemory.h +++ b/js/src/jit/ProcessExecutableMemory.h @@ -12,6 +12,14 @@ namespace js { namespace jit { +// Limit on the number of bytes of executable memory to prevent JIT spraying +// attacks. +#if JS_BITS_PER_WORD == 32 +static const size_t MaxCodeBytesPerProcess = 128 * 1024 * 1024; +#else +static const size_t MaxCodeBytesPerProcess = 640 * 1024 * 1024; +#endif + // Executable code is allocated in 64K chunks. ExecutableAllocator uses pools // that are at least this big. Code we allocate does not necessarily have 64K // alignment though. diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 561a78d6d848..35ebd13e1e91 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -6289,7 +6289,7 @@ GCRuntime::gcCycle(bool nonincrementalByAPI, SliceBudget& budget, JS::gcreason:: /* Clear gcMallocBytes for all zones. */ for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) - zone->resetGCMallocBytes(); + zone->resetAllMallocBytes(); resetMallocBytes(); diff --git a/js/src/wasm/WasmCode.cpp b/js/src/wasm/WasmCode.cpp index bb65b45adad4..623d95095592 100644 --- a/js/src/wasm/WasmCode.cpp +++ b/js/src/wasm/WasmCode.cpp @@ -88,6 +88,8 @@ AllocateCodeSegment(JSContext* cx, uint32_t codeLength) return nullptr; } + cx->zone()->updateJitCodeMallocBytes(codeLength); + wasmCodeAllocations++; return (uint8_t*)p; } @@ -259,7 +261,6 @@ CodeSegment::~CodeSegment() if (!bytes_) return; - MOZ_ASSERT(wasmCodeAllocations > 0); wasmCodeAllocations--; @@ -271,7 +272,6 @@ CodeSegment::~CodeSegment() vtune::UnmarkBytes(bytes_, size); #endif DeallocateExecutableMemory(bytes_, size); - } void From 9aff7496577b13948ea421170013428ac02dadff Mon Sep 17 00:00:00 2001 From: Andrew Osmond Date: Wed, 22 Feb 2017 09:30:22 -0500 Subject: [PATCH 010/102] Bug 1341624 - Include shared handle totals in memory reports for images. r=tnikkel --- gfx/layers/SourceSurfaceSharedData.h | 16 ++++++++++++++-- image/AnimationSurfaceProvider.cpp | 6 ++++-- image/AnimationSurfaceProvider.h | 3 ++- image/Decoder.cpp | 3 ++- image/FrameAnimator.cpp | 5 +++-- image/ISurfaceProvider.h | 6 ++++-- image/Image.h | 5 +++++ image/SurfaceCache.cpp | 4 +++- image/imgFrame.cpp | 11 ++++++++++- image/imgFrame.h | 3 ++- image/imgLoader.cpp | 5 +++++ 11 files changed, 54 insertions(+), 13 deletions(-) diff --git a/gfx/layers/SourceSurfaceSharedData.h b/gfx/layers/SourceSurfaceSharedData.h index 9a26ed26f5cd..d8557eb466b8 100644 --- a/gfx/layers/SourceSurfaceSharedData.h +++ b/gfx/layers/SourceSurfaceSharedData.h @@ -104,7 +104,8 @@ public: /** * Indicates the buffer is not expected to be shared with any more processes. - * May release the handle if possible (see CloseHandleInternal). */ + * May release the handle if possible (see CloseHandleInternal). + */ void FinishedSharing() { MutexAutoLock lock(mMutex); @@ -112,6 +113,17 @@ public: CloseHandleInternal(); } + /** + * Indicates whether or not the buffer can be shared with another process + * without reallocating. Note that this is racy and should only be used for + * informational/reporting purposes. + */ + bool CanShare() const + { + MutexAutoLock lock(mMutex); + return !mClosed; + } + /** * Allocate a new shared memory buffer so that we can get a new handle for * sharing to new processes. ShareToProcess must have failed with @@ -150,7 +162,7 @@ private: */ void CloseHandleInternal(); - Mutex mMutex; + mutable Mutex mMutex; int32_t mStride; int32_t mMapCount; IntSize mSize; diff --git a/image/AnimationSurfaceProvider.cpp b/image/AnimationSurfaceProvider.cpp index 6487ff35e6e9..5c34f21ba231 100644 --- a/image/AnimationSurfaceProvider.cpp +++ b/image/AnimationSurfaceProvider.cpp @@ -118,7 +118,8 @@ AnimationSurfaceProvider::LogicalSizeInBytes() const void AnimationSurfaceProvider::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut, - size_t& aNonHeapSizeOut) + size_t& aNonHeapSizeOut, + size_t& aSharedHandlesOut) { // Note that the surface cache lock is already held here, and then we acquire // mFramesMutex. For this method, this ordering is unavoidable, which means @@ -126,7 +127,8 @@ AnimationSurfaceProvider::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, MutexAutoLock lock(mFramesMutex); for (const RawAccessFrameRef& frame : mFrames) { - frame->AddSizeOfExcludingThis(aMallocSizeOf, aHeapSizeOut, aNonHeapSizeOut); + frame->AddSizeOfExcludingThis(aMallocSizeOf, aHeapSizeOut, + aNonHeapSizeOut, aSharedHandlesOut); } } diff --git a/image/AnimationSurfaceProvider.h b/image/AnimationSurfaceProvider.h index bf87f37ac4c9..b0e2213195a1 100644 --- a/image/AnimationSurfaceProvider.h +++ b/image/AnimationSurfaceProvider.h @@ -47,7 +47,8 @@ public: size_t LogicalSizeInBytes() const override; void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut, - size_t& aNonHeapSizeOut) override; + size_t& aNonHeapSizeOut, + size_t& aSharedHandlesOut) override; protected: DrawableFrameRef DrawableRef(size_t aFrame) override; diff --git a/image/Decoder.cpp b/image/Decoder.cpp index edfe3dfaf3a9..6f6a2f3a50d8 100644 --- a/image/Decoder.cpp +++ b/image/Decoder.cpp @@ -335,7 +335,8 @@ Decoder::AllocateFrameInternal(uint32_t aFrameNum, NotNull> frame = WrapNotNull(new imgFrame()); bool nonPremult = bool(mSurfaceFlags & SurfaceFlags::NO_PREMULTIPLY_ALPHA); if (NS_FAILED(frame->InitForDecoder(aOutputSize, aFrameRect, aFormat, - aPaletteDepth, nonPremult))) { + aPaletteDepth, nonPremult, + aFrameNum > 0))) { NS_WARNING("imgFrame::Init should succeed"); return RawAccessFrameRef(); } diff --git a/image/FrameAnimator.cpp b/image/FrameAnimator.cpp index d1cc0ab085a0..cf1e782a9b52 100644 --- a/image/FrameAnimator.cpp +++ b/image/FrameAnimator.cpp @@ -353,10 +353,11 @@ DoCollectSizeOfCompositingSurfaces(const RawAccessFrameRef& aSurface, SurfaceMemoryCounter counter(key, /* aIsLocked = */ true, aType); // Extract the surface's memory usage information. - size_t heap = 0, nonHeap = 0; - aSurface->AddSizeOfExcludingThis(aMallocSizeOf, heap, nonHeap); + size_t heap = 0, nonHeap = 0, handles = 0; + aSurface->AddSizeOfExcludingThis(aMallocSizeOf, heap, nonHeap, handles); counter.Values().SetDecodedHeap(heap); counter.Values().SetDecodedNonHeap(nonHeap); + counter.Values().SetSharedHandles(handles); // Record it. aCounters.AppendElement(counter); diff --git a/image/ISurfaceProvider.h b/image/ISurfaceProvider.h index 3b0aa3710588..e98afe229d94 100644 --- a/image/ISurfaceProvider.h +++ b/image/ISurfaceProvider.h @@ -64,14 +64,16 @@ public: /// implementation is appropriate for static ISurfaceProviders. virtual void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut, - size_t& aNonHeapSizeOut) + size_t& aNonHeapSizeOut, + size_t& aSharedHandlesOut) { DrawableFrameRef ref = DrawableRef(/* aFrame = */ 0); if (!ref) { return; } - ref->AddSizeOfExcludingThis(aMallocSizeOf, aHeapSizeOut, aNonHeapSizeOut); + ref->AddSizeOfExcludingThis(aMallocSizeOf, aHeapSizeOut, + aNonHeapSizeOut, aSharedHandlesOut); } /// @return the availability state of this ISurfaceProvider, which indicates diff --git a/image/Image.h b/image/Image.h index 8656b569f78c..5efa957ef4b3 100644 --- a/image/Image.h +++ b/image/Image.h @@ -33,6 +33,7 @@ struct MemoryCounter : mSource(0) , mDecodedHeap(0) , mDecodedNonHeap(0) + , mSharedHandles(0) { } void SetSource(size_t aCount) { mSource = aCount; } @@ -41,12 +42,15 @@ struct MemoryCounter size_t DecodedHeap() const { return mDecodedHeap; } void SetDecodedNonHeap(size_t aCount) { mDecodedNonHeap = aCount; } size_t DecodedNonHeap() const { return mDecodedNonHeap; } + void SetSharedHandles(size_t aCount) { mSharedHandles = aCount; } + size_t SharedHandles() const { return mSharedHandles; } MemoryCounter& operator+=(const MemoryCounter& aOther) { mSource += aOther.mSource; mDecodedHeap += aOther.mDecodedHeap; mDecodedNonHeap += aOther.mDecodedNonHeap; + mSharedHandles += aOther.mSharedHandles; return *this; } @@ -54,6 +58,7 @@ private: size_t mSource; size_t mDecodedHeap; size_t mDecodedNonHeap; + size_t mSharedHandles; }; enum class SurfaceMemoryCounterType diff --git a/image/SurfaceCache.cpp b/image/SurfaceCache.cpp index dd8982ce97f2..5e7bed4a5015 100644 --- a/image/SurfaceCache.cpp +++ b/image/SurfaceCache.cpp @@ -197,10 +197,12 @@ public: // for surfaces with PlaybackType::eAnimated.) size_t heap = 0; size_t nonHeap = 0; + size_t handles = 0; aCachedSurface->mProvider - ->AddSizeOfExcludingThis(mMallocSizeOf, heap, nonHeap); + ->AddSizeOfExcludingThis(mMallocSizeOf, heap, nonHeap, handles); counter.Values().SetDecodedHeap(heap); counter.Values().SetDecodedNonHeap(nonHeap); + counter.Values().SetSharedHandles(handles); mCounters.AppendElement(counter); } diff --git a/image/imgFrame.cpp b/image/imgFrame.cpp index db31c04989da..f5d6c675759c 100644 --- a/image/imgFrame.cpp +++ b/image/imgFrame.cpp @@ -932,7 +932,8 @@ imgFrame::SetCompositingFailed(bool val) void imgFrame::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut, - size_t& aNonHeapSizeOut) const + size_t& aNonHeapSizeOut, + size_t& aSharedHandlesOut) const { MonitorAutoLock lock(mMonitor); @@ -949,6 +950,14 @@ imgFrame::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, aHeapSizeOut += aMallocSizeOf(mRawSurface); mRawSurface->AddSizeOfExcludingThis(aMallocSizeOf, aHeapSizeOut, aNonHeapSizeOut); + + if (mRawSurface->GetType() == SurfaceType::DATA_SHARED) { + auto sharedSurface = + static_cast(mRawSurface.get()); + if (sharedSurface->CanShare()) { + ++aSharedHandlesOut; + } + } } } diff --git a/image/imgFrame.h b/image/imgFrame.h index b940777fa81e..34d19447620a 100644 --- a/image/imgFrame.h +++ b/image/imgFrame.h @@ -348,7 +348,8 @@ public: already_AddRefed GetSourceSurface(); void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut, - size_t& aNonHeapSizeOut) const; + size_t& aNonHeapSizeOut, + size_t& aSharedHandlesOut) const; private: // methods diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index 68facd72c51c..8daee793674c 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -280,6 +280,11 @@ private: surfacePathPrefix.Append("x"); surfacePathPrefix.AppendInt(counter.Key().Size().height); + if (counter.Values().SharedHandles() > 0) { + surfacePathPrefix.Append(", shared:"); + surfacePathPrefix.AppendInt(uint32_t(counter.Values().SharedHandles())); + } + if (counter.Type() == SurfaceMemoryCounterType::NORMAL) { PlaybackType playback = counter.Key().Playback(); surfacePathPrefix.Append(playback == PlaybackType::eAnimated From 4f2a256d0c12a4f98ccb9c9f3d23590c3c983c5d Mon Sep 17 00:00:00 2001 From: Joel Maher Date: Thu, 23 Feb 2017 08:01:45 -0500 Subject: [PATCH 011/102] Bug 1341794 - annotate startupcache/* moz.build file with BUG_COMPONENT. r=froydnj MozReview-Commit-ID: BQkxYXk6tl --- startupcache/moz.build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/startupcache/moz.build b/startupcache/moz.build index 24068cb7e800..e3d88e417a54 100644 --- a/startupcache/moz.build +++ b/startupcache/moz.build @@ -4,6 +4,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/. +with Files("**"): + BUG_COMPONENT = ("Core", "XPCOM") + if not CONFIG['MOZ_B2G']: TEST_DIRS += ['test'] From 01b0f2edd73e0a680cc4ff065c838424cfb35596 Mon Sep 17 00:00:00 2001 From: Joel Maher Date: Thu, 23 Feb 2017 08:01:50 -0500 Subject: [PATCH 012/102] Bug 1341799 - annotate storage/* with BUG_COMPONENT in moz.build files. r=mak MozReview-Commit-ID: 3g7WuMN6hR7 --- storage/moz.build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/moz.build b/storage/moz.build index 8863105c9d5c..f42c3e47061b 100644 --- a/storage/moz.build +++ b/storage/moz.build @@ -4,6 +4,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/. +with Files("**"): + BUG_COMPONENT = ("Toolkit", "Storage") + DIRS += ['build'] TEST_DIRS += ['test'] From 5e3def60d4180c89a3ebf433a277531baafa1f9a Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 23 Feb 2017 14:30:23 +0100 Subject: [PATCH 013/102] Bug 1341218 - nsNullPrincipal should serialize its URL, r=qdot --- caps/nsNullPrincipal.cpp | 30 ++++++++++++++++++++++++------ dom/base/nsContentUtils.cpp | 9 +++++---- dom/base/nsDocument.cpp | 3 ++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/caps/nsNullPrincipal.cpp b/caps/nsNullPrincipal.cpp index e1555e4794e1..20d713890c18 100644 --- a/caps/nsNullPrincipal.cpp +++ b/caps/nsNullPrincipal.cpp @@ -166,25 +166,43 @@ nsNullPrincipal::Read(nsIObjectInputStream* aStream) // that the Init() method has already been invoked by the time we deserialize. // This is in contrast to nsPrincipal, which uses NS_GENERIC_FACTORY_CONSTRUCTOR, // in which case ::Read needs to invoke Init(). - nsAutoCString suffix; - nsresult rv = aStream->ReadCString(suffix); + + nsAutoCString spec; + nsresult rv = aStream->ReadCString(spec); NS_ENSURE_SUCCESS(rv, rv); - bool ok = mOriginAttributes.PopulateFromSuffix(suffix); + nsCOMPtr uri; + rv = NS_NewURI(getter_AddRefs(uri), spec); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoCString suffix; + rv = aStream->ReadCString(suffix); + NS_ENSURE_SUCCESS(rv, rv); + + OriginAttributes attrs; + bool ok = attrs.PopulateFromSuffix(suffix); NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE); - return NS_OK; + return Init(attrs, uri); } NS_IMETHODIMP nsNullPrincipal::Write(nsIObjectOutputStream* aStream) { + NS_ENSURE_STATE(mURI); + + nsAutoCString spec; + nsresult rv = mURI->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); + + rv = aStream->WriteStringZ(spec.get()); + NS_ENSURE_SUCCESS(rv, rv); + nsAutoCString suffix; OriginAttributesRef().CreateSuffix(suffix); - nsresult rv = aStream->WriteStringZ(suffix.get()); + rv = aStream->WriteStringZ(suffix.get()); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } - diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index c09827e9497b..a0db9a2b3d3c 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -512,10 +512,11 @@ nsContentUtils::Init() sSecurityManager->GetSystemPrincipal(&sSystemPrincipal); MOZ_ASSERT(sSystemPrincipal); - // We use the constructor here because we want infallible initialization; we - // apparently don't care whether sNullSubjectPrincipal has a sane URI or not. - RefPtr nullPrincipal = new nsNullPrincipal(); - nullPrincipal->Init(); + RefPtr nullPrincipal = nsNullPrincipal::Create(); + if (!nullPrincipal) { + return NS_ERROR_FAILURE; + } + nullPrincipal.forget(&sNullSubjectPrincipal); nsresult rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService); diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 33395f6399c2..e7a06e5d0cf5 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -104,6 +104,7 @@ #include "nsIScriptSecurityManager.h" #include "nsIPermissionManager.h" #include "nsIPrincipal.h" +#include "nsNullPrincipal.h" #include "nsIDOMWindow.h" #include "nsPIDOMWindow.h" @@ -2738,7 +2739,7 @@ nsDocument::InitCSP(nsIChannel* aChannel) if (cspSandboxFlags & SANDBOXED_ORIGIN) { // If the new CSP sandbox flags do not have the allow-same-origin flag // reset the document principal to a null principal - principal = do_CreateInstance("@mozilla.org/nullprincipal;1"); + principal = nsNullPrincipal::Create(); SetPrincipal(principal); } From 4b17d5b284e941da2beed76bcdb2221ed17a3f5b Mon Sep 17 00:00:00 2001 From: "Nils Ohlmeier [:drno]" Date: Thu, 23 Feb 2017 08:55:35 -0500 Subject: [PATCH 014/102] Bug 1315248 - Hold on to references for WrapRunnable in UDPSocketParent. r=jesup MozReview-Commit-ID: CA14BbXYtcj --- dom/network/UDPSocketParent.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom/network/UDPSocketParent.cpp b/dom/network/UDPSocketParent.cpp index d3a7d7f2d221..3f4703ebe674 100644 --- a/dom/network/UDPSocketParent.cpp +++ b/dom/network/UDPSocketParent.cpp @@ -244,7 +244,7 @@ UDPSocketParent::RecvConnect(const UDPAddressInfo& aAddressInfo) nsCOMPtr thread(NS_GetCurrentThread()); Unused << NS_WARN_IF(NS_FAILED(GetSTSThread()->Dispatch(WrapRunnable( - this, + RefPtr(this), &UDPSocketParent::DoConnect, mSocket, thread, @@ -266,7 +266,7 @@ UDPSocketParent::SendConnectResponse(nsIEventTarget *aThread, { Unused << NS_WARN_IF(NS_FAILED(aThread->Dispatch(WrapRunnable( - this, + RefPtr(this), &UDPSocketParent::DoSendConnectResponse, aAddressInfo), NS_DISPATCH_NORMAL))); @@ -586,7 +586,7 @@ UDPSocketParent::SendInternalError(nsIEventTarget *aThread, UDPSOCKET_LOG(("SendInternalError: %u", aLineNo)); Unused << NS_WARN_IF(NS_FAILED(aThread->Dispatch(WrapRunnable( - this, + RefPtr(this), &UDPSocketParent::FireInternalError, aLineNo), NS_DISPATCH_NORMAL))); From 99b7921cf930bbcdb737574d845ed0a07b221b7b Mon Sep 17 00:00:00 2001 From: "Thinker K.F. Li" Date: Wed, 22 Feb 2017 00:26:00 -0500 Subject: [PATCH 015/102] Bug 1329929 - Fix memory leaking of TaskTracer. r=cervantes --- tools/profiler/tasktracer/GeckoTaskTracer.cpp | 110 ++++++++++-------- .../profiler/tasktracer/GeckoTaskTracerImpl.h | 37 +++++- .../profiler/tasktracer/TracedTaskCommon.cpp | 8 +- 3 files changed, 104 insertions(+), 51 deletions(-) diff --git a/tools/profiler/tasktracer/GeckoTaskTracer.cpp b/tools/profiler/tasktracer/GeckoTaskTracer.cpp index ed320e7b635f..5a0acd916c3a 100644 --- a/tools/profiler/tasktracer/GeckoTaskTracer.cpp +++ b/tools/profiler/tasktracer/GeckoTaskTracer.cpp @@ -57,7 +57,7 @@ static mozilla::StaticMutex sMutex; // The generation of TraceInfo. It will be > 0 if the Task Tracer is started and // <= 0 if stopped. -static mozilla::Atomic sStarted; +static mozilla::Atomic sStarted(false); static nsTArray>* sTraceInfos = nullptr; static PRTime sStartTime; @@ -74,8 +74,8 @@ GetTimestamp() static TraceInfo* AllocTraceInfo(int aTid) { - StaticMutexAutoLock lock(sMutex); - + sMutex.AssertCurrentThreadOwns(); + MOZ_ASSERT(sTraceInfos); auto* info = sTraceInfos->AppendElement(MakeUnique(aTid)); return info->get(); @@ -86,12 +86,14 @@ CreateSourceEvent(SourceEventType aType) { // Create a new unique task id. uint64_t newId = GenNewUniqueTaskId(); - TraceInfo* info = GetOrCreateTraceInfo(); - ENSURE_TRUE_VOID(info); + { + TraceInfoHolder info = GetOrCreateTraceInfo(); + ENSURE_TRUE_VOID(info); - info->mCurTraceSourceId = newId; - info->mCurTraceSourceType = aType; - info->mCurTaskId = newId; + info->mCurTraceSourceId = newId; + info->mCurTraceSourceType = aType; + info->mCurTaskId = newId; + } uintptr_t* namePtr; #define SOURCE_EVENT_NAME(type) \ @@ -118,10 +120,23 @@ static void DestroySourceEvent() { // Log a fake end for this source event. - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); - LogEnd(info->mCurTraceSourceId, info->mCurTraceSourceId); + uint64_t curTraceSourceId; + curTraceSourceId = info->mCurTraceSourceId; + info.Reset(); + + LogEnd(curTraceSourceId, curTraceSourceId); +} + +inline static void +ObsoleteCurrentTraceInfos() +{ + MOZ_ASSERT(sTraceInfos); + for (uint32_t i = 0; i < sTraceInfos->Length(); ++i) { + (*sTraceInfos)[i]->mObsolete = true; + } } inline static bool @@ -134,24 +149,16 @@ static void SetLogStarted(bool aIsStartLogging) { MOZ_ASSERT(aIsStartLogging != sStarted); - MOZ_ASSERT(sTraceInfos != nullptr); + StaticMutexAutoLock lock(sMutex); + sStarted = aIsStartLogging; - StaticMutexAutoLock lock(sMutex); - if (!aIsStartLogging && sTraceInfos) { - for (uint32_t i = 0; i < sTraceInfos->Length(); ++i) { - (*sTraceInfos)[i]->mObsolete = true; - } + if (aIsStartLogging && sTraceInfos == nullptr) { + sTraceInfos = new nsTArray>(); } -} -inline static void -ObsoleteCurrentTraceInfos() -{ - // Note that we can't and don't need to acquire sMutex here because this - // function is called before the other threads are recreated. - for (uint32_t i = 0; i < sTraceInfos->Length(); ++i) { - (*sTraceInfos)[i]->mObsolete = true; + if (!aIsStartLogging && sTraceInfos) { + ObsoleteCurrentTraceInfos(); } } @@ -191,9 +198,6 @@ InitTaskTracer(uint32_t aFlags) if (!success) { MOZ_CRASH(); } - - // A memory barrier is necessary here. - sTraceInfos = new nsTArray>(); } void @@ -201,13 +205,22 @@ ShutdownTaskTracer() { if (IsStartLogging()) { SetLogStarted(false); + + StaticMutexAutoLock lock(sMutex); + // Make sure all threads are out of holding mutics. + // See |GetOrCreateTraceInfo()| + for (auto& traceinfo: *sTraceInfos) { + MutexAutoLock lock(traceinfo->mLogsMutex); + } + delete sTraceInfos; + sTraceInfos = nullptr; } } static void FreeTraceInfo(TraceInfo* aTraceInfo) { - StaticMutexAutoLock lock(sMutex); + sMutex.AssertCurrentThreadOwns(); if (aTraceInfo) { UniquePtr traceinfo(aTraceInfo); mozilla::DebugOnly removed = @@ -219,15 +232,19 @@ FreeTraceInfo(TraceInfo* aTraceInfo) void FreeTraceInfo() { - FreeTraceInfo(sTraceInfoTLS.get()); + StaticMutexAutoLock lock(sMutex); + if (sTraceInfos) { + FreeTraceInfo(sTraceInfoTLS.get()); + } } -TraceInfo* +TraceInfoHolder GetOrCreateTraceInfo() { - ENSURE_TRUE(IsStartLogging(), nullptr); - TraceInfo* info = sTraceInfoTLS.get(); + StaticMutexAutoLock lock(sMutex); + ENSURE_TRUE(IsStartLogging(), TraceInfoHolder{}); + if (info && info->mObsolete) { // TraceInfo is obsolete: remove it. FreeTraceInfo(info); @@ -239,13 +256,15 @@ GetOrCreateTraceInfo() sTraceInfoTLS.set(info); } - return info; + return TraceInfoHolder{info}; // |mLogsMutex| will be held, then + // ||sMutex| will be released for + // efficiency reason. } uint64_t GenNewUniqueTaskId() { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE(info, 0); Thread::tid_t tid = Thread::GetCurrentId(); @@ -267,7 +286,7 @@ void SetCurTraceInfo(uint64_t aSourceEventId, uint64_t aParentTaskId, SourceEventType aSourceEventType) { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); info->mCurTraceSourceId = aSourceEventId; @@ -279,7 +298,7 @@ void GetCurTraceInfo(uint64_t* aOutSourceEventId, uint64_t* aOutParentTaskId, SourceEventType* aOutSourceEventType) { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); *aOutSourceEventId = info->mCurTraceSourceId; @@ -298,7 +317,7 @@ void LogDispatch(uint64_t aTaskId, uint64_t aParentTaskId, uint64_t aSourceEventId, SourceEventType aSourceEventType, int aDelayTimeMs) { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); // aDelayTimeMs is the expected delay time in milliseconds, thus the dispatch @@ -306,7 +325,6 @@ LogDispatch(uint64_t aTaskId, uint64_t aParentTaskId, uint64_t aSourceEventId, uint64_t time = (aDelayTimeMs <= 0) ? GetTimestamp() : GetTimestamp() + aDelayTimeMs; - MutexAutoLock lock(info->mLogsMutex); // Log format: // [0 taskId dispatchTime sourceEventId sourceEventType parentTaskId] TraceInfoLogType* log = info->AppendLog(); @@ -323,10 +341,9 @@ LogDispatch(uint64_t aTaskId, uint64_t aParentTaskId, uint64_t aSourceEventId, void LogBegin(uint64_t aTaskId, uint64_t aSourceEventId) { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); - MutexAutoLock lock(info->mLogsMutex); // Log format: // [1 taskId beginTime processId threadId] TraceInfoLogType* log = info->AppendLog(); @@ -342,10 +359,9 @@ LogBegin(uint64_t aTaskId, uint64_t aSourceEventId) void LogEnd(uint64_t aTaskId, uint64_t aSourceEventId) { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); - MutexAutoLock lock(info->mLogsMutex); // Log format: // [2 taskId endTime] TraceInfoLogType* log = info->AppendLog(); @@ -359,10 +375,9 @@ LogEnd(uint64_t aTaskId, uint64_t aSourceEventId) void LogVirtualTablePtr(uint64_t aTaskId, uint64_t aSourceEventId, uintptr_t* aVptr) { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); - MutexAutoLock lock(info->mLogsMutex); // Log format: // [4 taskId address] TraceInfoLogType* log = info->AppendLog(); @@ -412,10 +427,9 @@ AutoScopedLabel::~AutoScopedLabel() void AddLabel(const char* aFormat, ...) { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); - MutexAutoLock lock(info->mLogsMutex); // Log format: // [3 taskId "label"] TraceInfoLogType* log = info->AppendLog(); @@ -456,6 +470,10 @@ GetLoggedData(TimeStamp aTimeStamp) // TODO: This is called from a signal handler. Use semaphore instead. StaticMutexAutoLock lock(sMutex); + if (sTraceInfos == nullptr) { + return result; + } + for (uint32_t i = 0; i < sTraceInfos->Length(); ++i) { TraceInfo* info = (*sTraceInfos)[i].get(); MutexAutoLock lockLogs(info->mLogsMutex); diff --git a/tools/profiler/tasktracer/GeckoTaskTracerImpl.h b/tools/profiler/tasktracer/GeckoTaskTracerImpl.h index 428d020edbd0..48a9da1287fc 100644 --- a/tools/profiler/tasktracer/GeckoTaskTracerImpl.h +++ b/tools/profiler/tasktracer/GeckoTaskTracerImpl.h @@ -107,8 +107,43 @@ struct TraceInfo nsTArray mStrs; }; +class TraceInfoHolder { +public: + TraceInfoHolder() : mInfo(nullptr) {} + explicit TraceInfoHolder(TraceInfo* aInfo) : mInfo(aInfo) { + aInfo->mLogsMutex.AssertNotCurrentThreadOwns(); // in case of recursive + aInfo->mLogsMutex.Lock(); + MOZ_ASSERT(aInfo); + } + TraceInfoHolder(const TraceInfoHolder& aOther) = delete; + TraceInfoHolder(TraceInfoHolder&& aOther) : mInfo(aOther.mInfo) { + if (!!aOther) { + aOther->mLogsMutex.AssertCurrentThreadOwns(); + } + aOther.mInfo = nullptr; + } + ~TraceInfoHolder() { if (mInfo) mInfo->mLogsMutex.Unlock(); } + explicit operator bool() const { return !!mInfo; } + TraceInfo* operator ->() { return mInfo; } + bool operator ==(TraceInfo* aOther) const { + return mInfo == aOther; + } + bool operator ==(const TraceInfoHolder& aOther) const { + return mInfo == aOther.mInfo; + } + void Reset() { + if (mInfo) { + mInfo->mLogsMutex.Unlock(); + mInfo = nullptr; + } + } + +private: + TraceInfo* mInfo; +}; + // Return the TraceInfo of current thread, allocate a new one if not exit. -TraceInfo* GetOrCreateTraceInfo(); +TraceInfoHolder GetOrCreateTraceInfo(); uint64_t GenNewUniqueTaskId(); diff --git a/tools/profiler/tasktracer/TracedTaskCommon.cpp b/tools/profiler/tasktracer/TracedTaskCommon.cpp index bc4b4bd4030f..4e8796f8a3c9 100644 --- a/tools/profiler/tasktracer/TracedTaskCommon.cpp +++ b/tools/profiler/tasktracer/TracedTaskCommon.cpp @@ -34,7 +34,7 @@ TracedTaskCommon::~TracedTaskCommon() void TracedTaskCommon::Init() { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); mTaskId = GenNewUniqueTaskId(); @@ -54,7 +54,7 @@ TracedTaskCommon::DispatchTask(int aDelayTimeMs) void TracedTaskCommon::GetTLSTraceInfo() { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); mSourceEventType = info->mCurTraceSourceType; @@ -66,7 +66,7 @@ TracedTaskCommon::GetTLSTraceInfo() void TracedTaskCommon::SetTLSTraceInfo() { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); if (mIsTraceInfoInit) { @@ -79,7 +79,7 @@ TracedTaskCommon::SetTLSTraceInfo() void TracedTaskCommon::ClearTLSTraceInfo() { - TraceInfo* info = GetOrCreateTraceInfo(); + TraceInfoHolder info = GetOrCreateTraceInfo(); ENSURE_TRUE_VOID(info); info->mCurTraceSourceId = 0; From 41cfca6339250b6edff4a8152145f2e1b3066722 Mon Sep 17 00:00:00 2001 From: Noam Schmitt Date: Thu, 23 Feb 2017 13:27:13 +0100 Subject: [PATCH 016/102] Bug 1342022 - Remove useless a "using" declaration in WebrtcTelemetry.cpp. r=gfritzsche --- toolkit/components/telemetry/WebrtcTelemetry.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/toolkit/components/telemetry/WebrtcTelemetry.cpp b/toolkit/components/telemetry/WebrtcTelemetry.cpp index a437bff22f31..8c03f3a99fb0 100644 --- a/toolkit/components/telemetry/WebrtcTelemetry.cpp +++ b/toolkit/components/telemetry/WebrtcTelemetry.cpp @@ -12,8 +12,6 @@ #include "nsPrintfCString.h" #include "nsTHashtable.h" -using mozilla::Telemetry::Common::AutoHashtable; - void WebrtcTelemetry::RecordIceCandidateMask(const uint32_t iceCandidateBitmask, const bool success) From 51025861f3efddb1b482725843ef846ec575f02d Mon Sep 17 00:00:00 2001 From: Dan Minor Date: Wed, 22 Feb 2017 10:59:47 -0500 Subject: [PATCH 017/102] Bug 1305136 - Add additional status messages to loadFile function; r=padenot It seems like adding these extra "todos" decreases the frequency of this intermittent. I think it makes sense to land these temporarily while we look for a root cause. MozReview-Commit-ID: 4RiXtT3yBzG --- .../webaudio/test/test_audioContextSuspendResumeClose.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dom/media/webaudio/test/test_audioContextSuspendResumeClose.html b/dom/media/webaudio/test/test_audioContextSuspendResumeClose.html index e592cf0b1f6a..09ce1fd5aed3 100644 --- a/dom/media/webaudio/test/test_audioContextSuspendResumeClose.html +++ b/dom/media/webaudio/test/test_audioContextSuspendResumeClose.html @@ -48,10 +48,12 @@ function tryToCreateNodeOnClosedContext(ctx) { } function loadFile(url, callback) { + todo(false, "loadFile: " + url); var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.responseType = "arraybuffer"; xhr.onload = function() { + todo(false, "loadFile: " + url + " calling callback..."); callback(xhr.response); }; xhr.send(); From 8b6d3d5b8606913d83b6115a8ea1ddf645c71900 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Thu, 23 Feb 2017 15:26:49 +0100 Subject: [PATCH 018/102] Bug 1319087 - Add nukeCCW to the shell and test it. r=jandem --- js/src/jit-test/tests/cacheir/nukedCCW.js | 23 +++++++++++++++++++++++ js/src/shell/js.cpp | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 js/src/jit-test/tests/cacheir/nukedCCW.js diff --git a/js/src/jit-test/tests/cacheir/nukedCCW.js b/js/src/jit-test/tests/cacheir/nukedCCW.js new file mode 100644 index 000000000000..303750ce482a --- /dev/null +++ b/js/src/jit-test/tests/cacheir/nukedCCW.js @@ -0,0 +1,23 @@ +var wrapper = evaluate("({a: 15, b: {c: 42}})", {global: newGlobal({sameZoneAs: this})}); + +function test() { + var i, error; + try { + for (i = 0; i < 150; i++) { + assertEq(wrapper.b.c, 42); + assertEq(wrapper.a, 15); + + if (i == 142) { + // Next access to wrapper.b should throw. + nukeCCW(wrapper); + } + } + } catch (e) { + error = e; + } + + assertEq(error.message.includes("dead object"), true); + assertEq(i, 143); +} + +test(); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 89e012c925e2..5fb992b30e8b 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -5037,6 +5037,24 @@ NewGlobal(JSContext* cx, unsigned argc, Value* vp) return true; } +static bool +NukeCCW(JSContext* cx, unsigned argc, Value* vp) +{ + CallArgs args = CallArgsFromVp(argc, vp); + + if (args.length() != 1 || !args[0].isObject() || + !IsCrossCompartmentWrapper(&args[0].toObject())) + { + JS_ReportErrorNumberASCII(cx, my_GetErrorMessage, nullptr, JSSMSG_INVALID_ARGS, + "nukeCCW"); + return false; + } + + NukeCrossCompartmentWrapper(cx, &args[0].toObject()); + args.rval().setUndefined(); + return true; +} + static bool GetMaxArgs(JSContext* cx, unsigned argc, Value* vp) { @@ -6366,6 +6384,10 @@ static const JSFunctionSpecWithHelp shell_functions[] = { " principal is treated as if its bits were 0xffff, for subsumption\n" " purposes. If this property is omitted, supply no principal."), + JS_FN_HELP("nukeCCW", NukeCCW, 1, 0, +"nukeCCW(wrapper)", +" Nuke a CrossCompartmentWrapper, which turns it into a DeadProxyObject."), + JS_FN_HELP("createMappedArrayBuffer", CreateMappedArrayBuffer, 1, 0, "createMappedArrayBuffer(filename, [offset, [size]])", " Create an array buffer that mmaps the given file."), From 937b0ff5ffdac2b1d3fa7f2c3c524f82d1f977de Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Thu, 23 Feb 2017 09:01:16 -0600 Subject: [PATCH 019/102] Bug 1337561 - Increase executable code allocation size on 64-bit (r=jandem) MozReview-Commit-ID: DswlJQutGiC --- js/src/jit/ProcessExecutableMemory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/jit/ProcessExecutableMemory.h b/js/src/jit/ProcessExecutableMemory.h index df810ff16554..3323c5cba4f5 100644 --- a/js/src/jit/ProcessExecutableMemory.h +++ b/js/src/jit/ProcessExecutableMemory.h @@ -17,7 +17,7 @@ namespace jit { #if JS_BITS_PER_WORD == 32 static const size_t MaxCodeBytesPerProcess = 128 * 1024 * 1024; #else -static const size_t MaxCodeBytesPerProcess = 640 * 1024 * 1024; +static const size_t MaxCodeBytesPerProcess = 1 * 1024 * 1024 * 1024; #endif // Executable code is allocated in 64K chunks. ExecutableAllocator uses pools From 32c34613b1bf498bd4a8255f158ee6c4168d722b Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 23 Feb 2017 10:35:07 -0500 Subject: [PATCH 020/102] Bug 1302704 - part 1 - define CARGO_TARGET_DIR in the backend; r=chmanchester CARGO_TARGET_DIR is currently hardcoded to the current directory, but we'd like the ability to choose a value for Rust libraries. --- config/rules.mk | 2 +- python/mozbuild/mozbuild/backend/recursivemake.py | 2 ++ python/mozbuild/mozbuild/test/backend/test_recursivemake.py | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/rules.mk b/config/rules.mk index 1f974406b220..9bb17a2a8908 100644 --- a/config/rules.mk +++ b/config/rules.mk @@ -936,7 +936,7 @@ rustflags_override = RUSTFLAGS='$(rustflags)' endif CARGO_BUILD = env $(rustflags_override) \ - CARGO_TARGET_DIR=. \ + CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \ RUSTC=$(RUSTC) \ MOZ_DIST=$(ABS_DIST) \ LIBCLANG_PATH=$(MOZ_LIBCLANG_PATH) \ diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index 1e46d8d72e9f..d6c35d73893c 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -1077,6 +1077,7 @@ class RecursiveMakeBackend(CommonBackend): target_variable, target_cargo_variable): backend_file.write_once('CARGO_FILE := %s\n' % obj.cargo_file) + backend_file.write_once('CARGO_TARGET_DIR := .\n') backend_file.write('%s += %s\n' % (target_variable, obj.location)) backend_file.write('%s += %s\n' % (target_cargo_variable, obj.name)) @@ -1250,6 +1251,7 @@ class RecursiveMakeBackend(CommonBackend): feature_var = 'HOST_RUST_LIBRARY_FEATURES' backend_file.write_once('%s := %s\n' % (libdef.LIB_FILE_VAR, libdef.import_name)) backend_file.write('CARGO_FILE := $(srcdir)/Cargo.toml\n') + backend_file.write('CARGO_TARGET_DIR := .\n') if libdef.features: backend_file.write('%s := %s\n' % (libdef.FEATURES_VAR, ' '.join(libdef.features))) diff --git a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py index eacad57ef7d0..f0589ae311d0 100644 --- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py +++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py @@ -764,6 +764,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', + 'CARGO_TARGET_DIR := .', ] self.assertEqual(lines, expected) @@ -778,6 +779,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', + 'CARGO_TARGET_DIR := .', ] self.assertEqual(lines, expected) @@ -792,6 +794,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', + 'CARGO_TARGET_DIR := .', 'HOST_RUST_LIBRARY_FEATURES := musthave cantlivewithout', ] @@ -807,6 +810,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', + 'CARGO_TARGET_DIR := .', 'RUST_LIBRARY_FEATURES := musthave cantlivewithout', ] @@ -821,6 +825,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'CARGO_FILE := %s/code/Cargo.toml' % env.topsrcdir, + 'CARGO_TARGET_DIR := .', 'RUST_PROGRAMS += i686-pc-windows-msvc/release/target.exe', 'RUST_CARGO_PROGRAMS += target', 'HOST_RUST_PROGRAMS += i686-pc-windows-msvc/release/host.exe', From 288cc355afc8f7c6cc199dd9005f344c497977ac Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 23 Feb 2017 10:35:07 -0500 Subject: [PATCH 021/102] Bug 1302704 - part 2 - rename cargo_target_directory; r=chmanchester We're going to be introducing a value for CARGO_TARGET_DIR in a later patch, we we should rename this function to not conflict with that concept. --- python/mozbuild/mozbuild/frontend/data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/mozbuild/mozbuild/frontend/data.py b/python/mozbuild/mozbuild/frontend/data.py index 5c5893c28d25..d1254f17e787 100644 --- a/python/mozbuild/mozbuild/frontend/data.py +++ b/python/mozbuild/mozbuild/frontend/data.py @@ -420,7 +420,7 @@ class HostSimpleProgram(HostMixin, BaseProgram): KIND = 'host' -def cargo_target_directory(context, target_var): +def cargo_output_directory(context, target_var): # cargo creates several directories and places its build artifacts # in those directories. The directory structure depends not only # on the target, but also what sort of build we are doing. @@ -446,7 +446,7 @@ class BaseRustProgram(ContextDerived): ContextDerived.__init__(self, context) self.name = name self.cargo_file = cargo_file - cargo_dir = cargo_target_directory(context, self.TARGET_SUBST_VAR) + cargo_dir = cargo_output_directory(context, self.TARGET_SUBST_VAR) exe_file = '%s%s' % (name, context.config.substs.get(self.SUFFIX_VAR, '')) self.location = mozpath.join(cargo_dir, exe_file) @@ -542,7 +542,7 @@ class RustLibrary(StaticLibrary): basename.replace('-', '_'), context.config.lib_suffix) self.dependencies = dependencies - build_dir = cargo_target_directory(context, self.TARGET_SUBST_VAR) + build_dir = cargo_output_directory(context, self.TARGET_SUBST_VAR) self.import_name = mozpath.join(build_dir, self.lib_name) self.deps_path = mozpath.join(build_dir, 'deps') self.features = features From a2c19c682a7bcc143b8fa8460bbc33f2ccfdf37c Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 23 Feb 2017 10:35:07 -0500 Subject: [PATCH 022/102] Bug 1302704 - part 3 - propagate information about CARGO_TARGET_DIR from the frontend into the backend; r=chmanchester Rust libraries can set RUST_LIBRARY_TARGET_DIR so that they can share compilation artifacts with other libraries. This setting needs to be propagated to the backend so it can be communicated to Cargo. --- build/templates.mozbuild | 5 ++++- python/mozbuild/mozbuild/backend/recursivemake.py | 8 +++++++- python/mozbuild/mozbuild/frontend/context.py | 9 +++++++++ python/mozbuild/mozbuild/frontend/data.py | 7 +++++-- python/mozbuild/mozbuild/frontend/emitter.py | 4 +++- .../mozbuild/mozbuild/test/backend/test_recursivemake.py | 8 ++++---- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/build/templates.mozbuild b/build/templates.mozbuild index 9b8500f659b5..89240b5c5276 100644 --- a/build/templates.mozbuild +++ b/build/templates.mozbuild @@ -61,7 +61,7 @@ def Library(name): @template -def RustLibrary(name, features=None): +def RustLibrary(name, features=None, target_dir=None): '''Template for Rust libraries.''' Library(name) @@ -70,6 +70,9 @@ def RustLibrary(name, features=None): if features: RUST_LIBRARY_FEATURES = features + if target_dir: + RUST_LIBRARY_TARGET_DIR = target_dir + @template def SharedLibrary(name): diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index d6c35d73893c..b605fd7e745b 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -1251,7 +1251,13 @@ class RecursiveMakeBackend(CommonBackend): feature_var = 'HOST_RUST_LIBRARY_FEATURES' backend_file.write_once('%s := %s\n' % (libdef.LIB_FILE_VAR, libdef.import_name)) backend_file.write('CARGO_FILE := $(srcdir)/Cargo.toml\n') - backend_file.write('CARGO_TARGET_DIR := .\n') + # Need to normalize the path so Cargo sees the same paths from all + # possible invocations of Cargo with this CARGO_TARGET_DIR. Otherwise, + # Cargo's dependency calculations don't work as we expect and we wind + # up recompiling lots of things. + target_dir = mozpath.join(backend_file.objdir, libdef.target_dir) + target_dir = mozpath.normpath(target_dir) + backend_file.write('CARGO_TARGET_DIR := %s\n' % target_dir) if libdef.features: backend_file.write('%s := %s\n' % (libdef.FEATURES_VAR, ' '.join(libdef.features))) diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index 00560e85b606..0e784d835673 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -959,6 +959,15 @@ VARIABLES = { RustLibrary template instead. """), + 'RUST_LIBRARY_TARGET_DIR': (unicode, unicode, + """Where CARGO_TARGET_DIR should point when compiling this library. If + not set, it defaults to the current objdir. It should be a relative path + to the current objdir; absolute paths should not be used. + + This variable should not be used directly; you should be using the + RustLibrary template instead. + """), + 'HOST_RUST_LIBRARY_FEATURES': (List, list, """Cargo features to activate for this host library. diff --git a/python/mozbuild/mozbuild/frontend/data.py b/python/mozbuild/mozbuild/frontend/data.py index d1254f17e787..5b07dafdddcc 100644 --- a/python/mozbuild/mozbuild/frontend/data.py +++ b/python/mozbuild/mozbuild/frontend/data.py @@ -523,13 +523,14 @@ class RustLibrary(StaticLibrary): 'dependencies', 'deps_path', 'features', + 'target_dir', ) TARGET_SUBST_VAR = 'RUST_TARGET' FEATURES_VAR = 'RUST_LIBRARY_FEATURES' LIB_FILE_VAR = 'RUST_LIBRARY_FILE' def __init__(self, context, basename, cargo_file, crate_type, dependencies, - features, **args): + features, target_dir, **args): StaticLibrary.__init__(self, context, basename, **args) self.cargo_file = cargo_file self.crate_type = crate_type @@ -542,10 +543,12 @@ class RustLibrary(StaticLibrary): basename.replace('-', '_'), context.config.lib_suffix) self.dependencies = dependencies - build_dir = cargo_output_directory(context, self.TARGET_SUBST_VAR) + build_dir = mozpath.join(target_dir, + cargo_output_directory(context, self.TARGET_SUBST_VAR)) self.import_name = mozpath.join(build_dir, self.lib_name) self.deps_path = mozpath.join(build_dir, 'deps') self.features = features + self.target_dir = target_dir class SharedLibrary(Library): diff --git a/python/mozbuild/mozbuild/frontend/emitter.py b/python/mozbuild/mozbuild/frontend/emitter.py index d518bd20a32c..0dfa49c2ad32 100644 --- a/python/mozbuild/mozbuild/frontend/emitter.py +++ b/python/mozbuild/mozbuild/frontend/emitter.py @@ -465,6 +465,8 @@ class TreeMetadataEmitter(LoggingMixin): ' in [profile.%s] section') % (libname, profile_name), context) + cargo_target_dir = context.get('RUST_LIBRARY_TARGET_DIR', '.') + dependencies = set(config.get('dependencies', {}).iterkeys()) features = context.get(cls.FEATURES_VAR, []) @@ -475,7 +477,7 @@ class TreeMetadataEmitter(LoggingMixin): context) return cls(context, libname, cargo_file, crate_type, dependencies, - features, **static_args) + features, cargo_target_dir, **static_args) def _handle_linkables(self, context, passthru, generated_files): diff --git a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py index f0589ae311d0..8658ae2f33a9 100644 --- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py +++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py @@ -764,7 +764,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', - 'CARGO_TARGET_DIR := .', + 'CARGO_TARGET_DIR := %s' % env.topobjdir, ] self.assertEqual(lines, expected) @@ -779,7 +779,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', - 'CARGO_TARGET_DIR := .', + 'CARGO_TARGET_DIR := %s' % env.topobjdir, ] self.assertEqual(lines, expected) @@ -794,7 +794,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', - 'CARGO_TARGET_DIR := .', + 'CARGO_TARGET_DIR := %s' % env.topobjdir, 'HOST_RUST_LIBRARY_FEATURES := musthave cantlivewithout', ] @@ -810,7 +810,7 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ 'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', - 'CARGO_TARGET_DIR := .', + 'CARGO_TARGET_DIR := %s' % env.topobjdir, 'RUST_LIBRARY_FEATURES := musthave cantlivewithout', ] From 5e00cd9e5545e3332b342dc6b156d3da058c258b Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 23 Feb 2017 10:35:07 -0500 Subject: [PATCH 023/102] Bug 1302704 - part 4 - provide a target directory for gkrust and gkrust-gtest; r=chmanchester Doing this gets us all of the benefits that we want from Cargo workspaces (only compiling artifacts from gkrust-shared one time for both libraries) without all the hassles that using Cargo workspaces would require. We don't have to worry about multiple Cargo processes running simultaneously and racing to write files; Cargo is smart enough to lock the build directory to serialize access to it. --- toolkit/library/gtest/rust/moz.build | 2 +- toolkit/library/rust/moz.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/toolkit/library/gtest/rust/moz.build b/toolkit/library/gtest/rust/moz.build index 6fe3f8931bc2..26ba750e09f3 100644 --- a/toolkit/library/gtest/rust/moz.build +++ b/toolkit/library/gtest/rust/moz.build @@ -14,4 +14,4 @@ if CONFIG['MOZ_STYLO']: if CONFIG['MOZ_ENABLE_WEBRENDER']: features += ['quantum_render'] -RustLibrary('gkrust-gtest', features) +RustLibrary('gkrust-gtest', features, '../..') diff --git a/toolkit/library/rust/moz.build b/toolkit/library/rust/moz.build index a5cec1fbbf19..069a8d4ecde7 100644 --- a/toolkit/library/rust/moz.build +++ b/toolkit/library/rust/moz.build @@ -14,4 +14,4 @@ if CONFIG['MOZ_STYLO']: if CONFIG['MOZ_ENABLE_WEBRENDER']: features += ['quantum_render'] -RustLibrary('gkrust', features) +RustLibrary('gkrust', features, '..') From 77f7b6de8b370b3683de74397e385cd945ec0735 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 23 Feb 2017 10:35:07 -0500 Subject: [PATCH 024/102] Bug 1302704 - part 5 - harmonize gkrust_gtest's profile.release with gkrust's; r=chmanchester The comment here is a relic from bygone days when we tried sticking gkrust and gkrust-gtest into the same library at link time. Making gkrust and gkrust-gtest's profile.release settings identical also means that Cargo considers build artifacts from one suitable for the other, which is extremely desirable with our new shared CARGO_TARGET_DIR setup. --- toolkit/library/gtest/rust/Cargo.toml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/toolkit/library/gtest/rust/Cargo.toml b/toolkit/library/gtest/rust/Cargo.toml index 21627fc580aa..8d6e6b6ae6df 100644 --- a/toolkit/library/gtest/rust/Cargo.toml +++ b/toolkit/library/gtest/rust/Cargo.toml @@ -39,11 +39,6 @@ panic = "abort" opt-level = 2 debug = true rpath = false -# This would normally be 'true' for release configurations, but using LTO on -# rul-gtest causes link failures due to symbols also being found in libxul's -# librul.a. But LTO'ing things here is not crucial and not LTO'ing things -# enables us to link libxul-gtest, so we leave it turned off. -lto = false +lto = true debug-assertions = false -codegen-units = 1 panic = "abort" From 1a557cbccb41fe971fa4057dec678aa90e509a9c Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 23 Feb 2017 10:35:06 -0500 Subject: [PATCH 025/102] Bug 1302704 - part 6 - enforce identical profiles for gkrust and gkrust-gtest; r=chmanchester Cargo hashes various compilation settings into the dependency graph for dependent libraries. So if the compilation settings for gkrust and gkrust-gtest are different, their dependencies will likewise be different. The setup we've created in the previous patches depends on the compilation settings being identical, so we should enforce that at the moz.build level. --- python/mozbuild/mozbuild/frontend/emitter.py | 28 +++++++++++++++++++ .../data/rust-library-features/Cargo.toml | 2 +- .../data/rust-library-features/moz.build | 2 +- .../test/backend/data/rust-library/Cargo.toml | 2 +- .../test/backend/data/rust-library/moz.build | 2 +- .../test/backend/test_recursivemake.py | 8 +++--- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/python/mozbuild/mozbuild/frontend/emitter.py b/python/mozbuild/mozbuild/frontend/emitter.py index 0dfa49c2ad32..8de24fd8ee45 100644 --- a/python/mozbuild/mozbuild/frontend/emitter.py +++ b/python/mozbuild/mozbuild/frontend/emitter.py @@ -465,6 +465,34 @@ class TreeMetadataEmitter(LoggingMixin): ' in [profile.%s] section') % (libname, profile_name), context) + # gkrust and gkrust-gtest must have the exact same profile settings + # for our almost-workspaces configuration to work properly. + if libname in ('gkrust', 'gkrust-gtest'): + if profile_name == 'dev': + expected_profile = { + 'opt-level': 1, + 'debug': True, + 'rpath': False, + 'lto': False, + 'debug-assertions': True, + 'codegen-units': 1, + 'panic': 'abort', + } + else: + expected_profile = { + 'opt-level': 2, + 'debug': True, + 'rpath': False, + 'lto': True, + 'debug-assertions': False, + 'panic': 'abort', + } + + if profile != expected_profile: + raise SandboxValidationError( + 'Cargo profile.%s for %s is incorrect' % (profile_name, libname), + context) + cargo_target_dir = context.get('RUST_LIBRARY_TARGET_DIR', '.') dependencies = set(config.get('dependencies', {}).iterkeys()) diff --git a/python/mozbuild/mozbuild/test/backend/data/rust-library-features/Cargo.toml b/python/mozbuild/mozbuild/test/backend/data/rust-library-features/Cargo.toml index cbaeaecec8fb..756ab433420f 100644 --- a/python/mozbuild/mozbuild/test/backend/data/rust-library-features/Cargo.toml +++ b/python/mozbuild/mozbuild/test/backend/data/rust-library-features/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "gkrust" +name = "feature-library" version = "0.1.0" authors = [ "Nobody ", diff --git a/python/mozbuild/mozbuild/test/backend/data/rust-library-features/moz.build b/python/mozbuild/mozbuild/test/backend/data/rust-library-features/moz.build index 5efbe4d3763d..3394fdd4e39a 100644 --- a/python/mozbuild/mozbuild/test/backend/data/rust-library-features/moz.build +++ b/python/mozbuild/mozbuild/test/backend/data/rust-library-features/moz.build @@ -16,4 +16,4 @@ def RustLibrary(name, features): RUST_LIBRARY_FEATURES = features -RustLibrary('gkrust', ['musthave', 'cantlivewithout']) +RustLibrary('feature-library', ['musthave', 'cantlivewithout']) diff --git a/python/mozbuild/mozbuild/test/backend/data/rust-library/Cargo.toml b/python/mozbuild/mozbuild/test/backend/data/rust-library/Cargo.toml index cbaeaecec8fb..bde9b929d997 100644 --- a/python/mozbuild/mozbuild/test/backend/data/rust-library/Cargo.toml +++ b/python/mozbuild/mozbuild/test/backend/data/rust-library/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "gkrust" +name = "test-library" version = "0.1.0" authors = [ "Nobody ", diff --git a/python/mozbuild/mozbuild/test/backend/data/rust-library/moz.build b/python/mozbuild/mozbuild/test/backend/data/rust-library/moz.build index ec2c83d60393..970b6b4be5df 100644 --- a/python/mozbuild/mozbuild/test/backend/data/rust-library/moz.build +++ b/python/mozbuild/mozbuild/test/backend/data/rust-library/moz.build @@ -15,4 +15,4 @@ def RustLibrary(name): IS_RUST_LIBRARY = True -RustLibrary('gkrust') +RustLibrary('test-library') diff --git a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py index 8658ae2f33a9..d4fc1b87763b 100644 --- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py +++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py @@ -762,7 +762,7 @@ class TestRecursiveMakeBackend(BackendTester): lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]] expected = [ - 'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a', + 'RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libtest_library.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', 'CARGO_TARGET_DIR := %s' % env.topobjdir, ] @@ -777,7 +777,7 @@ class TestRecursiveMakeBackend(BackendTester): lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]] expected = [ - 'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a', + 'HOST_RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libhostrusttool.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', 'CARGO_TARGET_DIR := %s' % env.topobjdir, ] @@ -792,7 +792,7 @@ class TestRecursiveMakeBackend(BackendTester): lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]] expected = [ - 'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a', + 'HOST_RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libhostrusttool.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', 'CARGO_TARGET_DIR := %s' % env.topobjdir, 'HOST_RUST_LIBRARY_FEATURES := musthave cantlivewithout', @@ -808,7 +808,7 @@ class TestRecursiveMakeBackend(BackendTester): lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]] expected = [ - 'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a', + 'RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libfeature_library.a', 'CARGO_FILE := $(srcdir)/Cargo.toml', 'CARGO_TARGET_DIR := %s' % env.topobjdir, 'RUST_LIBRARY_FEATURES := musthave cantlivewithout', From 8cd96c78efc84495ae835dcaabce2946bfd002fa Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 23 Feb 2017 10:54:41 -0500 Subject: [PATCH 026/102] Bug 1340652 P1 Assert principal URL matches final worker script URL. r=baku --- dom/workers/ScriptLoader.cpp | 4 +++ dom/workers/WorkerPrivate.cpp | 58 +++++++++++++++++++++++++++++++++++ dom/workers/WorkerPrivate.h | 3 ++ dom/workers/Workers.h | 3 ++ 4 files changed, 68 insertions(+) diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 6d6cd257ba0d..d5990c691c34 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -622,6 +622,10 @@ private: MOZ_ASSERT(!loadInfo.mLoadingFinished); loadInfo.mLoadingFinished = true; + if (IsMainWorkerScript() && NS_SUCCEEDED(aRv)) { + MOZ_DIAGNOSTIC_ASSERT(mWorkerPrivate->PrincipalURIMatchesScriptURL()); + } + MaybeExecuteFinishedScripts(aIndex); } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index f79197835952..14efbbd9e8fb 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1985,6 +1985,57 @@ WorkerLoadInfo::PrincipalIsValid() const mPrincipalInfo->type() != PrincipalInfo::T__None && mPrincipalInfo->type() <= PrincipalInfo::T__Last; } + +bool +WorkerLoadInfo::PrincipalURIMatchesScriptURL() +{ + AssertIsOnMainThread(); + + nsAutoCString scheme; + nsresult rv = mBaseURI->GetScheme(scheme); + NS_ENSURE_SUCCESS(rv, false); + + // A system principal must either be a blob URL or a resource JSM. + if (mPrincipal->GetIsSystemPrincipal()) { + if (scheme == NS_LITERAL_CSTRING("blob")) { + return true; + } + + bool isResource = false; + nsresult rv = NS_URIChainHasFlags(mBaseURI, + nsIProtocolHandler::URI_IS_UI_RESOURCE, + &isResource); + NS_ENSURE_SUCCESS(rv, false); + + return isResource; + } + + // A null principal can occur for a data URL worker script or a blob URL + // worker script from a sandboxed iframe. + if (mPrincipal->GetIsNullPrincipal()) { + return scheme == NS_LITERAL_CSTRING("data") || + scheme == NS_LITERAL_CSTRING("blob"); + } + + // The principal for a blob: URL worker script does not have a matching URL. + // This is likely a bug in our referer setting logic, but exempt it for now. + // This is another reason we should fix bug 1340694 so that referer does not + // depend on the principal URI. + if (scheme == NS_LITERAL_CSTRING("blob")) { + return true; + } + + nsCOMPtr principalURI; + rv = mPrincipal->GetURI(getter_AddRefs(principalURI)); + NS_ENSURE_SUCCESS(rv, false); + NS_ENSURE_TRUE(principalURI, false); + + bool equal = false; + rv = principalURI->Equals(mBaseURI, &equal); + NS_ENSURE_SUCCESS(rv, false); + + return equal; +} #endif // defined(DEBUG) || !defined(RELEASE_OR_BETA) bool @@ -3869,6 +3920,13 @@ WorkerPrivateParent::FinalChannelPrincipalIsValid(nsIChannel* aChannel) { return mLoadInfo.FinalChannelPrincipalIsValid(aChannel); } + +template +bool +WorkerPrivateParent::PrincipalURIMatchesScriptURL() +{ + return mLoadInfo.PrincipalURIMatchesScriptURL(); +} #endif template diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 545f2c63a1d2..a79ac49d5ed8 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -655,6 +655,9 @@ public: #if defined(DEBUG) || !defined(RELEASE_OR_BETA) bool FinalChannelPrincipalIsValid(nsIChannel* aChannel); + + bool + PrincipalURIMatchesScriptURL(); #endif bool diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index 66e5b9ecceab..f7b94c5394ba 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -296,6 +296,9 @@ struct WorkerLoadInfo bool PrincipalIsValid() const; + + bool + PrincipalURIMatchesScriptURL(); #endif bool From e83a07114055f6934282327e6f74a9f51eaab7bd Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 23 Feb 2017 10:54:41 -0500 Subject: [PATCH 027/102] Bug 1340652 P2 Override worker principal after channel load completes to get correct principal URL. r=baku --- dom/workers/ScriptLoader.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index d5990c691c34..b2b7746a84ae 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -1141,8 +1141,18 @@ private: // Store the channel info if needed. mWorkerPrivate->InitChannelInfo(channel); + // Our final channel principal should match the original principal + // in terms of the origin. MOZ_DIAGNOSTIC_ASSERT(mWorkerPrivate->FinalChannelPrincipalIsValid(channel)); + // However, we must still override the principal since the nsIPrincipal + // URL may be different due to same-origin redirects. Unfortunately this + // URL must exactly match the final worker script URL in order to + // properly set the referrer header on fetch/xhr requests. If bug 1340694 + // is ever fixed this can be removed. + rv = mWorkerPrivate->SetPrincipalFromChannel(channel); + NS_ENSURE_SUCCESS(rv, rv); + // We did inherit CSP in bug 1223647. If we do not already have a CSP, we // should get it from the HTTP headers on the worker script. if (!mWorkerPrivate->GetCSP() && CSPService::sCSPEnabled) { @@ -1234,7 +1244,8 @@ private: // Override the principal on the WorkerPrivate. This is only necessary // in order to get a principal with exactly the correct URL. The fetch // referrer logic depends on the WorkerPrivate principal having a URL - // that matches the worker script URL. + // that matches the worker script URL. If bug 1340694 is ever fixed + // this can be removed. rv = mWorkerPrivate->SetPrincipalOnMainThread(responsePrincipal, loadGroup); MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); From 948075245c625280ffa7daa8148164eddcbd093a Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 23 Feb 2017 10:54:42 -0500 Subject: [PATCH 028/102] Bug 1340652 P3 Test XHR referer header from redirected worker script. r=baku --- testing/web-platform/meta/MANIFEST.json | 10 +++++ .../open-url-redirected-worker-origin.htm | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 testing/web-platform/tests/XMLHttpRequest/open-url-redirected-worker-origin.htm diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 8741ee781b29..ae800c288cb5 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -80855,6 +80855,12 @@ {} ] ], + "XMLHttpRequest/open-url-redirected-worker-origin.htm": [ + [ + "/XMLHttpRequest/open-url-redirected-worker-origin.htm", + {} + ] + ], "XMLHttpRequest/open-url-worker-origin.htm": [ [ "/XMLHttpRequest/open-url-worker-origin.htm", @@ -136404,6 +136410,10 @@ "28603b8d225367ba648bb9271dec5cb3da73d733", "testharness" ], + "XMLHttpRequest/open-url-redirected-worker-origin.htm": [ + "98c20df1cd8c7e27a94ba55f7c94d19244d7ff59", + "testharness" + ], "XMLHttpRequest/open-url-worker-origin.htm": [ "e4db65c7c0a98d7f5aa84eac01705259f377f44b", "testharness" diff --git a/testing/web-platform/tests/XMLHttpRequest/open-url-redirected-worker-origin.htm b/testing/web-platform/tests/XMLHttpRequest/open-url-redirected-worker-origin.htm new file mode 100644 index 000000000000..86cba0ccb5fc --- /dev/null +++ b/testing/web-platform/tests/XMLHttpRequest/open-url-redirected-worker-origin.htm @@ -0,0 +1,44 @@ + + + + + XMLHttpRequest: redirected worker scripts, origin and referrer + + + + + +
+ + + From 9d9c4dd5902e59c2fdfe937b6ba2f764eafc684c Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 23 Feb 2017 10:54:42 -0500 Subject: [PATCH 029/102] Bug 1340652 P4 Test fetch referer header in worker and redirected worker scripts. r=baku --- testing/web-platform/meta/MANIFEST.json | 22 ++++++++++++++++++- .../request-referrer-redirected-worker.html | 17 ++++++++++++++ .../api/basic/request-referrer-worker.html | 14 ++++++++++++ .../tests/fetch/api/basic/request-referrer.js | 10 ++++----- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 testing/web-platform/tests/fetch/api/basic/request-referrer-redirected-worker.html create mode 100644 testing/web-platform/tests/fetch/api/basic/request-referrer-worker.html diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index ae800c288cb5..177171d31a46 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -87099,6 +87099,18 @@ {} ] ], + "fetch/api/basic/request-referrer-redirected-worker.html": [ + [ + "/fetch/api/basic/request-referrer-redirected-worker.html", + {} + ] + ], + "fetch/api/basic/request-referrer-worker.html": [ + [ + "/fetch/api/basic/request-referrer-worker.html", + {} + ] + ], "fetch/api/basic/request-referrer.html": [ [ "/fetch/api/basic/request-referrer.html", @@ -163318,12 +163330,20 @@ "6a15c64c072f4e57470ed3f2709e43fa2f806b79", "support" ], + "fetch/api/basic/request-referrer-redirected-worker.html": [ + "41013925a84ab080c9c9f3b16ef4d8fdd1d50588", + "testharness" + ], + "fetch/api/basic/request-referrer-worker.html": [ + "3dad9617d76eed94d8b759d0d27b20c431873dd4", + "testharness" + ], "fetch/api/basic/request-referrer.html": [ "acf1ca37cf3904eccf4c7a9248c49e68f6260866", "testharness" ], "fetch/api/basic/request-referrer.js": [ - "5267f72887c4f7b039d2a5aae3519dc54cceca97", + "03c8ccec8ee4b37994bf38f20ff9fd531a209974", "support" ], "fetch/api/basic/request-upload-worker.html": [ diff --git a/testing/web-platform/tests/fetch/api/basic/request-referrer-redirected-worker.html b/testing/web-platform/tests/fetch/api/basic/request-referrer-redirected-worker.html new file mode 100644 index 000000000000..0306c8770c6d --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-referrer-redirected-worker.html @@ -0,0 +1,17 @@ + + + + + Fetch in worker: referrer header + + + + + + + diff --git a/testing/web-platform/tests/fetch/api/basic/request-referrer-worker.html b/testing/web-platform/tests/fetch/api/basic/request-referrer-worker.html new file mode 100644 index 000000000000..d598c8bad584 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/basic/request-referrer-worker.html @@ -0,0 +1,14 @@ + + + + + Fetch in worker: referrer header + + + + + + + diff --git a/testing/web-platform/tests/fetch/api/basic/request-referrer.js b/testing/web-platform/tests/fetch/api/basic/request-referrer.js index cc5cc8e01d40..6a55c6179e1b 100644 --- a/testing/web-platform/tests/fetch/api/basic/request-referrer.js +++ b/testing/web-platform/tests/fetch/api/basic/request-referrer.js @@ -3,7 +3,7 @@ if (this.document === undefined) { importScripts("../resources/utils.js"); } -function testReferrer(referrer, expected) { +function testReferrer(referrer, expected, desc) { promise_test(function(test) { var url = RESOURCES_DIR + "inspect-headers.py?headers=referer" var req = new Request(url, { referrer: referrer }); @@ -17,12 +17,12 @@ function testReferrer(referrer, expected) { assert_equals(actual, "", "request's referer should be empty"); } }); - }); + }, desc); } -testReferrer("about:client", window.location.href); +testReferrer("about:client", self.location.href, 'about:client referrer'); -var fooURL = new URL("./foo", window.location).href; -testReferrer(fooURL, fooURL); +var fooURL = new URL("./foo", self.location).href; +testReferrer(fooURL, fooURL, 'url referrer'); done(); From c9becaecea16a8e03c0835c5e6656634052f1b75 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 23 Feb 2017 10:54:42 -0500 Subject: [PATCH 030/102] Bug 1340654 P1 Set referrer policy in service workers. r=baku --- dom/workers/ScriptLoader.cpp | 27 ++++++++++++++------------- dom/workers/WorkerPrivate.cpp | 20 ++++++++++++++++++++ dom/workers/WorkerPrivate.h | 3 +++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index b2b7746a84ae..f2f92a7c175f 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -476,6 +476,7 @@ private: UniquePtr mPrincipalInfo; nsCString mCSPHeaderValue; nsCString mCSPReportOnlyHeaderValue; + nsCString mReferrerPolicyHeaderValue; }; NS_IMPL_ISUPPORTS(CacheScriptLoader, nsIStreamLoaderObserver) @@ -1160,6 +1161,9 @@ private: tCspROHeaderValue); NS_ENSURE_SUCCESS(rv, rv); } + + mWorkerPrivate->SetReferrerPolicyFromHeaderValue(tRPHeaderCValue); + WorkerPrivate* parent = mWorkerPrivate->GetParent(); if (parent) { // XHR Params Allowed @@ -1167,16 +1171,6 @@ private: } } - NS_ConvertUTF8toUTF16 tRPHeaderValue(tRPHeaderCValue); - // If there's a Referrer-Policy header, apply it. - if (!tRPHeaderValue.IsEmpty()) { - net::ReferrerPolicy policy = - nsContentUtils::GetReferrerPolicyFromHeader(tRPHeaderValue); - if (policy != net::RP_Unset) { - mWorkerPrivate->SetReferrerPolicy(policy); - } - } - return NS_OK; } @@ -1186,7 +1180,8 @@ private: const mozilla::dom::ChannelInfo& aChannelInfo, UniquePtr aPrincipalInfo, const nsACString& aCSPHeaderValue, - const nsACString& aCSPReportOnlyHeaderValue) + const nsACString& aCSPReportOnlyHeaderValue, + const nsACString& aReferrerPolicyHeaderValue) { AssertIsOnMainThread(); MOZ_ASSERT(aIndex < mLoadInfos.Length()); @@ -1252,6 +1247,8 @@ private: rv = mWorkerPrivate->SetCSPFromHeaderValues(aCSPHeaderValue, aCSPReportOnlyHeaderValue); MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); + + mWorkerPrivate->SetReferrerPolicyFromHeaderValue(aReferrerPolicyHeaderValue); } if (NS_SUCCEEDED(rv)) { @@ -1667,6 +1664,8 @@ CacheScriptLoader::ResolvedCallback(JSContext* aCx, mCSPHeaderValue, ignored); headers->Get(NS_LITERAL_CSTRING("content-security-policy-report-only"), mCSPReportOnlyHeaderValue, ignored); + headers->Get(NS_LITERAL_CSTRING("referrer-policy"), + mReferrerPolicyHeaderValue, ignored); nsCOMPtr inputStream; response->GetBody(getter_AddRefs(inputStream)); @@ -1680,7 +1679,8 @@ CacheScriptLoader::ResolvedCallback(JSContext* aCx, mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached; mRunnable->DataReceivedFromCache(mIndex, (uint8_t*)"", 0, mChannelInfo, Move(mPrincipalInfo), mCSPHeaderValue, - mCSPReportOnlyHeaderValue); + mCSPReportOnlyHeaderValue, + mReferrerPolicyHeaderValue); return; } @@ -1741,7 +1741,8 @@ CacheScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aCont MOZ_ASSERT(mPrincipalInfo); mRunnable->DataReceivedFromCache(mIndex, aString, aStringLen, mChannelInfo, Move(mPrincipalInfo), mCSPHeaderValue, - mCSPReportOnlyHeaderValue); + mCSPReportOnlyHeaderValue, + mReferrerPolicyHeaderValue); return NS_OK; } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 14efbbd9e8fb..37ed1641d83f 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -2691,6 +2691,26 @@ WorkerPrivateParent::SetCSPFromHeaderValues(const nsACString& aCSPHeade return NS_OK; } +template +void +WorkerPrivateParent::SetReferrerPolicyFromHeaderValue( + const nsACString& aReferrerPolicyHeaderValue) +{ + NS_ConvertUTF8toUTF16 headerValue(aReferrerPolicyHeaderValue); + + if (headerValue.IsEmpty()) { + return; + } + + net::ReferrerPolicy policy = + nsContentUtils::GetReferrerPolicyFromHeader(headerValue); + if (policy == net::RP_Unset) { + return; + } + + SetReferrerPolicy(policy); +} + // Can't use NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerPrivateParent) because of the // templates. diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index a79ac49d5ed8..5e243ec1057c 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -706,6 +706,9 @@ public: SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue, const nsACString& aCSPReportOnlyHeaderValue); + void + SetReferrerPolicyFromHeaderValue(const nsACString& aReferrerPolicyHeaderValue); + net::ReferrerPolicy GetReferrerPolicy() const { From c7bc529dfcb97a0ecf3cf353865a887d6eec43ac Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 23 Feb 2017 10:54:43 -0500 Subject: [PATCH 031/102] Bug 1340654 P2 Test that nested referrer policy from an importScripts() has no effect. r=baku --- testing/web-platform/meta/MANIFEST.json | 24 ++++++++++++++++--- .../tests/fetch/api/policies/nested-policy.js | 1 + .../api/policies/nested-policy.js.headers | 1 + .../referrer-origin-when-cross-origin.js | 4 ++++ .../fetch/api/policies/referrer-origin.js | 4 ++++ .../fetch/api/policies/referrer-unsafe-url.js | 4 ++++ 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 testing/web-platform/tests/fetch/api/policies/nested-policy.js create mode 100644 testing/web-platform/tests/fetch/api/policies/nested-policy.js.headers diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 177171d31a46..4ef43752cb42 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -43419,6 +43419,16 @@ {} ] ], + "fetch/api/policies/nested-policy.js": [ + [ + {} + ] + ], + "fetch/api/policies/nested-policy.js.headers": [ + [ + {} + ] + ], "fetch/api/policies/referrer-no-referrer.html.headers": [ [ {} @@ -163674,6 +163684,14 @@ "94dc6f63015b0835eb2a8c1892636bafeb1dfee7", "support" ], + "fetch/api/policies/nested-policy.js": [ + "57cfc2060102695b601209e4927861aaee377c4e", + "support" + ], + "fetch/api/policies/nested-policy.js.headers": [ + "fab90d344cbb78bad6445288c418b87736a830ae", + "support" + ], "fetch/api/policies/referrer-no-referrer-worker.html": [ "cc9274c1b182a487dbe945e6d8754a671d78e3c4", "testharness" @@ -163707,7 +163725,7 @@ "support" ], "fetch/api/policies/referrer-origin-when-cross-origin.js": [ - "e750c643dda40176e230d39e38057d4d2bda4fcf", + "f6b25aad46ba48422fab737582e82179666b5233", "support" ], "fetch/api/policies/referrer-origin-when-cross-origin.js.headers": [ @@ -163727,7 +163745,7 @@ "support" ], "fetch/api/policies/referrer-origin.js": [ - "368af4830da8fcd341ffb513b8c6c2c2bcfab3d9", + "8d8b58a4d5046e55e6bd97289cf6e515614e9577", "support" ], "fetch/api/policies/referrer-origin.js.headers": [ @@ -163747,7 +163765,7 @@ "support" ], "fetch/api/policies/referrer-unsafe-url.js": [ - "24d042ef4e85cccf3d178f701af5664c954deaf3", + "e1881c5f3f0a7d1705a5d2eb5d3381d8788374d8", "support" ], "fetch/api/policies/referrer-unsafe-url.js.headers": [ diff --git a/testing/web-platform/tests/fetch/api/policies/nested-policy.js b/testing/web-platform/tests/fetch/api/policies/nested-policy.js new file mode 100644 index 000000000000..b0d17696c337 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/policies/nested-policy.js @@ -0,0 +1 @@ +// empty, but referrer-policy set on this file diff --git a/testing/web-platform/tests/fetch/api/policies/nested-policy.js.headers b/testing/web-platform/tests/fetch/api/policies/nested-policy.js.headers new file mode 100644 index 000000000000..7ffbf17d6be5 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/policies/nested-policy.js.headers @@ -0,0 +1 @@ +Referrer-Policy: no-referrer diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js b/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js index 2baf7d12593f..b9e6b1fbe259 100644 --- a/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js +++ b/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js @@ -1,6 +1,10 @@ if (this.document === undefined) { importScripts("/resources/testharness.js"); importScripts("../resources/utils.js"); + + // A nested importScripts() with a referrer-policy should have no effect + // on overall worker policy. + importScripts("nested-policy.js"); } var referrerOrigin = "http://{{host}}:{{ports[http][0]}}/"; diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-origin.js b/testing/web-platform/tests/fetch/api/policies/referrer-origin.js index de187657486d..596ff818ca34 100644 --- a/testing/web-platform/tests/fetch/api/policies/referrer-origin.js +++ b/testing/web-platform/tests/fetch/api/policies/referrer-origin.js @@ -1,6 +1,10 @@ if (this.document === undefined) { importScripts("/resources/testharness.js"); importScripts("../resources/utils.js"); + + // A nested importScripts() with a referrer-policy should have no effect + // on overall worker policy. + importScripts("nested-policy.js"); } var referrerOrigin = "http://{{host}}:{{ports[http][0]}}/"; diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url.js b/testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url.js index b593fad5aa2b..4d61172613ee 100644 --- a/testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url.js +++ b/testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url.js @@ -1,6 +1,10 @@ if (this.document === undefined) { importScripts("/resources/testharness.js"); importScripts("../resources/utils.js"); + + // A nested importScripts() with a referrer-policy should have no effect + // on overall worker policy. + importScripts("nested-policy.js"); } var referrerUrl = location.href; From 400e3c0824221126afd76c74911d72c7523e0b9d Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 23 Feb 2017 10:54:43 -0500 Subject: [PATCH 032/102] Bug 1340654 P3 Test referrer-policy in service workers. r=baku --- testing/web-platform/meta/MANIFEST.json | 46 +++++++++++++++++-- ...errer-origin-service-worker.https.html.ini | 5 ++ ...rrer-no-referrer-service-worker.https.html | 18 ++++++++ .../referrer-origin-service-worker.https.html | 18 ++++++++ ...hen-cross-origin-service-worker.https.html | 17 +++++++ .../referrer-origin-when-cross-origin.js | 4 +- .../fetch/api/policies/referrer-origin.html | 2 +- .../fetch/api/policies/referrer-origin.js | 4 +- ...errer-unsafe-url-service-worker.https.html | 18 ++++++++ 9 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 testing/web-platform/meta/fetch/api/policies/referrer-origin-service-worker.https.html.ini create mode 100644 testing/web-platform/tests/fetch/api/policies/referrer-no-referrer-service-worker.https.html create mode 100644 testing/web-platform/tests/fetch/api/policies/referrer-origin-service-worker.https.html create mode 100644 testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html create mode 100644 testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url-service-worker.https.html diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 4ef43752cb42..e542ef445c40 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -87473,6 +87473,12 @@ {} ] ], + "fetch/api/policies/referrer-no-referrer-service-worker.https.html": [ + [ + "/fetch/api/policies/referrer-no-referrer-service-worker.https.html", + {} + ] + ], "fetch/api/policies/referrer-no-referrer-worker.html": [ [ "/fetch/api/policies/referrer-no-referrer-worker.html", @@ -87485,6 +87491,18 @@ {} ] ], + "fetch/api/policies/referrer-origin-service-worker.https.html": [ + [ + "/fetch/api/policies/referrer-origin-service-worker.https.html", + {} + ] + ], + "fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html": [ + [ + "/fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html", + {} + ] + ], "fetch/api/policies/referrer-origin-when-cross-origin-worker.html": [ [ "/fetch/api/policies/referrer-origin-when-cross-origin-worker.html", @@ -87509,6 +87527,12 @@ {} ] ], + "fetch/api/policies/referrer-unsafe-url-service-worker.https.html": [ + [ + "/fetch/api/policies/referrer-unsafe-url-service-worker.https.html", + {} + ] + ], "fetch/api/policies/referrer-unsafe-url-worker.html": [ [ "/fetch/api/policies/referrer-unsafe-url-worker.html", @@ -163692,6 +163716,10 @@ "fab90d344cbb78bad6445288c418b87736a830ae", "support" ], + "fetch/api/policies/referrer-no-referrer-service-worker.https.html": [ + "274797274e05e467499b98179dd23a19a960a014", + "testharness" + ], "fetch/api/policies/referrer-no-referrer-worker.html": [ "cc9274c1b182a487dbe945e6d8754a671d78e3c4", "testharness" @@ -163712,6 +163740,14 @@ "fab90d344cbb78bad6445288c418b87736a830ae", "support" ], + "fetch/api/policies/referrer-origin-service-worker.https.html": [ + "cf400b001e381251b0eaca8290e975dc27f6ff0f", + "testharness" + ], + "fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html": [ + "c2d6e3abb2b4ec0342ac9c16c468adb8b03e0426", + "testharness" + ], "fetch/api/policies/referrer-origin-when-cross-origin-worker.html": [ "3242db3a9319923287f36987f6f14581c239ced2", "testharness" @@ -163725,7 +163761,7 @@ "support" ], "fetch/api/policies/referrer-origin-when-cross-origin.js": [ - "f6b25aad46ba48422fab737582e82179666b5233", + "802ebd6d423099439a790c3db9b7ae37cbe5d9a0", "support" ], "fetch/api/policies/referrer-origin-when-cross-origin.js.headers": [ @@ -163737,7 +163773,7 @@ "testharness" ], "fetch/api/policies/referrer-origin.html": [ - "0ab191b8e4c349d47569a8d7cfeebec89711a0cb", + "ae8bfdfb5b9ae86522378ec798908b7db442797d", "testharness" ], "fetch/api/policies/referrer-origin.html.headers": [ @@ -163745,13 +163781,17 @@ "support" ], "fetch/api/policies/referrer-origin.js": [ - "8d8b58a4d5046e55e6bd97289cf6e515614e9577", + "e863bed9479b1b89cb0d8fae680e471ca66c757f", "support" ], "fetch/api/policies/referrer-origin.js.headers": [ "56b5f91097bb278ebc69345c0b56c65eb16cc3db", "support" ], + "fetch/api/policies/referrer-unsafe-url-service-worker.https.html": [ + "d2fa5c7813f57909228b51417df0267cd7ec0c20", + "testharness" + ], "fetch/api/policies/referrer-unsafe-url-worker.html": [ "70e7ec27a61ee68fb419213be149816ed618ce24", "testharness" diff --git a/testing/web-platform/meta/fetch/api/policies/referrer-origin-service-worker.https.html.ini b/testing/web-platform/meta/fetch/api/policies/referrer-origin-service-worker.https.html.ini new file mode 100644 index 000000000000..8df1d2a23318 --- /dev/null +++ b/testing/web-platform/meta/fetch/api/policies/referrer-origin-service-worker.https.html.ini @@ -0,0 +1,5 @@ +[referrer-origin-service-worker.https.html] + type: testharness + [Cross-origin referrer is overridden by client origin] + expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1341223 diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-no-referrer-service-worker.https.html b/testing/web-platform/tests/fetch/api/policies/referrer-no-referrer-service-worker.https.html new file mode 100644 index 000000000000..0d30ef9e3850 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/policies/referrer-no-referrer-service-worker.https.html @@ -0,0 +1,18 @@ + + + + + Fetch in service worker: referrer with no-referrer policy + + + + + + + + + + + diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-origin-service-worker.https.html b/testing/web-platform/tests/fetch/api/policies/referrer-origin-service-worker.https.html new file mode 100644 index 000000000000..4018b837816e --- /dev/null +++ b/testing/web-platform/tests/fetch/api/policies/referrer-origin-service-worker.https.html @@ -0,0 +1,18 @@ + + + + + Fetch in service worker: referrer with no-referrer policy + + + + + + + + + + + diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html b/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html new file mode 100644 index 000000000000..d87192e22711 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin-service-worker.https.html @@ -0,0 +1,17 @@ + + + + + Fetch in service worker: referrer with origin-when-cross-origin policy + + + + + + + + + + diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js b/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js index b9e6b1fbe259..7cd4113f506f 100644 --- a/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js +++ b/testing/web-platform/tests/fetch/api/policies/referrer-origin-when-cross-origin.js @@ -7,8 +7,8 @@ if (this.document === undefined) { importScripts("nested-policy.js"); } -var referrerOrigin = "http://{{host}}:{{ports[http][0]}}/"; -var fetchedUrl = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py?cors&headers=referer"; +var referrerOrigin = location.origin + '/'; +var fetchedUrl = "https://{{domains[www]}}:{{ports[https][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py?cors&headers=referer"; promise_test(function(test) { return fetch(fetchedUrl).then(function(resp) { diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-origin.html b/testing/web-platform/tests/fetch/api/policies/referrer-origin.html index 92baed79be76..b164afe01de9 100644 --- a/testing/web-platform/tests/fetch/api/policies/referrer-origin.html +++ b/testing/web-platform/tests/fetch/api/policies/referrer-origin.html @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-origin.js b/testing/web-platform/tests/fetch/api/policies/referrer-origin.js index 596ff818ca34..11541e94da59 100644 --- a/testing/web-platform/tests/fetch/api/policies/referrer-origin.js +++ b/testing/web-platform/tests/fetch/api/policies/referrer-origin.js @@ -7,7 +7,7 @@ if (this.document === undefined) { importScripts("nested-policy.js"); } -var referrerOrigin = "http://{{host}}:{{ports[http][0]}}/"; +var referrerOrigin = self.location.origin + '/'; var fetchedUrl = RESOURCES_DIR + "inspect-headers.py?headers=referer"; promise_test(function(test) { @@ -19,7 +19,7 @@ promise_test(function(test) { }, "Request's referrer is origin"); promise_test(function(test) { - var referrerUrl = "http://{{domains[www]}}:{{ports[http][0]}}/"; + var referrerUrl = "https://{{domains[www]}}:{{ports[https][0]}}/"; return fetch(fetchedUrl, { "referrer": referrerUrl }).then(function(resp) { assert_equals(resp.status, 200, "HTTP status is 200"); assert_equals(resp.type , "basic", "Response's type is basic"); diff --git a/testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url-service-worker.https.html b/testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url-service-worker.https.html new file mode 100644 index 000000000000..39a65b0e333a --- /dev/null +++ b/testing/web-platform/tests/fetch/api/policies/referrer-unsafe-url-service-worker.https.html @@ -0,0 +1,18 @@ + + + + + Fetch in worker: referrer with unsafe-url policy + + + + + + + + + + + From 34b6983682c8659f5107aac7d5b4fab68e9ce633 Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Thu, 23 Feb 2017 08:13:33 -0800 Subject: [PATCH 033/102] Backed out changeset d59ad4198154 (bug 1340450) for very frequent failures in browser_disable_containers.js --- .../preferences/in-content/privacy.js | 2 - .../components/sessionstore/SessionStore.jsm | 36 +-------- .../components/sessionstore/test/browser.ini | 2 - .../test/browser_disable_containers.js | 76 ------------------- .../ContextualIdentityService.jsm | 7 -- 5 files changed, 1 insertion(+), 122 deletions(-) delete mode 100644 browser/components/sessionstore/test/browser_disable_containers.js diff --git a/browser/components/preferences/in-content/privacy.js b/browser/components/preferences/in-content/privacy.js index 7a9d5b6f6dd5..6d557b80eae6 100644 --- a/browser/components/preferences/in-content/privacy.js +++ b/browser/components/preferences/in-content/privacy.js @@ -85,7 +85,6 @@ var gPrivacyPane = { let count = ContextualIdentityService.countContainerTabs(); if (count == 0) { - ContextualIdentityService.disableContainers(); Services.prefs.setBoolPref("privacy.userContext.enabled", false); return; } @@ -106,7 +105,6 @@ var gPrivacyPane = { okButton, cancelButton, null, null, {}); if (rv == 0) { ContextualIdentityService.closeContainerTabs(); - ContextualIdentityService.disableContainers(); Services.prefs.setBoolPref("privacy.userContext.enabled", false); return; } diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm index 2fc7cd098b5a..c4b680e0d92f 100644 --- a/browser/components/sessionstore/SessionStore.jsm +++ b/browser/components/sessionstore/SessionStore.jsm @@ -45,7 +45,7 @@ const OBSERVING = [ "quit-application-granted", "browser-lastwindow-close-granted", "quit-application", "browser:purge-session-history", "browser:purge-domain-data", - "idle-daily", "clear-origin-attributes-data" + "idle-daily", ]; // XUL Window properties to (re)store @@ -748,13 +748,6 @@ var SessionStoreInternal = { this.onIdleDaily(); this._notifyOfClosedObjectsChange(); break; - case "clear-origin-attributes-data": - let userContextId = 0; - try { - userContextId = JSON.parse(aData).userContextId; - } catch(e) {} - if (userContextId) - this._forgetTabsWithUserContextId(userContextId); } }, @@ -2589,33 +2582,6 @@ var SessionStoreInternal = { return undefined; }, - // This method deletes all the closedTabs matching userContextId. - _forgetTabsWithUserContextId(userContextId) { - let windowsEnum = Services.wm.getEnumerator("navigator:browser"); - while (windowsEnum.hasMoreElements()) { - let window = windowsEnum.getNext(); - let windowState = this._windows[window.__SSi]; - if (windowState) { - // In order to remove the tabs in the correct order, we store the - // indexes, into an array, then we revert the array and remove closed - // data from the last one going backward. - let indexes = []; - windowState._closedTabs.forEach((closedTab, index) => { - if (closedTab.state.userContextId == userContextId) { - indexes.push(index); - } - }); - - for (let index of indexes.reverse()) { - this.removeClosedTabData(windowState._closedTabs, index); - } - } - } - - // Notify of changes to closed objects. - this._notifyOfClosedObjectsChange(); - }, - /** * Restores the session state stored in LastSession. This will attempt * to merge data into the current session. If a window was opened at startup diff --git a/browser/components/sessionstore/test/browser.ini b/browser/components/sessionstore/test/browser.ini index 8ac1ffec7c1a..4566f3a0c605 100644 --- a/browser/components/sessionstore/test/browser.ini +++ b/browser/components/sessionstore/test/browser.ini @@ -243,5 +243,3 @@ skip-if = !e10s # GroupedSHistory is e10s-only [browser_closed_objects_changed_notifications_tabs.js] [browser_closed_objects_changed_notifications_windows.js] - -[browser_disable_containers.js] diff --git a/browser/components/sessionstore/test/browser_disable_containers.js b/browser/components/sessionstore/test/browser_disable_containers.js deleted file mode 100644 index c07297170c90..000000000000 --- a/browser/components/sessionstore/test/browser_disable_containers.js +++ /dev/null @@ -1,76 +0,0 @@ -"use strict"; - -/** - * This test is to see if tabs can be reopened when containers are disabled. - */ - -async function openAndCloseTab(window, userContextId, url) { - let tab = window.gBrowser.addTab(url, { userContextId }); - await promiseBrowserLoaded(tab.linkedBrowser, true, url); - await TabStateFlusher.flush(tab.linkedBrowser); - await promiseRemoveTab(tab); -} - -async function openTab(window, userContextId, url) { - let tab = window.gBrowser.addTab(url, { userContextId }); - await promiseBrowserLoaded(tab.linkedBrowser, true, url); - await TabStateFlusher.flush(tab.linkedBrowser); -} - -async function openWindow(url) { - let win = await promiseNewWindowLoaded(); - let flags = Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY; - win.gBrowser.selectedBrowser.loadURIWithFlags(url, flags); - await promiseBrowserLoaded(win.gBrowser.selectedBrowser, true, url); - return win; -} - -add_task(function* test_undoCloseById() { - // Clear the lists of closed windows and tabs. - forgetClosedWindows(); - while (SessionStore.getClosedTabCount(window)) { - SessionStore.forgetClosedTab(window, 0); - } - - // Open a new window. - let win = yield openWindow("about:robots"); - - // Open and close a tab. - yield openAndCloseTab(win, 0, "about:mozilla"); - is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab"); - - // Open and close a container tab. - yield openAndCloseTab(win, 3, "about:about"); - is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab"); - - // Restore the last closed tab. - let tab = SessionStore.undoCloseTab(win, 0); - yield promiseBrowserLoaded(tab.linkedBrowser); - is(tab.linkedBrowser.currentURI.spec, "about:about", "The expected tab was re-opened"); - is(tab.getAttribute("usercontextid"), 3, "Expected the tab userContextId to match"); - - // Open a few container tabs. - yield openTab(win, 1, "about:config"); - yield openTab(win, 1, "about:preferences"); - yield openTab(win, 2, "about:support"); - - // Let's simulate the disabling of containers. - ContextualIdentityService.closeContainerTabs(); - ContextualIdentityService.disableContainers(); - yield TabStateFlusher.flushWindow(win); - - // Let's check we don't have container tab opened. - for (let i = 0; i < win.gBrowser.tabContainer.childNodes.length; ++i) { - let tab = win.gBrowser.tabContainer.childNodes[i]; - ok(!tab.hasAttribute("usercontextid"), "No userContextId for this tab"); - } - - // Restore the last closed tab (we don't want the container tabs). - tab = SessionStore.undoCloseTab(win, 0); - yield promiseBrowserLoaded(tab.linkedBrowser); - is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "The expected tab was re-opened"); - ok(!tab.hasAttribute("usercontextid"), "No userContextId for this tab"); - - // Close the window again. - yield BrowserTestUtils.closeWindow(win); -}); diff --git a/toolkit/components/contextualidentity/ContextualIdentityService.jsm b/toolkit/components/contextualidentity/ContextualIdentityService.jsm index dd7a6d8d98d9..6bd4081326d8 100644 --- a/toolkit/components/contextualidentity/ContextualIdentityService.jsm +++ b/toolkit/components/contextualidentity/ContextualIdentityService.jsm @@ -298,13 +298,6 @@ _ContextualIdentityService.prototype = { }, userContextId); }, - disableContainers() { - for (let identity of this._identities) { - Services.obs.notifyObservers(null, "clear-origin-attributes-data", - JSON.stringify({ userContextId: identity.userContextId })); - } - }, - _forEachContainerTab(callback, userContextId = 0) { let windowList = Services.wm.getEnumerator("navigator:browser"); while (windowList.hasMoreElements()) { From 3f90fdb56cd9f91a5e390e330bf89fce84c196da Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Thu, 23 Feb 2017 17:19:28 +0100 Subject: [PATCH 034/102] Bug 1287330 - Insert tabs' linkedBrowser lazily into the document. r=dao --- browser/base/content/browser.js | 1 + browser/base/content/tabbrowser.xml | 216 ++++++++++++------ .../BrowserTestUtils/BrowserTestUtils.jsm | 7 + 3 files changed, 160 insertions(+), 64 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 621d2cc76fb0..a70d972b9cfa 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -5080,6 +5080,7 @@ nsBrowserAccess.prototype = { fromExternal: aIsExternal, inBackground: loadInBackground, forceNotRemote: aForceNotRemote, + forceBrowserInsertion: true, opener: aOpener, }); let browser = win.gBrowser.getBrowserForTab(tab); diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index d4973e065ec7..7e96d4d409c7 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -1514,6 +1514,7 @@ var aSameProcessAsFrameLoader; var aOriginPrincipal; var aOpener; + var aForceBrowserInsertion; if (arguments.length == 2 && typeof arguments[1] == "object" && !(arguments[1] instanceof Ci.nsIURI)) { @@ -1537,6 +1538,7 @@ aOriginPrincipal = params.originPrincipal; aOpener = params.opener; aIsPrerendered = params.isPrerendered; + aForceBrowserInsertion = params.forceBrowserInsertion; } var bgLoad = (aLoadInBackground != null) ? aLoadInBackground : @@ -1556,6 +1558,7 @@ skipAnimation: aSkipAnimation, allowMixedContent: aAllowMixedContent, forceNotRemote: aForceNotRemote, + forceBrowserInsertion: aForceBrowserInsertion, preferredRemoteType: aPreferredRemoteType, noReferrer: aNoReferrer, userContextId: aUserContextId, @@ -1710,6 +1713,9 @@ } let tab = this.getTabForBrowser(aBrowser); + // aBrowser needs to be inserted now if it hasn't been already. + this._insertBrowser(tab); + let evt = document.createEvent("Events"); evt.initEvent("BeforeTabRemotenessChange", true, false); tab.dispatchEvent(evt); @@ -1842,8 +1848,10 @@ // If we're in a LargeAllocation process, we prefer switching back // into a normal content process, as that way we can clean up the // L-A process. - let preferredRemoteType = aBrowser.remoteType; - if (aBrowser.remoteType == E10SUtils.LARGE_ALLOCATION_REMOTE_TYPE) { + let currentRemoteType = aBrowser.getAttribute("remoteType") || null; + let preferredRemoteType = currentRemoteType; + + if (currentRemoteType == E10SUtils.LARGE_ALLOCATION_REMOTE_TYPE) { preferredRemoteType = E10SUtils.DEFAULT_REMOTE_TYPE; } aOptions.remoteType = @@ -1854,7 +1862,7 @@ // If this URL can't load in the current browser then flip it to the // correct type. - if (aBrowser.remoteType != aOptions.remoteType || + if (currentRemoteType != aOptions.remoteType || aOptions.newFrameloader) { let remote = aOptions.remoteType != E10SUtils.NOT_REMOTE; return this.updateBrowserRemoteness(aBrowser, remote, aOptions); @@ -1943,12 +1951,12 @@ - + + [ + "canGoBack", "canGoForward", "goBack", "goForward", "permitUnload", + "reload", "reloadWithFlags", "stop", "loadURI", "loadURIWithFlags", + "goHome", "homePage", "gotoIndex", "currentURI", "documentURI", + "preferences", "imageDocument", "isRemoteBrowser", "messageManager", + "getTabBrowser", "finder", "fastFind", "sessionHistory", "contentTitle", + "characterSet", "fullZoom", "textZoom", "webProgress", + "addProgressListener", "removeProgressListener", "audioPlaybackStarted", + "audioPlaybackStopped", "adjustPriority", "pauseMedia", "stopMedia", + "blockMedia", "resumeMedia", "audioMuted", "mute", "unmute", + "blockedPopups", "mIconURL", "lastURI", "userTypedValue", + "purgeSessionHistory", "stopScroll", "startScroll" + ] + + + + + { + this._insertBrowser(aTab); + return browser[name]; + }; + setter = (value) => { + this._insertBrowser(aTab); + return browser[name] = value; + }; + } + Object.defineProperty(browser, name, { + get: getter, + set: setter, + configurable: true, + enumerable: true + }); + } + ]]> + + + + - - into the DOM if necessary. if (!notificationbox.parentNode) { @@ -2124,8 +2165,6 @@ var evt = new CustomEvent("TabBrowserInserted", { bubbles: true, detail: {} }); aTab.dispatchEvent(evt); - - return { usingPreloadedContent }; ]]> @@ -2158,6 +2197,7 @@ var aOriginPrincipal; var aDisallowInheritPrincipal; var aOpener; + var aForceBrowserInsertion; if (arguments.length == 2 && typeof arguments[1] == "object" && !(arguments[1] instanceof Ci.nsIURI)) { @@ -2183,6 +2223,7 @@ aDisallowInheritPrincipal = params.disallowInheritPrincipal; aOpener = params.opener; aIsPrerendered = params.isPrerendered; + aForceBrowserInsertion = params.forceBrowserInsertion; } // if we're adding tabs, we're past interrupt mode, ditch the owner @@ -2245,7 +2286,6 @@ var position = this.tabs.length - 1; t._tPos = position; - t.permanentKey = {}; this.tabContainer._setPositionalAttributes(); this.tabContainer.updateVisibility(); @@ -2259,23 +2299,51 @@ gMultiProcessBrowser); } - // Currently in this incarnation of bug 906076, we are forcing the - // browser to immediately be linked. In future incarnations of this - // bug this will be removed so we can leave the tab in its "lazy" - // state to be exploited for startup optimization. Note that for - // now this must occur before "TabOpen" event is fired, as that will - // trigger SessionStore.jsm to run code that expects the existence - // of tab.linkedBrowser. - let browserParams = { - forceNotRemote: aForceNotRemote, - preferredRemoteType: aPreferredRemoteType, - userContextId: aUserContextId, - sameProcessAsFrameLoader: aSameProcessAsFrameLoader, - opener: aOpener, - isPrerendered: aIsPrerendered, - }; - let { usingPreloadedContent } = this._linkBrowserToTab(t, aURI, browserParams); - let b = t.linkedBrowser; + let remoteType = + aForceNotRemote ? E10SUtils.NOT_REMOTE + : E10SUtils.getRemoteTypeForURI(aURI, gMultiProcessBrowser, + aPreferredRemoteType); + + let b; + let usingPreloadedContent = false; + + // If we open a new tab with the newtab URL in the default + // userContext, check if there is a preloaded browser ready. + // Private windows are not included because both the label and the + // icon for the tab would be set incorrectly (see bug 1195981). + if (aURI == BROWSER_NEW_TAB_URL && + !aUserContextId && + !PrivateBrowsingUtils.isWindowPrivate(window)) { + b = this._getPreloadedBrowser(); + if (b) { + usingPreloadedContent = true; + } + } + + if (!b) { + // No preloaded browser found, create one. + b = this._createBrowser({ remoteType, + uriIsAboutBlank, + userContextId: aUserContextId, + sameProcessAsFrameLoader: aSameProcessAsFrameLoader, + opener: aOpener, + isPrerendered: aIsPrerendered }); + } + + t.linkedBrowser = b; + this._tabForBrowser.set(b, t); + t.permanentKey = b.permanentKey; + t._browserParams = { uriIsAboutBlank, + remoteType, + usingPreloadedContent }; + + // If we're creating a blank tab, create a lazy browser. + // Otherwise insert the browser into the document now. + if (uriIsAboutBlank && !aForceBrowserInsertion) { + this._createLazyBrowser(t); + } else { + this._insertBrowser(t); + } // Dispatch a new tab notification. We do this once we're // entirely done, so that things are in a consistent state @@ -2495,6 +2563,9 @@ var skipPermitUnload = aParams.skipPermitUnload; } + // Ensure aTab's browser is inserted into the document. + this._insertBrowser(aTab); + window.maybeRecordAbandonmentTelemetry(aTab, "tabClosed"); // Handle requests for synchronously removing an already @@ -2994,6 +3065,9 @@ + + + + + + + diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index ab50db1c639b..48eae9c9c104 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -183,6 +183,13 @@ this.BrowserTestUtils = { * @resolves When a load event is triggered for the browser. */ browserLoaded(browser, includeSubFrames=false, wantLoad=null) { + // If browser belongs to tabbrowser-tab, ensure it has been + // inserted into the document. + let tabbrowser = browser.ownerGlobal.gBrowser; + if (tabbrowser && tabbrowser.getTabForBrowser) { + tabbrowser._insertBrowser(tabbrowser.getTabForBrowser(browser)); + } + function isWanted(url) { if (!wantLoad) { return true; From ecc7c32695171e26f8fb6979caae5d6adbc6a0eb Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Thu, 23 Feb 2017 16:26:14 +0000 Subject: [PATCH 035/102] Bug 1340597 - Avoid triggering read barrier in DumpHeap and when collecting stats r=sfink --- js/src/gc/Iteration.cpp | 38 ++++++++++++++++++------------------- js/src/jsfriendapi.cpp | 10 +++++----- js/src/jsgc.h | 23 ++++++++++++---------- js/src/jsgcinlines.h | 10 ++++++++-- js/src/vm/MemoryMetrics.cpp | 20 +++++++++---------- 5 files changed, 55 insertions(+), 46 deletions(-) diff --git a/js/src/gc/Iteration.cpp b/js/src/gc/Iteration.cpp index 228380f4740b..b83950ece6cc 100644 --- a/js/src/gc/Iteration.cpp +++ b/js/src/gc/Iteration.cpp @@ -20,10 +20,10 @@ using namespace js; using namespace js::gc; static void -IterateCompartmentsArenasCells(JSContext* cx, Zone* zone, void* data, - JSIterateCompartmentCallback compartmentCallback, - IterateArenaCallback arenaCallback, - IterateCellCallback cellCallback) +IterateCompartmentsArenasCellsUnbarriered(JSContext* cx, Zone* zone, void* data, + JSIterateCompartmentCallback compartmentCallback, + IterateArenaCallback arenaCallback, + IterateCellCallback cellCallback) { for (CompartmentsInZoneIter comp(zone); !comp.done(); comp.next()) (*compartmentCallback)(cx, data, comp); @@ -35,40 +35,40 @@ IterateCompartmentsArenasCells(JSContext* cx, Zone* zone, void* data, for (ArenaIter aiter(zone, thingKind); !aiter.done(); aiter.next()) { Arena* arena = aiter.get(); (*arenaCallback)(cx->runtime(), data, arena, traceKind, thingSize); - for (ArenaCellIter iter(arena); !iter.done(); iter.next()) + for (ArenaCellIterUnbarriered iter(arena); !iter.done(); iter.next()) (*cellCallback)(cx->runtime(), data, iter.getCell(), traceKind, thingSize); } } } void -js::IterateZonesCompartmentsArenasCells(JSContext* cx, void* data, - IterateZoneCallback zoneCallback, - JSIterateCompartmentCallback compartmentCallback, - IterateArenaCallback arenaCallback, - IterateCellCallback cellCallback) +js::IterateHeapUnbarriered(JSContext* cx, void* data, + IterateZoneCallback zoneCallback, + JSIterateCompartmentCallback compartmentCallback, + IterateArenaCallback arenaCallback, + IterateCellCallback cellCallback) { AutoPrepareForTracing prop(cx, WithAtoms); for (ZonesIter zone(cx->runtime(), WithAtoms); !zone.done(); zone.next()) { (*zoneCallback)(cx->runtime(), data, zone); - IterateCompartmentsArenasCells(cx, zone, data, - compartmentCallback, arenaCallback, cellCallback); + IterateCompartmentsArenasCellsUnbarriered(cx, zone, data, + compartmentCallback, arenaCallback, cellCallback); } } void -js::IterateZoneCompartmentsArenasCells(JSContext* cx, Zone* zone, void* data, - IterateZoneCallback zoneCallback, - JSIterateCompartmentCallback compartmentCallback, - IterateArenaCallback arenaCallback, - IterateCellCallback cellCallback) +js::IterateHeapUnbarrieredForZone(JSContext* cx, Zone* zone, void* data, + IterateZoneCallback zoneCallback, + JSIterateCompartmentCallback compartmentCallback, + IterateArenaCallback arenaCallback, + IterateCellCallback cellCallback) { AutoPrepareForTracing prop(cx, WithAtoms); (*zoneCallback)(cx->runtime(), data, zone); - IterateCompartmentsArenasCells(cx, zone, data, - compartmentCallback, arenaCallback, cellCallback); + IterateCompartmentsArenasCellsUnbarriered(cx, zone, data, + compartmentCallback, arenaCallback, cellCallback); } void diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index a134febf6a39..0989b942fb39 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -1184,11 +1184,11 @@ js::DumpHeap(JSContext* cx, FILE* fp, js::DumpHeapNurseryBehaviour nurseryBehavi fprintf(dtrc.output, "==========\n"); dtrc.prefix = "> "; - IterateZonesCompartmentsArenasCells(cx, &dtrc, - DumpHeapVisitZone, - DumpHeapVisitCompartment, - DumpHeapVisitArena, - DumpHeapVisitCell); + IterateHeapUnbarriered(cx, &dtrc, + DumpHeapVisitZone, + DumpHeapVisitCompartment, + DumpHeapVisitArena, + DumpHeapVisitCell); fflush(dtrc.output); } diff --git a/js/src/jsgc.h b/js/src/jsgc.h index e31d643960ec..b544d1b534f7 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -1018,24 +1018,27 @@ typedef void (*IterateCellCallback)(JSRuntime* rt, void* data, void* thing, * This function calls |zoneCallback| on every zone, |compartmentCallback| on * every compartment, |arenaCallback| on every in-use arena, and |cellCallback| * on every in-use cell in the GC heap. + * + * Note that no read barrier is triggered on the cells passed to cellCallback, + * so no these pointers must not escape the callback. */ extern void -IterateZonesCompartmentsArenasCells(JSContext* cx, void* data, - IterateZoneCallback zoneCallback, - JSIterateCompartmentCallback compartmentCallback, - IterateArenaCallback arenaCallback, - IterateCellCallback cellCallback); +IterateHeapUnbarriered(JSContext* cx, void* data, + IterateZoneCallback zoneCallback, + JSIterateCompartmentCallback compartmentCallback, + IterateArenaCallback arenaCallback, + IterateCellCallback cellCallback); /* * This function is like IterateZonesCompartmentsArenasCells, but does it for a * single zone. */ extern void -IterateZoneCompartmentsArenasCells(JSContext* cx, Zone* zone, void* data, - IterateZoneCallback zoneCallback, - JSIterateCompartmentCallback compartmentCallback, - IterateArenaCallback arenaCallback, - IterateCellCallback cellCallback); +IterateHeapUnbarrieredForZone(JSContext* cx, Zone* zone, void* data, + IterateZoneCallback zoneCallback, + JSIterateCompartmentCallback compartmentCallback, + IterateArenaCallback arenaCallback, + IterateCellCallback cellCallback); /* * Invoke chunkCallback on every in-use chunk. diff --git a/js/src/jsgcinlines.h b/js/src/jsgcinlines.h index 9ad1349da7eb..612c854b734d 100644 --- a/js/src/jsgcinlines.h +++ b/js/src/jsgcinlines.h @@ -154,8 +154,6 @@ class ArenaCellIterImpl void init(Arena* arena, CellIterNeedsBarrier mayNeedBarrier) { MOZ_ASSERT(!initialized); MOZ_ASSERT(arena); - MOZ_ASSERT_IF(!mayNeedBarrier, - CurrentThreadIsPerformingGC() || CurrentThreadIsGCSweeping()); initialized = true; AllocKind kind = arena->getAllocKind(); firstThingOffset = Arena::firstThingOffset(kind); @@ -243,6 +241,14 @@ class ArenaCellIterUnderFinalize : public ArenaCellIterImpl } }; +class ArenaCellIterUnbarriered : public ArenaCellIterImpl +{ + public: + explicit ArenaCellIterUnbarriered(Arena* arena) + : ArenaCellIterImpl(arena, CellIterDoesntNeedBarrier) + {} +}; + template class ZoneCellIter; diff --git a/js/src/vm/MemoryMetrics.cpp b/js/src/vm/MemoryMetrics.cpp index 4aa754eaeb72..fc9ab9149607 100644 --- a/js/src/vm/MemoryMetrics.cpp +++ b/js/src/vm/MemoryMetrics.cpp @@ -760,11 +760,11 @@ CollectRuntimeStatsHelper(JSContext* cx, RuntimeStats* rtStats, ObjectPrivateVis StatsClosure closure(rtStats, opv, anonymize); if (!closure.init()) return false; - IterateZonesCompartmentsArenasCells(cx, &closure, - StatsZoneCallback, - StatsCompartmentCallback, - StatsArenaCallback, - statsCellCallback); + IterateHeapUnbarriered(cx, &closure, + StatsZoneCallback, + StatsCompartmentCallback, + StatsArenaCallback, + statsCellCallback); // Take the "explicit/js/runtime/" measurements. rt->addSizeOfIncludingThis(rtStats->mallocSizeOf_, &rtStats->runtime); @@ -906,11 +906,11 @@ AddSizeOfTab(JSContext* cx, HandleObject obj, MallocSizeOf mallocSizeOf, ObjectP StatsClosure closure(&rtStats, opv, /* anonymize = */ false); if (!closure.init()) return false; - IterateZoneCompartmentsArenasCells(cx, zone, &closure, - StatsZoneCallback, - StatsCompartmentCallback, - StatsArenaCallback, - StatsCellCallback); + IterateHeapUnbarrieredForZone(cx, zone, &closure, + StatsZoneCallback, + StatsCompartmentCallback, + StatsArenaCallback, + StatsCellCallback); MOZ_ASSERT(rtStats.zoneStatsVector.length() == 1); rtStats.zTotals.addSizes(rtStats.zoneStatsVector[0]); From 8f21335fb214835c716fe2cb523a4ff652e835f1 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Thu, 23 Feb 2017 16:26:14 +0000 Subject: [PATCH 036/102] Bug 1337414 - Don't trace into GC things owned by other runtimes in CheckHeapTracer r=jandem --- js/src/gc/Verifier.cpp | 7 +++- js/src/jit-test/tests/gc/bug-1337414.js | 46 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 js/src/jit-test/tests/gc/bug-1337414.js diff --git a/js/src/gc/Verifier.cpp b/js/src/gc/Verifier.cpp index ff303567dfee..575e83889339 100644 --- a/js/src/gc/Verifier.cpp +++ b/js/src/gc/Verifier.cpp @@ -8,6 +8,7 @@ # include #endif +#include "mozilla/DebugOnly.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/Sprintf.h" @@ -302,7 +303,7 @@ CheckEdgeTracer::onChild(const JS::GCCellPtr& thing) void js::gc::AssertSafeToSkipBarrier(TenuredCell* thing) { - Zone* zone = thing->zoneFromAnyThread(); + mozilla::DebugOnly zone = thing->zoneFromAnyThread(); MOZ_ASSERT(!zone->needsIncrementalBarrier() || zone->isAtomsZone()); } @@ -531,6 +532,10 @@ CheckHeapTracer::onChild(const JS::GCCellPtr& thing) return; } + // Don't trace into GC things owned by another runtime. + if (cell->runtimeFromAnyThread() != rt) + return; + WorkItem item(thing, contextName(), parentIndex); if (!stack.append(item)) oom = true; diff --git a/js/src/jit-test/tests/gc/bug-1337414.js b/js/src/jit-test/tests/gc/bug-1337414.js new file mode 100644 index 000000000000..9e647a810cc2 --- /dev/null +++ b/js/src/jit-test/tests/gc/bug-1337414.js @@ -0,0 +1,46 @@ +var lfLogBuffer = ` +gczeal(15,10); +try { + a = [] + gczeal(2, 2)() +} catch (e) {} +a.every(function() {}) +//corefuzz-dcd-endofdata +//corefuzz-dcd-selectmode 5 +`; +lfLogBuffer = lfLogBuffer.split('\n'); +lfPreamble = ` +`; +var lfCodeBuffer = ""; +var lfRunTypeLimit = 7; +var lfOffThreadGlobal = newGlobal(); +try {} catch (lfVare5) {} +var lfAccumulatedCode = lfPreamble; +while (true) { + var line = lfLogBuffer.shift(); + if (line == null) { + break; + } else if (line == "//corefuzz-dcd-endofdata") { + loadFile(lfCodeBuffer); + } else if (line.indexOf("//corefuzz-dcd-selectmode ") === 0) { + loadFile(line); + } else { + lfCodeBuffer += line + "\n"; + } +} +if (lfCodeBuffer) loadFile(lfCodeBuffer); +function loadFile(lfVarx) { + try { + if (lfVarx.indexOf("//corefuzz-dcd-selectmode ") === 0) { + lfRunTypeId = parseInt(lfVarx.split(" ")[1]) % lfRunTypeLimit; + } else { + switch (lfRunTypeId) { + case 5: + evalInWorker(lfAccumulatedCode); + evaluate(lfVarx); + } + } + } catch (lfVare) { + lfAccumulatedCode += "try { evaluate(`\n" + lfVarx + "\n`); } catch(exc) {}\n"; + } +} From 8d44598069a4c2d3037eaa9b0d89a415bd9364db Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Thu, 23 Feb 2017 16:26:14 +0000 Subject: [PATCH 037/102] Bug 1340110 - Make shell resolve root module relative to current directory as happens for non-module scripts r=anba --- js/src/shell/ModuleLoader.js | 22 ++++++++++++++++------ js/src/shell/OSObject.cpp | 16 +++++++++------- js/src/shell/js.cpp | 32 +++++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/js/src/shell/ModuleLoader.js b/js/src/shell/ModuleLoader.js index d8767f05f4b0..58b095f4db10 100644 --- a/js/src/shell/ModuleLoader.js +++ b/js/src/shell/ModuleLoader.js @@ -21,9 +21,7 @@ Reflect.Loader = new class { return os.file.readFile(path); } - loadAndParse(name) { - let path = this.resolve(name); - + loadAndParse(path) { if (this.registry.has(path)) return this.registry.get(path); @@ -33,11 +31,23 @@ Reflect.Loader = new class { return module; } - ["import"](name, referrer) { - let module = this.loadAndParse(name); + loadAndExecute(path) { + let module = this.loadAndParse(path); module.declarationInstantiation(); return module.evaluation(); } + + importRoot(path) { + return this.loadAndExecute(path); + } + + ["import"](name, referrer) { + let path = this.resolve(name); + return this.loadAndExecute(path); + } }; -setModuleResolveHook((module, requestName) => Reflect.Loader.loadAndParse(requestName)); +setModuleResolveHook((module, requestName) => { + let path = Reflect.Loader.resolve(requestName); + return Reflect.Loader.loadAndParse(path) +}); diff --git a/js/src/shell/OSObject.cpp b/js/src/shell/OSObject.cpp index d1019c77fd25..7d36295a3022 100644 --- a/js/src/shell/OSObject.cpp +++ b/js/src/shell/OSObject.cpp @@ -112,16 +112,18 @@ ResolvePath(JSContext* cx, HandleString filenameStr, PathResolutionMode resolveM if (IsAbsolutePath(filename)) return filenameStr; - /* Get the currently executing script's name. */ JS::AutoFilename scriptFilename; - if (!DescribeScriptedCaller(cx, &scriptFilename)) - return nullptr; + if (resolveMode == ScriptRelative) { + // Get the currently executing script's name. + if (!DescribeScriptedCaller(cx, &scriptFilename)) + return nullptr; - if (!scriptFilename.get()) - return nullptr; + if (!scriptFilename.get()) + return nullptr; - if (strcmp(scriptFilename.get(), "-e") == 0 || strcmp(scriptFilename.get(), "typein") == 0) - resolveMode = RootRelative; + if (strcmp(scriptFilename.get(), "-e") == 0 || strcmp(scriptFilename.get(), "typein") == 0) + resolveMode = RootRelative; + } static char buffer[PATH_MAX+1]; if (resolveMode == ScriptRelative) { diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 5fb992b30e8b..87e5112b9a7d 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -733,12 +733,12 @@ GetLoaderObject(JSContext* cx, MutableHandleObject resultOut) } static bool -GetImportMethod(JSContext* cx, HandleObject loader, MutableHandleFunction resultOut) +GetImportRootMethod(JSContext* cx, HandleObject loader, MutableHandleFunction resultOut) { - // Look up the module loader's |import| method. + // Look up the module loader's |importRoot| method. RootedValue value(cx); - if (!JS_GetProperty(cx, loader, "import", &value) || !value.isObject()) + if (!JS_GetProperty(cx, loader, "importRoot", &value) || !value.isObject()) return false; RootedObject object(cx, &value.toObject()); @@ -752,17 +752,31 @@ GetImportMethod(JSContext* cx, HandleObject loader, MutableHandleFunction result static MOZ_MUST_USE bool RunModule(JSContext* cx, const char* filename, FILE* file, bool compileOnly) { - // Execute a module by calling |Reflect.Loader.import(filename)|. + // Execute a module by calling Reflect.Loader.importRoot on the resolved + // filename. RootedObject loaderObj(cx); - MOZ_ALWAYS_TRUE(GetLoaderObject(cx, &loaderObj)); + if (!GetLoaderObject(cx, &loaderObj)) { + JS_ReportErrorASCII(cx, "Failed to get Reflect.Loader"); + return false; + } RootedFunction importFun(cx); - MOZ_ALWAYS_TRUE(GetImportMethod(cx, loaderObj, &importFun)); + if (!GetImportRootMethod(cx, loaderObj, &importFun)) { + JS_ReportErrorASCII(cx, "Failed to get Reflect.Loader.importRoot method"); + return false; + } - JS::AutoValueArray<2> args(cx); - args[0].setString(JS_NewStringCopyZ(cx, filename)); - args[1].setUndefined(); + RootedString path(cx, JS_NewStringCopyZ(cx, filename)); + if (!path) + return false; + + path = ResolvePath(cx, path, RootRelative); + if (!path) + return false; + + JS::AutoValueArray<1> args(cx); + args[0].setString(path); RootedValue value(cx); return JS_CallFunction(cx, loaderObj, importFun, args, &value); From 105246b475295aaa6f636d4cd0a47f2a625a320e Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 22 Feb 2017 20:30:27 -0500 Subject: [PATCH 038/102] Bug 1341954 - Break a reference cycle caused by ChannelListener that creates leaks in all tests using it; r=mcmanus --- netwerk/test/unit/head_channels.js | 1 + 1 file changed, 1 insertion(+) diff --git a/netwerk/test/unit/head_channels.js b/netwerk/test/unit/head_channels.js index 6e37a18bc950..37c958dc811c 100644 --- a/netwerk/test/unit/head_channels.js +++ b/netwerk/test/unit/head_channels.js @@ -172,6 +172,7 @@ ChannelListener.prototype = { } try { this._closure(request, this._buffer, this._closurectx, this._isFromCache); + this._closurectx = null; } catch (ex) { do_throw("Error in closure function: " + ex); } From 3ca41325bb9773350970b3bc0feaa9e9cfaeeaa8 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Fri, 3 Feb 2017 16:55:22 -0500 Subject: [PATCH 039/102] Bug 1336510 - Part 2: Fix lambda captures of this in PresentationConnection, r=smaug MozReview-Commit-ID: 2fuMHyspjhs --- dom/presentation/PresentationConnection.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dom/presentation/PresentationConnection.cpp b/dom/presentation/PresentationConnection.cpp index 0ffd27b4f02a..f36b506d1e97 100644 --- a/dom/presentation/PresentationConnection.cpp +++ b/dom/presentation/PresentationConnection.cpp @@ -735,18 +735,19 @@ PresentationConnection::AsyncCloseConnectionWithErrorMsg(const nsAString& aMessa } nsString message = nsString(aMessage); + RefPtr self = this; nsCOMPtr r = - NS_NewRunnableFunction([this, message]() -> void { + NS_NewRunnableFunction([self, message]() -> void { // Set |mState| to |PresentationConnectionState::Closed| here to avoid // calling |ProcessStateChanged|. - mState = PresentationConnectionState::Closed; + self->mState = PresentationConnectionState::Closed; // Make sure dispatching the event and closing the connection are invoked // at the same time by setting |aDispatchNow| to true. Unused << NS_WARN_IF(NS_FAILED( - DispatchConnectionCloseEvent(PresentationConnectionClosedReason::Error, - message, - true))); + self->DispatchConnectionCloseEvent(PresentationConnectionClosedReason::Error, + message, + true))); nsCOMPtr service = do_GetService(PRESENTATION_SERVICE_CONTRACTID); @@ -755,8 +756,8 @@ PresentationConnection::AsyncCloseConnectionWithErrorMsg(const nsAString& aMessa } Unused << NS_WARN_IF(NS_FAILED( - service->CloseSession(mId, - mRole, + service->CloseSession(self->mId, + self->mRole, nsIPresentationService::CLOSED_REASON_ERROR))); }); From c74d63f75c1dc324fb0c9263c0eb9213552bde7b Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Fri, 3 Feb 2017 16:56:24 -0500 Subject: [PATCH 040/102] Bug 1336510 - Part 3: Capture a strong reference to this in CompositorBridgeParent::FlushApzRepaints, r=kats MozReview-Commit-ID: KdGBYEAC0dW --- gfx/layers/ipc/CompositorBridgeParent.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index 14cc36e576c7..6b8611359ff2 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -1316,8 +1316,9 @@ CompositorBridgeParent::FlushApzRepaints(const LayerTransactionParent* aLayerTre // use the compositor's root layer tree id. layersId = mRootLayerTreeID; } + RefPtr self = this; APZThreadUtils::RunOnControllerThread(NS_NewRunnableFunction([=] () { - mApzcTreeManager->FlushApzRepaints(layersId); + self->mApzcTreeManager->FlushApzRepaints(layersId); })); } From de7ee53299ff6008540beefbde62de3a35a875e3 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Fri, 3 Feb 2017 16:57:49 -0500 Subject: [PATCH 041/102] Bug 1336510 - Part 4: Capture a strong reference to this in dom/media, r=jwwang MozReview-Commit-ID: 4lVGrGzhVXh --- dom/media/MediaDecoder.cpp | 5 +- dom/media/MediaDecoderStateMachine.cpp | 53 ++++++++++--------- dom/media/MediaManager.cpp | 22 ++++---- dom/media/mediasink/DecodedStream.cpp | 5 +- dom/media/ogg/OggDemuxer.cpp | 3 +- dom/media/systemservices/CamerasChild.cpp | 50 ++++++++++------- .../webrtc/MediaEngineRemoteVideoSource.cpp | 8 +-- dom/media/webrtc/MediaEngineWebRTCAudio.cpp | 8 +-- 8 files changed, 87 insertions(+), 67 deletions(-) diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index b6c77d876ca5..62fcc972d759 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -1813,13 +1813,14 @@ MediaDecoder::DumpDebugInfo() return; } + RefPtr self = this; GetStateMachine()->RequestDebugInfo()->Then( AbstractThread::MainThread(), __func__, - [this, str] (const nsACString& aString) { + [this, self, str] (const nsACString& aString) { DUMP_LOG("%s", str.get()); DUMP_LOG("%s", aString.Data()); }, - [this, str] () { + [this, self, str] () { DUMP_LOG("%s", str.get()); }); } diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 43be192f4115..245be46b4de2 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2821,9 +2821,10 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) mMetadataManager.Connect(mReader->TimedMetadataEvent(), OwnerThread()); + RefPtr self = this; mOnMediaNotSeekable = mReader->OnMediaNotSeekable().Connect( - OwnerThread(), [this] () { - mMediaSeekable = false; + OwnerThread(), [self] () { + self->mMediaSeekable = false; }); mMediaSink = CreateMediaSink(mAudioCaptured); @@ -2837,7 +2838,6 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) nsresult rv = mReader->Init(); NS_ENSURE_SUCCESS(rv, rv); - RefPtr self = this; OwnerThread()->Dispatch(NS_NewRunnableFunction([self] () { MOZ_ASSERT(!self->mStateObj); auto s = new DecodeMetadataState(self); @@ -3112,9 +3112,10 @@ MediaDecoderStateMachine::RequestAudioData() SAMPLE_LOG("Queueing audio task - queued=%" PRIuSIZE ", decoder-queued=%" PRIuSIZE, AudioQueue().GetSize(), mReader->SizeOfAudioQueueInFrames()); + RefPtr self = this; mReader->RequestAudioData()->Then( OwnerThread(), __func__, - [this] (MediaData* aAudio) { + [this, self] (MediaData* aAudio) { MOZ_ASSERT(aAudio); mAudioDataRequest.Complete(); // audio->GetEndTime() is not always mono-increasing in chained ogg. @@ -3124,7 +3125,7 @@ MediaDecoderStateMachine::RequestAudioData() aAudio->GetEndTime()); mStateObj->HandleAudioDecoded(aAudio); }, - [this] (const MediaResult& aError) { + [this, self] (const MediaResult& aError) { SAMPLE_LOG("OnAudioNotDecoded aError=%" PRIu32, static_cast(aError.Code())); mAudioDataRequest.Complete(); switch (aError.Code()) { @@ -3158,9 +3159,10 @@ MediaDecoderStateMachine::RequestVideoData(bool aSkipToNextKeyframe, aSkipToNextKeyframe, aCurrentTime.ToMicroseconds()); TimeStamp videoDecodeStartTime = TimeStamp::Now(); + RefPtr self = this; mReader->RequestVideoData(aSkipToNextKeyframe, aCurrentTime)->Then( OwnerThread(), __func__, - [this, videoDecodeStartTime] (MediaData* aVideo) { + [this, self, videoDecodeStartTime] (MediaData* aVideo) { MOZ_ASSERT(aVideo); mVideoDataRequest.Complete(); // Handle abnormal or negative timestamps. @@ -3170,7 +3172,7 @@ MediaDecoderStateMachine::RequestVideoData(bool aSkipToNextKeyframe, aVideo->GetEndTime()); mStateObj->HandleVideoDecoded(aVideo, videoDecodeStartTime); }, - [this] (const MediaResult& aError) { + [this, self] (const MediaResult& aError) { SAMPLE_LOG("OnVideoNotDecoded aError=%" PRIu32 , static_cast(aError.Code())); mVideoDataRequest.Complete(); switch (aError.Code()) { @@ -3194,29 +3196,30 @@ MediaDecoderStateMachine::WaitForData(MediaData::Type aType) { MOZ_ASSERT(OnTaskQueue()); MOZ_ASSERT(aType == MediaData::AUDIO_DATA || aType == MediaData::VIDEO_DATA); + RefPtr self = this; if (aType == MediaData::AUDIO_DATA) { mReader->WaitForData(MediaData::AUDIO_DATA)->Then( OwnerThread(), __func__, - [this] (MediaData::Type aType) { - mAudioWaitRequest.Complete(); + [self] (MediaData::Type aType) { + self->mAudioWaitRequest.Complete(); MOZ_ASSERT(aType == MediaData::AUDIO_DATA); - mStateObj->HandleAudioWaited(aType); + self->mStateObj->HandleAudioWaited(aType); }, - [this] (const WaitForDataRejectValue& aRejection) { - mAudioWaitRequest.Complete(); - DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); + [self] (const WaitForDataRejectValue& aRejection) { + self->mAudioWaitRequest.Complete(); + self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); })->Track(mAudioWaitRequest); } else { mReader->WaitForData(MediaData::VIDEO_DATA)->Then( OwnerThread(), __func__, - [this] (MediaData::Type aType) { - mVideoWaitRequest.Complete(); + [self] (MediaData::Type aType) { + self->mVideoWaitRequest.Complete(); MOZ_ASSERT(aType == MediaData::VIDEO_DATA); - mStateObj->HandleVideoWaited(aType); + self->mStateObj->HandleVideoWaited(aType); }, - [this] (const WaitForDataRejectValue& aRejection) { - mVideoWaitRequest.Complete(); - DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); + [self] (const WaitForDataRejectValue& aRejection) { + self->mVideoWaitRequest.Complete(); + self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); })->Track(mVideoWaitRequest); } } @@ -3577,9 +3580,10 @@ MediaDecoderStateMachine::ScheduleStateMachineIn(int64_t aMicroseconds) // It is OK to capture 'this' without causing UAF because the callback // always happens before shutdown. - mDelayedScheduler.Ensure(target, [this] () { - mDelayedScheduler.CompleteRequest(); - RunStateMachine(); + RefPtr self = this; + mDelayedScheduler.Ensure(target, [self] () { + self->mDelayedScheduler.CompleteRequest(); + self->RunStateMachine(); }, [] () { MOZ_DIAGNOSTIC_ASSERT(false); }); @@ -3796,8 +3800,9 @@ MediaDecoderStateMachine::RequestDebugInfo() { using PromiseType = MediaDecoder::DebugInfoPromise; RefPtr p = new PromiseType::Private(__func__); - OwnerThread()->Dispatch(NS_NewRunnableFunction([this, p] () { - p->Resolve(GetDebugInfo(), __func__); + RefPtr self = this; + OwnerThread()->Dispatch(NS_NewRunnableFunction([self, p] () { + p->Resolve(self->GetDebugInfo(), __func__); }), AbstractThread::AssertDispatchSuccess, AbstractThread::TailDispatch); return p.forget(); } diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index e1e664e06b09..7a81f835a086 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -2295,23 +2295,23 @@ if (privileged) { RefPtr p = EnumerateDevicesImpl(windowID, videoType, audioType, fake); - p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission, + RefPtr self = this; + p->Then([self, onSuccess, onFailure, windowID, c, listener, askPermission, prefs, isHTTPS, callID, principalInfo, isChrome](SourceSet*& aDevices) mutable { RefPtr>> devices( new Refcountable>(aDevices)); // grab result - // Ensure that the captured 'this' pointer and our windowID are still good. - if (!MediaManager::Exists() || - !nsGlobalWindow::GetInnerWindowWithId(windowID)) { + // Ensure that our windowID is still good. + if (!nsGlobalWindow::GetInnerWindowWithId(windowID)) { return; } // Apply any constraints. This modifies the passed-in list. - RefPtr p2 = SelectSettings(c, isChrome, devices); + RefPtr p2 = self->SelectSettings(c, isChrome, devices); - p2->Then([this, onSuccess, onFailure, windowID, c, + p2->Then([self, onSuccess, onFailure, windowID, c, listener, askPermission, prefs, isHTTPS, callID, principalInfo, isChrome, devices](const char*& badConstraint) mutable { @@ -2359,13 +2359,13 @@ if (privileged) { isChrome, devices->release())); // Store the task w/callbacks. - mActiveCallbacks.Put(callID, task.forget()); + self->mActiveCallbacks.Put(callID, task.forget()); // Add a WindowID cross-reference so OnNavigation can tear things down nsTArray* array; - if (!mCallIds.Get(windowID, &array)) { + if (!self->mCallIds.Get(windowID, &array)) { array = new nsTArray(); - mCallIds.Put(windowID, array); + self->mCallIds.Put(windowID, array); } array->AppendElement(callID); @@ -3002,7 +3002,9 @@ MediaManager::Shutdown() // cleared until the lambda function clears it. // note that this == sSingleton - RefPtr that(sSingleton); + MOZ_ASSERT(this == sSingleton); + RefPtr that = this; + // Release the backend (and call Shutdown()) from within the MediaManager thread // Don't use MediaManager::PostTask() because we're sInShutdown=true here! RefPtr shutdown = new ShutdownTask(this, diff --git a/dom/media/mediasink/DecodedStream.cpp b/dom/media/mediasink/DecodedStream.cpp index 921f6d4e6951..44457f07222b 100644 --- a/dom/media/mediasink/DecodedStream.cpp +++ b/dom/media/mediasink/DecodedStream.cpp @@ -70,9 +70,10 @@ public: void Forget() { - mAbstractMainThread->Dispatch(NS_NewRunnableFunction([this] () { + RefPtr self = this; + mAbstractMainThread->Dispatch(NS_NewRunnableFunction([self] () { MOZ_ASSERT(NS_IsMainThread()); - mFinishPromise.ResolveIfExists(true, __func__); + self->mFinishPromise.ResolveIfExists(true, __func__); })); MutexAutoLock lock(mMutex); mStream = nullptr; diff --git a/dom/media/ogg/OggDemuxer.cpp b/dom/media/ogg/OggDemuxer.cpp index ab64a0599274..618a403b3b81 100644 --- a/dom/media/ogg/OggDemuxer.cpp +++ b/dom/media/ogg/OggDemuxer.cpp @@ -128,7 +128,8 @@ OggDemuxer::~OggDemuxer() // If we were able to initialize our decoders, report whether we encountered // a chained stream or not. bool isChained = mIsChained; - nsCOMPtr task = NS_NewRunnableFunction([=]() -> void { + RefPtr self = this; + nsCOMPtr task = NS_NewRunnableFunction([this, self, isChained]() -> void { OGG_DEBUG("Reporting telemetry MEDIA_OGG_LOADED_IS_CHAINED=%d", isChained); Telemetry::Accumulate(Telemetry::HistogramID::MEDIA_OGG_LOADED_IS_CHAINED, isChained); }); diff --git a/dom/media/systemservices/CamerasChild.cpp b/dom/media/systemservices/CamerasChild.cpp index 24047c27187d..8ece71ce16df 100644 --- a/dom/media/systemservices/CamerasChild.cpp +++ b/dom/media/systemservices/CamerasChild.cpp @@ -284,9 +284,10 @@ CamerasChild::NumberOfCapabilities(CaptureEngine aCapEngine, LOG((__PRETTY_FUNCTION__)); LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8)); nsCString unique_id(deviceUniqueIdUTF8); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine, unique_id]() -> nsresult { - if (this->SendNumberOfCapabilities(aCapEngine, unique_id)) { + media::NewRunnableFrom([self, aCapEngine, unique_id]() -> nsresult { + if (self->SendNumberOfCapabilities(aCapEngine, unique_id)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -300,9 +301,10 @@ int CamerasChild::NumberOfCaptureDevices(CaptureEngine aCapEngine) { LOG((__PRETTY_FUNCTION__)); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine]() -> nsresult { - if (this->SendNumberOfCaptureDevices(aCapEngine)) { + media::NewRunnableFrom([self, aCapEngine]() -> nsresult { + if (self->SendNumberOfCaptureDevices(aCapEngine)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -328,9 +330,10 @@ int CamerasChild::EnsureInitialized(CaptureEngine aCapEngine) { LOG((__PRETTY_FUNCTION__)); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine]() -> nsresult { - if (this->SendEnsureInitialized(aCapEngine)) { + media::NewRunnableFrom([self, aCapEngine]() -> nsresult { + if (self->SendEnsureInitialized(aCapEngine)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -348,9 +351,10 @@ CamerasChild::GetCaptureCapability(CaptureEngine aCapEngine, { LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number)); nsCString unique_id(unique_idUTF8); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine, unique_id, capability_number]() -> nsresult { - if (this->SendGetCaptureCapability(aCapEngine, unique_id, capability_number)) { + media::NewRunnableFrom([self, aCapEngine, unique_id, capability_number]() -> nsresult { + if (self->SendGetCaptureCapability(aCapEngine, unique_id, capability_number)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -389,9 +393,10 @@ CamerasChild::GetCaptureDevice(CaptureEngine aCapEngine, bool* scary) { LOG((__PRETTY_FUNCTION__)); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine, list_number]() -> nsresult { - if (this->SendGetCaptureDevice(aCapEngine, list_number)) { + media::NewRunnableFrom([self, aCapEngine, list_number]() -> nsresult { + if (self->SendGetCaptureDevice(aCapEngine, list_number)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -433,9 +438,10 @@ CamerasChild::AllocateCaptureDevice(CaptureEngine aCapEngine, { LOG((__PRETTY_FUNCTION__)); nsCString unique_id(unique_idUTF8); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine, unique_id, aPrincipalInfo]() -> nsresult { - if (this->SendAllocateCaptureDevice(aCapEngine, unique_id, aPrincipalInfo)) { + media::NewRunnableFrom([self, aCapEngine, unique_id, aPrincipalInfo]() -> nsresult { + if (self->SendAllocateCaptureDevice(aCapEngine, unique_id, aPrincipalInfo)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -466,9 +472,10 @@ CamerasChild::ReleaseCaptureDevice(CaptureEngine aCapEngine, const int capture_id) { LOG((__PRETTY_FUNCTION__)); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine, capture_id]() -> nsresult { - if (this->SendReleaseCaptureDevice(aCapEngine, capture_id)) { + media::NewRunnableFrom([self, aCapEngine, capture_id]() -> nsresult { + if (self->SendReleaseCaptureDevice(aCapEngine, capture_id)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -517,9 +524,10 @@ CamerasChild::StartCapture(CaptureEngine aCapEngine, webrtcCaps.rawType, webrtcCaps.codecType, webrtcCaps.interlaced); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine, capture_id, capCap]() -> nsresult { - if (this->SendStartCapture(aCapEngine, capture_id, capCap)) { + media::NewRunnableFrom([self, aCapEngine, capture_id, capCap]() -> nsresult { + if (self->SendStartCapture(aCapEngine, capture_id, capCap)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -532,9 +540,10 @@ int CamerasChild::StopCapture(CaptureEngine aCapEngine, const int capture_id) { LOG((__PRETTY_FUNCTION__)); + RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([this, aCapEngine, capture_id]() -> nsresult { - if (this->SendStopCapture(aCapEngine, capture_id)) { + media::NewRunnableFrom([self, aCapEngine, capture_id]() -> nsresult { + if (self->SendStopCapture(aCapEngine, capture_id)) { return NS_OK; } return NS_ERROR_FAILURE; @@ -599,11 +608,12 @@ CamerasChild::ShutdownParent() if (CamerasSingleton::Thread()) { LOG(("Dispatching actor deletion")); // Delete the parent actor. + RefPtr self = this; RefPtr deleteRunnable = // CamerasChild (this) will remain alive and is only deleted by the // IPC layer when SendAllDone returns. - media::NewRunnableFrom([this]() -> nsresult { - Unused << this->SendAllDone(); + media::NewRunnableFrom([self]() -> nsresult { + Unused << self->SendAllDone(); return NS_OK; }); CamerasSingleton::Thread()->Dispatch(deleteRunnable, NS_DISPATCH_NORMAL); diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp index c2df41c46ea2..4f6c26004a75 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp @@ -316,10 +316,10 @@ MediaEngineRemoteVideoSource::SetLastCapability( webrtc::CaptureCapability cap = aCapability; RefPtr that = this; - NS_DispatchToMainThread(media::NewRunnableFrom([this, that, cap]() mutable { - mSettings.mWidth.Value() = cap.width; - mSettings.mHeight.Value() = cap.height; - mSettings.mFrameRate.Value() = cap.maxFPS; + NS_DispatchToMainThread(media::NewRunnableFrom([that, cap]() mutable { + that->mSettings.mWidth.Value() = cap.width; + that->mSettings.mHeight.Value() = cap.height; + that->mSettings.mFrameRate.Value() = cap.maxFPS; return NS_OK; })); } diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index e8e625bf54c0..8bd1142d1995 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -373,10 +373,10 @@ MediaEngineWebRTCMicrophoneSource::SetLastPrefs( RefPtr that = this; - NS_DispatchToMainThread(media::NewRunnableFrom([this, that, aPrefs]() mutable { - mSettings.mEchoCancellation.Value() = aPrefs.mAecOn; - mSettings.mMozAutoGainControl.Value() = aPrefs.mAgcOn; - mSettings.mMozNoiseSuppression.Value() = aPrefs.mNoiseOn; + NS_DispatchToMainThread(media::NewRunnableFrom([that, aPrefs]() mutable { + that->mSettings.mEchoCancellation.Value() = aPrefs.mAecOn; + that->mSettings.mMozAutoGainControl.Value() = aPrefs.mAgcOn; + that->mSettings.mMozNoiseSuppression.Value() = aPrefs.mNoiseOn; return NS_OK; })); } From 8e27856bdb1628cf839ab74419e011f30dedf63c Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Tue, 14 Feb 2017 14:40:26 -0500 Subject: [PATCH 042/102] Bug 1336510 - Part 5: Workaround lambda static analysis in nsMultiMixedConv, r=valentin MozReview-Commit-ID: 7Mvh9aeCKOh --- netwerk/streamconv/converters/nsMultiMixedConv.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/netwerk/streamconv/converters/nsMultiMixedConv.cpp b/netwerk/streamconv/converters/nsMultiMixedConv.cpp index 47d4fe4a82aa..01f2c7a46fce 100644 --- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp +++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp @@ -807,9 +807,14 @@ nsMultiMixedConv::SwitchToControlParsing() nsMultiMixedConv::nsMultiMixedConv() : mCurrentPartID(0), mInOnDataAvailable(false), - mTokenizer([this](Token const& token, mozilla::IncrementalTokenizer&) -> nsresult { - return this->ConsumeToken(token); - }) + // XXX: This is a hack to bypass the raw pointer to refcounted object in + // lambda analysis. It should be removed and replaced when the + // IncrementalTokenizer API is improved to avoid the need for such + // workarounds. + // + // This is safe because `mTokenizer` will not outlive `this`, meaning that + // this std::bind object will be destroyed before `this` dies. + mTokenizer(std::bind(&nsMultiMixedConv::ConsumeToken, this, std::placeholders::_1)) { mContentLength = UINT64_MAX; mByteRangeStart = 0; From 0cb8e06e5236926d18b78180bb881ee83cd4dec0 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Thu, 16 Feb 2017 14:33:53 -0500 Subject: [PATCH 043/102] Bug 1336510 - Part 6: Avoid AddRefing/Releasing CamerasChild on the wrong thread, r=jwwang MozReview-Commit-ID: 8b5KK7sL6wb --- dom/media/ogg/OggDemuxer.cpp | 10 ++- dom/media/systemservices/CamerasChild.cpp | 93 ++++++----------------- 2 files changed, 29 insertions(+), 74 deletions(-) diff --git a/dom/media/ogg/OggDemuxer.cpp b/dom/media/ogg/OggDemuxer.cpp index 618a403b3b81..5da73ea16f5f 100644 --- a/dom/media/ogg/OggDemuxer.cpp +++ b/dom/media/ogg/OggDemuxer.cpp @@ -128,9 +128,13 @@ OggDemuxer::~OggDemuxer() // If we were able to initialize our decoders, report whether we encountered // a chained stream or not. bool isChained = mIsChained; - RefPtr self = this; - nsCOMPtr task = NS_NewRunnableFunction([this, self, isChained]() -> void { - OGG_DEBUG("Reporting telemetry MEDIA_OGG_LOADED_IS_CHAINED=%d", isChained); + void* ptr = this; + nsCOMPtr task = NS_NewRunnableFunction([ptr, isChained]() -> void { + // We can't use OGG_DEBUG here because it implicitly refers to `this`, + // which we can't capture in this runnable. + MOZ_LOG(gMediaDemuxerLog, mozilla::LogLevel::Debug, + ("OggDemuxer(%p)::%s: Reporting telemetry MEDIA_OGG_LOADED_IS_CHAINED=%d", + ptr, __func__, isChained)); Telemetry::Accumulate(Telemetry::HistogramID::MEDIA_OGG_LOADED_IS_CHAINED, isChained); }); // Non-DocGroup version of AbstractThread::MainThread is fine for Telemetry. diff --git a/dom/media/systemservices/CamerasChild.cpp b/dom/media/systemservices/CamerasChild.cpp index 8ece71ce16df..b955881291ff 100644 --- a/dom/media/systemservices/CamerasChild.cpp +++ b/dom/media/systemservices/CamerasChild.cpp @@ -284,14 +284,9 @@ CamerasChild::NumberOfCapabilities(CaptureEngine aCapEngine, LOG((__PRETTY_FUNCTION__)); LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8)); nsCString unique_id(deviceUniqueIdUTF8); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine, unique_id]() -> nsresult { - if (self->SendNumberOfCapabilities(aCapEngine, unique_id)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendNumberOfCapabilities, aCapEngine, unique_id); LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger); LOG(("Capture capability count: %d", dispatcher.ReturnValue())); return dispatcher.ReturnValue(); @@ -301,14 +296,9 @@ int CamerasChild::NumberOfCaptureDevices(CaptureEngine aCapEngine) { LOG((__PRETTY_FUNCTION__)); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine]() -> nsresult { - if (self->SendNumberOfCaptureDevices(aCapEngine)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendNumberOfCaptureDevices, aCapEngine); LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger); LOG(("Capture Devices: %d", dispatcher.ReturnValue())); return dispatcher.ReturnValue(); @@ -330,14 +320,9 @@ int CamerasChild::EnsureInitialized(CaptureEngine aCapEngine) { LOG((__PRETTY_FUNCTION__)); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine]() -> nsresult { - if (self->SendEnsureInitialized(aCapEngine)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendEnsureInitialized, aCapEngine); LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger); LOG(("Capture Devices: %d", dispatcher.ReturnValue())); return dispatcher.ReturnValue(); @@ -351,14 +336,9 @@ CamerasChild::GetCaptureCapability(CaptureEngine aCapEngine, { LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number)); nsCString unique_id(unique_idUTF8); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine, unique_id, capability_number]() -> nsresult { - if (self->SendGetCaptureCapability(aCapEngine, unique_id, capability_number)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendGetCaptureCapability, aCapEngine, unique_id, capability_number); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { capability = mReplyCapability; @@ -393,14 +373,9 @@ CamerasChild::GetCaptureDevice(CaptureEngine aCapEngine, bool* scary) { LOG((__PRETTY_FUNCTION__)); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine, list_number]() -> nsresult { - if (self->SendGetCaptureDevice(aCapEngine, list_number)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendGetCaptureDevice, aCapEngine, list_number); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { base::strlcpy(device_nameUTF8, mReplyDeviceName.get(), device_nameUTF8Length); @@ -438,14 +413,9 @@ CamerasChild::AllocateCaptureDevice(CaptureEngine aCapEngine, { LOG((__PRETTY_FUNCTION__)); nsCString unique_id(unique_idUTF8); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine, unique_id, aPrincipalInfo]() -> nsresult { - if (self->SendAllocateCaptureDevice(aCapEngine, unique_id, aPrincipalInfo)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendAllocateCaptureDevice, aCapEngine, unique_id, aPrincipalInfo); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { LOG(("Capture Device allocated: %d", mReplyInteger)); @@ -472,14 +442,9 @@ CamerasChild::ReleaseCaptureDevice(CaptureEngine aCapEngine, const int capture_id) { LOG((__PRETTY_FUNCTION__)); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine, capture_id]() -> nsresult { - if (self->SendReleaseCaptureDevice(aCapEngine, capture_id)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendReleaseCaptureDevice, aCapEngine, capture_id); LockAndDispatch<> dispatcher(this, __func__, runnable); return dispatcher.ReturnValue(); } @@ -524,14 +489,9 @@ CamerasChild::StartCapture(CaptureEngine aCapEngine, webrtcCaps.rawType, webrtcCaps.codecType, webrtcCaps.interlaced); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine, capture_id, capCap]() -> nsresult { - if (self->SendStartCapture(aCapEngine, capture_id, capCap)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendStartCapture, aCapEngine, capture_id, capCap); LockAndDispatch<> dispatcher(this, __func__, runnable); return dispatcher.ReturnValue(); } @@ -540,14 +500,9 @@ int CamerasChild::StopCapture(CaptureEngine aCapEngine, const int capture_id) { LOG((__PRETTY_FUNCTION__)); - RefPtr self = this; nsCOMPtr runnable = - media::NewRunnableFrom([self, aCapEngine, capture_id]() -> nsresult { - if (self->SendStopCapture(aCapEngine, capture_id)) { - return NS_OK; - } - return NS_ERROR_FAILURE; - }); + mozilla::NewNonOwningRunnableMethod + (this, &CamerasChild::SendStopCapture, aCapEngine, capture_id); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { RemoveCallback(aCapEngine, capture_id); @@ -608,14 +563,10 @@ CamerasChild::ShutdownParent() if (CamerasSingleton::Thread()) { LOG(("Dispatching actor deletion")); // Delete the parent actor. - RefPtr self = this; - RefPtr deleteRunnable = - // CamerasChild (this) will remain alive and is only deleted by the - // IPC layer when SendAllDone returns. - media::NewRunnableFrom([self]() -> nsresult { - Unused << self->SendAllDone(); - return NS_OK; - }); + // CamerasChild (this) will remain alive and is only deleted by the + // IPC layer when SendAllDone returns. + nsCOMPtr deleteRunnable = + mozilla::NewNonOwningRunnableMethod(this, &CamerasChild::SendAllDone); CamerasSingleton::Thread()->Dispatch(deleteRunnable, NS_DISPATCH_NORMAL); } else { LOG(("ShutdownParent called without PBackground thread")); From 62e029b414f7c0df5293be5cc727f8c3a7451c57 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Thu, 16 Feb 2017 14:38:09 -0500 Subject: [PATCH 044/102] Bug 1336510 - Part 7: Stop capturing this by value in windows-only code, r=aklotz MozReview-Commit-ID: B4dYo4ETzkL --- ipc/mscom/MainThreadHandoff.cpp | 12 ++++++------ ipc/mscom/WeakRef.cpp | 14 ++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/ipc/mscom/MainThreadHandoff.cpp b/ipc/mscom/MainThreadHandoff.cpp index 521bf7f8e8df..7f9e44a90437 100644 --- a/ipc/mscom/MainThreadHandoff.cpp +++ b/ipc/mscom/MainThreadHandoff.cpp @@ -13,6 +13,7 @@ #include "mozilla/Assertions.h" #include "mozilla/DebugOnly.h" #include "nsThreadUtils.h" +#include "nsProxyRelease.h" using mozilla::DebugOnly; @@ -107,12 +108,11 @@ MainThreadHandoff::Release() if (NS_IsMainThread()) { delete this; } else { - mozilla::DebugOnly rv = - NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void - { - delete this; - })); - MOZ_ASSERT(NS_SUCCEEDED(rv)); + // We need to delete this object on the main thread, but we aren't on the + // main thread right now, so we send a reference to ourselves to the main + // thread to be re-released there. + RefPtr self = this; + NS_ReleaseOnMainThread(self.forget()); } } return newRefCnt; diff --git a/ipc/mscom/WeakRef.cpp b/ipc/mscom/WeakRef.cpp index 807fcfb5eea1..80b2e4d633d9 100644 --- a/ipc/mscom/WeakRef.cpp +++ b/ipc/mscom/WeakRef.cpp @@ -11,6 +11,7 @@ #include "mozilla/Mutex.h" #include "nsThreadUtils.h" #include "nsWindowsHelpers.h" +#include "nsProxyRelease.h" static void InitializeCS(CRITICAL_SECTION& aCS) @@ -147,14 +148,11 @@ WeakReferenceSupport::Release() if (mFlags != Flags::eDestroyOnMainThread || NS_IsMainThread()) { delete this; } else { - // It is possible for the last Release() call to happen off-main-thread. - // If so, we need to dispatch an event to delete ourselves. - mozilla::DebugOnly rv = - NS_DispatchToMainThread(NS_NewRunnableFunction([this]() -> void - { - delete this; - })); - MOZ_ASSERT(NS_SUCCEEDED(rv)); + // We need to delete this object on the main thread, but we aren't on the + // main thread right now, so we send a reference to ourselves to the main + // thread to be re-released there. + RefPtr self = this; + NS_ReleaseOnMainThread(self.forget()); } } return newRefCnt; From 16e0562181f94a7ee3984ea56cbc6b1ee90852e6 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Thu, 16 Feb 2017 14:47:41 -0500 Subject: [PATCH 045/102] Bug 1336510 - Part 8: Stop capturing this by value in OSX only code, r=schien MozReview-Commit-ID: BHWJMHNgdRu --- netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp b/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp index 04e5b3ec7ebd..72b557774905 100644 --- a/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp +++ b/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp @@ -621,7 +621,7 @@ ResolveOperator::Reply(DNSServiceRef aSdRef, { MOZ_ASSERT(GetThread() == NS_GetCurrentThread()); - auto guard = MakeScopeExit([this] { + auto guard = MakeScopeExit([&] { Unused << NS_WARN_IF(NS_FAILED(Stop())); }); @@ -740,7 +740,7 @@ GetAddrInfoOperator::Reply(DNSServiceRef aSdRef, { MOZ_ASSERT(GetThread() == NS_GetCurrentThread()); - auto guard = MakeScopeExit([this] { + auto guard = MakeScopeExit([&] { Unused << NS_WARN_IF(NS_FAILED(Stop())); }); From 88cf28ec48f4e67aa21781214f434939780ae8b2 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Fri, 17 Feb 2017 14:44:51 -0500 Subject: [PATCH 046/102] Bug 1336510 - Part 9: Avoid MediaDecoder shutdown hang due to unnecessary strong reference capture, r=jwwang MozReview-Commit-ID: ElH27usjxlj --- dom/media/MediaDecoderStateMachine.cpp | 11 +++++++---- dom/media/MediaDecoderStateMachine.h | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 245be46b4de2..b1390ece876a 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2805,6 +2805,11 @@ bool MediaDecoderStateMachine::IsPlaying() const return mMediaSink->IsPlaying(); } +void MediaDecoderStateMachine::SetMediaNotSeekable() +{ + mMediaSeekable = false; +} + nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) { MOZ_ASSERT(NS_IsMainThread()); @@ -2821,11 +2826,8 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) mMetadataManager.Connect(mReader->TimedMetadataEvent(), OwnerThread()); - RefPtr self = this; mOnMediaNotSeekable = mReader->OnMediaNotSeekable().Connect( - OwnerThread(), [self] () { - self->mMediaSeekable = false; - }); + OwnerThread(), this, &MediaDecoderStateMachine::SetMediaNotSeekable); mMediaSink = CreateMediaSink(mAudioCaptured); @@ -2838,6 +2840,7 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) nsresult rv = mReader->Init(); NS_ENSURE_SUCCESS(rv, rv); + RefPtr self = this; OwnerThread()->Dispatch(NS_NewRunnableFunction([self] () { MOZ_ASSERT(!self->mStateObj); auto s = new DecodeMetadataState(self); diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 46b4d2a1af14..57abc3a2b62a 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -297,6 +297,9 @@ private: // be held. bool IsPlaying() const; + // Sets mMediaSeekable to false. + void SetMediaNotSeekable(); + // Resets all states related to decoding and aborts all pending requests // to the decoders. void ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack, From 9cf522342cd3fd19c22986e7a85d118cfea480f5 Mon Sep 17 00:00:00 2001 From: Alessio Placitelli Date: Thu, 23 Feb 2017 18:23:50 +0100 Subject: [PATCH 047/102] Backed out changeset 3bb2c974b5dc due to Browser Console spamming (bug 1334469) --- .../telemetry/TelemetryHistogram.cpp | 21 ------------------- .../telemetry/docs/collection/histograms.rst | 12 ++--------- .../tests/unit/test_TelemetryHistograms.js | 9 -------- 3 files changed, 2 insertions(+), 40 deletions(-) diff --git a/toolkit/components/telemetry/TelemetryHistogram.cpp b/toolkit/components/telemetry/TelemetryHistogram.cpp index 9a5366b5f509..89e1da08b3d3 100644 --- a/toolkit/components/telemetry/TelemetryHistogram.cpp +++ b/toolkit/components/telemetry/TelemetryHistogram.cpp @@ -1316,9 +1316,6 @@ internal_RemoteAccumulate(mozilla::Telemetry::HistogramID aId, KeyedHistogram* keyed = internal_GetKeyedHistogramById(nsDependentCString(th.id())); MOZ_ASSERT(keyed); - // Assert on empty keys as well, we should be filtering them out in - // the outer API. - MOZ_ASSERT(!aKey.IsEmpty()); if (!keyed->IsRecordingEnabled()) { return false; } @@ -1746,12 +1743,6 @@ internal_JSKeyedHistogram_Add(JSContext *cx, unsigned argc, JS::Value *vp) return true; } - if (key.IsEmpty()) { - LogToBrowserConsole(nsIScriptError::errorFlag, - NS_LITERAL_STRING("Empty histogram keys are not allowed.")); - return true; - } - const uint32_t type = keyed->GetHistogramType(); // If we don't have an argument for the count histogram, assume an increment of 1. @@ -2145,12 +2136,6 @@ TelemetryHistogram::Accumulate(mozilla::Telemetry::HistogramID aID, return; } - if (aKey.IsEmpty()) { - LogToBrowserConsole(nsIScriptError::errorFlag, - NS_LITERAL_STRING("Empty histogram keys are not allowed.")); - return; - } - StaticMutexAutoLock locker(gTelemetryHistogramMutex); internal_Accumulate(aID, aKey, aSample); } @@ -2174,12 +2159,6 @@ void TelemetryHistogram::Accumulate(const char* name, const nsCString& key, uint32_t sample) { - if (key.IsEmpty()) { - LogToBrowserConsole(nsIScriptError::errorFlag, - NS_LITERAL_STRING("Empty histogram keys are not allowed.")); - return; - } - StaticMutexAutoLock locker(gTelemetryHistogramMutex); if (!internal_CanRecordBase()) { return; diff --git a/toolkit/components/telemetry/docs/collection/histograms.rst b/toolkit/components/telemetry/docs/collection/histograms.rst index 6a4d4eafa575..7a943a572da7 100644 --- a/toolkit/components/telemetry/docs/collection/histograms.rst +++ b/toolkit/components/telemetry/docs/collection/histograms.rst @@ -89,11 +89,7 @@ Keyed Histograms ---------------- Keyed histograms are collections of one of the histogram types above, indexed by a string key. This is for example useful when you want to break down certain counts by a name, like how often searches happen with which search engine. - -Note that: - -- keys can't be empty strings; -- when you need to record for a small set of known keys, using separate plain histograms is more efficient. +Note that when you need to record for a small set of known keys, using separate plain histograms is more efficient. .. warning:: @@ -207,11 +203,7 @@ A Telemetry probe is the code that measures and stores values in a histogram. Pr let keyed = Services.telemetry.getKeyedHistogramById("TAG_SEEN_COUNTS"); keyed.add("blink"); -Note that: - -- ``nsITelemetry.getHistogramById()`` will throw an ``NS_ERROR_ILLEGAL_VALUE`` JavaScript exception if it is called with an invalid histogram ID; -- the ``add()`` function will not throw on failure, but log an error to the browser console; -- for keyed histograms, calling ``add()`` with an empty key will be ignored and log an error. +Note that ``nsITelemetry.getHistogramById()`` will throw an ``NS_ERROR_ILLEGAL_VALUE`` JavaScript exception if it is called with an invalid histogram ID. The ``add()`` function will not throw if it fails, instead it prints an error in the browser console. For histograms measuring time, `TelemetryStopwatch `_ can be used to avoid working with Dates manually: diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js b/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js index 55b9355f22a1..16650773126b 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js @@ -487,15 +487,6 @@ add_task(function* test_keyed_histogram() { threw = true; } Assert.ok(threw, "getKeyedHistogramById should have thrown"); - - // Check that empty keys are not allowed. - const KEYED_ID = "TELEMETRY_TEST_KEYED_COUNT"; - let h = Telemetry.getKeyedHistogramById(KEYED_ID); - - // Try to add to an empty key and make sure nothing happens. - h.add(""); - Assert.ok(!("" in h.snapshot()), - "Keyed histogram should not allow empty keys."); }); add_task(function* test_keyed_boolean_histogram() { From f4fe4c7e90e2504afda7f6630ffe955a5b8878a6 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Tue, 21 Feb 2017 22:17:52 -0500 Subject: [PATCH 048/102] bug 1341414 - Functions like GetBoolVarCache shouldn't assert when used early in startup r=billm --- dom/ipc/ContentPrefs.cpp | 159 ++----------------------- modules/libpref/Preferences.cpp | 17 +++ modules/libpref/prefapi.cpp | 11 +- modules/libpref/prefapi_private_data.h | 3 + 4 files changed, 37 insertions(+), 153 deletions(-) diff --git a/dom/ipc/ContentPrefs.cpp b/dom/ipc/ContentPrefs.cpp index 232570acd20a..479de1c9fba3 100644 --- a/dom/ipc/ContentPrefs.cpp +++ b/dom/ipc/ContentPrefs.cpp @@ -1,75 +1,30 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 "ContentPrefs.h" +/************************************************************ + * DO NOT ADD PREFS TO THIS LIST WITHOUT DOM PEER REVIEW * + ************************************************************/ + const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { - "accessibility.monoaudio.enable", "accessibility.mouse_focuses_formcontrol", "accessibility.tabfocus_applies_to_xul", "app.update.channel", "browser.dom.window.dump.enabled", "browser.sessionhistory.max_entries", "browser.sessionhistory.max_total_viewers", - "content.cors.disable", - "content.cors.no_private_data", - "content.notify.backoffcount", - "content.notify.interval", - "content.notify.ontimer", - "content.sink.enable_perf_mode", - "content.sink.event_probe_rate", - "content.sink.initial_perf_time", - "content.sink.interactive_deflect_count", - "content.sink.interactive_parse_time", - "content.sink.interactive_time", - "content.sink.pending_event_mode", - "content.sink.perf_deflect_count", - "content.sink.perf_parse_time", "device.storage.prompt.testing", "device.storage.writable.name", - "dom.allow_XUL_XBL_for_file", - "dom.allow_cut_copy", - "dom.enable_frame_timing", - "dom.enable_performance", - "dom.enable_resource_timing", - "dom.event.handling-user-input-time-limit", "dom.event.touch.coalescing.enabled", - "dom.forms.autocomplete.experimental", - "dom.ipc.processPriorityManager.backgroundGracePeriodMS", - "dom.ipc.processPriorityManager.backgroundPerceivableGracePeriodMS", "dom.max_chrome_script_run_time", "dom.max_script_run_time", - "dom.mozBrowserFramesEnabled", - "dom.performance.enable_notify_performance_timing", - "dom.performance.enable_user_timing_logging", - "dom.storage.testing", - "dom.url.encode_decode_hash", - "dom.url.getters_decode_hash", "dom.use_watchdog", - "dom.vibrator.enabled", - "dom.vibrator.max_vibrate_list_len", - "dom.vibrator.max_vibrate_ms", "focusmanager.testmode", - "font.size.inflation.disabledInMasterProcess", - "font.size.inflation.emPerLine", - "font.size.inflation.forceEnabled", - "font.size.inflation.lineThreshold", - "font.size.inflation.mappingIntercept", - "font.size.inflation.maxRatio", - "font.size.inflation.minTwips", - "full-screen-api.allow-trusted-requests-only", - "full-screen-api.enabled", - "full-screen-api.unprefix.enabled", - "gfx.font_rendering.opentype_svg.enabled", "hangmonitor.timeout", - "html5.flushtimer.initialdelay", - "html5.flushtimer.subsequentdelay", - "html5.offmainthread", - "intl.charset.fallback.tld", - "intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition", "javascript.enabled", "javascript.options.asmjs", "javascript.options.asyncstack", @@ -97,102 +52,22 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "javascript.options.werror", "javascript.use_us_english_locale", "jsloader.reuseGlobal", - "layout.css.all-shorthand.enabled", - "layout.css.background-blend-mode.enabled", - "layout.css.background-clip-text.enabled", - "layout.css.box-decoration-break.enabled", - "layout.css.color-adjust.enabled", - "layout.css.contain.enabled", - "layout.css.control-characters.visible", - "layout.css.display-flow-root.enabled", - "layout.css.expensive-style-struct-assertions.enabled", - "layout.css.float-logical-values.enabled", - "layout.css.font-variations.enabled", - "layout.css.grid.enabled", - "layout.css.image-orientation.enabled", - "layout.css.initial-letter.enabled", - "layout.css.isolation.enabled", - "layout.css.mix-blend-mode.enabled", - "layout.css.object-fit-and-position.enabled", - "layout.css.osx-font-smoothing.enabled", - "layout.css.overflow-clip-box.enabled", - "layout.css.prefixes.animations", - "layout.css.prefixes.border-image", - "layout.css.prefixes.box-sizing", - "layout.css.prefixes.device-pixel-ratio-webkit", - "layout.css.prefixes.font-features", - "layout.css.prefixes.gradients", - "layout.css.prefixes.transforms", - "layout.css.prefixes.transitions", - "layout.css.prefixes.webkit", - "layout.css.scope-pseudo.enabled", - "layout.css.scroll-behavior.property-enabled", - "layout.css.scroll-snap.enabled", "layout.css.servo.enabled", - "layout.css.shape-outside.enabled", - "layout.css.text-align-unsafe-value.enabled", - "layout.css.text-combine-upright-digits.enabled", - "layout.css.text-combine-upright.enabled", - "layout.css.touch_action.enabled", "layout.css.unprefixing-service.enabled", "layout.css.unprefixing-service.globally-whitelisted", "layout.css.unprefixing-service.include-test-domains", - "layout.css.variables.enabled", - "layout.css.visited_links_enabled", - "layout.idle_period.required_quiescent_frames", - "layout.idle_period.time_limit", - "layout.interruptible-reflow.enabled", "mathml.disabled", - "media.apple.forcevda", - "media.clearkey.persistent-license.enabled", "media.cubeb_latency_msg_frames", "media.cubeb_latency_playback_ms", "media.decoder-doctor.wmf-disabled-is-failure", - "media.decoder.fuzzing.dont-delay-inputexhausted", - "media.decoder.fuzzing.enabled", - "media.decoder.fuzzing.video-output-minimum-interval-ms", - "media.decoder.limit", - "media.decoder.recycle.enabled", - "media.dormant-on-pause-timeout-ms", - "media.eme.audio.blank", - "media.eme.enabled", - "media.eme.video.blank", - "media.ffmpeg.enabled", - "media.ffvpx.enabled", "media.ffvpx.low-latency.enabled", - "media.flac.enabled", - "media.forcestereo.enabled", "media.gmp.async-shutdown-timeout", - "media.gmp.decoder.aac", - "media.gmp.decoder.enabled", - "media.gmp.decoder.h264", - "media.gmp.insecure.allow", - "media.gpu-process-decoder", - "media.libavcodec.allow-obsolete", - "media.num-decode-threads", - "media.ogg.enabled", - "media.ogg.flac.enabled", - "media.resampling.enabled", - "media.resampling.rate", - "media.ruin-av-sync.enabled", - "media.rust.test_mode", - "media.suspend-bkgnd-video.delay-ms", - "media.suspend-bkgnd-video.enabled", - "media.use-blank-decoder", - "media.video_stats.enabled", "media.volume_scale", - "media.webspeech.recognition.enable", - "media.webspeech.recognition.force_enable", - "media.webspeech.synth.force_global_queue", - "media.webspeech.test.enable", - "media.webspeech.test.fake_fsm_events", - "media.webspeech.test.fake_recognition_service", "media.wmf.allow-unsupported-resolutions", "media.wmf.decoder.thread-count", "media.wmf.enabled", "media.wmf.skip-blacklist", "media.wmf.vp9.enabled", - "memory.free_dirty_pages", "memory.low_commit_space_threshold_mb", "memory.low_memory_notification_interval_ms", "memory.low_physical_memory_threshold_mb", @@ -204,20 +79,16 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "network.buffer.cache.count", "network.buffer.cache.size", "network.captive-portal-service.enabled", - "network.cookie.cookieBehavior", - "network.cookie.lifetimePolicy", "network.dns.disablePrefetch", "network.dns.disablePrefetchFromHTTPS", "network.jar.block-remote-files", "network.loadinfo.skip_type_assertion", "network.notify.changed", - "network.offline-mirrors-connectivity", "network.protocol-handler.external.jar", "network.proxy.type", "network.security.ports.banned", "network.security.ports.banned.override", "network.standard-url.enable-rust", - "network.standard-url.max-length", "network.sts.max_time_for_events_between_two_polls", "network.sts.max_time_for_pr_close_during_shutdown", "network.tcp.keepalive.enabled", @@ -225,12 +96,6 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "network.tcp.keepalive.probe_count", "network.tcp.keepalive.retry_interval", "network.tcp.sendbuffer", - "nglayout.debug.invalidation", - "privacy.donottrackheader.enabled", - "privacy.firstparty.isolate", - "privacy.firstparty.isolate.restrict_opener_access", - "privacy.resistFingerprinting", - "security.data_uri.inherit_security_context", "security.fileuri.strict_origin_policy", "security.sandbox.content.level", "security.sandbox.content.tempDirSuffix", @@ -239,14 +104,8 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "security.sandbox.windows.log", "security.sandbox.windows.log.stackTraceDepth", "shutdown.watchdog.timeoutSecs", - "signed.applets.codebase_principal_support", "svg.disabled", - "svg.display-lists.hit-testing.enabled", - "svg.display-lists.painting.enabled", - "svg.new-getBBox.enabled", - "svg.paint-order.enabled", "svg.path-caching.enabled", - "svg.transform-box.enabled", "toolkit.asyncshutdown.crash_timeout", "toolkit.asyncshutdown.log", "toolkit.osfile.log", @@ -259,11 +118,7 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "toolkit.telemetry.minSubsessionLength", "toolkit.telemetry.scheduler.idleTickInterval", "toolkit.telemetry.scheduler.tickInterval", - "toolkit.telemetry.unified", - "ui.key.menuAccessKeyFocuses", - "ui.popup.disable_autohide", - "ui.use_activity_cursor", - "view_source.editor.external"}; + "toolkit.telemetry.unified"}; const char** mozilla::dom::ContentPrefs::GetContentPrefs(size_t* aCount) { diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index b1f86b9e0f62..077289492076 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -60,11 +60,22 @@ return NS_ERROR_NOT_AVAILABLE; \ } \ } while (0); +class WatchinPrefRAII { +public: + WatchinPrefRAII() { + pref_SetWatchingPref(true); + } + ~WatchinPrefRAII() { + pref_SetWatchingPref(false); + } +}; +#define WATCHING_PREF_RAII() WatchinPrefRAII watchingPrefRAII #else #define ENSURE_MAIN_PROCESS(message, pref) \ if (MOZ_UNLIKELY(!XRE_IsParentProcess())) { \ return NS_ERROR_NOT_AVAILABLE; \ } +#define WATCHING_PREF_RAII() #endif class PrefCallback; @@ -1732,6 +1743,7 @@ Preferences::RegisterCallbackAndCall(PrefChangedFunc aCallback, void* aClosure, MatchKind aMatchKind) { + WATCHING_PREF_RAII(); nsresult rv = RegisterCallback(aCallback, aPref, aClosure, aMatchKind); if (NS_SUCCEEDED(rv)) { (*aCallback)(aPref, aClosure); @@ -1779,6 +1791,7 @@ Preferences::AddBoolVarCache(bool* aCache, const char* aPref, bool aDefault) { + WATCHING_PREF_RAII(); NS_ASSERTION(aCache, "aCache must not be NULL"); #ifdef DEBUG AssertNotAlreadyCached("bool", aPref, aCache); @@ -1804,6 +1817,7 @@ Preferences::AddIntVarCache(int32_t* aCache, const char* aPref, int32_t aDefault) { + WATCHING_PREF_RAII(); NS_ASSERTION(aCache, "aCache must not be NULL"); #ifdef DEBUG AssertNotAlreadyCached("int", aPref, aCache); @@ -1829,6 +1843,7 @@ Preferences::AddUintVarCache(uint32_t* aCache, const char* aPref, uint32_t aDefault) { + WATCHING_PREF_RAII(); NS_ASSERTION(aCache, "aCache must not be NULL"); #ifdef DEBUG AssertNotAlreadyCached("uint", aPref, aCache); @@ -1856,6 +1871,7 @@ Preferences::AddAtomicUintVarCache(Atomic* aCache, const char* aPref, uint32_t aDefault) { + WATCHING_PREF_RAII(); NS_ASSERTION(aCache, "aCache must not be NULL"); #ifdef DEBUG AssertNotAlreadyCached("uint", aPref, aCache); @@ -1888,6 +1904,7 @@ Preferences::AddFloatVarCache(float* aCache, const char* aPref, float aDefault) { + WATCHING_PREF_RAII(); NS_ASSERTION(aCache, "aCache must not be NULL"); #ifdef DEBUG AssertNotAlreadyCached("float", aPref, aCache); diff --git a/modules/libpref/prefapi.cpp b/modules/libpref/prefapi.cpp index b9052c5d95dc..e94c49868d45 100644 --- a/modules/libpref/prefapi.cpp +++ b/modules/libpref/prefapi.cpp @@ -737,12 +737,21 @@ static PrefTypeFlags pref_SetValue(PrefValue* existingValue, PrefTypeFlags flags #ifdef DEBUG static pref_initPhase gPhase = START; +static bool gWatchingPref = false; + void pref_SetInitPhase(pref_initPhase phase) { gPhase = phase; } +void +pref_SetWatchingPref(bool watching) +{ + gWatchingPref = watching; +} + + struct StringComparator { const char* mKey; @@ -774,7 +783,7 @@ PrefHashEntry* pref_HashTableLookup(const char *key) * Consider moving it later or add it to the whitelist in ContentPrefs.cpp * and get review from a DOM peer */ - MOZ_ASSERT((!XRE_IsContentProcess() || gPhase > END_INIT_PREFS || inInitArray(key)), + MOZ_ASSERT((!XRE_IsContentProcess() || gPhase > END_INIT_PREFS || gWatchingPref || inInitArray(key)), "accessing non-init pref before the rest of the prefs are sent"); return static_cast(gHashTable->Search(key)); } diff --git a/modules/libpref/prefapi_private_data.h b/modules/libpref/prefapi_private_data.h index 4cf58f6a9f85..b7c49dafe804 100644 --- a/modules/libpref/prefapi_private_data.h +++ b/modules/libpref/prefapi_private_data.h @@ -29,6 +29,9 @@ pref_SetPref(const mozilla::dom::PrefSetting& aPref); #ifdef DEBUG void pref_SetInitPhase(pref_initPhase phase); + +void +pref_SetWatchingPref(bool watching); #endif int pref_CompareStrings(const void *v1, const void *v2, void* unused); From c53133b756b345f3d065e54f12f6ce90e53b8307 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 23 Feb 2017 10:04:45 -0500 Subject: [PATCH 049/102] Bug 1342067 - Annotate the name of the preference accessed too early in the pre-END_INIT_PREFS phase preference access crash message; r=blassey --- modules/libpref/prefapi.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/libpref/prefapi.cpp b/modules/libpref/prefapi.cpp index e94c49868d45..65d984d0f6bb 100644 --- a/modules/libpref/prefapi.cpp +++ b/modules/libpref/prefapi.cpp @@ -783,8 +783,13 @@ PrefHashEntry* pref_HashTableLookup(const char *key) * Consider moving it later or add it to the whitelist in ContentPrefs.cpp * and get review from a DOM peer */ - MOZ_ASSERT((!XRE_IsContentProcess() || gPhase > END_INIT_PREFS || gWatchingPref || inInitArray(key)), - "accessing non-init pref before the rest of the prefs are sent"); +#ifdef DEBUG + if (XRE_IsContentProcess() && gPhase <= END_INIT_PREFS && + !gWatchingPref && !inInitArray(key)) { + MOZ_CRASH_UNSAFE_PRINTF("accessing non-init pref %s before the rest of the prefs are sent", + key); + } +#endif return static_cast(gHashTable->Search(key)); } From 796528885230efe1518af31bb88334366ccd6ef4 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 22 Feb 2017 22:55:25 -0500 Subject: [PATCH 050/102] Bug 1341898 - Make nsDocument::IsWebComponentsEnabled use a cached bool pref; r=baku --- dom/base/CustomElementRegistry.cpp | 2 +- dom/base/nsContentUtils.cpp | 4 ++++ dom/base/nsContentUtils.h | 4 ++++ dom/base/nsDocument.cpp | 4 ++-- dom/ipc/ContentPrefs.cpp | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 2fcd326e11bb..362c43ff8ca9 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -172,7 +172,7 @@ NS_INTERFACE_MAP_END CustomElementRegistry::IsCustomElementEnabled(JSContext* aCx, JSObject* aObject) { return Preferences::GetBool("dom.webcomponents.customelements.enabled") || - Preferences::GetBool("dom.webcomponents.enabled"); + nsContentUtils::IsWebComponentsEnabled(); } /* static */ already_AddRefed diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index a0db9a2b3d3c..27d92cef1109 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -285,6 +285,7 @@ bool nsContentUtils::sIsPerformanceTimingEnabled = false; bool nsContentUtils::sIsResourceTimingEnabled = false; bool nsContentUtils::sIsUserTimingLoggingEnabled = false; bool nsContentUtils::sIsExperimentalAutocompleteEnabled = false; +bool nsContentUtils::sIsWebComponentsEnabled = false; bool nsContentUtils::sEncodeDecodeURLHash = false; bool nsContentUtils::sGettersDecodeURLHash = false; bool nsContentUtils::sPrivacyResistFingerprinting = false; @@ -583,6 +584,9 @@ nsContentUtils::Init() Preferences::AddBoolVarCache(&sIsExperimentalAutocompleteEnabled, "dom.forms.autocomplete.experimental", false); + Preferences::AddBoolVarCache(&sIsWebComponentsEnabled, + "dom.webcomponents.enabled", false); + Preferences::AddBoolVarCache(&sEncodeDecodeURLHash, "dom.url.encode_decode_hash", false); diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index af250c46c05b..e7889f9d1cbe 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -2806,6 +2806,9 @@ public: const mozilla::dom::Sequence& aTransfer, JS::MutableHandle aValue); + static bool + IsWebComponentsEnabled() { return sIsWebComponentsEnabled; } + private: static bool InitializeEventTable(); @@ -2912,6 +2915,7 @@ private: static bool sIsUserTimingLoggingEnabled; static bool sIsFrameTimingPrefEnabled; static bool sIsExperimentalAutocompleteEnabled; + static bool sIsWebComponentsEnabled; static bool sEncodeDecodeURLHash; static bool sGettersDecodeURLHash; static bool sPrivacyResistFingerprinting; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index e7a06e5d0cf5..d3000a0584dd 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -5944,7 +5944,7 @@ nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject) { JS::Rooted obj(aCx, aObject); - if (Preferences::GetBool("dom.webcomponents.enabled")) { + if (nsContentUtils::IsWebComponentsEnabled()) { return true; } @@ -5960,7 +5960,7 @@ nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject) bool nsDocument::IsWebComponentsEnabled(dom::NodeInfo* aNodeInfo) { - if (Preferences::GetBool("dom.webcomponents.enabled")) { + if (nsContentUtils::IsWebComponentsEnabled()) { return true; } diff --git a/dom/ipc/ContentPrefs.cpp b/dom/ipc/ContentPrefs.cpp index 479de1c9fba3..6dabc2ef4e7e 100644 --- a/dom/ipc/ContentPrefs.cpp +++ b/dom/ipc/ContentPrefs.cpp @@ -23,6 +23,7 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "dom.max_chrome_script_run_time", "dom.max_script_run_time", "dom.use_watchdog", + "dom.webcomponents.enabled", "focusmanager.testmode", "hangmonitor.timeout", "javascript.enabled", From 3a10631b7cce79f640bab3df041e42f5983d61e0 Mon Sep 17 00:00:00 2001 From: Michael Kaply Date: Thu, 23 Feb 2017 11:24:59 -0600 Subject: [PATCH 051/102] Bug 1031210 - Don't assume URL format to prevent crash. r=snorp MozReview-Commit-ID: 23qE4mI5tBU --- .../org/mozilla/gecko/util/StringUtils.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java index e5bf6551bd23..56f782915135 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/StringUtils.java @@ -102,20 +102,19 @@ public class StringUtils { return url; } - int start = 0; - int end = url.length(); + String newURL = url; - if (url.startsWith("http://")) { - start = 7; - } else if (url.startsWith("https://") && flags == UrlFlags.STRIP_HTTPS) { - start = 8; + if (newURL.startsWith("http://")) { + newURL = newURL.replace("http://", ""); + } else if (newURL.startsWith("https://") && flags == UrlFlags.STRIP_HTTPS) { + newURL = newURL.replace("https://", ""); } - if (url.endsWith("/")) { - end--; + if (newURL.endsWith("/")) { + newURL = newURL.substring(0, newURL.length()-1); } - return url.substring(start, end); + return newURL; } public static boolean isHttpOrHttps(String url) { From 8702aa26dd1bc561d1b99880b42693426ba250d8 Mon Sep 17 00:00:00 2001 From: Michael Kaply Date: Thu, 23 Feb 2017 12:27:43 -0600 Subject: [PATCH 052/102] Bug 1332562 - OMA Downloads should go to the system Download directory. r=snorp MozReview-Commit-ID: 48fGzGYBoS6 --- .../base/java/org/mozilla/gecko/BrowserApp.java | 4 ++-- mobile/android/components/HelperAppDialog.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java index 4abe5fd9734c..c987cc67d723 100644 --- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java @@ -2070,8 +2070,8 @@ public class BrowserApp extends GeckoApp request.setMimeType(mimeType); try { - request.setDestinationInExternalFilesDir( - this, Environment.DIRECTORY_DOWNLOADS, filename); + request.setDestinationInExternalPublicDir( + Environment.DIRECTORY_DOWNLOADS, filename); } catch (IllegalStateException e) { Log.e(LOGTAG, "Cannot create download directory"); break; diff --git a/mobile/android/components/HelperAppDialog.js b/mobile/android/components/HelperAppDialog.js index be83983c8178..9769bc1fa2d6 100644 --- a/mobile/android/components/HelperAppDialog.js +++ b/mobile/android/components/HelperAppDialog.js @@ -137,8 +137,16 @@ HelperAppLauncherDialog.prototype = { } if (this._shouldForwardToAndroidDownloadManager(aLauncher)) { - this._downloadWithAndroidDownloadManager(aLauncher); - aLauncher.cancel(Cr.NS_BINDING_ABORTED); + Task.spawn(function* () { + try { + let hasPermission = yield RuntimePermissions.waitForPermissions(RuntimePermissions.WRITE_EXTERNAL_STORAGE); + if (hasPermission) { + this._downloadWithAndroidDownloadManager(aLauncher); + aLauncher.cancel(Cr.NS_BINDING_ABORTED); + } + } finally { + } + }.bind(this)).catch(Cu.reportError); return; } From 0c165fa02e3783c4b8662aa32afc36e675384c2a Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Thu, 23 Feb 2017 13:02:40 -0600 Subject: [PATCH 053/102] Bug 1342060 - wasm: enable by default (r=bbouvier,sr=jorendorff) MozReview-Commit-ID: LozhxKgleFc --- .../tests/unit/test_frameactor_wasm-01.js | 7 +------ dom/base/test/test_postMessages.html | 3 +-- dom/indexedDB/test/helpers.js | 3 +-- .../test/unit/wasm_recompile_profile.zip | Bin 5446 -> 5446 bytes .../test/unit/xpcshell-head-parent-process.js | 12 ------------ .../tests/test_webassembly_compile.html | 2 +- .../mochitest/general/test_interfaces.js | 1 + .../test_serviceworker_interfaces.js | 1 + dom/workers/test/test_worker_interfaces.js | 1 + js/src/jit-test/tests/wasm/binary.js | 3 --- js/src/jit-test/tests/wasm/spec/binary.wast | 14 +++++++------- .../tests/wasm/spec/custom_section.wast | 14 +++++++------- js/src/wasm/WasmBinaryConstants.h | 4 ---- js/src/wasm/WasmValidate.cpp | 2 +- modules/libpref/init/all.js | 2 +- 15 files changed, 23 insertions(+), 46 deletions(-) diff --git a/devtools/server/tests/unit/test_frameactor_wasm-01.js b/devtools/server/tests/unit/test_frameactor_wasm-01.js index 63376ae9efce..bc941b32283a 100644 --- a/devtools/server/tests/unit/test_frameactor_wasm-01.js +++ b/devtools/server/tests/unit/test_frameactor_wasm-01.js @@ -8,13 +8,9 @@ var gDebuggee; var gClient; var gThreadClient; -var gOldPref; function run_test() { - gOldPref = Services.prefs.getBoolPref("javascript.options.wasm"); - Services.prefs.setBoolPref("javascript.options.wasm", true); - if (typeof WebAssembly == "undefined") { return; // wasm is not enabled for this platform } @@ -49,7 +45,6 @@ function test_pause_frame() do_check_eq(location.column > 0, true); do_check_eq(location.source.url.endsWith(" > wasm"), true); - Services.prefs.setBoolPref("javascript.options.wasm", gOldPref); finishClient(gClient); }); }); @@ -58,7 +53,7 @@ function test_pause_frame() // WebAssembly bytecode was generated by running: // js -e 'print(wasmTextToBinary("(module(import \"a\" \"b\")(func(export \"c\")call 0))"))' var m = new WebAssembly.Module(new Uint8Array([ - 0,97,115,109,13,0,0,0,1,132,128,128,128,0,1,96,0,0,2,135,128,128,128,0,1,1,97,1, + 0,97,115,109,1,0,0,0,1,132,128,128,128,0,1,96,0,0,2,135,128,128,128,0,1,1,97,1, 98,0,0,3,130,128,128,128,0,1,0,6,129,128,128,128,0,0,7,133,128,128,128,0,1,1,99, 0,1,10,138,128,128,128,0,1,132,128,128,128,0,0,16,0,11 ])); diff --git a/dom/base/test/test_postMessages.html b/dom/base/test/test_postMessages.html index 13a284270083..f4cd87432fb9 100644 --- a/dom/base/test/test_postMessages.html +++ b/dom/base/test/test_postMessages.html @@ -11,8 +11,7 @@ diff --git a/dom/tests/mochitest/general/test_interfaces.js b/dom/tests/mochitest/general/test_interfaces.js index 80176a0fbe4f..4abbf8beaf0f 100644 --- a/dom/tests/mochitest/general/test_interfaces.js +++ b/dom/tests/mochitest/general/test_interfaces.js @@ -74,6 +74,7 @@ var ecmaGlobals = "URIError", "WeakMap", "WeakSet", + "WebAssembly" ]; // IMPORTANT: Do not change the list above without review from // a JavaScript Engine peer! diff --git a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js index af6d37a1069d..662c6e4b2aad 100644 --- a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js +++ b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js @@ -69,6 +69,7 @@ var ecmaGlobals = "URIError", "WeakMap", "WeakSet", + "WebAssembly" ]; // IMPORTANT: Do not change the list above without review from // a JavaScript Engine peer! diff --git a/dom/workers/test/test_worker_interfaces.js b/dom/workers/test/test_worker_interfaces.js index 694d99732929..9e8921d37dd6 100644 --- a/dom/workers/test/test_worker_interfaces.js +++ b/dom/workers/test/test_worker_interfaces.js @@ -69,6 +69,7 @@ var ecmaGlobals = "URIError", "WeakMap", "WeakSet", + "WebAssembly" ]; // IMPORTANT: Do not change the list above without review from // a JavaScript Engine peer! diff --git a/js/src/jit-test/tests/wasm/binary.js b/js/src/jit-test/tests/wasm/binary.js index f903f1c9fd8c..3aa6d69bef5e 100644 --- a/js/src/jit-test/tests/wasm/binary.js +++ b/js/src/jit-test/tests/wasm/binary.js @@ -64,9 +64,6 @@ assertErrorMessage(() => wasmEval(toU8([magic0, magic1, magic2, magic3, 1])), Co assertErrorMessage(() => wasmEval(toU8([magic0, magic1, magic2, magic3, ver0])), CompileError, versionError(0x6d736100)); assertErrorMessage(() => wasmEval(toU8([magic0, magic1, magic2, magic3, ver0, ver1, ver2])), CompileError, versionError(0x6d736100)); -// This test should be removed shortly. -assertEq(WebAssembly.validate(toU8([magic0, magic1, magic2, magic3, 0xd, 0x0, 0x0, 0x0])), true); - function moduleHeaderThen(...rest) { return [magic0, magic1, magic2, magic3, ver0, ver1, ver2, ver3, ...rest]; } diff --git a/js/src/jit-test/tests/wasm/spec/binary.wast b/js/src/jit-test/tests/wasm/spec/binary.wast index b0ab9c4266fd..9bb55ef9ea45 100644 --- a/js/src/jit-test/tests/wasm/spec/binary.wast +++ b/js/src/jit-test/tests/wasm/spec/binary.wast @@ -1,18 +1,18 @@ -(module "\00asm\0d\00\00\00") -(module "\00asm" "\0d\00\00\00") -(module $M1 "\00asm\0d\00\00\00") -(module $M2 "\00asm" "\0d\00\00\00") +(module "\00asm\01\00\00\00") +(module "\00asm" "\01\00\00\00") +(module $M1 "\00asm\01\00\00\00") +(module $M2 "\00asm" "\01\00\00\00") (assert_malformed (module "") "unexpected end") (assert_malformed (module "\01") "unexpected end") (assert_malformed (module "\00as") "unexpected end") (assert_malformed (module "asm\00") "magic header not detected") (assert_malformed (module "msa\00") "magic header not detected") -(assert_malformed (module "msa\00\0d\00\00\00") "magic header not detected") +(assert_malformed (module "msa\00\01\00\00\00") "magic header not detected") (assert_malformed (module "msa\00\00\00\00\0d") "magic header not detected") (assert_malformed (module "\00asm") "unexpected end") -(assert_malformed (module "\00asm\0d") "unexpected end") -(assert_malformed (module "\00asm\0d\00\00") "unexpected end") +(assert_malformed (module "\00asm\01") "unexpected end") +(assert_malformed (module "\00asm\01\00\00") "unexpected end") (assert_malformed (module "\00asm\0e\00\00\00") "unknown binary version") (assert_malformed (module "\00asm\00\00\00\0d") "unknown binary version") diff --git a/js/src/jit-test/tests/wasm/spec/custom_section.wast b/js/src/jit-test/tests/wasm/spec/custom_section.wast index 66e707c8fc36..f087a9d2d9c3 100644 --- a/js/src/jit-test/tests/wasm/spec/custom_section.wast +++ b/js/src/jit-test/tests/wasm/spec/custom_section.wast @@ -1,5 +1,5 @@ (module - "\00asm" "\0d\00\00\00" + "\00asm" "\01\00\00\00" "\00\24\10" "a custom section" "this is the payload" "\00\20\10" "a custom section" "this is payload" "\00\11\10" "a custom section" "" @@ -9,7 +9,7 @@ ) (module - "\00asm" "\0d\00\00\00" + "\00asm" "\01\00\00\00" "\00\0e\06" "custom" "payload" "\00\0e\06" "custom" "payload" "\01\01\00" ;; type section @@ -45,7 +45,7 @@ ) (module - "\00asm" "\0d\00\00\00" + "\00asm" "\01\00\00\00" "\01\07\01\60\02\7f\7f\01\7f" ;; type section "\00\1a\06" "custom" "this is the payload" ;; custom section "\03\02\01\00" ;; function section @@ -56,7 +56,7 @@ (assert_malformed (module - "\00asm" "\0d\00\00\00" + "\00asm" "\01\00\00\00" "\00\00" ) "unexpected end" @@ -64,7 +64,7 @@ (assert_malformed (module - "\00asm" "\0d\00\00\00" + "\00asm" "\01\00\00\00" "\00\26\10" "a custom section" "this is the payload" ) "unexpected end" @@ -72,7 +72,7 @@ (assert_malformed (module - "\00asm" "\0d\00\00\00" + "\00asm" "\01\00\00\00" "\00\25\10" "a custom section" "this is the payload" "\00\24\10" "a custom section" "this is the payload" ) @@ -81,7 +81,7 @@ (assert_malformed (module - "\00asm" "\0d\00\00\00" + "\00asm" "\01\00\00\00" "\01\07\01\60\02\7f\7f\01\7f" ;; type section "\00\25\10" "a custom section" "this is the payload" ;; invalid length! "\03\02\01\00" ;; function section diff --git a/js/src/wasm/WasmBinaryConstants.h b/js/src/wasm/WasmBinaryConstants.h index ca240f0a87b7..50253cfc18e8 100644 --- a/js/src/wasm/WasmBinaryConstants.h +++ b/js/src/wasm/WasmBinaryConstants.h @@ -27,10 +27,6 @@ namespace wasm { static const uint32_t MagicNumber = 0x6d736100; // "\0asm" static const uint32_t EncodingVersion = 0x01; -// 0xd is equivalent to 0x1 modulo unreachability validation rules, so to aid -// transition of toolchain, accept both for a short period of time. -static const uint32_t PrevEncodingVersion = 0x0d; - static const char NameSectionName[] = "name"; enum class SectionId diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp index 09a19f0a38c8..12d6c2b646e8 100644 --- a/js/src/wasm/WasmValidate.cpp +++ b/js/src/wasm/WasmValidate.cpp @@ -617,7 +617,7 @@ DecodePreamble(Decoder& d) if (!d.readFixedU32(&u32) || u32 != MagicNumber) return d.fail("failed to match magic number"); - if (!d.readFixedU32(&u32) || (u32 != EncodingVersion && u32 != PrevEncodingVersion)) { + if (!d.readFixedU32(&u32) || u32 != EncodingVersion) { return d.fail("binary version 0x%" PRIx32 " does not match expected version 0x%" PRIx32, u32, EncodingVersion); } diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 649c6b1a60d1..3c94c61460c9 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1273,7 +1273,7 @@ pref("javascript.options.strict.debug", false); pref("javascript.options.baselinejit", true); pref("javascript.options.ion", true); pref("javascript.options.asmjs", true); -pref("javascript.options.wasm", false); +pref("javascript.options.wasm", true); pref("javascript.options.wasm_baselinejit", false); pref("javascript.options.native_regexp", true); pref("javascript.options.parallel_parsing", true); From 450d0f1c0fa96dcb138c0368fb59676ac0790c18 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Thu, 23 Feb 2017 14:40:59 -0500 Subject: [PATCH 054/102] Bug 1303094 - avoid OOM crashes in SourceSurfaceSkia::DrawTargetWillChange. r=mchang MozReview-Commit-ID: 236vebw7ftU --- gfx/2d/SourceSurfaceSkia.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/gfx/2d/SourceSurfaceSkia.cpp b/gfx/2d/SourceSurfaceSkia.cpp index 3f242eaf9356..186e3b8c1c48 100644 --- a/gfx/2d/SourceSurfaceSkia.cpp +++ b/gfx/2d/SourceSurfaceSkia.cpp @@ -41,10 +41,10 @@ SourceSurfaceSkia::GetFormat() const } static sk_sp -MakeSkData(unsigned char* aData, const IntSize& aSize, int32_t aStride) +MakeSkData(void* aData, int32_t aHeight, size_t aStride) { CheckedInt size = aStride; - size *= aSize.height; + size *= aHeight; if (size.isValid()) { void* mem = sk_malloc_flags(size.value(), 0); if (mem) { @@ -57,13 +57,24 @@ MakeSkData(unsigned char* aData, const IntSize& aSize, int32_t aStride) return nullptr; } +static sk_sp +ReadSkImage(const sk_sp& aImage, const SkImageInfo& aInfo, size_t aStride) +{ + if (sk_sp data = MakeSkData(nullptr, aInfo.height(), aStride)) { + if (aImage->readPixels(aInfo, data->writable_data(), aStride, 0, 0, SkImage::kDisallow_CachingHint)) { + return SkImage::MakeRasterData(aInfo, data, aStride); + } + } + return nullptr; +} + bool SourceSurfaceSkia::InitFromData(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat) { - sk_sp data = MakeSkData(aData, aSize, aStride); + sk_sp data = MakeSkData(aData, aSize.height, aStride); if (!data) { return false; } @@ -125,16 +136,12 @@ SourceSurfaceSkia::InitFromImage(const sk_sp& aImage, uint8_t* SourceSurfaceSkia::GetData() { + if (!mImage) { + return nullptr; + } #ifdef USE_SKIA_GPU if (mImage->isTextureBacked()) { - sk_sp raster; - if (sk_sp data = MakeSkData(nullptr, mSize, mStride)) { - SkImageInfo info = MakeSkiaImageInfo(mSize, mFormat); - if (mImage->readPixels(info, data->writable_data(), mStride, 0, 0, SkImage::kDisallow_CachingHint)) { - raster = SkImage::MakeRasterData(info, data, mStride); - } - } - if (raster) { + if (sk_sp raster = ReadSkImage(mImage, MakeSkiaImageInfo(mSize, mFormat), mStride)) { mImage = raster; } else { gfxCriticalError() << "Failed making Skia raster image for GPU surface"; @@ -159,7 +166,7 @@ SourceSurfaceSkia::DrawTargetWillChange() // don't need to do anything for them here. SkPixmap pixmap; if (mImage->peekPixels(&pixmap)) { - mImage = SkImage::MakeRasterCopy(pixmap); + mImage = ReadSkImage(mImage, pixmap.info(), pixmap.rowBytes()); if (!mImage) { gfxCriticalError() << "Failed copying Skia raster snapshot"; } From 448b29c250fcd2dbcedab74979c5f4bae40e8a90 Mon Sep 17 00:00:00 2001 From: EKR Date: Thu, 23 Feb 2017 07:36:14 -0800 Subject: [PATCH 055/102] Bug 1342090 - Upgrade SSL_HANDSHAKE_RESULT to opt-out on release. r=bsmedberg --- toolkit/components/telemetry/Histograms.json | 1 + 1 file changed, 1 insertion(+) diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 592d2336a7b8..504b30ee19a9 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -1990,6 +1990,7 @@ "expires_in_version": "never", "kind": "enumerated", "n_values": 672, + "releaseChannelCollection": "opt-out", "description": "SSL handshake result, 0=success, 1-255=NSS error offset, 256-511=SEC error offset + 256, 512-639=NSPR error offset + 512, 640-670=PKIX error, 671=unknown err" }, "SSL_TIME_UNTIL_READY": { From 5c27030fc731a677f848c0c2b889c513e56940ff Mon Sep 17 00:00:00 2001 From: Adrien-Marie Enault Date: Thu, 23 Feb 2017 17:53:27 +0100 Subject: [PATCH 056/102] Bug 1341278 - Fix loss of filters in netmon when clicking on back from the perf tabs. r=Honza --- .../client/netmonitor/components/toolbar.js | 4 --- .../client/netmonitor/reducers/filters.js | 6 ++++- devtools/client/netmonitor/reducers/index.js | 14 +++++------ .../client/netmonitor/reducers/requests.js | 5 +++- devtools/client/netmonitor/reducers/sort.js | 5 +++- .../netmonitor/reducers/timing-markers.js | 5 +++- devtools/client/netmonitor/reducers/ui.js | 5 +++- devtools/client/netmonitor/store.js | 21 ++++++++++++++++ .../netmonitor/test/browser_net_filter-04.js | 25 +++++++++++++------ 9 files changed, 66 insertions(+), 24 deletions(-) diff --git a/devtools/client/netmonitor/components/toolbar.js b/devtools/client/netmonitor/components/toolbar.js index 71111b8ee369..826ed46f7555 100644 --- a/devtools/client/netmonitor/components/toolbar.js +++ b/devtools/client/netmonitor/components/toolbar.js @@ -56,10 +56,6 @@ const Toolbar = createClass({ toggleRequestFilterType: PropTypes.func.isRequired, }, - componentDidMount() { - Prefs.filters.forEach(this.props.toggleRequestFilterType); - }, - toggleRequestFilterType(evt) { if (evt.type === "keydown" && (evt.key !== "" || evt.key !== "Enter")) { return; diff --git a/devtools/client/netmonitor/reducers/filters.js b/devtools/client/netmonitor/reducers/filters.js index ad29c23a7f24..909bc542baae 100644 --- a/devtools/client/netmonitor/reducers/filters.js +++ b/devtools/client/netmonitor/reducers/filters.js @@ -80,4 +80,8 @@ function filters(state = new Filters(), action) { } } -module.exports = filters; +module.exports = { + FilterTypes, + Filters, + filters +}; diff --git a/devtools/client/netmonitor/reducers/index.js b/devtools/client/netmonitor/reducers/index.js index 479490c3c9e3..247fdcce7410 100644 --- a/devtools/client/netmonitor/reducers/index.js +++ b/devtools/client/netmonitor/reducers/index.js @@ -6,16 +6,16 @@ const { combineReducers } = require("devtools/client/shared/vendor/redux"); const batchingReducer = require("./batching"); -const requests = require("./requests"); -const sort = require("./sort"); -const filters = require("./filters"); -const timingMarkers = require("./timing-markers"); -const ui = require("./ui"); +const { requestsReducer } = require("./requests"); +const { sortReducer } = require("./sort"); +const { filters } = require("./filters"); +const { timingMarkers } = require("./timing-markers"); +const { ui } = require("./ui"); module.exports = batchingReducer( combineReducers({ - requests, - sort, + requests: requestsReducer, + sort: sortReducer, filters, timingMarkers, ui, diff --git a/devtools/client/netmonitor/reducers/requests.js b/devtools/client/netmonitor/reducers/requests.js index bceab1133cd4..a337d06adba3 100644 --- a/devtools/client/netmonitor/reducers/requests.js +++ b/devtools/client/netmonitor/reducers/requests.js @@ -245,4 +245,7 @@ function requestsReducer(state = new Requests(), action) { } } -module.exports = requestsReducer; +module.exports = { + Requests, + requestsReducer, +} diff --git a/devtools/client/netmonitor/reducers/sort.js b/devtools/client/netmonitor/reducers/sort.js index 33cbb64c5e2b..6e3756611bfb 100644 --- a/devtools/client/netmonitor/reducers/sort.js +++ b/devtools/client/netmonitor/reducers/sort.js @@ -30,4 +30,7 @@ function sortReducer(state = new Sort(), action) { } } -module.exports = sortReducer; +module.exports = { + Sort, + sortReducer +} diff --git a/devtools/client/netmonitor/reducers/timing-markers.js b/devtools/client/netmonitor/reducers/timing-markers.js index 4b0e92bcfd96..03915037ab28 100644 --- a/devtools/client/netmonitor/reducers/timing-markers.js +++ b/devtools/client/netmonitor/reducers/timing-markers.js @@ -51,4 +51,7 @@ function timingMarkers(state = new TimingMarkers(), action) { } } -module.exports = timingMarkers; +module.exports = { + TimingMarkers, + timingMarkers +} diff --git a/devtools/client/netmonitor/reducers/ui.js b/devtools/client/netmonitor/reducers/ui.js index 79bb9a6a7929..12e2548c9e6d 100644 --- a/devtools/client/netmonitor/reducers/ui.js +++ b/devtools/client/netmonitor/reducers/ui.js @@ -64,4 +64,7 @@ function ui(state = new UI(), action) { } } -module.exports = ui; +module.exports = { + UI, + ui +} diff --git a/devtools/client/netmonitor/store.js b/devtools/client/netmonitor/store.js index 48a94aebf33e..a15f0bb47a73 100644 --- a/devtools/client/netmonitor/store.js +++ b/devtools/client/netmonitor/store.js @@ -9,10 +9,31 @@ const { thunk } = require("devtools/client/shared/redux/middleware/thunk"); const batching = require("./middleware/batching"); const prefs = require("./middleware/prefs"); const rootReducer = require("./reducers/index"); +const { Prefs } = require("./utils/prefs"); +const { FilterTypes, Filters } = require("./reducers/filters"); +const { Requests } = require("./reducers/requests"); +const { Sort } = require("./reducers/sort"); +const { TimingMarkers } = require("./reducers/timing-markers"); +const { UI } = require("./reducers/ui"); function configureStore() { + let activeFilters = {}; + Prefs.filters.forEach((filter) => { + activeFilters[filter] = true; + }); + const initialState = { + filters: new Filters({ + requestFilterTypes: new FilterTypes(activeFilters) + }), + requests: new Requests(), + sort: new Sort(), + timingMarkers: new TimingMarkers(), + ui: new UI() + } + return createStore( rootReducer, + initialState, applyMiddleware( thunk, prefs, diff --git a/devtools/client/netmonitor/test/browser_net_filter-04.js b/devtools/client/netmonitor/test/browser_net_filter-04.js index 418a50dd66c2..590af012ae8a 100644 --- a/devtools/client/netmonitor/test/browser_net_filter-04.js +++ b/devtools/client/netmonitor/test/browser_net_filter-04.js @@ -35,16 +35,16 @@ add_task(function* () { let { monitor } = yield initNetMonitor(FILTERING_URL); info("Starting test... "); - let { gStore, windowRequire } = monitor.panelWin; + let { document, gStore, windowRequire } = monitor.panelWin; let Actions = windowRequire("devtools/client/netmonitor/actions/index"); let { Prefs } = windowRequire("devtools/client/netmonitor/utils/prefs"); gStore.dispatch(Actions.batchEnable(false)); - is(Prefs.filters.length, 1, - "Only the valid filter types should be loaded, the others should be ignored"); - is(Prefs.filters[0], "js", - "The only filter type is correct."); + is(Prefs.filters.length, 3, + "All the filter types should be loaded."); + is(Prefs.filters[0], "bogus", + "The first filter type is invalid, but loaded anyway."); let wait = waitForNetworkEvents(monitor, 9); loadCommonFrameScript(); @@ -54,9 +54,18 @@ add_task(function* () { testFilterButtons(monitor, "js"); ok(true, "Only the correct filter type was taken into consideration."); - yield teardown(monitor); + EventUtils.sendMouseEvent({ type: "click" }, + document.querySelector(".requests-list-filter-html-button")); let filters = Services.prefs.getCharPref("devtools.netmonitor.filters"); - is(filters, '["js"]', - "The bogus filter type was ignored and removed from the preferences."); + is(filters, '["html","js"]', + "The filters preferences were saved directly after the click and only with the valid."); + + EventUtils.sendMouseEvent({ type: "click" }, + document.querySelector(".requests-list-network-summary-button")); + yield wait; + + + + yield teardown(monitor); }); From 936b09324164b43fb74cc66ea059002cd57c5741 Mon Sep 17 00:00:00 2001 From: Tom Ritter Date: Wed, 22 Feb 2017 16:34:25 -0600 Subject: [PATCH 057/102] Bug 1341895 - Include most recent OTS tag allowing it to be tracked for automated release notifications. r=fredw MozReview-Commit-ID: KnZDJxWqjhI --- gfx/ots/README.mozilla | 2 +- gfx/ots/sync.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gfx/ots/README.mozilla b/gfx/ots/README.mozilla index b96826735f49..54262bc46cf6 100644 --- a/gfx/ots/README.mozilla +++ b/gfx/ots/README.mozilla @@ -2,7 +2,7 @@ This is the Sanitiser for OpenType project, from http://code.google.com/p/ots/. Our reference repository is https://github.com/khaledhosny/ots/. -Current revision: ba8417620956a920ed1f05a2f666fb6317fb10cb +Current revision: ba8417620956a920ed1f05a2f666fb6317fb10cb (5.1.0) Upstream files included: LICENSE, src/, include/ diff --git a/gfx/ots/sync.sh b/gfx/ots/sync.sh index 5a7e54b0a9d8..392e8af8208e 100755 --- a/gfx/ots/sync.sh +++ b/gfx/ots/sync.sh @@ -22,7 +22,8 @@ cp -r $1/include . echo "Updating README.mozilla..." REVISION=`cd $1; git log | head -1 | sed "s/commit //"` -sed -e "s/\(Current revision: \).*/\1$REVISION/" README.mozilla > README.tmp +VERSION=`cd $1; git describe | cut -d '-' -f 1 | sed 's/v//'` +sed -e "s/\(Current revision: \).*/\1$REVISION \($VERSION\)/" README.mozilla > README.tmp mv README.tmp README.mozilla echo "Applying ots-visibility.patch..." From 4d558d45a58a4a7b856028de5fb2bf4e55c27261 Mon Sep 17 00:00:00 2001 From: Ethan Lin Date: Thu, 23 Feb 2017 01:20:00 -0500 Subject: [PATCH 058/102] Bug 1341521 - Remove the retaining buffer machanism when setting the same canvas dimension. r=nical --- dom/canvas/CanvasRenderingContext2D.cpp | 21 ++------------------- dom/canvas/CanvasRenderingContext2D.h | 2 +- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index f1f46e4767db..e2d00e4f0078 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1906,11 +1906,7 @@ CanvasRenderingContext2D::GetHeight() const NS_IMETHODIMP CanvasRenderingContext2D::SetDimensions(int32_t aWidth, int32_t aHeight) { - bool retainBuffer = false; - if (aWidth == mWidth && aHeight == mHeight) { - retainBuffer = true; - } - ClearTarget(retainBuffer); + ClearTarget(); // Zero sized surfaces can cause problems. mZero = false; @@ -1929,23 +1925,10 @@ CanvasRenderingContext2D::SetDimensions(int32_t aWidth, int32_t aHeight) } void -CanvasRenderingContext2D::ClearTarget(bool aRetainBuffer) +CanvasRenderingContext2D::ClearTarget() { - RefPtr provider = mBufferProvider; - if (aRetainBuffer && provider) { - // We should reset the buffer data before reusing the buffer. - if (mTarget) { - mTarget->SetTransform(Matrix()); - } - ClearRect(0, 0, mWidth, mHeight); - } - Reset(); - if (aRetainBuffer) { - mBufferProvider = provider; - } - mResetLayer = true; SetInitialState(); diff --git a/dom/canvas/CanvasRenderingContext2D.h b/dom/canvas/CanvasRenderingContext2D.h index 5fdb847dfc81..8995f69e0144 100644 --- a/dom/canvas/CanvasRenderingContext2D.h +++ b/dom/canvas/CanvasRenderingContext2D.h @@ -682,7 +682,7 @@ protected: /** * Disposes an old target and prepares to lazily create a new target. */ - void ClearTarget(bool aRetainBuffer = false); + void ClearTarget(); /* * Returns the target to the buffer provider. i.e. this will queue a frame for From 18501f3c9292c5168fc337650a37c7a56cd687dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 23 Feb 2017 03:10:16 -0800 Subject: [PATCH 059/102] Bug 1341411 - Support circular module dependencies through export* per ES2017. r=jonco --- js/src/builtin/Module.js | 28 +++++++------------ js/src/builtin/ModuleObject.cpp | 2 +- js/src/jit-test/modules/empty.js | 1 + .../modules/export-star-circular-1.js | 1 + .../modules/export-star-circular-2.js | 3 ++ ...xport-star-cannot-rescue-missing-export.js | 4 +++ .../export-star-circular-dependencies.js | 6 ++++ 7 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 js/src/jit-test/modules/empty.js create mode 100644 js/src/jit-test/modules/export-star-circular-1.js create mode 100644 js/src/jit-test/modules/export-star-circular-2.js create mode 100644 js/src/jit-test/tests/modules/export-star-cannot-rescue-missing-export.js create mode 100644 js/src/jit-test/tests/modules/export-star-circular-dependencies.js diff --git a/js/src/builtin/Module.js b/js/src/builtin/Module.js index ced9630e9f1f..96ede2da8f90 100644 --- a/js/src/builtin/Module.js +++ b/js/src/builtin/Module.js @@ -65,12 +65,12 @@ function ModuleGetExportedNames(exportStarSet = []) return exportedNames; } -// 15.2.1.16.3 ResolveExport(exportName, resolveSet, exportStarSet) -function ModuleResolveExport(exportName, resolveSet = [], exportStarSet = []) +// 15.2.1.16.3 ResolveExport(exportName, resolveSet) +function ModuleResolveExport(exportName, resolveSet = []) { if (!IsObject(this) || !IsModule(this)) { return callFunction(CallModuleMethodIfWrapped, this, exportName, resolveSet, - exportStarSet, "ModuleResolveExport"); + "ModuleResolveExport"); } // Step 1 @@ -101,37 +101,28 @@ function ModuleResolveExport(exportName, resolveSet = [], exportStarSet = []) if (exportName === e.exportName) { let importedModule = CallModuleResolveHook(module, e.moduleRequest, MODULE_STATE_INSTANTIATED); - let indirectResolution = callFunction(importedModule.resolveExport, importedModule, - e.importName, resolveSet, exportStarSet); - if (indirectResolution !== null) - return indirectResolution; + return callFunction(importedModule.resolveExport, importedModule, e.importName, + resolveSet); } } // Step 6 if (exportName === "default") { // A default export cannot be provided by an export *. - ThrowSyntaxError(JSMSG_BAD_DEFAULT_EXPORT); + return null; } // Step 7 - if (callFunction(ArrayIncludes, exportStarSet, module)) - return null; - - // Step 8 - _DefineDataProperty(exportStarSet, exportStarSet.length, module); - - // Step 9 let starResolution = null; - // Step 10 + // Step 8 let starExportEntries = module.starExportEntries; for (let i = 0; i < starExportEntries.length; i++) { let e = starExportEntries[i]; let importedModule = CallModuleResolveHook(module, e.moduleRequest, MODULE_STATE_INSTANTIATED); let resolution = callFunction(importedModule.resolveExport, importedModule, - exportName, resolveSet, exportStarSet); + exportName, resolveSet); if (resolution === "ambiguous") return resolution; @@ -148,6 +139,7 @@ function ModuleResolveExport(exportName, resolveSet = [], exportStarSet = []) } } + // Step 9 return starResolution; } @@ -279,7 +271,7 @@ function ModuleDeclarationInstantiation() } } - // Step 16.iv + // Step 17.a.iii InstantiateModuleFunctionDeclarations(module); } catch (e) { RecordInstantationFailure(module); diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index dc9cf3bd884d..5f15014d30da 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -994,7 +994,7 @@ GlobalObject::initModuleProto(JSContext* cx, Handle global) static const JSFunctionSpec protoFunctions[] = { JS_SELF_HOSTED_FN("getExportedNames", "ModuleGetExportedNames", 1, 0), - JS_SELF_HOSTED_FN("resolveExport", "ModuleResolveExport", 3, 0), + JS_SELF_HOSTED_FN("resolveExport", "ModuleResolveExport", 2, 0), JS_SELF_HOSTED_FN("declarationInstantiation", "ModuleDeclarationInstantiation", 0, 0), JS_SELF_HOSTED_FN("evaluation", "ModuleEvaluation", 0, 0), JS_FS_END diff --git a/js/src/jit-test/modules/empty.js b/js/src/jit-test/modules/empty.js new file mode 100644 index 000000000000..bd9ec079d80d --- /dev/null +++ b/js/src/jit-test/modules/empty.js @@ -0,0 +1 @@ +// Intentionally empty. diff --git a/js/src/jit-test/modules/export-star-circular-1.js b/js/src/jit-test/modules/export-star-circular-1.js new file mode 100644 index 000000000000..9a0771b02411 --- /dev/null +++ b/js/src/jit-test/modules/export-star-circular-1.js @@ -0,0 +1 @@ +export* from "export-star-circular-2.js"; diff --git a/js/src/jit-test/modules/export-star-circular-2.js b/js/src/jit-test/modules/export-star-circular-2.js new file mode 100644 index 000000000000..b273d9cefa77 --- /dev/null +++ b/js/src/jit-test/modules/export-star-circular-2.js @@ -0,0 +1,3 @@ +export {y as x} from "export-star-circular-1.js"; + +export var y = "pass"; diff --git a/js/src/jit-test/tests/modules/export-star-cannot-rescue-missing-export.js b/js/src/jit-test/tests/modules/export-star-cannot-rescue-missing-export.js new file mode 100644 index 000000000000..f87829d89b8b --- /dev/null +++ b/js/src/jit-test/tests/modules/export-star-cannot-rescue-missing-export.js @@ -0,0 +1,4 @@ +// |jit-test| module; error:SyntaxError + +export { a } from "empty.js"; +export* from "module1.js"; diff --git a/js/src/jit-test/tests/modules/export-star-circular-dependencies.js b/js/src/jit-test/tests/modules/export-star-circular-dependencies.js new file mode 100644 index 000000000000..9aa612f087db --- /dev/null +++ b/js/src/jit-test/tests/modules/export-star-circular-dependencies.js @@ -0,0 +1,6 @@ +// |jit-test| module + +import { x, y } from "export-star-circular-1.js"; + +assertEq(x, "pass"); +assertEq(y, "pass"); From fe4383d39027a01146ca235fa52f2fc2e73d42c1 Mon Sep 17 00:00:00 2001 From: Jessica Jong Date: Thu, 23 Feb 2017 00:27:00 -0500 Subject: [PATCH 060/102] Bug 1341376 - Use BoolVarCache to cache preferences in HTMLInputElement. r=smaug --- dom/html/HTMLInputElement.cpp | 185 +++++++++++++++++++++++++++------- dom/html/HTMLInputElement.h | 63 ++++++++++++ 2 files changed, 210 insertions(+), 38 deletions(-) diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 94cc0c249246..3f1175c76cc2 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -544,9 +544,8 @@ GetDOMFileOrDirectoryPath(const OwningFileOrDirectory& aData, bool HTMLInputElement::ValueAsDateEnabled(JSContext* cx, JSObject* obj) { - return Preferences::GetBool("dom.experimental_forms", false) || - Preferences::GetBool("dom.forms.datepicker", false) || - Preferences::GetBool("dom.forms.datetime", false); + return IsExperimentalFormsEnabled() || IsDatePickerEnabled() || + IsInputDateTimeEnabled(); } NS_IMETHODIMP @@ -629,7 +628,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult) RefPtr dispatchChangeEventCallback = new DispatchChangeEventCallback(mInput); - if (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) && + if (IsWebkitDirPickerEnabled() && mInput->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) { ErrorResult error; GetFilesHelper* helper = mInput->GetOrCreateGetFilesHelper(true, error); @@ -830,7 +829,7 @@ HTMLInputElement::IsPopupBlocked() const nsresult HTMLInputElement::InitDatePicker() { - if (!Preferences::GetBool("dom.forms.datepicker", false)) { + if (!IsDatePickerEnabled()) { return NS_OK; } @@ -2568,10 +2567,8 @@ bool HTMLInputElement::IsExperimentalMobileType(uint8_t aType) { return (aType == NS_FORM_INPUT_DATE && - !Preferences::GetBool("dom.forms.datetime", false) && - !Preferences::GetBool("dom.forms.datepicker", false)) || - (aType == NS_FORM_INPUT_TIME && - !Preferences::GetBool("dom.forms.datetime", false)); + !IsInputDateTimeEnabled() && !IsDatePickerEnabled()) || + (aType == NS_FORM_INPUT_TIME && !IsInputDateTimeEnabled()); } bool @@ -3020,8 +3017,8 @@ HTMLInputElement::GetDisplayFileName(nsAString& aValue) const nsXPIDLString value; if (mFilesOrDirectories.IsEmpty()) { - if ((Preferences::GetBool("dom.input.dirpicker", false) && Allowdirs()) || - (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) && + if ((IsDirPickerEnabled() && Allowdirs()) || + (IsWebkitDirPickerEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) { nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES, "NoDirSelected", value); @@ -3050,7 +3047,7 @@ HTMLInputElement::SetFilesOrDirectories(const nsTArray& a { ClearGetFilesHelpers(); - if (Preferences::GetBool("dom.webkitBlink.filesystem.enabled", false)) { + if (IsWebkitFileSystemEnabled()) { HTMLInputElementBinding::ClearCachedWebkitEntriesValue(this); mEntries.Clear(); } @@ -3069,7 +3066,7 @@ HTMLInputElement::SetFiles(nsIDOMFileList* aFiles, mFilesOrDirectories.Clear(); ClearGetFilesHelpers(); - if (Preferences::GetBool("dom.webkitBlink.filesystem.enabled", false)) { + if (IsWebkitFileSystemEnabled()) { HTMLInputElementBinding::ClearCachedWebkitEntriesValue(this); mEntries.Clear(); } @@ -3092,14 +3089,14 @@ HTMLInputElement::MozSetDndFilesAndDirectories(const nsTArray dispatchChangeEventCallback = new DispatchChangeEventCallback(this); - if (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) && + if (IsWebkitDirPickerEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) { ErrorResult rv; GetFilesHelper* helper = GetOrCreateGetFilesHelper(true /* recursionFlag */, @@ -3179,8 +3176,8 @@ HTMLInputElement::GetFiles() return nullptr; } - if (Preferences::GetBool("dom.input.dirpicker", false) && Allowdirs() && - (!Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) || + if (IsDirPickerEnabled() && Allowdirs() && + (!IsWebkitDirPickerEnabled() || !HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) { return nullptr; } @@ -4392,8 +4389,8 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor) do_QueryInterface(aVisitor.mEvent->mOriginalTarget); if (target && target->FindFirstNonChromeOnlyAccessContent() == this && - ((Preferences::GetBool("dom.input.dirpicker", false) && Allowdirs()) || - (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) && + ((IsDirPickerEnabled() && Allowdirs()) || + (IsWebkitDirPickerEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)))) { type = FILE_PICKER_DIRECTORY; } @@ -5798,20 +5795,133 @@ HTMLInputElement::ParseTime(const nsAString& aValue, uint32_t* aResult) return true; } -static bool -IsDateTimeEnabled(int32_t aNewType) +/* static */ bool +HTMLInputElement::IsDateTimeTypeSupported(uint8_t aDateTimeInputType) { - return (aNewType == NS_FORM_INPUT_DATE && - (Preferences::GetBool("dom.forms.datetime", false) || - Preferences::GetBool("dom.experimental_forms", false) || - Preferences::GetBool("dom.forms.datepicker", false))) || - (aNewType == NS_FORM_INPUT_TIME && - (Preferences::GetBool("dom.forms.datetime", false) || - Preferences::GetBool("dom.experimental_forms", false))) || - ((aNewType == NS_FORM_INPUT_MONTH || - aNewType == NS_FORM_INPUT_WEEK || - aNewType == NS_FORM_INPUT_DATETIME_LOCAL) && - Preferences::GetBool("dom.forms.datetime", false)); + return (aDateTimeInputType == NS_FORM_INPUT_DATE && + (IsInputDateTimeEnabled() || IsExperimentalFormsEnabled() || + IsDatePickerEnabled())) || + (aDateTimeInputType == NS_FORM_INPUT_TIME && + (IsInputDateTimeEnabled() || IsExperimentalFormsEnabled())) || + ((aDateTimeInputType == NS_FORM_INPUT_MONTH || + aDateTimeInputType == NS_FORM_INPUT_WEEK || + aDateTimeInputType == NS_FORM_INPUT_DATETIME_LOCAL) && + IsInputDateTimeEnabled()); +} + +/* static */ bool +HTMLInputElement::IsWebkitDirPickerEnabled() +{ + static bool sWebkitDirPickerEnabled = false; + static bool sWebkitDirPickerPrefCached = false; + if (!sWebkitDirPickerPrefCached) { + sWebkitDirPickerPrefCached = true; + Preferences::AddBoolVarCache(&sWebkitDirPickerEnabled, + "dom.webkitBlink.dirPicker.enabled", + false); + } + + return sWebkitDirPickerEnabled; +} + +/* static */ bool +HTMLInputElement::IsWebkitFileSystemEnabled() +{ + static bool sWebkitFileSystemEnabled = false; + static bool sWebkitFileSystemPrefCached = false; + if (!sWebkitFileSystemPrefCached) { + sWebkitFileSystemPrefCached = true; + Preferences::AddBoolVarCache(&sWebkitFileSystemEnabled, + "dom.webkitBlink.filesystem.enabled", + false); + } + + return sWebkitFileSystemEnabled; +} + +/* static */ bool +HTMLInputElement::IsDirPickerEnabled() +{ + static bool sDirPickerEnabled = false; + static bool sDirPickerPrefCached = false; + if (!sDirPickerPrefCached) { + sDirPickerPrefCached = true; + Preferences::AddBoolVarCache(&sDirPickerEnabled, "dom.input.dirpicker", + false); + } + + return sDirPickerEnabled; +} + +/* static */ bool +HTMLInputElement::IsDatePickerEnabled() +{ + static bool sDatePickerEnabled = false; + static bool sDatePickerPrefCached = false; + if (!sDatePickerPrefCached) { + sDatePickerPrefCached = true; + Preferences::AddBoolVarCache(&sDatePickerEnabled, "dom.forms.datepicker", + false); + } + + return sDatePickerEnabled; +} + +/* static */ bool +HTMLInputElement::IsExperimentalFormsEnabled() +{ + static bool sExperimentalFormsEnabled = false; + static bool sExperimentalFormsPrefCached = false; + if (!sExperimentalFormsPrefCached) { + sExperimentalFormsPrefCached = true; + Preferences::AddBoolVarCache(&sExperimentalFormsEnabled, + "dom.experimental_forms", + false); + } + + return sExperimentalFormsEnabled; +} + +/* static */ bool +HTMLInputElement::IsInputDateTimeEnabled() +{ + static bool sDateTimeEnabled = false; + static bool sDateTimePrefCached = false; + if (!sDateTimePrefCached) { + sDateTimePrefCached = true; + Preferences::AddBoolVarCache(&sDateTimeEnabled, "dom.forms.datetime", + false); + } + + return sDateTimeEnabled; +} + +/* static */ bool +HTMLInputElement::IsInputNumberEnabled() +{ + static bool sInputNumberEnabled = false; + static bool sInputNumberPrefCached = false; + if (!sInputNumberPrefCached) { + sInputNumberPrefCached = true; + Preferences::AddBoolVarCache(&sInputNumberEnabled, "dom.forms.number", + false); + } + + return sInputNumberEnabled; +} + +/* static */ bool +HTMLInputElement::IsInputColorEnabled() +{ + static bool sInputColorEnabled = false; + static bool sInputColorPrefCached = false; + if (!sInputColorPrefCached) { + sInputColorPrefCached = true; + Preferences::AddBoolVarCache(&sInputColorEnabled, "dom.forms.color", + false); + } + + return sInputColorEnabled; } bool @@ -5829,12 +5939,11 @@ HTMLInputElement::ParseAttribute(int32_t aNamespaceID, if (success) { newType = aResult.GetEnumValue(); if ((IsExperimentalMobileType(newType) && - !Preferences::GetBool("dom.experimental_forms", false)) || - (newType == NS_FORM_INPUT_NUMBER && - !Preferences::GetBool("dom.forms.number", false)) || - (newType == NS_FORM_INPUT_COLOR && - !Preferences::GetBool("dom.forms.color", false)) || - (IsDateTimeInputType(newType) && !IsDateTimeEnabled(newType))) { + !IsExperimentalFormsEnabled()) || + (newType == NS_FORM_INPUT_NUMBER && !IsInputNumberEnabled()) || + (newType == NS_FORM_INPUT_COLOR && !IsInputColorEnabled()) || + (IsDateTimeInputType(newType) && + !IsDateTimeTypeSupported(newType))) { newType = kInputDefaultType->value; aResult.SetTo(newType, &aValue); } diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 69db31fd9612..ddf640d9719e 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -1650,6 +1650,69 @@ private: aType == NS_FORM_INPUT_TIME; } + /** + * Checks if aDateTimeInputType should be supported based on "dom.forms.datetime", + * "dom.forms.datepicker" and "dom.experimental_forms". + */ + static bool + IsDateTimeTypeSupported(uint8_t aDateTimeInputType); + + /** + * Checks preference "dom.webkitBlink.dirPicker.enabled" to determine if + * webkitdirectory should be supported. + */ + static bool + IsWebkitDirPickerEnabled(); + + /** + * Checks preference "dom.webkitBlink.filesystem.enabled" to determine if + * webkitEntries should be supported. + */ + static bool + IsWebkitFileSystemEnabled(); + + /** + * Checks preference "dom.input.dirpicker" to determine if file and directory + * entries API should be supported. + */ + static bool + IsDirPickerEnabled(); + + /** + * Checks preference "dom.forms.datepicker" to determine if date picker should + * be supported. + */ + static bool + IsDatePickerEnabled(); + + /** + * Checks preference "dom.experimental_forms" to determine if experimental + * implementation of input element should be enabled. + */ + static bool + IsExperimentalFormsEnabled(); + + /** + * Checks preference "dom.forms.datetime" to determine if input date/time + * related types should be supported. + */ + static bool + IsInputDateTimeEnabled(); + + /** + * Checks preference "dom.forms.number" to determine if input type=number + * should be supported. + */ + static bool + IsInputNumberEnabled(); + + /** + * Checks preference "dom.forms.color" to determine if date/time related + * types should be supported. + */ + static bool + IsInputColorEnabled(); + struct nsFilePickerFilter { nsFilePickerFilter() : mFilterMask(0) {} From 7002d1022afdefb620457ed4623fc681e1b8b914 Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Thu, 23 Feb 2017 21:52:33 +0100 Subject: [PATCH 061/102] Backed out changeset cd395be35318 (bug 1341278) for eslint failures. r=backout --- .../client/netmonitor/components/toolbar.js | 4 +++ .../client/netmonitor/reducers/filters.js | 6 +---- devtools/client/netmonitor/reducers/index.js | 14 +++++------ .../client/netmonitor/reducers/requests.js | 5 +--- devtools/client/netmonitor/reducers/sort.js | 5 +--- .../netmonitor/reducers/timing-markers.js | 5 +--- devtools/client/netmonitor/reducers/ui.js | 5 +--- devtools/client/netmonitor/store.js | 21 ---------------- .../netmonitor/test/browser_net_filter-04.js | 25 ++++++------------- 9 files changed, 24 insertions(+), 66 deletions(-) diff --git a/devtools/client/netmonitor/components/toolbar.js b/devtools/client/netmonitor/components/toolbar.js index 826ed46f7555..71111b8ee369 100644 --- a/devtools/client/netmonitor/components/toolbar.js +++ b/devtools/client/netmonitor/components/toolbar.js @@ -56,6 +56,10 @@ const Toolbar = createClass({ toggleRequestFilterType: PropTypes.func.isRequired, }, + componentDidMount() { + Prefs.filters.forEach(this.props.toggleRequestFilterType); + }, + toggleRequestFilterType(evt) { if (evt.type === "keydown" && (evt.key !== "" || evt.key !== "Enter")) { return; diff --git a/devtools/client/netmonitor/reducers/filters.js b/devtools/client/netmonitor/reducers/filters.js index 909bc542baae..ad29c23a7f24 100644 --- a/devtools/client/netmonitor/reducers/filters.js +++ b/devtools/client/netmonitor/reducers/filters.js @@ -80,8 +80,4 @@ function filters(state = new Filters(), action) { } } -module.exports = { - FilterTypes, - Filters, - filters -}; +module.exports = filters; diff --git a/devtools/client/netmonitor/reducers/index.js b/devtools/client/netmonitor/reducers/index.js index 247fdcce7410..479490c3c9e3 100644 --- a/devtools/client/netmonitor/reducers/index.js +++ b/devtools/client/netmonitor/reducers/index.js @@ -6,16 +6,16 @@ const { combineReducers } = require("devtools/client/shared/vendor/redux"); const batchingReducer = require("./batching"); -const { requestsReducer } = require("./requests"); -const { sortReducer } = require("./sort"); -const { filters } = require("./filters"); -const { timingMarkers } = require("./timing-markers"); -const { ui } = require("./ui"); +const requests = require("./requests"); +const sort = require("./sort"); +const filters = require("./filters"); +const timingMarkers = require("./timing-markers"); +const ui = require("./ui"); module.exports = batchingReducer( combineReducers({ - requests: requestsReducer, - sort: sortReducer, + requests, + sort, filters, timingMarkers, ui, diff --git a/devtools/client/netmonitor/reducers/requests.js b/devtools/client/netmonitor/reducers/requests.js index a337d06adba3..bceab1133cd4 100644 --- a/devtools/client/netmonitor/reducers/requests.js +++ b/devtools/client/netmonitor/reducers/requests.js @@ -245,7 +245,4 @@ function requestsReducer(state = new Requests(), action) { } } -module.exports = { - Requests, - requestsReducer, -} +module.exports = requestsReducer; diff --git a/devtools/client/netmonitor/reducers/sort.js b/devtools/client/netmonitor/reducers/sort.js index 6e3756611bfb..33cbb64c5e2b 100644 --- a/devtools/client/netmonitor/reducers/sort.js +++ b/devtools/client/netmonitor/reducers/sort.js @@ -30,7 +30,4 @@ function sortReducer(state = new Sort(), action) { } } -module.exports = { - Sort, - sortReducer -} +module.exports = sortReducer; diff --git a/devtools/client/netmonitor/reducers/timing-markers.js b/devtools/client/netmonitor/reducers/timing-markers.js index 03915037ab28..4b0e92bcfd96 100644 --- a/devtools/client/netmonitor/reducers/timing-markers.js +++ b/devtools/client/netmonitor/reducers/timing-markers.js @@ -51,7 +51,4 @@ function timingMarkers(state = new TimingMarkers(), action) { } } -module.exports = { - TimingMarkers, - timingMarkers -} +module.exports = timingMarkers; diff --git a/devtools/client/netmonitor/reducers/ui.js b/devtools/client/netmonitor/reducers/ui.js index 12e2548c9e6d..79bb9a6a7929 100644 --- a/devtools/client/netmonitor/reducers/ui.js +++ b/devtools/client/netmonitor/reducers/ui.js @@ -64,7 +64,4 @@ function ui(state = new UI(), action) { } } -module.exports = { - UI, - ui -} +module.exports = ui; diff --git a/devtools/client/netmonitor/store.js b/devtools/client/netmonitor/store.js index a15f0bb47a73..48a94aebf33e 100644 --- a/devtools/client/netmonitor/store.js +++ b/devtools/client/netmonitor/store.js @@ -9,31 +9,10 @@ const { thunk } = require("devtools/client/shared/redux/middleware/thunk"); const batching = require("./middleware/batching"); const prefs = require("./middleware/prefs"); const rootReducer = require("./reducers/index"); -const { Prefs } = require("./utils/prefs"); -const { FilterTypes, Filters } = require("./reducers/filters"); -const { Requests } = require("./reducers/requests"); -const { Sort } = require("./reducers/sort"); -const { TimingMarkers } = require("./reducers/timing-markers"); -const { UI } = require("./reducers/ui"); function configureStore() { - let activeFilters = {}; - Prefs.filters.forEach((filter) => { - activeFilters[filter] = true; - }); - const initialState = { - filters: new Filters({ - requestFilterTypes: new FilterTypes(activeFilters) - }), - requests: new Requests(), - sort: new Sort(), - timingMarkers: new TimingMarkers(), - ui: new UI() - } - return createStore( rootReducer, - initialState, applyMiddleware( thunk, prefs, diff --git a/devtools/client/netmonitor/test/browser_net_filter-04.js b/devtools/client/netmonitor/test/browser_net_filter-04.js index 590af012ae8a..418a50dd66c2 100644 --- a/devtools/client/netmonitor/test/browser_net_filter-04.js +++ b/devtools/client/netmonitor/test/browser_net_filter-04.js @@ -35,16 +35,16 @@ add_task(function* () { let { monitor } = yield initNetMonitor(FILTERING_URL); info("Starting test... "); - let { document, gStore, windowRequire } = monitor.panelWin; + let { gStore, windowRequire } = monitor.panelWin; let Actions = windowRequire("devtools/client/netmonitor/actions/index"); let { Prefs } = windowRequire("devtools/client/netmonitor/utils/prefs"); gStore.dispatch(Actions.batchEnable(false)); - is(Prefs.filters.length, 3, - "All the filter types should be loaded."); - is(Prefs.filters[0], "bogus", - "The first filter type is invalid, but loaded anyway."); + is(Prefs.filters.length, 1, + "Only the valid filter types should be loaded, the others should be ignored"); + is(Prefs.filters[0], "js", + "The only filter type is correct."); let wait = waitForNetworkEvents(monitor, 9); loadCommonFrameScript(); @@ -54,18 +54,9 @@ add_task(function* () { testFilterButtons(monitor, "js"); ok(true, "Only the correct filter type was taken into consideration."); - EventUtils.sendMouseEvent({ type: "click" }, - document.querySelector(".requests-list-filter-html-button")); + yield teardown(monitor); let filters = Services.prefs.getCharPref("devtools.netmonitor.filters"); - is(filters, '["html","js"]', - "The filters preferences were saved directly after the click and only with the valid."); - - EventUtils.sendMouseEvent({ type: "click" }, - document.querySelector(".requests-list-network-summary-button")); - yield wait; - - - - yield teardown(monitor); + is(filters, '["js"]', + "The bogus filter type was ignored and removed from the preferences."); }); From 17a4a1e15a4b6f47c24594905b37041951eb10b1 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Thu, 23 Feb 2017 16:02:50 -0500 Subject: [PATCH 062/102] bug 1341414 - reverting change to ContentPrefs.cpp to fix orange a11y tests r=orange --- dom/ipc/ContentPrefs.cpp | 155 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 152 insertions(+), 3 deletions(-) diff --git a/dom/ipc/ContentPrefs.cpp b/dom/ipc/ContentPrefs.cpp index 6dabc2ef4e7e..6106e526af62 100644 --- a/dom/ipc/ContentPrefs.cpp +++ b/dom/ipc/ContentPrefs.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ @@ -11,21 +11,70 @@ ************************************************************/ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { + "accessibility.monoaudio.enable", "accessibility.mouse_focuses_formcontrol", "accessibility.tabfocus_applies_to_xul", "app.update.channel", "browser.dom.window.dump.enabled", "browser.sessionhistory.max_entries", "browser.sessionhistory.max_total_viewers", + "content.cors.disable", + "content.cors.no_private_data", + "content.notify.backoffcount", + "content.notify.interval", + "content.notify.ontimer", + "content.sink.enable_perf_mode", + "content.sink.event_probe_rate", + "content.sink.initial_perf_time", + "content.sink.interactive_deflect_count", + "content.sink.interactive_parse_time", + "content.sink.interactive_time", + "content.sink.pending_event_mode", + "content.sink.perf_deflect_count", + "content.sink.perf_parse_time", "device.storage.prompt.testing", "device.storage.writable.name", + "dom.allow_XUL_XBL_for_file", + "dom.allow_cut_copy", + "dom.enable_frame_timing", + "dom.enable_performance", + "dom.enable_resource_timing", + "dom.event.handling-user-input-time-limit", "dom.event.touch.coalescing.enabled", + "dom.forms.autocomplete.experimental", + "dom.ipc.processPriorityManager.backgroundGracePeriodMS", + "dom.ipc.processPriorityManager.backgroundPerceivableGracePeriodMS", "dom.max_chrome_script_run_time", "dom.max_script_run_time", + "dom.mozBrowserFramesEnabled", + "dom.performance.enable_notify_performance_timing", + "dom.performance.enable_user_timing_logging", + "dom.storage.testing", + "dom.url.encode_decode_hash", + "dom.url.getters_decode_hash", "dom.use_watchdog", + "dom.vibrator.enabled", + "dom.vibrator.max_vibrate_list_len", + "dom.vibrator.max_vibrate_ms", "dom.webcomponents.enabled", "focusmanager.testmode", + "font.size.inflation.disabledInMasterProcess", + "font.size.inflation.emPerLine", + "font.size.inflation.forceEnabled", + "font.size.inflation.lineThreshold", + "font.size.inflation.mappingIntercept", + "font.size.inflation.maxRatio", + "font.size.inflation.minTwips", + "full-screen-api.allow-trusted-requests-only", + "full-screen-api.enabled", + "full-screen-api.unprefix.enabled", + "gfx.font_rendering.opentype_svg.enabled", "hangmonitor.timeout", + "html5.flushtimer.initialdelay", + "html5.flushtimer.subsequentdelay", + "html5.offmainthread", + "intl.charset.fallback.tld", + "intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition", "javascript.enabled", "javascript.options.asmjs", "javascript.options.asyncstack", @@ -53,22 +102,102 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "javascript.options.werror", "javascript.use_us_english_locale", "jsloader.reuseGlobal", + "layout.css.all-shorthand.enabled", + "layout.css.background-blend-mode.enabled", + "layout.css.background-clip-text.enabled", + "layout.css.box-decoration-break.enabled", + "layout.css.color-adjust.enabled", + "layout.css.contain.enabled", + "layout.css.control-characters.visible", + "layout.css.display-flow-root.enabled", + "layout.css.expensive-style-struct-assertions.enabled", + "layout.css.float-logical-values.enabled", + "layout.css.font-variations.enabled", + "layout.css.grid.enabled", + "layout.css.image-orientation.enabled", + "layout.css.initial-letter.enabled", + "layout.css.isolation.enabled", + "layout.css.mix-blend-mode.enabled", + "layout.css.object-fit-and-position.enabled", + "layout.css.osx-font-smoothing.enabled", + "layout.css.overflow-clip-box.enabled", + "layout.css.prefixes.animations", + "layout.css.prefixes.border-image", + "layout.css.prefixes.box-sizing", + "layout.css.prefixes.device-pixel-ratio-webkit", + "layout.css.prefixes.font-features", + "layout.css.prefixes.gradients", + "layout.css.prefixes.transforms", + "layout.css.prefixes.transitions", + "layout.css.prefixes.webkit", + "layout.css.scope-pseudo.enabled", + "layout.css.scroll-behavior.property-enabled", + "layout.css.scroll-snap.enabled", "layout.css.servo.enabled", + "layout.css.shape-outside.enabled", + "layout.css.text-align-unsafe-value.enabled", + "layout.css.text-combine-upright-digits.enabled", + "layout.css.text-combine-upright.enabled", + "layout.css.touch_action.enabled", "layout.css.unprefixing-service.enabled", "layout.css.unprefixing-service.globally-whitelisted", "layout.css.unprefixing-service.include-test-domains", + "layout.css.variables.enabled", + "layout.css.visited_links_enabled", + "layout.idle_period.required_quiescent_frames", + "layout.idle_period.time_limit", + "layout.interruptible-reflow.enabled", "mathml.disabled", + "media.apple.forcevda", + "media.clearkey.persistent-license.enabled", "media.cubeb_latency_msg_frames", "media.cubeb_latency_playback_ms", "media.decoder-doctor.wmf-disabled-is-failure", + "media.decoder.fuzzing.dont-delay-inputexhausted", + "media.decoder.fuzzing.enabled", + "media.decoder.fuzzing.video-output-minimum-interval-ms", + "media.decoder.limit", + "media.decoder.recycle.enabled", + "media.dormant-on-pause-timeout-ms", + "media.eme.audio.blank", + "media.eme.enabled", + "media.eme.video.blank", + "media.ffmpeg.enabled", + "media.ffvpx.enabled", "media.ffvpx.low-latency.enabled", + "media.flac.enabled", + "media.forcestereo.enabled", "media.gmp.async-shutdown-timeout", + "media.gmp.decoder.aac", + "media.gmp.decoder.enabled", + "media.gmp.decoder.h264", + "media.gmp.insecure.allow", + "media.gpu-process-decoder", + "media.libavcodec.allow-obsolete", + "media.num-decode-threads", + "media.ogg.enabled", + "media.ogg.flac.enabled", + "media.resampling.enabled", + "media.resampling.rate", + "media.ruin-av-sync.enabled", + "media.rust.test_mode", + "media.suspend-bkgnd-video.delay-ms", + "media.suspend-bkgnd-video.enabled", + "media.use-blank-decoder", + "media.video_stats.enabled", "media.volume_scale", + "media.webspeech.recognition.enable", + "media.webspeech.recognition.force_enable", + "media.webspeech.synth.force_global_queue", + "media.webspeech.test.enable", + "media.webspeech.test.fake_fsm_events", + "media.webspeech.test.fake_recognition_service", "media.wmf.allow-unsupported-resolutions", "media.wmf.decoder.thread-count", "media.wmf.enabled", "media.wmf.skip-blacklist", "media.wmf.vp9.enabled", + "memory.free_dirty_pages", "memory.low_commit_space_threshold_mb", "memory.low_memory_notification_interval_ms", "memory.low_physical_memory_threshold_mb", @@ -80,16 +209,20 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "network.buffer.cache.count", "network.buffer.cache.size", "network.captive-portal-service.enabled", + "network.cookie.cookieBehavior", + "network.cookie.lifetimePolicy", "network.dns.disablePrefetch", "network.dns.disablePrefetchFromHTTPS", "network.jar.block-remote-files", "network.loadinfo.skip_type_assertion", "network.notify.changed", + "network.offline-mirrors-connectivity", "network.protocol-handler.external.jar", "network.proxy.type", "network.security.ports.banned", "network.security.ports.banned.override", "network.standard-url.enable-rust", + "network.standard-url.max-length", "network.sts.max_time_for_events_between_two_polls", "network.sts.max_time_for_pr_close_during_shutdown", "network.tcp.keepalive.enabled", @@ -97,6 +230,12 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "network.tcp.keepalive.probe_count", "network.tcp.keepalive.retry_interval", "network.tcp.sendbuffer", + "nglayout.debug.invalidation", + "privacy.donottrackheader.enabled", + "privacy.firstparty.isolate", + "privacy.firstparty.isolate.restrict_opener_access", + "privacy.resistFingerprinting", + "security.data_uri.inherit_security_context", "security.fileuri.strict_origin_policy", "security.sandbox.content.level", "security.sandbox.content.tempDirSuffix", @@ -105,8 +244,14 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "security.sandbox.windows.log", "security.sandbox.windows.log.stackTraceDepth", "shutdown.watchdog.timeoutSecs", + "signed.applets.codebase_principal_support", "svg.disabled", + "svg.display-lists.hit-testing.enabled", + "svg.display-lists.painting.enabled", + "svg.new-getBBox.enabled", + "svg.paint-order.enabled", "svg.path-caching.enabled", + "svg.transform-box.enabled", "toolkit.asyncshutdown.crash_timeout", "toolkit.asyncshutdown.log", "toolkit.osfile.log", @@ -119,7 +264,11 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "toolkit.telemetry.minSubsessionLength", "toolkit.telemetry.scheduler.idleTickInterval", "toolkit.telemetry.scheduler.tickInterval", - "toolkit.telemetry.unified"}; + "toolkit.telemetry.unified", + "ui.key.menuAccessKeyFocuses", + "ui.popup.disable_autohide", + "ui.use_activity_cursor", + "view_source.editor.external"}; const char** mozilla::dom::ContentPrefs::GetContentPrefs(size_t* aCount) { From ae25436b1abd51ca8b385d0ae69438339626ad98 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Thu, 23 Feb 2017 08:13:33 -0700 Subject: [PATCH 063/102] Bug 1341006 - Use a sparse representation for atom mark bitmaps in zones, r=jonco. --- js/src/ds/Bitmap.cpp | 130 ++++++++++++++++++++++++++++++++++++++ js/src/ds/Bitmap.h | 103 ++++++++++++++++++++++++++++++ js/src/gc/AtomMarking.cpp | 91 +++++--------------------- js/src/gc/AtomMarking.h | 9 ++- js/src/gc/Zone.cpp | 3 +- js/src/gc/Zone.h | 4 +- js/src/jsgc.cpp | 2 +- js/src/moz.build | 1 + 8 files changed, 259 insertions(+), 84 deletions(-) create mode 100644 js/src/ds/Bitmap.cpp create mode 100644 js/src/ds/Bitmap.h diff --git a/js/src/ds/Bitmap.cpp b/js/src/ds/Bitmap.cpp new file mode 100644 index 000000000000..4cc698c3e375 --- /dev/null +++ b/js/src/ds/Bitmap.cpp @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * 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 "ds/Bitmap.h" + +using namespace js; + +SparseBitmap::~SparseBitmap() +{ + if (data.initialized()) { + for (Data::Range r(data.all()); !r.empty(); r.popFront()) + js_delete(r.front().value()); + } +} + +size_t +SparseBitmap::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) +{ + size_t size = data.sizeOfExcludingThis(mallocSizeOf); + for (Data::Range r(data.all()); !r.empty(); r.popFront()) + size += mallocSizeOf(r.front().value()); + return size; +} + +SparseBitmap::BitBlock& +SparseBitmap::getOrCreateBlock(size_t blockId) +{ + Data::AddPtr p = data.lookupForAdd(blockId); + if (!p) { + AutoEnterOOMUnsafeRegion oomUnsafe; + BitBlock* block = js_new(); + if (!block || !data.add(p, blockId, block)) + oomUnsafe.crash("Bitmap OOM"); + PodZero(block); + } + return *p->value(); +} + +void +SparseBitmap::setBit(size_t bit) +{ + size_t word = bit / JS_BITS_PER_WORD; + size_t blockWord = blockStartWord(word); + BitBlock& block = getOrCreateBlock(blockWord / WordsInBlock); + block[word - blockWord] |= uintptr_t(1) << (bit % JS_BITS_PER_WORD); +} + +SparseBitmap::BitBlock* +SparseBitmap::getBlock(size_t blockId) const +{ + Data::Ptr p = data.lookup(blockId); + return p ? p->value() : nullptr; +} + +bool +SparseBitmap::getBit(size_t bit) const +{ + size_t word = bit / JS_BITS_PER_WORD; + size_t blockWord = blockStartWord(word); + + BitBlock* block = getBlock(blockWord / WordsInBlock); + if (block) + return (*block)[word - blockWord] & (uintptr_t(1) << (bit % JS_BITS_PER_WORD)); + return false; +} + +void +SparseBitmap::bitwiseAndWith(const DenseBitmap& other) +{ + for (Data::Enum e(data); !e.empty(); e.popFront()) { + BitBlock& block = *e.front().value(); + size_t blockWord = e.front().key() * WordsInBlock; + bool anySet = false; + size_t numWords = wordIntersectCount(blockWord, other); + for (size_t i = 0; i < numWords; i++) { + block[i] &= other.word(blockWord + i); + anySet |= !!block[i]; + } + if (!anySet) { + js_delete(&block); + e.removeFront(); + } + } +} + +void +SparseBitmap::bitwiseOrWith(const SparseBitmap& other) +{ + for (Data::Range r(other.data.all()); !r.empty(); r.popFront()) { + const BitBlock& otherBlock = *r.front().value(); + BitBlock& block = getOrCreateBlock(r.front().key()); + for (size_t i = 0; i < WordsInBlock; i++) + block[i] |= otherBlock[i]; + } +} + +void +SparseBitmap::bitwiseOrInto(DenseBitmap& other) const +{ + for (Data::Range r(data.all()); !r.empty(); r.popFront()) { + BitBlock& block = *r.front().value(); + size_t blockWord = r.front().key() * WordsInBlock; + size_t numWords = wordIntersectCount(blockWord, other); +#ifdef DEBUG + // Any words out of range in other should be zero in this bitmap. + for (size_t i = numWords; i < WordsInBlock; i++) + MOZ_ASSERT(!block[i]); +#endif + for (size_t i = 0; i < numWords; i++) + other.word(blockWord + i) |= block[i]; + } +} + +void +SparseBitmap::bitwiseOrRangeInto(size_t wordStart, size_t numWords, uintptr_t* target) const +{ + size_t blockWord = blockStartWord(wordStart); + + // We only support using a single bit block in this API. + MOZ_ASSERT(numWords && (blockWord == blockStartWord(wordStart + numWords - 1))); + + BitBlock* block = getBlock(blockWord / WordsInBlock); + if (block) { + for (size_t i = 0; i < numWords; i++) + target[i] |= (*block)[wordStart - blockWord + i]; + } +} diff --git a/js/src/ds/Bitmap.h b/js/src/ds/Bitmap.h new file mode 100644 index 000000000000..2b0239e8b66a --- /dev/null +++ b/js/src/ds/Bitmap.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * 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 ds_Bitmap_h +#define ds_Bitmap_h + +#include + +#include "jsalloc.h" + +#include "js/HashTable.h" +#include "js/Vector.h" + +// This file provides two classes for representing bitmaps. +// +// DenseBitmap is an array of words of bits, with size linear in the maximum +// bit which has been set on it. +// +// SparseBitmap provides a reasonably simple, reasonably efficient (in time and +// space) implementation of a sparse bitmap. The basic representation is a hash +// table whose entries are fixed length malloc'ed blocks of bits. + +namespace js { + +class DenseBitmap +{ + typedef Vector Data; + Data data; + + public: + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) { + return data.sizeOfExcludingThis(mallocSizeOf); + } + + bool ensureSpace(size_t numWords) { + MOZ_ASSERT(data.empty()); + return data.appendN(0, numWords); + } + + size_t numWords() const { return data.length(); } + uintptr_t word(size_t i) const { return data[i]; } + uintptr_t& word(size_t i) { return data[i]; } + + void copyBitsFrom(size_t wordStart, size_t numWords, uintptr_t* source) { + MOZ_ASSERT(wordStart + numWords <= data.length()); + mozilla::PodCopy(&data[wordStart], source, numWords); + } + + void bitwiseOrRangeInto(size_t wordStart, size_t numWords, uintptr_t* target) const { + for (size_t i = 0; i < numWords; i++) + target[i] |= data[wordStart + i]; + } +}; + +class SparseBitmap +{ + // The number of words of bits to use for each block mainly affects the + // memory usage of the bitmap. To minimize overhead, bitmaps which are + // expected to be fairly dense should have a large block size, and bitmaps + // which are expected to be very sparse should have a small block size. + static const size_t WordsInBlock = 4096 / sizeof(uintptr_t); + + typedef mozilla::Array BitBlock; + typedef HashMap, SystemAllocPolicy> Data; + Data data; + + static size_t blockStartWord(size_t word) { + return word & ~(WordsInBlock - 1); + } + + // Return the number of words in a BitBlock starting at |blockWord| which + // are in |other|. + static size_t wordIntersectCount(size_t blockWord, const DenseBitmap& other) { + long count = other.numWords() - blockWord; + return std::min((size_t)WordsInBlock, std::max(count, 0)); + } + + BitBlock* getBlock(size_t blockId) const; + BitBlock& getOrCreateBlock(size_t blockId); + + public: + bool init() { return data.init(); } + ~SparseBitmap(); + + size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf); + + void setBit(size_t bit); + bool getBit(size_t bit) const; + + void bitwiseAndWith(const DenseBitmap& other); + void bitwiseOrWith(const SparseBitmap& other); + void bitwiseOrInto(DenseBitmap& other) const; + + // Currently, this API only supports a range of words that is in a single bit block. + void bitwiseOrRangeInto(size_t wordStart, size_t numWords, uintptr_t* target) const; +}; + +} // namespace js + +#endif // ds_Bitmap_h diff --git a/js/src/gc/AtomMarking.cpp b/js/src/gc/AtomMarking.cpp index ae01e2a8bb8c..affb78d4c264 100644 --- a/js/src/gc/AtomMarking.cpp +++ b/js/src/gc/AtomMarking.cpp @@ -44,29 +44,6 @@ namespace gc { // bits for space between things being unused when things are larger than a // single Cell. -static inline void -SetBit(uintptr_t* bitmap, size_t bit) -{ - bitmap[bit / JS_BITS_PER_WORD] |= uintptr_t(1) << (bit % JS_BITS_PER_WORD); -} - -static inline bool -GetBit(uintptr_t* bitmap, size_t bit) -{ - return bitmap[bit / JS_BITS_PER_WORD] & (uintptr_t(1) << (bit % JS_BITS_PER_WORD)); -} - -static inline bool -EnsureBitmapLength(AtomMarkingRuntime::Bitmap& bitmap, size_t nwords) -{ - if (nwords > bitmap.length()) { - size_t needed = nwords - bitmap.length(); - if (needed) - return bitmap.appendN(0, needed); - } - return true; -} - void AtomMarkingRuntime::registerArena(Arena* arena) { @@ -98,12 +75,11 @@ AtomMarkingRuntime::unregisterArena(Arena* arena) } bool -AtomMarkingRuntime::computeBitmapFromChunkMarkBits(JSRuntime* runtime, Bitmap& bitmap) +AtomMarkingRuntime::computeBitmapFromChunkMarkBits(JSRuntime* runtime, DenseBitmap& bitmap) { MOZ_ASSERT(runtime->currentThreadHasExclusiveAccess()); - MOZ_ASSERT(bitmap.empty()); - if (!EnsureBitmapLength(bitmap, allocatedWords)) + if (!bitmap.ensureSpace(allocatedWords)) return false; Zone* atomsZone = runtime->unsafeAtomsCompartment()->zone(); @@ -111,8 +87,7 @@ AtomMarkingRuntime::computeBitmapFromChunkMarkBits(JSRuntime* runtime, Bitmap& b for (ArenaIter aiter(atomsZone, thingKind); !aiter.done(); aiter.next()) { Arena* arena = aiter.get(); uintptr_t* chunkWords = arena->chunk()->bitmap.arenaBits(arena); - uintptr_t* bitmapWords = &bitmap[arena->atomBitmapStart()]; - mozilla::PodCopy(bitmapWords, chunkWords, ArenaBitmapWords); + bitmap.copyBitsFrom(arena->atomBitmapStart(), ArenaBitmapWords, chunkWords); } } @@ -120,25 +95,21 @@ AtomMarkingRuntime::computeBitmapFromChunkMarkBits(JSRuntime* runtime, Bitmap& b } void -AtomMarkingRuntime::updateZoneBitmap(Zone* zone, const Bitmap& bitmap) +AtomMarkingRuntime::updateZoneBitmap(Zone* zone, const DenseBitmap& bitmap) { if (zone->isAtomsZone()) return; - // |bitmap| was produced by computeBitmapFromChunkMarkBits, so it should - // have the maximum possible size. - MOZ_ASSERT(zone->markedAtoms().length() <= bitmap.length()); - // Take the bitwise and between the two mark bitmaps to get the best new // overapproximation we can. |bitmap| might include bits that are not in // the zone's mark bitmap, if additional zones were collected by the GC. - for (size_t i = 0; i < zone->markedAtoms().length(); i++) - zone->markedAtoms()[i] &= bitmap[i]; + zone->markedAtoms().bitwiseAndWith(bitmap); } // Set any bits in the chunk mark bitmaps for atoms which are marked in bitmap. +template static void -AddBitmapToChunkMarkBits(JSRuntime* runtime, AtomMarkingRuntime::Bitmap& bitmap) +AddBitmapToChunkMarkBits(JSRuntime* runtime, Bitmap& bitmap) { // Make sure that by copying the mark bits for one arena in word sizes we // do not affect the mark bits for other arenas. @@ -150,16 +121,7 @@ AddBitmapToChunkMarkBits(JSRuntime* runtime, AtomMarkingRuntime::Bitmap& bitmap) for (ArenaIter aiter(atomsZone, thingKind); !aiter.done(); aiter.next()) { Arena* arena = aiter.get(); uintptr_t* chunkWords = arena->chunk()->bitmap.arenaBits(arena); - - // The bitmap might not be long enough, in which case remaining - // bits are implicitly zero. - if (bitmap.length() <= arena->atomBitmapStart()) - continue; - MOZ_ASSERT(bitmap.length() >= arena->atomBitmapStart() + ArenaBitmapWords); - - uintptr_t* bitmapWords = &bitmap[arena->atomBitmapStart()]; - for (size_t i = 0; i < ArenaBitmapWords; i++) - chunkWords[i] |= bitmapWords[i]; + bitmap.bitwiseOrRangeInto(arena->atomBitmapStart(), ArenaBitmapWords, chunkWords); } } } @@ -172,17 +134,14 @@ AtomMarkingRuntime::updateChunkMarkBits(JSRuntime* runtime) // Try to compute a simple union of the zone atom bitmaps before updating // the chunk mark bitmaps. If this allocation fails then fall back to // updating the chunk mark bitmaps separately for each zone. - Bitmap markedUnion; - if (EnsureBitmapLength(markedUnion, allocatedWords)) { + DenseBitmap markedUnion; + if (markedUnion.ensureSpace(allocatedWords)) { for (ZonesIter zone(runtime, SkipAtoms); !zone.done(); zone.next()) { // We only need to update the chunk mark bits for zones which were // not collected in the current GC. Atoms which are referenced by // collected zones have already been marked. - if (!zone->isCollectingFromAnyThread()) { - MOZ_ASSERT(zone->markedAtoms().length() <= allocatedWords); - for (size_t i = 0; i < zone->markedAtoms().length(); i++) - markedUnion[i] |= zone->markedAtoms()[i]; - } + if (!zone->isCollectingFromAnyThread()) + zone->markedAtoms().bitwiseOrInto(markedUnion); } AddBitmapToChunkMarkBits(runtime, markedUnion); } else { @@ -225,14 +184,9 @@ AtomMarkingRuntime::markAtom(JSContext* cx, TenuredCell* thing) return; size_t bit = GetAtomBit(thing); + MOZ_ASSERT(bit / JS_BITS_PER_WORD < allocatedWords); - { - AutoEnterOOMUnsafeRegion oomUnsafe; - if (!EnsureBitmapLength(cx->zone()->markedAtoms(), allocatedWords)) - oomUnsafe.crash("Atom bitmap OOM"); - } - - SetBit(cx->zone()->markedAtoms().begin(), bit); + cx->zone()->markedAtoms().setBit(bit); if (!cx->helperThread()) { // Trigger a read barrier on the atom, in case there is an incremental @@ -272,18 +226,7 @@ void AtomMarkingRuntime::adoptMarkedAtoms(Zone* target, Zone* source) { MOZ_ASSERT(target->runtimeFromAnyThread()->currentThreadHasExclusiveAccess()); - - Bitmap* targetBitmap = &target->markedAtoms(); - Bitmap* sourceBitmap = &source->markedAtoms(); - if (targetBitmap->length() < sourceBitmap->length()) - std::swap(targetBitmap, sourceBitmap); - for (size_t i = 0; i < sourceBitmap->length(); i++) - (*targetBitmap)[i] |= (*sourceBitmap)[i]; - - if (targetBitmap != &target->markedAtoms()) - target->markedAtoms() = Move(source->markedAtoms()); - else - source->markedAtoms().clear(); + target->markedAtoms().bitwiseOrWith(source->markedAtoms()); } #ifdef DEBUG @@ -309,9 +252,7 @@ AtomMarkingRuntime::atomIsMarked(Zone* zone, Cell* thingArg) } size_t bit = GetAtomBit(thing); - if (bit >= zone->markedAtoms().length() * JS_BITS_PER_WORD) - return false; - return GetBit(zone->markedAtoms().begin(), bit); + return zone->markedAtoms().getBit(bit); } bool diff --git a/js/src/gc/AtomMarking.h b/js/src/gc/AtomMarking.h index c1cccd7f4067..f0d24b9b4547 100644 --- a/js/src/gc/AtomMarking.h +++ b/js/src/gc/AtomMarking.h @@ -8,6 +8,7 @@ #define gc_AtomMarking_h #include "NamespaceImports.h" +#include "ds/Bitmap.h" #include "gc/Heap.h" #include "threading/ProtectedData.h" @@ -21,13 +22,11 @@ class AtomMarkingRuntime // Unused arena atom bitmap indexes. Protected by the GC lock. js::ExclusiveAccessLockOrGCTaskData> freeArenaIndexes; + public: // The extent of all allocated and free words in atom mark bitmaps. // This monotonically increases and may be read from without locking. mozilla::Atomic allocatedWords; - public: - typedef Vector Bitmap; - AtomMarkingRuntime() : allocatedWords(0) {} @@ -41,11 +40,11 @@ class AtomMarkingRuntime // Fill |bitmap| with an atom marking bitmap based on the things that are // currently marked in the chunks used by atoms zone arenas. This returns // false on an allocation failure (but does not report an exception). - bool computeBitmapFromChunkMarkBits(JSRuntime* runtime, Bitmap& bitmap); + bool computeBitmapFromChunkMarkBits(JSRuntime* runtime, DenseBitmap& bitmap); // Update the atom marking bitmap in |zone| according to another // overapproximation of the reachable atoms in |bitmap|. - void updateZoneBitmap(Zone* zone, const Bitmap& bitmap); + void updateZoneBitmap(Zone* zone, const DenseBitmap& bitmap); // Set any bits in the chunk mark bitmaps for atoms which are marked in any // zone in the runtime. diff --git a/js/src/gc/Zone.cpp b/js/src/gc/Zone.cpp index 556bf7be5c1d..f815442fd867 100644 --- a/js/src/gc/Zone.cpp +++ b/js/src/gc/Zone.cpp @@ -91,7 +91,8 @@ bool Zone::init(bool isSystemArg) return uniqueIds().init() && gcZoneGroupEdges().init() && gcWeakKeys().init() && - typeDescrObjects().init(); + typeDescrObjects().init() && + markedAtoms().init(); } void diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index 6c61ec332cc9..15f234a00d5c 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -425,9 +425,9 @@ struct Zone : public JS::shadow::Zone, private: // Bitmap of atoms marked by this zone. - js::ZoneGroupOrGCTaskData markedAtoms_; + js::ZoneGroupOrGCTaskData markedAtoms_; public: - js::gc::AtomMarkingRuntime::Bitmap& markedAtoms() { return markedAtoms_.ref(); } + js::SparseBitmap& markedAtoms() { return markedAtoms_.ref(); } // Track heap usage under this Zone. js::gc::HeapUsage usage; diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 35ebd13e1e91..c1121371edd1 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -4897,7 +4897,7 @@ MAKE_GC_SWEEP_TASK(SweepMiscTask); /* virtual */ void SweepAtomsTask::run() { - AtomMarkingRuntime::Bitmap marked; + DenseBitmap marked; if (runtime()->gc.atomMarking.computeBitmapFromChunkMarkBits(runtime(), marked)) { for (GCZonesIter zone(runtime()); !zone.done(); zone.next()) runtime()->gc.atomMarking.updateZoneBitmap(zone, marked); diff --git a/js/src/moz.build b/js/src/moz.build index 2cd3d6bfb7c8..8b11432f99bc 100644 --- a/js/src/moz.build +++ b/js/src/moz.build @@ -176,6 +176,7 @@ UNIFIED_SOURCES += [ 'builtin/WeakMapObject.cpp', 'builtin/WeakSetObject.cpp', 'devtools/sharkctl.cpp', + 'ds/Bitmap.cpp', 'ds/LifoAlloc.cpp', 'ds/MemoryProtectionExceptionHandler.cpp', 'frontend/BytecodeCompiler.cpp', From 637007e153d9d6336ea62f1b27cda5d2dea68d4b Mon Sep 17 00:00:00 2001 From: David Keeler Date: Wed, 22 Feb 2017 15:07:05 -0800 Subject: [PATCH 064/102] bug 1341905 - double-check that uses of CERT_LIST_* are safe in PSM r=jcj MozReview-Commit-ID: BhGHd9xUUbP --- security/apps/AppSignatureVerification.cpp | 24 ++++++++++++++----- security/certverifier/CertVerifier.cpp | 5 ++-- .../manager/ssl/ContentSignatureVerifier.cpp | 2 +- .../manager/ssl/SSLServerCertVerification.cpp | 6 ++--- .../manager/ssl/tests/unit/test_cert_trust.js | 10 ++++++++ 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/security/apps/AppSignatureVerification.cpp b/security/apps/AppSignatureVerification.cpp index bd2d13dc6149..daef5a7ac499 100644 --- a/security/apps/AppSignatureVerification.cpp +++ b/security/apps/AppSignatureVerification.cpp @@ -864,9 +864,13 @@ OpenSignedAppFile(AppTrustedRoot aTrustedRoot, nsIFile* aJarFile, // Return the signer's certificate to the reader if they want it. // XXX: We should return an nsIX509CertList with the whole validated chain. if (aSignerCert) { - MOZ_ASSERT(CERT_LIST_HEAD(builtChain)); + CERTCertListNode* signerCertNode = CERT_LIST_HEAD(builtChain); + if (!signerCertNode || CERT_LIST_END(signerCertNode, builtChain) || + !signerCertNode->cert) { + return NS_ERROR_FAILURE; + } nsCOMPtr signerCert = - nsNSSCertificate::Create(CERT_LIST_HEAD(builtChain)->cert); + nsNSSCertificate::Create(signerCertNode->cert); NS_ENSURE_TRUE(signerCert, NS_ERROR_OUT_OF_MEMORY); signerCert.forget(aSignerCert); } @@ -938,9 +942,13 @@ VerifySignedManifest(AppTrustedRoot aTrustedRoot, // Return the signer's certificate to the reader if they want it. if (aSignerCert) { - MOZ_ASSERT(CERT_LIST_HEAD(builtChain)); + CERTCertListNode* signerCertNode = CERT_LIST_HEAD(builtChain); + if (!signerCertNode || CERT_LIST_END(signerCertNode, builtChain) || + !signerCertNode->cert) { + return NS_ERROR_FAILURE; + } nsCOMPtr signerCert = - nsNSSCertificate::Create(CERT_LIST_HEAD(builtChain)->cert); + nsNSSCertificate::Create(signerCertNode->cert); if (NS_WARN_IF(!signerCert)) { return NS_ERROR_OUT_OF_MEMORY; } @@ -1491,9 +1499,13 @@ VerifySignedDirectory(AppTrustedRoot aTrustedRoot, // Return the signer's certificate to the reader if they want it. // XXX: We should return an nsIX509CertList with the whole validated chain. if (aSignerCert) { - MOZ_ASSERT(CERT_LIST_HEAD(builtChain)); + CERTCertListNode* signerCertNode = CERT_LIST_HEAD(builtChain); + if (!signerCertNode || CERT_LIST_END(signerCertNode, builtChain) || + !signerCertNode->cert) { + return NS_ERROR_FAILURE; + } nsCOMPtr signerCert = - nsNSSCertificate::Create(CERT_LIST_HEAD(builtChain)->cert); + nsNSSCertificate::Create(signerCertNode->cert); NS_ENSURE_TRUE(signerCert, NS_ERROR_OUT_OF_MEMORY); signerCert.forget(aSignerCert); } diff --git a/security/certverifier/CertVerifier.cpp b/security/certverifier/CertVerifier.cpp index 87bbefa5cafb..8d5cc05d3c7f 100644 --- a/security/certverifier/CertVerifier.cpp +++ b/security/certverifier/CertVerifier.cpp @@ -286,12 +286,13 @@ CertVerifier::VerifyCertificateTransparencyPolicy( } CERTCertListNode* endEntityNode = CERT_LIST_HEAD(builtChain); - if (!endEntityNode) { + if (!endEntityNode || CERT_LIST_END(endEntityNode, builtChain)) { return Result::FATAL_ERROR_INVALID_ARGS; } CERTCertListNode* issuerNode = CERT_LIST_NEXT(endEntityNode); - if (!issuerNode) { + if (!issuerNode || CERT_LIST_END(issuerNode, builtChain)) { // Issuer certificate is required for SCT verification. + // TODO(bug 1294580): change this to Result::FATAL_ERROR_INVALID_ARGS return Success; } diff --git a/security/manager/ssl/ContentSignatureVerifier.cpp b/security/manager/ssl/ContentSignatureVerifier.cpp index 8ceaff5760e8..129bb153946b 100644 --- a/security/manager/ssl/ContentSignatureVerifier.cpp +++ b/security/manager/ssl/ContentSignatureVerifier.cpp @@ -158,7 +158,7 @@ ContentSignatureVerifier::CreateContextInternal(const nsACString& aData, } CERTCertListNode* node = CERT_LIST_HEAD(certCertList.get()); - if (!node || !node->cert) { + if (!node || CERT_LIST_END(node, certCertList.get()) || !node->cert) { return NS_ERROR_FAILURE; } diff --git a/security/manager/ssl/SSLServerCertVerification.cpp b/security/manager/ssl/SSLServerCertVerification.cpp index 419cab4086fb..71c112472804 100644 --- a/security/manager/ssl/SSLServerCertVerification.cpp +++ b/security/manager/ssl/SSLServerCertVerification.cpp @@ -1190,12 +1190,12 @@ void GatherEndEntityTelemetry(const UniqueCERTCertList& certList) { CERTCertListNode* endEntityNode = CERT_LIST_HEAD(certList); - MOZ_ASSERT(endEntityNode); - if (!endEntityNode) { + MOZ_ASSERT(endEntityNode && !CERT_LIST_END(endEntityNode, certList)); + if (!endEntityNode || CERT_LIST_END(endEntityNode, certList)) { return; } - CERTCertificate * endEntityCert = endEntityNode->cert; + CERTCertificate* endEntityCert = endEntityNode->cert; MOZ_ASSERT(endEntityCert); if (!endEntityCert) { return; diff --git a/security/manager/ssl/tests/unit/test_cert_trust.js b/security/manager/ssl/tests/unit/test_cert_trust.js index 21f93080a6c9..e33dae0234ce 100644 --- a/security/manager/ssl/tests/unit/test_cert_trust.js +++ b/security/manager/ssl/tests/unit/test_cert_trust.js @@ -204,4 +204,14 @@ function run_test() { setup_basic_trusts(ca_cert, int_cert); test_ca_distrust(ee_cert, int_cert, false); + + // Reset trust to default ("inherit trust") + setCertTrust(ca_cert, ",,"); + setCertTrust(int_cert, ",,"); + + // It turns out that if an end-entity certificate is manually trusted, it can + // be the root of its own verified chain. This will be removed in bug 1294580. + setCertTrust(ee_cert, "C,,"); + checkCertErrorGeneric(certdb, ee_cert, PRErrorCodeSuccess, + certificateUsageSSLServer); } From e822eea590dccc1afa2d80c1a60dc87aeadbddd0 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 23 Feb 2017 13:56:10 -0800 Subject: [PATCH 065/102] Bug 1322273: Cut wrappers that point out of a browser compartment when nuking it. r=bholley MozReview-Commit-ID: FLS3xRgih2u --- dom/base/nsGlobalWindow.cpp | 15 ++--- js/src/jsfriendapi.h | 10 ++- js/src/proxy/CrossCompartmentWrapper.cpp | 17 ++++-- js/xpconnect/src/XPCComponents.cpp | 8 +-- js/xpconnect/src/XPCJSContext.cpp | 31 ++++++++++ js/xpconnect/src/xpcpublic.h | 3 + js/xpconnect/tests/mochitest/mochitest.ini | 1 + .../mochitest/test_nukeContentWindow.html | 61 +++++++++++++++++++ 8 files changed, 121 insertions(+), 25 deletions(-) create mode 100644 js/xpconnect/tests/mochitest/test_nukeContentWindow.html diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 5f867545f177..3a9887d6bde9 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -9406,21 +9406,16 @@ public: nsAutoString addonId; if (NS_SUCCEEDED(pc->GetAddonId(addonId)) && !addonId.IsEmpty()) { // We want to nuke all references to the add-on compartment. - js::NukeCrossCompartmentWrappers(cx, js::AllCompartments(), - js::SingleCompartment(cpt), - win->IsInnerWindow() ? js::DontNukeWindowReferences - : js::NukeWindowReferences); - - // Now mark the compartment as nuked and non-scriptable. - auto compartmentPrivate = xpc::CompartmentPrivate::Get(cpt); - compartmentPrivate->wasNuked = true; - compartmentPrivate->scriptability.Block(); + xpc::NukeAllWrappersForCompartment(cx, cpt, + win->IsInnerWindow() ? js::DontNukeWindowReferences + : js::NukeWindowReferences); } else { // We only want to nuke wrappers for the chrome->content case js::NukeCrossCompartmentWrappers(cx, BrowserCompartmentMatcher(), js::SingleCompartment(cpt), win->IsInnerWindow() ? js::DontNukeWindowReferences - : js::NukeWindowReferences); + : js::NukeWindowReferences, + js::NukeIncomingReferences); } } } diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index fdcc1400782f..2460e31f8349 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -1130,12 +1130,17 @@ class RegExpGuard; extern JS_FRIEND_API(bool) RegExpToSharedNonInline(JSContext* cx, JS::HandleObject regexp, RegExpGuard* shared); -/* Implemented in jswrapper.cpp. */ +/* Implemented in CrossCompartmentWrapper.cpp. */ typedef enum NukeReferencesToWindow { NukeWindowReferences, DontNukeWindowReferences } NukeReferencesToWindow; +typedef enum NukeReferencesFromTarget { + NukeAllReferences, + NukeIncomingReferences, +} NukeReferencesFromTarget; + /* * These filters are designed to be ephemeral stack classes, and thus don't * do any rooting or holding of their members. @@ -1178,7 +1183,8 @@ extern JS_FRIEND_API(bool) NukeCrossCompartmentWrappers(JSContext* cx, const CompartmentFilter& sourceFilter, const CompartmentFilter& targetFilter, - NukeReferencesToWindow nukeReferencesToWindow); + NukeReferencesToWindow nukeReferencesToWindow, + NukeReferencesFromTarget nukeReferencesFromTarget); /* Specify information about DOMProxy proxies in the DOM, for use by ICs. */ diff --git a/js/src/proxy/CrossCompartmentWrapper.cpp b/js/src/proxy/CrossCompartmentWrapper.cpp index ba25c40bd0de..5e14980980e7 100644 --- a/js/src/proxy/CrossCompartmentWrapper.cpp +++ b/js/src/proxy/CrossCompartmentWrapper.cpp @@ -513,20 +513,23 @@ JS_FRIEND_API(bool) js::NukeCrossCompartmentWrappers(JSContext* cx, const CompartmentFilter& sourceFilter, const CompartmentFilter& targetFilter, - js::NukeReferencesToWindow nukeReferencesToWindow) + js::NukeReferencesToWindow nukeReferencesToWindow, + js::NukeReferencesFromTarget nukeReferencesFromTarget) { CHECK_REQUEST(cx); JSRuntime* rt = cx->runtime(); EvictAllNurseries(rt); - // Iterate through scopes looking for system cross compartment wrappers - // that point to an object that shares a global with obj. - for (CompartmentsIter c(rt, SkipAtoms); !c.done(); c.next()) { if (!sourceFilter.match(c)) continue; + // If the compartment matches both the source and target filter, we may + // want to cut both incoming and outgoing wrappers. + bool nukeAll = (nukeReferencesFromTarget == NukeAllReferences && + targetFilter.match(c)); + // Iterate the wrappers looking for anything interesting. for (JSCompartment::WrapperEnum e(c); !e.empty(); e.popFront()) { // Some cross-compartment wrappers are for strings. We're not @@ -538,13 +541,15 @@ js::NukeCrossCompartmentWrappers(JSContext* cx, AutoWrapperRooter wobj(cx, WrapperValue(e)); JSObject* wrapped = UncheckedUnwrap(wobj); + // We only skip nuking window references that point to a target + // compartment, not the ones that belong to it. if (nukeReferencesToWindow == DontNukeWindowReferences && - IsWindowProxy(wrapped)) + MOZ_LIKELY(!nukeAll) && IsWindowProxy(wrapped)) { continue; } - if (targetFilter.match(wrapped->compartment())) { + if (MOZ_UNLIKELY(nukeAll) || targetFilter.match(wrapped->compartment())) { // We found a wrapper to nuke. e.removeFront(); NukeCrossCompartmentWrapper(cx, wobj); diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 7a4f71975ecd..8b1876ff3b9a 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -3020,14 +3020,8 @@ nsXPCComponents_Utils::NukeSandbox(HandleValue obj, JSContext* cx) NS_ENSURE_TRUE(IsWrapper(wrapper), NS_ERROR_INVALID_ARG); RootedObject sb(cx, UncheckedUnwrap(wrapper)); NS_ENSURE_TRUE(IsSandbox(sb), NS_ERROR_INVALID_ARG); - NukeCrossCompartmentWrappers(cx, AllCompartments(), - SingleCompartment(GetObjectCompartment(sb)), - NukeWindowReferences); - // Now mark the compartment as nuked and non-scriptable. - auto compartmentPrivate = xpc::CompartmentPrivate::Get(sb); - compartmentPrivate->wasNuked = true; - compartmentPrivate->scriptability.Block(); + xpc::NukeAllWrappersForCompartment(cx, GetObjectCompartment(sb)); return NS_OK; } diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index 7cc451990926..d52bd6f1b9ea 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -580,6 +580,37 @@ CurrentWindowOrNull(JSContext* cx) return glob ? WindowOrNull(glob) : nullptr; } +// Nukes all wrappers into or out of the given compartment, and prevents new +// wrappers from being created. Additionally marks the compartment as +// unscriptable after wrappers have been nuked. +// +// Note: This should *only* be called for browser or extension compartments. +// Wrappers between web compartments must never be cut in web-observable +// ways. +void +NukeAllWrappersForCompartment(JSContext* cx, JSCompartment* compartment, + js::NukeReferencesToWindow nukeReferencesToWindow) +{ + // First, nuke all wrappers into or out of the target compartment. Once + // the compartment is marked as nuked, WrapperFactory will refuse to + // create new live wrappers for it, in either direction. This means that + // we need to be sure that we don't have any existing cross-compartment + // wrappers which may be replaced with dead wrappers during unrelated + // wrapper recomputation *before* we set that bit. + js::NukeCrossCompartmentWrappers(cx, js::AllCompartments(), + js::SingleCompartment(compartment), + nukeReferencesToWindow, + js::NukeAllReferences); + + // At this point, we should cross-compartment wrappers for the nuked + // compartment. Set the wasNuked bit so WrapperFactory will return a + // DeadObjectProxy when asked to create a new wrapper for it, and mark as + // unscriptable. + auto compartmentPrivate = xpc::CompartmentPrivate::Get(compartment); + compartmentPrivate->wasNuked = true; + compartmentPrivate->scriptability.Block(); +} + } // namespace xpc static void diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index 38375d00a17e..5115b7ea198f 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -400,6 +400,9 @@ bool StringToJsval(JSContext* cx, mozilla::dom::DOMString& str, nsIPrincipal* GetCompartmentPrincipal(JSCompartment* compartment); +void NukeAllWrappersForCompartment(JSContext* cx, JSCompartment* compartment, + js::NukeReferencesToWindow nukeReferencesToWindow = js::NukeWindowReferences); + void SetLocationForGlobal(JSObject* global, const nsACString& location); void SetLocationForGlobal(JSObject* global, nsIURI* locationURI); diff --git a/js/xpconnect/tests/mochitest/mochitest.ini b/js/xpconnect/tests/mochitest/mochitest.ini index de6759e7ab7c..ffac4cc8f4a6 100644 --- a/js/xpconnect/tests/mochitest/mochitest.ini +++ b/js/xpconnect/tests/mochitest/mochitest.ini @@ -101,6 +101,7 @@ support-files = [test_getWebIDLCaller.html] skip-if = (debug == false || os == "android") [test_nac.xhtml] +[test_nukeContentWindow.html] [test_sameOriginPolicy.html] [test_sandbox_fetch.html] support-files = diff --git a/js/xpconnect/tests/mochitest/test_nukeContentWindow.html b/js/xpconnect/tests/mochitest/test_nukeContentWindow.html new file mode 100644 index 000000000000..ce2fd2a89356 --- /dev/null +++ b/js/xpconnect/tests/mochitest/test_nukeContentWindow.html @@ -0,0 +1,61 @@ + + + + + + Test for Bug 1322273 + + + + + +Mozilla Bug 1322273 + + + + + + + From cf6b776ef4e14b6d8926b01656151b2cbfd229e5 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 22 Feb 2017 19:11:52 -0800 Subject: [PATCH 066/102] Bug 1322273: Return DeadObjectProxy when wrapping for nuked compartment. r=bholley MozReview-Commit-ID: V07P0eZvKO --- js/xpconnect/tests/unit/test_nuke_sandbox.js | 37 +++++++++++++++---- js/xpconnect/wrappers/WrapperFactory.cpp | 38 ++++++++++++-------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/js/xpconnect/tests/unit/test_nuke_sandbox.js b/js/xpconnect/tests/unit/test_nuke_sandbox.js index a4dd25498af1..9659902610d8 100644 --- a/js/xpconnect/tests/unit/test_nuke_sandbox.js +++ b/js/xpconnect/tests/unit/test_nuke_sandbox.js @@ -4,20 +4,46 @@ /* See https://bugzilla.mozilla.org/show_bug.cgi?id=769273 */ +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; + +const global = this; + function run_test() { - var sb = Components.utils.Sandbox("http://www.blah.com"); + var ifacePointer = Cc["@mozilla.org/supports-interface-pointer;1"] + .createInstance(Ci.nsISupportsInterfacePointer); + + var sb = Cu.Sandbox(global); sb.prop = "prop" - var refToObjFromSb = Components.utils.evalInSandbox("var a = {prop2:'prop2'}; a", sb); - Components.utils.nukeSandbox(sb); - do_check_true(Components.utils.isDeadWrapper(sb), "sb should be dead"); + sb.ifacePointer = ifacePointer + + var refToObjFromSb = Cu.evalInSandbox(` + Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + + ifacePointer.data = { + QueryInterface: XPCOMUtils.generateQI([]), + wrappedJSObject: {foo: "bar"}, + }; + + var a = {prop2:'prop2'}; + a + `, sb); + + equal(ifacePointer.data.wrappedJSObject.foo, "bar", + "Got expected wrapper into sandbox") + + Cu.nukeSandbox(sb); + ok(Cu.isDeadWrapper(sb), "sb should be dead"); + ok(Cu.isDeadWrapper(ifacePointer.data.wrappedJSObject), + "Wrapper retrieved via XPConnect should be dead"); + try{ sb.prop; do_check_true(false); } catch (e) { do_check_true(e.toString().indexOf("can't access dead object") > -1); } - + Components.utils.isDeadWrapper(refToObjFromSb, "ref to object from sb should be dead"); try{ refToObjFromSb.prop2; @@ -25,5 +51,4 @@ function run_test() } catch (e) { do_check_true(e.toString().indexOf("can't access dead object") > -1); } - } diff --git a/js/xpconnect/wrappers/WrapperFactory.cpp b/js/xpconnect/wrappers/WrapperFactory.cpp index bdb727841f08..c9ae96b7ff92 100644 --- a/js/xpconnect/wrappers/WrapperFactory.cpp +++ b/js/xpconnect/wrappers/WrapperFactory.cpp @@ -181,6 +181,24 @@ WrapperFactory::PrepareForWrapping(JSContext* cx, HandleObject scope, ExposeObjectToActiveJS(obj); } + // If we've somehow gotten to this point after either the source or target + // compartment has been nuked, return a DeadObjectProxy to prevent further + // access. + JSCompartment* origin = js::GetObjectCompartment(obj); + JSCompartment* target = js::GetObjectCompartment(scope); + if (CompartmentPrivate::Get(origin)->wasNuked || + CompartmentPrivate::Get(target)->wasNuked) { + NS_WARNING("Trying to create a wrapper into or out of a nuked compartment"); + + RootedObject ccw(cx, Wrapper::New(cx, obj, &CrossCompartmentWrapper::singleton)); + + NukeCrossCompartmentWrapper(cx, ccw); + + retObj.set(ccw); + return; + } + + // If we've got a WindowProxy, there's nothing special that needs to be // done here, and we can move on to the next phase of wrapping. We handle // this case first to allow us to assert against wrappers below. @@ -332,8 +350,10 @@ DEBUG_CheckUnwrapSafety(HandleObject obj, const js::Wrapper* handler, JSCompartment* origin, JSCompartment* target) { if (CompartmentPrivate::Get(origin)->wasNuked || CompartmentPrivate::Get(target)->wasNuked) { - // If either compartment has already been nuked, we should have an opaque wrapper. - MOZ_ASSERT(handler->hasSecurityPolicy()); + // If either compartment has already been nuked, we should have returned + // a dead wrapper from our prewrap callback, and this function should + // not be called. + MOZ_ASSERT_UNREACHABLE("CheckUnwrapSafety called for a dead wrapper"); } else if (AccessCheck::isChrome(target) || xpc::IsUniversalXPConnectEnabled(target)) { // If the caller is chrome (or effectively so), unwrap should always be allowed. MOZ_ASSERT(!handler->hasSecurityPolicy()); @@ -457,21 +477,9 @@ WrapperFactory::Rewrap(JSContext* cx, HandleObject existing, HandleObject obj) // First, handle the special cases. // - // If we've somehow gotten to this point after either the source or target - // compartment has been nuked, return an opaque wrapper to prevent further - // access. - // Ideally, we should return a DeadProxyObject instead of a wrapper in this - // case (bug 1322273). - if (CompartmentPrivate::Get(origin)->wasNuked || - CompartmentPrivate::Get(target)->wasNuked) { - NS_WARNING("Trying to create a wrapper into or out of a nuked compartment"); - - wrapper = &FilteringWrapper::singleton; - } - // If UniversalXPConnect is enabled, this is just some dumb mochitest. Use // a vanilla CCW. - else if (xpc::IsUniversalXPConnectEnabled(target)) { + if (xpc::IsUniversalXPConnectEnabled(target)) { CrashIfNotInAutomation(); wrapper = &CrossCompartmentWrapper::singleton; } From 6acaac043d12f94a003fe54c4ce90cbd244fa6d4 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Thu, 23 Feb 2017 16:38:39 -0600 Subject: [PATCH 067/102] Bug 1342060 - Followup to 391047948db4 to fix Android tests (r=jorendorff) MozReview-Commit-ID: HDD8v9tIEe7 --- dom/tests/mochitest/general/test_interfaces.js | 2 +- .../test_serviceworker_interfaces.js | 16 +++++++++++----- dom/workers/test/test_worker_interfaces.js | 16 +++++++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/dom/tests/mochitest/general/test_interfaces.js b/dom/tests/mochitest/general/test_interfaces.js index 4abbf8beaf0f..9422ed2080f5 100644 --- a/dom/tests/mochitest/general/test_interfaces.js +++ b/dom/tests/mochitest/general/test_interfaces.js @@ -74,7 +74,7 @@ var ecmaGlobals = "URIError", "WeakMap", "WeakSet", - "WebAssembly" + {name: "WebAssembly", disabled: !SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()} ]; // IMPORTANT: Do not change the list above without review from // a JavaScript Engine peer! diff --git a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js index 662c6e4b2aad..4f663e991f5c 100644 --- a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js +++ b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js @@ -69,7 +69,7 @@ var ecmaGlobals = "URIError", "WeakMap", "WeakSet", - "WebAssembly" + {name: "WebAssembly", optional: true} ]; // IMPORTANT: Do not change the list above without review from // a JavaScript Engine peer! @@ -253,6 +253,8 @@ function createInterfaceMap(version, userAgent) { (entry.android === !isAndroid && !entry.nonReleaseAndroid && !entry.nightlyAndroid) || (entry.release === !isRelease)) { interfaceMap[entry.name] = false; + } else if (entry.optional) { + interfaceMap[entry.name] = "optional"; } else { interfaceMap[entry.name] = true; } @@ -273,17 +275,21 @@ function runTest(version, userAgent) { if (!/^[A-Z]/.test(name)) { continue; } - ok(interfaceMap[name], + ok(interfaceMap[name] === "optional" || interfaceMap[name], "If this is failing: DANGER, are you sure you want to expose the new interface " + name + " to all webpages as a property on the service worker? Do not make a change to this file without a " + " review from a DOM peer for that specific change!!! (or a JS peer for changes to ecmaGlobals)"); delete interfaceMap[name]; } for (var name of Object.keys(interfaceMap)) { - ok(name in self === interfaceMap[name], - name + " should " + (interfaceMap[name] ? "" : " NOT") + " be defined on the global scope"); - if (!interfaceMap[name]) { + if (interfaceMap[name] === "optional") { delete interfaceMap[name]; + } else { + ok(name in self === interfaceMap[name], + name + " should " + (interfaceMap[name] ? "" : " NOT") + " be defined on the global scope"); + if (!interfaceMap[name]) { + delete interfaceMap[name]; + } } } is(Object.keys(interfaceMap).length, 0, diff --git a/dom/workers/test/test_worker_interfaces.js b/dom/workers/test/test_worker_interfaces.js index 9e8921d37dd6..e230f3ccf801 100644 --- a/dom/workers/test/test_worker_interfaces.js +++ b/dom/workers/test/test_worker_interfaces.js @@ -69,7 +69,7 @@ var ecmaGlobals = "URIError", "WeakMap", "WeakSet", - "WebAssembly" + {name: "WebAssembly", optional: true} ]; // IMPORTANT: Do not change the list above without review from // a JavaScript Engine peer! @@ -267,6 +267,8 @@ function createInterfaceMap(version, userAgent) { (entry.release === !isRelease) || entry.disabled) { interfaceMap[entry.name] = false; + } else if (entry.optional) { + interfaceMap[entry.name] = "optional"; } else { interfaceMap[entry.name] = true; } @@ -287,17 +289,21 @@ function runTest(version, userAgent) { if (!/^[A-Z]/.test(name)) { continue; } - ok(interfaceMap[name], + ok(interfaceMap[name] === "optional" || interfaceMap[name], "If this is failing: DANGER, are you sure you want to expose the new interface " + name + " to all webpages as a property on the worker? Do not make a change to this file without a " + " review from a DOM peer for that specific change!!! (or a JS peer for changes to ecmaGlobals)"); delete interfaceMap[name]; } for (var name of Object.keys(interfaceMap)) { - ok(name in self === interfaceMap[name], - name + " should " + (interfaceMap[name] ? "" : " NOT") + " be defined on the global scope"); - if (!interfaceMap[name]) { + if (interfaceMap[name] === "optional") { delete interfaceMap[name]; + } else { + ok(name in self === interfaceMap[name], + name + " should " + (interfaceMap[name] ? "" : " NOT") + " be defined on the global scope"); + if (!interfaceMap[name]) { + delete interfaceMap[name]; + } } } is(Object.keys(interfaceMap).length, 0, From 418aec3890a55233079bfe12b0ef8788573486e6 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 21 Feb 2017 17:31:21 -0800 Subject: [PATCH 068/102] Bug 1341502: Fix automatic regeneration of backend when an included test manifest changes. r=mshal MozReview-Commit-ID: 1ZQNQpqboz9 --- .../mozbuild/mozbuild/backend/test_manifest.py | 3 +++ .../mochitest-common.ini | 1 + .../mochitest.ini | 2 ++ .../test-manifests-backend-sources/moz.build | 6 ++++++ .../test-manifests-backend-sources/test_bar.js | 0 .../test-manifests-backend-sources/test_foo.js | 0 .../test/backend/test_test_manifest.py | 18 ++++++++++++++++++ 7 files changed, 30 insertions(+) create mode 100644 python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest-common.ini create mode 100644 python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest.ini create mode 100644 python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/moz.build create mode 100644 python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/test_bar.js create mode 100644 python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/test_foo.js diff --git a/python/mozbuild/mozbuild/backend/test_manifest.py b/python/mozbuild/mozbuild/backend/test_manifest.py index 4fb3b548abc9..0cfa59fb7772 100644 --- a/python/mozbuild/mozbuild/backend/test_manifest.py +++ b/python/mozbuild/mozbuild/backend/test_manifest.py @@ -32,6 +32,9 @@ class TestManifestBackend(PartialBackend): self.backend_input_files.add(obj.path) self.backend_input_files |= obj.context_all_paths + for source in obj.source_relpaths: + self.backend_input_files.add(mozpath.join(obj.topsrcdir, + source)) try: from reftest import ReftestManifest diff --git a/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest-common.ini b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest-common.ini new file mode 100644 index 000000000000..31d07b5af338 --- /dev/null +++ b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest-common.ini @@ -0,0 +1 @@ +[test_bar.js] diff --git a/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest.ini b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest.ini new file mode 100644 index 000000000000..cf7a3c44bd42 --- /dev/null +++ b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/mochitest.ini @@ -0,0 +1,2 @@ +[test_foo.js] +[include:mochitest-common.ini] diff --git a/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/moz.build b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/moz.build new file mode 100644 index 000000000000..d4003d0e0170 --- /dev/null +++ b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/moz.build @@ -0,0 +1,6 @@ +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +MOCHITEST_MANIFESTS += [ + 'mochitest.ini', +] diff --git a/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/test_bar.js b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/test_bar.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/test_foo.js b/python/mozbuild/mozbuild/test/backend/data/test-manifests-backend-sources/test_foo.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/mozbuild/mozbuild/test/backend/test_test_manifest.py b/python/mozbuild/mozbuild/test/backend/test_test_manifest.py index 9bb93db855e3..250eb401d80a 100644 --- a/python/mozbuild/mozbuild/test/backend/test_test_manifest.py +++ b/python/mozbuild/mozbuild/test/backend/test_test_manifest.py @@ -68,6 +68,24 @@ class TestTestManifestBackend(BackendTester): self.assertIn('here', o[manifest_path]) self.assertIn('support-files', o[manifest_path]) + def test_test_manifest_sources(self): + """Ensure that backend sources are generated correctly.""" + env = self._consume('test-manifests-backend-sources', TestManifestBackend) + + backend_path = mozpath.join(env.topobjdir, 'backend.TestManifestBackend.in') + self.assertTrue(os.path.exists(backend_path)) + + status_path = mozpath.join(env.topobjdir, 'config.status') + + with open(backend_path, 'r') as fh: + sources = set(source.strip() for source in fh) + + self.assertEquals(sources, + set([mozpath.join(env.topsrcdir, 'mochitest.ini'), + mozpath.join(env.topsrcdir, 'mochitest-common.ini'), + mozpath.join(env.topsrcdir, 'moz.build'), + status_path])) + if __name__ == '__main__': main() From ed4d7c9c699eedb50822ccfb56c21f44af12bd9c Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Wed, 22 Feb 2017 18:18:25 -0800 Subject: [PATCH 069/102] Bug 1341957 - Add webgl.getSupportedExtensions() to about:support. - r=daoshengmu MozReview-Commit-ID: EQci0ZxlVyM --- toolkit/content/aboutSupport.js | 6 ++++-- .../chrome/global/aboutSupport.properties | 18 ++++++++++-------- toolkit/modules/Troubleshoot.jsm | 7 ++++++- .../tests/browser/browser_Troubleshoot.js | 6 ++++++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/toolkit/content/aboutSupport.js b/toolkit/content/aboutSupport.js index 7183458ad5ff..ba8d1ba2dd24 100644 --- a/toolkit/content/aboutSupport.js +++ b/toolkit/content/aboutSupport.js @@ -376,14 +376,16 @@ var snapshotFormatters = { apzInfo.length ? apzInfo.join("; ") : localizedMsg(["apzNone"])); + addRowFromKey("features", "webgl1WSIInfo"); addRowFromKey("features", "webgl1Renderer"); addRowFromKey("features", "webgl1Version"); + addRowFromKey("features", "webgl1DriverExtensions"); addRowFromKey("features", "webgl1Extensions"); - addRowFromKey("features", "webgl1WSIInfo"); + addRowFromKey("features", "webgl2WSIInfo"); addRowFromKey("features", "webgl2Renderer"); addRowFromKey("features", "webgl2Version"); + addRowFromKey("features", "webgl2DriverExtensions"); addRowFromKey("features", "webgl2Extensions"); - addRowFromKey("features", "webgl2WSIInfo"); addRowFromKey("features", "supportsHardwareH264", "hardwareH264"); addRowFromKey("features", "currentAudioBackend", "audioBackend"); addRowFromKey("features", "direct2DEnabled", "#Direct2D"); diff --git a/toolkit/locales/en-US/chrome/global/aboutSupport.properties b/toolkit/locales/en-US/chrome/global/aboutSupport.properties index 09298359a1a5..d19dcd03cdae 100644 --- a/toolkit/locales/en-US/chrome/global/aboutSupport.properties +++ b/toolkit/locales/en-US/chrome/global/aboutSupport.properties @@ -71,14 +71,16 @@ gpuRAM = RAM gpuDriverVersion = Driver Version gpuDriverDate = Driver Date gpuActive = Active -webgl1Renderer = WebGL 1 Renderer -webgl1Version = WebGL 1 GL Version -webgl1Extensions = WebGL 1 GL Extensions -webgl1WSIInfo = WebGL 1 WSI Info -webgl2Renderer = WebGL 2 Renderer -webgl2Version = WebGL 2 GL Version -webgl2Extensions = WebGL 2 GL Extensions -webgl2WSIInfo = WebGL 2 WSI Info +webgl1WSIInfo = WebGL 1 Driver WSI Info +webgl1Renderer = WebGL 1 Driver Renderer +webgl1Version = WebGL 1 Driver Version +webgl1DriverExtensions = WebGL 1 Driver Extensions +webgl1Extensions = WebGL 1 Extensions +webgl2WSIInfo = WebGL 2 Driver WSI Info +webgl2Renderer = WebGL 2 Driver Renderer +webgl2Version = WebGL 2 Driver Version +webgl2DriverExtensions = WebGL 2 Driver Extensions +webgl2Extensions = WebGL 2 Extensions GPU1 = GPU #1 GPU2 = GPU #2 blocklistedBug = Blocklisted due to known issues diff --git a/toolkit/modules/Troubleshoot.jsm b/toolkit/modules/Troubleshoot.jsm index dbb114cb45b7..aea6dd80de79 100644 --- a/toolkit/modules/Troubleshoot.jsm +++ b/toolkit/modules/Troubleshoot.jsm @@ -422,6 +422,7 @@ var dataProviders = { function GetWebGLInfo(data, keyPrefix, contextType) { data[keyPrefix + "Renderer"] = "-"; data[keyPrefix + "Version"] = "-"; + data[keyPrefix + "DriverExtensions"] = "-"; data[keyPrefix + "Extensions"] = "-"; data[keyPrefix + "WSIInfo"] = "-"; @@ -458,6 +459,10 @@ var dataProviders = { // // + data[keyPrefix + "Extensions"] = gl.getSupportedExtensions().join(' '); + + // // + let ext = gl.getExtension("MOZ_debug_get"); // This extension is unconditionally available to chrome. No need to check. let vendor = ext.getParameter(gl.VENDOR); @@ -465,7 +470,7 @@ var dataProviders = { data[keyPrefix + "Renderer"] = vendor + " -- " + renderer; data[keyPrefix + "Version"] = ext.getParameter(gl.VERSION); - data[keyPrefix + "Extensions"] = ext.getParameter(ext.EXTENSIONS); + data[keyPrefix + "DriverExtensions"] = ext.getParameter(ext.EXTENSIONS); data[keyPrefix + "WSIInfo"] = ext.getParameter(ext.WSI_INFO); // // diff --git a/toolkit/modules/tests/browser/browser_Troubleshoot.js b/toolkit/modules/tests/browser/browser_Troubleshoot.js index d3c7711196ba..b1a9d71f90b2 100644 --- a/toolkit/modules/tests/browser/browser_Troubleshoot.js +++ b/toolkit/modules/tests/browser/browser_Troubleshoot.js @@ -300,6 +300,9 @@ const SNAPSHOT_SCHEMA = { webgl1Version: { type: "string", }, + webgl1DriverExtensions: { + type: "string", + }, webgl1Extensions: { type: "string", }, @@ -312,6 +315,9 @@ const SNAPSHOT_SCHEMA = { webgl2Version: { type: "string", }, + webgl2DriverExtensions: { + type: "string", + }, webgl2Extensions: { type: "string", }, From 546d9b8b0ecac7cb09175c19a16e5cfa9c28963d Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Thu, 23 Feb 2017 15:03:38 -0800 Subject: [PATCH 070/102] Bug 1341957 - ESLint requires double-quotes for strings. MozReview-Commit-ID: 2BYft7siVSc --- toolkit/modules/Troubleshoot.jsm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolkit/modules/Troubleshoot.jsm b/toolkit/modules/Troubleshoot.jsm index aea6dd80de79..09991395f224 100644 --- a/toolkit/modules/Troubleshoot.jsm +++ b/toolkit/modules/Troubleshoot.jsm @@ -459,7 +459,7 @@ var dataProviders = { // // - data[keyPrefix + "Extensions"] = gl.getSupportedExtensions().join(' '); + data[keyPrefix + "Extensions"] = gl.getSupportedExtensions().join(" "); // // From ff22604d6e221b3814c2147b15fa1f89fd255089 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 15 Feb 2017 10:27:53 +0100 Subject: [PATCH 071/102] Bug 1336198 - Part 2: Remove deprecated boxmodel stylesheet. r=jdescottes MozReview-Commit-ID: 3YkhBQnbJtI --- devtools/client/inspector/inspector.xhtml | 1 - devtools/client/jar.mn | 1 - .../client/themes/deprecated-boxmodel.css | 259 ------------------ 3 files changed, 261 deletions(-) delete mode 100644 devtools/client/themes/deprecated-boxmodel.css diff --git a/devtools/client/inspector/inspector.xhtml b/devtools/client/inspector/inspector.xhtml index d3e13fb7b781..b2e084d9fd74 100644 --- a/devtools/client/inspector/inspector.xhtml +++ b/devtools/client/inspector/inspector.xhtml @@ -14,7 +14,6 @@ - diff --git a/devtools/client/jar.mn b/devtools/client/jar.mn index 628a336e45c0..b68d20740c14 100644 --- a/devtools/client/jar.mn +++ b/devtools/client/jar.mn @@ -177,7 +177,6 @@ devtools.jar: skin/images/noise.png (themes/images/noise.png) skin/images/dropmarker.svg (themes/images/dropmarker.svg) skin/boxmodel.css (themes/boxmodel.css) - skin/deprecated-boxmodel.css (themes/deprecated-boxmodel.css) skin/images/geometry-editor.svg (themes/images/geometry-editor.svg) skin/images/pause.svg (themes/images/pause.svg) skin/images/play.svg (themes/images/play.svg) diff --git a/devtools/client/themes/deprecated-boxmodel.css b/devtools/client/themes/deprecated-boxmodel.css deleted file mode 100644 index e1f6d1432e20..000000000000 --- a/devtools/client/themes/deprecated-boxmodel.css +++ /dev/null @@ -1,259 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/ */ - -/** - * THIS STYLESHEET IS FOR THE DEPRECATED BOX MODEL MODULE (deprecated-box-model.js) AND - * SHOULD NO LONGER BE MODIFIED. - */ - -#old-boxmodel-wrapper { - border-bottom-style: solid; - border-bottom-width: 1px; - border-color: var(--theme-splitter-color); - -moz-user-select: none; -} - -#old-boxmodel-container { - /* The view will grow bigger as the window gets resized, until 400px */ - max-width: 400px; - margin: 0px auto; - padding: 0; -} - -/* Header */ - -#old-boxmodel-header, -#old-boxmodel-info { - display: flex; - align-items: center; - padding: 4px 17px; -} - -#old-layout-geometry-editor { - visibility: hidden; -} - -#old-layout-geometry-editor::before { - background: url(images/geometry-editor.svg) no-repeat center center / 16px 16px; -} - -/* Main: contains the box-model regions */ - -#old-boxmodel-main { - position: relative; - box-sizing: border-box; - /* The regions are semi-transparent, so the white background is partly - visible */ - background-color: white; - color: var(--theme-selection-color); - /* Make sure there is some space between the window's edges and the regions */ - margin: 0 14px 4px 14px; - width: calc(100% - 2 * 14px); -} - -.old-boxmodel-margin, -.old-boxmodel-size { - color: var(--theme-highlight-blue); -} - -/* Regions are 3 nested elements with wide borders and outlines */ - -#old-boxmodel-content { - height: 18px; -} - -#old-boxmodel-margins, -#old-boxmodel-borders, -#old-boxmodel-padding { - border-color: hsla(210,100%,85%,0.2); - border-width: 18px; - border-style: solid; - outline: dotted 1px hsl(210,100%,85%); -} - -#old-boxmodel-margins { - /* This opacity applies to all of the regions, since they are nested */ - opacity: .8; -} - -/* Regions colors */ - -#old-boxmodel-margins { - border-color: #edff64; -} - -#old-boxmodel-borders { - border-color: #444444; -} - -#old-boxmodel-padding { - border-color: #6a5acd; -} - -#old-boxmodel-content { - background-color: #87ceeb; -} - -.theme-firebug #old-boxmodel-main, -.theme-firebug #old-boxmodel-borders, -.theme-firebug #old-boxmodel-content { - border-style: solid; -} - -.theme-firebug #old-boxmodel-main, -.theme-firebug #old-boxmodel-header { - font-family: var(--proportional-font-family); -} - -.theme-firebug #old-boxmodel-main { - color: var(--theme-body-color); - font-size: var(--theme-toolbar-font-size); -} - -.theme-firebug #old-boxmodel-header { - font-size: var(--theme-toolbar-font-size); -} - -/* Editable region sizes are contained in absolutely positioned

*/ - -#old-boxmodel-main > p { - position: absolute; - pointer-events: none; - margin: 0; - text-align: center; -} - -#old-boxmodel-main > p > span, -#old-boxmodel-main > p > input { - vertical-align: middle; - pointer-events: auto; -} - -/* Coordinates for the region sizes */ - -.old-boxmodel-top, -.old-boxmodel-bottom { - width: calc(100% - 2px); - text-align: center; -} - -.old-boxmodel-padding.old-boxmodel-top { - top: 37px; -} - -.old-boxmodel-padding.old-boxmodel-bottom { - bottom: 38px; -} - -.old-boxmodel-border.old-boxmodel-top { - top: 19px; -} - -.old-boxmodel-border.old-boxmodel-bottom { - bottom: 20px; -} - -.old-boxmodel-margin.old-boxmodel-top { - top: 1px; -} - -.old-boxmodel-margin.old-boxmodel-bottom { - bottom: 2px; -} - -.old-boxmodel-size, -.old-boxmodel-margin.old-boxmodel-left, -.old-boxmodel-margin.old-boxmodel-right, -.old-boxmodel-border.old-boxmodel-left, -.old-boxmodel-border.old-boxmodel-right, -.old-boxmodel-padding.old-boxmodel-left, -.old-boxmodel-padding.old-boxmodel-right { - top: 22px; - line-height: 80px; -} - -.old-boxmodel-size { - width: calc(100% - 2px); -} - -.old-boxmodel-margin.old-boxmodel-right, -.old-boxmodel-margin.old-boxmodel-left, -.old-boxmodel-border.old-boxmodel-left, -.old-boxmodel-border.old-boxmodel-right, -.old-boxmodel-padding.old-boxmodel-right, -.old-boxmodel-padding.old-boxmodel-left { - width: 21px; -} - -.old-boxmodel-padding.old-boxmodel-left { - left: 35px; -} - -.old-boxmodel-padding.old-boxmodel-right { - right: 35px; -} - -.old-boxmodel-border.old-boxmodel-left { - left: 16px; -} - -.old-boxmodel-border.old-boxmodel-right { - right: 17px; -} - -.old-boxmodel-margin.old-boxmodel-right { - right: 0; -} - -.old-boxmodel-margin.old-boxmodel-left { - left: 0; -} - -.old-boxmodel-rotate.old-boxmodel-left:not(.old-boxmodel-editing) { - transform: rotate(-90deg); -} - -.old-boxmodel-rotate.old-boxmodel-right:not(.old-boxmodel-editing) { - transform: rotate(90deg); -} - -/* Legend: displayed inside regions */ - -.old-boxmodel-legend { - position: absolute; - margin: 2px 6px; - z-index: 1; -} - -.old-boxmodel-legend[data-box="margin"] { - color: var(--theme-highlight-blue); -} - -/* Editable fields */ - -.old-boxmodel-editable { - border: 1px dashed transparent; - -moz-user-select: none; -} - -.old-boxmodel-editable:hover { - border-bottom-color: hsl(0, 0%, 50%); -} - -/* Make sure the content size doesn't appear as editable like the other sizes */ - -.old-boxmodel-size > span { - cursor: default; -} - -/* Box Model Info: contains the position and size of the element */ - -#old-boxmodel-element-size { - flex: 1; -} - -#old-boxmodel-position-group { - display: flex; - align-items: center; -} From 3d1bd74f709f8a2f75f8cd2bf7d0b28ab103024d Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 15 Feb 2017 10:28:00 +0100 Subject: [PATCH 072/102] Bug 1336198 - Part 3: Remove the deprecated box model source file. r=jdescottes MozReview-Commit-ID: 9WzyF7D28Bs --- .../components/deprecated-box-model.js | 912 ------------------ .../client/inspector/components/moz.build | 1 - 2 files changed, 913 deletions(-) delete mode 100644 devtools/client/inspector/components/deprecated-box-model.js diff --git a/devtools/client/inspector/components/deprecated-box-model.js b/devtools/client/inspector/components/deprecated-box-model.js deleted file mode 100644 index 874a79939c97..000000000000 --- a/devtools/client/inspector/components/deprecated-box-model.js +++ /dev/null @@ -1,912 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ -/* 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 MODULE IS DEPRECATED. - * - * To continue any work related to the box model view, see the new react/redux - * implementation in devtools/client/inspector/layout/. - */ - -"use strict"; - -const {Task} = require("devtools/shared/task"); -const {InplaceEditor, editableItem} = - require("devtools/client/shared/inplace-editor"); -const {ReflowFront} = require("devtools/shared/fronts/reflow"); -const {LocalizationHelper} = require("devtools/shared/l10n"); -const {getCssProperties} = require("devtools/shared/fronts/css-properties"); -const {KeyCodes} = require("devtools/client/shared/keycodes"); -const EditingSession = require("devtools/client/inspector/layout/utils/editing-session"); - -const STRINGS_URI = "devtools/client/locales/shared.properties"; -const STRINGS_INSPECTOR = "devtools/shared/locales/styleinspector.properties"; -const SHARED_L10N = new LocalizationHelper(STRINGS_URI); -const INSPECTOR_L10N = new LocalizationHelper(STRINGS_INSPECTOR); -const NUMERIC = /^-?[\d\.]+$/; -const LONG_TEXT_ROTATE_LIMIT = 3; - -/** - * The box model view - * @param {InspectorPanel} inspector - * An instance of the inspector-panel currently loaded in the toolbox - * @param {Document} document - * The document that will contain the box model view. - */ -function BoxModelView(inspector, document) { - this.inspector = inspector; - this.doc = document; - this.wrapper = this.doc.getElementById("old-boxmodel-wrapper"); - this.container = this.doc.getElementById("old-boxmodel-container"); - this.expander = this.doc.getElementById("old-boxmodel-expander"); - this.sizeLabel = this.doc.querySelector(".old-boxmodel-size > span"); - this.sizeHeadingLabel = this.doc.getElementById("old-boxmodel-element-size"); - this._geometryEditorHighlighter = null; - this._cssProperties = getCssProperties(inspector.toolbox); - - this.init(); -} - -BoxModelView.prototype = { - init: function () { - this.update = this.update.bind(this); - - this.onNewSelection = this.onNewSelection.bind(this); - this.inspector.selection.on("new-node-front", this.onNewSelection); - - this.onNewNode = this.onNewNode.bind(this); - this.inspector.sidebar.on("computedview-selected", this.onNewNode); - - this.onSidebarSelect = this.onSidebarSelect.bind(this); - this.inspector.sidebar.on("select", this.onSidebarSelect); - - this.onToggleExpander = this.onToggleExpander.bind(this); - this.expander.addEventListener("click", this.onToggleExpander); - let header = this.doc.getElementById("old-boxmodel-header"); - header.addEventListener("dblclick", this.onToggleExpander); - - this.onFilterComputedView = this.onFilterComputedView.bind(this); - this.inspector.on("computed-view-filtered", - this.onFilterComputedView); - - this.onPickerStarted = this.onPickerStarted.bind(this); - this.onMarkupViewLeave = this.onMarkupViewLeave.bind(this); - this.onMarkupViewNodeHover = this.onMarkupViewNodeHover.bind(this); - this.onWillNavigate = this.onWillNavigate.bind(this); - this.onKeyDown = this.onKeyDown.bind(this); - this.onLevelClick = this.onLevelClick.bind(this); - this.setAriaActive = this.setAriaActive.bind(this); - this.getEditBoxes = this.getEditBoxes.bind(this); - this.makeFocusable = this.makeFocusable.bind(this); - this.makeUnfocasable = this.makeUnfocasable.bind(this); - this.moveFocus = this.moveFocus.bind(this); - this.onFocus = this.onFocus.bind(this); - - this.borderLayout = this.doc.getElementById("old-boxmodel-borders"); - this.boxModel = this.doc.getElementById("old-boxmodel-wrapper"); - this.marginLayout = this.doc.getElementById("old-boxmodel-margins"); - this.paddingLayout = this.doc.getElementById("old-boxmodel-padding"); - - this.layouts = { - "margin": new Map([ - [KeyCodes.DOM_VK_ESCAPE, this.marginLayout], - [KeyCodes.DOM_VK_DOWN, this.borderLayout], - [KeyCodes.DOM_VK_UP, null], - ["click", this.marginLayout] - ]), - "border": new Map([ - [KeyCodes.DOM_VK_ESCAPE, this.borderLayout], - [KeyCodes.DOM_VK_DOWN, this.paddingLayout], - [KeyCodes.DOM_VK_UP, this.marginLayout], - ["click", this.borderLayout] - ]), - "padding": new Map([ - [KeyCodes.DOM_VK_ESCAPE, this.paddingLayout], - [KeyCodes.DOM_VK_DOWN, null], - [KeyCodes.DOM_VK_UP, this.borderLayout], - ["click", this.paddingLayout] - ]) - }; - - this.boxModel.addEventListener("click", this.onLevelClick, true); - this.boxModel.addEventListener("focus", this.onFocus, true); - this.boxModel.addEventListener("keydown", this.onKeyDown, true); - - this.initBoxModelHighlighter(); - - // Store for the different dimensions of the node. - // 'selector' refers to the element that holds the value; - // 'property' is what we are measuring; - // 'value' is the computed dimension, computed in update(). - this.map = { - position: { - selector: "#old-boxmodel-element-position", - property: "position", - value: undefined - }, - marginTop: { - selector: ".old-boxmodel-margin.old-boxmodel-top > span", - property: "margin-top", - value: undefined - }, - marginBottom: { - selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", - property: "margin-bottom", - value: undefined - }, - marginLeft: { - selector: ".old-boxmodel-margin.old-boxmodel-left > span", - property: "margin-left", - value: undefined - }, - marginRight: { - selector: ".old-boxmodel-margin.old-boxmodel-right > span", - property: "margin-right", - value: undefined - }, - paddingTop: { - selector: ".old-boxmodel-padding.old-boxmodel-top > span", - property: "padding-top", - value: undefined - }, - paddingBottom: { - selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", - property: "padding-bottom", - value: undefined - }, - paddingLeft: { - selector: ".old-boxmodel-padding.old-boxmodel-left > span", - property: "padding-left", - value: undefined - }, - paddingRight: { - selector: ".old-boxmodel-padding.old-boxmodel-right > span", - property: "padding-right", - value: undefined - }, - borderTop: { - selector: ".old-boxmodel-border.old-boxmodel-top > span", - property: "border-top-width", - value: undefined - }, - borderBottom: { - selector: ".old-boxmodel-border.old-boxmodel-bottom > span", - property: "border-bottom-width", - value: undefined - }, - borderLeft: { - selector: ".old-boxmodel-border.old-boxmodel-left > span", - property: "border-left-width", - value: undefined - }, - borderRight: { - selector: ".old-boxmodel-border.old-boxmodel-right > span", - property: "border-right-width", - value: undefined - } - }; - - // Make each element the dimensions editable - for (let i in this.map) { - if (i == "position") { - continue; - } - - let dimension = this.map[i]; - editableItem({ - element: this.doc.querySelector(dimension.selector) - }, (element, event) => { - this.initEditor(element, event, dimension); - }); - } - - this.onNewNode(); - - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - this.onGeometryButtonClick = this.onGeometryButtonClick.bind(this); - nodeGeometry.addEventListener("click", this.onGeometryButtonClick); - }, - - initBoxModelHighlighter: function () { - let highlightElts = this.doc.querySelectorAll("#old-boxmodel-container *[title]"); - this.onHighlightMouseOver = this.onHighlightMouseOver.bind(this); - this.onHighlightMouseOut = this.onHighlightMouseOut.bind(this); - - for (let element of highlightElts) { - element.addEventListener("mouseover", this.onHighlightMouseOver, true); - element.addEventListener("mouseout", this.onHighlightMouseOut, true); - } - }, - - /** - * Start listening to reflows in the current tab. - */ - trackReflows: function () { - if (!this.reflowFront) { - let { target } = this.inspector; - if (target.form.reflowActor) { - this.reflowFront = ReflowFront(target.client, - target.form); - } else { - return; - } - } - - this.reflowFront.on("reflows", this.update); - this.reflowFront.start(); - }, - - /** - * Stop listening to reflows in the current tab. - */ - untrackReflows: function () { - if (!this.reflowFront) { - return; - } - - this.reflowFront.off("reflows", this.update); - this.reflowFront.stop(); - }, - - /** - * Called when the user clicks on one of the editable values in the box model view - */ - initEditor: function (element, event, dimension) { - let { property } = dimension; - let session = new EditingSession(this); - let initialValue = session.getProperty(property); - - let editor = new InplaceEditor({ - element: element, - initial: initialValue, - contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, - property: { - name: dimension.property - }, - start: self => { - self.elt.parentNode.classList.add("old-boxmodel-editing"); - }, - change: value => { - if (NUMERIC.test(value)) { - value += "px"; - } - - let properties = [ - { name: property, value: value } - ]; - - if (property.substring(0, 7) == "border-") { - let bprop = property.substring(0, property.length - 5) + "style"; - let style = session.getProperty(bprop); - if (!style || style == "none" || style == "hidden") { - properties.push({ name: bprop, value: "solid" }); - } - } - - session.setProperties(properties).catch(e => console.error(e)); - }, - done: (value, commit) => { - editor.elt.parentNode.classList.remove("old-boxmodel-editing"); - if (!commit) { - session.revert().then(() => { - session.destroy(); - }, e => console.error(e)); - } - }, - contextMenu: this.inspector.onTextBoxContextMenu, - cssProperties: this._cssProperties - }, event); - }, - - /** - * Is the BoxModelView visible in the sidebar. - * @return {Boolean} - */ - isViewVisible: function () { - return this.inspector && - this.inspector.sidebar.getCurrentTabID() == "computedview"; - }, - - /** - * Is the BoxModelView visible in the sidebar and is the current node valid to - * be displayed in the view. - * @return {Boolean} - */ - isViewVisibleAndNodeValid: function () { - return this.isViewVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode(); - }, - - /** - * Destroy the nodes. Remove listeners. - */ - destroy: function () { - let highlightElts = this.doc.querySelectorAll("#old-boxmodel-container *[title]"); - - for (let element of highlightElts) { - element.removeEventListener("mouseover", this.onHighlightMouseOver, true); - element.removeEventListener("mouseout", this.onHighlightMouseOut, true); - } - - this.expander.removeEventListener("click", this.onToggleExpander); - let header = this.doc.getElementById("old-boxmodel-header"); - header.removeEventListener("dblclick", this.onToggleExpander); - - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - nodeGeometry.removeEventListener("click", this.onGeometryButtonClick); - - this.boxModel.removeEventListener("click", this.onLevelClick, true); - this.boxModel.removeEventListener("focus", this.onFocus, true); - this.boxModel.removeEventListener("keydown", this.onKeyDown, true); - - this.inspector.off("picker-started", this.onPickerStarted); - - // Inspector Panel will destroy `markup` object on "will-navigate" event, - // therefore we have to check if it's still available in case BoxModelView - // is destroyed immediately after. - if (this.inspector.markup) { - this.inspector.markup.off("leave", this.onMarkupViewLeave); - this.inspector.markup.off("node-hover", this.onMarkupViewNodeHover); - } - - this.inspector.sidebar.off("computedview-selected", this.onNewNode); - this.inspector.selection.off("new-node-front", this.onNewSelection); - this.inspector.sidebar.off("select", this.onSidebarSelect); - this.inspector.target.off("will-navigate", this.onWillNavigate); - this.inspector.off("computed-view-filtered", this.onFilterComputedView); - - this.inspector = null; - this.doc = null; - this.wrapper = null; - this.container = null; - this.expander = null; - this.sizeLabel = null; - this.sizeHeadingLabel = null; - - this.marginLayout = null; - this.borderLayout = null; - this.paddingLayout = null; - this.boxModel = null; - this.layouts = null; - - if (this.reflowFront) { - this.untrackReflows(); - this.reflowFront.destroy(); - this.reflowFront = null; - } - }, - - /** - * Set initial box model focus to the margin layout. - */ - onFocus: function () { - let activeDescendant = this.boxModel.getAttribute("aria-activedescendant"); - - if (!activeDescendant) { - let nextLayout = this.marginLayout; - this.setAriaActive(nextLayout); - } - }, - - /** - * Active aria-level set to current layout. - * - * @param {Element} nextLayout - * Element of next layout that user has navigated to - * @param {Node} target - * Node to be observed - */ - setAriaActive: function (nextLayout, target) { - this.boxModel.setAttribute("aria-activedescendant", nextLayout.id); - if (target && target._editable) { - target.blur(); - } - - // Clear all - this.marginLayout.classList.remove("layout-active-elm"); - this.borderLayout.classList.remove("layout-active-elm"); - this.paddingLayout.classList.remove("layout-active-elm"); - - // Set the next level's border outline - nextLayout.classList.add("layout-active-elm"); - }, - - /** - * Update aria-active on mouse click. - * - * @param {Event} event - * The event triggered by a mouse click on the box model - */ - onLevelClick: function (event) { - let {target} = event; - let nextLayout = this.layouts[target.getAttribute("data-box")].get("click"); - - this.setAriaActive(nextLayout, target); - }, - - /** - * Handle keyboard navigation and focus for box model layouts. - * - * Updates active layout on arrow key navigation - * Focuses next layout's editboxes on enter key - * Unfocuses current layout's editboxes when active layout changes - * Controls tabbing between editBoxes - * - * @param {Event} event - * The event triggered by a keypress on the box model - */ - onKeyDown: function (event) { - let {target, keyCode} = event; - // If focused on editable value or in editing mode - let isEditable = target._editable || target.editor; - let level = this.boxModel.getAttribute("aria-activedescendant"); - let editingMode = target.tagName === "input"; - let nextLayout; - - switch (keyCode) { - case KeyCodes.DOM_VK_RETURN: - if (!isEditable) { - this.makeFocusable(level); - } - break; - case KeyCodes.DOM_VK_DOWN: - case KeyCodes.DOM_VK_UP: - if (!editingMode) { - event.preventDefault(); - this.makeUnfocasable(level); - let datalevel = this.doc.getElementById(level).getAttribute("data-box"); - nextLayout = this.layouts[datalevel].get(keyCode); - this.boxModel.focus(); - } - break; - case KeyCodes.DOM_VK_TAB: - if (isEditable) { - event.preventDefault(); - this.moveFocus(event, level); - } - break; - case KeyCodes.DOM_VK_ESCAPE: - if (isEditable && target._editable) { - event.preventDefault(); - event.stopPropagation(); - this.makeUnfocasable(level); - this.boxModel.focus(); - } - break; - default: - break; - } - - if (nextLayout) { - this.setAriaActive(nextLayout, target); - } - }, - - /** - * Make previous layout's elements unfocusable. - * - * @param {String} editLevel - * The previous layout - */ - makeUnfocasable: function (editLevel) { - let editBoxes = this.getEditBoxes(editLevel); - editBoxes.forEach(editBox => editBox.setAttribute("tabindex", "-1")); - }, - - /** - * Make current layout's elements focusable. - * - * @param {String} editLevel - * The current layout - */ - makeFocusable: function (editLevel) { - let editBoxes = this.getEditBoxes(editLevel); - editBoxes.forEach(editBox => editBox.setAttribute("tabindex", "0")); - editBoxes[0].focus(); - }, - - /** - * Keyboard navigation of edit boxes wraps around on edge - * elements ([layout]-top, [layout]-left). - * - * @param {Node} target - * Node to be observed - * @param {Boolean} shiftKey - * Determines if shiftKey was pressed - * @param {String} level - * Current active layout - */ - moveFocus: function ({target, shiftKey}, level) { - let editBoxes = this.getEditBoxes(level); - let editingMode = target.tagName === "input"; - // target.nextSibling is input field - let position = editingMode ? editBoxes.indexOf(target.nextSibling) - : editBoxes.indexOf(target); - - if (position === editBoxes.length - 1 && !shiftKey) { - position = 0; - } else if (position === 0 && shiftKey) { - position = editBoxes.length - 1; - } else { - shiftKey ? position-- : position++; - } - - let editBox = editBoxes[position]; - editBox.focus(); - - if (editingMode) { - editBox.click(); - } - }, - - /** - * Retrieve edit boxes for current layout. - * - * @param {String} editLevel - * Current active layout - * @return Layout's edit boxes - */ - getEditBoxes: function (editLevel) { - let dataLevel = this.doc.getElementById(editLevel).getAttribute("data-box"); - return [...this.doc.querySelectorAll( - `[data-box="${dataLevel}"].old-boxmodel-editable`)]; - }, - - onSidebarSelect: function (e, sidebar) { - this.setActive(sidebar === "computedview"); - }, - - /** - * Selection 'new-node-front' event handler. - */ - onNewSelection: function () { - let done = this.inspector.updating("computed-view"); - this.onNewNode() - .then(() => this.hideGeometryEditor()) - .then(done, (err) => { - console.error(err); - done(); - }).catch(console.error); - }, - - /** - * @return a promise that resolves when the view has been updated - */ - onNewNode: function () { - this.setActive(this.isViewVisibleAndNodeValid()); - return this.update(); - }, - - onHighlightMouseOver: function (e) { - let region = e.target.getAttribute("data-box"); - if (!region) { - return; - } - - this.showBoxModel({ - region, - showOnly: region, - onlyRegionArea: true - }); - }, - - onHighlightMouseOut: function () { - this.hideBoxModel(); - }, - - onGeometryButtonClick: function ({target}) { - if (target.hasAttribute("checked")) { - target.removeAttribute("checked"); - this.hideGeometryEditor(); - } else { - target.setAttribute("checked", "true"); - this.showGeometryEditor(); - } - }, - - onPickerStarted: function () { - this.hideGeometryEditor(); - }, - - onToggleExpander: function () { - let isOpen = this.expander.hasAttribute("open"); - - if (isOpen) { - this.container.hidden = true; - this.expander.removeAttribute("open"); - } else { - this.container.hidden = false; - this.expander.setAttribute("open", ""); - } - }, - - onMarkupViewLeave: function () { - this.showGeometryEditor(true); - }, - - onMarkupViewNodeHover: function () { - this.hideGeometryEditor(false); - }, - - onWillNavigate: function () { - this._geometryEditorHighlighter.release().catch(console.error); - this._geometryEditorHighlighter = null; - }, - - /** - * Event handler that responds to the computed view being filtered - * @param {String} reason - * @param {Boolean} hidden - * Whether or not to hide the box model wrapper - */ - onFilterComputedView: function (reason, hidden) { - this.wrapper.hidden = hidden; - }, - - /** - * Stop tracking reflows and hide all values when no node is selected or the - * box model view is hidden, otherwise track reflows and show values. - * @param {Boolean} isActive - */ - setActive: function (isActive) { - if (isActive === this.isActive) { - return; - } - this.isActive = isActive; - - if (isActive) { - this.trackReflows(); - } else { - this.untrackReflows(); - } - }, - - /** - * Compute the dimensions of the node and update the values in - * the inspector.xul document. - * @return a promise that will be resolved when complete. - */ - update: function () { - let lastRequest = Task.spawn((function* () { - if (!this.isViewVisibleAndNodeValid()) { - this.wrapper.hidden = true; - this.inspector.emit("boxmodel-view-updated"); - return null; - } - - let node = this.inspector.selection.nodeFront; - let layout = yield this.inspector.pageStyle.getLayout(node, { - autoMargins: this.isActive - }); - let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); - - yield this.updateGeometryButton(); - - // If a subsequent request has been made, wait for that one instead. - if (this._lastRequest != lastRequest) { - return this._lastRequest; - } - - this._lastRequest = null; - let width = layout.width; - let height = layout.height; - let newLabel = SHARED_L10N.getFormatStr("dimensions", width, height); - - if (this.sizeHeadingLabel.textContent != newLabel) { - this.sizeHeadingLabel.textContent = newLabel; - } - - for (let i in this.map) { - let property = this.map[i].property; - if (!(property in layout)) { - // Depending on the actor version, some properties - // might be missing. - continue; - } - let parsedValue = parseFloat(layout[property]); - if (Number.isNaN(parsedValue)) { - // Not a number. We use the raw string. - // Useful for "position" for example. - this.map[i].value = layout[property]; - } else { - this.map[i].value = parsedValue; - } - } - - let margins = layout.autoMargins; - if ("top" in margins) { - this.map.marginTop.value = "auto"; - } - if ("right" in margins) { - this.map.marginRight.value = "auto"; - } - if ("bottom" in margins) { - this.map.marginBottom.value = "auto"; - } - if ("left" in margins) { - this.map.marginLeft.value = "auto"; - } - - for (let i in this.map) { - let selector = this.map[i].selector; - let span = this.doc.querySelector(selector); - this.updateSourceRuleTooltip(span, this.map[i].property, styleEntries); - if (span.textContent.length > 0 && - span.textContent == this.map[i].value) { - continue; - } - span.textContent = this.map[i].value; - this.manageOverflowingText(span); - } - - width -= this.map.borderLeft.value + this.map.borderRight.value + - this.map.paddingLeft.value + this.map.paddingRight.value; - width = parseFloat(width.toPrecision(6)); - height -= this.map.borderTop.value + this.map.borderBottom.value + - this.map.paddingTop.value + this.map.paddingBottom.value; - height = parseFloat(height.toPrecision(6)); - - let newValue = width + "\u00D7" + height; - if (this.sizeLabel.textContent != newValue) { - this.sizeLabel.textContent = newValue; - } - - this.elementRules = styleEntries.map(e => e.rule); - - this.wrapper.hidden = false; - - this.inspector.emit("boxmodel-view-updated"); - return null; - }).bind(this)).catch(console.error); - - this._lastRequest = lastRequest; - return this._lastRequest; - }, - - /** - * Update the text in the tooltip shown when hovering over a value to provide - * information about the source CSS rule that sets this value. - * @param {DOMNode} el The element that will receive the tooltip. - * @param {String} property The name of the CSS property for the tooltip. - * @param {Array} rules An array of applied rules retrieved by - * styleActor.getApplied. - */ - updateSourceRuleTooltip: function (el, property, rules) { - // Dummy element used to parse the cssText of applied rules. - let dummyEl = this.doc.createElement("div"); - - // Rules are in order of priority so iterate until we find the first that - // defines a value for the property. - let sourceRule, value; - for (let {rule} of rules) { - dummyEl.style.cssText = rule.cssText; - value = dummyEl.style.getPropertyValue(property); - if (value !== "") { - sourceRule = rule; - break; - } - } - - let title = property; - if (sourceRule && sourceRule.selectors) { - title += "\n" + sourceRule.selectors.join(", "); - } - if (sourceRule && sourceRule.parentStyleSheet) { - if (sourceRule.parentStyleSheet.href) { - title += "\n" + sourceRule.parentStyleSheet.href + ":" + sourceRule.line; - } else { - title += "\n" + INSPECTOR_L10N.getStr("rule.sourceInline") + - ":" + sourceRule.line; - } - } - - el.setAttribute("title", title); - }, - - /** - * Show the box-model highlighter on the currently selected element - * @param {Object} options Options passed to the highlighter actor - */ - showBoxModel: function (options = {}) { - let toolbox = this.inspector.toolbox; - let nodeFront = this.inspector.selection.nodeFront; - - toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); - }, - - /** - * Hide the box-model highlighter on the currently selected element - */ - hideBoxModel: function () { - let toolbox = this.inspector.toolbox; - - toolbox.highlighterUtils.unhighlight(); - }, - - /** - * Show the geometry editor highlighter on the currently selected element - * @param {Boolean} [showOnlyIfActive=false] - * Indicates if the Geometry Editor should be shown only if it's active but - * hidden. - */ - showGeometryEditor: function (showOnlyIfActive = false) { - let toolbox = this.inspector.toolbox; - let nodeFront = this.inspector.selection.nodeFront; - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - let isActive = nodeGeometry.hasAttribute("checked"); - - if (showOnlyIfActive && !isActive) { - return; - } - - if (this._geometryEditorHighlighter) { - this._geometryEditorHighlighter.show(nodeFront).catch(console.error); - return; - } - - // instantiate Geometry Editor highlighter - toolbox.highlighterUtils - .getHighlighterByType("GeometryEditorHighlighter").then(highlighter => { - highlighter.show(nodeFront).catch(console.error); - this._geometryEditorHighlighter = highlighter; - - // Hide completely the geometry editor if the picker is clicked - toolbox.on("picker-started", this.onPickerStarted); - - // Temporary hide the geometry editor - this.inspector.markup.on("leave", this.onMarkupViewLeave); - this.inspector.markup.on("node-hover", this.onMarkupViewNodeHover); - - // Release the actor on will-navigate event - this.inspector.target.once("will-navigate", this.onWillNavigate); - }); - }, - - /** - * Hide the geometry editor highlighter on the currently selected element - * @param {Boolean} [updateButton=true] - * Indicates if the Geometry Editor's button needs to be unchecked too - */ - hideGeometryEditor: function (updateButton = true) { - if (this._geometryEditorHighlighter) { - this._geometryEditorHighlighter.hide().catch(console.error); - } - - if (updateButton) { - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - nodeGeometry.removeAttribute("checked"); - } - }, - - /** - * Update the visibility and the state of the geometry editor button, - * based on the selected node. - */ - updateGeometryButton: Task.async(function* () { - let node = this.inspector.selection.nodeFront; - let isEditable = false; - - if (node) { - isEditable = yield this.inspector.pageStyle.isPositionEditable(node); - } - - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - nodeGeometry.style.visibility = isEditable ? "visible" : "hidden"; - }), - - manageOverflowingText: function (span) { - let classList = span.parentNode.classList; - - if (classList.contains("old-boxmodel-left") || - classList.contains("old-boxmodel-right")) { - let force = span.textContent.length > LONG_TEXT_ROTATE_LIMIT; - classList.toggle("old-boxmodel-rotate", force); - } - } -}; - -module.exports = BoxModelView; diff --git a/devtools/client/inspector/components/moz.build b/devtools/client/inspector/components/moz.build index 23d85edcdb23..0ef321ae1da1 100644 --- a/devtools/client/inspector/components/moz.build +++ b/devtools/client/inspector/components/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'deprecated-box-model.js', 'inspector-tab-panel.css', 'inspector-tab-panel.js', ) From e93c90cb48ab288bb869e1eb2240c55122f34560 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 15 Feb 2017 10:28:06 +0100 Subject: [PATCH 073/102] Bug 1336198 - Part 4: Remove the deprecated box model markup. r=jdescottes MozReview-Commit-ID: WhkNI8XYk2 --- devtools/client/inspector/inspector.xhtml | 55 +---------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/devtools/client/inspector/inspector.xhtml b/devtools/client/inspector/inspector.xhtml index b2e084d9fd74..529627161088 100644 --- a/devtools/client/inspector/inspector.xhtml +++ b/devtools/client/inspector/inspector.xhtml @@ -131,60 +131,7 @@

-
-
- - -
- -
-
- -
- -
- -
-
-
-
-
-
- -

-

-

-

- -

-

-

-

- -

-

-

-

- -

- -

-
- -
- -
- - -
-
- -
-

-
-
+
From 0f06fdd2829942c598e5201f47a4bb6bcae2d5f1 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 15 Feb 2017 10:28:18 +0100 Subject: [PATCH 074/102] Bug 1336198 - Part 5: Remove initialization of the deprecated box model. r=jdescottes MozReview-Commit-ID: BxEsyysBpcf --- devtools/client/inspector/computed/computed.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/devtools/client/inspector/computed/computed.js b/devtools/client/inspector/computed/computed.js index 95c81f0cf14d..54c543c672ad 100644 --- a/devtools/client/inspector/computed/computed.js +++ b/devtools/client/inspector/computed/computed.js @@ -26,7 +26,6 @@ const { const StyleInspectorMenu = require("devtools/client/inspector/shared/style-inspector-menu"); const TooltipsOverlay = require("devtools/client/inspector/shared/tooltips-overlay"); const KeyShortcuts = require("devtools/client/shared/key-shortcuts"); -const BoxModelView = require("devtools/client/inspector/components/deprecated-box-model"); const clipboardHelper = require("devtools/shared/platform/clipboard"); const STYLE_INSPECTOR_PROPERTIES = "devtools/shared/locales/styleinspector.properties"; @@ -1416,7 +1415,6 @@ function ComputedViewTool(inspector, window) { this.computedView = new CssComputedView(this.inspector, this.document, this.inspector.pageStyle); - this.boxModelView = new BoxModelView(this.inspector, this.document); this.onSelected = this.onSelected.bind(this); this.refresh = this.refresh.bind(this); @@ -1525,9 +1523,8 @@ ComputedViewTool.prototype = { } this.computedView.destroy(); - this.boxModelView.destroy(); - this.computedView = this.boxModelView = this.document = this.inspector = null; + this.computedView = this.document = this.inspector = null; } }; From b79c053a65c59da3167c89e0639f68ec106c944d Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 15 Feb 2017 10:28:21 +0100 Subject: [PATCH 075/102] Bug 1336198 - Part 6: Refactor box model component into boxmodel/. r=jdescottes MozReview-Commit-ID: JGdBeK8AyEm --- .../{layout => boxmodel}/actions/box-model.js | 0 .../client/inspector/boxmodel/actions/index.js | 14 ++++++++++++++ .../client/inspector/boxmodel/actions/moz.build | 10 ++++++++++ .../{layout => boxmodel}/components/BoxModel.js | 0 .../components/BoxModelEditable.js | 0 .../components/BoxModelInfo.js | 0 .../components/BoxModelMain.js | 0 .../components/BoxModelProperties.js | 0 .../components/ComputedProperty.js | 0 .../inspector/boxmodel/components/moz.build | 14 ++++++++++++++ devtools/client/inspector/boxmodel/moz.build | 16 ++++++++++++++++ .../{layout => boxmodel}/reducers/box-model.js | 0 .../inspector/boxmodel/reducers/moz.build | 9 +++++++++ devtools/client/inspector/boxmodel/types.js | 17 +++++++++++++++++ .../utils/editing-session.js | 0 .../client/inspector/boxmodel/utils/moz.build | 9 +++++++++ .../client/inspector/layout/actions/index.js | 3 --- .../client/inspector/layout/actions/moz.build | 1 - .../inspector/layout/components/moz.build | 6 ------ .../client/inspector/layout/reducers/moz.build | 1 - devtools/client/inspector/layout/types.js | 10 ---------- .../client/inspector/layout/utils/moz.build | 1 - devtools/client/inspector/moz.build | 1 + devtools/client/inspector/reducers.js | 2 +- 24 files changed, 91 insertions(+), 23 deletions(-) rename devtools/client/inspector/{layout => boxmodel}/actions/box-model.js (100%) create mode 100644 devtools/client/inspector/boxmodel/actions/index.js create mode 100644 devtools/client/inspector/boxmodel/actions/moz.build rename devtools/client/inspector/{layout => boxmodel}/components/BoxModel.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelEditable.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelInfo.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelMain.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelProperties.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/ComputedProperty.js (100%) create mode 100644 devtools/client/inspector/boxmodel/components/moz.build create mode 100644 devtools/client/inspector/boxmodel/moz.build rename devtools/client/inspector/{layout => boxmodel}/reducers/box-model.js (100%) create mode 100644 devtools/client/inspector/boxmodel/reducers/moz.build create mode 100644 devtools/client/inspector/boxmodel/types.js rename devtools/client/inspector/{layout => boxmodel}/utils/editing-session.js (100%) create mode 100644 devtools/client/inspector/boxmodel/utils/moz.build diff --git a/devtools/client/inspector/layout/actions/box-model.js b/devtools/client/inspector/boxmodel/actions/box-model.js similarity index 100% rename from devtools/client/inspector/layout/actions/box-model.js rename to devtools/client/inspector/boxmodel/actions/box-model.js diff --git a/devtools/client/inspector/boxmodel/actions/index.js b/devtools/client/inspector/boxmodel/actions/index.js new file mode 100644 index 000000000000..45758428e733 --- /dev/null +++ b/devtools/client/inspector/boxmodel/actions/index.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { createEnum } = require("devtools/client/shared/enum"); + +createEnum([ + + // Update the layout state with the latest layout properties. + "UPDATE_LAYOUT", + +], module.exports); diff --git a/devtools/client/inspector/boxmodel/actions/moz.build b/devtools/client/inspector/boxmodel/actions/moz.build new file mode 100644 index 000000000000..2f98f6793d0c --- /dev/null +++ b/devtools/client/inspector/boxmodel/actions/moz.build @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'box-model.js', + 'index.js', +) diff --git a/devtools/client/inspector/layout/components/BoxModel.js b/devtools/client/inspector/boxmodel/components/BoxModel.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModel.js rename to devtools/client/inspector/boxmodel/components/BoxModel.js diff --git a/devtools/client/inspector/layout/components/BoxModelEditable.js b/devtools/client/inspector/boxmodel/components/BoxModelEditable.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelEditable.js rename to devtools/client/inspector/boxmodel/components/BoxModelEditable.js diff --git a/devtools/client/inspector/layout/components/BoxModelInfo.js b/devtools/client/inspector/boxmodel/components/BoxModelInfo.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelInfo.js rename to devtools/client/inspector/boxmodel/components/BoxModelInfo.js diff --git a/devtools/client/inspector/layout/components/BoxModelMain.js b/devtools/client/inspector/boxmodel/components/BoxModelMain.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelMain.js rename to devtools/client/inspector/boxmodel/components/BoxModelMain.js diff --git a/devtools/client/inspector/layout/components/BoxModelProperties.js b/devtools/client/inspector/boxmodel/components/BoxModelProperties.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelProperties.js rename to devtools/client/inspector/boxmodel/components/BoxModelProperties.js diff --git a/devtools/client/inspector/layout/components/ComputedProperty.js b/devtools/client/inspector/boxmodel/components/ComputedProperty.js similarity index 100% rename from devtools/client/inspector/layout/components/ComputedProperty.js rename to devtools/client/inspector/boxmodel/components/ComputedProperty.js diff --git a/devtools/client/inspector/boxmodel/components/moz.build b/devtools/client/inspector/boxmodel/components/moz.build new file mode 100644 index 000000000000..562fd1a2cba8 --- /dev/null +++ b/devtools/client/inspector/boxmodel/components/moz.build @@ -0,0 +1,14 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'BoxModel.js', + 'BoxModelEditable.js', + 'BoxModelInfo.js', + 'BoxModelMain.js', + 'BoxModelProperties.js', + 'ComputedProperty.js', +) diff --git a/devtools/client/inspector/boxmodel/moz.build b/devtools/client/inspector/boxmodel/moz.build new file mode 100644 index 000000000000..eeb9697a60cb --- /dev/null +++ b/devtools/client/inspector/boxmodel/moz.build @@ -0,0 +1,16 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DIRS += [ + 'actions', + 'components', + 'reducers', + 'utils', +] + +DevToolsModules( + 'types.js', +) diff --git a/devtools/client/inspector/layout/reducers/box-model.js b/devtools/client/inspector/boxmodel/reducers/box-model.js similarity index 100% rename from devtools/client/inspector/layout/reducers/box-model.js rename to devtools/client/inspector/boxmodel/reducers/box-model.js diff --git a/devtools/client/inspector/boxmodel/reducers/moz.build b/devtools/client/inspector/boxmodel/reducers/moz.build new file mode 100644 index 000000000000..e2402990ad80 --- /dev/null +++ b/devtools/client/inspector/boxmodel/reducers/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'box-model.js', +) diff --git a/devtools/client/inspector/boxmodel/types.js b/devtools/client/inspector/boxmodel/types.js new file mode 100644 index 000000000000..aba8f7893d7e --- /dev/null +++ b/devtools/client/inspector/boxmodel/types.js @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { PropTypes } = require("devtools/client/shared/vendor/react"); + +/** + * The box model data for the current selected node. + */ +exports.boxModel = { + + // The layout information of the current selected node + layout: PropTypes.object, + +}; diff --git a/devtools/client/inspector/layout/utils/editing-session.js b/devtools/client/inspector/boxmodel/utils/editing-session.js similarity index 100% rename from devtools/client/inspector/layout/utils/editing-session.js rename to devtools/client/inspector/boxmodel/utils/editing-session.js diff --git a/devtools/client/inspector/boxmodel/utils/moz.build b/devtools/client/inspector/boxmodel/utils/moz.build new file mode 100644 index 000000000000..4ad6c32d9ef5 --- /dev/null +++ b/devtools/client/inspector/boxmodel/utils/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'editing-session.js', +) diff --git a/devtools/client/inspector/layout/actions/index.js b/devtools/client/inspector/layout/actions/index.js index d694e37400a2..bf11969f238b 100644 --- a/devtools/client/inspector/layout/actions/index.js +++ b/devtools/client/inspector/layout/actions/index.js @@ -17,9 +17,6 @@ createEnum([ // Update the entire grids state with the new list of grids. "UPDATE_GRIDS", - // Update the layout state with the latest layout properties. - "UPDATE_LAYOUT", - // Update the grid highlighter's show grid line numbers state. "UPDATE_SHOW_GRID_LINE_NUMBERS", diff --git a/devtools/client/inspector/layout/actions/moz.build b/devtools/client/inspector/layout/actions/moz.build index 5e157a4bd728..09b7039d19de 100644 --- a/devtools/client/inspector/layout/actions/moz.build +++ b/devtools/client/inspector/layout/actions/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'box-model.js', 'grids.js', 'highlighter-settings.js', 'index.js', diff --git a/devtools/client/inspector/layout/components/moz.build b/devtools/client/inspector/layout/components/moz.build index 7ad90ba4572b..551eaa5eda51 100644 --- a/devtools/client/inspector/layout/components/moz.build +++ b/devtools/client/inspector/layout/components/moz.build @@ -8,12 +8,6 @@ DevToolsModules( 'Accordion.css', 'Accordion.js', 'App.js', - 'BoxModel.js', - 'BoxModelEditable.js', - 'BoxModelInfo.js', - 'BoxModelMain.js', - 'BoxModelProperties.js', - 'ComputedProperty.js', 'Grid.js', 'GridDisplaySettings.js', 'GridItem.js', diff --git a/devtools/client/inspector/layout/reducers/moz.build b/devtools/client/inspector/layout/reducers/moz.build index 50e631af17b1..34867f4e837f 100644 --- a/devtools/client/inspector/layout/reducers/moz.build +++ b/devtools/client/inspector/layout/reducers/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'box-model.js', 'grids.js', 'highlighter-settings.js', ) diff --git a/devtools/client/inspector/layout/types.js b/devtools/client/inspector/layout/types.js index b9c286200ca0..0c0cd3b77473 100644 --- a/devtools/client/inspector/layout/types.js +++ b/devtools/client/inspector/layout/types.js @@ -6,16 +6,6 @@ const { PropTypes } = require("devtools/client/shared/vendor/react"); -/** - * The box model data for the current selected node. - */ -exports.boxModel = { - - // The layout information of the current selected node - layout: PropTypes.object, - -}; - /** * A single grid container in the document. */ diff --git a/devtools/client/inspector/layout/utils/moz.build b/devtools/client/inspector/layout/utils/moz.build index 537f779cc3cb..e3053b63fab6 100644 --- a/devtools/client/inspector/layout/utils/moz.build +++ b/devtools/client/inspector/layout/utils/moz.build @@ -5,6 +5,5 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'editing-session.js', 'l10n.js', ) diff --git a/devtools/client/inspector/moz.build b/devtools/client/inspector/moz.build index 1c5f3e58dd4c..8f1679fd2b39 100644 --- a/devtools/client/inspector/moz.build +++ b/devtools/client/inspector/moz.build @@ -3,6 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += [ + 'boxmodel', 'components', 'computed', 'fonts', diff --git a/devtools/client/inspector/reducers.js b/devtools/client/inspector/reducers.js index 6c09e49c49e4..a6818664560e 100644 --- a/devtools/client/inspector/reducers.js +++ b/devtools/client/inspector/reducers.js @@ -7,6 +7,6 @@ // This file exposes the Redux reducers of the box model, grid and grid highlighter // settings. -exports.boxModel = require("devtools/client/inspector/layout/reducers/box-model"); +exports.boxModel = require("devtools/client/inspector/boxmodel/reducers/box-model"); exports.grids = require("devtools/client/inspector/layout/reducers/grids"); exports.highlighterSettings = require("devtools/client/inspector/layout/reducers/highlighter-settings"); From a8e907805f0d89c5f96f99dfbc5eee132265421c Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 00:45:24 +0100 Subject: [PATCH 076/102] Bug 1336198 - Part 7: Refactor box model logic into box-model.js. r=jdescottes MozReview-Commit-ID: C4DMNTYoTU --- .../client/inspector/boxmodel/box-model.js | 285 ++++++++++++++++++ devtools/client/inspector/boxmodel/moz.build | 1 + devtools/client/inspector/inspector.js | 2 + .../client/inspector/layout/components/App.js | 3 +- devtools/client/inspector/layout/layout.js | 213 +------------ devtools/client/shared/browser-loader.js | 1 + 6 files changed, 301 insertions(+), 204 deletions(-) create mode 100644 devtools/client/inspector/boxmodel/box-model.js diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js new file mode 100644 index 000000000000..9edf3164c9c9 --- /dev/null +++ b/devtools/client/inspector/boxmodel/box-model.js @@ -0,0 +1,285 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { Task } = require("devtools/shared/task"); +const { getCssProperties } = require("devtools/shared/fronts/css-properties"); +const { ReflowFront } = require("devtools/shared/fronts/reflow"); + +const { InplaceEditor } = require("devtools/client/shared/inplace-editor"); + +const { updateLayout } = require("./actions/box-model"); + +const EditingSession = require("./utils/editing-session"); + +const NUMERIC = /^-?[\d\.]+$/; + +/** + * A singleton instance of the box model controllers. + * + * @param {Inspector} inspector + * An instance of the Inspector currently loaded in the toolbox. + * @param {Window} window + * The document window of the toolbox. + */ +function BoxModel(inspector, window) { + this.document = window.document; + this.inspector = inspector; + this.store = inspector.store; + + this.updateBoxModel = this.updateBoxModel.bind(this); + + this.onHideBoxModelHighlighter = this.onHideBoxModelHighlighter.bind(this); + this.onNewSelection = this.onNewSelection.bind(this); + this.onShowBoxModelEditor = this.onShowBoxModelEditor.bind(this); + this.onShowBoxModelHighlighter = this.onShowBoxModelHighlighter.bind(this); + this.onSidebarSelect = this.onSidebarSelect.bind(this); + + this.inspector.selection.on("new-node-front", this.onNewSelection); + this.inspector.sidebar.on("select", this.onSidebarSelect); +} + +BoxModel.prototype = { + + /** + * Destruction function called when the inspector is destroyed. Removes event listeners + * and cleans up references. + */ + destroy() { + this.inspector.selection.off("new-node-front", this.onNewSelection); + this.inspector.sidebar.off("select", this.onSidebarSelect); + + if (this.reflowFront) { + this.untrackReflows(); + this.reflowFront.destroy(); + this.reflowFront = null; + } + + this.document = null; + this.inspector = null; + this.walker = null; + }, + + /** + * Returns an object containing the box model's handler functions used in the box + * model's React component props. + */ + getComponentProps() { + return { + onHideBoxModelHighlighter: this.onHideBoxModelHighlighter, + onShowBoxModelEditor: this.onShowBoxModelEditor, + onShowBoxModelHighlighter: this.onShowBoxModelHighlighter, + }; + }, + + /** + * Returns true if the layout panel is visible, and false otherwise. + */ + isPanelVisible() { + return this.inspector.toolbox.currentToolId === "inspector" && + this.inspector.sidebar && + this.inspector.sidebar.getCurrentTabID() === "layoutview"; + }, + + /** + * Returns true if the layout panel is visible and the current node is valid to + * be displayed in the view. + */ + isPanelVisibleAndNodeValid() { + return this.isPanelVisible() && + this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode(); + }, + + /** + * Starts listening to reflows in the current tab. + */ + trackReflows() { + if (!this.reflowFront) { + let { target } = this.inspector; + if (target.form.reflowActor) { + this.reflowFront = ReflowFront(target.client, + target.form); + } else { + return; + } + } + + this.reflowFront.on("reflows", this.updateBoxModel); + this.reflowFront.start(); + }, + + /** + * Stops listening to reflows in the current tab. + */ + untrackReflows() { + if (!this.reflowFront) { + return; + } + + this.reflowFront.off("reflows", this.updateBoxModel); + this.reflowFront.stop(); + }, + + /** + * Updates the box model panel by dispatching the new layout data. + */ + updateBoxModel() { + let lastRequest = Task.spawn((function* () { + if (!(this.isPanelVisible() && + this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode())) { + return null; + } + + let node = this.inspector.selection.nodeFront; + let layout = yield this.inspector.pageStyle.getLayout(node, { + autoMargins: true, + }); + let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); + this.elementRules = styleEntries.map(e => e.rule); + + // Update the redux store with the latest layout properties and update the box + // model view. + this.store.dispatch(updateLayout(layout)); + + // If a subsequent request has been made, wait for that one instead. + if (this._lastRequest != lastRequest) { + return this._lastRequest; + } + + this._lastRequest = null; + + this.inspector.emit("boxmodel-view-updated"); + return null; + }).bind(this)).catch(console.error); + + this._lastRequest = lastRequest; + }, + + /** + * Selection 'new-node-front' event handler. + */ + onNewSelection: function () { + if (!this.isPanelVisibleAndNodeValid()) { + return; + } + + this.updateBoxModel(); + }, + + /** + * Hides the box-model highlighter on the currently selected element. + */ + onHideBoxModelHighlighter() { + let toolbox = this.inspector.toolbox; + toolbox.highlighterUtils.unhighlight(); + }, + + /** + * Shows the inplace editor when a box model editable value is clicked on the + * box model panel. + * + * @param {DOMNode} element + * The element that was clicked. + * @param {Event} event + * The event object. + * @param {String} property + * The name of the property. + */ + onShowBoxModelEditor(element, event, property) { + let session = new EditingSession({ + inspector: this.inspector, + doc: this.document, + elementRules: this.elementRules, + }); + let initialValue = session.getProperty(property); + + let editor = new InplaceEditor({ + element: element, + initial: initialValue, + contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, + property: { + name: property + }, + start: self => { + self.elt.parentNode.classList.add("boxmodel-editing"); + }, + change: value => { + if (NUMERIC.test(value)) { + value += "px"; + } + + let properties = [ + { name: property, value: value } + ]; + + if (property.substring(0, 7) == "border-") { + let bprop = property.substring(0, property.length - 5) + "style"; + let style = session.getProperty(bprop); + if (!style || style == "none" || style == "hidden") { + properties.push({ name: bprop, value: "solid" }); + } + } + + session.setProperties(properties).catch(e => console.error(e)); + }, + done: (value, commit) => { + editor.elt.parentNode.classList.remove("boxmodel-editing"); + if (!commit) { + session.revert().then(() => { + session.destroy(); + }, e => console.error(e)); + return; + } + + let node = this.inspector.selection.nodeFront; + this.inspector.pageStyle.getLayout(node, { + autoMargins: true, + }).then(layout => { + this.store.dispatch(updateLayout(layout)); + }, e => console.error(e)); + }, + contextMenu: this.inspector.onTextBoxContextMenu, + cssProperties: getCssProperties(this.inspector.toolbox) + }, event); + }, + + /** + * Shows the box-model highlighter on the currently selected element. + * + * @param {Object} options + * Options passed to the highlighter actor. + */ + onShowBoxModelHighlighter(options = {}) { + let toolbox = this.inspector.toolbox; + let nodeFront = this.inspector.selection.nodeFront; + + toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); + }, + + /** + * Handler for the inspector sidebar select event. Starts listening for + * "grid-layout-changed" if the layout panel is visible. Otherwise, stop + * listening for grid layout changes. Finally, refresh the layout view if + * it is visible. + */ + onSidebarSelect() { + if (!this.isPanelVisible()) { + this.untrackReflows(); + return; + } + + if (this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode()) { + this.trackReflows(); + } + + this.updateBoxModel(); + }, + +}; + +module.exports = BoxModel; diff --git a/devtools/client/inspector/boxmodel/moz.build b/devtools/client/inspector/boxmodel/moz.build index eeb9697a60cb..07b54256bdd3 100644 --- a/devtools/client/inspector/boxmodel/moz.build +++ b/devtools/client/inspector/boxmodel/moz.build @@ -12,5 +12,6 @@ DIRS += [ ] DevToolsModules( + 'box-model.js', 'types.js', ) diff --git a/devtools/client/inspector/inspector.js b/devtools/client/inspector/inspector.js index 1e9af044f029..c77a4bb6daed 100644 --- a/devtools/client/inspector/inspector.js +++ b/devtools/client/inspector/inspector.js @@ -23,6 +23,7 @@ const Menu = require("devtools/client/framework/menu"); const MenuItem = require("devtools/client/framework/menu-item"); const {HTMLBreadcrumbs} = require("devtools/client/inspector/breadcrumbs"); +const BoxModelView = require("devtools/client/inspector/boxmodel/box-model"); const {ComputedViewTool} = require("devtools/client/inspector/computed/computed"); const {FontInspector} = require("devtools/client/inspector/fonts/fonts"); const {InspectorSearch} = require("devtools/client/inspector/inspector-search"); @@ -573,6 +574,7 @@ Inspector.prototype = { this.ruleview = new RuleViewTool(this, this.panelWin); this.computedview = new ComputedViewTool(this, this.panelWin); + this.boxmodelview = new BoxModelView(this, this.panelWin); if (Services.prefs.getBoolPref("devtools.layoutview.enabled")) { const LayoutView = this.browserRequire("devtools/client/inspector/layout/layout"); diff --git a/devtools/client/inspector/layout/components/App.js b/devtools/client/inspector/layout/components/App.js index d8dd19582d0c..cbcb2bebc271 100644 --- a/devtools/client/inspector/layout/components/App.js +++ b/devtools/client/inspector/layout/components/App.js @@ -11,9 +11,10 @@ const { connect } = require("devtools/client/shared/vendor/react-redux"); const { LocalizationHelper } = require("devtools/shared/l10n"); const Accordion = createFactory(require("./Accordion")); -const BoxModel = createFactory(require("./BoxModel")); const Grid = createFactory(require("./Grid")); +const BoxModel = createFactory(require("devtools/client/inspector/boxmodel/components/BoxModel")); + const Types = require("../types"); const { getStr } = require("../utils/l10n"); diff --git a/devtools/client/inspector/layout/layout.js b/devtools/client/inspector/layout/layout.js index d9c6ba201be7..91ccd4b2402c 100644 --- a/devtools/client/inspector/layout/layout.js +++ b/devtools/client/inspector/layout/layout.js @@ -6,18 +6,12 @@ const Services = require("Services"); const { Task } = require("devtools/shared/task"); -const { getCssProperties } = require("devtools/shared/fronts/css-properties"); -const { ReflowFront } = require("devtools/shared/fronts/reflow"); -const { InplaceEditor } = require("devtools/client/shared/inplace-editor"); const { createFactory, createElement } = require("devtools/client/shared/vendor/react"); const { Provider } = require("devtools/client/shared/vendor/react-redux"); const SwatchColorPickerTooltip = require("devtools/client/shared/widgets/tooltip/SwatchColorPickerTooltip"); -const { - updateLayout, -} = require("./actions/box-model"); const { updateGridColor, updateGridHighlighted, @@ -30,13 +24,10 @@ const { const App = createFactory(require("./components/App")); -const EditingSession = require("./utils/editing-session"); - const { LocalizationHelper } = require("devtools/shared/l10n"); const INSPECTOR_L10N = new LocalizationHelper("devtools/client/locales/inspector.properties"); -const NUMERIC = /^-?[\d\.]+$/; const SHOW_GRID_LINE_NUMBERS = "devtools.gridinspector.showGridLineNumbers"; const SHOW_INFINITE_LINES_PREF = "devtools.gridinspector.showInfiniteLines"; @@ -59,11 +50,8 @@ function LayoutView(inspector, window) { this.store = inspector.store; this.walker = this.inspector.walker; - this.updateBoxModel = this.updateBoxModel.bind(this); - this.onGridLayoutChange = this.onGridLayoutChange.bind(this); this.onHighlighterChange = this.onHighlighterChange.bind(this); - this.onNewSelection = this.onNewSelection.bind(this); this.onSidebarSelect = this.onSidebarSelect.bind(this); this.init(); @@ -80,13 +68,18 @@ LayoutView.prototype = { return; } + let { + onHideBoxModelHighlighter, + onShowBoxModelEditor, + onShowBoxModelHighlighter, + } = this.inspector.boxmodelview.getComponentProps(); + this.layoutInspector = yield this.inspector.walker.getLayoutInspector(); this.loadHighlighterSettings(); this.highlighters.on("grid-highlighter-hidden", this.onHighlighterChange); this.highlighters.on("grid-highlighter-shown", this.onHighlighterChange); - this.inspector.selection.on("new-node-front", this.onNewSelection); this.inspector.sidebar.on("select", this.onSidebarSelect); // Create a shared SwatchColorPicker instance to be reused by all GridItem components. @@ -112,13 +105,10 @@ LayoutView.prototype = { */ showBoxModelProperties: true, - /** - * Hides the box-model highlighter on the currently selected element. - */ - onHideBoxModelHighlighter: () => { - let toolbox = this.inspector.toolbox; - toolbox.highlighterUtils.unhighlight(); - }, + onHideBoxModelHighlighter: () => onHideBoxModelHighlighter(), + onShowBoxModelEditor: (element, event, property) => + onShowBoxModelEditor(element, event, property), + onShowBoxModelHighlighter: (options = {}) => onShowBoxModelHighlighter(options), /** * Handler for a change in the grid overlay color picker for a grid container. @@ -143,88 +133,6 @@ LayoutView.prototype = { } }, - /** - * Shows the inplace editor when a box model editable value is clicked on the - * box model panel. - * - * @param {DOMNode} element - * The element that was clicked. - * @param {Event} event - * The event object. - * @param {String} property - * The name of the property. - */ - onShowBoxModelEditor: (element, event, property) => { - let session = new EditingSession({ - inspector: this.inspector, - doc: this.document, - elementRules: this.elementRules, - }); - let initialValue = session.getProperty(property); - - let editor = new InplaceEditor({ - element: element, - initial: initialValue, - contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, - property: { - name: property - }, - start: self => { - self.elt.parentNode.classList.add("boxmodel-editing"); - }, - change: value => { - if (NUMERIC.test(value)) { - value += "px"; - } - - let properties = [ - { name: property, value: value } - ]; - - if (property.substring(0, 7) == "border-") { - let bprop = property.substring(0, property.length - 5) + "style"; - let style = session.getProperty(bprop); - if (!style || style == "none" || style == "hidden") { - properties.push({ name: bprop, value: "solid" }); - } - } - - session.setProperties(properties).catch(e => console.error(e)); - }, - done: (value, commit) => { - editor.elt.parentNode.classList.remove("boxmodel-editing"); - if (!commit) { - session.revert().then(() => { - session.destroy(); - }, e => console.error(e)); - return; - } - - let node = this.inspector.selection.nodeFront; - this.inspector.pageStyle.getLayout(node, { - autoMargins: true, - }).then(layout => { - this.store.dispatch(updateLayout(layout)); - }, e => console.error(e)); - }, - contextMenu: this.inspector.onTextBoxContextMenu, - cssProperties: getCssProperties(this.inspector.toolbox) - }, event); - }, - - /** - * Shows the box-model highlighter on the currently selected element. - * - * @param {Object} options - * Options passed to the highlighter actor. - */ - onShowBoxModelHighlighter: (options = {}) => { - let toolbox = this.inspector.toolbox; - let nodeFront = this.inspector.selection.nodeFront; - - toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); - }, - /** * Handler for a change in the input checkboxes in the GridList component. * Toggles on/off the grid highlighter for the provided grid container element. @@ -309,16 +217,9 @@ LayoutView.prototype = { destroy() { this.highlighters.off("grid-highlighter-hidden", this.onHighlighterChange); this.highlighters.off("grid-highlighter-shown", this.onHighlighterChange); - this.inspector.selection.off("new-node-front", this.onNewSelection); this.inspector.sidebar.off("select", this.onSidebarSelect); this.layoutInspector.off("grid-layout-changed", this.onGridLayoutChange); - if (this.reflowFront) { - this.untrackReflows(); - this.reflowFront.destroy(); - this.reflowFront = null; - } - this.document = null; this.inspector = null; this.layoutInspector = null; @@ -372,16 +273,6 @@ LayoutView.prototype = { this.inspector.sidebar.getCurrentTabID() === "layoutview"; }, - /** - * Returns true if the layout panel is visible and the current node is valid to - * be displayed in the view. - */ - isPanelVisibleAndNodeValid() { - return this.isPanelVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode(); - }, - /** * Load the grid highligher display settings into the store from the stored preferences. */ @@ -395,72 +286,6 @@ LayoutView.prototype = { dispatch(updateShowInfiniteLines(showInfinteLines)); }, - /** - * Starts listening to reflows in the current tab. - */ - trackReflows() { - if (!this.reflowFront) { - let { target } = this.inspector; - if (target.form.reflowActor) { - this.reflowFront = ReflowFront(target.client, - target.form); - } else { - return; - } - } - - this.reflowFront.on("reflows", this.updateBoxModel); - this.reflowFront.start(); - }, - - /** - * Stops listening to reflows in the current tab. - */ - untrackReflows() { - if (!this.reflowFront) { - return; - } - - this.reflowFront.off("reflows", this.updateBoxModel); - this.reflowFront.stop(); - }, - - /** - * Updates the box model panel by dispatching the new layout data. - */ - updateBoxModel() { - let lastRequest = Task.spawn((function* () { - if (!(this.isPanelVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode())) { - return null; - } - - let node = this.inspector.selection.nodeFront; - let layout = yield this.inspector.pageStyle.getLayout(node, { - autoMargins: true, - }); - let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); - this.elementRules = styleEntries.map(e => e.rule); - - // Update the redux store with the latest layout properties and update the box - // model view. - this.store.dispatch(updateLayout(layout)); - - // If a subsequent request has been made, wait for that one instead. - if (this._lastRequest != lastRequest) { - return this._lastRequest; - } - - this._lastRequest = null; - - this.inspector.emit("boxmodel-view-updated"); - return null; - }).bind(this)).catch(console.error); - - this._lastRequest = lastRequest; - }, - /** * Updates the grid panel by dispatching the new grid data. This is called when the * layout view becomes visible or the view needs to be updated with new grid data. @@ -526,17 +351,6 @@ LayoutView.prototype = { this.store.dispatch(updateGridHighlighted(nodeFront, highlighted)); }, - /** - * Selection 'new-node-front' event handler. - */ - onNewSelection: function () { - if (!this.isPanelVisibleAndNodeValid()) { - return; - } - - this.updateBoxModel(); - }, - /** * Handler for the inspector sidebar select event. Starts listening for * "grid-layout-changed" if the layout panel is visible. Otherwise, stop @@ -546,17 +360,10 @@ LayoutView.prototype = { onSidebarSelect() { if (!this.isPanelVisible()) { this.layoutInspector.off("grid-layout-changed", this.onGridLayoutChange); - this.untrackReflows(); return; } - if (this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode()) { - this.trackReflows(); - } - this.layoutInspector.on("grid-layout-changed", this.onGridLayoutChange); - this.updateBoxModel(); this.updateGridPanel(); }, diff --git a/devtools/client/shared/browser-loader.js b/devtools/client/shared/browser-loader.js index ab7505beee9b..e21a899044a3 100644 --- a/devtools/client/shared/browser-loader.js +++ b/devtools/client/shared/browser-loader.js @@ -12,6 +12,7 @@ const Services = devtools.require("Services"); const { AppConstants } = devtools.require("resource://gre/modules/AppConstants.jsm"); const BROWSER_BASED_DIRS = [ + "resource://devtools/client/inspector/boxmodel", "resource://devtools/client/inspector/layout", "resource://devtools/client/jsonview", "resource://devtools/client/shared/vendor", From 5980eb0bb7e4a725c1eafdb18d8922c5494d2410 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Thu, 16 Feb 2017 15:50:59 +0100 Subject: [PATCH 077/102] Bug 1336198 - Part 8: Use the react/redux box model in the computed view. r=jdescottes MozReview-Commit-ID: 8D53vJG3zda --- .../client/inspector/boxmodel/box-model.js | 10 +++- .../boxmodel/components/BoxModelApp.js | 51 +++++++++++++++++++ .../inspector/boxmodel/components/moz.build | 1 + .../client/inspector/computed/computed.js | 32 ++++++++++++ devtools/client/inspector/inspector.js | 5 +- devtools/client/shared/browser-loader.js | 1 + 6 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 devtools/client/inspector/boxmodel/components/BoxModelApp.js diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js index 9edf3164c9c9..839b608f5ca2 100644 --- a/devtools/client/inspector/boxmodel/box-model.js +++ b/devtools/client/inspector/boxmodel/box-model.js @@ -75,12 +75,13 @@ BoxModel.prototype = { }, /** - * Returns true if the layout panel is visible, and false otherwise. + * Returns true if the computed or layout panel is visible, and false otherwise. */ isPanelVisible() { return this.inspector.toolbox.currentToolId === "inspector" && this.inspector.sidebar && - this.inspector.sidebar.getCurrentTabID() === "layoutview"; + (this.inspector.sidebar.getCurrentTabID() === "layoutview" || + this.inspector.sidebar.getCurrentTabID() === "computedview"); }, /** @@ -167,6 +168,11 @@ BoxModel.prototype = { return; } + if (this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode()) { + this.trackReflows(); + } + this.updateBoxModel(); }, diff --git a/devtools/client/inspector/boxmodel/components/BoxModelApp.js b/devtools/client/inspector/boxmodel/components/BoxModelApp.js new file mode 100644 index 000000000000..2af27ac77c2f --- /dev/null +++ b/devtools/client/inspector/boxmodel/components/BoxModelApp.js @@ -0,0 +1,51 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { addons, createClass, createFactory, PropTypes } = + require("devtools/client/shared/vendor/react"); +const { connect } = require("devtools/client/shared/vendor/react-redux"); + +const { LocalizationHelper } = require("devtools/shared/l10n"); + +const Accordion = + createFactory(require("devtools/client/inspector/layout/components/Accordion")); +const BoxModel = createFactory(require("./BoxModel")); + +const Types = require("../types"); + +const BOXMODEL_STRINGS_URI = "devtools/client/locales/boxmodel.properties"; +const BOXMODEL_L10N = new LocalizationHelper(BOXMODEL_STRINGS_URI); + +const BoxModelApp = createClass({ + + displayName: "BoxModelApp", + + propTypes: { + boxModel: PropTypes.shape(Types.boxModel).isRequired, + showBoxModelProperties: PropTypes.bool.isRequired, + onHideBoxModelHighlighter: PropTypes.func.isRequired, + onShowBoxModelEditor: PropTypes.func.isRequired, + onShowBoxModelHighlighter: PropTypes.func.isRequired, + }, + + mixins: [ addons.PureRenderMixin ], + + render() { + return Accordion({ + items: [ + { + header: BOXMODEL_L10N.getStr("boxmodel.title"), + component: BoxModel, + componentProps: this.props, + opened: true, + } + ] + }); + }, + +}); + +module.exports = connect(state => state)(BoxModelApp); diff --git a/devtools/client/inspector/boxmodel/components/moz.build b/devtools/client/inspector/boxmodel/components/moz.build index 562fd1a2cba8..02638ae7b291 100644 --- a/devtools/client/inspector/boxmodel/components/moz.build +++ b/devtools/client/inspector/boxmodel/components/moz.build @@ -6,6 +6,7 @@ DevToolsModules( 'BoxModel.js', + 'BoxModelApp.js', 'BoxModelEditable.js', 'BoxModelInfo.js', 'BoxModelMain.js', diff --git a/devtools/client/inspector/computed/computed.js b/devtools/client/inspector/computed/computed.js index 54c543c672ad..55fc88c4f916 100644 --- a/devtools/client/inspector/computed/computed.js +++ b/devtools/client/inspector/computed/computed.js @@ -28,6 +28,12 @@ const TooltipsOverlay = require("devtools/client/inspector/shared/tooltips-overl const KeyShortcuts = require("devtools/client/shared/key-shortcuts"); const clipboardHelper = require("devtools/shared/platform/clipboard"); +const { createElement, createFactory } = require("devtools/client/shared/vendor/react"); +const ReactDOM = require("devtools/client/shared/vendor/react-dom"); +const { Provider } = require("devtools/client/shared/vendor/react-redux"); + +const BoxModelApp = createFactory(require("devtools/client/inspector/boxmodel/components/BoxModelApp")); + const STYLE_INSPECTOR_PROPERTIES = "devtools/shared/locales/styleinspector.properties"; const {LocalizationHelper} = require("devtools/shared/l10n"); const STYLE_INSPECTOR_L10N = new LocalizationHelper(STYLE_INSPECTOR_PROPERTIES); @@ -153,6 +159,7 @@ UpdateProcess.prototype = { function CssComputedView(inspector, document, pageStyle) { this.inspector = inspector; this.highlighters = inspector.highlighters; + this.store = inspector.store; this.styleDocument = document; this.styleWindow = this.styleDocument.defaultView; this.pageStyle = pageStyle; @@ -208,6 +215,7 @@ function CssComputedView(inspector, document, pageStyle) { // The element that we're inspecting, and the document that it comes from. this._viewedElement = null; + this.createBoxModelView(); this.createStyleViews(); this._contextmenu = new StyleInspectorMenu(this, { isRuleView: false }); @@ -604,6 +612,29 @@ CssComputedView.prototype = { this.inspector.emit("computed-view-sourcelinks-updated"); }, + /** + * Render the box model view. + */ + createBoxModelView: function () { + let { + onHideBoxModelHighlighter, + onShowBoxModelEditor, + onShowBoxModelHighlighter, + } = this.inspector.boxmodelview.getComponentProps(); + + let provider = createElement( + Provider, + { store: this.store }, + BoxModelApp({ + showBoxModelProperties: false, + onHideBoxModelHighlighter, + onShowBoxModelEditor, + onShowBoxModelHighlighter, + }) + ); + ReactDOM.render(provider, this.styleDocument.getElementById("boxmodel-wrapper")); + }, + /** * The CSS as displayed by the UI. */ @@ -795,6 +826,7 @@ CssComputedView.prototype = { this.inspector = null; this.highlighters = null; + this.store = null; this.styleDocument = null; this.styleWindow = null; diff --git a/devtools/client/inspector/inspector.js b/devtools/client/inspector/inspector.js index c77a4bb6daed..7b251be95c84 100644 --- a/devtools/client/inspector/inspector.js +++ b/devtools/client/inspector/inspector.js @@ -24,7 +24,6 @@ const MenuItem = require("devtools/client/framework/menu-item"); const {HTMLBreadcrumbs} = require("devtools/client/inspector/breadcrumbs"); const BoxModelView = require("devtools/client/inspector/boxmodel/box-model"); -const {ComputedViewTool} = require("devtools/client/inspector/computed/computed"); const {FontInspector} = require("devtools/client/inspector/fonts/fonts"); const {InspectorSearch} = require("devtools/client/inspector/inspector-search"); const {RuleViewTool} = require("devtools/client/inspector/rules/rules"); @@ -573,8 +572,10 @@ Inspector.prototype = { defaultTab == "computedview"); this.ruleview = new RuleViewTool(this, this.panelWin); - this.computedview = new ComputedViewTool(this, this.panelWin); this.boxmodelview = new BoxModelView(this, this.panelWin); + const {ComputedViewTool} = + this.browserRequire("devtools/client/inspector/computed/computed"); + this.computedview = new ComputedViewTool(this, this.panelWin); if (Services.prefs.getBoolPref("devtools.layoutview.enabled")) { const LayoutView = this.browserRequire("devtools/client/inspector/layout/layout"); diff --git a/devtools/client/shared/browser-loader.js b/devtools/client/shared/browser-loader.js index e21a899044a3..3aef74a99bf9 100644 --- a/devtools/client/shared/browser-loader.js +++ b/devtools/client/shared/browser-loader.js @@ -13,6 +13,7 @@ const { AppConstants } = devtools.require("resource://gre/modules/AppConstants.j const BROWSER_BASED_DIRS = [ "resource://devtools/client/inspector/boxmodel", + "resource://devtools/client/inspector/computed", "resource://devtools/client/inspector/layout", "resource://devtools/client/jsonview", "resource://devtools/client/shared/vendor", From bdd771f1bcdc922650c03952faf8e3cc38503c01 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 22 Feb 2017 19:26:57 +0100 Subject: [PATCH 078/102] Bug 1336198 - Part 9: Use existing box model tests with the new react/redux box model. r=jdescottes MozReview-Commit-ID: HrqeP2X35t --- .../boxmodel/components/BoxModelMain.js | 24 ++++++-- devtools/client/inspector/boxmodel/moz.build | 2 + .../test/.eslintrc.js | 0 .../{components => boxmodel}/test/browser.ini | 2 + .../test/browser_boxmodel.js | 60 +++++++++---------- .../test/browser_boxmodel_editablemodel.js | 58 +++++++++--------- ...er_boxmodel_editablemodel_allproperties.js | 40 ++++++------- ...wser_boxmodel_editablemodel_bluronclick.js | 24 ++++---- .../browser_boxmodel_editablemodel_border.js | 10 ++-- ...owser_boxmodel_editablemodel_stylerules.js | 32 +++++----- .../test/browser_boxmodel_guides.js | 8 +-- .../test/browser_boxmodel_navigation.js | 26 ++++---- ...browser_boxmodel_rotate-labels-on-sides.js | 49 +++++++++++++++ .../test/browser_boxmodel_sync.js | 10 ++-- .../test/browser_boxmodel_tooltips.js | 18 +++--- ...rowser_boxmodel_update-after-navigation.js | 13 ++-- .../browser_boxmodel_update-after-reload.js | 5 +- .../browser_boxmodel_update-in-iframes.js | 4 +- .../test/doc_boxmodel_iframe1.html | 0 .../test/doc_boxmodel_iframe2.html | 0 .../{components => boxmodel}/test/head.js | 13 +++- .../client/inspector/components/moz.build | 2 - ...browser_boxmodel_rotate-labels-on-sides.js | 49 --------------- .../client/inspector/computed/computed.js | 9 +-- .../test/browser_computed_search-filter.js | 2 +- .../browser_computed_search-filter_clear.js | 2 +- devtools/client/inspector/inspector.js | 2 - .../test/browser_inspector_textbox-menu.js | 2 +- 28 files changed, 245 insertions(+), 221 deletions(-) rename devtools/client/inspector/{components => boxmodel}/test/.eslintrc.js (100%) rename devtools/client/inspector/{components => boxmodel}/test/browser.ini (94%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel.js (58%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel.js (74%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_allproperties.js (74%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_bluronclick.js (69%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_border.js (82%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_stylerules.js (74%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_guides.js (89%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_navigation.js (75%) create mode 100644 devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_sync.js (77%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_tooltips.js (83%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_update-after-navigation.js (88%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_update-after-reload.js (90%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_update-in-iframes.js (96%) rename devtools/client/inspector/{components => boxmodel}/test/doc_boxmodel_iframe1.html (100%) rename devtools/client/inspector/{components => boxmodel}/test/doc_boxmodel_iframe2.html (100%) rename devtools/client/inspector/{components => boxmodel}/test/head.js (86%) delete mode 100644 devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js diff --git a/devtools/client/inspector/boxmodel/components/BoxModelMain.js b/devtools/client/inspector/boxmodel/components/BoxModelMain.js index 42baa7427453..a3980c79d104 100644 --- a/devtools/client/inspector/boxmodel/components/BoxModelMain.js +++ b/devtools/client/inspector/boxmodel/components/BoxModelMain.js @@ -37,7 +37,23 @@ module.exports = createClass({ return layout[property] ? parseFloat(layout[property]) : "-"; }, - getHeightOrWidthValue(property) { + getHeightValue(property) { + let { layout } = this.props.boxModel; + + if (property == undefined) { + return "-"; + } + + property -= parseFloat(layout["border-top-width"]) + + parseFloat(layout["border-bottom-width"]) + + parseFloat(layout["padding-top"]) + + parseFloat(layout["padding-bottom"]); + property = parseFloat(property.toPrecision(6)); + + return property; + }, + + getWidthValue(property) { let { layout } = this.props.boxModel; if (property == undefined) { @@ -83,7 +99,7 @@ module.exports = createClass({ render() { let { boxModel, onShowBoxModelEditor } = this.props; let { layout } = boxModel; - let { width, height } = layout; + let { height, width } = layout; let borderTop = this.getBorderOrPaddingValue("border-top-width"); let borderRight = this.getBorderOrPaddingValue("border-right-width"); @@ -100,8 +116,8 @@ module.exports = createClass({ let marginBottom = this.getMarginValue("margin-bottom", "bottom"); let marginLeft = this.getMarginValue("margin-left", "left"); - width = this.getHeightOrWidthValue(width); - height = this.getHeightOrWidthValue(height); + height = this.getHeightValue(height); + width = this.getWidthValue(width); return dom.div( { diff --git a/devtools/client/inspector/boxmodel/moz.build b/devtools/client/inspector/boxmodel/moz.build index 07b54256bdd3..6ef44c80c361 100644 --- a/devtools/client/inspector/boxmodel/moz.build +++ b/devtools/client/inspector/boxmodel/moz.build @@ -15,3 +15,5 @@ DevToolsModules( 'box-model.js', 'types.js', ) + +BROWSER_CHROME_MANIFESTS += ['test/browser.ini'] diff --git a/devtools/client/inspector/components/test/.eslintrc.js b/devtools/client/inspector/boxmodel/test/.eslintrc.js similarity index 100% rename from devtools/client/inspector/components/test/.eslintrc.js rename to devtools/client/inspector/boxmodel/test/.eslintrc.js diff --git a/devtools/client/inspector/components/test/browser.ini b/devtools/client/inspector/boxmodel/test/browser.ini similarity index 94% rename from devtools/client/inspector/components/test/browser.ini rename to devtools/client/inspector/boxmodel/test/browser.ini index be937ecfd3d7..c9881c903937 100644 --- a/devtools/client/inspector/components/test/browser.ini +++ b/devtools/client/inspector/boxmodel/test/browser.ini @@ -21,9 +21,11 @@ support-files = [browser_boxmodel_editablemodel_stylerules.js] [browser_boxmodel_guides.js] [browser_boxmodel_navigation.js] +skip-if = true # Bug 1336198 [browser_boxmodel_rotate-labels-on-sides.js] [browser_boxmodel_sync.js] [browser_boxmodel_tooltips.js] +skip-if = true # Bug 1336198 [browser_boxmodel_update-after-navigation.js] [browser_boxmodel_update-after-reload.js] # [browser_boxmodel_update-in-iframes.js] diff --git a/devtools/client/inspector/components/test/browser_boxmodel.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel.js similarity index 58% rename from devtools/client/inspector/components/test/browser_boxmodel.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel.js index d26d9061ce52..9e085cafe232 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel.js @@ -10,118 +10,118 @@ // Expected values: var res1 = [ { - selector: "#old-boxmodel-element-size", + selector: ".boxmodel-element-size", value: "160" + "\u00D7" + "160.117" }, { - selector: ".old-boxmodel-size > span", + selector: ".boxmodel-size > span", value: "100" + "\u00D7" + "100.117" }, { - selector: ".old-boxmodel-margin.old-boxmodel-top > span", + selector: ".boxmodel-margin.boxmodel-top > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-left > span", + selector: ".boxmodel-margin.boxmodel-left > span", value: "auto" }, { - selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", + selector: ".boxmodel-margin.boxmodel-bottom > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-right > span", + selector: ".boxmodel-margin.boxmodel-right > span", value: "auto" }, { - selector: ".old-boxmodel-padding.old-boxmodel-top > span", + selector: ".boxmodel-padding.boxmodel-top > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-left > span", + selector: ".boxmodel-padding.boxmodel-left > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", + selector: ".boxmodel-padding.boxmodel-bottom > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-right > span", + selector: ".boxmodel-padding.boxmodel-right > span", value: 20 }, { - selector: ".old-boxmodel-border.old-boxmodel-top > span", + selector: ".boxmodel-border.boxmodel-top > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-left > span", + selector: ".boxmodel-border.boxmodel-left > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-bottom > span", + selector: ".boxmodel-border.boxmodel-bottom > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-right > span", + selector: ".boxmodel-border.boxmodel-right > span", value: 10 }, ]; var res2 = [ { - selector: "#old-boxmodel-element-size", + selector: ".boxmodel-element-size", value: "190" + "\u00D7" + "210" }, { - selector: ".old-boxmodel-size > span", + selector: ".boxmodel-size > span", value: "100" + "\u00D7" + "150" }, { - selector: ".old-boxmodel-margin.old-boxmodel-top > span", + selector: ".boxmodel-margin.boxmodel-top > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-left > span", + selector: ".boxmodel-margin.boxmodel-left > span", value: "auto" }, { - selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", + selector: ".boxmodel-margin.boxmodel-bottom > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-right > span", + selector: ".boxmodel-margin.boxmodel-right > span", value: "auto" }, { - selector: ".old-boxmodel-padding.old-boxmodel-top > span", + selector: ".boxmodel-padding.boxmodel-top > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-left > span", + selector: ".boxmodel-padding.boxmodel-left > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", + selector: ".boxmodel-padding.boxmodel-bottom > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-right > span", + selector: ".boxmodel-padding.boxmodel-right > span", value: 50 }, { - selector: ".old-boxmodel-border.old-boxmodel-top > span", + selector: ".boxmodel-border.boxmodel-top > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-left > span", + selector: ".boxmodel-border.boxmodel-left > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-bottom > span", + selector: ".boxmodel-border.boxmodel-bottom > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-right > span", + selector: ".boxmodel-border.boxmodel-right > span", value: 10 }, ]; @@ -142,7 +142,7 @@ add_task(function* () { function* testInitialValues(inspector, view) { info("Test that the initial values of the box model are correct"); - let viewdoc = view.doc; + let viewdoc = view.document; for (let i = 0; i < res1.length; i++) { let elt = viewdoc.querySelector(res1[i].selector); @@ -153,7 +153,7 @@ function* testInitialValues(inspector, view) { function* testChangingValues(inspector, view, testActor) { info("Test that changing the document updates the box model"); - let viewdoc = view.doc; + let viewdoc = view.document; let onUpdated = waitForUpdate(inspector); yield testActor.setAttribute("div", "style", diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js similarity index 74% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js index 5bb882dd6e7b..37736152011b 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js @@ -36,21 +36,21 @@ function* testEditingMargins(inspector, view, testActor) { "Should be no margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("3", {}, view.doc.defaultView); + EventUtils.synthesizeKey("3", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-top")), "3px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-top")), "", @@ -66,35 +66,35 @@ function* testKeyBindings(inspector, view, testActor) { "Should be no margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-left > span"); is(span.textContent, 10, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "10px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_UP", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_UP", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "11px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "11px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_DOWN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DOWN", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "10px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "10px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view.doc.defaultView); + EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "20px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", "Should be the right margin-top on the element."); @@ -109,22 +109,22 @@ function* testEscapeToUndo(inspector, view, testActor) { "Should be the right margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-left > span"); is(span.textContent, 20, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "20px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", @@ -140,22 +140,22 @@ function* testDeletingValue(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-right > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-right > span"); is(span.textContent, 15, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "15px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-right")), "", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "margin-right")), "", "Should be the right margin-top on the element."); @@ -167,26 +167,26 @@ function* testRefocusingOnClick(inspector, view, testActor) { yield selectNode("#div4", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 1, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); info("Click in the already opened editor input"); - EventUtils.synthesizeMouseAtCenter(editor, {}, view.doc.defaultView); - is(editor, view.doc.activeElement, + EventUtils.synthesizeMouseAtCenter(editor, {}, view.document.defaultView); + is(editor, view.document.activeElement, "Inplace editor input should still have focus."); info("Check the input can still be used as expected"); - EventUtils.synthesizeKey("VK_UP", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_UP", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "2px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div4", "margin-top")), "2px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div4", "margin-top")), "2px", "Should be the right margin-top on the element."); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js similarity index 74% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js index ca5194266319..ab49a191429c 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js @@ -32,22 +32,22 @@ function* testEditing(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-bottom > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-bottom > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("7", {}, view.doc.defaultView); + EventUtils.synthesizeKey("7", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "7", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-bottom")), "7px", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "padding-bottom")), "7px", "Should be the right padding."); @@ -63,22 +63,22 @@ function* testEditingAndCanceling(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("8", {}, view.doc.defaultView); + EventUtils.synthesizeKey("8", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "8", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "8px", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-left")), "5px", @@ -91,22 +91,22 @@ function* testDeleting(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should be the right padding."); @@ -122,22 +122,22 @@ function* testDeletingAndCanceling(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-left")), "5px", diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js similarity index 69% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js index f56f584ddf95..c251dfbc162f 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js @@ -30,45 +30,45 @@ add_task(function* () { function* testClickingOutsideEditor(view) { info("Test that clicking outside the editor blurs it"); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 10, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); info("Click next to the opened editor input."); let onBlur = once(editor, "blur"); let rect = editor.getBoundingClientRect(); EventUtils.synthesizeMouse(editor, rect.width + 10, rect.height / 2, {}, - view.doc.defaultView); + view.document.defaultView); yield onBlur; - is(view.doc.querySelector(".styleinspector-propertyeditor"), null, + is(view.document.querySelector(".styleinspector-propertyeditor"), null, "Inplace editor has been removed."); } function* testClickingBelowContainer(view) { info("Test that clicking below the box-model container blurs it"); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 10, "Should have the right value in the box model."); - info("Test that clicking below the old-boxmodel-container blurs the opened editor"); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + info("Test that clicking below the boxmodel-container blurs the opened editor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); let onBlur = once(editor, "blur"); - let container = view.doc.querySelector("#old-boxmodel-container"); + let container = view.document.querySelector(".boxmodel-container"); // Using getBoxQuads here because getBoundingClientRect (and therefore synthesizeMouse) // use an erroneous height of ~50px for the boxmodel-container. let bounds = container.getBoxQuads({relativeTo: view.doc})[0].bounds; EventUtils.synthesizeMouseAtPoint( bounds.left + 10, bounds.top + bounds.height + 10, - {}, view.doc.defaultView); + {}, view.document.defaultView); yield onBlur; - is(view.doc.querySelector(".styleinspector-propertyeditor"), null, + is(view.document.querySelector(".styleinspector-propertyeditor"), null, "Inplace editor has been removed."); } diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js similarity index 82% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js index 5550a66423a4..197ef99d3b47 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js @@ -24,15 +24,15 @@ add_task(function* () { "Should have the right border"); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-border.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-border.boxmodel-top > span"); is(span.textContent, 0, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "0", "Should have the right value in the editor."); - EventUtils.synthesizeKey("1", {}, view.doc.defaultView); + EventUtils.synthesizeKey("1", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "1", "Should have the right value in the editor."); @@ -41,7 +41,7 @@ add_task(function* () { is((yield getStyle(testActor, "#div1", "border-top-style")), "solid", "Should have the right border"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "border-top-width")), "", diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js similarity index 74% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js index f3f41e4d04ed..28ba89898062 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js @@ -31,30 +31,30 @@ function* testUnits(inspector, view, testActor) { "Should have the right padding"); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-top > span"); is(span.textContent, 3, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "3px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("1", {}, view.doc.defaultView); + EventUtils.synthesizeKey("1", {}, view.document.defaultView); yield waitForUpdate(inspector); - EventUtils.synthesizeKey("e", {}, view.doc.defaultView); + EventUtils.synthesizeKey("e", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-top")), "", "An invalid value is handled cleanly"); - EventUtils.synthesizeKey("m", {}, view.doc.defaultView); + EventUtils.synthesizeKey("m", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "1em", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-top")), "1em", "Should have updated the padding."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "padding-top")), "1em", "Should be the right padding."); @@ -68,22 +68,22 @@ function* testValueComesFromStyleRule(inspector, view, testActor) { "Should have the right border-bottom-width"); yield selectNode("#div2", inspector); - let span = view.doc.querySelector(".old-boxmodel-border.old-boxmodel-bottom > span"); + let span = view.document.querySelector(".boxmodel-border.boxmodel-bottom > span"); is(span.textContent, 16, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "1em", "Should have the right value in the editor."); - EventUtils.synthesizeKey("0", {}, view.doc.defaultView); + EventUtils.synthesizeKey("0", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "0", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div2", "border-bottom-width")), "0px", "Should have updated the border."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div2", "border-bottom-width")), "0px", "Should be the right border-bottom-width."); @@ -97,15 +97,15 @@ function* testShorthandsAreParsed(inspector, view, testActor) { "Should have the right padding"); yield selectNode("#div3", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-right > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-right > span"); is(span.textContent, 32, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "2em", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div3", "padding-right")), "", "Should be the right padding."); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_guides.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js similarity index 89% rename from devtools/client/inspector/components/test/browser_boxmodel_guides.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js index 9dcaaa609cce..51457e25cd46 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_guides.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js @@ -28,16 +28,16 @@ add_task(function* () { highlighterOptions = options; }; - let elt = view.doc.getElementById("old-boxmodel-margins"); + let elt = view.document.querySelector(".boxmodel-margins"); yield testGuideOnLayoutHover(elt, "margin", inspector, view); - elt = view.doc.getElementById("old-boxmodel-borders"); + elt = view.document.querySelector(".boxmodel-borders"); yield testGuideOnLayoutHover(elt, "border", inspector, view); - elt = view.doc.getElementById("old-boxmodel-padding"); + elt = view.document.querySelector(".boxmodel-paddings"); yield testGuideOnLayoutHover(elt, "padding", inspector, view); - elt = view.doc.getElementById("old-boxmodel-content"); + elt = view.document.querySelector(".boxmodel-content"); yield testGuideOnLayoutHover(elt, "content", inspector, view); }); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_navigation.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js similarity index 75% rename from devtools/client/inspector/components/test/browser_boxmodel_navigation.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js index 6b8439710227..deee191fd2aa 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_navigation.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js @@ -29,50 +29,50 @@ add_task(function* () { function* testInitialFocus(inspector, view) { info("Test that the focus is on margin layout."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-margins", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-margins", "Should be set to the margin layout."); } function* testChangingLevels(inspector, view) { info("Test that using arrow keys updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); EventUtils.synthesizeKey("VK_ESCAPE", {}); EventUtils.synthesizeKey("VK_DOWN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-borders", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-borders", "Should be set to the border layout."); EventUtils.synthesizeKey("VK_DOWN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-padding", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-padding", "Should be set to the padding layout."); EventUtils.synthesizeKey("VK_UP", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-borders", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-borders", "Should be set to the border layout."); EventUtils.synthesizeKey("VK_UP", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-margins", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-margins", "Should be set to the margin layout."); } function* testTabbingWrapAround(inspector, view) { info("Test that using arrow keys updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); let editLevel = boxmodel.getAttribute("aria-activedescendant"); let dataLevel = viewdoc.getElementById(editLevel).getAttribute("data-box"); let editBoxes = [...viewdoc.querySelectorAll( - `[data-box="${dataLevel}"].old-boxmodel-editable`)]; + `[data-box="${dataLevel}"].boxmodel-editable`)]; EventUtils.synthesizeKey("VK_ESCAPE", {}); editBoxes[3].focus(); @@ -87,12 +87,12 @@ function* testTabbingWrapAround(inspector, view) { function* testChangingLevelsByClicking(inspector, view) { info("Test that clicking on levels updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); - let marginLayout = viewdoc.getElementById("old-boxmodel-margins"); - let borderLayout = viewdoc.getElementById("old-boxmodel-borders"); - let paddingLayout = viewdoc.getElementById("old-boxmodel-padding"); + let marginLayout = viewdoc.getElementById("boxmodel-margins"); + let borderLayout = viewdoc.getElementById("boxmodel-borders"); + let paddingLayout = viewdoc.getElementById("boxmodel-padding"); let layouts = [paddingLayout, borderLayout, marginLayout]; layouts.forEach(layout => { diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js new file mode 100644 index 000000000000..e931830b534f --- /dev/null +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js @@ -0,0 +1,49 @@ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that longer values are rotated on the side + +const res1 = [ + {selector: ".boxmodel-margin.boxmodel-top > span", value: 30}, + {selector: ".boxmodel-margin.boxmodel-left > span", value: "auto"}, + {selector: ".boxmodel-margin.boxmodel-bottom > span", value: 30}, + {selector: ".boxmodel-margin.boxmodel-right > span", value: "auto"}, + {selector: ".boxmodel-padding.boxmodel-top > span", value: 20}, + {selector: ".boxmodel-padding.boxmodel-left > span", value: 2000000}, + {selector: ".boxmodel-padding.boxmodel-bottom > span", value: 20}, + {selector: ".boxmodel-padding.boxmodel-right > span", value: 20}, + {selector: ".boxmodel-border.boxmodel-top > span", value: 10}, + {selector: ".boxmodel-border.boxmodel-left > span", value: 10}, + {selector: ".boxmodel-border.boxmodel-bottom > span", value: 10}, + {selector: ".boxmodel-border.boxmodel-right > span", value: 10}, +]; + +const TEST_URI = encodeURIComponent([ + "", + "
" +].join("")); +const LONG_TEXT_ROTATE_LIMIT = 3; + +add_task(function* () { + yield addTab("data:text/html," + TEST_URI); + let {inspector, view} = yield openBoxModelView(); + yield selectNode("div", inspector); + + for (let i = 0; i < res1.length; i++) { + let elt = view.document.querySelector(res1[i].selector); + let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT; + let classList = elt.parentNode.classList; + let canBeRotated = classList.contains("boxmodel-left") || + classList.contains("boxmodel-right"); + let isRotated = classList.contains("boxmodel-rotate"); + + is(canBeRotated && isLong, + isRotated, res1[i].selector + " correctly rotated."); + } +}); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_sync.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js similarity index 77% rename from devtools/client/inspector/components/test/browser_boxmodel_sync.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js index c0fde5c80b86..382675ad2d2d 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_sync.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js @@ -17,14 +17,14 @@ add_task(function* () { yield selectNode("p", inspector); info("Modify padding-bottom in box model view"); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-bottom > span"); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-bottom > span"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); - EventUtils.synthesizeKey("7", {}, view.doc.defaultView); + EventUtils.synthesizeKey("7", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "7", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); let onRuleViewRefreshed = once(inspector, "rule-view-refreshed"); let onRuleViewSelected = once(inspector.sidebar, "ruleview-selected"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_tooltips.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js similarity index 83% rename from devtools/client/inspector/components/test/browser_boxmodel_tooltips.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js index cdbbd6885bb4..6f5997635fe8 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_tooltips.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js @@ -76,24 +76,24 @@ add_task(function* () { info("Checking the regions tooltips"); - ok(view.doc.querySelector("#old-boxmodel-margins").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-margins").hasAttribute("title"), "The margin region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-margins").getAttribute("title"), "margin", + is(view.document.querySelector(".boxmodel-margins").getAttribute("title"), "margin", "The margin region has the correct tooltip content"); - ok(view.doc.querySelector("#old-boxmodel-borders").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-borders").hasAttribute("title"), "The border region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-borders").getAttribute("title"), "border", + is(view.document.querySelector(".boxmodel-borders").getAttribute("title"), "border", "The border region has the correct tooltip content"); - ok(view.doc.querySelector("#old-boxmodel-padding").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-paddings").hasAttribute("title"), "The padding region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-padding").getAttribute("title"), "padding", + is(view.document.querySelector(".boxmodel-paddings").getAttribute("title"), "padding", "The padding region has the correct tooltip content"); - ok(view.doc.querySelector("#old-boxmodel-content").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-content").hasAttribute("title"), "The content region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-content").getAttribute("title"), "content", + is(view.document.querySelector(".boxmodel-content").getAttribute("title"), "content", "The content region has the correct tooltip content"); for (let {selector, values} of VALUES_TEST_DATA) { @@ -108,7 +108,7 @@ add_task(function* () { let name = view.map[key].property; let expectedTooltipData = values.find(o => o.name === name); - let el = view.doc.querySelector(view.map[key].selector); + let el = view.document.querySelector(view.map[key].selector); ok(el.hasAttribute("title"), "The " + name + " value has a tooltip"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js similarity index 88% rename from devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js index 62918310ceea..1638b4791415 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js @@ -32,12 +32,11 @@ add_task(function* () { function* testFirstPage(inspector, view, testActor) { info("Test that the box model view works on the first page"); - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let paddingElt = view.doc.querySelector( - ".old-boxmodel-padding.old-boxmodel-top > span"); + let paddingElt = view.document.querySelector( + ".boxmodel-padding.boxmodel-top > span"); is(paddingElt.textContent, "50"); info("Listening for box model view changes and modifying the padding"); @@ -53,11 +52,10 @@ function* testFirstPage(inspector, view, testActor) { function* testSecondPage(inspector, view, testActor) { info("Test that the box model view works on the second page"); - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); + let sizeElt = view.document.querySelector(".boxmodel-size > span"); is(sizeElt.textContent, "100" + "\u00D7" + "100"); info("Listening for box model view changes and modifying the size"); @@ -73,13 +71,12 @@ function* testSecondPage(inspector, view, testActor) { function* testBackToFirstPage(inspector, view, testActor) { info("Test that the box model view works on the first page after going back"); - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value, which is the" + "modified value from step one because of the bfcache"); - let paddingElt = view.doc.querySelector( - ".old-boxmodel-padding.old-boxmodel-top > span"); + let paddingElt = view.document.querySelector( + ".boxmodel-padding.boxmodel-top > span"); is(paddingElt.textContent, "20"); info("Listening for box model view changes and modifying the padding"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js similarity index 90% rename from devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js index 111031e115d2..f589a82632e8 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js @@ -22,12 +22,11 @@ add_task(function* () { }); function* assertBoxModelView(inspector, view, testActor) { - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let paddingElt = view.doc.querySelector( - ".old-boxmodel-padding.old-boxmodel-top > span"); + let paddingElt = view.document.querySelector( + ".boxmodel-padding.boxmodel-top > span"); is(paddingElt.textContent, "50"); info("Listening for box model view changes and modifying the padding"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js similarity index 96% rename from devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js index 9aedb1b581ac..3e7b82e46b10 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js @@ -22,7 +22,7 @@ function* testResizingInIframe(inspector, view, testActor) { yield selectNodeInIframe2("div", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); + let sizeElt = view.document.querySelector(".boxmodel-size > span"); is(sizeElt.textContent, "400\u00D7200"); info("Listening for box model view changes and modifying its size"); @@ -47,7 +47,7 @@ function* testReflowsAfterIframeDeletion(inspector, view, testActor) { yield selectNodeInIframe1("p", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); + let sizeElt = view.document.querySelector(".boxmodel-size > span"); is(sizeElt.textContent, "100\u00D7100"); info("Listening for box model view changes and modifying its size"); diff --git a/devtools/client/inspector/components/test/doc_boxmodel_iframe1.html b/devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe1.html similarity index 100% rename from devtools/client/inspector/components/test/doc_boxmodel_iframe1.html rename to devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe1.html diff --git a/devtools/client/inspector/components/test/doc_boxmodel_iframe2.html b/devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe2.html similarity index 100% rename from devtools/client/inspector/components/test/doc_boxmodel_iframe2.html rename to devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe2.html diff --git a/devtools/client/inspector/components/test/head.js b/devtools/client/inspector/boxmodel/test/head.js similarity index 86% rename from devtools/client/inspector/components/test/head.js rename to devtools/client/inspector/boxmodel/test/head.js index fa86b5e9e179..6074a45ec8ec 100644 --- a/devtools/client/inspector/components/test/head.js +++ b/devtools/client/inspector/boxmodel/test/head.js @@ -58,7 +58,7 @@ function openBoxModelView() { return { toolbox: data.toolbox, inspector: data.inspector, - view: data.inspector.computedview.boxModelView, + view: data.inspector.computedview, testActor: data.testActor }; }); @@ -85,3 +85,14 @@ function setStyle(testActor, selector, propertyName, value) { .style.${propertyName} = "${value}"; `); } + +/** + * The box model doesn't participate in the inspector's update mechanism, so simply + * calling the default selectNode isn't enough to guarantee that the box model view has + * finished updating. We also need to wait for the "boxmodel-view-updated" event. + */ +var _selectNode = selectNode; +selectNode = function* (node, inspector, reason) { + yield _selectNode(node, inspector, reason); + yield waitForUpdate(inspector); +}; diff --git a/devtools/client/inspector/components/moz.build b/devtools/client/inspector/components/moz.build index 0ef321ae1da1..50556cf26ecf 100644 --- a/devtools/client/inspector/components/moz.build +++ b/devtools/client/inspector/components/moz.build @@ -8,5 +8,3 @@ DevToolsModules( 'inspector-tab-panel.css', 'inspector-tab-panel.js', ) - -BROWSER_CHROME_MANIFESTS += ['test/browser.ini'] diff --git a/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js b/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js deleted file mode 100644 index df667e6d1a55..000000000000 --- a/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js +++ /dev/null @@ -1,49 +0,0 @@ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -// Test that longer values are rotated on the side - -const res1 = [ - {selector: ".old-boxmodel-margin.old-boxmodel-top > span", value: 30}, - {selector: ".old-boxmodel-margin.old-boxmodel-left > span", value: "auto"}, - {selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", value: 30}, - {selector: ".old-boxmodel-margin.old-boxmodel-right > span", value: "auto"}, - {selector: ".old-boxmodel-padding.old-boxmodel-top > span", value: 20}, - {selector: ".old-boxmodel-padding.old-boxmodel-left > span", value: 2000000}, - {selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", value: 20}, - {selector: ".old-boxmodel-padding.old-boxmodel-right > span", value: 20}, - {selector: ".old-boxmodel-border.old-boxmodel-top > span", value: 10}, - {selector: ".old-boxmodel-border.old-boxmodel-left > span", value: 10}, - {selector: ".old-boxmodel-border.old-boxmodel-bottom > span", value: 10}, - {selector: ".old-boxmodel-border.old-boxmodel-right > span", value: 10}, -]; - -const TEST_URI = encodeURIComponent([ - "", - "
" -].join("")); -const LONG_TEXT_ROTATE_LIMIT = 3; - -add_task(function* () { - yield addTab("data:text/html," + TEST_URI); - let {inspector, view} = yield openBoxModelView(); - yield selectNode("div", inspector); - - for (let i = 0; i < res1.length; i++) { - let elt = view.doc.querySelector(res1[i].selector); - let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT; - let classList = elt.parentNode.classList; - let canBeRotated = classList.contains("old-boxmodel-left") || - classList.contains("old-boxmodel-right"); - let isRotated = classList.contains("old-boxmodel-rotate"); - - is(canBeRotated && isLong, - isRotated, res1[i].selector + " correctly rotated."); - } -}); diff --git a/devtools/client/inspector/computed/computed.js b/devtools/client/inspector/computed/computed.js index 55fc88c4f916..500ccb4968a0 100644 --- a/devtools/client/inspector/computed/computed.js +++ b/devtools/client/inspector/computed/computed.js @@ -180,6 +180,7 @@ function CssComputedView(inspector, document, pageStyle) { let doc = this.styleDocument; this.element = doc.getElementById("propertyContainer"); + this.boxModelWrapper = doc.getElementById("boxmodel-wrapper"); this.searchField = doc.getElementById("computedview-searchbox"); this.searchClearButton = doc.getElementById("computedview-searchinput-clear"); this.includeBrowserStylesCheckbox = @@ -559,10 +560,10 @@ CssComputedView.prototype = { this._filterChangedTimeout = setTimeout(() => { if (this.searchField.value.length > 0) { this.searchField.setAttribute("filled", true); - this.inspector.emit("computed-view-filtered", true); + this.boxModelWrapper.hidden = true; } else { this.searchField.removeAttribute("filled"); - this.inspector.emit("computed-view-filtered", false); + this.boxModelWrapper.hidden = false; } this.refreshPanel(); @@ -632,7 +633,7 @@ CssComputedView.prototype = { onShowBoxModelHighlighter, }) ); - ReactDOM.render(provider, this.styleDocument.getElementById("boxmodel-wrapper")); + ReactDOM.render(provider, this.boxModelWrapper); }, /** @@ -813,7 +814,7 @@ CssComputedView.prototype = { // Nodes used in templating this.element = null; - this.panel = null; + this.boxModelWrapper = null; this.searchField = null; this.searchClearButton = null; this.includeBrowserStylesCheckbox = null; diff --git a/devtools/client/inspector/computed/test/browser_computed_search-filter.js b/devtools/client/inspector/computed/test/browser_computed_search-filter.js index d5b2634f4884..f8f25f23a639 100644 --- a/devtools/client/inspector/computed/test/browser_computed_search-filter.js +++ b/devtools/client/inspector/computed/test/browser_computed_search-filter.js @@ -34,7 +34,7 @@ function* testToggleDefaultStyles(inspector, computedView) { function* testAddTextInFilter(inspector, computedView) { info("setting filter text to \"color\""); let doc = computedView.styleDocument; - let boxModelWrapper = doc.querySelector("#old-boxmodel-wrapper"); + let boxModelWrapper = doc.getElementById("boxmodel-wrapper"); let searchField = computedView.searchField; let onRefreshed = inspector.once("computed-view-refreshed"); let win = computedView.styleWindow; diff --git a/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js b/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js index 2b4a29618310..39dcefcb3838 100644 --- a/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js +++ b/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js @@ -50,7 +50,7 @@ function* testClearSearchFilter(inspector, computedView) { let win = computedView.styleWindow; let doc = computedView.styleDocument; - let boxModelWrapper = doc.querySelector("#old-boxmodel-wrapper"); + let boxModelWrapper = doc.getElementById("boxmodel-wrapper"); let propertyViews = computedView.propertyViews; let searchField = computedView.searchField; let searchClearButton = computedView.searchClearButton; diff --git a/devtools/client/inspector/inspector.js b/devtools/client/inspector/inspector.js index 7b251be95c84..34ab2b12d86c 100644 --- a/devtools/client/inspector/inspector.js +++ b/devtools/client/inspector/inspector.js @@ -78,8 +78,6 @@ const PORTRAIT_MODE_WIDTH = 700; * - computed-view-sourcelinks-updated * Fired when the stylesheet source links have been updated (when switching * to source-mapped files) - * - computed-view-filtered - * Fired when the computed rules view is filtered * - rule-view-refreshed * Fired when the rule view updates to a new node * - rule-view-sourcelinks-updated diff --git a/devtools/client/inspector/test/browser_inspector_textbox-menu.js b/devtools/client/inspector/test/browser_inspector_textbox-menu.js index a5e0e75622d8..b3e9ca68515c 100644 --- a/devtools/client/inspector/test/browser_inspector_textbox-menu.js +++ b/devtools/client/inspector/test/browser_inspector_textbox-menu.js @@ -66,7 +66,7 @@ add_task(function* () { info("Testing the box-model region"); let margin = inspector.panelDoc.querySelector( - ".old-boxmodel-margin.old-boxmodel-top > span"); + ".boxmodel-margin.boxmodel-top > span"); EventUtils.synthesizeMouseAtCenter(margin, {}, inspector.panelWin); yield checkTextBox(inspector.panelDoc.activeElement, toolbox); }); From 1e114ac15fe20a2f8b7993605eabdaa483a33355 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Wed, 22 Feb 2017 20:48:23 +0100 Subject: [PATCH 079/102] Bug 1336198 - part10: fix race condition in boxmodel tests;r=gl MozReview-Commit-ID: IDBgbnlMX2c --- .../client/inspector/boxmodel/box-model.js | 16 +++++++-- ...rowser_boxmodel_update-after-navigation.js | 6 ++-- .../browser_boxmodel_update-after-reload.js | 3 +- .../browser_boxmodel_update-in-iframes.js | 3 +- .../client/inspector/boxmodel/test/head.js | 36 ++++++++++++++++--- devtools/client/inspector/test/shared-head.js | 10 +++++- 6 files changed, 62 insertions(+), 12 deletions(-) diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js index 839b608f5ca2..0290d69af88a 100644 --- a/devtools/client/inspector/boxmodel/box-model.js +++ b/devtools/client/inspector/boxmodel/box-model.js @@ -126,8 +126,16 @@ BoxModel.prototype = { /** * Updates the box model panel by dispatching the new layout data. + * + * @param {String} reason + * Optional string describing the reason why the boxmodel is updated. */ - updateBoxModel() { + updateBoxModel(reason) { + this._updateReasons = this._updateReasons || []; + if (reason) { + this._updateReasons.push(reason); + } + let lastRequest = Task.spawn((function* () { if (!(this.isPanelVisible() && this.inspector.selection.isConnected() && @@ -151,9 +159,11 @@ BoxModel.prototype = { return this._lastRequest; } + this.inspector.emit("boxmodel-view-updated", this._updateReasons); + this._lastRequest = null; + this._updateReasons = []; - this.inspector.emit("boxmodel-view-updated"); return null; }).bind(this)).catch(console.error); @@ -173,7 +183,7 @@ BoxModel.prototype = { this.trackReflows(); } - this.updateBoxModel(); + this.updateBoxModel("new-selection"); }, /** diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js index 1638b4791415..dfcf8ceefe5a 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js @@ -17,14 +17,16 @@ add_task(function* () { yield testFirstPage(inspector, view, testActor); info("Navigate to the second page"); + let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval(`content.location.href="${IFRAME2}"`); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; yield testSecondPage(inspector, view, testActor); info("Go back to the first page"); + onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval("content.history.back();"); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; yield testBackToFirstPage(inspector, view, testActor); }); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js index f589a82632e8..f1ed222949a4 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js @@ -14,8 +14,9 @@ add_task(function* () { yield assertBoxModelView(inspector, view, testActor); info("Reload the page"); + let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.reload(); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; info("Test that the box model view works on the reloaded page"); yield assertBoxModelView(inspector, view, testActor); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js index 3e7b82e46b10..6aa10e441ae9 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js @@ -40,8 +40,9 @@ function* testReflowsAfterIframeDeletion(inspector, view, testActor) { "iframe"); info("Deleting the iframe2"); + let onInspectorUpdated = inspector.once("inspector-updated"); yield removeIframe2(testActor); - yield inspector.once("inspector-updated"); + yield onInspectorUpdated; info("Selecting the test node in iframe1"); yield selectNodeInIframe1("p", inspector); diff --git a/devtools/client/inspector/boxmodel/test/head.js b/devtools/client/inspector/boxmodel/test/head.js index 6074a45ec8ec..de25fe893077 100644 --- a/devtools/client/inspector/boxmodel/test/head.js +++ b/devtools/client/inspector/boxmodel/test/head.js @@ -66,10 +66,37 @@ function openBoxModelView() { /** * Wait for the boxmodel-view-updated event. - * @return a promise + * + * @param {InspectorPanel} inspector + * The instance of InspectorPanel currently loaded in the toolbox. + * @param {Boolean} waitForSelectionUpdate + * Should the boxmodel-view-updated event come from a new selection. + * @return {Promise} a promise */ -function waitForUpdate(inspector) { - return inspector.once("boxmodel-view-updated"); +function waitForUpdate(inspector, waitForSelectionUpdate) { + return new Promise(resolve => { + inspector.on("boxmodel-view-updated", function onUpdate(e, reasons) { + // Wait for another update event if we are waiting for a selection related event. + if (waitForSelectionUpdate && !reasons.includes("new-selection")) { + return; + } + + inspector.off("boxmodel-view-updated", onUpdate); + resolve(); + }); + }); +} + +/** + * Wait for both boxmode-view-updated and markuploaded events. + * + * @return {Promise} a promise that resolves when both events have been received. + */ +function waitForMarkupLoaded(inspector) { + return Promise.all([ + waitForUpdate(inspector), + inspector.once("markuploaded"), + ]); } function getStyle(testActor, selector, propertyName) { @@ -93,6 +120,7 @@ function setStyle(testActor, selector, propertyName, value) { */ var _selectNode = selectNode; selectNode = function* (node, inspector, reason) { + let onUpdate = waitForUpdate(inspector, true); yield _selectNode(node, inspector, reason); - yield waitForUpdate(inspector); + yield onUpdate; }; diff --git a/devtools/client/inspector/test/shared-head.js b/devtools/client/inspector/test/shared-head.js index a953d547e7f5..c42690a2813e 100644 --- a/devtools/client/inspector/test/shared-head.js +++ b/devtools/client/inspector/test/shared-head.js @@ -52,7 +52,15 @@ var openInspectorSidebarTab = Task.async(function* (id) { let {toolbox, inspector, testActor} = yield openInspector(); info("Selecting the " + id + " sidebar"); - inspector.sidebar.select(id); + + if (id === "computedview" || id === "layoutview") { + // The layout and computed views should wait until the box-model widget is ready. + let onBoxModelViewReady = inspector.once("boxmodel-view-updated"); + inspector.sidebar.select(id); + yield onBoxModelViewReady; + } else { + inspector.sidebar.select(id); + } return { toolbox, From 35b4353957b4a6650f512d605914779a63ef743c Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Thu, 23 Feb 2017 17:59:22 -0600 Subject: [PATCH 080/102] Bug 1341412 - Baldr: fix offset reported by validation error (r=bbouvier) MozReview-Commit-ID: CllhPo4uGde --- js/src/jit-test/lib/wasm-binary.js | 1 + js/src/jit-test/tests/wasm/errors.js | 19 +++++++++++++++++++ js/src/wasm/WasmBaselineCompile.cpp | 14 ++++++-------- js/src/wasm/WasmBinaryIterator.h | 20 ++++++++++++-------- js/src/wasm/WasmBinaryToAST.cpp | 2 +- js/src/wasm/WasmCompile.cpp | 2 +- js/src/wasm/WasmIonCompile.cpp | 13 ++++--------- js/src/wasm/WasmValidate.cpp | 22 +++++++++++----------- js/src/wasm/WasmValidate.h | 16 ++++++++++++---- 9 files changed, 67 insertions(+), 42 deletions(-) diff --git a/js/src/jit-test/lib/wasm-binary.js b/js/src/jit-test/lib/wasm-binary.js index e57ac84914c3..df5116b35588 100644 --- a/js/src/jit-test/lib/wasm-binary.js +++ b/js/src/jit-test/lib/wasm-binary.js @@ -71,6 +71,7 @@ const I32ConstCode = 0x41; const I64ConstCode = 0x42; const F32ConstCode = 0x43; const F64ConstCode = 0x44; +const I32AddCode = 0x6a; const I32DivSCode = 0x6d; const I32DivUCode = 0x6e; const I32RemSCode = 0x6f; diff --git a/js/src/jit-test/tests/wasm/errors.js b/js/src/jit-test/tests/wasm/errors.js index 65eb1cc20521..3efcf838bdb9 100644 --- a/js/src/jit-test/tests/wasm/errors.js +++ b/js/src/jit-test/tests/wasm/errors.js @@ -3,6 +3,7 @@ load(libdir + "wasm-binary.js"); const Module = WebAssembly.Module; const Instance = WebAssembly.Instance; +const CompileError = WebAssembly.CompileError; const RuntimeError = WebAssembly.RuntimeError; function isWasmFunction(name) { @@ -153,3 +154,21 @@ for (var i = 1; i < N; i++) { assertEq(binary[stack[i].line], i == 3 ? CallIndirectCode : CallCode); assertEq(stack[i].column, 1); } + +function testCompileError(opcode, text) { + var binary = new Uint8Array(wasmTextToBinary(text)); + var exn; + try { + new Instance(new Module(binary)); + } catch (e) { + exn = e; + } + + assertEq(exn instanceof CompileError, true); + var offset = Number(exn.message.match(/at offset (\d*)/)[1]); + assertEq(binary[offset], opcode); +} + +testCompileError(CallCode, '(module (func $f (param i32)) (func $g call $f))'); +testCompileError(I32AddCode, '(module (func (i32.add (i32.const 1) (f32.const 1))))'); +testCompileError(EndCode, '(module (func (block i32)))'); diff --git a/js/src/wasm/WasmBaselineCompile.cpp b/js/src/wasm/WasmBaselineCompile.cpp index ebadecb1e5ed..c66f02c95b2d 100644 --- a/js/src/wasm/WasmBaselineCompile.cpp +++ b/js/src/wasm/WasmBaselineCompile.cpp @@ -489,7 +489,6 @@ class BaseCompiler ValTypeVector Sig_; Label returnLabel_; Label stackOverflowLabel_; - TrapOffset prologueTrapOffset_; CodeOffset stackAddOffset_; LatentOp latentOp_; // Latent operation for branch (seen next) @@ -2106,8 +2105,7 @@ class BaseCompiler // Labels void insertBreakablePoint(CallSiteDesc::Kind kind) { - const uint32_t offset = trapOffset().bytecodeOffset; - masm.nopPatchableToCall(CallSiteDesc(offset, kind)); + masm.nopPatchableToCall(CallSiteDesc(iter_.errorOffset(), kind)); } ////////////////////////////////////////////////////////////////////// @@ -2271,7 +2269,8 @@ class BaseCompiler MOZ_ASSERT(localSize_ >= debugFrameReserved); if (localSize_ > debugFrameReserved) masm.addToStackPtr(Imm32(localSize_ - debugFrameReserved)); - masm.jump(TrapDesc(prologueTrapOffset_, Trap::StackOverflow, debugFrameReserved)); + TrapOffset prologueTrapOffset(func_.lineOrBytecode()); + masm.jump(TrapDesc(prologueTrapOffset, Trap::StackOverflow, debugFrameReserved)); masm.bind(&returnLabel_); @@ -3513,7 +3512,7 @@ class BaseCompiler uint32_t readCallSiteLineOrBytecode() { if (!func_.callSiteLineNums().empty()) return func_.callSiteLineNums()[lastReadCallSite_++]; - return trapOffset().bytecodeOffset; + return iter_.errorOffset(); } bool done() const { @@ -7334,7 +7333,7 @@ BaseCompiler::BaseCompiler(const ModuleEnvironment& env, TempAllocator* alloc, MacroAssembler* masm) : env_(env), - iter_(env, decoder, func.lineOrBytecode()), + iter_(env, decoder), func_(func), lastReadCallSite_(0), alloc_(*alloc), @@ -7346,7 +7345,6 @@ BaseCompiler::BaseCompiler(const ModuleEnvironment& env, deadCode_(false), debugEnabled_(debugEnabled), bceSafe_(0), - prologueTrapOffset_(trapOffset()), stackAddOffset_(0), latentOp_(LatentOp::None), latentType_(ValType::I32), @@ -7547,7 +7545,7 @@ js::wasm::BaselineCompileFunction(CompileTask* task, FuncCompileUnit* unit, Uniq const FuncBytes& func = unit->func(); uint32_t bodySize = func.bytes().length(); - Decoder d(func.bytes(), error); + Decoder d(func.bytes().begin(), func.bytes().end(), func.lineOrBytecode(), error); if (!ValidateFunctionBody(task->env(), func.index(), bodySize, d)) return false; diff --git a/js/src/wasm/WasmBinaryIterator.h b/js/src/wasm/WasmBinaryIterator.h index 5048eaf320ba..bae3edb8776f 100644 --- a/js/src/wasm/WasmBinaryIterator.h +++ b/js/src/wasm/WasmBinaryIterator.h @@ -326,13 +326,12 @@ class MOZ_STACK_CLASS OpIter : private Policy Decoder& d_; const ModuleEnvironment& env_; - const size_t offsetInModule_; Vector, 8, SystemAllocPolicy> valueStack_; Vector, 8, SystemAllocPolicy> controlStack_; DebugOnly op_; - size_t offsetOfExpr_; + size_t offsetOfLastReadOp_; MOZ_MUST_USE bool readFixedU8(uint8_t* out) { if (Validate) @@ -485,8 +484,8 @@ class MOZ_STACK_CLASS OpIter : private Policy public: typedef Vector ValueVector; - explicit OpIter(const ModuleEnvironment& env, Decoder& decoder, uint32_t offsetInModule = 0) - : d_(decoder), env_(env), offsetInModule_(offsetInModule), op_(Op::Limit), offsetOfExpr_(0) + explicit OpIter(const ModuleEnvironment& env, Decoder& decoder) + : d_(decoder), env_(env), op_(Op::Limit), offsetOfLastReadOp_(0) {} // Return the decoding byte offset. @@ -494,9 +493,14 @@ class MOZ_STACK_CLASS OpIter : private Policy return d_.currentOffset(); } - // Returning the offset within the entire module of the last-read Op. + // Return the offset within the entire module of the last-read op. + size_t errorOffset() const { + return offsetOfLastReadOp_ ? offsetOfLastReadOp_ : d_.currentOffset(); + } + + // Return a TrapOffset describing where the current op should be reported to trap. TrapOffset trapOffset() const { - return TrapOffset(offsetInModule_ + offsetOfExpr_); + return TrapOffset(errorOffset()); } // Test whether the iterator has reached the end of the buffer. @@ -661,7 +665,7 @@ template inline bool OpIter::fail(const char* msg) { - return d_.fail("%s", msg); + return d_.fail(errorOffset(), msg); } // This function pops exactly one value from the stack, yielding Any types in @@ -904,7 +908,7 @@ OpIter::readOp(uint16_t* op) { MOZ_ASSERT(!controlStack_.empty()); - offsetOfExpr_ = d_.currentOffset(); + offsetOfLastReadOp_ = d_.currentOffset(); if (Validate) { if (MOZ_UNLIKELY(!d_.readOp(op))) diff --git a/js/src/wasm/WasmBinaryToAST.cpp b/js/src/wasm/WasmBinaryToAST.cpp index 0296ed8a7d51..6c03543b54f5 100644 --- a/js/src/wasm/WasmBinaryToAST.cpp +++ b/js/src/wasm/WasmBinaryToAST.cpp @@ -1855,7 +1855,7 @@ wasm::BinaryToAst(JSContext* cx, const uint8_t* bytes, uint32_t length, LifoAllo return false; UniqueChars error; - Decoder d(bytes, bytes + length, &error, /* resilient */ true); + Decoder d(bytes, bytes + length, 0, &error, /* resilient */ true); AstDecodeContext c(cx, lifo, d, *result, true); if (!AstDecodeEnvironment(c) || diff --git a/js/src/wasm/WasmCompile.cpp b/js/src/wasm/WasmCompile.cpp index 5a5916f031b6..0dbf45ec80e0 100644 --- a/js/src/wasm/WasmCompile.cpp +++ b/js/src/wasm/WasmCompile.cpp @@ -110,7 +110,7 @@ wasm::Compile(const ShareableBytes& bytecode, const CompileArgs& args, UniqueCha { MOZ_RELEASE_ASSERT(wasm::HaveSignalHandlers()); - Decoder d(bytecode.begin(), bytecode.end(), error); + Decoder d(bytecode.bytes, error); auto env = js::MakeUnique(); if (!env) diff --git a/js/src/wasm/WasmIonCompile.cpp b/js/src/wasm/WasmIonCompile.cpp index 5c7d41d962bc..0d468408d60b 100644 --- a/js/src/wasm/WasmIonCompile.cpp +++ b/js/src/wasm/WasmIonCompile.cpp @@ -176,7 +176,7 @@ class FunctionCompiler const ValTypeVector& locals, MIRGenerator& mirGen) : env_(env), - iter_(env, decoder, func.lineOrBytecode()), + iter_(env, decoder), func_(func), locals_(locals), lastReadCallSite_(0), @@ -1509,7 +1509,7 @@ class FunctionCompiler uint32_t readCallSiteLineOrBytecode() { if (!func_.callSiteLineNums().empty()) return func_.callSiteLineNums()[lastReadCallSite_++]; - return iter_.trapOffset().bytecodeOffset; + return iter_.errorOffset(); } bool done() const { return iter_.done(); } @@ -3618,7 +3618,7 @@ wasm::IonCompileFunction(CompileTask* task, FuncCompileUnit* unit, UniqueChars* const ModuleEnvironment& env = task->env(); uint32_t bodySize = func.bytes().length(); - Decoder d(func.bytes(), error); + Decoder d(func.bytes().begin(), func.bytes().end(), func.lineOrBytecode(), error); if (!env.isAsmJS()) { if (!ValidateFunctionBody(task->env(), func.index(), bodySize, d)) @@ -3645,18 +3645,12 @@ wasm::IonCompileFunction(CompileTask* task, FuncCompileUnit* unit, UniqueChars* IonOptimizations.get(OptimizationLevel::Wasm)); mir.initMinWasmHeapLength(env.minMemoryLength); - // Capture the prologue's trap site before decoding the function. - - TrapOffset prologueTrapOffset; - // Build MIR graph { FunctionCompiler f(env, d, func, locals, mir); if (!f.init()) return false; - prologueTrapOffset = f.iter().trapOffset(); - if (!f.startBlock()) return false; @@ -3695,6 +3689,7 @@ wasm::IonCompileFunction(CompileTask* task, FuncCompileUnit* unit, UniqueChars* CodeGenerator codegen(&mir, lir, &task->masm()); + TrapOffset prologueTrapOffset(func.lineOrBytecode()); FuncOffsets offsets; if (!codegen.generateWasm(sigId, prologueTrapOffset, &offsets)) return false; diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp index 12d6c2b646e8..e7580ff3ede3 100644 --- a/js/src/wasm/WasmValidate.cpp +++ b/js/src/wasm/WasmValidate.cpp @@ -34,7 +34,7 @@ using mozilla::CheckedInt; // Decoder implementation. bool -Decoder::fail(const char* msg, ...) +Decoder::failf(const char* msg, ...) { va_list ap; va_start(ap, msg); @@ -43,14 +43,14 @@ Decoder::fail(const char* msg, ...) if (!str) return false; - return fail(Move(str)); + return fail(str.get()); } bool -Decoder::fail(UniqueChars msg) +Decoder::fail(size_t errorOffset, const char* msg) { MOZ_ASSERT(error_); - UniqueChars strWithOffset(JS_smprintf("at offset %" PRIuSIZE ": %s", currentOffset(), msg.get())); + UniqueChars strWithOffset(JS_smprintf("at offset %" PRIuSIZE ": %s", errorOffset, msg)); if (!strWithOffset) return false; @@ -110,7 +110,7 @@ Decoder::startSection(SectionId id, ModuleEnvironment* env, uint32_t* sectionSta return true; fail: - return fail("failed to start %s section", sectionName); + return failf("failed to start %s section", sectionName); } bool @@ -119,7 +119,7 @@ Decoder::finishSection(uint32_t sectionStart, uint32_t sectionSize, const char* if (resilientMode_) return true; if (sectionSize != (cur_ - beg_) - sectionStart) - return fail("byte size mismatch in %s section", sectionName); + return failf("byte size mismatch in %s section", sectionName); return true; } @@ -735,7 +735,7 @@ DecodeLimits(Decoder& d, Limits* limits) return d.fail("expected flags"); if (flags & ~uint32_t(0x1)) - return d.fail("unexpected bits set in flags: %" PRIu32, (flags & ~uint32_t(0x1))); + return d.failf("unexpected bits set in flags: %" PRIu32, (flags & ~uint32_t(0x1))); if (!d.readVarU32(&limits->initial)) return d.fail("expected initial length"); @@ -746,9 +746,9 @@ DecodeLimits(Decoder& d, Limits* limits) return d.fail("expected maximum length"); if (limits->initial > maximum) { - return d.fail("memory size minimum must not be greater than maximum; " - "maximum length %" PRIu32 " is less than initial length %" PRIu32, - maximum, limits->initial); + return d.failf("memory size minimum must not be greater than maximum; " + "maximum length %" PRIu32 " is less than initial length %" PRIu32, + maximum, limits->initial); } limits->maximum.emplace(maximum); @@ -1580,7 +1580,7 @@ wasm::DecodeModuleTail(Decoder& d, ModuleEnvironment* env) bool wasm::Validate(const ShareableBytes& bytecode, UniqueChars* error) { - Decoder d(bytecode.begin(), bytecode.end(), error); + Decoder d(bytecode.bytes, error); ModuleEnvironment env; if (!DecodeModuleEnvironment(d, &env)) diff --git a/js/src/wasm/WasmValidate.h b/js/src/wasm/WasmValidate.h index 49dfe2eb31fc..cae95917abb9 100644 --- a/js/src/wasm/WasmValidate.h +++ b/js/src/wasm/WasmValidate.h @@ -302,6 +302,7 @@ class Decoder const uint8_t* const beg_; const uint8_t* const end_; const uint8_t* cur_; + const size_t offsetInModule_; UniqueChars* error_; bool resilientMode_; @@ -384,11 +385,12 @@ class Decoder } public: - Decoder(const uint8_t* begin, const uint8_t* end, UniqueChars* error, + Decoder(const uint8_t* begin, const uint8_t* end, size_t offsetInModule, UniqueChars* error, bool resilientMode = false) : beg_(begin), end_(end), cur_(begin), + offsetInModule_(offsetInModule), error_(error), resilientMode_(resilientMode) { @@ -398,12 +400,18 @@ class Decoder : beg_(bytes.begin()), end_(bytes.end()), cur_(bytes.begin()), + offsetInModule_(0), error_(error), resilientMode_(false) {} - bool fail(const char* msg, ...) MOZ_FORMAT_PRINTF(2, 3); - bool fail(UniqueChars msg); + // These convenience functions use currentOffset() as the errorOffset. + bool fail(const char* msg) { return fail(currentOffset(), msg); } + bool failf(const char* msg, ...) MOZ_FORMAT_PRINTF(2, 3); + + // Report an error at the given offset (relative to the whole module). + bool fail(size_t errorOffset, const char* msg); + void clearError() { if (error_) error_->reset(); @@ -429,7 +437,7 @@ class Decoder return cur_; } size_t currentOffset() const { - return cur_ - beg_; + return offsetInModule_ + (cur_ - beg_); } const uint8_t* begin() const { return beg_; From 4f2e3a1877a95744679a9ca5ba29005347aac530 Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Thu, 23 Feb 2017 16:07:41 -0800 Subject: [PATCH 081/102] Backed out 8 changesets (bug 1336510) for windows debug mn-e10s failures a=backout Backed out changeset 419ada2f9e81 (bug 1336510) Backed out changeset 19239f566a93 (bug 1336510) Backed out changeset c8aeead6fe83 (bug 1336510) Backed out changeset 422e63b872b5 (bug 1336510) Backed out changeset 21869174dfd3 (bug 1336510) Backed out changeset 57476b9f342d (bug 1336510) Backed out changeset e842cdaaa7e5 (bug 1336510) Backed out changeset bd943b368ff7 (bug 1336510) MozReview-Commit-ID: 2z3Wa9QFkX4 --- dom/media/MediaDecoder.cpp | 5 +- dom/media/MediaDecoderStateMachine.cpp | 56 ++++++------- dom/media/MediaDecoderStateMachine.h | 3 - dom/media/MediaManager.cpp | 22 +++-- dom/media/mediasink/DecodedStream.cpp | 5 +- dom/media/ogg/OggDemuxer.cpp | 9 +- dom/media/systemservices/CamerasChild.cpp | 83 ++++++++++++++----- .../webrtc/MediaEngineRemoteVideoSource.cpp | 8 +- dom/media/webrtc/MediaEngineWebRTCAudio.cpp | 8 +- dom/presentation/PresentationConnection.cpp | 15 ++-- gfx/layers/ipc/CompositorBridgeParent.cpp | 3 +- ipc/mscom/MainThreadHandoff.cpp | 12 +-- ipc/mscom/WeakRef.cpp | 14 ++-- .../mdns/libmdns/MDNSResponderOperator.cpp | 4 +- .../converters/nsMultiMixedConv.cpp | 11 +-- 15 files changed, 136 insertions(+), 122 deletions(-) diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 62fcc972d759..b6c77d876ca5 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -1813,14 +1813,13 @@ MediaDecoder::DumpDebugInfo() return; } - RefPtr self = this; GetStateMachine()->RequestDebugInfo()->Then( AbstractThread::MainThread(), __func__, - [this, self, str] (const nsACString& aString) { + [this, str] (const nsACString& aString) { DUMP_LOG("%s", str.get()); DUMP_LOG("%s", aString.Data()); }, - [this, self, str] () { + [this, str] () { DUMP_LOG("%s", str.get()); }); } diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index b1390ece876a..43be192f4115 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2805,11 +2805,6 @@ bool MediaDecoderStateMachine::IsPlaying() const return mMediaSink->IsPlaying(); } -void MediaDecoderStateMachine::SetMediaNotSeekable() -{ - mMediaSeekable = false; -} - nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) { MOZ_ASSERT(NS_IsMainThread()); @@ -2827,7 +2822,9 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) mMetadataManager.Connect(mReader->TimedMetadataEvent(), OwnerThread()); mOnMediaNotSeekable = mReader->OnMediaNotSeekable().Connect( - OwnerThread(), this, &MediaDecoderStateMachine::SetMediaNotSeekable); + OwnerThread(), [this] () { + mMediaSeekable = false; + }); mMediaSink = CreateMediaSink(mAudioCaptured); @@ -3115,10 +3112,9 @@ MediaDecoderStateMachine::RequestAudioData() SAMPLE_LOG("Queueing audio task - queued=%" PRIuSIZE ", decoder-queued=%" PRIuSIZE, AudioQueue().GetSize(), mReader->SizeOfAudioQueueInFrames()); - RefPtr self = this; mReader->RequestAudioData()->Then( OwnerThread(), __func__, - [this, self] (MediaData* aAudio) { + [this] (MediaData* aAudio) { MOZ_ASSERT(aAudio); mAudioDataRequest.Complete(); // audio->GetEndTime() is not always mono-increasing in chained ogg. @@ -3128,7 +3124,7 @@ MediaDecoderStateMachine::RequestAudioData() aAudio->GetEndTime()); mStateObj->HandleAudioDecoded(aAudio); }, - [this, self] (const MediaResult& aError) { + [this] (const MediaResult& aError) { SAMPLE_LOG("OnAudioNotDecoded aError=%" PRIu32, static_cast(aError.Code())); mAudioDataRequest.Complete(); switch (aError.Code()) { @@ -3162,10 +3158,9 @@ MediaDecoderStateMachine::RequestVideoData(bool aSkipToNextKeyframe, aSkipToNextKeyframe, aCurrentTime.ToMicroseconds()); TimeStamp videoDecodeStartTime = TimeStamp::Now(); - RefPtr self = this; mReader->RequestVideoData(aSkipToNextKeyframe, aCurrentTime)->Then( OwnerThread(), __func__, - [this, self, videoDecodeStartTime] (MediaData* aVideo) { + [this, videoDecodeStartTime] (MediaData* aVideo) { MOZ_ASSERT(aVideo); mVideoDataRequest.Complete(); // Handle abnormal or negative timestamps. @@ -3175,7 +3170,7 @@ MediaDecoderStateMachine::RequestVideoData(bool aSkipToNextKeyframe, aVideo->GetEndTime()); mStateObj->HandleVideoDecoded(aVideo, videoDecodeStartTime); }, - [this, self] (const MediaResult& aError) { + [this] (const MediaResult& aError) { SAMPLE_LOG("OnVideoNotDecoded aError=%" PRIu32 , static_cast(aError.Code())); mVideoDataRequest.Complete(); switch (aError.Code()) { @@ -3199,30 +3194,29 @@ MediaDecoderStateMachine::WaitForData(MediaData::Type aType) { MOZ_ASSERT(OnTaskQueue()); MOZ_ASSERT(aType == MediaData::AUDIO_DATA || aType == MediaData::VIDEO_DATA); - RefPtr self = this; if (aType == MediaData::AUDIO_DATA) { mReader->WaitForData(MediaData::AUDIO_DATA)->Then( OwnerThread(), __func__, - [self] (MediaData::Type aType) { - self->mAudioWaitRequest.Complete(); + [this] (MediaData::Type aType) { + mAudioWaitRequest.Complete(); MOZ_ASSERT(aType == MediaData::AUDIO_DATA); - self->mStateObj->HandleAudioWaited(aType); + mStateObj->HandleAudioWaited(aType); }, - [self] (const WaitForDataRejectValue& aRejection) { - self->mAudioWaitRequest.Complete(); - self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); + [this] (const WaitForDataRejectValue& aRejection) { + mAudioWaitRequest.Complete(); + DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); })->Track(mAudioWaitRequest); } else { mReader->WaitForData(MediaData::VIDEO_DATA)->Then( OwnerThread(), __func__, - [self] (MediaData::Type aType) { - self->mVideoWaitRequest.Complete(); + [this] (MediaData::Type aType) { + mVideoWaitRequest.Complete(); MOZ_ASSERT(aType == MediaData::VIDEO_DATA); - self->mStateObj->HandleVideoWaited(aType); + mStateObj->HandleVideoWaited(aType); }, - [self] (const WaitForDataRejectValue& aRejection) { - self->mVideoWaitRequest.Complete(); - self->DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); + [this] (const WaitForDataRejectValue& aRejection) { + mVideoWaitRequest.Complete(); + DecodeError(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA); })->Track(mVideoWaitRequest); } } @@ -3583,10 +3577,9 @@ MediaDecoderStateMachine::ScheduleStateMachineIn(int64_t aMicroseconds) // It is OK to capture 'this' without causing UAF because the callback // always happens before shutdown. - RefPtr self = this; - mDelayedScheduler.Ensure(target, [self] () { - self->mDelayedScheduler.CompleteRequest(); - self->RunStateMachine(); + mDelayedScheduler.Ensure(target, [this] () { + mDelayedScheduler.CompleteRequest(); + RunStateMachine(); }, [] () { MOZ_DIAGNOSTIC_ASSERT(false); }); @@ -3803,9 +3796,8 @@ MediaDecoderStateMachine::RequestDebugInfo() { using PromiseType = MediaDecoder::DebugInfoPromise; RefPtr p = new PromiseType::Private(__func__); - RefPtr self = this; - OwnerThread()->Dispatch(NS_NewRunnableFunction([self, p] () { - p->Resolve(self->GetDebugInfo(), __func__); + OwnerThread()->Dispatch(NS_NewRunnableFunction([this, p] () { + p->Resolve(GetDebugInfo(), __func__); }), AbstractThread::AssertDispatchSuccess, AbstractThread::TailDispatch); return p.forget(); } diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 57abc3a2b62a..46b4d2a1af14 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -297,9 +297,6 @@ private: // be held. bool IsPlaying() const; - // Sets mMediaSeekable to false. - void SetMediaNotSeekable(); - // Resets all states related to decoding and aborts all pending requests // to the decoders. void ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack, diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 7a81f835a086..e1e664e06b09 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -2295,23 +2295,23 @@ if (privileged) { RefPtr p = EnumerateDevicesImpl(windowID, videoType, audioType, fake); - RefPtr self = this; - p->Then([self, onSuccess, onFailure, windowID, c, listener, askPermission, + p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission, prefs, isHTTPS, callID, principalInfo, isChrome](SourceSet*& aDevices) mutable { RefPtr>> devices( new Refcountable>(aDevices)); // grab result - // Ensure that our windowID is still good. - if (!nsGlobalWindow::GetInnerWindowWithId(windowID)) { + // Ensure that the captured 'this' pointer and our windowID are still good. + if (!MediaManager::Exists() || + !nsGlobalWindow::GetInnerWindowWithId(windowID)) { return; } // Apply any constraints. This modifies the passed-in list. - RefPtr p2 = self->SelectSettings(c, isChrome, devices); + RefPtr p2 = SelectSettings(c, isChrome, devices); - p2->Then([self, onSuccess, onFailure, windowID, c, + p2->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission, prefs, isHTTPS, callID, principalInfo, isChrome, devices](const char*& badConstraint) mutable { @@ -2359,13 +2359,13 @@ if (privileged) { isChrome, devices->release())); // Store the task w/callbacks. - self->mActiveCallbacks.Put(callID, task.forget()); + mActiveCallbacks.Put(callID, task.forget()); // Add a WindowID cross-reference so OnNavigation can tear things down nsTArray* array; - if (!self->mCallIds.Get(windowID, &array)) { + if (!mCallIds.Get(windowID, &array)) { array = new nsTArray(); - self->mCallIds.Put(windowID, array); + mCallIds.Put(windowID, array); } array->AppendElement(callID); @@ -3002,9 +3002,7 @@ MediaManager::Shutdown() // cleared until the lambda function clears it. // note that this == sSingleton - MOZ_ASSERT(this == sSingleton); - RefPtr that = this; - + RefPtr that(sSingleton); // Release the backend (and call Shutdown()) from within the MediaManager thread // Don't use MediaManager::PostTask() because we're sInShutdown=true here! RefPtr shutdown = new ShutdownTask(this, diff --git a/dom/media/mediasink/DecodedStream.cpp b/dom/media/mediasink/DecodedStream.cpp index 44457f07222b..921f6d4e6951 100644 --- a/dom/media/mediasink/DecodedStream.cpp +++ b/dom/media/mediasink/DecodedStream.cpp @@ -70,10 +70,9 @@ public: void Forget() { - RefPtr self = this; - mAbstractMainThread->Dispatch(NS_NewRunnableFunction([self] () { + mAbstractMainThread->Dispatch(NS_NewRunnableFunction([this] () { MOZ_ASSERT(NS_IsMainThread()); - self->mFinishPromise.ResolveIfExists(true, __func__); + mFinishPromise.ResolveIfExists(true, __func__); })); MutexAutoLock lock(mMutex); mStream = nullptr; diff --git a/dom/media/ogg/OggDemuxer.cpp b/dom/media/ogg/OggDemuxer.cpp index 5da73ea16f5f..ab64a0599274 100644 --- a/dom/media/ogg/OggDemuxer.cpp +++ b/dom/media/ogg/OggDemuxer.cpp @@ -128,13 +128,8 @@ OggDemuxer::~OggDemuxer() // If we were able to initialize our decoders, report whether we encountered // a chained stream or not. bool isChained = mIsChained; - void* ptr = this; - nsCOMPtr task = NS_NewRunnableFunction([ptr, isChained]() -> void { - // We can't use OGG_DEBUG here because it implicitly refers to `this`, - // which we can't capture in this runnable. - MOZ_LOG(gMediaDemuxerLog, mozilla::LogLevel::Debug, - ("OggDemuxer(%p)::%s: Reporting telemetry MEDIA_OGG_LOADED_IS_CHAINED=%d", - ptr, __func__, isChained)); + nsCOMPtr task = NS_NewRunnableFunction([=]() -> void { + OGG_DEBUG("Reporting telemetry MEDIA_OGG_LOADED_IS_CHAINED=%d", isChained); Telemetry::Accumulate(Telemetry::HistogramID::MEDIA_OGG_LOADED_IS_CHAINED, isChained); }); // Non-DocGroup version of AbstractThread::MainThread is fine for Telemetry. diff --git a/dom/media/systemservices/CamerasChild.cpp b/dom/media/systemservices/CamerasChild.cpp index b955881291ff..24047c27187d 100644 --- a/dom/media/systemservices/CamerasChild.cpp +++ b/dom/media/systemservices/CamerasChild.cpp @@ -285,8 +285,12 @@ CamerasChild::NumberOfCapabilities(CaptureEngine aCapEngine, LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8)); nsCString unique_id(deviceUniqueIdUTF8); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendNumberOfCapabilities, aCapEngine, unique_id); + media::NewRunnableFrom([this, aCapEngine, unique_id]() -> nsresult { + if (this->SendNumberOfCapabilities(aCapEngine, unique_id)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger); LOG(("Capture capability count: %d", dispatcher.ReturnValue())); return dispatcher.ReturnValue(); @@ -297,8 +301,12 @@ CamerasChild::NumberOfCaptureDevices(CaptureEngine aCapEngine) { LOG((__PRETTY_FUNCTION__)); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendNumberOfCaptureDevices, aCapEngine); + media::NewRunnableFrom([this, aCapEngine]() -> nsresult { + if (this->SendNumberOfCaptureDevices(aCapEngine)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger); LOG(("Capture Devices: %d", dispatcher.ReturnValue())); return dispatcher.ReturnValue(); @@ -321,8 +329,12 @@ CamerasChild::EnsureInitialized(CaptureEngine aCapEngine) { LOG((__PRETTY_FUNCTION__)); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendEnsureInitialized, aCapEngine); + media::NewRunnableFrom([this, aCapEngine]() -> nsresult { + if (this->SendEnsureInitialized(aCapEngine)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger); LOG(("Capture Devices: %d", dispatcher.ReturnValue())); return dispatcher.ReturnValue(); @@ -337,8 +349,12 @@ CamerasChild::GetCaptureCapability(CaptureEngine aCapEngine, LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number)); nsCString unique_id(unique_idUTF8); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendGetCaptureCapability, aCapEngine, unique_id, capability_number); + media::NewRunnableFrom([this, aCapEngine, unique_id, capability_number]() -> nsresult { + if (this->SendGetCaptureCapability(aCapEngine, unique_id, capability_number)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { capability = mReplyCapability; @@ -374,8 +390,12 @@ CamerasChild::GetCaptureDevice(CaptureEngine aCapEngine, { LOG((__PRETTY_FUNCTION__)); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendGetCaptureDevice, aCapEngine, list_number); + media::NewRunnableFrom([this, aCapEngine, list_number]() -> nsresult { + if (this->SendGetCaptureDevice(aCapEngine, list_number)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { base::strlcpy(device_nameUTF8, mReplyDeviceName.get(), device_nameUTF8Length); @@ -414,8 +434,12 @@ CamerasChild::AllocateCaptureDevice(CaptureEngine aCapEngine, LOG((__PRETTY_FUNCTION__)); nsCString unique_id(unique_idUTF8); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendAllocateCaptureDevice, aCapEngine, unique_id, aPrincipalInfo); + media::NewRunnableFrom([this, aCapEngine, unique_id, aPrincipalInfo]() -> nsresult { + if (this->SendAllocateCaptureDevice(aCapEngine, unique_id, aPrincipalInfo)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { LOG(("Capture Device allocated: %d", mReplyInteger)); @@ -443,8 +467,12 @@ CamerasChild::ReleaseCaptureDevice(CaptureEngine aCapEngine, { LOG((__PRETTY_FUNCTION__)); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendReleaseCaptureDevice, aCapEngine, capture_id); + media::NewRunnableFrom([this, aCapEngine, capture_id]() -> nsresult { + if (this->SendReleaseCaptureDevice(aCapEngine, capture_id)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable); return dispatcher.ReturnValue(); } @@ -490,8 +518,12 @@ CamerasChild::StartCapture(CaptureEngine aCapEngine, webrtcCaps.codecType, webrtcCaps.interlaced); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendStartCapture, aCapEngine, capture_id, capCap); + media::NewRunnableFrom([this, aCapEngine, capture_id, capCap]() -> nsresult { + if (this->SendStartCapture(aCapEngine, capture_id, capCap)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable); return dispatcher.ReturnValue(); } @@ -501,8 +533,12 @@ CamerasChild::StopCapture(CaptureEngine aCapEngine, const int capture_id) { LOG((__PRETTY_FUNCTION__)); nsCOMPtr runnable = - mozilla::NewNonOwningRunnableMethod - (this, &CamerasChild::SendStopCapture, aCapEngine, capture_id); + media::NewRunnableFrom([this, aCapEngine, capture_id]() -> nsresult { + if (this->SendStopCapture(aCapEngine, capture_id)) { + return NS_OK; + } + return NS_ERROR_FAILURE; + }); LockAndDispatch<> dispatcher(this, __func__, runnable); if (dispatcher.Success()) { RemoveCallback(aCapEngine, capture_id); @@ -563,10 +599,13 @@ CamerasChild::ShutdownParent() if (CamerasSingleton::Thread()) { LOG(("Dispatching actor deletion")); // Delete the parent actor. - // CamerasChild (this) will remain alive and is only deleted by the - // IPC layer when SendAllDone returns. - nsCOMPtr deleteRunnable = - mozilla::NewNonOwningRunnableMethod(this, &CamerasChild::SendAllDone); + RefPtr deleteRunnable = + // CamerasChild (this) will remain alive and is only deleted by the + // IPC layer when SendAllDone returns. + media::NewRunnableFrom([this]() -> nsresult { + Unused << this->SendAllDone(); + return NS_OK; + }); CamerasSingleton::Thread()->Dispatch(deleteRunnable, NS_DISPATCH_NORMAL); } else { LOG(("ShutdownParent called without PBackground thread")); diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp index 4f6c26004a75..c2df41c46ea2 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp @@ -316,10 +316,10 @@ MediaEngineRemoteVideoSource::SetLastCapability( webrtc::CaptureCapability cap = aCapability; RefPtr that = this; - NS_DispatchToMainThread(media::NewRunnableFrom([that, cap]() mutable { - that->mSettings.mWidth.Value() = cap.width; - that->mSettings.mHeight.Value() = cap.height; - that->mSettings.mFrameRate.Value() = cap.maxFPS; + NS_DispatchToMainThread(media::NewRunnableFrom([this, that, cap]() mutable { + mSettings.mWidth.Value() = cap.width; + mSettings.mHeight.Value() = cap.height; + mSettings.mFrameRate.Value() = cap.maxFPS; return NS_OK; })); } diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index 8bd1142d1995..e8e625bf54c0 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -373,10 +373,10 @@ MediaEngineWebRTCMicrophoneSource::SetLastPrefs( RefPtr that = this; - NS_DispatchToMainThread(media::NewRunnableFrom([that, aPrefs]() mutable { - that->mSettings.mEchoCancellation.Value() = aPrefs.mAecOn; - that->mSettings.mMozAutoGainControl.Value() = aPrefs.mAgcOn; - that->mSettings.mMozNoiseSuppression.Value() = aPrefs.mNoiseOn; + NS_DispatchToMainThread(media::NewRunnableFrom([this, that, aPrefs]() mutable { + mSettings.mEchoCancellation.Value() = aPrefs.mAecOn; + mSettings.mMozAutoGainControl.Value() = aPrefs.mAgcOn; + mSettings.mMozNoiseSuppression.Value() = aPrefs.mNoiseOn; return NS_OK; })); } diff --git a/dom/presentation/PresentationConnection.cpp b/dom/presentation/PresentationConnection.cpp index f36b506d1e97..0ffd27b4f02a 100644 --- a/dom/presentation/PresentationConnection.cpp +++ b/dom/presentation/PresentationConnection.cpp @@ -735,19 +735,18 @@ PresentationConnection::AsyncCloseConnectionWithErrorMsg(const nsAString& aMessa } nsString message = nsString(aMessage); - RefPtr self = this; nsCOMPtr r = - NS_NewRunnableFunction([self, message]() -> void { + NS_NewRunnableFunction([this, message]() -> void { // Set |mState| to |PresentationConnectionState::Closed| here to avoid // calling |ProcessStateChanged|. - self->mState = PresentationConnectionState::Closed; + mState = PresentationConnectionState::Closed; // Make sure dispatching the event and closing the connection are invoked // at the same time by setting |aDispatchNow| to true. Unused << NS_WARN_IF(NS_FAILED( - self->DispatchConnectionCloseEvent(PresentationConnectionClosedReason::Error, - message, - true))); + DispatchConnectionCloseEvent(PresentationConnectionClosedReason::Error, + message, + true))); nsCOMPtr service = do_GetService(PRESENTATION_SERVICE_CONTRACTID); @@ -756,8 +755,8 @@ PresentationConnection::AsyncCloseConnectionWithErrorMsg(const nsAString& aMessa } Unused << NS_WARN_IF(NS_FAILED( - service->CloseSession(self->mId, - self->mRole, + service->CloseSession(mId, + mRole, nsIPresentationService::CLOSED_REASON_ERROR))); }); diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index 6b8611359ff2..14cc36e576c7 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -1316,9 +1316,8 @@ CompositorBridgeParent::FlushApzRepaints(const LayerTransactionParent* aLayerTre // use the compositor's root layer tree id. layersId = mRootLayerTreeID; } - RefPtr self = this; APZThreadUtils::RunOnControllerThread(NS_NewRunnableFunction([=] () { - self->mApzcTreeManager->FlushApzRepaints(layersId); + mApzcTreeManager->FlushApzRepaints(layersId); })); } diff --git a/ipc/mscom/MainThreadHandoff.cpp b/ipc/mscom/MainThreadHandoff.cpp index 7f9e44a90437..521bf7f8e8df 100644 --- a/ipc/mscom/MainThreadHandoff.cpp +++ b/ipc/mscom/MainThreadHandoff.cpp @@ -13,7 +13,6 @@ #include "mozilla/Assertions.h" #include "mozilla/DebugOnly.h" #include "nsThreadUtils.h" -#include "nsProxyRelease.h" using mozilla::DebugOnly; @@ -108,11 +107,12 @@ MainThreadHandoff::Release() if (NS_IsMainThread()) { delete this; } else { - // We need to delete this object on the main thread, but we aren't on the - // main thread right now, so we send a reference to ourselves to the main - // thread to be re-released there. - RefPtr self = this; - NS_ReleaseOnMainThread(self.forget()); + mozilla::DebugOnly rv = + NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void + { + delete this; + })); + MOZ_ASSERT(NS_SUCCEEDED(rv)); } } return newRefCnt; diff --git a/ipc/mscom/WeakRef.cpp b/ipc/mscom/WeakRef.cpp index 80b2e4d633d9..807fcfb5eea1 100644 --- a/ipc/mscom/WeakRef.cpp +++ b/ipc/mscom/WeakRef.cpp @@ -11,7 +11,6 @@ #include "mozilla/Mutex.h" #include "nsThreadUtils.h" #include "nsWindowsHelpers.h" -#include "nsProxyRelease.h" static void InitializeCS(CRITICAL_SECTION& aCS) @@ -148,11 +147,14 @@ WeakReferenceSupport::Release() if (mFlags != Flags::eDestroyOnMainThread || NS_IsMainThread()) { delete this; } else { - // We need to delete this object on the main thread, but we aren't on the - // main thread right now, so we send a reference to ourselves to the main - // thread to be re-released there. - RefPtr self = this; - NS_ReleaseOnMainThread(self.forget()); + // It is possible for the last Release() call to happen off-main-thread. + // If so, we need to dispatch an event to delete ourselves. + mozilla::DebugOnly rv = + NS_DispatchToMainThread(NS_NewRunnableFunction([this]() -> void + { + delete this; + })); + MOZ_ASSERT(NS_SUCCEEDED(rv)); } } return newRefCnt; diff --git a/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp b/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp index 72b557774905..04e5b3ec7ebd 100644 --- a/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp +++ b/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp @@ -621,7 +621,7 @@ ResolveOperator::Reply(DNSServiceRef aSdRef, { MOZ_ASSERT(GetThread() == NS_GetCurrentThread()); - auto guard = MakeScopeExit([&] { + auto guard = MakeScopeExit([this] { Unused << NS_WARN_IF(NS_FAILED(Stop())); }); @@ -740,7 +740,7 @@ GetAddrInfoOperator::Reply(DNSServiceRef aSdRef, { MOZ_ASSERT(GetThread() == NS_GetCurrentThread()); - auto guard = MakeScopeExit([&] { + auto guard = MakeScopeExit([this] { Unused << NS_WARN_IF(NS_FAILED(Stop())); }); diff --git a/netwerk/streamconv/converters/nsMultiMixedConv.cpp b/netwerk/streamconv/converters/nsMultiMixedConv.cpp index 01f2c7a46fce..47d4fe4a82aa 100644 --- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp +++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp @@ -807,14 +807,9 @@ nsMultiMixedConv::SwitchToControlParsing() nsMultiMixedConv::nsMultiMixedConv() : mCurrentPartID(0), mInOnDataAvailable(false), - // XXX: This is a hack to bypass the raw pointer to refcounted object in - // lambda analysis. It should be removed and replaced when the - // IncrementalTokenizer API is improved to avoid the need for such - // workarounds. - // - // This is safe because `mTokenizer` will not outlive `this`, meaning that - // this std::bind object will be destroyed before `this` dies. - mTokenizer(std::bind(&nsMultiMixedConv::ConsumeToken, this, std::placeholders::_1)) + mTokenizer([this](Token const& token, mozilla::IncrementalTokenizer&) -> nsresult { + return this->ConsumeToken(token); + }) { mContentLength = UINT64_MAX; mByteRangeStart = 0; From af27d74cd59bc10c3b73db374a4c437cbb244fa7 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Thu, 23 Feb 2017 18:14:04 -0600 Subject: [PATCH 082/102] Bug 1341412 - Baldr: fix rebase fail (r=bustage) MozReview-Commit-ID: Kydw7jaZiQ7 --- js/src/wasm/WasmValidate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp index e7580ff3ede3..c68d152f17f3 100644 --- a/js/src/wasm/WasmValidate.cpp +++ b/js/src/wasm/WasmValidate.cpp @@ -618,8 +618,8 @@ DecodePreamble(Decoder& d) return d.fail("failed to match magic number"); if (!d.readFixedU32(&u32) || u32 != EncodingVersion) { - return d.fail("binary version 0x%" PRIx32 " does not match expected version 0x%" PRIx32, - u32, EncodingVersion); + return d.failf("binary version 0x%" PRIx32 " does not match expected version 0x%" PRIx32, + u32, EncodingVersion); } return true; From a689ea0aceca7a9662c7e0fd46a5426072ebebb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 23 Feb 2017 07:04:20 -0800 Subject: [PATCH 083/102] Bug 1341298 - Relax expected module state when resolving modules and circular module dependencies are present. r=jonco --- js/src/builtin/Module.js | 10 ++++++---- .../modules/export-circular-nonexisting-binding-1.js | 4 ++++ .../modules/export-circular-nonexisting-binding-2.js | 1 + .../modules/export-circular-nonexisting-binding.js | 3 +++ js/src/vm/EnvironmentObject.cpp | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 js/src/jit-test/modules/export-circular-nonexisting-binding-1.js create mode 100644 js/src/jit-test/modules/export-circular-nonexisting-binding-2.js create mode 100644 js/src/jit-test/tests/modules/export-circular-nonexisting-binding.js diff --git a/js/src/builtin/Module.js b/js/src/builtin/Module.js index 96ede2da8f90..c9fafbcbd916 100644 --- a/js/src/builtin/Module.js +++ b/js/src/builtin/Module.js @@ -100,7 +100,7 @@ function ModuleResolveExport(exportName, resolveSet = []) let e = indirectExportEntries[i]; if (exportName === e.exportName) { let importedModule = CallModuleResolveHook(module, e.moduleRequest, - MODULE_STATE_INSTANTIATED); + MODULE_STATE_PARSED); return callFunction(importedModule.resolveExport, importedModule, e.importName, resolveSet); } @@ -120,7 +120,7 @@ function ModuleResolveExport(exportName, resolveSet = []) for (let i = 0; i < starExportEntries.length; i++) { let e = starExportEntries[i]; let importedModule = CallModuleResolveHook(module, e.moduleRequest, - MODULE_STATE_INSTANTIATED); + MODULE_STATE_PARSED); let resolution = callFunction(importedModule.resolveExport, importedModule, exportName, resolveSet); if (resolution === "ambiguous") @@ -205,8 +205,8 @@ function GetModuleEnvironment(module) function RecordInstantationFailure(module) { - // Set the module's environment slot to 'null' to indicate a failed module - // instantiation. + // Set the module's state to 'failed' to indicate a failed module + // instantiation and reset the environment slot to 'undefined'. assert(IsModule(module), "Non-module passed to RecordInstantationFailure"); SetModuleState(module, MODULE_STATE_FAILED); UnsafeSetReservedSlot(module, MODULE_OBJECT_ENVIRONMENT_SLOT, undefined); @@ -267,6 +267,8 @@ function ModuleDeclarationInstantiation() ThrowSyntaxError(JSMSG_MISSING_IMPORT, imp.importName); if (resolution === "ambiguous") ThrowSyntaxError(JSMSG_AMBIGUOUS_IMPORT, imp.importName); + if (resolution.module.state < MODULE_STATE_INSTANTIATED) + ThrowInternalError(JSMSG_BAD_MODULE_STATE); CreateImportBinding(env, imp.localName, resolution.module, resolution.bindingName); } } diff --git a/js/src/jit-test/modules/export-circular-nonexisting-binding-1.js b/js/src/jit-test/modules/export-circular-nonexisting-binding-1.js new file mode 100644 index 000000000000..2b91b6a28473 --- /dev/null +++ b/js/src/jit-test/modules/export-circular-nonexisting-binding-1.js @@ -0,0 +1,4 @@ +import "export-circular-nonexisting-binding-2.js"; + +export* from "empty.js"; +export {x} from "empty.js"; diff --git a/js/src/jit-test/modules/export-circular-nonexisting-binding-2.js b/js/src/jit-test/modules/export-circular-nonexisting-binding-2.js new file mode 100644 index 000000000000..ba7dcc1b4879 --- /dev/null +++ b/js/src/jit-test/modules/export-circular-nonexisting-binding-2.js @@ -0,0 +1 @@ +export {x} from "export-circular-nonexisting-binding-1.js"; diff --git a/js/src/jit-test/tests/modules/export-circular-nonexisting-binding.js b/js/src/jit-test/tests/modules/export-circular-nonexisting-binding.js new file mode 100644 index 000000000000..387c7c369a3d --- /dev/null +++ b/js/src/jit-test/tests/modules/export-circular-nonexisting-binding.js @@ -0,0 +1,3 @@ +// |jit-test| module; error:SyntaxError + +import "export-circular-nonexisting-binding-1.js"; diff --git a/js/src/vm/EnvironmentObject.cpp b/js/src/vm/EnvironmentObject.cpp index cafc846668cc..e59842ef0461 100644 --- a/js/src/vm/EnvironmentObject.cpp +++ b/js/src/vm/EnvironmentObject.cpp @@ -488,7 +488,7 @@ ModuleEnvironmentObject::createImportBinding(JSContext* cx, HandleAtom importNam { RootedId importNameId(cx, AtomToId(importName)); RootedId localNameId(cx, AtomToId(localName)); - RootedModuleEnvironmentObject env(cx, module->environment()); + RootedModuleEnvironmentObject env(cx, &module->initialEnvironment()); if (!importBindings().putNew(cx, importNameId, env, localNameId)) { ReportOutOfMemory(cx); return false; From 14fdda126b5163f7d1a08b720d790c0dbbd6cefc Mon Sep 17 00:00:00 2001 From: Sean Stangl Date: Thu, 23 Feb 2017 12:11:00 -0500 Subject: [PATCH 084/102] Bug 1342196 - Remove assertion exception for MagicOptimizedArguments. r=h4writer --- js/src/jit/IonAnalysis.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/js/src/jit/IonAnalysis.cpp b/js/src/jit/IonAnalysis.cpp index 9260df3114a3..5410c7a4b657 100644 --- a/js/src/jit/IonAnalysis.cpp +++ b/js/src/jit/IonAnalysis.cpp @@ -3038,12 +3038,6 @@ jit::AssertExtendedGraphCoherency(MIRGraph& graph, bool underValueNumberer, bool for (MPhiIterator iter(block->phisBegin()), end(block->phisEnd()); iter != end; ++iter) { MPhi* phi = *iter; for (size_t i = 0, e = phi->numOperands(); i < e; ++i) { - // We sometimes see a phi with a magic-optimized-arguments - // operand defined in the normal entry block, while the phi is - // also reachable from the OSR entry (auto-regress/bug779818.js) - if (phi->getOperand(i)->type() == MIRType::MagicOptimizedArguments) - continue; - MOZ_ASSERT(phi->getOperand(i)->block()->dominates(block->getPredecessor(i)), "Phi input is not dominated by its operand"); } From 0669dcd3f51d00a6c42882834ea22d227677977d Mon Sep 17 00:00:00 2001 From: Emanuel Hoogeveen Date: Thu, 23 Feb 2017 14:27:00 -0500 Subject: [PATCH 085/102] Bug 1341889 - Part 1: Add more checks during reallocation to rule out other possibilities. r=jandem --- js/src/ds/PageProtectingVector.h | 116 ++++++++++++++++++++++++++++--- 1 file changed, 106 insertions(+), 10 deletions(-) diff --git a/js/src/ds/PageProtectingVector.h b/js/src/ds/PageProtectingVector.h index acd1440cb967..cf3bcd47b18a 100644 --- a/js/src/ds/PageProtectingVector.h +++ b/js/src/ds/PageProtectingVector.h @@ -8,13 +8,27 @@ #define ds_PageProtectingVector_h #include "mozilla/Atomics.h" +#include "mozilla/IntegerPrintfMacros.h" #include "mozilla/PodOperations.h" +#include "mozilla/Types.h" #include "mozilla/Vector.h" +#ifdef MALLOC_H +# include MALLOC_H +#endif + #include "ds/MemoryProtectionExceptionHandler.h" #include "gc/Memory.h" #include "js/Utility.h" +#ifdef MOZ_MEMORY +# ifdef XP_DARWIN +# define malloc_usable_size malloc_size +# else +extern "C" MFBT_API size_t malloc_usable_size(MALLOC_USABLE_SIZE_CONST_PTR void* p); +# endif +#endif + namespace js { /* @@ -455,23 +469,82 @@ PageProtectingVector::appendSlow(const U* values, size_t class ProtectedReallocPolicy { + uintptr_t currAddr; + size_t currSize; + uintptr_t prevAddr; + size_t prevSize; + + template void update(T* newAddr, size_t newSize) { + prevAddr = currAddr; + prevSize = currSize; + currAddr = uintptr_t(newAddr); + currSize = newSize * sizeof(T); + } + + template void updateIfValid(T* newAddr, size_t newSize) { + if (newAddr) + update(newAddr, newSize); + } + + template T* reallocUpdate(T* oldAddr, size_t oldSize, size_t newSize) { + T* newAddr = js_pod_realloc(oldAddr, oldSize, newSize); + updateIfValid(newAddr, newSize); + return newAddr; + } + public: + ProtectedReallocPolicy() : currAddr(0), currSize(0), prevAddr(0), prevSize(0) {} + + ~ProtectedReallocPolicy() { + MOZ_RELEASE_ASSERT(!currSize && !currAddr); + } + template T* maybe_pod_malloc(size_t numElems) { - return js_pod_malloc(numElems); + MOZ_RELEASE_ASSERT(!currSize && !currAddr); + T* addr = js_pod_malloc(numElems); + updateIfValid(addr, numElems); + return addr; } + template T* maybe_pod_calloc(size_t numElems) { - return js_pod_calloc(numElems); + MOZ_RELEASE_ASSERT(!currSize && !currAddr); + T* addr = js_pod_calloc(numElems); + updateIfValid(addr, numElems); + return addr; } + template T* maybe_pod_realloc(T* oldAddr, size_t oldSize, size_t newSize) { + if (uintptr_t(oldAddr) != currAddr) { + MOZ_CRASH_UNSAFE_PRINTF("maybe_pod_realloc: oldAddr and currAddr don't match " + "(0x%" PRIx64 " != 0x%" PRIx64 ", %" PRIu64 ")!", + uint64_t(oldAddr), uint64_t(currAddr), uint64_t(currSize)); + } + if (oldSize * sizeof(T) != currSize) { + MOZ_CRASH_UNSAFE_PRINTF("maybe_pod_realloc: oldSize and currSize don't match " + "(%" PRIu64 " != %" PRIu64 ", 0x%" PRIx64 ")!", + uint64_t(oldSize * sizeof(T)), uint64_t(currSize), + uint64_t(currAddr)); + } + MOZ_ASSERT_IF(oldAddr, oldSize); if (MOZ_UNLIKELY(!newSize)) return nullptr; if (MOZ_UNLIKELY(!oldAddr)) - return js_pod_malloc(newSize); + return maybe_pod_malloc(newSize); + +#ifdef MOZ_MEMORY + size_t usableSize = malloc_usable_size(oldAddr); + if (usableSize < currSize) { + MOZ_CRASH_UNSAFE_PRINTF("maybe_pod_realloc: usableSize < currSize " + "(%" PRIu64 " < %" PRIu64 ", %" PRIu64 ", %s)!", + uint64_t(usableSize), uint64_t(currSize), + uint64_t(prevSize), prevAddr == currAddr ? "true" : "false"); + } +#endif T* tmpAddr = js_pod_malloc(newSize); if (MOZ_UNLIKELY(!tmpAddr)) - return js_pod_realloc(oldAddr, oldSize, newSize); + return reallocUpdate(oldAddr, oldSize, newSize); size_t bytes = (newSize >= oldSize ? oldSize : newSize) * sizeof(T); memcpy(tmpAddr, oldAddr, bytes); @@ -479,19 +552,27 @@ class ProtectedReallocPolicy T* newAddr = js_pod_realloc(oldAddr, oldSize, newSize); if (MOZ_UNLIKELY(!newAddr)) { js_free(tmpAddr); - return js_pod_realloc(oldAddr, oldSize, newSize); + return reallocUpdate(oldAddr, oldSize, newSize); } const uint8_t* newAddrBytes = reinterpret_cast(newAddr); const uint8_t* tmpAddrBytes = reinterpret_cast(tmpAddr); if (!mozilla::PodEqual(tmpAddrBytes, newAddrBytes, bytes)) { - if (oldAddr == newAddr) - MOZ_CRASH("New buffer doesn't match the old buffer (newAddr == oldAddr)!"); - else - MOZ_CRASH("New buffer doesn't match the old buffer (newAddr != oldAddr)!"); +#ifdef MOZ_MEMORY + MOZ_CRASH_UNSAFE_PRINTF("maybe_pod_realloc: buffers don't match " + "(%" PRIu64 " >= %" PRIu64 ", %" PRIu64 ", %s)!", + uint64_t(usableSize), uint64_t(currSize), + uint64_t(prevSize), prevAddr == currAddr ? "true" : "false"); +#else + MOZ_CRASH_UNSAFE_PRINTF("maybe_pod_realloc: buffers don't match " + "(%" PRIu64 ", %" PRIu64 ", %s)!", + uint64_t(currSize), uint64_t(prevSize), + prevAddr == currAddr ? "true" : "false"); +#endif } js_free(tmpAddr); + update(newAddr, newSize); return newAddr; } @@ -500,7 +581,22 @@ class ProtectedReallocPolicy template T* pod_realloc(T* p, size_t oldSize, size_t newSize) { return maybe_pod_realloc(p, oldSize, newSize); } - void free_(void* p) { js_free(p); } + + void free_(void* p) { + MOZ_RELEASE_ASSERT(uintptr_t(p) == currAddr); +#ifdef MOZ_MEMORY + size_t usableSize = malloc_usable_size(p); + if (usableSize < currSize) { + MOZ_CRASH_UNSAFE_PRINTF("free_: usableSize < currSize " + "(%" PRIu64 " < %" PRIu64 ", %" PRIu64 ", %s)!", + uint64_t(usableSize), uint64_t(currSize), + uint64_t(prevSize), prevAddr == currAddr ? "true" : "false"); + } +#endif + js_free(p); + update(0, 0); + } + void reportAllocOverflow() const {} bool checkSimulatedOOM() const { return !js::oom::ShouldFailWithOOM(); From ef7f4555ba529c8b5efc936e511966466e55f24d Mon Sep 17 00:00:00 2001 From: Emanuel Hoogeveen Date: Thu, 23 Feb 2017 14:27:00 -0500 Subject: [PATCH 086/102] Bug 1341889 - Part 2: Add a hazard suppression for malloc_usable_size. r=sfink --- js/src/devtools/rootAnalysis/annotations.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/devtools/rootAnalysis/annotations.js b/js/src/devtools/rootAnalysis/annotations.js index 7e92b89b90de..1ca950e9e92b 100644 --- a/js/src/devtools/rootAnalysis/annotations.js +++ b/js/src/devtools/rootAnalysis/annotations.js @@ -160,6 +160,7 @@ function isSuppressedVirtualMethod(csu, method) var ignoreFunctions = { "ptio.c:pt_MapError" : true, "je_malloc_printf" : true, + "malloc_usable_size" : true, "vprintf_stderr" : true, "PR_ExplodeTime" : true, "PR_ErrorInstallTable" : true, From 0d6f78efb042f1c4841756673f5e00e4d7a57a58 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Thu, 23 Feb 2017 19:22:10 -0500 Subject: [PATCH 087/102] Bug 1342274 - Update pdf.js to version 1.7.312. r=bdahl --- browser/extensions/pdfjs/README.mozilla | 2 +- browser/extensions/pdfjs/content/build/pdf.js | 88 ++++++++- .../pdfjs/content/build/pdf.worker.js | 186 +++++++++--------- .../extensions/pdfjs/content/web/viewer.js | 44 ++++- 4 files changed, 207 insertions(+), 113 deletions(-) diff --git a/browser/extensions/pdfjs/README.mozilla b/browser/extensions/pdfjs/README.mozilla index 975b06fbe425..da0e38f01d95 100644 --- a/browser/extensions/pdfjs/README.mozilla +++ b/browser/extensions/pdfjs/README.mozilla @@ -1,3 +1,3 @@ This is the pdf.js project output, https://github.com/mozilla/pdf.js -Current extension version is: 1.7.297 +Current extension version is: 1.7.312 diff --git a/browser/extensions/pdfjs/content/build/pdf.js b/browser/extensions/pdfjs/content/build/pdf.js index 20b137d2ddd5..4b0b7fd115a5 100644 --- a/browser/extensions/pdfjs/content/build/pdf.js +++ b/browser/extensions/pdfjs/content/build/pdf.js @@ -221,6 +221,11 @@ var VERBOSITY_LEVELS = { warnings: 1, infos: 5 }; +var CMapCompressionType = { + NONE: 0, + BINARY: 1, + STREAM: 2 +}; var OPS = { dependency: 1, setLineWidth: 2, @@ -1166,6 +1171,12 @@ function isArrayBuffer(v) { function isSpace(ch) { return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A; } +function isNodeJS() { + if (typeof __pdfjsdev_webpack__ === 'undefined') { + return typeof process === 'object' && process + '' === '[object process]'; + } + return false; +} function createPromiseCapability() { var capability = {}; capability.promise = new Promise(function (resolve, reject) { @@ -1438,6 +1449,7 @@ exports.AnnotationFlag = AnnotationFlag; exports.AnnotationType = AnnotationType; exports.FontType = FontType; exports.ImageKind = ImageKind; +exports.CMapCompressionType = CMapCompressionType; exports.InvalidPDFException = InvalidPDFException; exports.MessageHandler = MessageHandler; exports.MissingDataException = MissingDataException; @@ -1474,6 +1486,7 @@ exports.isInt = isInt; exports.isNum = isNum; exports.isString = isString; exports.isSpace = isSpace; +exports.isNodeJS = isNodeJS; exports.isSameOrigin = isSameOrigin; exports.createValidAbsoluteUrl = createValidAbsoluteUrl; exports.isLittleEndian = isLittleEndian; @@ -1506,6 +1519,8 @@ var removeNullCharacters = sharedUtil.removeNullCharacters; var warn = sharedUtil.warn; var deprecated = sharedUtil.deprecated; var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl; +var stringToBytes = sharedUtil.stringToBytes; +var CMapCompressionType = sharedUtil.CMapCompressionType; var DEFAULT_LINK_REL = 'noopener noreferrer nofollow'; function DOMCanvasFactory() { } @@ -1535,6 +1550,48 @@ DOMCanvasFactory.prototype = { canvasAndContextPair.context = null; } }; +var DOMCMapReaderFactory = function DOMCMapReaderFactoryClosure() { + function DOMCMapReaderFactory(params) { + this.baseUrl = params.baseUrl || null; + this.isCompressed = params.isCompressed || false; + } + DOMCMapReaderFactory.prototype = { + fetch: function (params) { + if (!params.name) { + return Promise.reject(new Error('CMap name must be specified.')); + } + return new Promise(function (resolve, reject) { + var url = this.baseUrl + params.name; + var request = new XMLHttpRequest(); + if (this.isCompressed) { + url += '.bcmap'; + request.responseType = 'arraybuffer'; + } + request.onreadystatechange = function () { + if (request.readyState === XMLHttpRequest.DONE && (request.status === 200 || request.status === 0)) { + var data; + if (this.isCompressed && request.response) { + data = new Uint8Array(request.response); + } else if (!this.isCompressed && request.responseText) { + data = stringToBytes(request.responseText); + } + if (data) { + resolve({ + cMapData: data, + compressionType: this.isCompressed ? CMapCompressionType.BINARY : CMapCompressionType.NONE + }); + return; + } + reject(new Error('Unable to load ' + (this.isCompressed ? 'binary' : '') + ' CMap at: ' + url)); + } + }.bind(this); + request.open('GET', url, true); + request.send(null); + }.bind(this)); + } + }; + return DOMCMapReaderFactory; +}(); var CustomStyle = function CustomStyleClosure() { var prefixes = [ 'ms', @@ -1694,6 +1751,7 @@ exports.hasCanvasTypedArrays = hasCanvasTypedArrays; exports.getDefaultSetting = getDefaultSetting; exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL; exports.DOMCanvasFactory = DOMCanvasFactory; +exports.DOMCMapReaderFactory = DOMCMapReaderFactory; /***/ }), /* 2 */ @@ -2358,6 +2416,7 @@ var CanvasGraphics = displayCanvas.CanvasGraphics; var Metadata = displayMetadata.Metadata; var getDefaultSetting = displayDOMUtils.getDefaultSetting; var DOMCanvasFactory = displayDOMUtils.DOMCanvasFactory; +var DOMCMapReaderFactory = displayDOMUtils.DOMCMapReaderFactory; var DEFAULT_RANGE_CHUNK_SIZE = 65536; var isWorkerDisabled = false; var workerSrc; @@ -2431,6 +2490,7 @@ function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallb } params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE; params.disableNativeImageDecoder = params.disableNativeImageDecoder === true; + var CMapReaderFactory = params.CMapReaderFactory || DOMCMapReaderFactory; if (!worker) { worker = new PDFWorker(); task._worker = worker; @@ -2445,7 +2505,7 @@ function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallb throw new Error('Loading aborted'); } var messageHandler = new MessageHandler(docId, workerId, worker.port); - var transport = new WorkerTransport(messageHandler, task, rangeTransport); + var transport = new WorkerTransport(messageHandler, task, rangeTransport, CMapReaderFactory); task._transport = transport; messageHandler.send('Ready', null); }); @@ -2468,8 +2528,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { source: source, disableRange: getDefaultSetting('disableRange'), maxImageSize: getDefaultSetting('maxImageSize'), - cMapUrl: getDefaultSetting('cMapUrl'), - cMapPacked: getDefaultSetting('cMapPacked'), disableFontFace: getDefaultSetting('disableFontFace'), disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'), postMessageTransfers: getDefaultSetting('postMessageTransfers') && !isPostMessageTransfersDisabled, @@ -3081,12 +3139,16 @@ var PDFWorker = function PDFWorkerClosure() { return PDFWorker; }(); var WorkerTransport = function WorkerTransportClosure() { - function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) { + function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport, CMapReaderFactory) { this.messageHandler = messageHandler; this.loadingTask = loadingTask; this.pdfDataRangeTransport = pdfDataRangeTransport; this.commonObjs = new PDFObjects(); this.fontLoader = new FontLoader(loadingTask.docId); + this.CMapReaderFactory = new CMapReaderFactory({ + baseUrl: getDefaultSetting('cMapUrl'), + isCompressed: getDefaultSetting('cMapPacked') + }); this.destroyed = false; this.destroyCapability = null; this._passwordCapability = null; @@ -3371,6 +3433,12 @@ var WorkerTransport = function WorkerTransportClosure() { img.src = imageUrl; }); }, this); + messageHandler.on('FetchBuiltInCMap', function (data) { + if (this.destroyed) { + return Promise.reject(new Error('Worker was destroyed')); + } + return this.CMapReaderFactory.fetch({ name: data.name }); + }, this); }, getData: function WorkerTransport_getData() { return this.messageHandler.sendWithPromise('GetData', null); @@ -3632,8 +3700,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() { } }; }(); -exports.version = '1.7.297'; -exports.build = '425ad309'; +exports.version = '1.7.312'; +exports.build = 'cada411a'; exports.getDocument = getDocument; exports.PDFDataRangeTransport = PDFDataRangeTransport; exports.PDFWorker = PDFWorker; @@ -4650,8 +4718,8 @@ if (!globalScope.PDFJS) { globalScope.PDFJS = {}; } var PDFJS = globalScope.PDFJS; -PDFJS.version = '1.7.297'; -PDFJS.build = '425ad309'; +PDFJS.version = '1.7.312'; +PDFJS.build = 'cada411a'; PDFJS.pdfBug = false; if (PDFJS.verbosity !== undefined) { sharedUtil.setVerbosityLevel(PDFJS.verbosity); @@ -7143,8 +7211,8 @@ exports.TilingPattern = TilingPattern; "use strict"; -var pdfjsVersion = '1.7.297'; -var pdfjsBuild = '425ad309'; +var pdfjsVersion = '1.7.312'; +var pdfjsBuild = 'cada411a'; var pdfjsSharedUtil = __w_pdfjs_require__(0); var pdfjsDisplayGlobal = __w_pdfjs_require__(8); var pdfjsDisplayAPI = __w_pdfjs_require__(3); diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 63170673249f..8c47f3c4b461 100644 --- a/browser/extensions/pdfjs/content/build/pdf.worker.js +++ b/browser/extensions/pdfjs/content/build/pdf.worker.js @@ -221,6 +221,11 @@ var VERBOSITY_LEVELS = { warnings: 1, infos: 5 }; +var CMapCompressionType = { + NONE: 0, + BINARY: 1, + STREAM: 2 +}; var OPS = { dependency: 1, setLineWidth: 2, @@ -1166,6 +1171,12 @@ function isArrayBuffer(v) { function isSpace(ch) { return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A; } +function isNodeJS() { + if (typeof __pdfjsdev_webpack__ === 'undefined') { + return typeof process === 'object' && process + '' === '[object process]'; + } + return false; +} function createPromiseCapability() { var capability = {}; capability.promise = new Promise(function (resolve, reject) { @@ -1438,6 +1449,7 @@ exports.AnnotationFlag = AnnotationFlag; exports.AnnotationType = AnnotationType; exports.FontType = FontType; exports.ImageKind = ImageKind; +exports.CMapCompressionType = CMapCompressionType; exports.InvalidPDFException = InvalidPDFException; exports.MessageHandler = MessageHandler; exports.MissingDataException = MissingDataException; @@ -1474,6 +1486,7 @@ exports.isInt = isInt; exports.isNum = isNum; exports.isString = isString; exports.isSpace = isSpace; +exports.isNodeJS = isNodeJS; exports.isSameOrigin = isSameOrigin; exports.createValidAbsoluteUrl = createValidAbsoluteUrl; exports.isLittleEndian = isLittleEndian; @@ -24787,6 +24800,7 @@ var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES; var ImageKind = sharedUtil.ImageKind; var OPS = sharedUtil.OPS; var TextRenderingMode = sharedUtil.TextRenderingMode; +var CMapCompressionType = sharedUtil.CMapCompressionType; var Util = sharedUtil.Util; var assert = sharedUtil.assert; var createPromiseCapability = sharedUtil.createPromiseCapability; @@ -24845,10 +24859,6 @@ var PartialEvaluator = function PartialEvaluatorClosure() { forceDataSchema: false, maxImageSize: -1, disableFontFace: false, - cMapOptions: { - url: null, - packed: false - }, disableNativeImageDecoder: false }; function NativeImageDecoder(xref, resources, handler, forceDataSchema) { @@ -24892,14 +24902,27 @@ var PartialEvaluator = function PartialEvaluatorClosure() { var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res); return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D')); }; - function PartialEvaluator(pdfManager, xref, handler, pageIndex, idFactory, fontCache, options) { + function PartialEvaluator(pdfManager, xref, handler, pageIndex, idFactory, fontCache, builtInCMapCache, options) { this.pdfManager = pdfManager; this.xref = xref; this.handler = handler; this.pageIndex = pageIndex; this.idFactory = idFactory; this.fontCache = fontCache; + this.builtInCMapCache = builtInCMapCache; this.options = options || DefaultPartialEvaluatorOptions; + this.fetchBuiltInCMap = function (name) { + var cachedCMap = builtInCMapCache[name]; + if (cachedCMap) { + return Promise.resolve(cachedCMap); + } + return handler.sendWithPromise('FetchBuiltInCMap', { name: name }).then(function (data) { + if (data.compressionType !== CMapCompressionType.NONE) { + builtInCMapCache[name] = data; + } + return data; + }); + }; } var TIME_SLOT_DURATION_MS = 20; var CHECK_TIME_EVERY = 100; @@ -26236,7 +26259,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() { var registry = properties.cidSystemInfo.registry; var ordering = properties.cidSystemInfo.ordering; var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2'); - return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) { + return CMapFactory.create({ + encoding: ucs2CMapName, + fetchBuiltInCMap: this.fetchBuiltInCMap, + useCMap: null + }).then(function (ucs2CMap) { var cMap = properties.cMap; toUnicode = []; cMap.forEach(function (charcode, cid) { @@ -26254,14 +26281,22 @@ var PartialEvaluator = function PartialEvaluatorClosure() { readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) { var cmapObj = toUnicode; if (isName(cmapObj)) { - return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) { + return CMapFactory.create({ + encoding: cmapObj, + fetchBuiltInCMap: this.fetchBuiltInCMap, + useCMap: null + }).then(function (cmap) { if (cmap instanceof IdentityCMap) { return new IdentityToUnicodeMap(0, 0xFFFF); } return new ToUnicodeMap(cmap.getMap()); }); } else if (isStream(cmapObj)) { - return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) { + return CMapFactory.create({ + encoding: cmapObj, + fetchBuiltInCMap: this.fetchBuiltInCMap, + useCMap: null + }).then(function (cmap) { if (cmap instanceof IdentityCMap) { return new IdentityToUnicodeMap(0, 0xFFFF); } @@ -26524,7 +26559,6 @@ var PartialEvaluator = function PartialEvaluatorClosure() { var descriptor = preEvaluatedFont.descriptor; var type = preEvaluatedFont.type; var maxCharIndex = composite ? 0xFFFF : 0xFF; - var cMapOptions = this.options.cMapOptions; var properties; if (!descriptor) { if (type === 'Type3') { @@ -26619,7 +26653,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() { if (isName(cidEncoding)) { properties.cidEncoding = cidEncoding.name; } - cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) { + cMapPromise = CMapFactory.create({ + encoding: cidEncoding, + fetchBuiltInCMap: this.fetchBuiltInCMap, + useCMap: null + }).then(function (cMap) { properties.cMap = cMap; properties.vertical = properties.cMap.vertical; }); @@ -29872,6 +29910,7 @@ var Catalog = function CatalogClosure() { this.xref = xref; this.catDict = xref.getCatalogObj(); this.fontCache = new RefSetCache(); + this.builtInCMapCache = Object.create(null); assert(isDict(this.catDict), 'catalog object is not a dictionary'); this.pageFactory = pageFactory; this.pagePromises = []; @@ -30186,6 +30225,7 @@ var Catalog = function CatalogClosure() { delete font.translated; } this.fontCache.clear(); + this.builtInCMapCache = Object.create(null); }.bind(this)); }, getPage: function Catalog_getPage(pageIndex) { @@ -30193,7 +30233,7 @@ var Catalog = function CatalogClosure() { this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) { var dict = a[0]; var ref = a[1]; - return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache); + return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache, this.builtInCMapCache); }.bind(this)); } return this.pagePromises[pageIndex]; @@ -33926,6 +33966,7 @@ var error = sharedUtil.error; var info = sharedUtil.info; var warn = sharedUtil.warn; var setVerbosityLevel = sharedUtil.setVerbosityLevel; +var isNodeJS = sharedUtil.isNodeJS; var Ref = corePrimitives.Ref; var LocalPdfManager = corePdfManager.LocalPdfManager; var NetworkPdfManager = corePdfManager.NetworkPdfManager; @@ -34403,15 +34444,10 @@ var WorkerMessageHandler = { }, onFailure); } ensureNotTerminated(); - var cMapOptions = { - url: data.cMapUrl === undefined ? null : data.cMapUrl, - packed: data.cMapPacked === true - }; var evaluatorOptions = { forceDataSchema: data.disableCreateObjectURL, maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize, disableFontFace: data.disableFontFace, - cMapOptions: cMapOptions, disableNativeImageDecoder: data.disableNativeImageDecoder }; getPdfManager(data, evaluatorOptions).then(function (newPdfManager) { @@ -34588,12 +34624,6 @@ function initializeWorker() { WorkerMessageHandler.setup(handler, self); handler.send('ready', null); } -function isNodeJS() { - if (typeof __pdfjsdev_webpack__ === 'undefined') { - return typeof process === 'object' && process + '' === '[object process]'; - } - return false; -} if (typeof window === 'undefined' && !isNodeJS()) { initializeWorker(); } @@ -36580,11 +36610,12 @@ var error = sharedUtil.error; var isInt = sharedUtil.isInt; var isString = sharedUtil.isString; var MissingDataException = sharedUtil.MissingDataException; +var CMapCompressionType = sharedUtil.CMapCompressionType; var isEOF = corePrimitives.isEOF; var isName = corePrimitives.isName; var isCmd = corePrimitives.isCmd; var isStream = corePrimitives.isStream; -var StringStream = coreStream.StringStream; +var Stream = coreStream.Stream; var Lexer = coreParser.Lexer; var BUILT_IN_CMAPS = [ 'Adobe-GB1-UCS2', @@ -36919,23 +36950,6 @@ var IdentityCMap = function IdentityCMapClosure() { return IdentityCMap; }(); var BinaryCMapReader = function BinaryCMapReaderClosure() { - function fetchBinaryData(url) { - return new Promise(function (resolve, reject) { - var request = new XMLHttpRequest(); - request.open('GET', url, true); - request.responseType = 'arraybuffer'; - request.onreadystatechange = function () { - if (request.readyState === XMLHttpRequest.DONE) { - if (!request.response || request.status !== 200 && request.status !== 0) { - reject(new Error('Unable to get binary cMap at: ' + url)); - } else { - resolve(new Uint8Array(request.response)); - } - } - }; - request.send(null); - }); - } function hexToInt(a, size) { var n = 0; for (var i = 0; i <= size; i++) { @@ -37045,8 +37059,8 @@ var BinaryCMapReader = function BinaryCMapReaderClosure() { return s; } }; - function processBinaryCMap(url, cMap, extend) { - return fetchBinaryData(url).then(function (data) { + function processBinaryCMap(data, cMap, extend) { + return new Promise(function (resolve, reject) { var stream = new BinaryCMapStream(data); var header = stream.readByte(); cMap.vertical = !!(header & 1); @@ -37177,19 +37191,20 @@ var BinaryCMapReader = function BinaryCMapReaderClosure() { } break; default: - error('Unknown type: ' + type); - break; + reject(new Error('processBinaryCMap: Unknown type: ' + type)); + return; } } if (useCMap) { - return extend(useCMap); + resolve(extend(useCMap)); + return; } - return cMap; + resolve(cMap); }); } function BinaryCMapReader() { } - BinaryCMapReader.prototype = { read: processBinaryCMap }; + BinaryCMapReader.prototype = { process: processBinaryCMap }; return BinaryCMapReader; }(); var CMapFactory = function CMapFactoryClosure() { @@ -37330,7 +37345,7 @@ var CMapFactory = function CMapFactoryClosure() { cMap.name = obj.name; } } - function parseCMap(cMap, lexer, builtInCMapParams, useCMap) { + function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) { var previous; var embededUseCMap; objLoop: @@ -37384,12 +37399,12 @@ var CMapFactory = function CMapFactoryClosure() { useCMap = embededUseCMap; } if (useCMap) { - return extendCMap(cMap, builtInCMapParams, useCMap); + return extendCMap(cMap, fetchBuiltInCMap, useCMap); } return Promise.resolve(cMap); } - function extendCMap(cMap, builtInCMapParams, useCMap) { - return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) { + function extendCMap(cMap, fetchBuiltInCMap, useCMap) { + return createBuiltInCMap(useCMap, fetchBuiltInCMap).then(function (newCMap) { cMap.useCMap = newCMap; if (cMap.numCodespaceRanges === 0) { var useCodespaceRanges = cMap.useCMap.codespaceRanges; @@ -37406,14 +37421,7 @@ var CMapFactory = function CMapFactoryClosure() { return cMap; }); } - function parseBinaryCMap(name, builtInCMapParams) { - var url = builtInCMapParams.url + name + '.bcmap'; - var cMap = new CMap(true); - return new BinaryCMapReader().read(url, cMap, function (useCMap) { - return extendCMap(cMap, builtInCMapParams, useCMap); - }); - } - function createBuiltInCMap(name, builtInCMapParams) { + function createBuiltInCMap(name, fetchBuiltInCMap) { if (name === 'Identity-H') { return Promise.resolve(new IdentityCMap(false, 2)); } else if (name === 'Identity-V') { @@ -37422,40 +37430,33 @@ var CMapFactory = function CMapFactoryClosure() { if (BUILT_IN_CMAPS.indexOf(name) === -1) { return Promise.reject(new Error('Unknown cMap name: ' + name)); } - assert(builtInCMapParams, 'built-in cMap parameters are not provided'); - if (builtInCMapParams.packed) { - return parseBinaryCMap(name, builtInCMapParams); - } - return new Promise(function (resolve, reject) { - var url = builtInCMapParams.url + name; - var request = new XMLHttpRequest(); - request.onreadystatechange = function () { - if (request.readyState === XMLHttpRequest.DONE) { - if (request.status === 200 || request.status === 0) { - var cMap = new CMap(true); - var lexer = new Lexer(new StringStream(request.responseText)); - parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) { - resolve(parsedCMap); - }); - } else { - reject(new Error('Unable to get cMap at: ' + url)); - } - } - }; - request.open('GET', url, true); - request.send(null); + assert(fetchBuiltInCMap, 'Built-in CMap parameters are not provided.'); + return fetchBuiltInCMap(name).then(function (data) { + var cMapData = data.cMapData, compressionType = data.compressionType; + var cMap = new CMap(true); + if (compressionType === CMapCompressionType.BINARY) { + return new BinaryCMapReader().process(cMapData, cMap, function (useCMap) { + return extendCMap(cMap, fetchBuiltInCMap, useCMap); + }); + } + assert(compressionType === CMapCompressionType.NONE, 'TODO: Only BINARY/NONE CMap compression is currently supported.'); + var lexer = new Lexer(new Stream(cMapData)); + return parseCMap(cMap, lexer, fetchBuiltInCMap, null); }); } return { - create: function (encoding, builtInCMapParams, useCMap) { + create: function (params) { + var encoding = params.encoding; + var fetchBuiltInCMap = params.fetchBuiltInCMap; + var useCMap = params.useCMap; if (isName(encoding)) { - return createBuiltInCMap(encoding.name, builtInCMapParams); + return createBuiltInCMap(encoding.name, fetchBuiltInCMap); } else if (isStream(encoding)) { var cMap = new CMap(); var lexer = new Lexer(encoding); - return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) { + return parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap).then(function (parsedCMap) { if (parsedCMap.isIdentityCMap) { - return createBuiltInCMap(parsedCMap.name, builtInCMapParams); + return createBuiltInCMap(parsedCMap.name, fetchBuiltInCMap); } return parsedCMap; }); @@ -37520,13 +37521,14 @@ var Page = function PageClosure() { 612, 792 ]; - function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) { + function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache, builtInCMapCache) { this.pdfManager = pdfManager; this.pageIndex = pageIndex; this.pageDict = pageDict; this.xref = xref; this.ref = ref; this.fontCache = fontCache; + this.builtInCMapCache = builtInCMapCache; this.evaluatorOptions = pdfManager.evaluatorOptions; this.resourcesPromise = null; var uniquePrefix = 'p' + this.pageIndex + '_'; @@ -37652,7 +37654,7 @@ var Page = function PageClosure() { 'XObject', 'Font' ]); - var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.idFactory, this.fontCache, this.evaluatorOptions); + var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.idFactory, this.fontCache, this.builtInCMapCache, this.evaluatorOptions); var dataPromises = Promise.all([ contentStreamPromise, resourcesPromise @@ -37708,7 +37710,7 @@ var Page = function PageClosure() { ]); return dataPromises.then(function (data) { var contentStream = data[0]; - var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.idFactory, self.fontCache, self.evaluatorOptions); + var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.idFactory, self.fontCache, self.builtInCMapCache, self.evaluatorOptions); return partialEvaluator.getTextContent(contentStream, task, self.resources, null, normalizeWhitespace, combineTextItems); }); }, @@ -37901,8 +37903,8 @@ var PDFDocument = function PDFDocumentClosure() { this.xref.parse(recoveryMode); var self = this; var pageFactory = { - createPage: function (pageIndex, dict, ref, fontCache) { - return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache); + createPage: function (pageIndex, dict, ref, fontCache, builtInCMapCache) { + return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache, builtInCMapCache); } }; this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory); @@ -49174,8 +49176,8 @@ exports.Type1Parser = Type1Parser; "use strict"; -var pdfjsVersion = '1.7.297'; -var pdfjsBuild = '425ad309'; +var pdfjsVersion = '1.7.312'; +var pdfjsBuild = 'cada411a'; var pdfjsCoreWorker = __w_pdfjs_require__(17); ; exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler; diff --git a/browser/extensions/pdfjs/content/web/viewer.js b/browser/extensions/pdfjs/content/web/viewer.js index e163c108658c..749355fed12c 100644 --- a/browser/extensions/pdfjs/content/web/viewer.js +++ b/browser/extensions/pdfjs/content/web/viewer.js @@ -321,8 +321,11 @@ function getVisibleElements(scrollEl, views, sortByVisibility) { function noContextMenuHandler(e) { e.preventDefault(); } -function getPDFFileNameFromURL(url) { - var reURI = /^(?:([^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/; +function getPDFFileNameFromURL(url, defaultFilename) { + if (typeof defaultFilename === 'undefined') { + defaultFilename = 'document.pdf'; + } + var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/; var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i; var splitURI = reURI.exec(url); var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]); @@ -335,7 +338,7 @@ function getPDFFileNameFromURL(url) { } } } - return suggestedFilename || 'document.pdf'; + return suggestedFilename || defaultFilename; } function normalizeWheelEventDelta(evt) { var delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY); @@ -1148,11 +1151,15 @@ var PDFViewerApplication = { setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) { this.url = url; this.baseUrl = url.split('#')[0]; - try { - this.setTitle(decodeURIComponent(pdfjsLib.getFilenameFromUrl(url)) || url); - } catch (e) { - this.setTitle(url); + var title = getPDFFileNameFromURL(url, ''); + if (!title) { + try { + title = decodeURIComponent(pdfjsLib.getFilenameFromUrl(url)) || url; + } catch (e) { + title = url; + } } + this.setTitle(title); }, setTitle: function pdfViewSetTitle(title) { if (this.isViewerEmbedded) { @@ -1251,7 +1258,7 @@ var PDFViewerApplication = { downloadManager.downloadUrl(url, filename); } var url = this.baseUrl; - var filename = getPDFFileNameFromURL(url); + var filename = getPDFFileNameFromURL(this.url); var downloadManager = this.downloadManager; downloadManager.onerror = function (err) { PDFViewerApplication.error('PDF failed to download.'); @@ -3896,6 +3903,18 @@ var PDFAttachmentViewer = function PDFAttachmentViewerClosure() { }); this._renderedCapability.resolve(); }, + _bindPdfLink: function PDFAttachmentViewer_bindPdfLink(button, content, filename) { + var blobUrl; + button.onclick = function () { + if (!blobUrl) { + blobUrl = pdfjsLib.createObjectURL(content, 'application/pdf', pdfjsLib.PDFJS.disableCreateObjectURL); + } + var viewerUrl; + viewerUrl = blobUrl + '?' + encodeURIComponent(filename); + window.open(viewerUrl); + return false; + }; + }, _bindLink: function PDFAttachmentViewer_bindLink(button, content, filename) { button.onclick = function downloadFile(e) { this.downloadManager.downloadData(content, filename, ''); @@ -3922,11 +3941,16 @@ var PDFAttachmentViewer = function PDFAttachmentViewerClosure() { for (var i = 0; i < attachmentsCount; i++) { var item = attachments[names[i]]; var filename = pdfjsLib.getFilenameFromUrl(item.filename); + filename = pdfjsLib.removeNullCharacters(filename); var div = document.createElement('div'); div.className = 'attachmentsItem'; var button = document.createElement('button'); - this._bindLink(button, item.content, filename); - button.textContent = pdfjsLib.removeNullCharacters(filename); + button.textContent = filename; + if (/\.pdf$/i.test(filename)) { + this._bindPdfLink(button, item.content, filename); + } else { + this._bindLink(button, item.content, filename); + } div.appendChild(button); this.container.appendChild(div); } From b90c90aec2879423f9972fb0aa9874e3b2cae460 Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Thu, 23 Feb 2017 17:47:02 -0800 Subject: [PATCH 088/102] Bug 1341621 - Avoid deadlocks in DMD when forking. r=njn In order to avoid the possibility of a deadlock if the DMD state lock is currently acquired when forking a |pthread_atfork| hook is added to wait for and acquire the lock prior to forking, then release it after forking. --- memory/replace/dmd/DMD.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/memory/replace/dmd/DMD.cpp b/memory/replace/dmd/DMD.cpp index 49eb2797020b..4019119651a7 100644 --- a/memory/replace/dmd/DMD.cpp +++ b/memory/replace/dmd/DMD.cpp @@ -1546,6 +1546,22 @@ NopStackWalkCallback(uint32_t aFrameNumber, void* aPc, void* aSp, } #endif +static void +prefork() +{ + if (gStateLock) { + gStateLock->Lock(); + } +} + +static void +postfork() +{ + if (gStateLock) { + gStateLock->Unlock(); + } +} + // WARNING: this function runs *very* early -- before all static initializers // have run. For this reason, non-scalar globals such as gStateLock and // gStackTraceTable are allocated dynamically (so we can guarantee their @@ -1556,6 +1572,16 @@ Init(const malloc_table_t* aMallocTable) gMallocTable = aMallocTable; gDMDBridge = InfallibleAllocPolicy::new_(); +#ifndef XP_WIN + // Avoid deadlocks when forking by acquiring our state lock prior to forking + // and releasing it after forking. See |LogAlloc|'s |replace_init| for + // in-depth details. + // + // Note: This must run after attempting an allocation so as to give the + // system malloc a chance to insert its own atfork handler. + pthread_atfork(prefork, postfork, postfork); +#endif + // DMD is controlled by the |DMD| environment variable. const char* e = getenv("DMD"); From 5855c0f88a746404ae819be3c1934559f5ed81b2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 23 Feb 2017 14:26:46 +1100 Subject: [PATCH 089/102] Bug 1340928 (part 16) - Clean up profiler env var handling. r=mstange. This patch does the following. - Uses "entries" consistently for the name of the value that is obtained from MOZ_PROFILER_ENTRIES and is the first argument to profiler_start(). (I.e. not "entry" or "entrySize".) - Removes variables (e.g. PROFILER_HELP) holding env var names and uses the names (e.g. "MOZ_PROFILER_HELP") directly. Some of the names are already used directly and I think the slight repetition isn't harmful. It's unlikely that we'd want to change these names the way we might need to change a numeric value, and they're perfectly descriptive. - Changes the "MOZ_PROFILING_FEATURES" string in the weird Android-only startup code to be "MOZ_PROFILER_FEATURES", for consistency. - Renames gUnwindInterval and gProfileEntries as gEnvVarInterval and gEnvVarEntries to make it clearer that they come from environment variables, but otherwise are parallel to gInterval and gEntries. - Puts entries before intervals in most places, to match the profiler_start() argument order. - Changes profiler_usage() so that (a) it always prints, no matter the verbosity, (b) it exits at its end, and (c) doesn't double-print "Profiler: " at the start of each line. --- tools/profiler/core/SyncProfile.cpp | 2 +- .../profiler/core/platform-linux-android.cpp | 21 ++- tools/profiler/core/platform.cpp | 174 +++++++----------- tools/profiler/gecko/nsProfiler.cpp | 3 +- tools/profiler/public/GeckoProfiler.h | 24 +-- widget/android/ANRReporter.cpp | 6 +- 6 files changed, 102 insertions(+), 128 deletions(-) diff --git a/tools/profiler/core/SyncProfile.cpp b/tools/profiler/core/SyncProfile.cpp index c164f0e51798..4b092bd5b138 100644 --- a/tools/profiler/core/SyncProfile.cpp +++ b/tools/profiler/core/SyncProfile.cpp @@ -12,7 +12,7 @@ SyncProfile::SyncProfile(int aThreadId, PseudoStack* aStack) , mOwnerState(REFERENCED) { MOZ_COUNT_CTOR(SyncProfile); - SetProfile(new ProfileBuffer(GET_BACKTRACE_DEFAULT_ENTRY)); + SetProfile(new ProfileBuffer(GET_BACKTRACE_DEFAULT_ENTRIES)); } SyncProfile::~SyncProfile() diff --git a/tools/profiler/core/platform-linux-android.cpp b/tools/profiler/core/platform-linux-android.cpp index 7713b837ba73..6b9cbdba4bcc 100644 --- a/tools/profiler/core/platform-linux-android.cpp +++ b/tools/profiler/core/platform-linux-android.cpp @@ -458,10 +458,12 @@ static uint32_t readCSVArray(char* csvList, const char** buffer) { return count; } -// Currently support only the env variables -// reported in read_profiler_env -static void ReadProfilerVars(const char* fileName, const char** features, - uint32_t* featureCount, const char** threadNames, uint32_t* threadCount) { +// Support some of the env variables reported in ReadProfilerEnvVars, plus some +// extra stuff. +static void +ReadProfilerVars(const char* fileName, + const char** features, uint32_t* featureCount, + const char** threadNames, uint32_t* threadCount) { FILE* file = fopen(fileName, "r"); const int bufferSize = 1024; char line[bufferSize]; @@ -474,11 +476,11 @@ static void ReadProfilerVars(const char* fileName, const char** features, feature = strtok_r(line, "=", &savePtr); value = strtok_r(NULL, "", &savePtr); - if (strncmp(feature, PROFILER_INTERVAL, bufferSize) == 0) { + if (strncmp(feature, "MOZ_PROFILER_INTERVAL", bufferSize) == 0) { set_profiler_interval(value); - } else if (strncmp(feature, PROFILER_ENTRIES, bufferSize) == 0) { + } else if (strncmp(feature, "MOZ_PROFILER_ENTRIES", bufferSize) == 0) { set_profiler_entries(value); - } else if (strncmp(feature, PROFILER_FEATURES, bufferSize) == 0) { + } else if (strncmp(feature, "MOZ_PROFILER_FEATURES", bufferSize) == 0) { *featureCount = readCSVArray(value, features); } else if (strncmp(feature, "threads", bufferSize) == 0) { *threadCount = readCSVArray(value, threadNames); @@ -505,9 +507,8 @@ static void DoStartTask() { MOZ_ASSERT(featureCount < 10); MOZ_ASSERT(threadCount < 10); - profiler_start(PROFILE_DEFAULT_ENTRY, 1, - features, featureCount, - threadNames, threadCount); + profiler_start(PROFILE_DEFAULT_ENTRIES, /* interval */ 1, + features, featureCount, threadNames, threadCount); freeArray(threadNames, threadCount); freeArray(features, featureCount); diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index b268e9237121..cfb0c9991df9 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -119,8 +119,8 @@ static mozilla::StaticMutex gThreadNameFiltersMutex; // All accesses to gFeatures are on the main thread, so no locking is needed. static Vector gFeatures; -// All accesses to gEntrySize are on the main thread, so no locking is needed. -static int gEntrySize = 0; +// All accesses to gEntries are on the main thread, so no locking is needed. +static int gEntries = 0; // All accesses to gInterval are on the main thread, so no locking is needed. static double gInterval = 0; @@ -173,8 +173,8 @@ static Atomic gUseStackWalk(false); * to know are associated with different events */ // Values harvested from env vars, that control the profiler. -static int gUnwindInterval; /* in milliseconds */ -static int gProfileEntries; /* how many entries do we store? */ +static int gEnvVarEntries; /* how many entries do we store? */ +static int gEnvVarInterval; /* in milliseconds */ static mozilla::StaticAutoPtr gInterposeObserver; @@ -1233,9 +1233,7 @@ void ProfilerMarker::StreamJSON(SpliceableJSONWriter& aWriter, } // Verbosity control for the profiler. The aim is to check env var -// MOZ_PROFILER_VERBOSE only once. However, we may need to temporarily -// override that so as to print the profiler's help message. That's -// what profiler_set_verbosity is for. +// MOZ_PROFILER_VERBOSE only once. enum class Verbosity : int8_t { UNCHECKED, NOTVERBOSE, VERBOSE }; @@ -1247,21 +1245,13 @@ profiler_verbose() { if (gVerbosity == Verbosity::UNCHECKED) { gVerbosity = getenv("MOZ_PROFILER_VERBOSE") - ? Verbosity::VERBOSE - : Verbosity::NOTVERBOSE; + ? Verbosity::VERBOSE + : Verbosity::NOTVERBOSE; } return gVerbosity == Verbosity::VERBOSE; } -static void -profiler_set_verbosity(Verbosity aPv) -{ - MOZ_ASSERT(aPv == Verbosity::UNCHECKED || - aPv == Verbosity::VERBOSE); - gVerbosity = aPv; -} - static bool set_profiler_interval(const char* aInterval) { @@ -1269,7 +1259,7 @@ set_profiler_interval(const char* aInterval) errno = 0; long int n = strtol(aInterval, nullptr, 10); if (errno == 0 && 1 <= n && n <= 1000) { - gUnwindInterval = n; + gEnvVarInterval = n; return true; } return false; @@ -1285,7 +1275,7 @@ set_profiler_entries(const char* aEntries) errno = 0; long int n = strtol(aEntries, nullptr, 10); if (errno == 0 && n > 0) { - gProfileEntries = n; + gEnvVarEntries = n; return true; } return false; @@ -1304,84 +1294,63 @@ is_native_unwinding_avail() #endif } -// Environment variables to control the profiler -static const char* PROFILER_HELP = "MOZ_PROFILER_HELP"; -static const char* PROFILER_INTERVAL = "MOZ_PROFILER_INTERVAL"; -static const char* PROFILER_ENTRIES = "MOZ_PROFILER_ENTRIES"; -#if defined(GP_OS_android) -static const char* PROFILER_FEATURES = "MOZ_PROFILING_FEATURES"; -#endif - static void -profiler_usage() +profiler_usage(int aExitCode) { - LOG( "Profiler: "); - LOG( "Profiler: Environment variable usage:"); - LOG( "Profiler: "); - LOG( "Profiler: MOZ_PROFILER_HELP"); - LOG( "Profiler: If set to any value, prints this message."); - LOG( "Profiler: "); - LOG( "Profiler: MOZ_PROFILER_INTERVAL= (milliseconds, 1 to 1000)"); - LOG( "Profiler: If unset, platform default is used."); - LOG( "Profiler: "); - LOG( "Profiler: MOZ_PROFILER_ENTRIES= (count, minimum of 1)"); - LOG( "Profiler: If unset, platform default is used."); - LOG( "Profiler: "); - LOG( "Profiler: MOZ_PROFILER_VERBOSE"); - LOG( "Profiler: If set to any value, increases verbosity (recommended)."); - LOG( "Profiler: "); - LOG( "Profiler: MOZ_PROFILER_LUL_TEST"); - LOG( "Profiler: If set to any value, runs LUL unit tests at startup of"); - LOG( "Profiler: the unwinder thread, and prints a short summary of results."); - LOG( "Profiler: "); - LOGF("Profiler: This platform %s native unwinding.", + // Force-enable verbosity so that LOG prints something. + gVerbosity = Verbosity::VERBOSE; + + LOG (""); + LOG ("Environment variable usage:"); + LOG (""); + LOG (" MOZ_PROFILER_HELP"); + LOG (" If set to any value, prints this message."); + LOG (""); + LOG (" MOZ_PROFILER_ENTRIES=<1..> (count)"); + LOG (" If unset, platform default is used."); + LOG (""); + LOG (" MOZ_PROFILER_INTERVAL=<1..1000> (milliseconds)"); + LOG (" If unset, platform default is used."); + LOG (""); + LOG (" MOZ_PROFILER_VERBOSE"); + LOG (" If set to any value, increases verbosity (recommended)."); + LOG (""); + LOG (" MOZ_PROFILER_LUL_TEST"); + LOG (" If set to any value, runs LUL unit tests at startup of"); + LOG (" the unwinder thread, and prints a short summary of "); + LOG (" results."); + LOG (""); + LOGF(" This platform %s native unwinding.", is_native_unwinding_avail() ? "supports" : "does not support"); - LOG( "Profiler: "); + LOG (""); - /* Re-set defaults */ - gUnwindInterval = 0; /* We'll have to look elsewhere */ - gProfileEntries = 0; - - LOG( "Profiler:"); - LOGF("Profiler: Sampling interval = %d ms (zero means \"platform default\")", - (int)gUnwindInterval); - LOGF("Profiler: Entry store size = %d (zero means \"platform default\")", - (int)gProfileEntries); - LOG( "Profiler:"); + exit(aExitCode); } // Read env vars at startup, so as to set: -// gUnwindInterval, gProfileEntries +// gEnvVarEntries, gEnvVarInterval static void -read_profiler_env_vars() +ReadProfilerEnvVars() { - /* Set defaults */ - gUnwindInterval = 0; /* We'll have to look elsewhere */ - gProfileEntries = 0; + const char* help = getenv("MOZ_PROFILER_HELP"); + const char* entries = getenv("MOZ_PROFILER_ENTRIES"); + const char* interval = getenv("MOZ_PROFILER_INTERVAL"); - const char* interval = getenv(PROFILER_INTERVAL); - const char* entries = getenv(PROFILER_ENTRIES); - - if (getenv(PROFILER_HELP)) { - // Enable verbose output - profiler_set_verbosity(Verbosity::VERBOSE); - profiler_usage(); - // Now force the next enquiry of profiler_verbose to re-query - // env var MOZ_PROFILER_VERBOSE. - profiler_set_verbosity(Verbosity::UNCHECKED); + if (help) { + profiler_usage(0); // terminates execution } - if (!set_profiler_interval(interval) || - !set_profiler_entries(entries)) { - profiler_usage(); - } else { - LOG( "Profiler:"); - LOGF("Profiler: Sampling interval = %d ms (zero means \"platform default\")", - (int)gUnwindInterval); - LOGF("Profiler: Entry store size = %d (zero means \"platform default\")", - (int)gProfileEntries); - LOG( "Profiler:"); + if (!set_profiler_entries(entries) || + !set_profiler_interval(interval)) { + profiler_usage(1); // terminates execution } + + LOG (""); + LOGF("entries = %d (zero means \"platform default\")", + gEnvVarEntries); + LOGF("interval = %d ms (zero means \"platform default\")", + gEnvVarInterval); + LOG (""); } static bool @@ -1600,7 +1569,7 @@ profiler_init(void* stackTop) RegisterCurrentThread(gGeckoThreadName, stack, isMainThread, stackTop); // Read settings from environment variables. - read_profiler_env_vars(); + ReadProfilerEnvVars(); // Platform-specific initialization. PlatformInit(); @@ -1632,7 +1601,7 @@ profiler_init(void* stackTop) const char* threadFilters[] = { "GeckoMain", "Compositor" }; - profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL, + profiler_start(PROFILE_DEFAULT_ENTRIES, PROFILE_DEFAULT_INTERVAL, features, MOZ_ARRAY_LENGTH(features), threadFilters, MOZ_ARRAY_LENGTH(threadFilters)); LOG("END profiler_init"); @@ -1752,19 +1721,18 @@ profiler_save_profile_to_file_async(double aSinceTime, const char* aFileName) } void -profiler_get_start_params(int* aEntrySize, - double* aInterval, +profiler_get_start_params(int* aEntries, double* aInterval, mozilla::Vector* aFilters, mozilla::Vector* aFeatures) { MOZ_RELEASE_ASSERT(NS_IsMainThread()); - if (NS_WARN_IF(!aEntrySize) || NS_WARN_IF(!aInterval) || + if (NS_WARN_IF(!aEntries) || NS_WARN_IF(!aInterval) || NS_WARN_IF(!aFilters) || NS_WARN_IF(!aFeatures)) { return; } - *aEntrySize = gEntrySize; + *aEntries = gEntries; *aInterval = gInterval; { @@ -1886,9 +1854,9 @@ profiler_get_features() } void -profiler_get_buffer_info_helper(uint32_t *aCurrentPosition, - uint32_t *aTotalSize, - uint32_t *aGeneration) +profiler_get_buffer_info_helper(uint32_t* aCurrentPosition, + uint32_t* aEntries, + uint32_t* aGeneration) { // This function is called by profiler_get_buffer_info(), which has already // zeroed the outparams. @@ -1903,7 +1871,7 @@ profiler_get_buffer_info_helper(uint32_t *aCurrentPosition, } *aCurrentPosition = gBuffer->mWritePos; - *aTotalSize = gEntrySize; + *aEntries = gEntries; *aGeneration = gBuffer->mGeneration; } @@ -1923,7 +1891,7 @@ class Sampler {}; // Values are only honored on the first start void -profiler_start(int aProfileEntries, double aInterval, +profiler_start(int aEntries, double aInterval, const char** aFeatures, uint32_t aFeatureCount, const char** aThreadNameFilters, uint32_t aFilterCount) @@ -1937,12 +1905,12 @@ profiler_start(int aProfileEntries, double aInterval, /* If the sampling interval was set using env vars, use that in preference to anything else. */ - if (gUnwindInterval > 0) - aInterval = gUnwindInterval; + if (gEnvVarInterval > 0) + aInterval = gEnvVarInterval; /* If the entry count was set using env vars, use that, too: */ - if (gProfileEntries > 0) - aProfileEntries = gProfileEntries; + if (gEnvVarEntries > 0) + aEntries = gEnvVarEntries; // Reset the current state if the profiler is running profiler_stop(); @@ -1987,9 +1955,9 @@ profiler_start(int aProfileEntries, double aInterval, aFilterCount > 0; gUseStackWalk = hasFeature(aFeatures, aFeatureCount, "stackwalk"); - gEntrySize = aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY; + gEntries = aEntries ? aEntries : PROFILE_DEFAULT_ENTRIES; gInterval = aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL; - gBuffer = new ProfileBuffer(gEntrySize); + gBuffer = new ProfileBuffer(gEntries); gSampler = new Sampler(); bool ignore; @@ -2073,7 +2041,7 @@ profiler_start(int aProfileEntries, double aInterval, } nsCOMPtr params = - new nsProfilerStartParams(aProfileEntries, aInterval, featuresArray, + new nsProfilerStartParams(aEntries, aInterval, featuresArray, threadNameFiltersArray); os->NotifyObservers(params, "profiler-started", nullptr); @@ -2150,7 +2118,7 @@ profiler_stop() delete gSampler; gSampler = nullptr; gBuffer = nullptr; - gEntrySize = 0; + gEntries = 0; gInterval = 0; // Cancel any in-flight async profile gatherering requests. diff --git a/tools/profiler/gecko/nsProfiler.cpp b/tools/profiler/gecko/nsProfiler.cpp index 582a26e12aa7..fb6c0d306fb9 100644 --- a/tools/profiler/gecko/nsProfiler.cpp +++ b/tools/profiler/gecko/nsProfiler.cpp @@ -280,7 +280,8 @@ nsProfiler::GetStartParams(nsIProfilerStartParams** aRetVal) } NS_IMETHODIMP -nsProfiler::GetBufferInfo(uint32_t *aCurrentPosition, uint32_t *aTotalSize, uint32_t *aGeneration) +nsProfiler::GetBufferInfo(uint32_t* aCurrentPosition, uint32_t* aTotalSize, + uint32_t* aGeneration) { MOZ_ASSERT(aCurrentPosition); MOZ_ASSERT(aTotalSize); diff --git a/tools/profiler/public/GeckoProfiler.h b/tools/profiler/public/GeckoProfiler.h index 49effd3fe5fc..14c3247d7bd3 100644 --- a/tools/profiler/public/GeckoProfiler.h +++ b/tools/profiler/public/GeckoProfiler.h @@ -161,15 +161,17 @@ PROFILER_FUNC_VOID(profiler_shutdown()) // Start the profiler with the selected options. The samples will be // recorded in a circular buffer. -// "aProfileEntries" is an abstract size indication of how big +// "aEntries" is an abstract size indication of how big // the profile's circular buffer should be. Multiply by 4 // words to get the cost. // "aInterval" the sampling interval. The profiler will do its // best to sample at this interval. The profiler visualization // should represent the actual sampling accuracy. -PROFILER_FUNC_VOID(profiler_start(int aProfileEntries, double aInterval, - const char** aFeatures, uint32_t aFeatureCount, - const char** aThreadNameFilters, uint32_t aFilterCount)) +PROFILER_FUNC_VOID(profiler_start(int aEntries, double aInterval, + const char** aFeatures, + uint32_t aFeatureCount, + const char** aThreadNameFilters, + uint32_t aFilterCount)) // Stop the profiler and discard the profile. Call 'profiler_save' before this // to retrieve the profile. @@ -234,7 +236,7 @@ PROFILER_FUNC_VOID(profiler_save_profile_to_file(const char* aFilename)) PROFILER_FUNC(const char** profiler_get_features(), nullptr) PROFILER_FUNC_VOID(profiler_get_buffer_info_helper(uint32_t* aCurrentPosition, - uint32_t* aTotalSize, + uint32_t* aEntries, uint32_t* aGeneration)) // Get information about the current buffer status. @@ -245,14 +247,14 @@ PROFILER_FUNC_VOID(profiler_get_buffer_info_helper(uint32_t* aCurrentPosition, // for how fast the buffer is being written to, and how much // data is visible. static inline void profiler_get_buffer_info(uint32_t* aCurrentPosition, - uint32_t* aTotalSize, + uint32_t* aEntries, uint32_t* aGeneration) { *aCurrentPosition = 0; - *aTotalSize = 0; + *aEntries = 0; *aGeneration = 0; - profiler_get_buffer_info_helper(aCurrentPosition, aTotalSize, aGeneration); + profiler_get_buffer_info_helper(aCurrentPosition, aEntries, aGeneration); } // Lock the profiler. When locked the profiler is (1) stopped, @@ -433,14 +435,14 @@ void profiler_OOP_exit_profile(const nsCString& aProfile); #endif #if !defined(PLATFORM_LIKELY_MEMORY_CONSTRAINED) && !defined(ARCH_ARMV6) -# define PROFILE_DEFAULT_ENTRY 1000000 +# define PROFILE_DEFAULT_ENTRIES 1000000 #else -# define PROFILE_DEFAULT_ENTRY 100000 +# define PROFILE_DEFAULT_ENTRIES 100000 #endif // In the case of profiler_get_backtrace we know that we only need enough space // for a single backtrace. -#define GET_BACKTRACE_DEFAULT_ENTRY 1000 +#define GET_BACKTRACE_DEFAULT_ENTRIES 1000 #if defined(PLATFORM_LIKELY_MEMORY_CONSTRAINED) /* A 1ms sampling interval has been shown to be a large perf hit diff --git a/widget/android/ANRReporter.cpp b/widget/android/ANRReporter.cpp index 30d9b3d7624d..052299c41366 100644 --- a/widget/android/ANRReporter.cpp +++ b/widget/android/ANRReporter.cpp @@ -38,8 +38,10 @@ ANRReporter::RequestNativeStack(bool aUnwind) const char *NATIVE_STACK_THREADS[] = {"GeckoMain", "Compositor"}; // Buffer one sample and let the profiler wait a long time - profiler_start(100, 10000, features, features_size / sizeof(char*), - NATIVE_STACK_THREADS, sizeof(NATIVE_STACK_THREADS) / sizeof(char*)); + profiler_start(/* entries */ 100, /* interval */ 10000, + features, features_size / sizeof(char*), + NATIVE_STACK_THREADS, + sizeof(NATIVE_STACK_THREADS) / sizeof(char*)); return true; } From 08151dafcbefda93995881a99e77ce04b08a7372 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:12:28 -0500 Subject: [PATCH 090/102] Backed out 9 changesets (bug 1336198). r=backout Backed out changeset fd85a5aafa9f (bug 1336198) Backed out changeset e1624f6a8087 (bug 1336198) Backed out changeset a174ae51463a (bug 1336198) Backed out changeset a7e1c96ccf87 (bug 1336198) Backed out changeset c0df0213c72b (bug 1336198) Backed out changeset e7d3c4bfc729 (bug 1336198) Backed out changeset 3c88ae1e9508 (bug 1336198) Backed out changeset 0461bc95ee7f (bug 1336198) Backed out changeset f6710bb42058 (bug 1336198) --- .../inspector/boxmodel/actions/index.js | 14 - .../inspector/boxmodel/actions/moz.build | 10 - .../client/inspector/boxmodel/box-model.js | 301 ------ .../boxmodel/components/BoxModelApp.js | 51 - .../inspector/boxmodel/components/moz.build | 15 - devtools/client/inspector/boxmodel/moz.build | 19 - .../inspector/boxmodel/reducers/moz.build | 9 - ...browser_boxmodel_rotate-labels-on-sides.js | 49 - devtools/client/inspector/boxmodel/types.js | 17 - .../client/inspector/boxmodel/utils/moz.build | 9 - .../components/deprecated-box-model.js | 912 ++++++++++++++++++ .../client/inspector/components/moz.build | 3 + .../test/.eslintrc.js | 0 .../{boxmodel => components}/test/browser.ini | 2 - .../test/browser_boxmodel.js | 60 +- .../test/browser_boxmodel_editablemodel.js | 58 +- ...er_boxmodel_editablemodel_allproperties.js | 40 +- ...wser_boxmodel_editablemodel_bluronclick.js | 24 +- .../browser_boxmodel_editablemodel_border.js | 10 +- ...owser_boxmodel_editablemodel_stylerules.js | 32 +- .../test/browser_boxmodel_guides.js | 8 +- .../test/browser_boxmodel_navigation.js | 26 +- ...browser_boxmodel_rotate-labels-on-sides.js | 49 + .../test/browser_boxmodel_sync.js | 10 +- .../test/browser_boxmodel_tooltips.js | 18 +- ...rowser_boxmodel_update-after-navigation.js | 19 +- .../browser_boxmodel_update-after-reload.js | 8 +- .../browser_boxmodel_update-in-iframes.js | 7 +- .../test/doc_boxmodel_iframe1.html | 0 .../test/doc_boxmodel_iframe2.html | 0 .../{boxmodel => components}/test/head.js | 47 +- .../client/inspector/computed/computed.js | 44 +- .../test/browser_computed_search-filter.js | 2 +- .../browser_computed_search-filter_clear.js | 2 +- devtools/client/inspector/inspector.js | 7 +- devtools/client/inspector/inspector.xhtml | 56 +- .../{boxmodel => layout}/actions/box-model.js | 0 .../client/inspector/layout/actions/index.js | 3 + .../client/inspector/layout/actions/moz.build | 1 + .../client/inspector/layout/components/App.js | 3 +- .../components/BoxModel.js | 0 .../components/BoxModelEditable.js | 0 .../components/BoxModelInfo.js | 0 .../components/BoxModelMain.js | 24 +- .../components/BoxModelProperties.js | 0 .../components/ComputedProperty.js | 0 .../inspector/layout/components/moz.build | 6 + devtools/client/inspector/layout/layout.js | 213 +++- .../reducers/box-model.js | 0 .../inspector/layout/reducers/moz.build | 1 + devtools/client/inspector/layout/types.js | 10 + .../utils/editing-session.js | 0 .../client/inspector/layout/utils/moz.build | 1 + devtools/client/inspector/moz.build | 1 - devtools/client/inspector/reducers.js | 2 +- .../test/browser_inspector_textbox-menu.js | 2 +- devtools/client/inspector/test/shared-head.js | 10 +- devtools/client/jar.mn | 1 + devtools/client/shared/browser-loader.js | 2 - .../client/themes/deprecated-boxmodel.css | 259 +++++ 60 files changed, 1688 insertions(+), 789 deletions(-) delete mode 100644 devtools/client/inspector/boxmodel/actions/index.js delete mode 100644 devtools/client/inspector/boxmodel/actions/moz.build delete mode 100644 devtools/client/inspector/boxmodel/box-model.js delete mode 100644 devtools/client/inspector/boxmodel/components/BoxModelApp.js delete mode 100644 devtools/client/inspector/boxmodel/components/moz.build delete mode 100644 devtools/client/inspector/boxmodel/moz.build delete mode 100644 devtools/client/inspector/boxmodel/reducers/moz.build delete mode 100644 devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js delete mode 100644 devtools/client/inspector/boxmodel/types.js delete mode 100644 devtools/client/inspector/boxmodel/utils/moz.build create mode 100644 devtools/client/inspector/components/deprecated-box-model.js rename devtools/client/inspector/{boxmodel => components}/test/.eslintrc.js (100%) rename devtools/client/inspector/{boxmodel => components}/test/browser.ini (94%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel.js (58%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_editablemodel.js (74%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_editablemodel_allproperties.js (74%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_editablemodel_bluronclick.js (69%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_editablemodel_border.js (82%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_editablemodel_stylerules.js (74%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_guides.js (89%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_navigation.js (75%) create mode 100644 devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_sync.js (77%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_tooltips.js (83%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_update-after-navigation.js (86%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_update-after-reload.js (87%) rename devtools/client/inspector/{boxmodel => components}/test/browser_boxmodel_update-in-iframes.js (93%) rename devtools/client/inspector/{boxmodel => components}/test/doc_boxmodel_iframe1.html (100%) rename devtools/client/inspector/{boxmodel => components}/test/doc_boxmodel_iframe2.html (100%) rename devtools/client/inspector/{boxmodel => components}/test/head.js (65%) rename devtools/client/inspector/{boxmodel => layout}/actions/box-model.js (100%) rename devtools/client/inspector/{boxmodel => layout}/components/BoxModel.js (100%) rename devtools/client/inspector/{boxmodel => layout}/components/BoxModelEditable.js (100%) rename devtools/client/inspector/{boxmodel => layout}/components/BoxModelInfo.js (100%) rename devtools/client/inspector/{boxmodel => layout}/components/BoxModelMain.js (92%) rename devtools/client/inspector/{boxmodel => layout}/components/BoxModelProperties.js (100%) rename devtools/client/inspector/{boxmodel => layout}/components/ComputedProperty.js (100%) rename devtools/client/inspector/{boxmodel => layout}/reducers/box-model.js (100%) rename devtools/client/inspector/{boxmodel => layout}/utils/editing-session.js (100%) create mode 100644 devtools/client/themes/deprecated-boxmodel.css diff --git a/devtools/client/inspector/boxmodel/actions/index.js b/devtools/client/inspector/boxmodel/actions/index.js deleted file mode 100644 index 45758428e733..000000000000 --- a/devtools/client/inspector/boxmodel/actions/index.js +++ /dev/null @@ -1,14 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -const { createEnum } = require("devtools/client/shared/enum"); - -createEnum([ - - // Update the layout state with the latest layout properties. - "UPDATE_LAYOUT", - -], module.exports); diff --git a/devtools/client/inspector/boxmodel/actions/moz.build b/devtools/client/inspector/boxmodel/actions/moz.build deleted file mode 100644 index 2f98f6793d0c..000000000000 --- a/devtools/client/inspector/boxmodel/actions/moz.build +++ /dev/null @@ -1,10 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -DevToolsModules( - 'box-model.js', - 'index.js', -) diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js deleted file mode 100644 index 0290d69af88a..000000000000 --- a/devtools/client/inspector/boxmodel/box-model.js +++ /dev/null @@ -1,301 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -const { Task } = require("devtools/shared/task"); -const { getCssProperties } = require("devtools/shared/fronts/css-properties"); -const { ReflowFront } = require("devtools/shared/fronts/reflow"); - -const { InplaceEditor } = require("devtools/client/shared/inplace-editor"); - -const { updateLayout } = require("./actions/box-model"); - -const EditingSession = require("./utils/editing-session"); - -const NUMERIC = /^-?[\d\.]+$/; - -/** - * A singleton instance of the box model controllers. - * - * @param {Inspector} inspector - * An instance of the Inspector currently loaded in the toolbox. - * @param {Window} window - * The document window of the toolbox. - */ -function BoxModel(inspector, window) { - this.document = window.document; - this.inspector = inspector; - this.store = inspector.store; - - this.updateBoxModel = this.updateBoxModel.bind(this); - - this.onHideBoxModelHighlighter = this.onHideBoxModelHighlighter.bind(this); - this.onNewSelection = this.onNewSelection.bind(this); - this.onShowBoxModelEditor = this.onShowBoxModelEditor.bind(this); - this.onShowBoxModelHighlighter = this.onShowBoxModelHighlighter.bind(this); - this.onSidebarSelect = this.onSidebarSelect.bind(this); - - this.inspector.selection.on("new-node-front", this.onNewSelection); - this.inspector.sidebar.on("select", this.onSidebarSelect); -} - -BoxModel.prototype = { - - /** - * Destruction function called when the inspector is destroyed. Removes event listeners - * and cleans up references. - */ - destroy() { - this.inspector.selection.off("new-node-front", this.onNewSelection); - this.inspector.sidebar.off("select", this.onSidebarSelect); - - if (this.reflowFront) { - this.untrackReflows(); - this.reflowFront.destroy(); - this.reflowFront = null; - } - - this.document = null; - this.inspector = null; - this.walker = null; - }, - - /** - * Returns an object containing the box model's handler functions used in the box - * model's React component props. - */ - getComponentProps() { - return { - onHideBoxModelHighlighter: this.onHideBoxModelHighlighter, - onShowBoxModelEditor: this.onShowBoxModelEditor, - onShowBoxModelHighlighter: this.onShowBoxModelHighlighter, - }; - }, - - /** - * Returns true if the computed or layout panel is visible, and false otherwise. - */ - isPanelVisible() { - return this.inspector.toolbox.currentToolId === "inspector" && - this.inspector.sidebar && - (this.inspector.sidebar.getCurrentTabID() === "layoutview" || - this.inspector.sidebar.getCurrentTabID() === "computedview"); - }, - - /** - * Returns true if the layout panel is visible and the current node is valid to - * be displayed in the view. - */ - isPanelVisibleAndNodeValid() { - return this.isPanelVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode(); - }, - - /** - * Starts listening to reflows in the current tab. - */ - trackReflows() { - if (!this.reflowFront) { - let { target } = this.inspector; - if (target.form.reflowActor) { - this.reflowFront = ReflowFront(target.client, - target.form); - } else { - return; - } - } - - this.reflowFront.on("reflows", this.updateBoxModel); - this.reflowFront.start(); - }, - - /** - * Stops listening to reflows in the current tab. - */ - untrackReflows() { - if (!this.reflowFront) { - return; - } - - this.reflowFront.off("reflows", this.updateBoxModel); - this.reflowFront.stop(); - }, - - /** - * Updates the box model panel by dispatching the new layout data. - * - * @param {String} reason - * Optional string describing the reason why the boxmodel is updated. - */ - updateBoxModel(reason) { - this._updateReasons = this._updateReasons || []; - if (reason) { - this._updateReasons.push(reason); - } - - let lastRequest = Task.spawn((function* () { - if (!(this.isPanelVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode())) { - return null; - } - - let node = this.inspector.selection.nodeFront; - let layout = yield this.inspector.pageStyle.getLayout(node, { - autoMargins: true, - }); - let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); - this.elementRules = styleEntries.map(e => e.rule); - - // Update the redux store with the latest layout properties and update the box - // model view. - this.store.dispatch(updateLayout(layout)); - - // If a subsequent request has been made, wait for that one instead. - if (this._lastRequest != lastRequest) { - return this._lastRequest; - } - - this.inspector.emit("boxmodel-view-updated", this._updateReasons); - - this._lastRequest = null; - this._updateReasons = []; - - return null; - }).bind(this)).catch(console.error); - - this._lastRequest = lastRequest; - }, - - /** - * Selection 'new-node-front' event handler. - */ - onNewSelection: function () { - if (!this.isPanelVisibleAndNodeValid()) { - return; - } - - if (this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode()) { - this.trackReflows(); - } - - this.updateBoxModel("new-selection"); - }, - - /** - * Hides the box-model highlighter on the currently selected element. - */ - onHideBoxModelHighlighter() { - let toolbox = this.inspector.toolbox; - toolbox.highlighterUtils.unhighlight(); - }, - - /** - * Shows the inplace editor when a box model editable value is clicked on the - * box model panel. - * - * @param {DOMNode} element - * The element that was clicked. - * @param {Event} event - * The event object. - * @param {String} property - * The name of the property. - */ - onShowBoxModelEditor(element, event, property) { - let session = new EditingSession({ - inspector: this.inspector, - doc: this.document, - elementRules: this.elementRules, - }); - let initialValue = session.getProperty(property); - - let editor = new InplaceEditor({ - element: element, - initial: initialValue, - contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, - property: { - name: property - }, - start: self => { - self.elt.parentNode.classList.add("boxmodel-editing"); - }, - change: value => { - if (NUMERIC.test(value)) { - value += "px"; - } - - let properties = [ - { name: property, value: value } - ]; - - if (property.substring(0, 7) == "border-") { - let bprop = property.substring(0, property.length - 5) + "style"; - let style = session.getProperty(bprop); - if (!style || style == "none" || style == "hidden") { - properties.push({ name: bprop, value: "solid" }); - } - } - - session.setProperties(properties).catch(e => console.error(e)); - }, - done: (value, commit) => { - editor.elt.parentNode.classList.remove("boxmodel-editing"); - if (!commit) { - session.revert().then(() => { - session.destroy(); - }, e => console.error(e)); - return; - } - - let node = this.inspector.selection.nodeFront; - this.inspector.pageStyle.getLayout(node, { - autoMargins: true, - }).then(layout => { - this.store.dispatch(updateLayout(layout)); - }, e => console.error(e)); - }, - contextMenu: this.inspector.onTextBoxContextMenu, - cssProperties: getCssProperties(this.inspector.toolbox) - }, event); - }, - - /** - * Shows the box-model highlighter on the currently selected element. - * - * @param {Object} options - * Options passed to the highlighter actor. - */ - onShowBoxModelHighlighter(options = {}) { - let toolbox = this.inspector.toolbox; - let nodeFront = this.inspector.selection.nodeFront; - - toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); - }, - - /** - * Handler for the inspector sidebar select event. Starts listening for - * "grid-layout-changed" if the layout panel is visible. Otherwise, stop - * listening for grid layout changes. Finally, refresh the layout view if - * it is visible. - */ - onSidebarSelect() { - if (!this.isPanelVisible()) { - this.untrackReflows(); - return; - } - - if (this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode()) { - this.trackReflows(); - } - - this.updateBoxModel(); - }, - -}; - -module.exports = BoxModel; diff --git a/devtools/client/inspector/boxmodel/components/BoxModelApp.js b/devtools/client/inspector/boxmodel/components/BoxModelApp.js deleted file mode 100644 index 2af27ac77c2f..000000000000 --- a/devtools/client/inspector/boxmodel/components/BoxModelApp.js +++ /dev/null @@ -1,51 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -const { addons, createClass, createFactory, PropTypes } = - require("devtools/client/shared/vendor/react"); -const { connect } = require("devtools/client/shared/vendor/react-redux"); - -const { LocalizationHelper } = require("devtools/shared/l10n"); - -const Accordion = - createFactory(require("devtools/client/inspector/layout/components/Accordion")); -const BoxModel = createFactory(require("./BoxModel")); - -const Types = require("../types"); - -const BOXMODEL_STRINGS_URI = "devtools/client/locales/boxmodel.properties"; -const BOXMODEL_L10N = new LocalizationHelper(BOXMODEL_STRINGS_URI); - -const BoxModelApp = createClass({ - - displayName: "BoxModelApp", - - propTypes: { - boxModel: PropTypes.shape(Types.boxModel).isRequired, - showBoxModelProperties: PropTypes.bool.isRequired, - onHideBoxModelHighlighter: PropTypes.func.isRequired, - onShowBoxModelEditor: PropTypes.func.isRequired, - onShowBoxModelHighlighter: PropTypes.func.isRequired, - }, - - mixins: [ addons.PureRenderMixin ], - - render() { - return Accordion({ - items: [ - { - header: BOXMODEL_L10N.getStr("boxmodel.title"), - component: BoxModel, - componentProps: this.props, - opened: true, - } - ] - }); - }, - -}); - -module.exports = connect(state => state)(BoxModelApp); diff --git a/devtools/client/inspector/boxmodel/components/moz.build b/devtools/client/inspector/boxmodel/components/moz.build deleted file mode 100644 index 02638ae7b291..000000000000 --- a/devtools/client/inspector/boxmodel/components/moz.build +++ /dev/null @@ -1,15 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -DevToolsModules( - 'BoxModel.js', - 'BoxModelApp.js', - 'BoxModelEditable.js', - 'BoxModelInfo.js', - 'BoxModelMain.js', - 'BoxModelProperties.js', - 'ComputedProperty.js', -) diff --git a/devtools/client/inspector/boxmodel/moz.build b/devtools/client/inspector/boxmodel/moz.build deleted file mode 100644 index 6ef44c80c361..000000000000 --- a/devtools/client/inspector/boxmodel/moz.build +++ /dev/null @@ -1,19 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -DIRS += [ - 'actions', - 'components', - 'reducers', - 'utils', -] - -DevToolsModules( - 'box-model.js', - 'types.js', -) - -BROWSER_CHROME_MANIFESTS += ['test/browser.ini'] diff --git a/devtools/client/inspector/boxmodel/reducers/moz.build b/devtools/client/inspector/boxmodel/reducers/moz.build deleted file mode 100644 index e2402990ad80..000000000000 --- a/devtools/client/inspector/boxmodel/reducers/moz.build +++ /dev/null @@ -1,9 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -DevToolsModules( - 'box-model.js', -) diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js deleted file mode 100644 index e931830b534f..000000000000 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js +++ /dev/null @@ -1,49 +0,0 @@ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -// Test that longer values are rotated on the side - -const res1 = [ - {selector: ".boxmodel-margin.boxmodel-top > span", value: 30}, - {selector: ".boxmodel-margin.boxmodel-left > span", value: "auto"}, - {selector: ".boxmodel-margin.boxmodel-bottom > span", value: 30}, - {selector: ".boxmodel-margin.boxmodel-right > span", value: "auto"}, - {selector: ".boxmodel-padding.boxmodel-top > span", value: 20}, - {selector: ".boxmodel-padding.boxmodel-left > span", value: 2000000}, - {selector: ".boxmodel-padding.boxmodel-bottom > span", value: 20}, - {selector: ".boxmodel-padding.boxmodel-right > span", value: 20}, - {selector: ".boxmodel-border.boxmodel-top > span", value: 10}, - {selector: ".boxmodel-border.boxmodel-left > span", value: 10}, - {selector: ".boxmodel-border.boxmodel-bottom > span", value: 10}, - {selector: ".boxmodel-border.boxmodel-right > span", value: 10}, -]; - -const TEST_URI = encodeURIComponent([ - "", - "
" -].join("")); -const LONG_TEXT_ROTATE_LIMIT = 3; - -add_task(function* () { - yield addTab("data:text/html," + TEST_URI); - let {inspector, view} = yield openBoxModelView(); - yield selectNode("div", inspector); - - for (let i = 0; i < res1.length; i++) { - let elt = view.document.querySelector(res1[i].selector); - let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT; - let classList = elt.parentNode.classList; - let canBeRotated = classList.contains("boxmodel-left") || - classList.contains("boxmodel-right"); - let isRotated = classList.contains("boxmodel-rotate"); - - is(canBeRotated && isLong, - isRotated, res1[i].selector + " correctly rotated."); - } -}); diff --git a/devtools/client/inspector/boxmodel/types.js b/devtools/client/inspector/boxmodel/types.js deleted file mode 100644 index aba8f7893d7e..000000000000 --- a/devtools/client/inspector/boxmodel/types.js +++ /dev/null @@ -1,17 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -const { PropTypes } = require("devtools/client/shared/vendor/react"); - -/** - * The box model data for the current selected node. - */ -exports.boxModel = { - - // The layout information of the current selected node - layout: PropTypes.object, - -}; diff --git a/devtools/client/inspector/boxmodel/utils/moz.build b/devtools/client/inspector/boxmodel/utils/moz.build deleted file mode 100644 index 4ad6c32d9ef5..000000000000 --- a/devtools/client/inspector/boxmodel/utils/moz.build +++ /dev/null @@ -1,9 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -DevToolsModules( - 'editing-session.js', -) diff --git a/devtools/client/inspector/components/deprecated-box-model.js b/devtools/client/inspector/components/deprecated-box-model.js new file mode 100644 index 000000000000..874a79939c97 --- /dev/null +++ b/devtools/client/inspector/components/deprecated-box-model.js @@ -0,0 +1,912 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* 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 MODULE IS DEPRECATED. + * + * To continue any work related to the box model view, see the new react/redux + * implementation in devtools/client/inspector/layout/. + */ + +"use strict"; + +const {Task} = require("devtools/shared/task"); +const {InplaceEditor, editableItem} = + require("devtools/client/shared/inplace-editor"); +const {ReflowFront} = require("devtools/shared/fronts/reflow"); +const {LocalizationHelper} = require("devtools/shared/l10n"); +const {getCssProperties} = require("devtools/shared/fronts/css-properties"); +const {KeyCodes} = require("devtools/client/shared/keycodes"); +const EditingSession = require("devtools/client/inspector/layout/utils/editing-session"); + +const STRINGS_URI = "devtools/client/locales/shared.properties"; +const STRINGS_INSPECTOR = "devtools/shared/locales/styleinspector.properties"; +const SHARED_L10N = new LocalizationHelper(STRINGS_URI); +const INSPECTOR_L10N = new LocalizationHelper(STRINGS_INSPECTOR); +const NUMERIC = /^-?[\d\.]+$/; +const LONG_TEXT_ROTATE_LIMIT = 3; + +/** + * The box model view + * @param {InspectorPanel} inspector + * An instance of the inspector-panel currently loaded in the toolbox + * @param {Document} document + * The document that will contain the box model view. + */ +function BoxModelView(inspector, document) { + this.inspector = inspector; + this.doc = document; + this.wrapper = this.doc.getElementById("old-boxmodel-wrapper"); + this.container = this.doc.getElementById("old-boxmodel-container"); + this.expander = this.doc.getElementById("old-boxmodel-expander"); + this.sizeLabel = this.doc.querySelector(".old-boxmodel-size > span"); + this.sizeHeadingLabel = this.doc.getElementById("old-boxmodel-element-size"); + this._geometryEditorHighlighter = null; + this._cssProperties = getCssProperties(inspector.toolbox); + + this.init(); +} + +BoxModelView.prototype = { + init: function () { + this.update = this.update.bind(this); + + this.onNewSelection = this.onNewSelection.bind(this); + this.inspector.selection.on("new-node-front", this.onNewSelection); + + this.onNewNode = this.onNewNode.bind(this); + this.inspector.sidebar.on("computedview-selected", this.onNewNode); + + this.onSidebarSelect = this.onSidebarSelect.bind(this); + this.inspector.sidebar.on("select", this.onSidebarSelect); + + this.onToggleExpander = this.onToggleExpander.bind(this); + this.expander.addEventListener("click", this.onToggleExpander); + let header = this.doc.getElementById("old-boxmodel-header"); + header.addEventListener("dblclick", this.onToggleExpander); + + this.onFilterComputedView = this.onFilterComputedView.bind(this); + this.inspector.on("computed-view-filtered", + this.onFilterComputedView); + + this.onPickerStarted = this.onPickerStarted.bind(this); + this.onMarkupViewLeave = this.onMarkupViewLeave.bind(this); + this.onMarkupViewNodeHover = this.onMarkupViewNodeHover.bind(this); + this.onWillNavigate = this.onWillNavigate.bind(this); + this.onKeyDown = this.onKeyDown.bind(this); + this.onLevelClick = this.onLevelClick.bind(this); + this.setAriaActive = this.setAriaActive.bind(this); + this.getEditBoxes = this.getEditBoxes.bind(this); + this.makeFocusable = this.makeFocusable.bind(this); + this.makeUnfocasable = this.makeUnfocasable.bind(this); + this.moveFocus = this.moveFocus.bind(this); + this.onFocus = this.onFocus.bind(this); + + this.borderLayout = this.doc.getElementById("old-boxmodel-borders"); + this.boxModel = this.doc.getElementById("old-boxmodel-wrapper"); + this.marginLayout = this.doc.getElementById("old-boxmodel-margins"); + this.paddingLayout = this.doc.getElementById("old-boxmodel-padding"); + + this.layouts = { + "margin": new Map([ + [KeyCodes.DOM_VK_ESCAPE, this.marginLayout], + [KeyCodes.DOM_VK_DOWN, this.borderLayout], + [KeyCodes.DOM_VK_UP, null], + ["click", this.marginLayout] + ]), + "border": new Map([ + [KeyCodes.DOM_VK_ESCAPE, this.borderLayout], + [KeyCodes.DOM_VK_DOWN, this.paddingLayout], + [KeyCodes.DOM_VK_UP, this.marginLayout], + ["click", this.borderLayout] + ]), + "padding": new Map([ + [KeyCodes.DOM_VK_ESCAPE, this.paddingLayout], + [KeyCodes.DOM_VK_DOWN, null], + [KeyCodes.DOM_VK_UP, this.borderLayout], + ["click", this.paddingLayout] + ]) + }; + + this.boxModel.addEventListener("click", this.onLevelClick, true); + this.boxModel.addEventListener("focus", this.onFocus, true); + this.boxModel.addEventListener("keydown", this.onKeyDown, true); + + this.initBoxModelHighlighter(); + + // Store for the different dimensions of the node. + // 'selector' refers to the element that holds the value; + // 'property' is what we are measuring; + // 'value' is the computed dimension, computed in update(). + this.map = { + position: { + selector: "#old-boxmodel-element-position", + property: "position", + value: undefined + }, + marginTop: { + selector: ".old-boxmodel-margin.old-boxmodel-top > span", + property: "margin-top", + value: undefined + }, + marginBottom: { + selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", + property: "margin-bottom", + value: undefined + }, + marginLeft: { + selector: ".old-boxmodel-margin.old-boxmodel-left > span", + property: "margin-left", + value: undefined + }, + marginRight: { + selector: ".old-boxmodel-margin.old-boxmodel-right > span", + property: "margin-right", + value: undefined + }, + paddingTop: { + selector: ".old-boxmodel-padding.old-boxmodel-top > span", + property: "padding-top", + value: undefined + }, + paddingBottom: { + selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", + property: "padding-bottom", + value: undefined + }, + paddingLeft: { + selector: ".old-boxmodel-padding.old-boxmodel-left > span", + property: "padding-left", + value: undefined + }, + paddingRight: { + selector: ".old-boxmodel-padding.old-boxmodel-right > span", + property: "padding-right", + value: undefined + }, + borderTop: { + selector: ".old-boxmodel-border.old-boxmodel-top > span", + property: "border-top-width", + value: undefined + }, + borderBottom: { + selector: ".old-boxmodel-border.old-boxmodel-bottom > span", + property: "border-bottom-width", + value: undefined + }, + borderLeft: { + selector: ".old-boxmodel-border.old-boxmodel-left > span", + property: "border-left-width", + value: undefined + }, + borderRight: { + selector: ".old-boxmodel-border.old-boxmodel-right > span", + property: "border-right-width", + value: undefined + } + }; + + // Make each element the dimensions editable + for (let i in this.map) { + if (i == "position") { + continue; + } + + let dimension = this.map[i]; + editableItem({ + element: this.doc.querySelector(dimension.selector) + }, (element, event) => { + this.initEditor(element, event, dimension); + }); + } + + this.onNewNode(); + + let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); + this.onGeometryButtonClick = this.onGeometryButtonClick.bind(this); + nodeGeometry.addEventListener("click", this.onGeometryButtonClick); + }, + + initBoxModelHighlighter: function () { + let highlightElts = this.doc.querySelectorAll("#old-boxmodel-container *[title]"); + this.onHighlightMouseOver = this.onHighlightMouseOver.bind(this); + this.onHighlightMouseOut = this.onHighlightMouseOut.bind(this); + + for (let element of highlightElts) { + element.addEventListener("mouseover", this.onHighlightMouseOver, true); + element.addEventListener("mouseout", this.onHighlightMouseOut, true); + } + }, + + /** + * Start listening to reflows in the current tab. + */ + trackReflows: function () { + if (!this.reflowFront) { + let { target } = this.inspector; + if (target.form.reflowActor) { + this.reflowFront = ReflowFront(target.client, + target.form); + } else { + return; + } + } + + this.reflowFront.on("reflows", this.update); + this.reflowFront.start(); + }, + + /** + * Stop listening to reflows in the current tab. + */ + untrackReflows: function () { + if (!this.reflowFront) { + return; + } + + this.reflowFront.off("reflows", this.update); + this.reflowFront.stop(); + }, + + /** + * Called when the user clicks on one of the editable values in the box model view + */ + initEditor: function (element, event, dimension) { + let { property } = dimension; + let session = new EditingSession(this); + let initialValue = session.getProperty(property); + + let editor = new InplaceEditor({ + element: element, + initial: initialValue, + contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, + property: { + name: dimension.property + }, + start: self => { + self.elt.parentNode.classList.add("old-boxmodel-editing"); + }, + change: value => { + if (NUMERIC.test(value)) { + value += "px"; + } + + let properties = [ + { name: property, value: value } + ]; + + if (property.substring(0, 7) == "border-") { + let bprop = property.substring(0, property.length - 5) + "style"; + let style = session.getProperty(bprop); + if (!style || style == "none" || style == "hidden") { + properties.push({ name: bprop, value: "solid" }); + } + } + + session.setProperties(properties).catch(e => console.error(e)); + }, + done: (value, commit) => { + editor.elt.parentNode.classList.remove("old-boxmodel-editing"); + if (!commit) { + session.revert().then(() => { + session.destroy(); + }, e => console.error(e)); + } + }, + contextMenu: this.inspector.onTextBoxContextMenu, + cssProperties: this._cssProperties + }, event); + }, + + /** + * Is the BoxModelView visible in the sidebar. + * @return {Boolean} + */ + isViewVisible: function () { + return this.inspector && + this.inspector.sidebar.getCurrentTabID() == "computedview"; + }, + + /** + * Is the BoxModelView visible in the sidebar and is the current node valid to + * be displayed in the view. + * @return {Boolean} + */ + isViewVisibleAndNodeValid: function () { + return this.isViewVisible() && + this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode(); + }, + + /** + * Destroy the nodes. Remove listeners. + */ + destroy: function () { + let highlightElts = this.doc.querySelectorAll("#old-boxmodel-container *[title]"); + + for (let element of highlightElts) { + element.removeEventListener("mouseover", this.onHighlightMouseOver, true); + element.removeEventListener("mouseout", this.onHighlightMouseOut, true); + } + + this.expander.removeEventListener("click", this.onToggleExpander); + let header = this.doc.getElementById("old-boxmodel-header"); + header.removeEventListener("dblclick", this.onToggleExpander); + + let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); + nodeGeometry.removeEventListener("click", this.onGeometryButtonClick); + + this.boxModel.removeEventListener("click", this.onLevelClick, true); + this.boxModel.removeEventListener("focus", this.onFocus, true); + this.boxModel.removeEventListener("keydown", this.onKeyDown, true); + + this.inspector.off("picker-started", this.onPickerStarted); + + // Inspector Panel will destroy `markup` object on "will-navigate" event, + // therefore we have to check if it's still available in case BoxModelView + // is destroyed immediately after. + if (this.inspector.markup) { + this.inspector.markup.off("leave", this.onMarkupViewLeave); + this.inspector.markup.off("node-hover", this.onMarkupViewNodeHover); + } + + this.inspector.sidebar.off("computedview-selected", this.onNewNode); + this.inspector.selection.off("new-node-front", this.onNewSelection); + this.inspector.sidebar.off("select", this.onSidebarSelect); + this.inspector.target.off("will-navigate", this.onWillNavigate); + this.inspector.off("computed-view-filtered", this.onFilterComputedView); + + this.inspector = null; + this.doc = null; + this.wrapper = null; + this.container = null; + this.expander = null; + this.sizeLabel = null; + this.sizeHeadingLabel = null; + + this.marginLayout = null; + this.borderLayout = null; + this.paddingLayout = null; + this.boxModel = null; + this.layouts = null; + + if (this.reflowFront) { + this.untrackReflows(); + this.reflowFront.destroy(); + this.reflowFront = null; + } + }, + + /** + * Set initial box model focus to the margin layout. + */ + onFocus: function () { + let activeDescendant = this.boxModel.getAttribute("aria-activedescendant"); + + if (!activeDescendant) { + let nextLayout = this.marginLayout; + this.setAriaActive(nextLayout); + } + }, + + /** + * Active aria-level set to current layout. + * + * @param {Element} nextLayout + * Element of next layout that user has navigated to + * @param {Node} target + * Node to be observed + */ + setAriaActive: function (nextLayout, target) { + this.boxModel.setAttribute("aria-activedescendant", nextLayout.id); + if (target && target._editable) { + target.blur(); + } + + // Clear all + this.marginLayout.classList.remove("layout-active-elm"); + this.borderLayout.classList.remove("layout-active-elm"); + this.paddingLayout.classList.remove("layout-active-elm"); + + // Set the next level's border outline + nextLayout.classList.add("layout-active-elm"); + }, + + /** + * Update aria-active on mouse click. + * + * @param {Event} event + * The event triggered by a mouse click on the box model + */ + onLevelClick: function (event) { + let {target} = event; + let nextLayout = this.layouts[target.getAttribute("data-box")].get("click"); + + this.setAriaActive(nextLayout, target); + }, + + /** + * Handle keyboard navigation and focus for box model layouts. + * + * Updates active layout on arrow key navigation + * Focuses next layout's editboxes on enter key + * Unfocuses current layout's editboxes when active layout changes + * Controls tabbing between editBoxes + * + * @param {Event} event + * The event triggered by a keypress on the box model + */ + onKeyDown: function (event) { + let {target, keyCode} = event; + // If focused on editable value or in editing mode + let isEditable = target._editable || target.editor; + let level = this.boxModel.getAttribute("aria-activedescendant"); + let editingMode = target.tagName === "input"; + let nextLayout; + + switch (keyCode) { + case KeyCodes.DOM_VK_RETURN: + if (!isEditable) { + this.makeFocusable(level); + } + break; + case KeyCodes.DOM_VK_DOWN: + case KeyCodes.DOM_VK_UP: + if (!editingMode) { + event.preventDefault(); + this.makeUnfocasable(level); + let datalevel = this.doc.getElementById(level).getAttribute("data-box"); + nextLayout = this.layouts[datalevel].get(keyCode); + this.boxModel.focus(); + } + break; + case KeyCodes.DOM_VK_TAB: + if (isEditable) { + event.preventDefault(); + this.moveFocus(event, level); + } + break; + case KeyCodes.DOM_VK_ESCAPE: + if (isEditable && target._editable) { + event.preventDefault(); + event.stopPropagation(); + this.makeUnfocasable(level); + this.boxModel.focus(); + } + break; + default: + break; + } + + if (nextLayout) { + this.setAriaActive(nextLayout, target); + } + }, + + /** + * Make previous layout's elements unfocusable. + * + * @param {String} editLevel + * The previous layout + */ + makeUnfocasable: function (editLevel) { + let editBoxes = this.getEditBoxes(editLevel); + editBoxes.forEach(editBox => editBox.setAttribute("tabindex", "-1")); + }, + + /** + * Make current layout's elements focusable. + * + * @param {String} editLevel + * The current layout + */ + makeFocusable: function (editLevel) { + let editBoxes = this.getEditBoxes(editLevel); + editBoxes.forEach(editBox => editBox.setAttribute("tabindex", "0")); + editBoxes[0].focus(); + }, + + /** + * Keyboard navigation of edit boxes wraps around on edge + * elements ([layout]-top, [layout]-left). + * + * @param {Node} target + * Node to be observed + * @param {Boolean} shiftKey + * Determines if shiftKey was pressed + * @param {String} level + * Current active layout + */ + moveFocus: function ({target, shiftKey}, level) { + let editBoxes = this.getEditBoxes(level); + let editingMode = target.tagName === "input"; + // target.nextSibling is input field + let position = editingMode ? editBoxes.indexOf(target.nextSibling) + : editBoxes.indexOf(target); + + if (position === editBoxes.length - 1 && !shiftKey) { + position = 0; + } else if (position === 0 && shiftKey) { + position = editBoxes.length - 1; + } else { + shiftKey ? position-- : position++; + } + + let editBox = editBoxes[position]; + editBox.focus(); + + if (editingMode) { + editBox.click(); + } + }, + + /** + * Retrieve edit boxes for current layout. + * + * @param {String} editLevel + * Current active layout + * @return Layout's edit boxes + */ + getEditBoxes: function (editLevel) { + let dataLevel = this.doc.getElementById(editLevel).getAttribute("data-box"); + return [...this.doc.querySelectorAll( + `[data-box="${dataLevel}"].old-boxmodel-editable`)]; + }, + + onSidebarSelect: function (e, sidebar) { + this.setActive(sidebar === "computedview"); + }, + + /** + * Selection 'new-node-front' event handler. + */ + onNewSelection: function () { + let done = this.inspector.updating("computed-view"); + this.onNewNode() + .then(() => this.hideGeometryEditor()) + .then(done, (err) => { + console.error(err); + done(); + }).catch(console.error); + }, + + /** + * @return a promise that resolves when the view has been updated + */ + onNewNode: function () { + this.setActive(this.isViewVisibleAndNodeValid()); + return this.update(); + }, + + onHighlightMouseOver: function (e) { + let region = e.target.getAttribute("data-box"); + if (!region) { + return; + } + + this.showBoxModel({ + region, + showOnly: region, + onlyRegionArea: true + }); + }, + + onHighlightMouseOut: function () { + this.hideBoxModel(); + }, + + onGeometryButtonClick: function ({target}) { + if (target.hasAttribute("checked")) { + target.removeAttribute("checked"); + this.hideGeometryEditor(); + } else { + target.setAttribute("checked", "true"); + this.showGeometryEditor(); + } + }, + + onPickerStarted: function () { + this.hideGeometryEditor(); + }, + + onToggleExpander: function () { + let isOpen = this.expander.hasAttribute("open"); + + if (isOpen) { + this.container.hidden = true; + this.expander.removeAttribute("open"); + } else { + this.container.hidden = false; + this.expander.setAttribute("open", ""); + } + }, + + onMarkupViewLeave: function () { + this.showGeometryEditor(true); + }, + + onMarkupViewNodeHover: function () { + this.hideGeometryEditor(false); + }, + + onWillNavigate: function () { + this._geometryEditorHighlighter.release().catch(console.error); + this._geometryEditorHighlighter = null; + }, + + /** + * Event handler that responds to the computed view being filtered + * @param {String} reason + * @param {Boolean} hidden + * Whether or not to hide the box model wrapper + */ + onFilterComputedView: function (reason, hidden) { + this.wrapper.hidden = hidden; + }, + + /** + * Stop tracking reflows and hide all values when no node is selected or the + * box model view is hidden, otherwise track reflows and show values. + * @param {Boolean} isActive + */ + setActive: function (isActive) { + if (isActive === this.isActive) { + return; + } + this.isActive = isActive; + + if (isActive) { + this.trackReflows(); + } else { + this.untrackReflows(); + } + }, + + /** + * Compute the dimensions of the node and update the values in + * the inspector.xul document. + * @return a promise that will be resolved when complete. + */ + update: function () { + let lastRequest = Task.spawn((function* () { + if (!this.isViewVisibleAndNodeValid()) { + this.wrapper.hidden = true; + this.inspector.emit("boxmodel-view-updated"); + return null; + } + + let node = this.inspector.selection.nodeFront; + let layout = yield this.inspector.pageStyle.getLayout(node, { + autoMargins: this.isActive + }); + let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); + + yield this.updateGeometryButton(); + + // If a subsequent request has been made, wait for that one instead. + if (this._lastRequest != lastRequest) { + return this._lastRequest; + } + + this._lastRequest = null; + let width = layout.width; + let height = layout.height; + let newLabel = SHARED_L10N.getFormatStr("dimensions", width, height); + + if (this.sizeHeadingLabel.textContent != newLabel) { + this.sizeHeadingLabel.textContent = newLabel; + } + + for (let i in this.map) { + let property = this.map[i].property; + if (!(property in layout)) { + // Depending on the actor version, some properties + // might be missing. + continue; + } + let parsedValue = parseFloat(layout[property]); + if (Number.isNaN(parsedValue)) { + // Not a number. We use the raw string. + // Useful for "position" for example. + this.map[i].value = layout[property]; + } else { + this.map[i].value = parsedValue; + } + } + + let margins = layout.autoMargins; + if ("top" in margins) { + this.map.marginTop.value = "auto"; + } + if ("right" in margins) { + this.map.marginRight.value = "auto"; + } + if ("bottom" in margins) { + this.map.marginBottom.value = "auto"; + } + if ("left" in margins) { + this.map.marginLeft.value = "auto"; + } + + for (let i in this.map) { + let selector = this.map[i].selector; + let span = this.doc.querySelector(selector); + this.updateSourceRuleTooltip(span, this.map[i].property, styleEntries); + if (span.textContent.length > 0 && + span.textContent == this.map[i].value) { + continue; + } + span.textContent = this.map[i].value; + this.manageOverflowingText(span); + } + + width -= this.map.borderLeft.value + this.map.borderRight.value + + this.map.paddingLeft.value + this.map.paddingRight.value; + width = parseFloat(width.toPrecision(6)); + height -= this.map.borderTop.value + this.map.borderBottom.value + + this.map.paddingTop.value + this.map.paddingBottom.value; + height = parseFloat(height.toPrecision(6)); + + let newValue = width + "\u00D7" + height; + if (this.sizeLabel.textContent != newValue) { + this.sizeLabel.textContent = newValue; + } + + this.elementRules = styleEntries.map(e => e.rule); + + this.wrapper.hidden = false; + + this.inspector.emit("boxmodel-view-updated"); + return null; + }).bind(this)).catch(console.error); + + this._lastRequest = lastRequest; + return this._lastRequest; + }, + + /** + * Update the text in the tooltip shown when hovering over a value to provide + * information about the source CSS rule that sets this value. + * @param {DOMNode} el The element that will receive the tooltip. + * @param {String} property The name of the CSS property for the tooltip. + * @param {Array} rules An array of applied rules retrieved by + * styleActor.getApplied. + */ + updateSourceRuleTooltip: function (el, property, rules) { + // Dummy element used to parse the cssText of applied rules. + let dummyEl = this.doc.createElement("div"); + + // Rules are in order of priority so iterate until we find the first that + // defines a value for the property. + let sourceRule, value; + for (let {rule} of rules) { + dummyEl.style.cssText = rule.cssText; + value = dummyEl.style.getPropertyValue(property); + if (value !== "") { + sourceRule = rule; + break; + } + } + + let title = property; + if (sourceRule && sourceRule.selectors) { + title += "\n" + sourceRule.selectors.join(", "); + } + if (sourceRule && sourceRule.parentStyleSheet) { + if (sourceRule.parentStyleSheet.href) { + title += "\n" + sourceRule.parentStyleSheet.href + ":" + sourceRule.line; + } else { + title += "\n" + INSPECTOR_L10N.getStr("rule.sourceInline") + + ":" + sourceRule.line; + } + } + + el.setAttribute("title", title); + }, + + /** + * Show the box-model highlighter on the currently selected element + * @param {Object} options Options passed to the highlighter actor + */ + showBoxModel: function (options = {}) { + let toolbox = this.inspector.toolbox; + let nodeFront = this.inspector.selection.nodeFront; + + toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); + }, + + /** + * Hide the box-model highlighter on the currently selected element + */ + hideBoxModel: function () { + let toolbox = this.inspector.toolbox; + + toolbox.highlighterUtils.unhighlight(); + }, + + /** + * Show the geometry editor highlighter on the currently selected element + * @param {Boolean} [showOnlyIfActive=false] + * Indicates if the Geometry Editor should be shown only if it's active but + * hidden. + */ + showGeometryEditor: function (showOnlyIfActive = false) { + let toolbox = this.inspector.toolbox; + let nodeFront = this.inspector.selection.nodeFront; + let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); + let isActive = nodeGeometry.hasAttribute("checked"); + + if (showOnlyIfActive && !isActive) { + return; + } + + if (this._geometryEditorHighlighter) { + this._geometryEditorHighlighter.show(nodeFront).catch(console.error); + return; + } + + // instantiate Geometry Editor highlighter + toolbox.highlighterUtils + .getHighlighterByType("GeometryEditorHighlighter").then(highlighter => { + highlighter.show(nodeFront).catch(console.error); + this._geometryEditorHighlighter = highlighter; + + // Hide completely the geometry editor if the picker is clicked + toolbox.on("picker-started", this.onPickerStarted); + + // Temporary hide the geometry editor + this.inspector.markup.on("leave", this.onMarkupViewLeave); + this.inspector.markup.on("node-hover", this.onMarkupViewNodeHover); + + // Release the actor on will-navigate event + this.inspector.target.once("will-navigate", this.onWillNavigate); + }); + }, + + /** + * Hide the geometry editor highlighter on the currently selected element + * @param {Boolean} [updateButton=true] + * Indicates if the Geometry Editor's button needs to be unchecked too + */ + hideGeometryEditor: function (updateButton = true) { + if (this._geometryEditorHighlighter) { + this._geometryEditorHighlighter.hide().catch(console.error); + } + + if (updateButton) { + let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); + nodeGeometry.removeAttribute("checked"); + } + }, + + /** + * Update the visibility and the state of the geometry editor button, + * based on the selected node. + */ + updateGeometryButton: Task.async(function* () { + let node = this.inspector.selection.nodeFront; + let isEditable = false; + + if (node) { + isEditable = yield this.inspector.pageStyle.isPositionEditable(node); + } + + let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); + nodeGeometry.style.visibility = isEditable ? "visible" : "hidden"; + }), + + manageOverflowingText: function (span) { + let classList = span.parentNode.classList; + + if (classList.contains("old-boxmodel-left") || + classList.contains("old-boxmodel-right")) { + let force = span.textContent.length > LONG_TEXT_ROTATE_LIMIT; + classList.toggle("old-boxmodel-rotate", force); + } + } +}; + +module.exports = BoxModelView; diff --git a/devtools/client/inspector/components/moz.build b/devtools/client/inspector/components/moz.build index 50556cf26ecf..23d85edcdb23 100644 --- a/devtools/client/inspector/components/moz.build +++ b/devtools/client/inspector/components/moz.build @@ -5,6 +5,9 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( + 'deprecated-box-model.js', 'inspector-tab-panel.css', 'inspector-tab-panel.js', ) + +BROWSER_CHROME_MANIFESTS += ['test/browser.ini'] diff --git a/devtools/client/inspector/boxmodel/test/.eslintrc.js b/devtools/client/inspector/components/test/.eslintrc.js similarity index 100% rename from devtools/client/inspector/boxmodel/test/.eslintrc.js rename to devtools/client/inspector/components/test/.eslintrc.js diff --git a/devtools/client/inspector/boxmodel/test/browser.ini b/devtools/client/inspector/components/test/browser.ini similarity index 94% rename from devtools/client/inspector/boxmodel/test/browser.ini rename to devtools/client/inspector/components/test/browser.ini index c9881c903937..be937ecfd3d7 100644 --- a/devtools/client/inspector/boxmodel/test/browser.ini +++ b/devtools/client/inspector/components/test/browser.ini @@ -21,11 +21,9 @@ support-files = [browser_boxmodel_editablemodel_stylerules.js] [browser_boxmodel_guides.js] [browser_boxmodel_navigation.js] -skip-if = true # Bug 1336198 [browser_boxmodel_rotate-labels-on-sides.js] [browser_boxmodel_sync.js] [browser_boxmodel_tooltips.js] -skip-if = true # Bug 1336198 [browser_boxmodel_update-after-navigation.js] [browser_boxmodel_update-after-reload.js] # [browser_boxmodel_update-in-iframes.js] diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel.js b/devtools/client/inspector/components/test/browser_boxmodel.js similarity index 58% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel.js rename to devtools/client/inspector/components/test/browser_boxmodel.js index 9e085cafe232..d26d9061ce52 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel.js +++ b/devtools/client/inspector/components/test/browser_boxmodel.js @@ -10,118 +10,118 @@ // Expected values: var res1 = [ { - selector: ".boxmodel-element-size", + selector: "#old-boxmodel-element-size", value: "160" + "\u00D7" + "160.117" }, { - selector: ".boxmodel-size > span", + selector: ".old-boxmodel-size > span", value: "100" + "\u00D7" + "100.117" }, { - selector: ".boxmodel-margin.boxmodel-top > span", + selector: ".old-boxmodel-margin.old-boxmodel-top > span", value: 30 }, { - selector: ".boxmodel-margin.boxmodel-left > span", + selector: ".old-boxmodel-margin.old-boxmodel-left > span", value: "auto" }, { - selector: ".boxmodel-margin.boxmodel-bottom > span", + selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", value: 30 }, { - selector: ".boxmodel-margin.boxmodel-right > span", + selector: ".old-boxmodel-margin.old-boxmodel-right > span", value: "auto" }, { - selector: ".boxmodel-padding.boxmodel-top > span", + selector: ".old-boxmodel-padding.old-boxmodel-top > span", value: 20 }, { - selector: ".boxmodel-padding.boxmodel-left > span", + selector: ".old-boxmodel-padding.old-boxmodel-left > span", value: 20 }, { - selector: ".boxmodel-padding.boxmodel-bottom > span", + selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", value: 20 }, { - selector: ".boxmodel-padding.boxmodel-right > span", + selector: ".old-boxmodel-padding.old-boxmodel-right > span", value: 20 }, { - selector: ".boxmodel-border.boxmodel-top > span", + selector: ".old-boxmodel-border.old-boxmodel-top > span", value: 10 }, { - selector: ".boxmodel-border.boxmodel-left > span", + selector: ".old-boxmodel-border.old-boxmodel-left > span", value: 10 }, { - selector: ".boxmodel-border.boxmodel-bottom > span", + selector: ".old-boxmodel-border.old-boxmodel-bottom > span", value: 10 }, { - selector: ".boxmodel-border.boxmodel-right > span", + selector: ".old-boxmodel-border.old-boxmodel-right > span", value: 10 }, ]; var res2 = [ { - selector: ".boxmodel-element-size", + selector: "#old-boxmodel-element-size", value: "190" + "\u00D7" + "210" }, { - selector: ".boxmodel-size > span", + selector: ".old-boxmodel-size > span", value: "100" + "\u00D7" + "150" }, { - selector: ".boxmodel-margin.boxmodel-top > span", + selector: ".old-boxmodel-margin.old-boxmodel-top > span", value: 30 }, { - selector: ".boxmodel-margin.boxmodel-left > span", + selector: ".old-boxmodel-margin.old-boxmodel-left > span", value: "auto" }, { - selector: ".boxmodel-margin.boxmodel-bottom > span", + selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", value: 30 }, { - selector: ".boxmodel-margin.boxmodel-right > span", + selector: ".old-boxmodel-margin.old-boxmodel-right > span", value: "auto" }, { - selector: ".boxmodel-padding.boxmodel-top > span", + selector: ".old-boxmodel-padding.old-boxmodel-top > span", value: 20 }, { - selector: ".boxmodel-padding.boxmodel-left > span", + selector: ".old-boxmodel-padding.old-boxmodel-left > span", value: 20 }, { - selector: ".boxmodel-padding.boxmodel-bottom > span", + selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", value: 20 }, { - selector: ".boxmodel-padding.boxmodel-right > span", + selector: ".old-boxmodel-padding.old-boxmodel-right > span", value: 50 }, { - selector: ".boxmodel-border.boxmodel-top > span", + selector: ".old-boxmodel-border.old-boxmodel-top > span", value: 10 }, { - selector: ".boxmodel-border.boxmodel-left > span", + selector: ".old-boxmodel-border.old-boxmodel-left > span", value: 10 }, { - selector: ".boxmodel-border.boxmodel-bottom > span", + selector: ".old-boxmodel-border.old-boxmodel-bottom > span", value: 10 }, { - selector: ".boxmodel-border.boxmodel-right > span", + selector: ".old-boxmodel-border.old-boxmodel-right > span", value: 10 }, ]; @@ -142,7 +142,7 @@ add_task(function* () { function* testInitialValues(inspector, view) { info("Test that the initial values of the box model are correct"); - let viewdoc = view.document; + let viewdoc = view.doc; for (let i = 0; i < res1.length; i++) { let elt = viewdoc.querySelector(res1[i].selector); @@ -153,7 +153,7 @@ function* testInitialValues(inspector, view) { function* testChangingValues(inspector, view, testActor) { info("Test that changing the document updates the box model"); - let viewdoc = view.document; + let viewdoc = view.doc; let onUpdated = waitForUpdate(inspector); yield testActor.setAttribute("div", "style", diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js similarity index 74% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js rename to devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js index 37736152011b..5bb882dd6e7b 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js @@ -36,21 +36,21 @@ function* testEditingMargins(inspector, view, testActor) { "Should be no margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); + let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("3", {}, view.document.defaultView); + EventUtils.synthesizeKey("3", {}, view.doc.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-top")), "3px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-top")), "", @@ -66,35 +66,35 @@ function* testKeyBindings(inspector, view, testActor) { "Should be no margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-margin.boxmodel-left > span"); + let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-left > span"); is(span.textContent, 10, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "10px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_UP", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_UP", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "11px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "11px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_DOWN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_DOWN", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "10px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "10px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view.document.defaultView); + EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "20px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", "Should be the right margin-top on the element."); @@ -109,22 +109,22 @@ function* testEscapeToUndo(inspector, view, testActor) { "Should be the right margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-margin.boxmodel-left > span"); + let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-left > span"); is(span.textContent, 20, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "20px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", @@ -140,22 +140,22 @@ function* testDeletingValue(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-margin.boxmodel-right > span"); + let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-right > span"); is(span.textContent, 15, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "15px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-right")), "", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div1", "margin-right")), "", "Should be the right margin-top on the element."); @@ -167,26 +167,26 @@ function* testRefocusingOnClick(inspector, view, testActor) { yield selectNode("#div4", inspector); - let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); + let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); is(span.textContent, 1, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); info("Click in the already opened editor input"); - EventUtils.synthesizeMouseAtCenter(editor, {}, view.document.defaultView); - is(editor, view.document.activeElement, + EventUtils.synthesizeMouseAtCenter(editor, {}, view.doc.defaultView); + is(editor, view.doc.activeElement, "Inplace editor input should still have focus."); info("Check the input can still be used as expected"); - EventUtils.synthesizeKey("VK_UP", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_UP", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "2px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div4", "margin-top")), "2px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div4", "margin-top")), "2px", "Should be the right margin-top on the element."); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js similarity index 74% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js rename to devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js index ab49a191429c..ca5194266319 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js @@ -32,22 +32,22 @@ function* testEditing(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-padding.boxmodel-bottom > span"); + let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-bottom > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("7", {}, view.document.defaultView); + EventUtils.synthesizeKey("7", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "7", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-bottom")), "7px", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div1", "padding-bottom")), "7px", "Should be the right padding."); @@ -63,22 +63,22 @@ function* testEditingAndCanceling(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); + let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("8", {}, view.document.defaultView); + EventUtils.synthesizeKey("8", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "8", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "8px", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-left")), "5px", @@ -91,22 +91,22 @@ function* testDeleting(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); + let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should be the right padding."); @@ -122,22 +122,22 @@ function* testDeletingAndCanceling(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); + let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-left")), "5px", diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js similarity index 69% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js rename to devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js index c251dfbc162f..f56f584ddf95 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js @@ -30,45 +30,45 @@ add_task(function* () { function* testClickingOutsideEditor(view) { info("Test that clicking outside the editor blurs it"); - let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); + let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); is(span.textContent, 10, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); info("Click next to the opened editor input."); let onBlur = once(editor, "blur"); let rect = editor.getBoundingClientRect(); EventUtils.synthesizeMouse(editor, rect.width + 10, rect.height / 2, {}, - view.document.defaultView); + view.doc.defaultView); yield onBlur; - is(view.document.querySelector(".styleinspector-propertyeditor"), null, + is(view.doc.querySelector(".styleinspector-propertyeditor"), null, "Inplace editor has been removed."); } function* testClickingBelowContainer(view) { info("Test that clicking below the box-model container blurs it"); - let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); + let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); is(span.textContent, 10, "Should have the right value in the box model."); - info("Test that clicking below the boxmodel-container blurs the opened editor"); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + info("Test that clicking below the old-boxmodel-container blurs the opened editor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); let onBlur = once(editor, "blur"); - let container = view.document.querySelector(".boxmodel-container"); + let container = view.doc.querySelector("#old-boxmodel-container"); // Using getBoxQuads here because getBoundingClientRect (and therefore synthesizeMouse) // use an erroneous height of ~50px for the boxmodel-container. let bounds = container.getBoxQuads({relativeTo: view.doc})[0].bounds; EventUtils.synthesizeMouseAtPoint( bounds.left + 10, bounds.top + bounds.height + 10, - {}, view.document.defaultView); + {}, view.doc.defaultView); yield onBlur; - is(view.document.querySelector(".styleinspector-propertyeditor"), null, + is(view.doc.querySelector(".styleinspector-propertyeditor"), null, "Inplace editor has been removed."); } diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js similarity index 82% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js rename to devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js index 197ef99d3b47..5550a66423a4 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js @@ -24,15 +24,15 @@ add_task(function* () { "Should have the right border"); yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-border.boxmodel-top > span"); + let span = view.doc.querySelector(".old-boxmodel-border.old-boxmodel-top > span"); is(span.textContent, 0, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "0", "Should have the right value in the editor."); - EventUtils.synthesizeKey("1", {}, view.document.defaultView); + EventUtils.synthesizeKey("1", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "1", "Should have the right value in the editor."); @@ -41,7 +41,7 @@ add_task(function* () { is((yield getStyle(testActor, "#div1", "border-top-style")), "solid", "Should have the right border"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "border-top-width")), "", diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js similarity index 74% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js rename to devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js index 28ba89898062..f3f41e4d04ed 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js @@ -31,30 +31,30 @@ function* testUnits(inspector, view, testActor) { "Should have the right padding"); yield selectNode("#div1", inspector); - let span = view.document.querySelector(".boxmodel-padding.boxmodel-top > span"); + let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-top > span"); is(span.textContent, 3, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "3px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("1", {}, view.document.defaultView); + EventUtils.synthesizeKey("1", {}, view.doc.defaultView); yield waitForUpdate(inspector); - EventUtils.synthesizeKey("e", {}, view.document.defaultView); + EventUtils.synthesizeKey("e", {}, view.doc.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-top")), "", "An invalid value is handled cleanly"); - EventUtils.synthesizeKey("m", {}, view.document.defaultView); + EventUtils.synthesizeKey("m", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "1em", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-top")), "1em", "Should have updated the padding."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div1", "padding-top")), "1em", "Should be the right padding."); @@ -68,22 +68,22 @@ function* testValueComesFromStyleRule(inspector, view, testActor) { "Should have the right border-bottom-width"); yield selectNode("#div2", inspector); - let span = view.document.querySelector(".boxmodel-border.boxmodel-bottom > span"); + let span = view.doc.querySelector(".old-boxmodel-border.old-boxmodel-bottom > span"); is(span.textContent, 16, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "1em", "Should have the right value in the editor."); - EventUtils.synthesizeKey("0", {}, view.document.defaultView); + EventUtils.synthesizeKey("0", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "0", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div2", "border-bottom-width")), "0px", "Should have updated the border."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div2", "border-bottom-width")), "0px", "Should be the right border-bottom-width."); @@ -97,15 +97,15 @@ function* testShorthandsAreParsed(inspector, view, testActor) { "Should have the right padding"); yield selectNode("#div3", inspector); - let span = view.document.querySelector(".boxmodel-padding.boxmodel-right > span"); + let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-right > span"); is(span.textContent, 32, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "2em", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); is((yield getStyle(testActor, "#div3", "padding-right")), "", "Should be the right padding."); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js b/devtools/client/inspector/components/test/browser_boxmodel_guides.js similarity index 89% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js rename to devtools/client/inspector/components/test/browser_boxmodel_guides.js index 51457e25cd46..9dcaaa609cce 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_guides.js @@ -28,16 +28,16 @@ add_task(function* () { highlighterOptions = options; }; - let elt = view.document.querySelector(".boxmodel-margins"); + let elt = view.doc.getElementById("old-boxmodel-margins"); yield testGuideOnLayoutHover(elt, "margin", inspector, view); - elt = view.document.querySelector(".boxmodel-borders"); + elt = view.doc.getElementById("old-boxmodel-borders"); yield testGuideOnLayoutHover(elt, "border", inspector, view); - elt = view.document.querySelector(".boxmodel-paddings"); + elt = view.doc.getElementById("old-boxmodel-padding"); yield testGuideOnLayoutHover(elt, "padding", inspector, view); - elt = view.document.querySelector(".boxmodel-content"); + elt = view.doc.getElementById("old-boxmodel-content"); yield testGuideOnLayoutHover(elt, "content", inspector, view); }); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js b/devtools/client/inspector/components/test/browser_boxmodel_navigation.js similarity index 75% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js rename to devtools/client/inspector/components/test/browser_boxmodel_navigation.js index deee191fd2aa..6b8439710227 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_navigation.js @@ -29,50 +29,50 @@ add_task(function* () { function* testInitialFocus(inspector, view) { info("Test that the focus is on margin layout."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-margins", + is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-margins", "Should be set to the margin layout."); } function* testChangingLevels(inspector, view) { info("Test that using arrow keys updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); EventUtils.synthesizeKey("VK_ESCAPE", {}); EventUtils.synthesizeKey("VK_DOWN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-borders", + is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-borders", "Should be set to the border layout."); EventUtils.synthesizeKey("VK_DOWN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-padding", + is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-padding", "Should be set to the padding layout."); EventUtils.synthesizeKey("VK_UP", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-borders", + is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-borders", "Should be set to the border layout."); EventUtils.synthesizeKey("VK_UP", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-margins", + is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-margins", "Should be set to the margin layout."); } function* testTabbingWrapAround(inspector, view) { info("Test that using arrow keys updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); let editLevel = boxmodel.getAttribute("aria-activedescendant"); let dataLevel = viewdoc.getElementById(editLevel).getAttribute("data-box"); let editBoxes = [...viewdoc.querySelectorAll( - `[data-box="${dataLevel}"].boxmodel-editable`)]; + `[data-box="${dataLevel}"].old-boxmodel-editable`)]; EventUtils.synthesizeKey("VK_ESCAPE", {}); editBoxes[3].focus(); @@ -87,12 +87,12 @@ function* testTabbingWrapAround(inspector, view) { function* testChangingLevelsByClicking(inspector, view) { info("Test that clicking on levels updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); boxmodel.focus(); - let marginLayout = viewdoc.getElementById("boxmodel-margins"); - let borderLayout = viewdoc.getElementById("boxmodel-borders"); - let paddingLayout = viewdoc.getElementById("boxmodel-padding"); + let marginLayout = viewdoc.getElementById("old-boxmodel-margins"); + let borderLayout = viewdoc.getElementById("old-boxmodel-borders"); + let paddingLayout = viewdoc.getElementById("old-boxmodel-padding"); let layouts = [paddingLayout, borderLayout, marginLayout]; layouts.forEach(layout => { diff --git a/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js b/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js new file mode 100644 index 000000000000..df667e6d1a55 --- /dev/null +++ b/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js @@ -0,0 +1,49 @@ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that longer values are rotated on the side + +const res1 = [ + {selector: ".old-boxmodel-margin.old-boxmodel-top > span", value: 30}, + {selector: ".old-boxmodel-margin.old-boxmodel-left > span", value: "auto"}, + {selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", value: 30}, + {selector: ".old-boxmodel-margin.old-boxmodel-right > span", value: "auto"}, + {selector: ".old-boxmodel-padding.old-boxmodel-top > span", value: 20}, + {selector: ".old-boxmodel-padding.old-boxmodel-left > span", value: 2000000}, + {selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", value: 20}, + {selector: ".old-boxmodel-padding.old-boxmodel-right > span", value: 20}, + {selector: ".old-boxmodel-border.old-boxmodel-top > span", value: 10}, + {selector: ".old-boxmodel-border.old-boxmodel-left > span", value: 10}, + {selector: ".old-boxmodel-border.old-boxmodel-bottom > span", value: 10}, + {selector: ".old-boxmodel-border.old-boxmodel-right > span", value: 10}, +]; + +const TEST_URI = encodeURIComponent([ + "", + "
" +].join("")); +const LONG_TEXT_ROTATE_LIMIT = 3; + +add_task(function* () { + yield addTab("data:text/html," + TEST_URI); + let {inspector, view} = yield openBoxModelView(); + yield selectNode("div", inspector); + + for (let i = 0; i < res1.length; i++) { + let elt = view.doc.querySelector(res1[i].selector); + let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT; + let classList = elt.parentNode.classList; + let canBeRotated = classList.contains("old-boxmodel-left") || + classList.contains("old-boxmodel-right"); + let isRotated = classList.contains("old-boxmodel-rotate"); + + is(canBeRotated && isLong, + isRotated, res1[i].selector + " correctly rotated."); + } +}); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js b/devtools/client/inspector/components/test/browser_boxmodel_sync.js similarity index 77% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js rename to devtools/client/inspector/components/test/browser_boxmodel_sync.js index 382675ad2d2d..c0fde5c80b86 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_sync.js @@ -17,14 +17,14 @@ add_task(function* () { yield selectNode("p", inspector); info("Modify padding-bottom in box model view"); - let span = view.document.querySelector(".boxmodel-padding.boxmodel-bottom > span"); - EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); - let editor = view.document.querySelector(".styleinspector-propertyeditor"); + let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-bottom > span"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); + let editor = view.doc.querySelector(".styleinspector-propertyeditor"); - EventUtils.synthesizeKey("7", {}, view.document.defaultView); + EventUtils.synthesizeKey("7", {}, view.doc.defaultView); yield waitForUpdate(inspector); is(editor.value, "7", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); let onRuleViewRefreshed = once(inspector, "rule-view-refreshed"); let onRuleViewSelected = once(inspector.sidebar, "ruleview-selected"); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js b/devtools/client/inspector/components/test/browser_boxmodel_tooltips.js similarity index 83% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js rename to devtools/client/inspector/components/test/browser_boxmodel_tooltips.js index 6f5997635fe8..cdbbd6885bb4 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_tooltips.js @@ -76,24 +76,24 @@ add_task(function* () { info("Checking the regions tooltips"); - ok(view.document.querySelector(".boxmodel-margins").hasAttribute("title"), + ok(view.doc.querySelector("#old-boxmodel-margins").hasAttribute("title"), "The margin region has a tooltip"); - is(view.document.querySelector(".boxmodel-margins").getAttribute("title"), "margin", + is(view.doc.querySelector("#old-boxmodel-margins").getAttribute("title"), "margin", "The margin region has the correct tooltip content"); - ok(view.document.querySelector(".boxmodel-borders").hasAttribute("title"), + ok(view.doc.querySelector("#old-boxmodel-borders").hasAttribute("title"), "The border region has a tooltip"); - is(view.document.querySelector(".boxmodel-borders").getAttribute("title"), "border", + is(view.doc.querySelector("#old-boxmodel-borders").getAttribute("title"), "border", "The border region has the correct tooltip content"); - ok(view.document.querySelector(".boxmodel-paddings").hasAttribute("title"), + ok(view.doc.querySelector("#old-boxmodel-padding").hasAttribute("title"), "The padding region has a tooltip"); - is(view.document.querySelector(".boxmodel-paddings").getAttribute("title"), "padding", + is(view.doc.querySelector("#old-boxmodel-padding").getAttribute("title"), "padding", "The padding region has the correct tooltip content"); - ok(view.document.querySelector(".boxmodel-content").hasAttribute("title"), + ok(view.doc.querySelector("#old-boxmodel-content").hasAttribute("title"), "The content region has a tooltip"); - is(view.document.querySelector(".boxmodel-content").getAttribute("title"), "content", + is(view.doc.querySelector("#old-boxmodel-content").getAttribute("title"), "content", "The content region has the correct tooltip content"); for (let {selector, values} of VALUES_TEST_DATA) { @@ -108,7 +108,7 @@ add_task(function* () { let name = view.map[key].property; let expectedTooltipData = values.find(o => o.name === name); - let el = view.document.querySelector(view.map[key].selector); + let el = view.doc.querySelector(view.map[key].selector); ok(el.hasAttribute("title"), "The " + name + " value has a tooltip"); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js b/devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js similarity index 86% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js rename to devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js index dfcf8ceefe5a..62918310ceea 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js @@ -17,16 +17,14 @@ add_task(function* () { yield testFirstPage(inspector, view, testActor); info("Navigate to the second page"); - let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval(`content.location.href="${IFRAME2}"`); - yield onMarkupLoaded; + yield inspector.once("markuploaded"); yield testSecondPage(inspector, view, testActor); info("Go back to the first page"); - onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval("content.history.back();"); - yield onMarkupLoaded; + yield inspector.once("markuploaded"); yield testBackToFirstPage(inspector, view, testActor); }); @@ -34,11 +32,12 @@ add_task(function* () { function* testFirstPage(inspector, view, testActor) { info("Test that the box model view works on the first page"); + info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let paddingElt = view.document.querySelector( - ".boxmodel-padding.boxmodel-top > span"); + let paddingElt = view.doc.querySelector( + ".old-boxmodel-padding.old-boxmodel-top > span"); is(paddingElt.textContent, "50"); info("Listening for box model view changes and modifying the padding"); @@ -54,10 +53,11 @@ function* testFirstPage(inspector, view, testActor) { function* testSecondPage(inspector, view, testActor) { info("Test that the box model view works on the second page"); + info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.document.querySelector(".boxmodel-size > span"); + let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); is(sizeElt.textContent, "100" + "\u00D7" + "100"); info("Listening for box model view changes and modifying the size"); @@ -73,12 +73,13 @@ function* testSecondPage(inspector, view, testActor) { function* testBackToFirstPage(inspector, view, testActor) { info("Test that the box model view works on the first page after going back"); + info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value, which is the" + "modified value from step one because of the bfcache"); - let paddingElt = view.document.querySelector( - ".boxmodel-padding.boxmodel-top > span"); + let paddingElt = view.doc.querySelector( + ".old-boxmodel-padding.old-boxmodel-top > span"); is(paddingElt.textContent, "20"); info("Listening for box model view changes and modifying the padding"); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js b/devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js similarity index 87% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js rename to devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js index f1ed222949a4..111031e115d2 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js @@ -14,20 +14,20 @@ add_task(function* () { yield assertBoxModelView(inspector, view, testActor); info("Reload the page"); - let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.reload(); - yield onMarkupLoaded; + yield inspector.once("markuploaded"); info("Test that the box model view works on the reloaded page"); yield assertBoxModelView(inspector, view, testActor); }); function* assertBoxModelView(inspector, view, testActor) { + info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let paddingElt = view.document.querySelector( - ".boxmodel-padding.boxmodel-top > span"); + let paddingElt = view.doc.querySelector( + ".old-boxmodel-padding.old-boxmodel-top > span"); is(paddingElt.textContent, "50"); info("Listening for box model view changes and modifying the padding"); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js b/devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js similarity index 93% rename from devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js rename to devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js index 6aa10e441ae9..9aedb1b581ac 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js +++ b/devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js @@ -22,7 +22,7 @@ function* testResizingInIframe(inspector, view, testActor) { yield selectNodeInIframe2("div", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.document.querySelector(".boxmodel-size > span"); + let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); is(sizeElt.textContent, "400\u00D7200"); info("Listening for box model view changes and modifying its size"); @@ -40,15 +40,14 @@ function* testReflowsAfterIframeDeletion(inspector, view, testActor) { "iframe"); info("Deleting the iframe2"); - let onInspectorUpdated = inspector.once("inspector-updated"); yield removeIframe2(testActor); - yield onInspectorUpdated; + yield inspector.once("inspector-updated"); info("Selecting the test node in iframe1"); yield selectNodeInIframe1("p", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.document.querySelector(".boxmodel-size > span"); + let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); is(sizeElt.textContent, "100\u00D7100"); info("Listening for box model view changes and modifying its size"); diff --git a/devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe1.html b/devtools/client/inspector/components/test/doc_boxmodel_iframe1.html similarity index 100% rename from devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe1.html rename to devtools/client/inspector/components/test/doc_boxmodel_iframe1.html diff --git a/devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe2.html b/devtools/client/inspector/components/test/doc_boxmodel_iframe2.html similarity index 100% rename from devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe2.html rename to devtools/client/inspector/components/test/doc_boxmodel_iframe2.html diff --git a/devtools/client/inspector/boxmodel/test/head.js b/devtools/client/inspector/components/test/head.js similarity index 65% rename from devtools/client/inspector/boxmodel/test/head.js rename to devtools/client/inspector/components/test/head.js index de25fe893077..fa86b5e9e179 100644 --- a/devtools/client/inspector/boxmodel/test/head.js +++ b/devtools/client/inspector/components/test/head.js @@ -58,7 +58,7 @@ function openBoxModelView() { return { toolbox: data.toolbox, inspector: data.inspector, - view: data.inspector.computedview, + view: data.inspector.computedview.boxModelView, testActor: data.testActor }; }); @@ -66,37 +66,10 @@ function openBoxModelView() { /** * Wait for the boxmodel-view-updated event. - * - * @param {InspectorPanel} inspector - * The instance of InspectorPanel currently loaded in the toolbox. - * @param {Boolean} waitForSelectionUpdate - * Should the boxmodel-view-updated event come from a new selection. - * @return {Promise} a promise + * @return a promise */ -function waitForUpdate(inspector, waitForSelectionUpdate) { - return new Promise(resolve => { - inspector.on("boxmodel-view-updated", function onUpdate(e, reasons) { - // Wait for another update event if we are waiting for a selection related event. - if (waitForSelectionUpdate && !reasons.includes("new-selection")) { - return; - } - - inspector.off("boxmodel-view-updated", onUpdate); - resolve(); - }); - }); -} - -/** - * Wait for both boxmode-view-updated and markuploaded events. - * - * @return {Promise} a promise that resolves when both events have been received. - */ -function waitForMarkupLoaded(inspector) { - return Promise.all([ - waitForUpdate(inspector), - inspector.once("markuploaded"), - ]); +function waitForUpdate(inspector) { + return inspector.once("boxmodel-view-updated"); } function getStyle(testActor, selector, propertyName) { @@ -112,15 +85,3 @@ function setStyle(testActor, selector, propertyName, value) { .style.${propertyName} = "${value}"; `); } - -/** - * The box model doesn't participate in the inspector's update mechanism, so simply - * calling the default selectNode isn't enough to guarantee that the box model view has - * finished updating. We also need to wait for the "boxmodel-view-updated" event. - */ -var _selectNode = selectNode; -selectNode = function* (node, inspector, reason) { - let onUpdate = waitForUpdate(inspector, true); - yield _selectNode(node, inspector, reason); - yield onUpdate; -}; diff --git a/devtools/client/inspector/computed/computed.js b/devtools/client/inspector/computed/computed.js index 500ccb4968a0..95c81f0cf14d 100644 --- a/devtools/client/inspector/computed/computed.js +++ b/devtools/client/inspector/computed/computed.js @@ -26,14 +26,9 @@ const { const StyleInspectorMenu = require("devtools/client/inspector/shared/style-inspector-menu"); const TooltipsOverlay = require("devtools/client/inspector/shared/tooltips-overlay"); const KeyShortcuts = require("devtools/client/shared/key-shortcuts"); +const BoxModelView = require("devtools/client/inspector/components/deprecated-box-model"); const clipboardHelper = require("devtools/shared/platform/clipboard"); -const { createElement, createFactory } = require("devtools/client/shared/vendor/react"); -const ReactDOM = require("devtools/client/shared/vendor/react-dom"); -const { Provider } = require("devtools/client/shared/vendor/react-redux"); - -const BoxModelApp = createFactory(require("devtools/client/inspector/boxmodel/components/BoxModelApp")); - const STYLE_INSPECTOR_PROPERTIES = "devtools/shared/locales/styleinspector.properties"; const {LocalizationHelper} = require("devtools/shared/l10n"); const STYLE_INSPECTOR_L10N = new LocalizationHelper(STYLE_INSPECTOR_PROPERTIES); @@ -159,7 +154,6 @@ UpdateProcess.prototype = { function CssComputedView(inspector, document, pageStyle) { this.inspector = inspector; this.highlighters = inspector.highlighters; - this.store = inspector.store; this.styleDocument = document; this.styleWindow = this.styleDocument.defaultView; this.pageStyle = pageStyle; @@ -180,7 +174,6 @@ function CssComputedView(inspector, document, pageStyle) { let doc = this.styleDocument; this.element = doc.getElementById("propertyContainer"); - this.boxModelWrapper = doc.getElementById("boxmodel-wrapper"); this.searchField = doc.getElementById("computedview-searchbox"); this.searchClearButton = doc.getElementById("computedview-searchinput-clear"); this.includeBrowserStylesCheckbox = @@ -216,7 +209,6 @@ function CssComputedView(inspector, document, pageStyle) { // The element that we're inspecting, and the document that it comes from. this._viewedElement = null; - this.createBoxModelView(); this.createStyleViews(); this._contextmenu = new StyleInspectorMenu(this, { isRuleView: false }); @@ -560,10 +552,10 @@ CssComputedView.prototype = { this._filterChangedTimeout = setTimeout(() => { if (this.searchField.value.length > 0) { this.searchField.setAttribute("filled", true); - this.boxModelWrapper.hidden = true; + this.inspector.emit("computed-view-filtered", true); } else { this.searchField.removeAttribute("filled"); - this.boxModelWrapper.hidden = false; + this.inspector.emit("computed-view-filtered", false); } this.refreshPanel(); @@ -613,29 +605,6 @@ CssComputedView.prototype = { this.inspector.emit("computed-view-sourcelinks-updated"); }, - /** - * Render the box model view. - */ - createBoxModelView: function () { - let { - onHideBoxModelHighlighter, - onShowBoxModelEditor, - onShowBoxModelHighlighter, - } = this.inspector.boxmodelview.getComponentProps(); - - let provider = createElement( - Provider, - { store: this.store }, - BoxModelApp({ - showBoxModelProperties: false, - onHideBoxModelHighlighter, - onShowBoxModelEditor, - onShowBoxModelHighlighter, - }) - ); - ReactDOM.render(provider, this.boxModelWrapper); - }, - /** * The CSS as displayed by the UI. */ @@ -814,7 +783,7 @@ CssComputedView.prototype = { // Nodes used in templating this.element = null; - this.boxModelWrapper = null; + this.panel = null; this.searchField = null; this.searchClearButton = null; this.includeBrowserStylesCheckbox = null; @@ -827,7 +796,6 @@ CssComputedView.prototype = { this.inspector = null; this.highlighters = null; - this.store = null; this.styleDocument = null; this.styleWindow = null; @@ -1448,6 +1416,7 @@ function ComputedViewTool(inspector, window) { this.computedView = new CssComputedView(this.inspector, this.document, this.inspector.pageStyle); + this.boxModelView = new BoxModelView(this.inspector, this.document); this.onSelected = this.onSelected.bind(this); this.refresh = this.refresh.bind(this); @@ -1556,8 +1525,9 @@ ComputedViewTool.prototype = { } this.computedView.destroy(); + this.boxModelView.destroy(); - this.computedView = this.document = this.inspector = null; + this.computedView = this.boxModelView = this.document = this.inspector = null; } }; diff --git a/devtools/client/inspector/computed/test/browser_computed_search-filter.js b/devtools/client/inspector/computed/test/browser_computed_search-filter.js index f8f25f23a639..d5b2634f4884 100644 --- a/devtools/client/inspector/computed/test/browser_computed_search-filter.js +++ b/devtools/client/inspector/computed/test/browser_computed_search-filter.js @@ -34,7 +34,7 @@ function* testToggleDefaultStyles(inspector, computedView) { function* testAddTextInFilter(inspector, computedView) { info("setting filter text to \"color\""); let doc = computedView.styleDocument; - let boxModelWrapper = doc.getElementById("boxmodel-wrapper"); + let boxModelWrapper = doc.querySelector("#old-boxmodel-wrapper"); let searchField = computedView.searchField; let onRefreshed = inspector.once("computed-view-refreshed"); let win = computedView.styleWindow; diff --git a/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js b/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js index 39dcefcb3838..2b4a29618310 100644 --- a/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js +++ b/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js @@ -50,7 +50,7 @@ function* testClearSearchFilter(inspector, computedView) { let win = computedView.styleWindow; let doc = computedView.styleDocument; - let boxModelWrapper = doc.getElementById("boxmodel-wrapper"); + let boxModelWrapper = doc.querySelector("#old-boxmodel-wrapper"); let propertyViews = computedView.propertyViews; let searchField = computedView.searchField; let searchClearButton = computedView.searchClearButton; diff --git a/devtools/client/inspector/inspector.js b/devtools/client/inspector/inspector.js index 34ab2b12d86c..1e9af044f029 100644 --- a/devtools/client/inspector/inspector.js +++ b/devtools/client/inspector/inspector.js @@ -23,7 +23,7 @@ const Menu = require("devtools/client/framework/menu"); const MenuItem = require("devtools/client/framework/menu-item"); const {HTMLBreadcrumbs} = require("devtools/client/inspector/breadcrumbs"); -const BoxModelView = require("devtools/client/inspector/boxmodel/box-model"); +const {ComputedViewTool} = require("devtools/client/inspector/computed/computed"); const {FontInspector} = require("devtools/client/inspector/fonts/fonts"); const {InspectorSearch} = require("devtools/client/inspector/inspector-search"); const {RuleViewTool} = require("devtools/client/inspector/rules/rules"); @@ -78,6 +78,8 @@ const PORTRAIT_MODE_WIDTH = 700; * - computed-view-sourcelinks-updated * Fired when the stylesheet source links have been updated (when switching * to source-mapped files) + * - computed-view-filtered + * Fired when the computed rules view is filtered * - rule-view-refreshed * Fired when the rule view updates to a new node * - rule-view-sourcelinks-updated @@ -570,9 +572,6 @@ Inspector.prototype = { defaultTab == "computedview"); this.ruleview = new RuleViewTool(this, this.panelWin); - this.boxmodelview = new BoxModelView(this, this.panelWin); - const {ComputedViewTool} = - this.browserRequire("devtools/client/inspector/computed/computed"); this.computedview = new ComputedViewTool(this, this.panelWin); if (Services.prefs.getBoolPref("devtools.layoutview.enabled")) { diff --git a/devtools/client/inspector/inspector.xhtml b/devtools/client/inspector/inspector.xhtml index 529627161088..d3e13fb7b781 100644 --- a/devtools/client/inspector/inspector.xhtml +++ b/devtools/client/inspector/inspector.xhtml @@ -14,6 +14,7 @@ + @@ -131,7 +132,60 @@
-
+
+
+ + +
+ +
+
+ +
+ +
+ +
+
+
+
+
+
+ +

+

+

+

+ +

+

+

+

+ +

+

+

+

+ +

+ +

+
+ +
+ +
+ + +
+
+ +
+

+
+
diff --git a/devtools/client/inspector/boxmodel/actions/box-model.js b/devtools/client/inspector/layout/actions/box-model.js similarity index 100% rename from devtools/client/inspector/boxmodel/actions/box-model.js rename to devtools/client/inspector/layout/actions/box-model.js diff --git a/devtools/client/inspector/layout/actions/index.js b/devtools/client/inspector/layout/actions/index.js index bf11969f238b..d694e37400a2 100644 --- a/devtools/client/inspector/layout/actions/index.js +++ b/devtools/client/inspector/layout/actions/index.js @@ -17,6 +17,9 @@ createEnum([ // Update the entire grids state with the new list of grids. "UPDATE_GRIDS", + // Update the layout state with the latest layout properties. + "UPDATE_LAYOUT", + // Update the grid highlighter's show grid line numbers state. "UPDATE_SHOW_GRID_LINE_NUMBERS", diff --git a/devtools/client/inspector/layout/actions/moz.build b/devtools/client/inspector/layout/actions/moz.build index 09b7039d19de..5e157a4bd728 100644 --- a/devtools/client/inspector/layout/actions/moz.build +++ b/devtools/client/inspector/layout/actions/moz.build @@ -5,6 +5,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( + 'box-model.js', 'grids.js', 'highlighter-settings.js', 'index.js', diff --git a/devtools/client/inspector/layout/components/App.js b/devtools/client/inspector/layout/components/App.js index cbcb2bebc271..d8dd19582d0c 100644 --- a/devtools/client/inspector/layout/components/App.js +++ b/devtools/client/inspector/layout/components/App.js @@ -11,10 +11,9 @@ const { connect } = require("devtools/client/shared/vendor/react-redux"); const { LocalizationHelper } = require("devtools/shared/l10n"); const Accordion = createFactory(require("./Accordion")); +const BoxModel = createFactory(require("./BoxModel")); const Grid = createFactory(require("./Grid")); -const BoxModel = createFactory(require("devtools/client/inspector/boxmodel/components/BoxModel")); - const Types = require("../types"); const { getStr } = require("../utils/l10n"); diff --git a/devtools/client/inspector/boxmodel/components/BoxModel.js b/devtools/client/inspector/layout/components/BoxModel.js similarity index 100% rename from devtools/client/inspector/boxmodel/components/BoxModel.js rename to devtools/client/inspector/layout/components/BoxModel.js diff --git a/devtools/client/inspector/boxmodel/components/BoxModelEditable.js b/devtools/client/inspector/layout/components/BoxModelEditable.js similarity index 100% rename from devtools/client/inspector/boxmodel/components/BoxModelEditable.js rename to devtools/client/inspector/layout/components/BoxModelEditable.js diff --git a/devtools/client/inspector/boxmodel/components/BoxModelInfo.js b/devtools/client/inspector/layout/components/BoxModelInfo.js similarity index 100% rename from devtools/client/inspector/boxmodel/components/BoxModelInfo.js rename to devtools/client/inspector/layout/components/BoxModelInfo.js diff --git a/devtools/client/inspector/boxmodel/components/BoxModelMain.js b/devtools/client/inspector/layout/components/BoxModelMain.js similarity index 92% rename from devtools/client/inspector/boxmodel/components/BoxModelMain.js rename to devtools/client/inspector/layout/components/BoxModelMain.js index a3980c79d104..42baa7427453 100644 --- a/devtools/client/inspector/boxmodel/components/BoxModelMain.js +++ b/devtools/client/inspector/layout/components/BoxModelMain.js @@ -37,23 +37,7 @@ module.exports = createClass({ return layout[property] ? parseFloat(layout[property]) : "-"; }, - getHeightValue(property) { - let { layout } = this.props.boxModel; - - if (property == undefined) { - return "-"; - } - - property -= parseFloat(layout["border-top-width"]) + - parseFloat(layout["border-bottom-width"]) + - parseFloat(layout["padding-top"]) + - parseFloat(layout["padding-bottom"]); - property = parseFloat(property.toPrecision(6)); - - return property; - }, - - getWidthValue(property) { + getHeightOrWidthValue(property) { let { layout } = this.props.boxModel; if (property == undefined) { @@ -99,7 +83,7 @@ module.exports = createClass({ render() { let { boxModel, onShowBoxModelEditor } = this.props; let { layout } = boxModel; - let { height, width } = layout; + let { width, height } = layout; let borderTop = this.getBorderOrPaddingValue("border-top-width"); let borderRight = this.getBorderOrPaddingValue("border-right-width"); @@ -116,8 +100,8 @@ module.exports = createClass({ let marginBottom = this.getMarginValue("margin-bottom", "bottom"); let marginLeft = this.getMarginValue("margin-left", "left"); - height = this.getHeightValue(height); - width = this.getWidthValue(width); + width = this.getHeightOrWidthValue(width); + height = this.getHeightOrWidthValue(height); return dom.div( { diff --git a/devtools/client/inspector/boxmodel/components/BoxModelProperties.js b/devtools/client/inspector/layout/components/BoxModelProperties.js similarity index 100% rename from devtools/client/inspector/boxmodel/components/BoxModelProperties.js rename to devtools/client/inspector/layout/components/BoxModelProperties.js diff --git a/devtools/client/inspector/boxmodel/components/ComputedProperty.js b/devtools/client/inspector/layout/components/ComputedProperty.js similarity index 100% rename from devtools/client/inspector/boxmodel/components/ComputedProperty.js rename to devtools/client/inspector/layout/components/ComputedProperty.js diff --git a/devtools/client/inspector/layout/components/moz.build b/devtools/client/inspector/layout/components/moz.build index 551eaa5eda51..7ad90ba4572b 100644 --- a/devtools/client/inspector/layout/components/moz.build +++ b/devtools/client/inspector/layout/components/moz.build @@ -8,6 +8,12 @@ DevToolsModules( 'Accordion.css', 'Accordion.js', 'App.js', + 'BoxModel.js', + 'BoxModelEditable.js', + 'BoxModelInfo.js', + 'BoxModelMain.js', + 'BoxModelProperties.js', + 'ComputedProperty.js', 'Grid.js', 'GridDisplaySettings.js', 'GridItem.js', diff --git a/devtools/client/inspector/layout/layout.js b/devtools/client/inspector/layout/layout.js index 91ccd4b2402c..d9c6ba201be7 100644 --- a/devtools/client/inspector/layout/layout.js +++ b/devtools/client/inspector/layout/layout.js @@ -6,12 +6,18 @@ const Services = require("Services"); const { Task } = require("devtools/shared/task"); +const { getCssProperties } = require("devtools/shared/fronts/css-properties"); +const { ReflowFront } = require("devtools/shared/fronts/reflow"); +const { InplaceEditor } = require("devtools/client/shared/inplace-editor"); const { createFactory, createElement } = require("devtools/client/shared/vendor/react"); const { Provider } = require("devtools/client/shared/vendor/react-redux"); const SwatchColorPickerTooltip = require("devtools/client/shared/widgets/tooltip/SwatchColorPickerTooltip"); +const { + updateLayout, +} = require("./actions/box-model"); const { updateGridColor, updateGridHighlighted, @@ -24,10 +30,13 @@ const { const App = createFactory(require("./components/App")); +const EditingSession = require("./utils/editing-session"); + const { LocalizationHelper } = require("devtools/shared/l10n"); const INSPECTOR_L10N = new LocalizationHelper("devtools/client/locales/inspector.properties"); +const NUMERIC = /^-?[\d\.]+$/; const SHOW_GRID_LINE_NUMBERS = "devtools.gridinspector.showGridLineNumbers"; const SHOW_INFINITE_LINES_PREF = "devtools.gridinspector.showInfiniteLines"; @@ -50,8 +59,11 @@ function LayoutView(inspector, window) { this.store = inspector.store; this.walker = this.inspector.walker; + this.updateBoxModel = this.updateBoxModel.bind(this); + this.onGridLayoutChange = this.onGridLayoutChange.bind(this); this.onHighlighterChange = this.onHighlighterChange.bind(this); + this.onNewSelection = this.onNewSelection.bind(this); this.onSidebarSelect = this.onSidebarSelect.bind(this); this.init(); @@ -68,18 +80,13 @@ LayoutView.prototype = { return; } - let { - onHideBoxModelHighlighter, - onShowBoxModelEditor, - onShowBoxModelHighlighter, - } = this.inspector.boxmodelview.getComponentProps(); - this.layoutInspector = yield this.inspector.walker.getLayoutInspector(); this.loadHighlighterSettings(); this.highlighters.on("grid-highlighter-hidden", this.onHighlighterChange); this.highlighters.on("grid-highlighter-shown", this.onHighlighterChange); + this.inspector.selection.on("new-node-front", this.onNewSelection); this.inspector.sidebar.on("select", this.onSidebarSelect); // Create a shared SwatchColorPicker instance to be reused by all GridItem components. @@ -105,10 +112,13 @@ LayoutView.prototype = { */ showBoxModelProperties: true, - onHideBoxModelHighlighter: () => onHideBoxModelHighlighter(), - onShowBoxModelEditor: (element, event, property) => - onShowBoxModelEditor(element, event, property), - onShowBoxModelHighlighter: (options = {}) => onShowBoxModelHighlighter(options), + /** + * Hides the box-model highlighter on the currently selected element. + */ + onHideBoxModelHighlighter: () => { + let toolbox = this.inspector.toolbox; + toolbox.highlighterUtils.unhighlight(); + }, /** * Handler for a change in the grid overlay color picker for a grid container. @@ -133,6 +143,88 @@ LayoutView.prototype = { } }, + /** + * Shows the inplace editor when a box model editable value is clicked on the + * box model panel. + * + * @param {DOMNode} element + * The element that was clicked. + * @param {Event} event + * The event object. + * @param {String} property + * The name of the property. + */ + onShowBoxModelEditor: (element, event, property) => { + let session = new EditingSession({ + inspector: this.inspector, + doc: this.document, + elementRules: this.elementRules, + }); + let initialValue = session.getProperty(property); + + let editor = new InplaceEditor({ + element: element, + initial: initialValue, + contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, + property: { + name: property + }, + start: self => { + self.elt.parentNode.classList.add("boxmodel-editing"); + }, + change: value => { + if (NUMERIC.test(value)) { + value += "px"; + } + + let properties = [ + { name: property, value: value } + ]; + + if (property.substring(0, 7) == "border-") { + let bprop = property.substring(0, property.length - 5) + "style"; + let style = session.getProperty(bprop); + if (!style || style == "none" || style == "hidden") { + properties.push({ name: bprop, value: "solid" }); + } + } + + session.setProperties(properties).catch(e => console.error(e)); + }, + done: (value, commit) => { + editor.elt.parentNode.classList.remove("boxmodel-editing"); + if (!commit) { + session.revert().then(() => { + session.destroy(); + }, e => console.error(e)); + return; + } + + let node = this.inspector.selection.nodeFront; + this.inspector.pageStyle.getLayout(node, { + autoMargins: true, + }).then(layout => { + this.store.dispatch(updateLayout(layout)); + }, e => console.error(e)); + }, + contextMenu: this.inspector.onTextBoxContextMenu, + cssProperties: getCssProperties(this.inspector.toolbox) + }, event); + }, + + /** + * Shows the box-model highlighter on the currently selected element. + * + * @param {Object} options + * Options passed to the highlighter actor. + */ + onShowBoxModelHighlighter: (options = {}) => { + let toolbox = this.inspector.toolbox; + let nodeFront = this.inspector.selection.nodeFront; + + toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); + }, + /** * Handler for a change in the input checkboxes in the GridList component. * Toggles on/off the grid highlighter for the provided grid container element. @@ -217,9 +309,16 @@ LayoutView.prototype = { destroy() { this.highlighters.off("grid-highlighter-hidden", this.onHighlighterChange); this.highlighters.off("grid-highlighter-shown", this.onHighlighterChange); + this.inspector.selection.off("new-node-front", this.onNewSelection); this.inspector.sidebar.off("select", this.onSidebarSelect); this.layoutInspector.off("grid-layout-changed", this.onGridLayoutChange); + if (this.reflowFront) { + this.untrackReflows(); + this.reflowFront.destroy(); + this.reflowFront = null; + } + this.document = null; this.inspector = null; this.layoutInspector = null; @@ -273,6 +372,16 @@ LayoutView.prototype = { this.inspector.sidebar.getCurrentTabID() === "layoutview"; }, + /** + * Returns true if the layout panel is visible and the current node is valid to + * be displayed in the view. + */ + isPanelVisibleAndNodeValid() { + return this.isPanelVisible() && + this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode(); + }, + /** * Load the grid highligher display settings into the store from the stored preferences. */ @@ -286,6 +395,72 @@ LayoutView.prototype = { dispatch(updateShowInfiniteLines(showInfinteLines)); }, + /** + * Starts listening to reflows in the current tab. + */ + trackReflows() { + if (!this.reflowFront) { + let { target } = this.inspector; + if (target.form.reflowActor) { + this.reflowFront = ReflowFront(target.client, + target.form); + } else { + return; + } + } + + this.reflowFront.on("reflows", this.updateBoxModel); + this.reflowFront.start(); + }, + + /** + * Stops listening to reflows in the current tab. + */ + untrackReflows() { + if (!this.reflowFront) { + return; + } + + this.reflowFront.off("reflows", this.updateBoxModel); + this.reflowFront.stop(); + }, + + /** + * Updates the box model panel by dispatching the new layout data. + */ + updateBoxModel() { + let lastRequest = Task.spawn((function* () { + if (!(this.isPanelVisible() && + this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode())) { + return null; + } + + let node = this.inspector.selection.nodeFront; + let layout = yield this.inspector.pageStyle.getLayout(node, { + autoMargins: true, + }); + let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); + this.elementRules = styleEntries.map(e => e.rule); + + // Update the redux store with the latest layout properties and update the box + // model view. + this.store.dispatch(updateLayout(layout)); + + // If a subsequent request has been made, wait for that one instead. + if (this._lastRequest != lastRequest) { + return this._lastRequest; + } + + this._lastRequest = null; + + this.inspector.emit("boxmodel-view-updated"); + return null; + }).bind(this)).catch(console.error); + + this._lastRequest = lastRequest; + }, + /** * Updates the grid panel by dispatching the new grid data. This is called when the * layout view becomes visible or the view needs to be updated with new grid data. @@ -351,6 +526,17 @@ LayoutView.prototype = { this.store.dispatch(updateGridHighlighted(nodeFront, highlighted)); }, + /** + * Selection 'new-node-front' event handler. + */ + onNewSelection: function () { + if (!this.isPanelVisibleAndNodeValid()) { + return; + } + + this.updateBoxModel(); + }, + /** * Handler for the inspector sidebar select event. Starts listening for * "grid-layout-changed" if the layout panel is visible. Otherwise, stop @@ -360,10 +546,17 @@ LayoutView.prototype = { onSidebarSelect() { if (!this.isPanelVisible()) { this.layoutInspector.off("grid-layout-changed", this.onGridLayoutChange); + this.untrackReflows(); return; } + if (this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode()) { + this.trackReflows(); + } + this.layoutInspector.on("grid-layout-changed", this.onGridLayoutChange); + this.updateBoxModel(); this.updateGridPanel(); }, diff --git a/devtools/client/inspector/boxmodel/reducers/box-model.js b/devtools/client/inspector/layout/reducers/box-model.js similarity index 100% rename from devtools/client/inspector/boxmodel/reducers/box-model.js rename to devtools/client/inspector/layout/reducers/box-model.js diff --git a/devtools/client/inspector/layout/reducers/moz.build b/devtools/client/inspector/layout/reducers/moz.build index 34867f4e837f..50e631af17b1 100644 --- a/devtools/client/inspector/layout/reducers/moz.build +++ b/devtools/client/inspector/layout/reducers/moz.build @@ -5,6 +5,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( + 'box-model.js', 'grids.js', 'highlighter-settings.js', ) diff --git a/devtools/client/inspector/layout/types.js b/devtools/client/inspector/layout/types.js index 0c0cd3b77473..b9c286200ca0 100644 --- a/devtools/client/inspector/layout/types.js +++ b/devtools/client/inspector/layout/types.js @@ -6,6 +6,16 @@ const { PropTypes } = require("devtools/client/shared/vendor/react"); +/** + * The box model data for the current selected node. + */ +exports.boxModel = { + + // The layout information of the current selected node + layout: PropTypes.object, + +}; + /** * A single grid container in the document. */ diff --git a/devtools/client/inspector/boxmodel/utils/editing-session.js b/devtools/client/inspector/layout/utils/editing-session.js similarity index 100% rename from devtools/client/inspector/boxmodel/utils/editing-session.js rename to devtools/client/inspector/layout/utils/editing-session.js diff --git a/devtools/client/inspector/layout/utils/moz.build b/devtools/client/inspector/layout/utils/moz.build index e3053b63fab6..537f779cc3cb 100644 --- a/devtools/client/inspector/layout/utils/moz.build +++ b/devtools/client/inspector/layout/utils/moz.build @@ -5,5 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( + 'editing-session.js', 'l10n.js', ) diff --git a/devtools/client/inspector/moz.build b/devtools/client/inspector/moz.build index 8f1679fd2b39..1c5f3e58dd4c 100644 --- a/devtools/client/inspector/moz.build +++ b/devtools/client/inspector/moz.build @@ -3,7 +3,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += [ - 'boxmodel', 'components', 'computed', 'fonts', diff --git a/devtools/client/inspector/reducers.js b/devtools/client/inspector/reducers.js index a6818664560e..6c09e49c49e4 100644 --- a/devtools/client/inspector/reducers.js +++ b/devtools/client/inspector/reducers.js @@ -7,6 +7,6 @@ // This file exposes the Redux reducers of the box model, grid and grid highlighter // settings. -exports.boxModel = require("devtools/client/inspector/boxmodel/reducers/box-model"); +exports.boxModel = require("devtools/client/inspector/layout/reducers/box-model"); exports.grids = require("devtools/client/inspector/layout/reducers/grids"); exports.highlighterSettings = require("devtools/client/inspector/layout/reducers/highlighter-settings"); diff --git a/devtools/client/inspector/test/browser_inspector_textbox-menu.js b/devtools/client/inspector/test/browser_inspector_textbox-menu.js index b3e9ca68515c..a5e0e75622d8 100644 --- a/devtools/client/inspector/test/browser_inspector_textbox-menu.js +++ b/devtools/client/inspector/test/browser_inspector_textbox-menu.js @@ -66,7 +66,7 @@ add_task(function* () { info("Testing the box-model region"); let margin = inspector.panelDoc.querySelector( - ".boxmodel-margin.boxmodel-top > span"); + ".old-boxmodel-margin.old-boxmodel-top > span"); EventUtils.synthesizeMouseAtCenter(margin, {}, inspector.panelWin); yield checkTextBox(inspector.panelDoc.activeElement, toolbox); }); diff --git a/devtools/client/inspector/test/shared-head.js b/devtools/client/inspector/test/shared-head.js index c42690a2813e..a953d547e7f5 100644 --- a/devtools/client/inspector/test/shared-head.js +++ b/devtools/client/inspector/test/shared-head.js @@ -52,15 +52,7 @@ var openInspectorSidebarTab = Task.async(function* (id) { let {toolbox, inspector, testActor} = yield openInspector(); info("Selecting the " + id + " sidebar"); - - if (id === "computedview" || id === "layoutview") { - // The layout and computed views should wait until the box-model widget is ready. - let onBoxModelViewReady = inspector.once("boxmodel-view-updated"); - inspector.sidebar.select(id); - yield onBoxModelViewReady; - } else { - inspector.sidebar.select(id); - } + inspector.sidebar.select(id); return { toolbox, diff --git a/devtools/client/jar.mn b/devtools/client/jar.mn index b68d20740c14..628a336e45c0 100644 --- a/devtools/client/jar.mn +++ b/devtools/client/jar.mn @@ -177,6 +177,7 @@ devtools.jar: skin/images/noise.png (themes/images/noise.png) skin/images/dropmarker.svg (themes/images/dropmarker.svg) skin/boxmodel.css (themes/boxmodel.css) + skin/deprecated-boxmodel.css (themes/deprecated-boxmodel.css) skin/images/geometry-editor.svg (themes/images/geometry-editor.svg) skin/images/pause.svg (themes/images/pause.svg) skin/images/play.svg (themes/images/play.svg) diff --git a/devtools/client/shared/browser-loader.js b/devtools/client/shared/browser-loader.js index 3aef74a99bf9..ab7505beee9b 100644 --- a/devtools/client/shared/browser-loader.js +++ b/devtools/client/shared/browser-loader.js @@ -12,8 +12,6 @@ const Services = devtools.require("Services"); const { AppConstants } = devtools.require("resource://gre/modules/AppConstants.jsm"); const BROWSER_BASED_DIRS = [ - "resource://devtools/client/inspector/boxmodel", - "resource://devtools/client/inspector/computed", "resource://devtools/client/inspector/layout", "resource://devtools/client/jsonview", "resource://devtools/client/shared/vendor", diff --git a/devtools/client/themes/deprecated-boxmodel.css b/devtools/client/themes/deprecated-boxmodel.css new file mode 100644 index 000000000000..e1f6d1432e20 --- /dev/null +++ b/devtools/client/themes/deprecated-boxmodel.css @@ -0,0 +1,259 @@ +/* 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 STYLESHEET IS FOR THE DEPRECATED BOX MODEL MODULE (deprecated-box-model.js) AND + * SHOULD NO LONGER BE MODIFIED. + */ + +#old-boxmodel-wrapper { + border-bottom-style: solid; + border-bottom-width: 1px; + border-color: var(--theme-splitter-color); + -moz-user-select: none; +} + +#old-boxmodel-container { + /* The view will grow bigger as the window gets resized, until 400px */ + max-width: 400px; + margin: 0px auto; + padding: 0; +} + +/* Header */ + +#old-boxmodel-header, +#old-boxmodel-info { + display: flex; + align-items: center; + padding: 4px 17px; +} + +#old-layout-geometry-editor { + visibility: hidden; +} + +#old-layout-geometry-editor::before { + background: url(images/geometry-editor.svg) no-repeat center center / 16px 16px; +} + +/* Main: contains the box-model regions */ + +#old-boxmodel-main { + position: relative; + box-sizing: border-box; + /* The regions are semi-transparent, so the white background is partly + visible */ + background-color: white; + color: var(--theme-selection-color); + /* Make sure there is some space between the window's edges and the regions */ + margin: 0 14px 4px 14px; + width: calc(100% - 2 * 14px); +} + +.old-boxmodel-margin, +.old-boxmodel-size { + color: var(--theme-highlight-blue); +} + +/* Regions are 3 nested elements with wide borders and outlines */ + +#old-boxmodel-content { + height: 18px; +} + +#old-boxmodel-margins, +#old-boxmodel-borders, +#old-boxmodel-padding { + border-color: hsla(210,100%,85%,0.2); + border-width: 18px; + border-style: solid; + outline: dotted 1px hsl(210,100%,85%); +} + +#old-boxmodel-margins { + /* This opacity applies to all of the regions, since they are nested */ + opacity: .8; +} + +/* Regions colors */ + +#old-boxmodel-margins { + border-color: #edff64; +} + +#old-boxmodel-borders { + border-color: #444444; +} + +#old-boxmodel-padding { + border-color: #6a5acd; +} + +#old-boxmodel-content { + background-color: #87ceeb; +} + +.theme-firebug #old-boxmodel-main, +.theme-firebug #old-boxmodel-borders, +.theme-firebug #old-boxmodel-content { + border-style: solid; +} + +.theme-firebug #old-boxmodel-main, +.theme-firebug #old-boxmodel-header { + font-family: var(--proportional-font-family); +} + +.theme-firebug #old-boxmodel-main { + color: var(--theme-body-color); + font-size: var(--theme-toolbar-font-size); +} + +.theme-firebug #old-boxmodel-header { + font-size: var(--theme-toolbar-font-size); +} + +/* Editable region sizes are contained in absolutely positioned

*/ + +#old-boxmodel-main > p { + position: absolute; + pointer-events: none; + margin: 0; + text-align: center; +} + +#old-boxmodel-main > p > span, +#old-boxmodel-main > p > input { + vertical-align: middle; + pointer-events: auto; +} + +/* Coordinates for the region sizes */ + +.old-boxmodel-top, +.old-boxmodel-bottom { + width: calc(100% - 2px); + text-align: center; +} + +.old-boxmodel-padding.old-boxmodel-top { + top: 37px; +} + +.old-boxmodel-padding.old-boxmodel-bottom { + bottom: 38px; +} + +.old-boxmodel-border.old-boxmodel-top { + top: 19px; +} + +.old-boxmodel-border.old-boxmodel-bottom { + bottom: 20px; +} + +.old-boxmodel-margin.old-boxmodel-top { + top: 1px; +} + +.old-boxmodel-margin.old-boxmodel-bottom { + bottom: 2px; +} + +.old-boxmodel-size, +.old-boxmodel-margin.old-boxmodel-left, +.old-boxmodel-margin.old-boxmodel-right, +.old-boxmodel-border.old-boxmodel-left, +.old-boxmodel-border.old-boxmodel-right, +.old-boxmodel-padding.old-boxmodel-left, +.old-boxmodel-padding.old-boxmodel-right { + top: 22px; + line-height: 80px; +} + +.old-boxmodel-size { + width: calc(100% - 2px); +} + +.old-boxmodel-margin.old-boxmodel-right, +.old-boxmodel-margin.old-boxmodel-left, +.old-boxmodel-border.old-boxmodel-left, +.old-boxmodel-border.old-boxmodel-right, +.old-boxmodel-padding.old-boxmodel-right, +.old-boxmodel-padding.old-boxmodel-left { + width: 21px; +} + +.old-boxmodel-padding.old-boxmodel-left { + left: 35px; +} + +.old-boxmodel-padding.old-boxmodel-right { + right: 35px; +} + +.old-boxmodel-border.old-boxmodel-left { + left: 16px; +} + +.old-boxmodel-border.old-boxmodel-right { + right: 17px; +} + +.old-boxmodel-margin.old-boxmodel-right { + right: 0; +} + +.old-boxmodel-margin.old-boxmodel-left { + left: 0; +} + +.old-boxmodel-rotate.old-boxmodel-left:not(.old-boxmodel-editing) { + transform: rotate(-90deg); +} + +.old-boxmodel-rotate.old-boxmodel-right:not(.old-boxmodel-editing) { + transform: rotate(90deg); +} + +/* Legend: displayed inside regions */ + +.old-boxmodel-legend { + position: absolute; + margin: 2px 6px; + z-index: 1; +} + +.old-boxmodel-legend[data-box="margin"] { + color: var(--theme-highlight-blue); +} + +/* Editable fields */ + +.old-boxmodel-editable { + border: 1px dashed transparent; + -moz-user-select: none; +} + +.old-boxmodel-editable:hover { + border-bottom-color: hsl(0, 0%, 50%); +} + +/* Make sure the content size doesn't appear as editable like the other sizes */ + +.old-boxmodel-size > span { + cursor: default; +} + +/* Box Model Info: contains the position and size of the element */ + +#old-boxmodel-element-size { + flex: 1; +} + +#old-boxmodel-position-group { + display: flex; + align-items: center; +} From 034cb6569f6b9883bfdbc76cd28270a858f37232 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:37:30 -0500 Subject: [PATCH 091/102] Bug 1336198 - Part 2: Remove deprecated boxmodel stylesheet. r=jdescottes --- devtools/client/inspector/inspector.xhtml | 1 - devtools/client/jar.mn | 1 - .../client/themes/deprecated-boxmodel.css | 259 ------------------ 3 files changed, 261 deletions(-) delete mode 100644 devtools/client/themes/deprecated-boxmodel.css diff --git a/devtools/client/inspector/inspector.xhtml b/devtools/client/inspector/inspector.xhtml index d3e13fb7b781..b2e084d9fd74 100644 --- a/devtools/client/inspector/inspector.xhtml +++ b/devtools/client/inspector/inspector.xhtml @@ -14,7 +14,6 @@ - diff --git a/devtools/client/jar.mn b/devtools/client/jar.mn index 628a336e45c0..b68d20740c14 100644 --- a/devtools/client/jar.mn +++ b/devtools/client/jar.mn @@ -177,7 +177,6 @@ devtools.jar: skin/images/noise.png (themes/images/noise.png) skin/images/dropmarker.svg (themes/images/dropmarker.svg) skin/boxmodel.css (themes/boxmodel.css) - skin/deprecated-boxmodel.css (themes/deprecated-boxmodel.css) skin/images/geometry-editor.svg (themes/images/geometry-editor.svg) skin/images/pause.svg (themes/images/pause.svg) skin/images/play.svg (themes/images/play.svg) diff --git a/devtools/client/themes/deprecated-boxmodel.css b/devtools/client/themes/deprecated-boxmodel.css deleted file mode 100644 index e1f6d1432e20..000000000000 --- a/devtools/client/themes/deprecated-boxmodel.css +++ /dev/null @@ -1,259 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/ */ - -/** - * THIS STYLESHEET IS FOR THE DEPRECATED BOX MODEL MODULE (deprecated-box-model.js) AND - * SHOULD NO LONGER BE MODIFIED. - */ - -#old-boxmodel-wrapper { - border-bottom-style: solid; - border-bottom-width: 1px; - border-color: var(--theme-splitter-color); - -moz-user-select: none; -} - -#old-boxmodel-container { - /* The view will grow bigger as the window gets resized, until 400px */ - max-width: 400px; - margin: 0px auto; - padding: 0; -} - -/* Header */ - -#old-boxmodel-header, -#old-boxmodel-info { - display: flex; - align-items: center; - padding: 4px 17px; -} - -#old-layout-geometry-editor { - visibility: hidden; -} - -#old-layout-geometry-editor::before { - background: url(images/geometry-editor.svg) no-repeat center center / 16px 16px; -} - -/* Main: contains the box-model regions */ - -#old-boxmodel-main { - position: relative; - box-sizing: border-box; - /* The regions are semi-transparent, so the white background is partly - visible */ - background-color: white; - color: var(--theme-selection-color); - /* Make sure there is some space between the window's edges and the regions */ - margin: 0 14px 4px 14px; - width: calc(100% - 2 * 14px); -} - -.old-boxmodel-margin, -.old-boxmodel-size { - color: var(--theme-highlight-blue); -} - -/* Regions are 3 nested elements with wide borders and outlines */ - -#old-boxmodel-content { - height: 18px; -} - -#old-boxmodel-margins, -#old-boxmodel-borders, -#old-boxmodel-padding { - border-color: hsla(210,100%,85%,0.2); - border-width: 18px; - border-style: solid; - outline: dotted 1px hsl(210,100%,85%); -} - -#old-boxmodel-margins { - /* This opacity applies to all of the regions, since they are nested */ - opacity: .8; -} - -/* Regions colors */ - -#old-boxmodel-margins { - border-color: #edff64; -} - -#old-boxmodel-borders { - border-color: #444444; -} - -#old-boxmodel-padding { - border-color: #6a5acd; -} - -#old-boxmodel-content { - background-color: #87ceeb; -} - -.theme-firebug #old-boxmodel-main, -.theme-firebug #old-boxmodel-borders, -.theme-firebug #old-boxmodel-content { - border-style: solid; -} - -.theme-firebug #old-boxmodel-main, -.theme-firebug #old-boxmodel-header { - font-family: var(--proportional-font-family); -} - -.theme-firebug #old-boxmodel-main { - color: var(--theme-body-color); - font-size: var(--theme-toolbar-font-size); -} - -.theme-firebug #old-boxmodel-header { - font-size: var(--theme-toolbar-font-size); -} - -/* Editable region sizes are contained in absolutely positioned

*/ - -#old-boxmodel-main > p { - position: absolute; - pointer-events: none; - margin: 0; - text-align: center; -} - -#old-boxmodel-main > p > span, -#old-boxmodel-main > p > input { - vertical-align: middle; - pointer-events: auto; -} - -/* Coordinates for the region sizes */ - -.old-boxmodel-top, -.old-boxmodel-bottom { - width: calc(100% - 2px); - text-align: center; -} - -.old-boxmodel-padding.old-boxmodel-top { - top: 37px; -} - -.old-boxmodel-padding.old-boxmodel-bottom { - bottom: 38px; -} - -.old-boxmodel-border.old-boxmodel-top { - top: 19px; -} - -.old-boxmodel-border.old-boxmodel-bottom { - bottom: 20px; -} - -.old-boxmodel-margin.old-boxmodel-top { - top: 1px; -} - -.old-boxmodel-margin.old-boxmodel-bottom { - bottom: 2px; -} - -.old-boxmodel-size, -.old-boxmodel-margin.old-boxmodel-left, -.old-boxmodel-margin.old-boxmodel-right, -.old-boxmodel-border.old-boxmodel-left, -.old-boxmodel-border.old-boxmodel-right, -.old-boxmodel-padding.old-boxmodel-left, -.old-boxmodel-padding.old-boxmodel-right { - top: 22px; - line-height: 80px; -} - -.old-boxmodel-size { - width: calc(100% - 2px); -} - -.old-boxmodel-margin.old-boxmodel-right, -.old-boxmodel-margin.old-boxmodel-left, -.old-boxmodel-border.old-boxmodel-left, -.old-boxmodel-border.old-boxmodel-right, -.old-boxmodel-padding.old-boxmodel-right, -.old-boxmodel-padding.old-boxmodel-left { - width: 21px; -} - -.old-boxmodel-padding.old-boxmodel-left { - left: 35px; -} - -.old-boxmodel-padding.old-boxmodel-right { - right: 35px; -} - -.old-boxmodel-border.old-boxmodel-left { - left: 16px; -} - -.old-boxmodel-border.old-boxmodel-right { - right: 17px; -} - -.old-boxmodel-margin.old-boxmodel-right { - right: 0; -} - -.old-boxmodel-margin.old-boxmodel-left { - left: 0; -} - -.old-boxmodel-rotate.old-boxmodel-left:not(.old-boxmodel-editing) { - transform: rotate(-90deg); -} - -.old-boxmodel-rotate.old-boxmodel-right:not(.old-boxmodel-editing) { - transform: rotate(90deg); -} - -/* Legend: displayed inside regions */ - -.old-boxmodel-legend { - position: absolute; - margin: 2px 6px; - z-index: 1; -} - -.old-boxmodel-legend[data-box="margin"] { - color: var(--theme-highlight-blue); -} - -/* Editable fields */ - -.old-boxmodel-editable { - border: 1px dashed transparent; - -moz-user-select: none; -} - -.old-boxmodel-editable:hover { - border-bottom-color: hsl(0, 0%, 50%); -} - -/* Make sure the content size doesn't appear as editable like the other sizes */ - -.old-boxmodel-size > span { - cursor: default; -} - -/* Box Model Info: contains the position and size of the element */ - -#old-boxmodel-element-size { - flex: 1; -} - -#old-boxmodel-position-group { - display: flex; - align-items: center; -} From 742aa7ccc39bb998243303a46c87d4409f8c047b Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:37:34 -0500 Subject: [PATCH 092/102] Bug 1336198 - Part 3: Remove the deprecated box model source file. r=jdescottes --- .../components/deprecated-box-model.js | 912 ------------------ .../client/inspector/components/moz.build | 1 - 2 files changed, 913 deletions(-) delete mode 100644 devtools/client/inspector/components/deprecated-box-model.js diff --git a/devtools/client/inspector/components/deprecated-box-model.js b/devtools/client/inspector/components/deprecated-box-model.js deleted file mode 100644 index 874a79939c97..000000000000 --- a/devtools/client/inspector/components/deprecated-box-model.js +++ /dev/null @@ -1,912 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ -/* 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 MODULE IS DEPRECATED. - * - * To continue any work related to the box model view, see the new react/redux - * implementation in devtools/client/inspector/layout/. - */ - -"use strict"; - -const {Task} = require("devtools/shared/task"); -const {InplaceEditor, editableItem} = - require("devtools/client/shared/inplace-editor"); -const {ReflowFront} = require("devtools/shared/fronts/reflow"); -const {LocalizationHelper} = require("devtools/shared/l10n"); -const {getCssProperties} = require("devtools/shared/fronts/css-properties"); -const {KeyCodes} = require("devtools/client/shared/keycodes"); -const EditingSession = require("devtools/client/inspector/layout/utils/editing-session"); - -const STRINGS_URI = "devtools/client/locales/shared.properties"; -const STRINGS_INSPECTOR = "devtools/shared/locales/styleinspector.properties"; -const SHARED_L10N = new LocalizationHelper(STRINGS_URI); -const INSPECTOR_L10N = new LocalizationHelper(STRINGS_INSPECTOR); -const NUMERIC = /^-?[\d\.]+$/; -const LONG_TEXT_ROTATE_LIMIT = 3; - -/** - * The box model view - * @param {InspectorPanel} inspector - * An instance of the inspector-panel currently loaded in the toolbox - * @param {Document} document - * The document that will contain the box model view. - */ -function BoxModelView(inspector, document) { - this.inspector = inspector; - this.doc = document; - this.wrapper = this.doc.getElementById("old-boxmodel-wrapper"); - this.container = this.doc.getElementById("old-boxmodel-container"); - this.expander = this.doc.getElementById("old-boxmodel-expander"); - this.sizeLabel = this.doc.querySelector(".old-boxmodel-size > span"); - this.sizeHeadingLabel = this.doc.getElementById("old-boxmodel-element-size"); - this._geometryEditorHighlighter = null; - this._cssProperties = getCssProperties(inspector.toolbox); - - this.init(); -} - -BoxModelView.prototype = { - init: function () { - this.update = this.update.bind(this); - - this.onNewSelection = this.onNewSelection.bind(this); - this.inspector.selection.on("new-node-front", this.onNewSelection); - - this.onNewNode = this.onNewNode.bind(this); - this.inspector.sidebar.on("computedview-selected", this.onNewNode); - - this.onSidebarSelect = this.onSidebarSelect.bind(this); - this.inspector.sidebar.on("select", this.onSidebarSelect); - - this.onToggleExpander = this.onToggleExpander.bind(this); - this.expander.addEventListener("click", this.onToggleExpander); - let header = this.doc.getElementById("old-boxmodel-header"); - header.addEventListener("dblclick", this.onToggleExpander); - - this.onFilterComputedView = this.onFilterComputedView.bind(this); - this.inspector.on("computed-view-filtered", - this.onFilterComputedView); - - this.onPickerStarted = this.onPickerStarted.bind(this); - this.onMarkupViewLeave = this.onMarkupViewLeave.bind(this); - this.onMarkupViewNodeHover = this.onMarkupViewNodeHover.bind(this); - this.onWillNavigate = this.onWillNavigate.bind(this); - this.onKeyDown = this.onKeyDown.bind(this); - this.onLevelClick = this.onLevelClick.bind(this); - this.setAriaActive = this.setAriaActive.bind(this); - this.getEditBoxes = this.getEditBoxes.bind(this); - this.makeFocusable = this.makeFocusable.bind(this); - this.makeUnfocasable = this.makeUnfocasable.bind(this); - this.moveFocus = this.moveFocus.bind(this); - this.onFocus = this.onFocus.bind(this); - - this.borderLayout = this.doc.getElementById("old-boxmodel-borders"); - this.boxModel = this.doc.getElementById("old-boxmodel-wrapper"); - this.marginLayout = this.doc.getElementById("old-boxmodel-margins"); - this.paddingLayout = this.doc.getElementById("old-boxmodel-padding"); - - this.layouts = { - "margin": new Map([ - [KeyCodes.DOM_VK_ESCAPE, this.marginLayout], - [KeyCodes.DOM_VK_DOWN, this.borderLayout], - [KeyCodes.DOM_VK_UP, null], - ["click", this.marginLayout] - ]), - "border": new Map([ - [KeyCodes.DOM_VK_ESCAPE, this.borderLayout], - [KeyCodes.DOM_VK_DOWN, this.paddingLayout], - [KeyCodes.DOM_VK_UP, this.marginLayout], - ["click", this.borderLayout] - ]), - "padding": new Map([ - [KeyCodes.DOM_VK_ESCAPE, this.paddingLayout], - [KeyCodes.DOM_VK_DOWN, null], - [KeyCodes.DOM_VK_UP, this.borderLayout], - ["click", this.paddingLayout] - ]) - }; - - this.boxModel.addEventListener("click", this.onLevelClick, true); - this.boxModel.addEventListener("focus", this.onFocus, true); - this.boxModel.addEventListener("keydown", this.onKeyDown, true); - - this.initBoxModelHighlighter(); - - // Store for the different dimensions of the node. - // 'selector' refers to the element that holds the value; - // 'property' is what we are measuring; - // 'value' is the computed dimension, computed in update(). - this.map = { - position: { - selector: "#old-boxmodel-element-position", - property: "position", - value: undefined - }, - marginTop: { - selector: ".old-boxmodel-margin.old-boxmodel-top > span", - property: "margin-top", - value: undefined - }, - marginBottom: { - selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", - property: "margin-bottom", - value: undefined - }, - marginLeft: { - selector: ".old-boxmodel-margin.old-boxmodel-left > span", - property: "margin-left", - value: undefined - }, - marginRight: { - selector: ".old-boxmodel-margin.old-boxmodel-right > span", - property: "margin-right", - value: undefined - }, - paddingTop: { - selector: ".old-boxmodel-padding.old-boxmodel-top > span", - property: "padding-top", - value: undefined - }, - paddingBottom: { - selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", - property: "padding-bottom", - value: undefined - }, - paddingLeft: { - selector: ".old-boxmodel-padding.old-boxmodel-left > span", - property: "padding-left", - value: undefined - }, - paddingRight: { - selector: ".old-boxmodel-padding.old-boxmodel-right > span", - property: "padding-right", - value: undefined - }, - borderTop: { - selector: ".old-boxmodel-border.old-boxmodel-top > span", - property: "border-top-width", - value: undefined - }, - borderBottom: { - selector: ".old-boxmodel-border.old-boxmodel-bottom > span", - property: "border-bottom-width", - value: undefined - }, - borderLeft: { - selector: ".old-boxmodel-border.old-boxmodel-left > span", - property: "border-left-width", - value: undefined - }, - borderRight: { - selector: ".old-boxmodel-border.old-boxmodel-right > span", - property: "border-right-width", - value: undefined - } - }; - - // Make each element the dimensions editable - for (let i in this.map) { - if (i == "position") { - continue; - } - - let dimension = this.map[i]; - editableItem({ - element: this.doc.querySelector(dimension.selector) - }, (element, event) => { - this.initEditor(element, event, dimension); - }); - } - - this.onNewNode(); - - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - this.onGeometryButtonClick = this.onGeometryButtonClick.bind(this); - nodeGeometry.addEventListener("click", this.onGeometryButtonClick); - }, - - initBoxModelHighlighter: function () { - let highlightElts = this.doc.querySelectorAll("#old-boxmodel-container *[title]"); - this.onHighlightMouseOver = this.onHighlightMouseOver.bind(this); - this.onHighlightMouseOut = this.onHighlightMouseOut.bind(this); - - for (let element of highlightElts) { - element.addEventListener("mouseover", this.onHighlightMouseOver, true); - element.addEventListener("mouseout", this.onHighlightMouseOut, true); - } - }, - - /** - * Start listening to reflows in the current tab. - */ - trackReflows: function () { - if (!this.reflowFront) { - let { target } = this.inspector; - if (target.form.reflowActor) { - this.reflowFront = ReflowFront(target.client, - target.form); - } else { - return; - } - } - - this.reflowFront.on("reflows", this.update); - this.reflowFront.start(); - }, - - /** - * Stop listening to reflows in the current tab. - */ - untrackReflows: function () { - if (!this.reflowFront) { - return; - } - - this.reflowFront.off("reflows", this.update); - this.reflowFront.stop(); - }, - - /** - * Called when the user clicks on one of the editable values in the box model view - */ - initEditor: function (element, event, dimension) { - let { property } = dimension; - let session = new EditingSession(this); - let initialValue = session.getProperty(property); - - let editor = new InplaceEditor({ - element: element, - initial: initialValue, - contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, - property: { - name: dimension.property - }, - start: self => { - self.elt.parentNode.classList.add("old-boxmodel-editing"); - }, - change: value => { - if (NUMERIC.test(value)) { - value += "px"; - } - - let properties = [ - { name: property, value: value } - ]; - - if (property.substring(0, 7) == "border-") { - let bprop = property.substring(0, property.length - 5) + "style"; - let style = session.getProperty(bprop); - if (!style || style == "none" || style == "hidden") { - properties.push({ name: bprop, value: "solid" }); - } - } - - session.setProperties(properties).catch(e => console.error(e)); - }, - done: (value, commit) => { - editor.elt.parentNode.classList.remove("old-boxmodel-editing"); - if (!commit) { - session.revert().then(() => { - session.destroy(); - }, e => console.error(e)); - } - }, - contextMenu: this.inspector.onTextBoxContextMenu, - cssProperties: this._cssProperties - }, event); - }, - - /** - * Is the BoxModelView visible in the sidebar. - * @return {Boolean} - */ - isViewVisible: function () { - return this.inspector && - this.inspector.sidebar.getCurrentTabID() == "computedview"; - }, - - /** - * Is the BoxModelView visible in the sidebar and is the current node valid to - * be displayed in the view. - * @return {Boolean} - */ - isViewVisibleAndNodeValid: function () { - return this.isViewVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode(); - }, - - /** - * Destroy the nodes. Remove listeners. - */ - destroy: function () { - let highlightElts = this.doc.querySelectorAll("#old-boxmodel-container *[title]"); - - for (let element of highlightElts) { - element.removeEventListener("mouseover", this.onHighlightMouseOver, true); - element.removeEventListener("mouseout", this.onHighlightMouseOut, true); - } - - this.expander.removeEventListener("click", this.onToggleExpander); - let header = this.doc.getElementById("old-boxmodel-header"); - header.removeEventListener("dblclick", this.onToggleExpander); - - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - nodeGeometry.removeEventListener("click", this.onGeometryButtonClick); - - this.boxModel.removeEventListener("click", this.onLevelClick, true); - this.boxModel.removeEventListener("focus", this.onFocus, true); - this.boxModel.removeEventListener("keydown", this.onKeyDown, true); - - this.inspector.off("picker-started", this.onPickerStarted); - - // Inspector Panel will destroy `markup` object on "will-navigate" event, - // therefore we have to check if it's still available in case BoxModelView - // is destroyed immediately after. - if (this.inspector.markup) { - this.inspector.markup.off("leave", this.onMarkupViewLeave); - this.inspector.markup.off("node-hover", this.onMarkupViewNodeHover); - } - - this.inspector.sidebar.off("computedview-selected", this.onNewNode); - this.inspector.selection.off("new-node-front", this.onNewSelection); - this.inspector.sidebar.off("select", this.onSidebarSelect); - this.inspector.target.off("will-navigate", this.onWillNavigate); - this.inspector.off("computed-view-filtered", this.onFilterComputedView); - - this.inspector = null; - this.doc = null; - this.wrapper = null; - this.container = null; - this.expander = null; - this.sizeLabel = null; - this.sizeHeadingLabel = null; - - this.marginLayout = null; - this.borderLayout = null; - this.paddingLayout = null; - this.boxModel = null; - this.layouts = null; - - if (this.reflowFront) { - this.untrackReflows(); - this.reflowFront.destroy(); - this.reflowFront = null; - } - }, - - /** - * Set initial box model focus to the margin layout. - */ - onFocus: function () { - let activeDescendant = this.boxModel.getAttribute("aria-activedescendant"); - - if (!activeDescendant) { - let nextLayout = this.marginLayout; - this.setAriaActive(nextLayout); - } - }, - - /** - * Active aria-level set to current layout. - * - * @param {Element} nextLayout - * Element of next layout that user has navigated to - * @param {Node} target - * Node to be observed - */ - setAriaActive: function (nextLayout, target) { - this.boxModel.setAttribute("aria-activedescendant", nextLayout.id); - if (target && target._editable) { - target.blur(); - } - - // Clear all - this.marginLayout.classList.remove("layout-active-elm"); - this.borderLayout.classList.remove("layout-active-elm"); - this.paddingLayout.classList.remove("layout-active-elm"); - - // Set the next level's border outline - nextLayout.classList.add("layout-active-elm"); - }, - - /** - * Update aria-active on mouse click. - * - * @param {Event} event - * The event triggered by a mouse click on the box model - */ - onLevelClick: function (event) { - let {target} = event; - let nextLayout = this.layouts[target.getAttribute("data-box")].get("click"); - - this.setAriaActive(nextLayout, target); - }, - - /** - * Handle keyboard navigation and focus for box model layouts. - * - * Updates active layout on arrow key navigation - * Focuses next layout's editboxes on enter key - * Unfocuses current layout's editboxes when active layout changes - * Controls tabbing between editBoxes - * - * @param {Event} event - * The event triggered by a keypress on the box model - */ - onKeyDown: function (event) { - let {target, keyCode} = event; - // If focused on editable value or in editing mode - let isEditable = target._editable || target.editor; - let level = this.boxModel.getAttribute("aria-activedescendant"); - let editingMode = target.tagName === "input"; - let nextLayout; - - switch (keyCode) { - case KeyCodes.DOM_VK_RETURN: - if (!isEditable) { - this.makeFocusable(level); - } - break; - case KeyCodes.DOM_VK_DOWN: - case KeyCodes.DOM_VK_UP: - if (!editingMode) { - event.preventDefault(); - this.makeUnfocasable(level); - let datalevel = this.doc.getElementById(level).getAttribute("data-box"); - nextLayout = this.layouts[datalevel].get(keyCode); - this.boxModel.focus(); - } - break; - case KeyCodes.DOM_VK_TAB: - if (isEditable) { - event.preventDefault(); - this.moveFocus(event, level); - } - break; - case KeyCodes.DOM_VK_ESCAPE: - if (isEditable && target._editable) { - event.preventDefault(); - event.stopPropagation(); - this.makeUnfocasable(level); - this.boxModel.focus(); - } - break; - default: - break; - } - - if (nextLayout) { - this.setAriaActive(nextLayout, target); - } - }, - - /** - * Make previous layout's elements unfocusable. - * - * @param {String} editLevel - * The previous layout - */ - makeUnfocasable: function (editLevel) { - let editBoxes = this.getEditBoxes(editLevel); - editBoxes.forEach(editBox => editBox.setAttribute("tabindex", "-1")); - }, - - /** - * Make current layout's elements focusable. - * - * @param {String} editLevel - * The current layout - */ - makeFocusable: function (editLevel) { - let editBoxes = this.getEditBoxes(editLevel); - editBoxes.forEach(editBox => editBox.setAttribute("tabindex", "0")); - editBoxes[0].focus(); - }, - - /** - * Keyboard navigation of edit boxes wraps around on edge - * elements ([layout]-top, [layout]-left). - * - * @param {Node} target - * Node to be observed - * @param {Boolean} shiftKey - * Determines if shiftKey was pressed - * @param {String} level - * Current active layout - */ - moveFocus: function ({target, shiftKey}, level) { - let editBoxes = this.getEditBoxes(level); - let editingMode = target.tagName === "input"; - // target.nextSibling is input field - let position = editingMode ? editBoxes.indexOf(target.nextSibling) - : editBoxes.indexOf(target); - - if (position === editBoxes.length - 1 && !shiftKey) { - position = 0; - } else if (position === 0 && shiftKey) { - position = editBoxes.length - 1; - } else { - shiftKey ? position-- : position++; - } - - let editBox = editBoxes[position]; - editBox.focus(); - - if (editingMode) { - editBox.click(); - } - }, - - /** - * Retrieve edit boxes for current layout. - * - * @param {String} editLevel - * Current active layout - * @return Layout's edit boxes - */ - getEditBoxes: function (editLevel) { - let dataLevel = this.doc.getElementById(editLevel).getAttribute("data-box"); - return [...this.doc.querySelectorAll( - `[data-box="${dataLevel}"].old-boxmodel-editable`)]; - }, - - onSidebarSelect: function (e, sidebar) { - this.setActive(sidebar === "computedview"); - }, - - /** - * Selection 'new-node-front' event handler. - */ - onNewSelection: function () { - let done = this.inspector.updating("computed-view"); - this.onNewNode() - .then(() => this.hideGeometryEditor()) - .then(done, (err) => { - console.error(err); - done(); - }).catch(console.error); - }, - - /** - * @return a promise that resolves when the view has been updated - */ - onNewNode: function () { - this.setActive(this.isViewVisibleAndNodeValid()); - return this.update(); - }, - - onHighlightMouseOver: function (e) { - let region = e.target.getAttribute("data-box"); - if (!region) { - return; - } - - this.showBoxModel({ - region, - showOnly: region, - onlyRegionArea: true - }); - }, - - onHighlightMouseOut: function () { - this.hideBoxModel(); - }, - - onGeometryButtonClick: function ({target}) { - if (target.hasAttribute("checked")) { - target.removeAttribute("checked"); - this.hideGeometryEditor(); - } else { - target.setAttribute("checked", "true"); - this.showGeometryEditor(); - } - }, - - onPickerStarted: function () { - this.hideGeometryEditor(); - }, - - onToggleExpander: function () { - let isOpen = this.expander.hasAttribute("open"); - - if (isOpen) { - this.container.hidden = true; - this.expander.removeAttribute("open"); - } else { - this.container.hidden = false; - this.expander.setAttribute("open", ""); - } - }, - - onMarkupViewLeave: function () { - this.showGeometryEditor(true); - }, - - onMarkupViewNodeHover: function () { - this.hideGeometryEditor(false); - }, - - onWillNavigate: function () { - this._geometryEditorHighlighter.release().catch(console.error); - this._geometryEditorHighlighter = null; - }, - - /** - * Event handler that responds to the computed view being filtered - * @param {String} reason - * @param {Boolean} hidden - * Whether or not to hide the box model wrapper - */ - onFilterComputedView: function (reason, hidden) { - this.wrapper.hidden = hidden; - }, - - /** - * Stop tracking reflows and hide all values when no node is selected or the - * box model view is hidden, otherwise track reflows and show values. - * @param {Boolean} isActive - */ - setActive: function (isActive) { - if (isActive === this.isActive) { - return; - } - this.isActive = isActive; - - if (isActive) { - this.trackReflows(); - } else { - this.untrackReflows(); - } - }, - - /** - * Compute the dimensions of the node and update the values in - * the inspector.xul document. - * @return a promise that will be resolved when complete. - */ - update: function () { - let lastRequest = Task.spawn((function* () { - if (!this.isViewVisibleAndNodeValid()) { - this.wrapper.hidden = true; - this.inspector.emit("boxmodel-view-updated"); - return null; - } - - let node = this.inspector.selection.nodeFront; - let layout = yield this.inspector.pageStyle.getLayout(node, { - autoMargins: this.isActive - }); - let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); - - yield this.updateGeometryButton(); - - // If a subsequent request has been made, wait for that one instead. - if (this._lastRequest != lastRequest) { - return this._lastRequest; - } - - this._lastRequest = null; - let width = layout.width; - let height = layout.height; - let newLabel = SHARED_L10N.getFormatStr("dimensions", width, height); - - if (this.sizeHeadingLabel.textContent != newLabel) { - this.sizeHeadingLabel.textContent = newLabel; - } - - for (let i in this.map) { - let property = this.map[i].property; - if (!(property in layout)) { - // Depending on the actor version, some properties - // might be missing. - continue; - } - let parsedValue = parseFloat(layout[property]); - if (Number.isNaN(parsedValue)) { - // Not a number. We use the raw string. - // Useful for "position" for example. - this.map[i].value = layout[property]; - } else { - this.map[i].value = parsedValue; - } - } - - let margins = layout.autoMargins; - if ("top" in margins) { - this.map.marginTop.value = "auto"; - } - if ("right" in margins) { - this.map.marginRight.value = "auto"; - } - if ("bottom" in margins) { - this.map.marginBottom.value = "auto"; - } - if ("left" in margins) { - this.map.marginLeft.value = "auto"; - } - - for (let i in this.map) { - let selector = this.map[i].selector; - let span = this.doc.querySelector(selector); - this.updateSourceRuleTooltip(span, this.map[i].property, styleEntries); - if (span.textContent.length > 0 && - span.textContent == this.map[i].value) { - continue; - } - span.textContent = this.map[i].value; - this.manageOverflowingText(span); - } - - width -= this.map.borderLeft.value + this.map.borderRight.value + - this.map.paddingLeft.value + this.map.paddingRight.value; - width = parseFloat(width.toPrecision(6)); - height -= this.map.borderTop.value + this.map.borderBottom.value + - this.map.paddingTop.value + this.map.paddingBottom.value; - height = parseFloat(height.toPrecision(6)); - - let newValue = width + "\u00D7" + height; - if (this.sizeLabel.textContent != newValue) { - this.sizeLabel.textContent = newValue; - } - - this.elementRules = styleEntries.map(e => e.rule); - - this.wrapper.hidden = false; - - this.inspector.emit("boxmodel-view-updated"); - return null; - }).bind(this)).catch(console.error); - - this._lastRequest = lastRequest; - return this._lastRequest; - }, - - /** - * Update the text in the tooltip shown when hovering over a value to provide - * information about the source CSS rule that sets this value. - * @param {DOMNode} el The element that will receive the tooltip. - * @param {String} property The name of the CSS property for the tooltip. - * @param {Array} rules An array of applied rules retrieved by - * styleActor.getApplied. - */ - updateSourceRuleTooltip: function (el, property, rules) { - // Dummy element used to parse the cssText of applied rules. - let dummyEl = this.doc.createElement("div"); - - // Rules are in order of priority so iterate until we find the first that - // defines a value for the property. - let sourceRule, value; - for (let {rule} of rules) { - dummyEl.style.cssText = rule.cssText; - value = dummyEl.style.getPropertyValue(property); - if (value !== "") { - sourceRule = rule; - break; - } - } - - let title = property; - if (sourceRule && sourceRule.selectors) { - title += "\n" + sourceRule.selectors.join(", "); - } - if (sourceRule && sourceRule.parentStyleSheet) { - if (sourceRule.parentStyleSheet.href) { - title += "\n" + sourceRule.parentStyleSheet.href + ":" + sourceRule.line; - } else { - title += "\n" + INSPECTOR_L10N.getStr("rule.sourceInline") + - ":" + sourceRule.line; - } - } - - el.setAttribute("title", title); - }, - - /** - * Show the box-model highlighter on the currently selected element - * @param {Object} options Options passed to the highlighter actor - */ - showBoxModel: function (options = {}) { - let toolbox = this.inspector.toolbox; - let nodeFront = this.inspector.selection.nodeFront; - - toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); - }, - - /** - * Hide the box-model highlighter on the currently selected element - */ - hideBoxModel: function () { - let toolbox = this.inspector.toolbox; - - toolbox.highlighterUtils.unhighlight(); - }, - - /** - * Show the geometry editor highlighter on the currently selected element - * @param {Boolean} [showOnlyIfActive=false] - * Indicates if the Geometry Editor should be shown only if it's active but - * hidden. - */ - showGeometryEditor: function (showOnlyIfActive = false) { - let toolbox = this.inspector.toolbox; - let nodeFront = this.inspector.selection.nodeFront; - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - let isActive = nodeGeometry.hasAttribute("checked"); - - if (showOnlyIfActive && !isActive) { - return; - } - - if (this._geometryEditorHighlighter) { - this._geometryEditorHighlighter.show(nodeFront).catch(console.error); - return; - } - - // instantiate Geometry Editor highlighter - toolbox.highlighterUtils - .getHighlighterByType("GeometryEditorHighlighter").then(highlighter => { - highlighter.show(nodeFront).catch(console.error); - this._geometryEditorHighlighter = highlighter; - - // Hide completely the geometry editor if the picker is clicked - toolbox.on("picker-started", this.onPickerStarted); - - // Temporary hide the geometry editor - this.inspector.markup.on("leave", this.onMarkupViewLeave); - this.inspector.markup.on("node-hover", this.onMarkupViewNodeHover); - - // Release the actor on will-navigate event - this.inspector.target.once("will-navigate", this.onWillNavigate); - }); - }, - - /** - * Hide the geometry editor highlighter on the currently selected element - * @param {Boolean} [updateButton=true] - * Indicates if the Geometry Editor's button needs to be unchecked too - */ - hideGeometryEditor: function (updateButton = true) { - if (this._geometryEditorHighlighter) { - this._geometryEditorHighlighter.hide().catch(console.error); - } - - if (updateButton) { - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - nodeGeometry.removeAttribute("checked"); - } - }, - - /** - * Update the visibility and the state of the geometry editor button, - * based on the selected node. - */ - updateGeometryButton: Task.async(function* () { - let node = this.inspector.selection.nodeFront; - let isEditable = false; - - if (node) { - isEditable = yield this.inspector.pageStyle.isPositionEditable(node); - } - - let nodeGeometry = this.doc.getElementById("old-layout-geometry-editor"); - nodeGeometry.style.visibility = isEditable ? "visible" : "hidden"; - }), - - manageOverflowingText: function (span) { - let classList = span.parentNode.classList; - - if (classList.contains("old-boxmodel-left") || - classList.contains("old-boxmodel-right")) { - let force = span.textContent.length > LONG_TEXT_ROTATE_LIMIT; - classList.toggle("old-boxmodel-rotate", force); - } - } -}; - -module.exports = BoxModelView; diff --git a/devtools/client/inspector/components/moz.build b/devtools/client/inspector/components/moz.build index 23d85edcdb23..0ef321ae1da1 100644 --- a/devtools/client/inspector/components/moz.build +++ b/devtools/client/inspector/components/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'deprecated-box-model.js', 'inspector-tab-panel.css', 'inspector-tab-panel.js', ) From 4a882e19be497c8151c33f6ac3d24f1eda2af38d Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:37:37 -0500 Subject: [PATCH 093/102] Bug 1336198 - Part 4: Remove the deprecated box model markup. r=jdescottes --- devtools/client/inspector/inspector.xhtml | 55 +---------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/devtools/client/inspector/inspector.xhtml b/devtools/client/inspector/inspector.xhtml index b2e084d9fd74..529627161088 100644 --- a/devtools/client/inspector/inspector.xhtml +++ b/devtools/client/inspector/inspector.xhtml @@ -131,60 +131,7 @@

-
-
- - -
- -
-
- -
- -
- -
-
-
-
-
-
- -

-

-

-

- -

-

-

-

- -

-

-

-

- -

- -

-
- -
- -
- - -
-
- -
-

-
-
+
From fbd7fff31cbcfa3974d423f1c2b5b2f7112360eb Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:37:40 -0500 Subject: [PATCH 094/102] Bug 1336198 - Part 5: Remove initialization of the deprecated box model. r=jdescottes --- devtools/client/inspector/computed/computed.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/devtools/client/inspector/computed/computed.js b/devtools/client/inspector/computed/computed.js index 95c81f0cf14d..54c543c672ad 100644 --- a/devtools/client/inspector/computed/computed.js +++ b/devtools/client/inspector/computed/computed.js @@ -26,7 +26,6 @@ const { const StyleInspectorMenu = require("devtools/client/inspector/shared/style-inspector-menu"); const TooltipsOverlay = require("devtools/client/inspector/shared/tooltips-overlay"); const KeyShortcuts = require("devtools/client/shared/key-shortcuts"); -const BoxModelView = require("devtools/client/inspector/components/deprecated-box-model"); const clipboardHelper = require("devtools/shared/platform/clipboard"); const STYLE_INSPECTOR_PROPERTIES = "devtools/shared/locales/styleinspector.properties"; @@ -1416,7 +1415,6 @@ function ComputedViewTool(inspector, window) { this.computedView = new CssComputedView(this.inspector, this.document, this.inspector.pageStyle); - this.boxModelView = new BoxModelView(this.inspector, this.document); this.onSelected = this.onSelected.bind(this); this.refresh = this.refresh.bind(this); @@ -1525,9 +1523,8 @@ ComputedViewTool.prototype = { } this.computedView.destroy(); - this.boxModelView.destroy(); - this.computedView = this.boxModelView = this.document = this.inspector = null; + this.computedView = this.document = this.inspector = null; } }; From a5ce26680896e3b3a6f89696bbdd78928d6e4f07 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:37:44 -0500 Subject: [PATCH 095/102] Bug 1336198 - Part 6: Refactor box model component into boxmodel/. r=jdescottes --- .../{layout => boxmodel}/actions/box-model.js | 0 .../client/inspector/boxmodel/actions/index.js | 14 ++++++++++++++ .../client/inspector/boxmodel/actions/moz.build | 10 ++++++++++ .../{layout => boxmodel}/components/BoxModel.js | 0 .../components/BoxModelEditable.js | 0 .../components/BoxModelInfo.js | 0 .../components/BoxModelMain.js | 0 .../components/BoxModelProperties.js | 0 .../components/ComputedProperty.js | 0 .../inspector/boxmodel/components/moz.build | 14 ++++++++++++++ devtools/client/inspector/boxmodel/moz.build | 16 ++++++++++++++++ .../{layout => boxmodel}/reducers/box-model.js | 0 .../inspector/boxmodel/reducers/moz.build | 9 +++++++++ devtools/client/inspector/boxmodel/types.js | 17 +++++++++++++++++ .../utils/editing-session.js | 0 .../client/inspector/boxmodel/utils/moz.build | 9 +++++++++ .../client/inspector/layout/actions/index.js | 3 --- .../client/inspector/layout/actions/moz.build | 1 - .../inspector/layout/components/moz.build | 6 ------ .../client/inspector/layout/reducers/moz.build | 1 - devtools/client/inspector/layout/types.js | 10 ---------- .../client/inspector/layout/utils/moz.build | 1 - devtools/client/inspector/moz.build | 1 + devtools/client/inspector/reducers.js | 2 +- 24 files changed, 91 insertions(+), 23 deletions(-) rename devtools/client/inspector/{layout => boxmodel}/actions/box-model.js (100%) create mode 100644 devtools/client/inspector/boxmodel/actions/index.js create mode 100644 devtools/client/inspector/boxmodel/actions/moz.build rename devtools/client/inspector/{layout => boxmodel}/components/BoxModel.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelEditable.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelInfo.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelMain.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/BoxModelProperties.js (100%) rename devtools/client/inspector/{layout => boxmodel}/components/ComputedProperty.js (100%) create mode 100644 devtools/client/inspector/boxmodel/components/moz.build create mode 100644 devtools/client/inspector/boxmodel/moz.build rename devtools/client/inspector/{layout => boxmodel}/reducers/box-model.js (100%) create mode 100644 devtools/client/inspector/boxmodel/reducers/moz.build create mode 100644 devtools/client/inspector/boxmodel/types.js rename devtools/client/inspector/{layout => boxmodel}/utils/editing-session.js (100%) create mode 100644 devtools/client/inspector/boxmodel/utils/moz.build diff --git a/devtools/client/inspector/layout/actions/box-model.js b/devtools/client/inspector/boxmodel/actions/box-model.js similarity index 100% rename from devtools/client/inspector/layout/actions/box-model.js rename to devtools/client/inspector/boxmodel/actions/box-model.js diff --git a/devtools/client/inspector/boxmodel/actions/index.js b/devtools/client/inspector/boxmodel/actions/index.js new file mode 100644 index 000000000000..45758428e733 --- /dev/null +++ b/devtools/client/inspector/boxmodel/actions/index.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { createEnum } = require("devtools/client/shared/enum"); + +createEnum([ + + // Update the layout state with the latest layout properties. + "UPDATE_LAYOUT", + +], module.exports); diff --git a/devtools/client/inspector/boxmodel/actions/moz.build b/devtools/client/inspector/boxmodel/actions/moz.build new file mode 100644 index 000000000000..2f98f6793d0c --- /dev/null +++ b/devtools/client/inspector/boxmodel/actions/moz.build @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'box-model.js', + 'index.js', +) diff --git a/devtools/client/inspector/layout/components/BoxModel.js b/devtools/client/inspector/boxmodel/components/BoxModel.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModel.js rename to devtools/client/inspector/boxmodel/components/BoxModel.js diff --git a/devtools/client/inspector/layout/components/BoxModelEditable.js b/devtools/client/inspector/boxmodel/components/BoxModelEditable.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelEditable.js rename to devtools/client/inspector/boxmodel/components/BoxModelEditable.js diff --git a/devtools/client/inspector/layout/components/BoxModelInfo.js b/devtools/client/inspector/boxmodel/components/BoxModelInfo.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelInfo.js rename to devtools/client/inspector/boxmodel/components/BoxModelInfo.js diff --git a/devtools/client/inspector/layout/components/BoxModelMain.js b/devtools/client/inspector/boxmodel/components/BoxModelMain.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelMain.js rename to devtools/client/inspector/boxmodel/components/BoxModelMain.js diff --git a/devtools/client/inspector/layout/components/BoxModelProperties.js b/devtools/client/inspector/boxmodel/components/BoxModelProperties.js similarity index 100% rename from devtools/client/inspector/layout/components/BoxModelProperties.js rename to devtools/client/inspector/boxmodel/components/BoxModelProperties.js diff --git a/devtools/client/inspector/layout/components/ComputedProperty.js b/devtools/client/inspector/boxmodel/components/ComputedProperty.js similarity index 100% rename from devtools/client/inspector/layout/components/ComputedProperty.js rename to devtools/client/inspector/boxmodel/components/ComputedProperty.js diff --git a/devtools/client/inspector/boxmodel/components/moz.build b/devtools/client/inspector/boxmodel/components/moz.build new file mode 100644 index 000000000000..562fd1a2cba8 --- /dev/null +++ b/devtools/client/inspector/boxmodel/components/moz.build @@ -0,0 +1,14 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'BoxModel.js', + 'BoxModelEditable.js', + 'BoxModelInfo.js', + 'BoxModelMain.js', + 'BoxModelProperties.js', + 'ComputedProperty.js', +) diff --git a/devtools/client/inspector/boxmodel/moz.build b/devtools/client/inspector/boxmodel/moz.build new file mode 100644 index 000000000000..eeb9697a60cb --- /dev/null +++ b/devtools/client/inspector/boxmodel/moz.build @@ -0,0 +1,16 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DIRS += [ + 'actions', + 'components', + 'reducers', + 'utils', +] + +DevToolsModules( + 'types.js', +) diff --git a/devtools/client/inspector/layout/reducers/box-model.js b/devtools/client/inspector/boxmodel/reducers/box-model.js similarity index 100% rename from devtools/client/inspector/layout/reducers/box-model.js rename to devtools/client/inspector/boxmodel/reducers/box-model.js diff --git a/devtools/client/inspector/boxmodel/reducers/moz.build b/devtools/client/inspector/boxmodel/reducers/moz.build new file mode 100644 index 000000000000..e2402990ad80 --- /dev/null +++ b/devtools/client/inspector/boxmodel/reducers/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'box-model.js', +) diff --git a/devtools/client/inspector/boxmodel/types.js b/devtools/client/inspector/boxmodel/types.js new file mode 100644 index 000000000000..aba8f7893d7e --- /dev/null +++ b/devtools/client/inspector/boxmodel/types.js @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { PropTypes } = require("devtools/client/shared/vendor/react"); + +/** + * The box model data for the current selected node. + */ +exports.boxModel = { + + // The layout information of the current selected node + layout: PropTypes.object, + +}; diff --git a/devtools/client/inspector/layout/utils/editing-session.js b/devtools/client/inspector/boxmodel/utils/editing-session.js similarity index 100% rename from devtools/client/inspector/layout/utils/editing-session.js rename to devtools/client/inspector/boxmodel/utils/editing-session.js diff --git a/devtools/client/inspector/boxmodel/utils/moz.build b/devtools/client/inspector/boxmodel/utils/moz.build new file mode 100644 index 000000000000..4ad6c32d9ef5 --- /dev/null +++ b/devtools/client/inspector/boxmodel/utils/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DevToolsModules( + 'editing-session.js', +) diff --git a/devtools/client/inspector/layout/actions/index.js b/devtools/client/inspector/layout/actions/index.js index d694e37400a2..bf11969f238b 100644 --- a/devtools/client/inspector/layout/actions/index.js +++ b/devtools/client/inspector/layout/actions/index.js @@ -17,9 +17,6 @@ createEnum([ // Update the entire grids state with the new list of grids. "UPDATE_GRIDS", - // Update the layout state with the latest layout properties. - "UPDATE_LAYOUT", - // Update the grid highlighter's show grid line numbers state. "UPDATE_SHOW_GRID_LINE_NUMBERS", diff --git a/devtools/client/inspector/layout/actions/moz.build b/devtools/client/inspector/layout/actions/moz.build index 5e157a4bd728..09b7039d19de 100644 --- a/devtools/client/inspector/layout/actions/moz.build +++ b/devtools/client/inspector/layout/actions/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'box-model.js', 'grids.js', 'highlighter-settings.js', 'index.js', diff --git a/devtools/client/inspector/layout/components/moz.build b/devtools/client/inspector/layout/components/moz.build index 7ad90ba4572b..551eaa5eda51 100644 --- a/devtools/client/inspector/layout/components/moz.build +++ b/devtools/client/inspector/layout/components/moz.build @@ -8,12 +8,6 @@ DevToolsModules( 'Accordion.css', 'Accordion.js', 'App.js', - 'BoxModel.js', - 'BoxModelEditable.js', - 'BoxModelInfo.js', - 'BoxModelMain.js', - 'BoxModelProperties.js', - 'ComputedProperty.js', 'Grid.js', 'GridDisplaySettings.js', 'GridItem.js', diff --git a/devtools/client/inspector/layout/reducers/moz.build b/devtools/client/inspector/layout/reducers/moz.build index 50e631af17b1..34867f4e837f 100644 --- a/devtools/client/inspector/layout/reducers/moz.build +++ b/devtools/client/inspector/layout/reducers/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'box-model.js', 'grids.js', 'highlighter-settings.js', ) diff --git a/devtools/client/inspector/layout/types.js b/devtools/client/inspector/layout/types.js index b9c286200ca0..0c0cd3b77473 100644 --- a/devtools/client/inspector/layout/types.js +++ b/devtools/client/inspector/layout/types.js @@ -6,16 +6,6 @@ const { PropTypes } = require("devtools/client/shared/vendor/react"); -/** - * The box model data for the current selected node. - */ -exports.boxModel = { - - // The layout information of the current selected node - layout: PropTypes.object, - -}; - /** * A single grid container in the document. */ diff --git a/devtools/client/inspector/layout/utils/moz.build b/devtools/client/inspector/layout/utils/moz.build index 537f779cc3cb..e3053b63fab6 100644 --- a/devtools/client/inspector/layout/utils/moz.build +++ b/devtools/client/inspector/layout/utils/moz.build @@ -5,6 +5,5 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'editing-session.js', 'l10n.js', ) diff --git a/devtools/client/inspector/moz.build b/devtools/client/inspector/moz.build index 1c5f3e58dd4c..8f1679fd2b39 100644 --- a/devtools/client/inspector/moz.build +++ b/devtools/client/inspector/moz.build @@ -3,6 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += [ + 'boxmodel', 'components', 'computed', 'fonts', diff --git a/devtools/client/inspector/reducers.js b/devtools/client/inspector/reducers.js index 6c09e49c49e4..a6818664560e 100644 --- a/devtools/client/inspector/reducers.js +++ b/devtools/client/inspector/reducers.js @@ -7,6 +7,6 @@ // This file exposes the Redux reducers of the box model, grid and grid highlighter // settings. -exports.boxModel = require("devtools/client/inspector/layout/reducers/box-model"); +exports.boxModel = require("devtools/client/inspector/boxmodel/reducers/box-model"); exports.grids = require("devtools/client/inspector/layout/reducers/grids"); exports.highlighterSettings = require("devtools/client/inspector/layout/reducers/highlighter-settings"); From 5b2a39cff832552b2c705d940b45d2e2a5c80596 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:37:47 -0500 Subject: [PATCH 096/102] Bug 1336198 - Part 7: Refactor box model logic into box-model.js. r=jdescottes --- .../client/inspector/boxmodel/box-model.js | 285 ++++++++++++++++++ devtools/client/inspector/boxmodel/moz.build | 1 + devtools/client/inspector/inspector.js | 2 + .../client/inspector/layout/components/App.js | 3 +- devtools/client/inspector/layout/layout.js | 212 +------------ devtools/client/shared/browser-loader.js | 1 + 6 files changed, 300 insertions(+), 204 deletions(-) create mode 100644 devtools/client/inspector/boxmodel/box-model.js diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js new file mode 100644 index 000000000000..9edf3164c9c9 --- /dev/null +++ b/devtools/client/inspector/boxmodel/box-model.js @@ -0,0 +1,285 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { Task } = require("devtools/shared/task"); +const { getCssProperties } = require("devtools/shared/fronts/css-properties"); +const { ReflowFront } = require("devtools/shared/fronts/reflow"); + +const { InplaceEditor } = require("devtools/client/shared/inplace-editor"); + +const { updateLayout } = require("./actions/box-model"); + +const EditingSession = require("./utils/editing-session"); + +const NUMERIC = /^-?[\d\.]+$/; + +/** + * A singleton instance of the box model controllers. + * + * @param {Inspector} inspector + * An instance of the Inspector currently loaded in the toolbox. + * @param {Window} window + * The document window of the toolbox. + */ +function BoxModel(inspector, window) { + this.document = window.document; + this.inspector = inspector; + this.store = inspector.store; + + this.updateBoxModel = this.updateBoxModel.bind(this); + + this.onHideBoxModelHighlighter = this.onHideBoxModelHighlighter.bind(this); + this.onNewSelection = this.onNewSelection.bind(this); + this.onShowBoxModelEditor = this.onShowBoxModelEditor.bind(this); + this.onShowBoxModelHighlighter = this.onShowBoxModelHighlighter.bind(this); + this.onSidebarSelect = this.onSidebarSelect.bind(this); + + this.inspector.selection.on("new-node-front", this.onNewSelection); + this.inspector.sidebar.on("select", this.onSidebarSelect); +} + +BoxModel.prototype = { + + /** + * Destruction function called when the inspector is destroyed. Removes event listeners + * and cleans up references. + */ + destroy() { + this.inspector.selection.off("new-node-front", this.onNewSelection); + this.inspector.sidebar.off("select", this.onSidebarSelect); + + if (this.reflowFront) { + this.untrackReflows(); + this.reflowFront.destroy(); + this.reflowFront = null; + } + + this.document = null; + this.inspector = null; + this.walker = null; + }, + + /** + * Returns an object containing the box model's handler functions used in the box + * model's React component props. + */ + getComponentProps() { + return { + onHideBoxModelHighlighter: this.onHideBoxModelHighlighter, + onShowBoxModelEditor: this.onShowBoxModelEditor, + onShowBoxModelHighlighter: this.onShowBoxModelHighlighter, + }; + }, + + /** + * Returns true if the layout panel is visible, and false otherwise. + */ + isPanelVisible() { + return this.inspector.toolbox.currentToolId === "inspector" && + this.inspector.sidebar && + this.inspector.sidebar.getCurrentTabID() === "layoutview"; + }, + + /** + * Returns true if the layout panel is visible and the current node is valid to + * be displayed in the view. + */ + isPanelVisibleAndNodeValid() { + return this.isPanelVisible() && + this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode(); + }, + + /** + * Starts listening to reflows in the current tab. + */ + trackReflows() { + if (!this.reflowFront) { + let { target } = this.inspector; + if (target.form.reflowActor) { + this.reflowFront = ReflowFront(target.client, + target.form); + } else { + return; + } + } + + this.reflowFront.on("reflows", this.updateBoxModel); + this.reflowFront.start(); + }, + + /** + * Stops listening to reflows in the current tab. + */ + untrackReflows() { + if (!this.reflowFront) { + return; + } + + this.reflowFront.off("reflows", this.updateBoxModel); + this.reflowFront.stop(); + }, + + /** + * Updates the box model panel by dispatching the new layout data. + */ + updateBoxModel() { + let lastRequest = Task.spawn((function* () { + if (!(this.isPanelVisible() && + this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode())) { + return null; + } + + let node = this.inspector.selection.nodeFront; + let layout = yield this.inspector.pageStyle.getLayout(node, { + autoMargins: true, + }); + let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); + this.elementRules = styleEntries.map(e => e.rule); + + // Update the redux store with the latest layout properties and update the box + // model view. + this.store.dispatch(updateLayout(layout)); + + // If a subsequent request has been made, wait for that one instead. + if (this._lastRequest != lastRequest) { + return this._lastRequest; + } + + this._lastRequest = null; + + this.inspector.emit("boxmodel-view-updated"); + return null; + }).bind(this)).catch(console.error); + + this._lastRequest = lastRequest; + }, + + /** + * Selection 'new-node-front' event handler. + */ + onNewSelection: function () { + if (!this.isPanelVisibleAndNodeValid()) { + return; + } + + this.updateBoxModel(); + }, + + /** + * Hides the box-model highlighter on the currently selected element. + */ + onHideBoxModelHighlighter() { + let toolbox = this.inspector.toolbox; + toolbox.highlighterUtils.unhighlight(); + }, + + /** + * Shows the inplace editor when a box model editable value is clicked on the + * box model panel. + * + * @param {DOMNode} element + * The element that was clicked. + * @param {Event} event + * The event object. + * @param {String} property + * The name of the property. + */ + onShowBoxModelEditor(element, event, property) { + let session = new EditingSession({ + inspector: this.inspector, + doc: this.document, + elementRules: this.elementRules, + }); + let initialValue = session.getProperty(property); + + let editor = new InplaceEditor({ + element: element, + initial: initialValue, + contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, + property: { + name: property + }, + start: self => { + self.elt.parentNode.classList.add("boxmodel-editing"); + }, + change: value => { + if (NUMERIC.test(value)) { + value += "px"; + } + + let properties = [ + { name: property, value: value } + ]; + + if (property.substring(0, 7) == "border-") { + let bprop = property.substring(0, property.length - 5) + "style"; + let style = session.getProperty(bprop); + if (!style || style == "none" || style == "hidden") { + properties.push({ name: bprop, value: "solid" }); + } + } + + session.setProperties(properties).catch(e => console.error(e)); + }, + done: (value, commit) => { + editor.elt.parentNode.classList.remove("boxmodel-editing"); + if (!commit) { + session.revert().then(() => { + session.destroy(); + }, e => console.error(e)); + return; + } + + let node = this.inspector.selection.nodeFront; + this.inspector.pageStyle.getLayout(node, { + autoMargins: true, + }).then(layout => { + this.store.dispatch(updateLayout(layout)); + }, e => console.error(e)); + }, + contextMenu: this.inspector.onTextBoxContextMenu, + cssProperties: getCssProperties(this.inspector.toolbox) + }, event); + }, + + /** + * Shows the box-model highlighter on the currently selected element. + * + * @param {Object} options + * Options passed to the highlighter actor. + */ + onShowBoxModelHighlighter(options = {}) { + let toolbox = this.inspector.toolbox; + let nodeFront = this.inspector.selection.nodeFront; + + toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); + }, + + /** + * Handler for the inspector sidebar select event. Starts listening for + * "grid-layout-changed" if the layout panel is visible. Otherwise, stop + * listening for grid layout changes. Finally, refresh the layout view if + * it is visible. + */ + onSidebarSelect() { + if (!this.isPanelVisible()) { + this.untrackReflows(); + return; + } + + if (this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode()) { + this.trackReflows(); + } + + this.updateBoxModel(); + }, + +}; + +module.exports = BoxModel; diff --git a/devtools/client/inspector/boxmodel/moz.build b/devtools/client/inspector/boxmodel/moz.build index eeb9697a60cb..07b54256bdd3 100644 --- a/devtools/client/inspector/boxmodel/moz.build +++ b/devtools/client/inspector/boxmodel/moz.build @@ -12,5 +12,6 @@ DIRS += [ ] DevToolsModules( + 'box-model.js', 'types.js', ) diff --git a/devtools/client/inspector/inspector.js b/devtools/client/inspector/inspector.js index 1e9af044f029..ca42f4decb9a 100644 --- a/devtools/client/inspector/inspector.js +++ b/devtools/client/inspector/inspector.js @@ -23,6 +23,7 @@ const Menu = require("devtools/client/framework/menu"); const MenuItem = require("devtools/client/framework/menu-item"); const {HTMLBreadcrumbs} = require("devtools/client/inspector/breadcrumbs"); +const BoxModel = require("devtools/client/inspector/boxmodel/box-model"); const {ComputedViewTool} = require("devtools/client/inspector/computed/computed"); const {FontInspector} = require("devtools/client/inspector/fonts/fonts"); const {InspectorSearch} = require("devtools/client/inspector/inspector-search"); @@ -573,6 +574,7 @@ Inspector.prototype = { this.ruleview = new RuleViewTool(this, this.panelWin); this.computedview = new ComputedViewTool(this, this.panelWin); + this.boxmodel = new BoxModel(this, this.panelWin); if (Services.prefs.getBoolPref("devtools.layoutview.enabled")) { const LayoutView = this.browserRequire("devtools/client/inspector/layout/layout"); diff --git a/devtools/client/inspector/layout/components/App.js b/devtools/client/inspector/layout/components/App.js index d8dd19582d0c..cbcb2bebc271 100644 --- a/devtools/client/inspector/layout/components/App.js +++ b/devtools/client/inspector/layout/components/App.js @@ -11,9 +11,10 @@ const { connect } = require("devtools/client/shared/vendor/react-redux"); const { LocalizationHelper } = require("devtools/shared/l10n"); const Accordion = createFactory(require("./Accordion")); -const BoxModel = createFactory(require("./BoxModel")); const Grid = createFactory(require("./Grid")); +const BoxModel = createFactory(require("devtools/client/inspector/boxmodel/components/BoxModel")); + const Types = require("../types"); const { getStr } = require("../utils/l10n"); diff --git a/devtools/client/inspector/layout/layout.js b/devtools/client/inspector/layout/layout.js index d9c6ba201be7..2d6f1fe0cf60 100644 --- a/devtools/client/inspector/layout/layout.js +++ b/devtools/client/inspector/layout/layout.js @@ -6,18 +6,12 @@ const Services = require("Services"); const { Task } = require("devtools/shared/task"); -const { getCssProperties } = require("devtools/shared/fronts/css-properties"); -const { ReflowFront } = require("devtools/shared/fronts/reflow"); -const { InplaceEditor } = require("devtools/client/shared/inplace-editor"); const { createFactory, createElement } = require("devtools/client/shared/vendor/react"); const { Provider } = require("devtools/client/shared/vendor/react-redux"); const SwatchColorPickerTooltip = require("devtools/client/shared/widgets/tooltip/SwatchColorPickerTooltip"); -const { - updateLayout, -} = require("./actions/box-model"); const { updateGridColor, updateGridHighlighted, @@ -30,13 +24,10 @@ const { const App = createFactory(require("./components/App")); -const EditingSession = require("./utils/editing-session"); - const { LocalizationHelper } = require("devtools/shared/l10n"); const INSPECTOR_L10N = new LocalizationHelper("devtools/client/locales/inspector.properties"); -const NUMERIC = /^-?[\d\.]+$/; const SHOW_GRID_LINE_NUMBERS = "devtools.gridinspector.showGridLineNumbers"; const SHOW_INFINITE_LINES_PREF = "devtools.gridinspector.showInfiniteLines"; @@ -59,11 +50,8 @@ function LayoutView(inspector, window) { this.store = inspector.store; this.walker = this.inspector.walker; - this.updateBoxModel = this.updateBoxModel.bind(this); - this.onGridLayoutChange = this.onGridLayoutChange.bind(this); this.onHighlighterChange = this.onHighlighterChange.bind(this); - this.onNewSelection = this.onNewSelection.bind(this); this.onSidebarSelect = this.onSidebarSelect.bind(this); this.init(); @@ -80,13 +68,18 @@ LayoutView.prototype = { return; } + let { + onHideBoxModelHighlighter, + onShowBoxModelEditor, + onShowBoxModelHighlighter, + } = this.inspector.boxmodel.getComponentProps(); + this.layoutInspector = yield this.inspector.walker.getLayoutInspector(); this.loadHighlighterSettings(); this.highlighters.on("grid-highlighter-hidden", this.onHighlighterChange); this.highlighters.on("grid-highlighter-shown", this.onHighlighterChange); - this.inspector.selection.on("new-node-front", this.onNewSelection); this.inspector.sidebar.on("select", this.onSidebarSelect); // Create a shared SwatchColorPicker instance to be reused by all GridItem components. @@ -112,13 +105,9 @@ LayoutView.prototype = { */ showBoxModelProperties: true, - /** - * Hides the box-model highlighter on the currently selected element. - */ - onHideBoxModelHighlighter: () => { - let toolbox = this.inspector.toolbox; - toolbox.highlighterUtils.unhighlight(); - }, + onHideBoxModelHighlighter, + onShowBoxModelEditor, + onShowBoxModelHighlighter, /** * Handler for a change in the grid overlay color picker for a grid container. @@ -143,88 +132,6 @@ LayoutView.prototype = { } }, - /** - * Shows the inplace editor when a box model editable value is clicked on the - * box model panel. - * - * @param {DOMNode} element - * The element that was clicked. - * @param {Event} event - * The event object. - * @param {String} property - * The name of the property. - */ - onShowBoxModelEditor: (element, event, property) => { - let session = new EditingSession({ - inspector: this.inspector, - doc: this.document, - elementRules: this.elementRules, - }); - let initialValue = session.getProperty(property); - - let editor = new InplaceEditor({ - element: element, - initial: initialValue, - contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE, - property: { - name: property - }, - start: self => { - self.elt.parentNode.classList.add("boxmodel-editing"); - }, - change: value => { - if (NUMERIC.test(value)) { - value += "px"; - } - - let properties = [ - { name: property, value: value } - ]; - - if (property.substring(0, 7) == "border-") { - let bprop = property.substring(0, property.length - 5) + "style"; - let style = session.getProperty(bprop); - if (!style || style == "none" || style == "hidden") { - properties.push({ name: bprop, value: "solid" }); - } - } - - session.setProperties(properties).catch(e => console.error(e)); - }, - done: (value, commit) => { - editor.elt.parentNode.classList.remove("boxmodel-editing"); - if (!commit) { - session.revert().then(() => { - session.destroy(); - }, e => console.error(e)); - return; - } - - let node = this.inspector.selection.nodeFront; - this.inspector.pageStyle.getLayout(node, { - autoMargins: true, - }).then(layout => { - this.store.dispatch(updateLayout(layout)); - }, e => console.error(e)); - }, - contextMenu: this.inspector.onTextBoxContextMenu, - cssProperties: getCssProperties(this.inspector.toolbox) - }, event); - }, - - /** - * Shows the box-model highlighter on the currently selected element. - * - * @param {Object} options - * Options passed to the highlighter actor. - */ - onShowBoxModelHighlighter: (options = {}) => { - let toolbox = this.inspector.toolbox; - let nodeFront = this.inspector.selection.nodeFront; - - toolbox.highlighterUtils.highlightNodeFront(nodeFront, options); - }, - /** * Handler for a change in the input checkboxes in the GridList component. * Toggles on/off the grid highlighter for the provided grid container element. @@ -309,16 +216,9 @@ LayoutView.prototype = { destroy() { this.highlighters.off("grid-highlighter-hidden", this.onHighlighterChange); this.highlighters.off("grid-highlighter-shown", this.onHighlighterChange); - this.inspector.selection.off("new-node-front", this.onNewSelection); this.inspector.sidebar.off("select", this.onSidebarSelect); this.layoutInspector.off("grid-layout-changed", this.onGridLayoutChange); - if (this.reflowFront) { - this.untrackReflows(); - this.reflowFront.destroy(); - this.reflowFront = null; - } - this.document = null; this.inspector = null; this.layoutInspector = null; @@ -372,16 +272,6 @@ LayoutView.prototype = { this.inspector.sidebar.getCurrentTabID() === "layoutview"; }, - /** - * Returns true if the layout panel is visible and the current node is valid to - * be displayed in the view. - */ - isPanelVisibleAndNodeValid() { - return this.isPanelVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode(); - }, - /** * Load the grid highligher display settings into the store from the stored preferences. */ @@ -395,72 +285,6 @@ LayoutView.prototype = { dispatch(updateShowInfiniteLines(showInfinteLines)); }, - /** - * Starts listening to reflows in the current tab. - */ - trackReflows() { - if (!this.reflowFront) { - let { target } = this.inspector; - if (target.form.reflowActor) { - this.reflowFront = ReflowFront(target.client, - target.form); - } else { - return; - } - } - - this.reflowFront.on("reflows", this.updateBoxModel); - this.reflowFront.start(); - }, - - /** - * Stops listening to reflows in the current tab. - */ - untrackReflows() { - if (!this.reflowFront) { - return; - } - - this.reflowFront.off("reflows", this.updateBoxModel); - this.reflowFront.stop(); - }, - - /** - * Updates the box model panel by dispatching the new layout data. - */ - updateBoxModel() { - let lastRequest = Task.spawn((function* () { - if (!(this.isPanelVisible() && - this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode())) { - return null; - } - - let node = this.inspector.selection.nodeFront; - let layout = yield this.inspector.pageStyle.getLayout(node, { - autoMargins: true, - }); - let styleEntries = yield this.inspector.pageStyle.getApplied(node, {}); - this.elementRules = styleEntries.map(e => e.rule); - - // Update the redux store with the latest layout properties and update the box - // model view. - this.store.dispatch(updateLayout(layout)); - - // If a subsequent request has been made, wait for that one instead. - if (this._lastRequest != lastRequest) { - return this._lastRequest; - } - - this._lastRequest = null; - - this.inspector.emit("boxmodel-view-updated"); - return null; - }).bind(this)).catch(console.error); - - this._lastRequest = lastRequest; - }, - /** * Updates the grid panel by dispatching the new grid data. This is called when the * layout view becomes visible or the view needs to be updated with new grid data. @@ -526,17 +350,6 @@ LayoutView.prototype = { this.store.dispatch(updateGridHighlighted(nodeFront, highlighted)); }, - /** - * Selection 'new-node-front' event handler. - */ - onNewSelection: function () { - if (!this.isPanelVisibleAndNodeValid()) { - return; - } - - this.updateBoxModel(); - }, - /** * Handler for the inspector sidebar select event. Starts listening for * "grid-layout-changed" if the layout panel is visible. Otherwise, stop @@ -546,17 +359,10 @@ LayoutView.prototype = { onSidebarSelect() { if (!this.isPanelVisible()) { this.layoutInspector.off("grid-layout-changed", this.onGridLayoutChange); - this.untrackReflows(); return; } - if (this.inspector.selection.isConnected() && - this.inspector.selection.isElementNode()) { - this.trackReflows(); - } - this.layoutInspector.on("grid-layout-changed", this.onGridLayoutChange); - this.updateBoxModel(); this.updateGridPanel(); }, diff --git a/devtools/client/shared/browser-loader.js b/devtools/client/shared/browser-loader.js index ab7505beee9b..e21a899044a3 100644 --- a/devtools/client/shared/browser-loader.js +++ b/devtools/client/shared/browser-loader.js @@ -12,6 +12,7 @@ const Services = devtools.require("Services"); const { AppConstants } = devtools.require("resource://gre/modules/AppConstants.jsm"); const BROWSER_BASED_DIRS = [ + "resource://devtools/client/inspector/boxmodel", "resource://devtools/client/inspector/layout", "resource://devtools/client/jsonview", "resource://devtools/client/shared/vendor", From 6d31199605a180dd61432d80f707a0f14054140d Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Fri, 24 Feb 2017 01:37:51 -0500 Subject: [PATCH 097/102] Bug 1336198 - Part 8: Use the react/redux box model in the computed view. r=jdescottes --- .../client/inspector/boxmodel/box-model.js | 10 +++- .../boxmodel/components/BoxModelApp.js | 51 +++++++++++++++++++ .../inspector/boxmodel/components/moz.build | 1 + .../client/inspector/computed/computed.js | 32 ++++++++++++ devtools/client/inspector/inspector.js | 6 ++- devtools/client/shared/browser-loader.js | 1 + 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 devtools/client/inspector/boxmodel/components/BoxModelApp.js diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js index 9edf3164c9c9..839b608f5ca2 100644 --- a/devtools/client/inspector/boxmodel/box-model.js +++ b/devtools/client/inspector/boxmodel/box-model.js @@ -75,12 +75,13 @@ BoxModel.prototype = { }, /** - * Returns true if the layout panel is visible, and false otherwise. + * Returns true if the computed or layout panel is visible, and false otherwise. */ isPanelVisible() { return this.inspector.toolbox.currentToolId === "inspector" && this.inspector.sidebar && - this.inspector.sidebar.getCurrentTabID() === "layoutview"; + (this.inspector.sidebar.getCurrentTabID() === "layoutview" || + this.inspector.sidebar.getCurrentTabID() === "computedview"); }, /** @@ -167,6 +168,11 @@ BoxModel.prototype = { return; } + if (this.inspector.selection.isConnected() && + this.inspector.selection.isElementNode()) { + this.trackReflows(); + } + this.updateBoxModel(); }, diff --git a/devtools/client/inspector/boxmodel/components/BoxModelApp.js b/devtools/client/inspector/boxmodel/components/BoxModelApp.js new file mode 100644 index 000000000000..2af27ac77c2f --- /dev/null +++ b/devtools/client/inspector/boxmodel/components/BoxModelApp.js @@ -0,0 +1,51 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { addons, createClass, createFactory, PropTypes } = + require("devtools/client/shared/vendor/react"); +const { connect } = require("devtools/client/shared/vendor/react-redux"); + +const { LocalizationHelper } = require("devtools/shared/l10n"); + +const Accordion = + createFactory(require("devtools/client/inspector/layout/components/Accordion")); +const BoxModel = createFactory(require("./BoxModel")); + +const Types = require("../types"); + +const BOXMODEL_STRINGS_URI = "devtools/client/locales/boxmodel.properties"; +const BOXMODEL_L10N = new LocalizationHelper(BOXMODEL_STRINGS_URI); + +const BoxModelApp = createClass({ + + displayName: "BoxModelApp", + + propTypes: { + boxModel: PropTypes.shape(Types.boxModel).isRequired, + showBoxModelProperties: PropTypes.bool.isRequired, + onHideBoxModelHighlighter: PropTypes.func.isRequired, + onShowBoxModelEditor: PropTypes.func.isRequired, + onShowBoxModelHighlighter: PropTypes.func.isRequired, + }, + + mixins: [ addons.PureRenderMixin ], + + render() { + return Accordion({ + items: [ + { + header: BOXMODEL_L10N.getStr("boxmodel.title"), + component: BoxModel, + componentProps: this.props, + opened: true, + } + ] + }); + }, + +}); + +module.exports = connect(state => state)(BoxModelApp); diff --git a/devtools/client/inspector/boxmodel/components/moz.build b/devtools/client/inspector/boxmodel/components/moz.build index 562fd1a2cba8..02638ae7b291 100644 --- a/devtools/client/inspector/boxmodel/components/moz.build +++ b/devtools/client/inspector/boxmodel/components/moz.build @@ -6,6 +6,7 @@ DevToolsModules( 'BoxModel.js', + 'BoxModelApp.js', 'BoxModelEditable.js', 'BoxModelInfo.js', 'BoxModelMain.js', diff --git a/devtools/client/inspector/computed/computed.js b/devtools/client/inspector/computed/computed.js index 54c543c672ad..3754e5584c9c 100644 --- a/devtools/client/inspector/computed/computed.js +++ b/devtools/client/inspector/computed/computed.js @@ -28,6 +28,12 @@ const TooltipsOverlay = require("devtools/client/inspector/shared/tooltips-overl const KeyShortcuts = require("devtools/client/shared/key-shortcuts"); const clipboardHelper = require("devtools/shared/platform/clipboard"); +const { createElement, createFactory } = require("devtools/client/shared/vendor/react"); +const ReactDOM = require("devtools/client/shared/vendor/react-dom"); +const { Provider } = require("devtools/client/shared/vendor/react-redux"); + +const BoxModelApp = createFactory(require("devtools/client/inspector/boxmodel/components/BoxModelApp")); + const STYLE_INSPECTOR_PROPERTIES = "devtools/shared/locales/styleinspector.properties"; const {LocalizationHelper} = require("devtools/shared/l10n"); const STYLE_INSPECTOR_L10N = new LocalizationHelper(STYLE_INSPECTOR_PROPERTIES); @@ -153,6 +159,7 @@ UpdateProcess.prototype = { function CssComputedView(inspector, document, pageStyle) { this.inspector = inspector; this.highlighters = inspector.highlighters; + this.store = inspector.store; this.styleDocument = document; this.styleWindow = this.styleDocument.defaultView; this.pageStyle = pageStyle; @@ -208,6 +215,7 @@ function CssComputedView(inspector, document, pageStyle) { // The element that we're inspecting, and the document that it comes from. this._viewedElement = null; + this.createBoxModelView(); this.createStyleViews(); this._contextmenu = new StyleInspectorMenu(this, { isRuleView: false }); @@ -604,6 +612,29 @@ CssComputedView.prototype = { this.inspector.emit("computed-view-sourcelinks-updated"); }, + /** + * Render the box model view. + */ + createBoxModelView: function () { + let { + onHideBoxModelHighlighter, + onShowBoxModelEditor, + onShowBoxModelHighlighter, + } = this.inspector.boxmodel.getComponentProps(); + + let provider = createElement( + Provider, + { store: this.store }, + BoxModelApp({ + showBoxModelProperties: false, + onHideBoxModelHighlighter, + onShowBoxModelEditor, + onShowBoxModelHighlighter, + }) + ); + ReactDOM.render(provider, this.styleDocument.getElementById("boxmodel-wrapper")); + }, + /** * The CSS as displayed by the UI. */ @@ -795,6 +826,7 @@ CssComputedView.prototype = { this.inspector = null; this.highlighters = null; + this.store = null; this.styleDocument = null; this.styleWindow = null; diff --git a/devtools/client/inspector/inspector.js b/devtools/client/inspector/inspector.js index ca42f4decb9a..493aa7792e10 100644 --- a/devtools/client/inspector/inspector.js +++ b/devtools/client/inspector/inspector.js @@ -24,7 +24,6 @@ const MenuItem = require("devtools/client/framework/menu-item"); const {HTMLBreadcrumbs} = require("devtools/client/inspector/breadcrumbs"); const BoxModel = require("devtools/client/inspector/boxmodel/box-model"); -const {ComputedViewTool} = require("devtools/client/inspector/computed/computed"); const {FontInspector} = require("devtools/client/inspector/fonts/fonts"); const {InspectorSearch} = require("devtools/client/inspector/inspector-search"); const {RuleViewTool} = require("devtools/client/inspector/rules/rules"); @@ -573,9 +572,12 @@ Inspector.prototype = { defaultTab == "computedview"); this.ruleview = new RuleViewTool(this, this.panelWin); - this.computedview = new ComputedViewTool(this, this.panelWin); this.boxmodel = new BoxModel(this, this.panelWin); + const {ComputedViewTool} = + this.browserRequire("devtools/client/inspector/computed/computed"); + this.computedview = new ComputedViewTool(this, this.panelWin); + if (Services.prefs.getBoolPref("devtools.layoutview.enabled")) { const LayoutView = this.browserRequire("devtools/client/inspector/layout/layout"); this.layoutview = new LayoutView(this, this.panelWin); diff --git a/devtools/client/shared/browser-loader.js b/devtools/client/shared/browser-loader.js index e21a899044a3..3aef74a99bf9 100644 --- a/devtools/client/shared/browser-loader.js +++ b/devtools/client/shared/browser-loader.js @@ -13,6 +13,7 @@ const { AppConstants } = devtools.require("resource://gre/modules/AppConstants.j const BROWSER_BASED_DIRS = [ "resource://devtools/client/inspector/boxmodel", + "resource://devtools/client/inspector/computed", "resource://devtools/client/inspector/layout", "resource://devtools/client/jsonview", "resource://devtools/client/shared/vendor", From 7b1d35d588dd98ba71ff49d77305b6d52dc76051 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 22 Feb 2017 19:26:57 +0100 Subject: [PATCH 098/102] Bug 1336198 - Part 9: Use existing box model tests with the new react/redux box model. r=jdescottes MozReview-Commit-ID: HrqeP2X35t --- .../boxmodel/components/BoxModelMain.js | 24 ++++++-- devtools/client/inspector/boxmodel/moz.build | 2 + .../test/.eslintrc.js | 0 .../{components => boxmodel}/test/browser.ini | 2 + .../test/browser_boxmodel.js | 60 +++++++++---------- .../test/browser_boxmodel_editablemodel.js | 58 +++++++++--------- ...er_boxmodel_editablemodel_allproperties.js | 40 ++++++------- ...wser_boxmodel_editablemodel_bluronclick.js | 24 ++++---- .../browser_boxmodel_editablemodel_border.js | 10 ++-- ...owser_boxmodel_editablemodel_stylerules.js | 32 +++++----- .../test/browser_boxmodel_guides.js | 8 +-- .../test/browser_boxmodel_navigation.js | 26 ++++---- ...browser_boxmodel_rotate-labels-on-sides.js | 49 +++++++++++++++ .../test/browser_boxmodel_sync.js | 10 ++-- .../test/browser_boxmodel_tooltips.js | 18 +++--- ...rowser_boxmodel_update-after-navigation.js | 13 ++-- .../browser_boxmodel_update-after-reload.js | 5 +- .../browser_boxmodel_update-in-iframes.js | 4 +- .../test/doc_boxmodel_iframe1.html | 0 .../test/doc_boxmodel_iframe2.html | 0 .../{components => boxmodel}/test/head.js | 13 +++- .../client/inspector/components/moz.build | 2 - ...browser_boxmodel_rotate-labels-on-sides.js | 49 --------------- .../client/inspector/computed/computed.js | 9 +-- .../test/browser_computed_search-filter.js | 2 +- .../browser_computed_search-filter_clear.js | 2 +- devtools/client/inspector/inspector.js | 2 - .../test/browser_inspector_textbox-menu.js | 2 +- 28 files changed, 245 insertions(+), 221 deletions(-) rename devtools/client/inspector/{components => boxmodel}/test/.eslintrc.js (100%) rename devtools/client/inspector/{components => boxmodel}/test/browser.ini (94%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel.js (58%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel.js (74%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_allproperties.js (74%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_bluronclick.js (69%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_border.js (82%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_editablemodel_stylerules.js (74%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_guides.js (89%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_navigation.js (75%) create mode 100644 devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_sync.js (77%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_tooltips.js (83%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_update-after-navigation.js (88%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_update-after-reload.js (90%) rename devtools/client/inspector/{components => boxmodel}/test/browser_boxmodel_update-in-iframes.js (96%) rename devtools/client/inspector/{components => boxmodel}/test/doc_boxmodel_iframe1.html (100%) rename devtools/client/inspector/{components => boxmodel}/test/doc_boxmodel_iframe2.html (100%) rename devtools/client/inspector/{components => boxmodel}/test/head.js (86%) delete mode 100644 devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js diff --git a/devtools/client/inspector/boxmodel/components/BoxModelMain.js b/devtools/client/inspector/boxmodel/components/BoxModelMain.js index 42baa7427453..a3980c79d104 100644 --- a/devtools/client/inspector/boxmodel/components/BoxModelMain.js +++ b/devtools/client/inspector/boxmodel/components/BoxModelMain.js @@ -37,7 +37,23 @@ module.exports = createClass({ return layout[property] ? parseFloat(layout[property]) : "-"; }, - getHeightOrWidthValue(property) { + getHeightValue(property) { + let { layout } = this.props.boxModel; + + if (property == undefined) { + return "-"; + } + + property -= parseFloat(layout["border-top-width"]) + + parseFloat(layout["border-bottom-width"]) + + parseFloat(layout["padding-top"]) + + parseFloat(layout["padding-bottom"]); + property = parseFloat(property.toPrecision(6)); + + return property; + }, + + getWidthValue(property) { let { layout } = this.props.boxModel; if (property == undefined) { @@ -83,7 +99,7 @@ module.exports = createClass({ render() { let { boxModel, onShowBoxModelEditor } = this.props; let { layout } = boxModel; - let { width, height } = layout; + let { height, width } = layout; let borderTop = this.getBorderOrPaddingValue("border-top-width"); let borderRight = this.getBorderOrPaddingValue("border-right-width"); @@ -100,8 +116,8 @@ module.exports = createClass({ let marginBottom = this.getMarginValue("margin-bottom", "bottom"); let marginLeft = this.getMarginValue("margin-left", "left"); - width = this.getHeightOrWidthValue(width); - height = this.getHeightOrWidthValue(height); + height = this.getHeightValue(height); + width = this.getWidthValue(width); return dom.div( { diff --git a/devtools/client/inspector/boxmodel/moz.build b/devtools/client/inspector/boxmodel/moz.build index 07b54256bdd3..6ef44c80c361 100644 --- a/devtools/client/inspector/boxmodel/moz.build +++ b/devtools/client/inspector/boxmodel/moz.build @@ -15,3 +15,5 @@ DevToolsModules( 'box-model.js', 'types.js', ) + +BROWSER_CHROME_MANIFESTS += ['test/browser.ini'] diff --git a/devtools/client/inspector/components/test/.eslintrc.js b/devtools/client/inspector/boxmodel/test/.eslintrc.js similarity index 100% rename from devtools/client/inspector/components/test/.eslintrc.js rename to devtools/client/inspector/boxmodel/test/.eslintrc.js diff --git a/devtools/client/inspector/components/test/browser.ini b/devtools/client/inspector/boxmodel/test/browser.ini similarity index 94% rename from devtools/client/inspector/components/test/browser.ini rename to devtools/client/inspector/boxmodel/test/browser.ini index be937ecfd3d7..c9881c903937 100644 --- a/devtools/client/inspector/components/test/browser.ini +++ b/devtools/client/inspector/boxmodel/test/browser.ini @@ -21,9 +21,11 @@ support-files = [browser_boxmodel_editablemodel_stylerules.js] [browser_boxmodel_guides.js] [browser_boxmodel_navigation.js] +skip-if = true # Bug 1336198 [browser_boxmodel_rotate-labels-on-sides.js] [browser_boxmodel_sync.js] [browser_boxmodel_tooltips.js] +skip-if = true # Bug 1336198 [browser_boxmodel_update-after-navigation.js] [browser_boxmodel_update-after-reload.js] # [browser_boxmodel_update-in-iframes.js] diff --git a/devtools/client/inspector/components/test/browser_boxmodel.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel.js similarity index 58% rename from devtools/client/inspector/components/test/browser_boxmodel.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel.js index d26d9061ce52..9e085cafe232 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel.js @@ -10,118 +10,118 @@ // Expected values: var res1 = [ { - selector: "#old-boxmodel-element-size", + selector: ".boxmodel-element-size", value: "160" + "\u00D7" + "160.117" }, { - selector: ".old-boxmodel-size > span", + selector: ".boxmodel-size > span", value: "100" + "\u00D7" + "100.117" }, { - selector: ".old-boxmodel-margin.old-boxmodel-top > span", + selector: ".boxmodel-margin.boxmodel-top > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-left > span", + selector: ".boxmodel-margin.boxmodel-left > span", value: "auto" }, { - selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", + selector: ".boxmodel-margin.boxmodel-bottom > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-right > span", + selector: ".boxmodel-margin.boxmodel-right > span", value: "auto" }, { - selector: ".old-boxmodel-padding.old-boxmodel-top > span", + selector: ".boxmodel-padding.boxmodel-top > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-left > span", + selector: ".boxmodel-padding.boxmodel-left > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", + selector: ".boxmodel-padding.boxmodel-bottom > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-right > span", + selector: ".boxmodel-padding.boxmodel-right > span", value: 20 }, { - selector: ".old-boxmodel-border.old-boxmodel-top > span", + selector: ".boxmodel-border.boxmodel-top > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-left > span", + selector: ".boxmodel-border.boxmodel-left > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-bottom > span", + selector: ".boxmodel-border.boxmodel-bottom > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-right > span", + selector: ".boxmodel-border.boxmodel-right > span", value: 10 }, ]; var res2 = [ { - selector: "#old-boxmodel-element-size", + selector: ".boxmodel-element-size", value: "190" + "\u00D7" + "210" }, { - selector: ".old-boxmodel-size > span", + selector: ".boxmodel-size > span", value: "100" + "\u00D7" + "150" }, { - selector: ".old-boxmodel-margin.old-boxmodel-top > span", + selector: ".boxmodel-margin.boxmodel-top > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-left > span", + selector: ".boxmodel-margin.boxmodel-left > span", value: "auto" }, { - selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", + selector: ".boxmodel-margin.boxmodel-bottom > span", value: 30 }, { - selector: ".old-boxmodel-margin.old-boxmodel-right > span", + selector: ".boxmodel-margin.boxmodel-right > span", value: "auto" }, { - selector: ".old-boxmodel-padding.old-boxmodel-top > span", + selector: ".boxmodel-padding.boxmodel-top > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-left > span", + selector: ".boxmodel-padding.boxmodel-left > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", + selector: ".boxmodel-padding.boxmodel-bottom > span", value: 20 }, { - selector: ".old-boxmodel-padding.old-boxmodel-right > span", + selector: ".boxmodel-padding.boxmodel-right > span", value: 50 }, { - selector: ".old-boxmodel-border.old-boxmodel-top > span", + selector: ".boxmodel-border.boxmodel-top > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-left > span", + selector: ".boxmodel-border.boxmodel-left > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-bottom > span", + selector: ".boxmodel-border.boxmodel-bottom > span", value: 10 }, { - selector: ".old-boxmodel-border.old-boxmodel-right > span", + selector: ".boxmodel-border.boxmodel-right > span", value: 10 }, ]; @@ -142,7 +142,7 @@ add_task(function* () { function* testInitialValues(inspector, view) { info("Test that the initial values of the box model are correct"); - let viewdoc = view.doc; + let viewdoc = view.document; for (let i = 0; i < res1.length; i++) { let elt = viewdoc.querySelector(res1[i].selector); @@ -153,7 +153,7 @@ function* testInitialValues(inspector, view) { function* testChangingValues(inspector, view, testActor) { info("Test that changing the document updates the box model"); - let viewdoc = view.doc; + let viewdoc = view.document; let onUpdated = waitForUpdate(inspector); yield testActor.setAttribute("div", "style", diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js similarity index 74% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js index 5bb882dd6e7b..37736152011b 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel.js @@ -36,21 +36,21 @@ function* testEditingMargins(inspector, view, testActor) { "Should be no margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("3", {}, view.doc.defaultView); + EventUtils.synthesizeKey("3", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-top")), "3px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-top")), "", @@ -66,35 +66,35 @@ function* testKeyBindings(inspector, view, testActor) { "Should be no margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-left > span"); is(span.textContent, 10, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "10px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_UP", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_UP", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "11px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "11px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_DOWN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DOWN", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "10px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "10px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view.doc.defaultView); + EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "20px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", "Should be the right margin-top on the element."); @@ -109,22 +109,22 @@ function* testEscapeToUndo(inspector, view, testActor) { "Should be the right margin-top on the element."); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-left > span"); is(span.textContent, 20, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "20px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-left")), "", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "margin-left")), "20px", @@ -140,22 +140,22 @@ function* testDeletingValue(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-right > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-right > span"); is(span.textContent, 15, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "15px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "margin-right")), "", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "margin-right")), "", "Should be the right margin-top on the element."); @@ -167,26 +167,26 @@ function* testRefocusingOnClick(inspector, view, testActor) { yield selectNode("#div4", inspector); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 1, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); info("Click in the already opened editor input"); - EventUtils.synthesizeMouseAtCenter(editor, {}, view.doc.defaultView); - is(editor, view.doc.activeElement, + EventUtils.synthesizeMouseAtCenter(editor, {}, view.document.defaultView); + is(editor, view.document.activeElement, "Inplace editor input should still have focus."); info("Check the input can still be used as expected"); - EventUtils.synthesizeKey("VK_UP", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_UP", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "2px", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div4", "margin-top")), "2px", "Should have updated the margin."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div4", "margin-top")), "2px", "Should be the right margin-top on the element."); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js similarity index 74% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js index ca5194266319..ab49a191429c 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_allproperties.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_allproperties.js @@ -32,22 +32,22 @@ function* testEditing(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-bottom > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-bottom > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("7", {}, view.doc.defaultView); + EventUtils.synthesizeKey("7", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "7", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-bottom")), "7px", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "padding-bottom")), "7px", "Should be the right padding."); @@ -63,22 +63,22 @@ function* testEditingAndCanceling(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("8", {}, view.doc.defaultView); + EventUtils.synthesizeKey("8", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "8", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "8px", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-left")), "5px", @@ -91,22 +91,22 @@ function* testDeleting(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should be the right padding."); @@ -122,22 +122,22 @@ function* testDeletingAndCanceling(inspector, view, testActor) { yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-left > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-left > span"); is(span.textContent, 5, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "5px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_DELETE", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-left")), "", "Should have updated the padding"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-left")), "5px", diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js similarity index 69% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js index f56f584ddf95..c251dfbc162f 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_bluronclick.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_bluronclick.js @@ -30,45 +30,45 @@ add_task(function* () { function* testClickingOutsideEditor(view) { info("Test that clicking outside the editor blurs it"); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 10, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); info("Click next to the opened editor input."); let onBlur = once(editor, "blur"); let rect = editor.getBoundingClientRect(); EventUtils.synthesizeMouse(editor, rect.width + 10, rect.height / 2, {}, - view.doc.defaultView); + view.document.defaultView); yield onBlur; - is(view.doc.querySelector(".styleinspector-propertyeditor"), null, + is(view.document.querySelector(".styleinspector-propertyeditor"), null, "Inplace editor has been removed."); } function* testClickingBelowContainer(view) { info("Test that clicking below the box-model container blurs it"); - let span = view.doc.querySelector(".old-boxmodel-margin.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-margin.boxmodel-top > span"); is(span.textContent, 10, "Should have the right value in the box model."); - info("Test that clicking below the old-boxmodel-container blurs the opened editor"); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + info("Test that clicking below the boxmodel-container blurs the opened editor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); let onBlur = once(editor, "blur"); - let container = view.doc.querySelector("#old-boxmodel-container"); + let container = view.document.querySelector(".boxmodel-container"); // Using getBoxQuads here because getBoundingClientRect (and therefore synthesizeMouse) // use an erroneous height of ~50px for the boxmodel-container. let bounds = container.getBoxQuads({relativeTo: view.doc})[0].bounds; EventUtils.synthesizeMouseAtPoint( bounds.left + 10, bounds.top + bounds.height + 10, - {}, view.doc.defaultView); + {}, view.document.defaultView); yield onBlur; - is(view.doc.querySelector(".styleinspector-propertyeditor"), null, + is(view.document.querySelector(".styleinspector-propertyeditor"), null, "Inplace editor has been removed."); } diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js similarity index 82% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js index 5550a66423a4..197ef99d3b47 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_border.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_border.js @@ -24,15 +24,15 @@ add_task(function* () { "Should have the right border"); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-border.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-border.boxmodel-top > span"); is(span.textContent, 0, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "0", "Should have the right value in the editor."); - EventUtils.synthesizeKey("1", {}, view.doc.defaultView); + EventUtils.synthesizeKey("1", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "1", "Should have the right value in the editor."); @@ -41,7 +41,7 @@ add_task(function* () { is((yield getStyle(testActor, "#div1", "border-top-style")), "solid", "Should have the right border"); - EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "border-top-width")), "", diff --git a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js similarity index 74% rename from devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js index f3f41e4d04ed..28ba89898062 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_editablemodel_stylerules.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_editablemodel_stylerules.js @@ -31,30 +31,30 @@ function* testUnits(inspector, view, testActor) { "Should have the right padding"); yield selectNode("#div1", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-top > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-top > span"); is(span.textContent, 3, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "3px", "Should have the right value in the editor."); - EventUtils.synthesizeKey("1", {}, view.doc.defaultView); + EventUtils.synthesizeKey("1", {}, view.document.defaultView); yield waitForUpdate(inspector); - EventUtils.synthesizeKey("e", {}, view.doc.defaultView); + EventUtils.synthesizeKey("e", {}, view.document.defaultView); yield waitForUpdate(inspector); is((yield getStyle(testActor, "#div1", "padding-top")), "", "An invalid value is handled cleanly"); - EventUtils.synthesizeKey("m", {}, view.doc.defaultView); + EventUtils.synthesizeKey("m", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "1em", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div1", "padding-top")), "1em", "Should have updated the padding."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div1", "padding-top")), "1em", "Should be the right padding."); @@ -68,22 +68,22 @@ function* testValueComesFromStyleRule(inspector, view, testActor) { "Should have the right border-bottom-width"); yield selectNode("#div2", inspector); - let span = view.doc.querySelector(".old-boxmodel-border.old-boxmodel-bottom > span"); + let span = view.document.querySelector(".boxmodel-border.boxmodel-bottom > span"); is(span.textContent, 16, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "1em", "Should have the right value in the editor."); - EventUtils.synthesizeKey("0", {}, view.doc.defaultView); + EventUtils.synthesizeKey("0", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "0", "Should have the right value in the editor."); is((yield getStyle(testActor, "#div2", "border-bottom-width")), "0px", "Should have updated the border."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div2", "border-bottom-width")), "0px", "Should be the right border-bottom-width."); @@ -97,15 +97,15 @@ function* testShorthandsAreParsed(inspector, view, testActor) { "Should have the right padding"); yield selectNode("#div3", inspector); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-right > span"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-right > span"); is(span.textContent, 32, "Should have the right value in the box model."); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); ok(editor, "Should have opened the editor."); is(editor.value, "2em", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); is((yield getStyle(testActor, "#div3", "padding-right")), "", "Should be the right padding."); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_guides.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js similarity index 89% rename from devtools/client/inspector/components/test/browser_boxmodel_guides.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js index 9dcaaa609cce..51457e25cd46 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_guides.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_guides.js @@ -28,16 +28,16 @@ add_task(function* () { highlighterOptions = options; }; - let elt = view.doc.getElementById("old-boxmodel-margins"); + let elt = view.document.querySelector(".boxmodel-margins"); yield testGuideOnLayoutHover(elt, "margin", inspector, view); - elt = view.doc.getElementById("old-boxmodel-borders"); + elt = view.document.querySelector(".boxmodel-borders"); yield testGuideOnLayoutHover(elt, "border", inspector, view); - elt = view.doc.getElementById("old-boxmodel-padding"); + elt = view.document.querySelector(".boxmodel-paddings"); yield testGuideOnLayoutHover(elt, "padding", inspector, view); - elt = view.doc.getElementById("old-boxmodel-content"); + elt = view.document.querySelector(".boxmodel-content"); yield testGuideOnLayoutHover(elt, "content", inspector, view); }); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_navigation.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js similarity index 75% rename from devtools/client/inspector/components/test/browser_boxmodel_navigation.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js index 6b8439710227..deee191fd2aa 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_navigation.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_navigation.js @@ -29,50 +29,50 @@ add_task(function* () { function* testInitialFocus(inspector, view) { info("Test that the focus is on margin layout."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-margins", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-margins", "Should be set to the margin layout."); } function* testChangingLevels(inspector, view) { info("Test that using arrow keys updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); EventUtils.synthesizeKey("VK_ESCAPE", {}); EventUtils.synthesizeKey("VK_DOWN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-borders", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-borders", "Should be set to the border layout."); EventUtils.synthesizeKey("VK_DOWN", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-padding", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-padding", "Should be set to the padding layout."); EventUtils.synthesizeKey("VK_UP", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-borders", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-borders", "Should be set to the border layout."); EventUtils.synthesizeKey("VK_UP", {}); - is(boxmodel.getAttribute("aria-activedescendant"), "old-boxmodel-margins", + is(boxmodel.getAttribute("aria-activedescendant"), "boxmodel-margins", "Should be set to the margin layout."); } function* testTabbingWrapAround(inspector, view) { info("Test that using arrow keys updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); EventUtils.synthesizeKey("VK_RETURN", {}); let editLevel = boxmodel.getAttribute("aria-activedescendant"); let dataLevel = viewdoc.getElementById(editLevel).getAttribute("data-box"); let editBoxes = [...viewdoc.querySelectorAll( - `[data-box="${dataLevel}"].old-boxmodel-editable`)]; + `[data-box="${dataLevel}"].boxmodel-editable`)]; EventUtils.synthesizeKey("VK_ESCAPE", {}); editBoxes[3].focus(); @@ -87,12 +87,12 @@ function* testTabbingWrapAround(inspector, view) { function* testChangingLevelsByClicking(inspector, view) { info("Test that clicking on levels updates level."); let viewdoc = view.doc; - let boxmodel = viewdoc.getElementById("old-boxmodel-wrapper"); + let boxmodel = viewdoc.getElementById("boxmodel-wrapper"); boxmodel.focus(); - let marginLayout = viewdoc.getElementById("old-boxmodel-margins"); - let borderLayout = viewdoc.getElementById("old-boxmodel-borders"); - let paddingLayout = viewdoc.getElementById("old-boxmodel-padding"); + let marginLayout = viewdoc.getElementById("boxmodel-margins"); + let borderLayout = viewdoc.getElementById("boxmodel-borders"); + let paddingLayout = viewdoc.getElementById("boxmodel-padding"); let layouts = [paddingLayout, borderLayout, marginLayout]; layouts.forEach(layout => { diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js new file mode 100644 index 000000000000..e931830b534f --- /dev/null +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_rotate-labels-on-sides.js @@ -0,0 +1,49 @@ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that longer values are rotated on the side + +const res1 = [ + {selector: ".boxmodel-margin.boxmodel-top > span", value: 30}, + {selector: ".boxmodel-margin.boxmodel-left > span", value: "auto"}, + {selector: ".boxmodel-margin.boxmodel-bottom > span", value: 30}, + {selector: ".boxmodel-margin.boxmodel-right > span", value: "auto"}, + {selector: ".boxmodel-padding.boxmodel-top > span", value: 20}, + {selector: ".boxmodel-padding.boxmodel-left > span", value: 2000000}, + {selector: ".boxmodel-padding.boxmodel-bottom > span", value: 20}, + {selector: ".boxmodel-padding.boxmodel-right > span", value: 20}, + {selector: ".boxmodel-border.boxmodel-top > span", value: 10}, + {selector: ".boxmodel-border.boxmodel-left > span", value: 10}, + {selector: ".boxmodel-border.boxmodel-bottom > span", value: 10}, + {selector: ".boxmodel-border.boxmodel-right > span", value: 10}, +]; + +const TEST_URI = encodeURIComponent([ + "", + "
" +].join("")); +const LONG_TEXT_ROTATE_LIMIT = 3; + +add_task(function* () { + yield addTab("data:text/html," + TEST_URI); + let {inspector, view} = yield openBoxModelView(); + yield selectNode("div", inspector); + + for (let i = 0; i < res1.length; i++) { + let elt = view.document.querySelector(res1[i].selector); + let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT; + let classList = elt.parentNode.classList; + let canBeRotated = classList.contains("boxmodel-left") || + classList.contains("boxmodel-right"); + let isRotated = classList.contains("boxmodel-rotate"); + + is(canBeRotated && isLong, + isRotated, res1[i].selector + " correctly rotated."); + } +}); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_sync.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js similarity index 77% rename from devtools/client/inspector/components/test/browser_boxmodel_sync.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js index c0fde5c80b86..382675ad2d2d 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_sync.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_sync.js @@ -17,14 +17,14 @@ add_task(function* () { yield selectNode("p", inspector); info("Modify padding-bottom in box model view"); - let span = view.doc.querySelector(".old-boxmodel-padding.old-boxmodel-bottom > span"); - EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView); - let editor = view.doc.querySelector(".styleinspector-propertyeditor"); + let span = view.document.querySelector(".boxmodel-padding.boxmodel-bottom > span"); + EventUtils.synthesizeMouseAtCenter(span, {}, view.document.defaultView); + let editor = view.document.querySelector(".styleinspector-propertyeditor"); - EventUtils.synthesizeKey("7", {}, view.doc.defaultView); + EventUtils.synthesizeKey("7", {}, view.document.defaultView); yield waitForUpdate(inspector); is(editor.value, "7", "Should have the right value in the editor."); - EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); + EventUtils.synthesizeKey("VK_RETURN", {}, view.document.defaultView); let onRuleViewRefreshed = once(inspector, "rule-view-refreshed"); let onRuleViewSelected = once(inspector.sidebar, "ruleview-selected"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_tooltips.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js similarity index 83% rename from devtools/client/inspector/components/test/browser_boxmodel_tooltips.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js index cdbbd6885bb4..6f5997635fe8 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_tooltips.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_tooltips.js @@ -76,24 +76,24 @@ add_task(function* () { info("Checking the regions tooltips"); - ok(view.doc.querySelector("#old-boxmodel-margins").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-margins").hasAttribute("title"), "The margin region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-margins").getAttribute("title"), "margin", + is(view.document.querySelector(".boxmodel-margins").getAttribute("title"), "margin", "The margin region has the correct tooltip content"); - ok(view.doc.querySelector("#old-boxmodel-borders").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-borders").hasAttribute("title"), "The border region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-borders").getAttribute("title"), "border", + is(view.document.querySelector(".boxmodel-borders").getAttribute("title"), "border", "The border region has the correct tooltip content"); - ok(view.doc.querySelector("#old-boxmodel-padding").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-paddings").hasAttribute("title"), "The padding region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-padding").getAttribute("title"), "padding", + is(view.document.querySelector(".boxmodel-paddings").getAttribute("title"), "padding", "The padding region has the correct tooltip content"); - ok(view.doc.querySelector("#old-boxmodel-content").hasAttribute("title"), + ok(view.document.querySelector(".boxmodel-content").hasAttribute("title"), "The content region has a tooltip"); - is(view.doc.querySelector("#old-boxmodel-content").getAttribute("title"), "content", + is(view.document.querySelector(".boxmodel-content").getAttribute("title"), "content", "The content region has the correct tooltip content"); for (let {selector, values} of VALUES_TEST_DATA) { @@ -108,7 +108,7 @@ add_task(function* () { let name = view.map[key].property; let expectedTooltipData = values.find(o => o.name === name); - let el = view.doc.querySelector(view.map[key].selector); + let el = view.document.querySelector(view.map[key].selector); ok(el.hasAttribute("title"), "The " + name + " value has a tooltip"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js similarity index 88% rename from devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js index 62918310ceea..1638b4791415 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_update-after-navigation.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js @@ -32,12 +32,11 @@ add_task(function* () { function* testFirstPage(inspector, view, testActor) { info("Test that the box model view works on the first page"); - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let paddingElt = view.doc.querySelector( - ".old-boxmodel-padding.old-boxmodel-top > span"); + let paddingElt = view.document.querySelector( + ".boxmodel-padding.boxmodel-top > span"); is(paddingElt.textContent, "50"); info("Listening for box model view changes and modifying the padding"); @@ -53,11 +52,10 @@ function* testFirstPage(inspector, view, testActor) { function* testSecondPage(inspector, view, testActor) { info("Test that the box model view works on the second page"); - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); + let sizeElt = view.document.querySelector(".boxmodel-size > span"); is(sizeElt.textContent, "100" + "\u00D7" + "100"); info("Listening for box model view changes and modifying the size"); @@ -73,13 +71,12 @@ function* testSecondPage(inspector, view, testActor) { function* testBackToFirstPage(inspector, view, testActor) { info("Test that the box model view works on the first page after going back"); - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value, which is the" + "modified value from step one because of the bfcache"); - let paddingElt = view.doc.querySelector( - ".old-boxmodel-padding.old-boxmodel-top > span"); + let paddingElt = view.document.querySelector( + ".boxmodel-padding.boxmodel-top > span"); is(paddingElt.textContent, "20"); info("Listening for box model view changes and modifying the padding"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js similarity index 90% rename from devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js index 111031e115d2..f589a82632e8 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_update-after-reload.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js @@ -22,12 +22,11 @@ add_task(function* () { }); function* assertBoxModelView(inspector, view, testActor) { - info("Selecting the test node"); yield selectNode("p", inspector); info("Checking that the box model view shows the right value"); - let paddingElt = view.doc.querySelector( - ".old-boxmodel-padding.old-boxmodel-top > span"); + let paddingElt = view.document.querySelector( + ".boxmodel-padding.boxmodel-top > span"); is(paddingElt.textContent, "50"); info("Listening for box model view changes and modifying the padding"); diff --git a/devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js similarity index 96% rename from devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js rename to devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js index 9aedb1b581ac..3e7b82e46b10 100644 --- a/devtools/client/inspector/components/test/browser_boxmodel_update-in-iframes.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js @@ -22,7 +22,7 @@ function* testResizingInIframe(inspector, view, testActor) { yield selectNodeInIframe2("div", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); + let sizeElt = view.document.querySelector(".boxmodel-size > span"); is(sizeElt.textContent, "400\u00D7200"); info("Listening for box model view changes and modifying its size"); @@ -47,7 +47,7 @@ function* testReflowsAfterIframeDeletion(inspector, view, testActor) { yield selectNodeInIframe1("p", inspector); info("Checking that the box model view shows the right value"); - let sizeElt = view.doc.querySelector(".old-boxmodel-size > span"); + let sizeElt = view.document.querySelector(".boxmodel-size > span"); is(sizeElt.textContent, "100\u00D7100"); info("Listening for box model view changes and modifying its size"); diff --git a/devtools/client/inspector/components/test/doc_boxmodel_iframe1.html b/devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe1.html similarity index 100% rename from devtools/client/inspector/components/test/doc_boxmodel_iframe1.html rename to devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe1.html diff --git a/devtools/client/inspector/components/test/doc_boxmodel_iframe2.html b/devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe2.html similarity index 100% rename from devtools/client/inspector/components/test/doc_boxmodel_iframe2.html rename to devtools/client/inspector/boxmodel/test/doc_boxmodel_iframe2.html diff --git a/devtools/client/inspector/components/test/head.js b/devtools/client/inspector/boxmodel/test/head.js similarity index 86% rename from devtools/client/inspector/components/test/head.js rename to devtools/client/inspector/boxmodel/test/head.js index fa86b5e9e179..6074a45ec8ec 100644 --- a/devtools/client/inspector/components/test/head.js +++ b/devtools/client/inspector/boxmodel/test/head.js @@ -58,7 +58,7 @@ function openBoxModelView() { return { toolbox: data.toolbox, inspector: data.inspector, - view: data.inspector.computedview.boxModelView, + view: data.inspector.computedview, testActor: data.testActor }; }); @@ -85,3 +85,14 @@ function setStyle(testActor, selector, propertyName, value) { .style.${propertyName} = "${value}"; `); } + +/** + * The box model doesn't participate in the inspector's update mechanism, so simply + * calling the default selectNode isn't enough to guarantee that the box model view has + * finished updating. We also need to wait for the "boxmodel-view-updated" event. + */ +var _selectNode = selectNode; +selectNode = function* (node, inspector, reason) { + yield _selectNode(node, inspector, reason); + yield waitForUpdate(inspector); +}; diff --git a/devtools/client/inspector/components/moz.build b/devtools/client/inspector/components/moz.build index 0ef321ae1da1..50556cf26ecf 100644 --- a/devtools/client/inspector/components/moz.build +++ b/devtools/client/inspector/components/moz.build @@ -8,5 +8,3 @@ DevToolsModules( 'inspector-tab-panel.css', 'inspector-tab-panel.js', ) - -BROWSER_CHROME_MANIFESTS += ['test/browser.ini'] diff --git a/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js b/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js deleted file mode 100644 index df667e6d1a55..000000000000 --- a/devtools/client/inspector/components/test/browser_boxmodel_rotate-labels-on-sides.js +++ /dev/null @@ -1,49 +0,0 @@ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -// Test that longer values are rotated on the side - -const res1 = [ - {selector: ".old-boxmodel-margin.old-boxmodel-top > span", value: 30}, - {selector: ".old-boxmodel-margin.old-boxmodel-left > span", value: "auto"}, - {selector: ".old-boxmodel-margin.old-boxmodel-bottom > span", value: 30}, - {selector: ".old-boxmodel-margin.old-boxmodel-right > span", value: "auto"}, - {selector: ".old-boxmodel-padding.old-boxmodel-top > span", value: 20}, - {selector: ".old-boxmodel-padding.old-boxmodel-left > span", value: 2000000}, - {selector: ".old-boxmodel-padding.old-boxmodel-bottom > span", value: 20}, - {selector: ".old-boxmodel-padding.old-boxmodel-right > span", value: 20}, - {selector: ".old-boxmodel-border.old-boxmodel-top > span", value: 10}, - {selector: ".old-boxmodel-border.old-boxmodel-left > span", value: 10}, - {selector: ".old-boxmodel-border.old-boxmodel-bottom > span", value: 10}, - {selector: ".old-boxmodel-border.old-boxmodel-right > span", value: 10}, -]; - -const TEST_URI = encodeURIComponent([ - "", - "
" -].join("")); -const LONG_TEXT_ROTATE_LIMIT = 3; - -add_task(function* () { - yield addTab("data:text/html," + TEST_URI); - let {inspector, view} = yield openBoxModelView(); - yield selectNode("div", inspector); - - for (let i = 0; i < res1.length; i++) { - let elt = view.doc.querySelector(res1[i].selector); - let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT; - let classList = elt.parentNode.classList; - let canBeRotated = classList.contains("old-boxmodel-left") || - classList.contains("old-boxmodel-right"); - let isRotated = classList.contains("old-boxmodel-rotate"); - - is(canBeRotated && isLong, - isRotated, res1[i].selector + " correctly rotated."); - } -}); diff --git a/devtools/client/inspector/computed/computed.js b/devtools/client/inspector/computed/computed.js index 3754e5584c9c..c721518adff8 100644 --- a/devtools/client/inspector/computed/computed.js +++ b/devtools/client/inspector/computed/computed.js @@ -180,6 +180,7 @@ function CssComputedView(inspector, document, pageStyle) { let doc = this.styleDocument; this.element = doc.getElementById("propertyContainer"); + this.boxModelWrapper = doc.getElementById("boxmodel-wrapper"); this.searchField = doc.getElementById("computedview-searchbox"); this.searchClearButton = doc.getElementById("computedview-searchinput-clear"); this.includeBrowserStylesCheckbox = @@ -559,10 +560,10 @@ CssComputedView.prototype = { this._filterChangedTimeout = setTimeout(() => { if (this.searchField.value.length > 0) { this.searchField.setAttribute("filled", true); - this.inspector.emit("computed-view-filtered", true); + this.boxModelWrapper.hidden = true; } else { this.searchField.removeAttribute("filled"); - this.inspector.emit("computed-view-filtered", false); + this.boxModelWrapper.hidden = false; } this.refreshPanel(); @@ -632,7 +633,7 @@ CssComputedView.prototype = { onShowBoxModelHighlighter, }) ); - ReactDOM.render(provider, this.styleDocument.getElementById("boxmodel-wrapper")); + ReactDOM.render(provider, this.boxModelWrapper); }, /** @@ -813,7 +814,7 @@ CssComputedView.prototype = { // Nodes used in templating this.element = null; - this.panel = null; + this.boxModelWrapper = null; this.searchField = null; this.searchClearButton = null; this.includeBrowserStylesCheckbox = null; diff --git a/devtools/client/inspector/computed/test/browser_computed_search-filter.js b/devtools/client/inspector/computed/test/browser_computed_search-filter.js index d5b2634f4884..f8f25f23a639 100644 --- a/devtools/client/inspector/computed/test/browser_computed_search-filter.js +++ b/devtools/client/inspector/computed/test/browser_computed_search-filter.js @@ -34,7 +34,7 @@ function* testToggleDefaultStyles(inspector, computedView) { function* testAddTextInFilter(inspector, computedView) { info("setting filter text to \"color\""); let doc = computedView.styleDocument; - let boxModelWrapper = doc.querySelector("#old-boxmodel-wrapper"); + let boxModelWrapper = doc.getElementById("boxmodel-wrapper"); let searchField = computedView.searchField; let onRefreshed = inspector.once("computed-view-refreshed"); let win = computedView.styleWindow; diff --git a/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js b/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js index 2b4a29618310..39dcefcb3838 100644 --- a/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js +++ b/devtools/client/inspector/computed/test/browser_computed_search-filter_clear.js @@ -50,7 +50,7 @@ function* testClearSearchFilter(inspector, computedView) { let win = computedView.styleWindow; let doc = computedView.styleDocument; - let boxModelWrapper = doc.querySelector("#old-boxmodel-wrapper"); + let boxModelWrapper = doc.getElementById("boxmodel-wrapper"); let propertyViews = computedView.propertyViews; let searchField = computedView.searchField; let searchClearButton = computedView.searchClearButton; diff --git a/devtools/client/inspector/inspector.js b/devtools/client/inspector/inspector.js index 493aa7792e10..2b6aecf95c80 100644 --- a/devtools/client/inspector/inspector.js +++ b/devtools/client/inspector/inspector.js @@ -78,8 +78,6 @@ const PORTRAIT_MODE_WIDTH = 700; * - computed-view-sourcelinks-updated * Fired when the stylesheet source links have been updated (when switching * to source-mapped files) - * - computed-view-filtered - * Fired when the computed rules view is filtered * - rule-view-refreshed * Fired when the rule view updates to a new node * - rule-view-sourcelinks-updated diff --git a/devtools/client/inspector/test/browser_inspector_textbox-menu.js b/devtools/client/inspector/test/browser_inspector_textbox-menu.js index a5e0e75622d8..b3e9ca68515c 100644 --- a/devtools/client/inspector/test/browser_inspector_textbox-menu.js +++ b/devtools/client/inspector/test/browser_inspector_textbox-menu.js @@ -66,7 +66,7 @@ add_task(function* () { info("Testing the box-model region"); let margin = inspector.panelDoc.querySelector( - ".old-boxmodel-margin.old-boxmodel-top > span"); + ".boxmodel-margin.boxmodel-top > span"); EventUtils.synthesizeMouseAtCenter(margin, {}, inspector.panelWin); yield checkTextBox(inspector.panelDoc.activeElement, toolbox); }); From 04a8b1ea18fa94b539e7f1e58107c78612f8ee86 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Wed, 22 Feb 2017 20:48:23 +0100 Subject: [PATCH 099/102] Bug 1336198 - Part 10: Fix race condition in boxmodel tests. r=gl MozReview-Commit-ID: IDBgbnlMX2c --- .../client/inspector/boxmodel/box-model.js | 16 ++++-- ...rowser_boxmodel_update-after-navigation.js | 6 ++- .../browser_boxmodel_update-after-reload.js | 3 +- .../browser_boxmodel_update-in-iframes.js | 3 +- .../client/inspector/boxmodel/test/head.js | 54 ++++++++++++++----- devtools/client/inspector/test/shared-head.js | 10 +++- 6 files changed, 72 insertions(+), 20 deletions(-) diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js index 839b608f5ca2..0290d69af88a 100644 --- a/devtools/client/inspector/boxmodel/box-model.js +++ b/devtools/client/inspector/boxmodel/box-model.js @@ -126,8 +126,16 @@ BoxModel.prototype = { /** * Updates the box model panel by dispatching the new layout data. + * + * @param {String} reason + * Optional string describing the reason why the boxmodel is updated. */ - updateBoxModel() { + updateBoxModel(reason) { + this._updateReasons = this._updateReasons || []; + if (reason) { + this._updateReasons.push(reason); + } + let lastRequest = Task.spawn((function* () { if (!(this.isPanelVisible() && this.inspector.selection.isConnected() && @@ -151,9 +159,11 @@ BoxModel.prototype = { return this._lastRequest; } + this.inspector.emit("boxmodel-view-updated", this._updateReasons); + this._lastRequest = null; + this._updateReasons = []; - this.inspector.emit("boxmodel-view-updated"); return null; }).bind(this)).catch(console.error); @@ -173,7 +183,7 @@ BoxModel.prototype = { this.trackReflows(); } - this.updateBoxModel(); + this.updateBoxModel("new-selection"); }, /** diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js index 1638b4791415..dfcf8ceefe5a 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js @@ -17,14 +17,16 @@ add_task(function* () { yield testFirstPage(inspector, view, testActor); info("Navigate to the second page"); + let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval(`content.location.href="${IFRAME2}"`); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; yield testSecondPage(inspector, view, testActor); info("Go back to the first page"); + onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval("content.history.back();"); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; yield testBackToFirstPage(inspector, view, testActor); }); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js index f589a82632e8..f1ed222949a4 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js @@ -14,8 +14,9 @@ add_task(function* () { yield assertBoxModelView(inspector, view, testActor); info("Reload the page"); + let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.reload(); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; info("Test that the box model view works on the reloaded page"); yield assertBoxModelView(inspector, view, testActor); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js index 3e7b82e46b10..6aa10e441ae9 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js @@ -40,8 +40,9 @@ function* testReflowsAfterIframeDeletion(inspector, view, testActor) { "iframe"); info("Deleting the iframe2"); + let onInspectorUpdated = inspector.once("inspector-updated"); yield removeIframe2(testActor); - yield inspector.once("inspector-updated"); + yield onInspectorUpdated; info("Selecting the test node in iframe1"); yield selectNodeInIframe1("p", inspector); diff --git a/devtools/client/inspector/boxmodel/test/head.js b/devtools/client/inspector/boxmodel/test/head.js index 6074a45ec8ec..b842968a5595 100644 --- a/devtools/client/inspector/boxmodel/test/head.js +++ b/devtools/client/inspector/boxmodel/test/head.js @@ -19,12 +19,13 @@ registerCleanupFunction(() => { /** * Highlight a node and set the inspector's current selection to the node or * the first match of the given css selector. - * @param {String|NodeFront} selectorOrNodeFront - * The selector for the node to be set, or the nodeFront - * @param {InspectorPanel} inspector - * The instance of InspectorPanel currently loaded in the toolbox - * @return a promise that resolves when the inspector is updated with the new - * node + * + * @param {String|NodeFront} selectorOrNodeFront + * The selector for the node to be set, or the nodeFront. + * @param {InspectorPanel} inspector + * The instance of InspectorPanel currently loaded in the toolbox. + * @return {Promise} a promise that resolves when the inspector is updated with the new + * node. */ function* selectAndHighlightNode(selectorOrNodeFront, inspector) { info("Highlighting and selecting the node " + selectorOrNodeFront); @@ -38,8 +39,9 @@ function* selectAndHighlightNode(selectorOrNodeFront, inspector) { /** * Open the toolbox, with the inspector tool visible, and the computed view * sidebar tab selected to display the box model view. - * @return a promise that resolves when the inspector is ready and the box model - * view is visible and ready + * + * @return {Promise} a promise that resolves when the inspector is ready and the box model + * view is visible and ready. */ function openBoxModelView() { return openInspectorSidebarTab("computedview").then(data => { @@ -66,10 +68,37 @@ function openBoxModelView() { /** * Wait for the boxmodel-view-updated event. - * @return a promise + * + * @param {InspectorPanel} inspector + * The instance of InspectorPanel currently loaded in the toolbox. + * @param {Boolean} waitForSelectionUpdate + * Should the boxmodel-view-updated event come from a new selection. + * @return {Promise} a promise */ -function waitForUpdate(inspector) { - return inspector.once("boxmodel-view-updated"); +function waitForUpdate(inspector, waitForSelectionUpdate) { + return new Promise(resolve => { + inspector.on("boxmodel-view-updated", function onUpdate(e, reasons) { + // Wait for another update event if we are waiting for a selection related event. + if (waitForSelectionUpdate && !reasons.includes("new-selection")) { + return; + } + + inspector.off("boxmodel-view-updated", onUpdate); + resolve(); + }); + }); +} + +/** + * Wait for both boxmode-view-updated and markuploaded events. + * + * @return {Promise} a promise that resolves when both events have been received. + */ +function waitForMarkupLoaded(inspector) { + return Promise.all([ + waitForUpdate(inspector), + inspector.once("markuploaded"), + ]); } function getStyle(testActor, selector, propertyName) { @@ -93,6 +122,7 @@ function setStyle(testActor, selector, propertyName, value) { */ var _selectNode = selectNode; selectNode = function* (node, inspector, reason) { + let onUpdate = waitForUpdate(inspector, true); yield _selectNode(node, inspector, reason); - yield waitForUpdate(inspector); + yield onUpdate; }; diff --git a/devtools/client/inspector/test/shared-head.js b/devtools/client/inspector/test/shared-head.js index a953d547e7f5..c42690a2813e 100644 --- a/devtools/client/inspector/test/shared-head.js +++ b/devtools/client/inspector/test/shared-head.js @@ -52,7 +52,15 @@ var openInspectorSidebarTab = Task.async(function* (id) { let {toolbox, inspector, testActor} = yield openInspector(); info("Selecting the " + id + " sidebar"); - inspector.sidebar.select(id); + + if (id === "computedview" || id === "layoutview") { + // The layout and computed views should wait until the box-model widget is ready. + let onBoxModelViewReady = inspector.once("boxmodel-view-updated"); + inspector.sidebar.select(id); + yield onBoxModelViewReady; + } else { + inspector.sidebar.select(id); + } return { toolbox, From bccb83b4c8fee91c8bcb9e2968b0755e38c86abc Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Thu, 16 Feb 2017 11:10:05 +0100 Subject: [PATCH 100/102] Bug 1338449 - use ToIndex to convert TA indices for atomic operations. r=shu --- js/src/builtin/AtomicsObject.cpp | 6 +++--- js/src/jit-test/tests/atomics/basic-tests.js | 6 ++++-- js/src/tests/shell/futex-apis.js | 5 ++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/js/src/builtin/AtomicsObject.cpp b/js/src/builtin/AtomicsObject.cpp index f710a95863be..298c273cbbbb 100644 --- a/js/src/builtin/AtomicsObject.cpp +++ b/js/src/builtin/AtomicsObject.cpp @@ -84,8 +84,8 @@ ReportBadArrayType(JSContext* cx) static bool ReportOutOfRange(JSContext* cx) { - // Use JSMSG_BAD_INDEX here even if it is generic, since that is - // the message used by NonStandardToIndex for its initial range checking. + // Use JSMSG_BAD_INDEX here, it is what ToIndex uses for some cases that it + // reports directly. JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX); return false; } @@ -115,7 +115,7 @@ static bool GetTypedArrayIndex(JSContext* cx, HandleValue v, Handle view, uint32_t* offset) { uint64_t index; - if (!NonStandardToIndex(cx, v, &index)) + if (!ToIndex(cx, v, &index)) return false; if (index >= view->length()) return ReportOutOfRange(cx); diff --git a/js/src/jit-test/tests/atomics/basic-tests.js b/js/src/jit-test/tests/atomics/basic-tests.js index 3869d5dd6a7d..59f7e5ac3008 100644 --- a/js/src/jit-test/tests/atomics/basic-tests.js +++ b/js/src/jit-test/tests/atomics/basic-tests.js @@ -212,8 +212,10 @@ function testRangeCAS(a) { assertErrorMessage(() => Atomics.compareExchange(a, -1, 0, 1), RangeError, msg); assertEq(a[0], 0); - assertErrorMessage(() => Atomics.compareExchange(a, "hi", 0, 1), RangeError, msg); - assertEq(a[0], 0); + // Converted to 0 + assertEq(Atomics.compareExchange(a, "hi", 0, 33), 0); + assertEq(a[0], 33); + a[0] = 0; assertErrorMessage(() => Atomics.compareExchange(a, a.length + 5, 0, 1), RangeError, msg); assertEq(a[0], 0); diff --git a/js/src/tests/shell/futex-apis.js b/js/src/tests/shell/futex-apis.js index b3e0acd55488..6df6ca3e3739 100644 --- a/js/src/tests/shell/futex-apis.js +++ b/js/src/tests/shell/futex-apis.js @@ -99,9 +99,8 @@ let sab = new SharedArrayBuffer(16); let indices = [ (view) => -1, (view) => view.length, (view) => view.length*2, - (view) => undefined, - (view) => '3.5', - (view) => { password: "qumquat" } ]; + (view) => '-3.5', + (view) => ({ valueOf: () => -8 }) ]; for ( let iidx=0 ; iidx < indices.length ; iidx++ ) { let Idx = indices[iidx](view); From eb67afc06af25903eec9db373cd96508d30e59b5 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Thu, 23 Feb 2017 23:04:13 +0100 Subject: [PATCH 101/102] Bug 1341255 - Profiler tidyups: remove StackEntry, rename ProfileEntry to ProfileBufferEntry (part 1: remove StackEntry). r=n.nethercote. --- tools/profiler/core/platform.cpp | 18 +++++++++--------- tools/profiler/public/PseudoStack.h | 16 ++-------------- xpcom/threads/ThreadStackHelper.cpp | 6 +++--- xpcom/threads/ThreadStackHelper.h | 5 ++--- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index cfb0c9991df9..7beaecedc7bd 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -251,12 +251,12 @@ AddDynamicCodeLocationTag(ThreadInfo& aInfo, const char* aStr) } static void -AddPseudoEntry(volatile StackEntry& entry, ThreadInfo& aInfo, +AddPseudoEntry(volatile js::ProfileEntry& entry, ThreadInfo& aInfo, PseudoStack* stack, void* lastpc) { // Pseudo-frames with the BEGIN_PSEUDO_JS flag are just annotations and // should not be recorded in the profile. - if (entry.hasFlag(StackEntry::BEGIN_PSEUDO_JS)) { + if (entry.hasFlag(js::ProfileEntry::BEGIN_PSEUDO_JS)) { return; } @@ -307,8 +307,8 @@ AddPseudoEntry(volatile StackEntry& entry, ThreadInfo& aInfo, } uint32_t category = entry.category(); - MOZ_ASSERT(!(category & StackEntry::IS_CPP_ENTRY)); - MOZ_ASSERT(!(category & StackEntry::FRAME_LABEL_COPY)); + MOZ_ASSERT(!(category & js::ProfileEntry::IS_CPP_ENTRY)); + MOZ_ASSERT(!(category & js::ProfileEntry::FRAME_LABEL_COPY)); if (category) { aInfo.addTag(ProfileEntry::Category((int)category)); @@ -345,7 +345,7 @@ MergeStacksIntoProfile(ThreadInfo& aInfo, TickSample* aSample, NativeStack& aNativeStack) { PseudoStack* pseudoStack = aInfo.Stack(); - volatile StackEntry* pseudoFrames = pseudoStack->mStack; + volatile js::ProfileEntry* pseudoFrames = pseudoStack->mStack; uint32_t pseudoCount = pseudoStack->stackSize(); // Make a copy of the JS stack into a JSFrame array. This is necessary since, @@ -420,7 +420,7 @@ MergeStacksIntoProfile(ThreadInfo& aInfo, TickSample* aSample, uint8_t* nativeStackAddr = nullptr; if (pseudoIndex != pseudoCount) { - volatile StackEntry& pseudoFrame = pseudoFrames[pseudoIndex]; + volatile js::ProfileEntry& pseudoFrame = pseudoFrames[pseudoIndex]; if (pseudoFrame.isCpp()) { lastPseudoCppStackAddr = (uint8_t*) pseudoFrame.stackAddress(); @@ -471,7 +471,7 @@ MergeStacksIntoProfile(ThreadInfo& aInfo, TickSample* aSample, // Check to see if pseudoStack frame is top-most. if (pseudoStackAddr > jsStackAddr && pseudoStackAddr > nativeStackAddr) { MOZ_ASSERT(pseudoIndex < pseudoCount); - volatile StackEntry& pseudoFrame = pseudoFrames[pseudoIndex]; + volatile js::ProfileEntry& pseudoFrame = pseudoFrames[pseudoIndex]; AddPseudoEntry(pseudoFrame, aInfo, pseudoStack, nullptr); pseudoIndex++; continue; @@ -616,7 +616,7 @@ DoNativeBacktrace(ThreadInfo& aInfo, TickSample* aSample) for (uint32_t i = pseudoStack->stackSize(); i > 0; --i) { // The pseudostack grows towards higher indices, so we iterate // backwards (from callee to caller). - volatile StackEntry& entry = pseudoStack->mStack[i - 1]; + volatile js::ProfileEntry& entry = pseudoStack->mStack[i - 1]; if (!entry.isJs() && strcmp(entry.label(), "EnterJIT") == 0) { // Found JIT entry frame. Unwind up to that point (i.e., force // the stack walk to stop before the block of saved registers; @@ -2486,7 +2486,7 @@ profiler_get_backtrace_noalloc(char *output, size_t outputSize) return; } - volatile StackEntry *pseudoFrames = pseudoStack->mStack; + volatile js::ProfileEntry *pseudoFrames = pseudoStack->mStack; uint32_t pseudoCount = pseudoStack->stackSize(); for (uint32_t i = 0; i < pseudoCount; i++) { diff --git a/tools/profiler/public/PseudoStack.h b/tools/profiler/public/PseudoStack.h index cabeabe17f9d..c5e8765401cf 100644 --- a/tools/profiler/public/PseudoStack.h +++ b/tools/profiler/public/PseudoStack.h @@ -49,18 +49,6 @@ LinuxKernelMemoryBarrierFunc pLinuxKernelMemoryBarrier __attribute__((weak)) = # error "Memory clobber not supported for your platform." #endif -// A stack entry exists to allow the JS engine to inform the Gecko Profiler of -// the current backtrace, but also to instrument particular points in C++ in -// case stack walking is not available on the platform we are running on. -// -// Each entry has a descriptive string, a relevant stack address, and some extra -// information the JS engine might want to inform the Gecko Profiler of. This -// class inherits from the JS engine's version of the entry to ensure that the -// size and layout of the two representations are consistent. -class StackEntry : public js::ProfileEntry -{ -}; - class ProfilerMarkerPayload; template class ProfilerLinkedList; @@ -273,7 +261,7 @@ public: return; } - volatile StackEntry& entry = mStack[mStackPointer]; + volatile js::ProfileEntry& entry = mStack[mStackPointer]; // Make sure we increment the pointer after the name has been written such // that mStack is always consistent. @@ -412,7 +400,7 @@ private: public: // The list of active checkpoints. - StackEntry volatile mStack[1024]; + js::ProfileEntry volatile mStack[1024]; private: // A list of pending markers that must be moved to the circular buffer. diff --git a/xpcom/threads/ThreadStackHelper.cpp b/xpcom/threads/ThreadStackHelper.cpp index 66d1d550adcd..0e2437e8cc6e 100644 --- a/xpcom/threads/ThreadStackHelper.cpp +++ b/xpcom/threads/ThreadStackHelper.cpp @@ -426,7 +426,7 @@ GetPathAfterComponent(const char* filename, const char (&component)[LEN]) { } // namespace const char* -ThreadStackHelper::AppendJSEntry(const volatile StackEntry* aEntry, +ThreadStackHelper::AppendJSEntry(const volatile js::ProfileEntry* aEntry, intptr_t& aAvailableBufferSize, const char* aPrevLabel) { @@ -513,8 +513,8 @@ ThreadStackHelper::FillStackBuffer() intptr_t availableBufferSize = intptr_t(reservedBufferSize); // Go from front to back - const volatile StackEntry* entry = mPseudoStack->mStack; - const volatile StackEntry* end = entry + mPseudoStack->stackSize(); + const volatile js::ProfileEntry* entry = mPseudoStack->mStack; + const volatile js::ProfileEntry* end = entry + mPseudoStack->stackSize(); // Deduplicate identical, consecutive frames const char* prevLabel = nullptr; for (; reservedSize-- && entry != end; entry++) { diff --git a/xpcom/threads/ThreadStackHelper.h b/xpcom/threads/ThreadStackHelper.h index 12e9e6487b9d..347f7c0d4c97 100644 --- a/xpcom/threads/ThreadStackHelper.h +++ b/xpcom/threads/ThreadStackHelper.h @@ -8,8 +8,7 @@ #define mozilla_ThreadStackHelper_h #include "mozilla/ThreadHangStats.h" - -#include "GeckoProfiler.h" +#include "js/ProfilingStack.h" #include @@ -79,7 +78,7 @@ private: void FillStackBuffer(); void FillThreadContext(void* aContext = nullptr); #ifdef MOZ_THREADSTACKHELPER_PSEUDO - const char* AppendJSEntry(const volatile StackEntry* aEntry, + const char* AppendJSEntry(const volatile js::ProfileEntry* aEntry, intptr_t& aAvailableBufferSize, const char* aPrevLabel); #endif From c3547e1c36f61de8aea7bba916c42ee599178d4c Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Thu, 23 Feb 2017 23:05:23 +0100 Subject: [PATCH 102/102] Bug 1341255 - Profiler tidyups: remove StackEntry, rename ProfileEntry to ProfileBufferEntry (part 2: rename ProfileEntry). r=n.nethercote. --- tools/profiler/core/ProfileBuffer.cpp | 8 +-- tools/profiler/core/ProfileBuffer.h | 6 +- ...rofileEntry.cpp => ProfileBufferEntry.cpp} | 57 ++++++++++--------- .../{ProfileEntry.h => ProfileBufferEntry.h} | 38 +++++++------ tools/profiler/core/SyncProfile.h | 1 - tools/profiler/core/ThreadInfo.cpp | 2 +- tools/profiler/core/ThreadInfo.h | 2 +- .../profiler/core/platform-linux-android.cpp | 1 - tools/profiler/core/platform-win32.cpp | 1 - tools/profiler/core/platform.cpp | 34 +++++------ tools/profiler/gecko/ThreadResponsiveness.cpp | 1 - tools/profiler/moz.build | 2 +- .../tests/gtest/ThreadProfileTest.cpp | 17 +++--- 13 files changed, 87 insertions(+), 83 deletions(-) rename tools/profiler/core/{ProfileEntry.cpp => ProfileBufferEntry.cpp} (93%) rename tools/profiler/core/{ProfileEntry.h => ProfileBufferEntry.h} (92%) diff --git a/tools/profiler/core/ProfileBuffer.cpp b/tools/profiler/core/ProfileBuffer.cpp index 864f212b3bf4..3ae360420c1a 100644 --- a/tools/profiler/core/ProfileBuffer.cpp +++ b/tools/profiler/core/ProfileBuffer.cpp @@ -6,7 +6,7 @@ #include "ProfileBuffer.h" ProfileBuffer::ProfileBuffer(int aEntrySize) - : mEntries(mozilla::MakeUnique(aEntrySize)) + : mEntries(mozilla::MakeUnique(aEntrySize)) , mWritePos(0) , mReadPos(0) , mEntrySize(aEntrySize) @@ -22,7 +22,7 @@ ProfileBuffer::~ProfileBuffer() } // Called from signal, call only reentrant functions -void ProfileBuffer::addTag(const ProfileEntry& aTag) +void ProfileBuffer::addTag(const ProfileBufferEntry& aTag) { mEntries[mWritePos++] = aTag; if (mWritePos == mEntrySize) { @@ -34,7 +34,7 @@ void ProfileBuffer::addTag(const ProfileEntry& aTag) } if (mWritePos == mReadPos) { // Keep one slot open. - mEntries[mReadPos] = ProfileEntry(); + mEntries[mReadPos] = ProfileBufferEntry(); mReadPos = (mReadPos + 1) % mEntrySize; } } @@ -85,7 +85,7 @@ char* ProfileBuffer::processDynamicTag(int readPos, bool seenNullByte = false; while (readAheadPos != mWritePos && !seenNullByte) { (*tagsConsumed)++; - ProfileEntry readAheadEntry = mEntries[readAheadPos]; + ProfileBufferEntry readAheadEntry = mEntries[readAheadPos]; for (size_t pos = 0; pos < sizeof(void*); pos++) { tagBuff[tagBuffPos] = readAheadEntry.mTagChars[pos]; if (tagBuff[tagBuffPos] == '\0' || tagBuffPos == DYNAMIC_MAX_STRING-2) { diff --git a/tools/profiler/core/ProfileBuffer.h b/tools/profiler/core/ProfileBuffer.h index 427afcd379f1..93d549d83b4e 100644 --- a/tools/profiler/core/ProfileBuffer.h +++ b/tools/profiler/core/ProfileBuffer.h @@ -6,7 +6,7 @@ #ifndef MOZ_PROFILE_BUFFER_H #define MOZ_PROFILE_BUFFER_H -#include "ProfileEntry.h" +#include "ProfileBufferEntry.h" #include "platform.h" #include "ProfileJSONWriter.h" #include "mozilla/RefPtr.h" @@ -21,7 +21,7 @@ public: virtual ~ProfileBuffer(); - void addTag(const ProfileEntry& aTag); + void addTag(const ProfileBufferEntry& aTag); void StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime, JSContext* cx, UniqueStacks& aUniqueStacks); void StreamMarkersToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime, @@ -42,7 +42,7 @@ protected: public: // Circular buffer 'Keep One Slot Open' implementation for simplicity - mozilla::UniquePtr mEntries; + mozilla::UniquePtr mEntries; // Points to the next entry we will write to, which is also the one at which // we need to stop reading. diff --git a/tools/profiler/core/ProfileEntry.cpp b/tools/profiler/core/ProfileBufferEntry.cpp similarity index 93% rename from tools/profiler/core/ProfileEntry.cpp rename to tools/profiler/core/ProfileBufferEntry.cpp index 8a3cc88edf16..9a5acdb95488 100644 --- a/tools/profiler/core/ProfileEntry.cpp +++ b/tools/profiler/core/ProfileBufferEntry.cpp @@ -16,7 +16,7 @@ #include "js/TrackedOptimizationInfo.h" // Self -#include "ProfileEntry.h" +#include "ProfileBufferEntry.h" using mozilla::JSONWriter; using mozilla::MakeUnique; @@ -27,55 +27,55 @@ using mozilla::TimeStamp; using mozilla::UniquePtr; //////////////////////////////////////////////////////////////////////// -// BEGIN ProfileEntry +// BEGIN ProfileBufferEntry -ProfileEntry::ProfileEntry() +ProfileBufferEntry::ProfileBufferEntry() : mTagData(nullptr) , mKind(Kind::INVALID) { } // aTagData must not need release (i.e. be a string from the text segment) -ProfileEntry::ProfileEntry(Kind aKind, const char *aTagData) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, const char *aTagData) : mTagData(aTagData) , mKind(aKind) { } -ProfileEntry::ProfileEntry(Kind aKind, ProfilerMarker *aTagMarker) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, ProfilerMarker *aTagMarker) : mTagMarker(aTagMarker) , mKind(aKind) { } -ProfileEntry::ProfileEntry(Kind aKind, void *aTagPtr) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, void *aTagPtr) : mTagPtr(aTagPtr) , mKind(aKind) { } -ProfileEntry::ProfileEntry(Kind aKind, double aTagDouble) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, double aTagDouble) : mTagDouble(aTagDouble) , mKind(aKind) { } -ProfileEntry::ProfileEntry(Kind aKind, uintptr_t aTagOffset) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, uintptr_t aTagOffset) : mTagOffset(aTagOffset) , mKind(aKind) { } -ProfileEntry::ProfileEntry(Kind aKind, Address aTagAddress) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, Address aTagAddress) : mTagAddress(aTagAddress) , mKind(aKind) { } -ProfileEntry::ProfileEntry(Kind aKind, int aTagInt) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, int aTagInt) : mTagInt(aTagInt) , mKind(aKind) { } -ProfileEntry::ProfileEntry(Kind aKind, char aTagChar) +ProfileBufferEntry::ProfileBufferEntry(Kind aKind, char aTagChar) : mTagChar(aTagChar) , mKind(aKind) { } -// END ProfileEntry +// END ProfileBufferEntry //////////////////////////////////////////////////////////////////////// class JSONSchemaWriter @@ -153,8 +153,8 @@ public: } }; -// As mentioned in ProfileEntry.h, the JSON format contains many arrays whose -// elements are laid out according to various schemas to help +// As mentioned in ProfileBufferEntry.h, the JSON format contains many +// arrays whose elements are laid out according to various schemas to help // de-duplication. This RAII class helps write these arrays by keeping track of // the last non-null element written and adding the appropriate number of null // elements when writing new non-null elements. It also automatically opens and @@ -589,13 +589,13 @@ void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThre UniquePtr tagBuff = MakeUnique(DYNAMIC_MAX_STRING); while (readPos != mWritePos) { - ProfileEntry entry = mEntries[readPos]; + ProfileBufferEntry entry = mEntries[readPos]; if (entry.isThreadId()) { currentThreadID = entry.mTagInt; currentTime.reset(); int readAheadPos = (readPos + 1) % mEntrySize; if (readAheadPos != mWritePos) { - ProfileEntry readAheadEntry = mEntries[readAheadPos]; + ProfileBufferEntry readAheadEntry = mEntries[readAheadPos]; if (readAheadEntry.isTime()) { currentTime = Some(readAheadEntry.mTagDouble); } @@ -603,27 +603,27 @@ void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThre } if (currentThreadID == aThreadId && (currentTime.isNothing() || *currentTime >= aSinceTime)) { switch (entry.kind()) { - case ProfileEntry::Kind::Responsiveness: + case ProfileBufferEntry::Kind::Responsiveness: if (sample.isSome()) { sample->mResponsiveness = Some(entry.mTagDouble); } break; - case ProfileEntry::Kind::ResidentMemory: + case ProfileBufferEntry::Kind::ResidentMemory: if (sample.isSome()) { sample->mRSS = Some(entry.mTagDouble); } break; - case ProfileEntry::Kind::UnsharedMemory: + case ProfileBufferEntry::Kind::UnsharedMemory: if (sample.isSome()) { sample->mUSS = Some(entry.mTagDouble); } break; - case ProfileEntry::Kind::FrameNumber: + case ProfileBufferEntry::Kind::FrameNumber: if (sample.isSome()) { sample->mFrameNumber = Some(entry.mTagInt); } break; - case ProfileEntry::Kind::Sample: + case ProfileBufferEntry::Kind::Sample: { // end the previous sample if there was one if (sample.isSome()) { @@ -642,7 +642,7 @@ void ProfileBuffer::StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThre aUniqueStacks.BeginStack(UniqueStacks::OnStackFrameKey("(root)")); int framePos = (readPos + 1) % mEntrySize; - ProfileEntry frame = mEntries[framePos]; + ProfileBufferEntry frame = mEntries[framePos]; while (framePos != mWritePos && !frame.isSample() && !frame.isThreadId()) { int incBy = 1; frame = mEntries[framePos]; @@ -725,7 +725,7 @@ void ProfileBuffer::StreamMarkersToJSON(SpliceableJSONWriter& aWriter, int aThre int readPos = mReadPos; int currentThreadID = -1; while (readPos != mWritePos) { - ProfileEntry entry = mEntries[readPos]; + ProfileBufferEntry entry = mEntries[readPos]; if (entry.isThreadId()) { currentThreadID = entry.mTagInt; } else if (currentThreadID == aThreadId && entry.isMarker()) { @@ -745,7 +745,7 @@ int ProfileBuffer::FindLastSampleOfThread(int aThreadId) for (int readPos = (mWritePos + mEntrySize - 1) % mEntrySize; readPos != (mReadPos + mEntrySize - 1) % mEntrySize; readPos = (readPos + mEntrySize - 1) % mEntrySize) { - ProfileEntry entry = mEntries[readPos]; + ProfileBufferEntry entry = mEntries[readPos]; if (entry.isThreadId() && entry.mTagInt == aThreadId) { return readPos; } @@ -771,14 +771,15 @@ ProfileBuffer::DuplicateLastSample(int aThreadId, const TimeStamp& aStartTime) readPos != mWritePos; readPos = (readPos + 1) % mEntrySize) { switch (mEntries[readPos].kind()) { - case ProfileEntry::Kind::ThreadId: + case ProfileBufferEntry::Kind::ThreadId: // We're done. return; - case ProfileEntry::Kind::Time: + case ProfileBufferEntry::Kind::Time: // Copy with new time - addTag(ProfileEntry::Time((TimeStamp::Now() - aStartTime).ToMilliseconds())); + addTag(ProfileBufferEntry::Time((TimeStamp::Now() - + aStartTime).ToMilliseconds())); break; - case ProfileEntry::Kind::Marker: + case ProfileBufferEntry::Kind::Marker: // Don't copy markers break; default: diff --git a/tools/profiler/core/ProfileEntry.h b/tools/profiler/core/ProfileBufferEntry.h similarity index 92% rename from tools/profiler/core/ProfileEntry.h rename to tools/profiler/core/ProfileBufferEntry.h index 6cec5b0babe1..25c328d8d6a2 100644 --- a/tools/profiler/core/ProfileEntry.h +++ b/tools/profiler/core/ProfileBufferEntry.h @@ -4,8 +4,8 @@ * 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 MOZ_PROFILE_ENTRY_H -#define MOZ_PROFILE_ENTRY_H +#ifndef ProfileBufferEntry_h +#define ProfileBufferEntry_h #include #include "GeckoProfiler.h" @@ -25,7 +25,7 @@ #include "mozilla/HashFunctions.h" #include "mozilla/UniquePtr.h" -#define PROFILE_ENTRY_KIND_LIST(_) \ +#define PROFILE_BUFFER_ENTRY_KIND_LIST(_) \ _(Category, int) \ _(CodeLocation, const char *) \ _(EmbeddedString, void *) \ @@ -46,34 +46,36 @@ #pragma pack(push, 1) #endif -class ProfileEntry +class ProfileBufferEntry { public: enum class Kind : uint8_t { INVALID = 0, # define DEF_ENUM_(k, t) k, - PROFILE_ENTRY_KIND_LIST(DEF_ENUM_) + PROFILE_BUFFER_ENTRY_KIND_LIST(DEF_ENUM_) # undef DEF_ENUM_ LIMIT }; - ProfileEntry(); + ProfileBufferEntry(); private: // aTagData must not need release (i.e. be a string from the text segment) - ProfileEntry(Kind aKind, const char *aTagData); - ProfileEntry(Kind aKind, void *aTagPtr); - ProfileEntry(Kind aKind, ProfilerMarker *aTagMarker); - ProfileEntry(Kind aKind, double aTagDouble); - ProfileEntry(Kind aKind, uintptr_t aTagOffset); - ProfileEntry(Kind aKind, Address aTagAddress); - ProfileEntry(Kind aKind, int aTagLine); - ProfileEntry(Kind aKind, char aTagChar); + ProfileBufferEntry(Kind aKind, const char *aTagData); + ProfileBufferEntry(Kind aKind, void *aTagPtr); + ProfileBufferEntry(Kind aKind, ProfilerMarker *aTagMarker); + ProfileBufferEntry(Kind aKind, double aTagDouble); + ProfileBufferEntry(Kind aKind, uintptr_t aTagOffset); + ProfileBufferEntry(Kind aKind, Address aTagAddress); + ProfileBufferEntry(Kind aKind, int aTagLine); + ProfileBufferEntry(Kind aKind, char aTagChar); public: # define DEF_MAKE_(k, t) \ - static ProfileEntry k(t val) { return ProfileEntry(Kind::k, val); } - PROFILE_ENTRY_KIND_LIST(DEF_MAKE_) + static ProfileBufferEntry k(t val) { \ + return ProfileBufferEntry(Kind::k, val); \ + } + PROFILE_BUFFER_ENTRY_KIND_LIST(DEF_MAKE_) # undef DEF_MAKE_ Kind kind() const { return mKind; } @@ -81,7 +83,7 @@ public: # define DEF_METHODS_(k, t) \ bool is##k() const { return hasKind(Kind::k); } - PROFILE_ENTRY_KIND_LIST(DEF_METHODS_) + PROFILE_BUFFER_ENTRY_KIND_LIST(DEF_METHODS_) # undef DEF_METHODS_ const ProfilerMarker* getMarker() { @@ -408,4 +410,4 @@ private: // } // -#endif /* ndef MOZ_PROFILE_ENTRY_H */ +#endif /* ndef ProfileBufferEntry_h */ diff --git a/tools/profiler/core/SyncProfile.h b/tools/profiler/core/SyncProfile.h index af7689002a40..96ebaafcfd62 100644 --- a/tools/profiler/core/SyncProfile.h +++ b/tools/profiler/core/SyncProfile.h @@ -7,7 +7,6 @@ #ifndef __SYNCPROFILE_H #define __SYNCPROFILE_H -#include "ProfileEntry.h" #include "ThreadInfo.h" class SyncProfile : public ThreadInfo diff --git a/tools/profiler/core/ThreadInfo.cpp b/tools/profiler/core/ThreadInfo.cpp index 808d7834f79b..35f1b7d778f2 100644 --- a/tools/profiler/core/ThreadInfo.cpp +++ b/tools/profiler/core/ThreadInfo.cpp @@ -64,7 +64,7 @@ ThreadInfo::CanInvokeJS() const } void -ThreadInfo::addTag(const ProfileEntry& aTag) +ThreadInfo::addTag(const ProfileBufferEntry& aTag) { mBuffer->addTag(aTag); } diff --git a/tools/profiler/core/ThreadInfo.h b/tools/profiler/core/ThreadInfo.h index addfb6d7b402..8da8e783df10 100644 --- a/tools/profiler/core/ThreadInfo.h +++ b/tools/profiler/core/ThreadInfo.h @@ -57,7 +57,7 @@ class ThreadInfo { public: bool hasProfile() { return !!mBuffer; } - void addTag(const ProfileEntry& aTag); + void addTag(const ProfileBufferEntry& aTag); // Track a marker which has been inserted into the thread profile. // This marker can safely be deleted once the generation has diff --git a/tools/profiler/core/platform-linux-android.cpp b/tools/profiler/core/platform-linux-android.cpp index 6b9cbdba4bcc..bdb481dbe407 100644 --- a/tools/profiler/core/platform-linux-android.cpp +++ b/tools/profiler/core/platform-linux-android.cpp @@ -63,7 +63,6 @@ #include "prenv.h" #include "mozilla/LinuxSignal.h" #include "mozilla/DebugOnly.h" -#include "ProfileEntry.h" // Memory profile #include "nsMemoryReporterManager.h" diff --git a/tools/profiler/core/platform-win32.cpp b/tools/profiler/core/platform-win32.cpp index e66438025a37..26ed3bc50df6 100644 --- a/tools/profiler/core/platform-win32.cpp +++ b/tools/profiler/core/platform-win32.cpp @@ -31,7 +31,6 @@ #include #include #include -#include "ProfileEntry.h" // Memory profile #include "nsMemoryReporterManager.h" diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index 7beaecedc7bd..89c63bdf634d 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -232,7 +232,7 @@ public: static void AddDynamicCodeLocationTag(ThreadInfo& aInfo, const char* aStr) { - aInfo.addTag(ProfileEntry::CodeLocation("")); + aInfo.addTag(ProfileBufferEntry::CodeLocation("")); size_t strLen = strlen(aStr) + 1; // +1 for the null terminator for (size_t j = 0; j < strLen; ) { @@ -246,7 +246,7 @@ AddDynamicCodeLocationTag(ThreadInfo& aInfo, const char* aStr) j += sizeof(void*) / sizeof(char); // Cast to *((void**) to pass the text data to a void*. - aInfo.addTag(ProfileEntry::EmbeddedString(*((void**)(&text[0])))); + aInfo.addTag(ProfileBufferEntry::EmbeddedString(*((void**)(&text[0])))); } } @@ -293,7 +293,7 @@ AddPseudoEntry(volatile js::ProfileEntry& entry, ThreadInfo& aInfo, lineno = entry.line(); } } else { - aInfo.addTag(ProfileEntry::CodeLocation(sampleLabel)); + aInfo.addTag(ProfileBufferEntry::CodeLocation(sampleLabel)); // XXX: Bug 1010578. Don't assume a CPP entry and try to get the line for // js entries as well. @@ -303,7 +303,7 @@ AddPseudoEntry(volatile js::ProfileEntry& entry, ThreadInfo& aInfo, } if (lineno != -1) { - aInfo.addTag(ProfileEntry::LineNumber(lineno)); + aInfo.addTag(ProfileBufferEntry::LineNumber(lineno)); } uint32_t category = entry.category(); @@ -311,7 +311,7 @@ AddPseudoEntry(volatile js::ProfileEntry& entry, ThreadInfo& aInfo, MOZ_ASSERT(!(category & js::ProfileEntry::FRAME_LABEL_COPY)); if (category) { - aInfo.addTag(ProfileEntry::Category((int)category)); + aInfo.addTag(ProfileBufferEntry::Category((int)category)); } } @@ -399,7 +399,7 @@ MergeStacksIntoProfile(ThreadInfo& aInfo, TickSample* aSample, } // Start the sample with a root entry. - aInfo.addTag(ProfileEntry::Sample("(root)")); + aInfo.addTag(ProfileBufferEntry::Sample("(root)")); // While the pseudo-stack array is ordered oldest-to-youngest, the JS and // native arrays are ordered youngest-to-oldest. We must add frames to aInfo @@ -502,7 +502,7 @@ MergeStacksIntoProfile(ThreadInfo& aInfo, TickSample* aSample, MOZ_ASSERT(jsFrame.kind == JS::ProfilingFrameIterator::Frame_Ion || jsFrame.kind == JS::ProfilingFrameIterator::Frame_Baseline); aInfo.addTag( - ProfileEntry::JitReturnAddr(jsFrames[jsIndex].returnAddress)); + ProfileBufferEntry::JitReturnAddr(jsFrames[jsIndex].returnAddress)); } jsIndex--; @@ -514,7 +514,7 @@ MergeStacksIntoProfile(ThreadInfo& aInfo, TickSample* aSample, if (nativeStackAddr) { MOZ_ASSERT(nativeIndex >= 0); void* addr = (void*)aNativeStack.pc_array[nativeIndex]; - aInfo.addTag(ProfileEntry::NativeLeafAddr(addr)); + aInfo.addTag(ProfileBufferEntry::NativeLeafAddr(addr)); } if (nativeIndex >= 0) { nativeIndex--; @@ -772,7 +772,7 @@ DoSampleStackTrace(ThreadInfo& aInfo, TickSample* aSample, MergeStacksIntoProfile(aInfo, aSample, nativeStack); if (aSample && aAddLeafAddresses) { - aInfo.addTag(ProfileEntry::NativeLeafAddr((void*)aSample->pc)); + aInfo.addTag(ProfileBufferEntry::NativeLeafAddr((void*)aSample->pc)); } } @@ -783,10 +783,11 @@ Tick(TickSample* aSample) { ThreadInfo& currThreadInfo = *aSample->threadInfo; - currThreadInfo.addTag(ProfileEntry::ThreadId(currThreadInfo.ThreadId())); + currThreadInfo.addTag( + ProfileBufferEntry::ThreadId(currThreadInfo.ThreadId())); mozilla::TimeDuration delta = aSample->timestamp - gStartTime; - currThreadInfo.addTag(ProfileEntry::Time(delta.ToMilliseconds())); + currThreadInfo.addTag(ProfileBufferEntry::Time(delta.ToMilliseconds())); PseudoStack* stack = currThreadInfo.Stack(); @@ -808,7 +809,7 @@ Tick(TickSample* aSample) while (pendingMarkersList && pendingMarkersList->peek()) { ProfilerMarker* marker = pendingMarkersList->popHead(); currThreadInfo.addStoredMarker(marker); - currThreadInfo.addTag(ProfileEntry::Marker(marker)); + currThreadInfo.addTag(ProfileBufferEntry::Marker(marker)); } } @@ -816,23 +817,24 @@ Tick(TickSample* aSample) mozilla::TimeDuration delta = currThreadInfo.GetThreadResponsiveness()->GetUnresponsiveDuration( aSample->timestamp); - currThreadInfo.addTag(ProfileEntry::Responsiveness(delta.ToMilliseconds())); + currThreadInfo.addTag( + ProfileBufferEntry::Responsiveness(delta.ToMilliseconds())); } // rssMemory is equal to 0 when we are not recording. if (aSample->rssMemory != 0) { - currThreadInfo.addTag(ProfileEntry::ResidentMemory( + currThreadInfo.addTag(ProfileBufferEntry::ResidentMemory( static_cast(aSample->rssMemory))); } // ussMemory is equal to 0 when we are not recording. if (aSample->ussMemory != 0) { - currThreadInfo.addTag(ProfileEntry::UnsharedMemory( + currThreadInfo.addTag(ProfileBufferEntry::UnsharedMemory( static_cast(aSample->ussMemory))); } if (gLastFrameNumber != gFrameNumber) { - currThreadInfo.addTag(ProfileEntry::FrameNumber(gFrameNumber)); + currThreadInfo.addTag(ProfileBufferEntry::FrameNumber(gFrameNumber)); gLastFrameNumber = gFrameNumber; } } diff --git a/tools/profiler/gecko/ThreadResponsiveness.cpp b/tools/profiler/gecko/ThreadResponsiveness.cpp index 6d2d7e0025de..b7e317e6abc8 100644 --- a/tools/profiler/gecko/ThreadResponsiveness.cpp +++ b/tools/profiler/gecko/ThreadResponsiveness.cpp @@ -9,7 +9,6 @@ #include "nsThreadUtils.h" #include "nsITimer.h" #include "mozilla/Monitor.h" -#include "ProfileEntry.h" using mozilla::Monitor; using mozilla::MonitorAutoLock; diff --git a/tools/profiler/moz.build b/tools/profiler/moz.build index 5b83893a4ab6..cc85bb43706e 100644 --- a/tools/profiler/moz.build +++ b/tools/profiler/moz.build @@ -22,7 +22,7 @@ if CONFIG['MOZ_GECKO_PROFILER']: UNIFIED_SOURCES += [ 'core/platform.cpp', 'core/ProfileBuffer.cpp', - 'core/ProfileEntry.cpp', + 'core/ProfileBufferEntry.cpp', 'core/ProfileJSONWriter.cpp', 'core/ProfilerBacktrace.cpp', 'core/ProfilerMarkers.cpp', diff --git a/tools/profiler/tests/gtest/ThreadProfileTest.cpp b/tools/profiler/tests/gtest/ThreadProfileTest.cpp index a7f04bca329e..3c05b813c6ed 100644 --- a/tools/profiler/tests/gtest/ThreadProfileTest.cpp +++ b/tools/profiler/tests/gtest/ThreadProfileTest.cpp @@ -5,7 +5,7 @@ #include "gtest/gtest.h" -#include "ProfileEntry.h" +#include "ProfileBufferEntry.h" #include "ThreadInfo.h" // Make sure we can initialize our thread profile @@ -23,9 +23,10 @@ TEST(ThreadProfile, InsertOneTag) { Thread::tid_t tid = 1000; ThreadInfo info("testThread", tid, true, stack, nullptr); RefPtr pb = new ProfileBuffer(10); - pb->addTag(ProfileEntry::Time(123.1)); + pb->addTag(ProfileBufferEntry::Time(123.1)); ASSERT_TRUE(pb->mEntries != nullptr); - ASSERT_TRUE(pb->mEntries[pb->mReadPos].kind() == ProfileEntry::Kind::Time); + ASSERT_TRUE(pb->mEntries[pb->mReadPos].kind() == + ProfileBufferEntry::Kind::Time); ASSERT_TRUE(pb->mEntries[pb->mReadPos].mTagDouble == 123.1); } @@ -37,12 +38,13 @@ TEST(ThreadProfile, InsertTagsNoWrap) { RefPtr pb = new ProfileBuffer(100); int test_size = 50; for (int i = 0; i < test_size; i++) { - pb->addTag(ProfileEntry::Time(i)); + pb->addTag(ProfileBufferEntry::Time(i)); } ASSERT_TRUE(pb->mEntries != nullptr); int readPos = pb->mReadPos; while (readPos != pb->mWritePos) { - ASSERT_TRUE(pb->mEntries[readPos].kind() == ProfileEntry::Kind::Time); + ASSERT_TRUE(pb->mEntries[readPos].kind() == + ProfileBufferEntry::Kind::Time); ASSERT_TRUE(pb->mEntries[readPos].mTagDouble == readPos); readPos = (readPos + 1) % pb->mEntrySize; } @@ -59,13 +61,14 @@ TEST(ThreadProfile, InsertTagsWrap) { RefPtr pb = new ProfileBuffer(buffer_size); int test_size = 43; for (int i = 0; i < test_size; i++) { - pb->addTag(ProfileEntry::Time(i)); + pb->addTag(ProfileBufferEntry::Time(i)); } ASSERT_TRUE(pb->mEntries != nullptr); int readPos = pb->mReadPos; int ctr = 0; while (readPos != pb->mWritePos) { - ASSERT_TRUE(pb->mEntries[readPos].kind() == ProfileEntry::Kind::Time); + ASSERT_TRUE(pb->mEntries[readPos].kind() == + ProfileBufferEntry::Kind::Time); // the first few tags were discarded when we wrapped ASSERT_TRUE(pb->mEntries[readPos].mTagDouble == ctr + (test_size - tags)); ctr++;