Skip to content

Commit

Permalink
Bug 1252211 - Remove DOMCI for TreeSelection, XULCommandDispatcher an…
Browse files Browse the repository at this point in the history
…d XULControllers. r=bz.
  • Loading branch information
petervanderbeken committed May 18, 2017
1 parent dde7299 commit 7753cb5
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 100 deletions.
19 changes: 18 additions & 1 deletion caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#include "nsContentUtils.h"
#include "nsJSUtils.h"
#include "nsILoadInfo.h"
#include "nsIDOMXULCommandDispatcher.h"
#include "nsITreeSelection.h"

// This should be probably defined on some other place... but I couldn't find it
#define WEBAPPS_PERM_NAME "webapps-manage"
Expand Down Expand Up @@ -1208,7 +1210,8 @@ nsScriptSecurityManager::CanCreateWrapper(JSContext *cx,
}

// We give remote-XUL whitelisted domains a free pass here. See bug 932906.
if (!xpc::AllowContentXBLScope(js::GetContextCompartment(cx)))
JSCompartment* contextCompartment = js::GetContextCompartment(cx);
if (!xpc::AllowContentXBLScope(contextCompartment))
{
return NS_OK;
}
Expand All @@ -1218,6 +1221,20 @@ nsScriptSecurityManager::CanCreateWrapper(JSContext *cx,
return NS_OK;
}

// We want to expose nsIDOMXULCommandDispatcher and nsITreeSelection implementations
// in XBL scopes.
if (xpc::IsContentXBLScope(contextCompartment)) {
nsCOMPtr<nsIDOMXULCommandDispatcher> dispatcher = do_QueryInterface(aObj);
if (dispatcher) {
return NS_OK;
}

nsCOMPtr<nsITreeSelection> treeSelection = do_QueryInterface(aObj);
if (treeSelection) {
return NS_OK;
}
}

//-- Access denied, report an error
NS_ConvertUTF8toUTF16 strName("CreateWrapperDenied");
nsAutoCString origin;
Expand Down
54 changes: 12 additions & 42 deletions dom/base/nsDOMClassInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@
#include "nsMemory.h"

// includes needed for the prototype chain interfaces
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIControllers.h"
#ifdef MOZ_XUL
#include "nsITreeSelection.h"
#include "nsITreeContentView.h"
#include "nsITreeView.h"
#include "nsIXULTemplateBuilder.h"
Expand Down Expand Up @@ -180,19 +177,8 @@ static nsDOMClassInfoData sClassInfoData[] = {

// XUL classes
#ifdef MOZ_XUL
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULCommandDispatcher, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControllers, nsNonDOMObjectSH,
DEFAULT_SCRIPTABLE_FLAGS)
#ifdef MOZ_XUL
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(TreeSelection, nsDOMGenericSH,
DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(TreeContentView, nsDOMGenericSH,
DEFAULT_SCRIPTABLE_FLAGS)
#endif

#ifdef MOZ_XUL
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULTemplateBuilder, nsDOMGenericSH,
DEFAULT_SCRIPTABLE_FLAGS)

Expand Down Expand Up @@ -469,27 +455,11 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END

#ifdef MOZ_XUL
DOM_CLASSINFO_MAP_BEGIN(XULCommandDispatcher, nsIDOMXULCommandDispatcher)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULCommandDispatcher)
DOM_CLASSINFO_MAP_END
#endif

DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControllers, nsIControllers)
DOM_CLASSINFO_MAP_ENTRY(nsIControllers)
DOM_CLASSINFO_MAP_END

#ifdef MOZ_XUL
DOM_CLASSINFO_MAP_BEGIN(TreeSelection, nsITreeSelection)
DOM_CLASSINFO_MAP_ENTRY(nsITreeSelection)
DOM_CLASSINFO_MAP_END

DOM_CLASSINFO_MAP_BEGIN(TreeContentView, nsITreeContentView)
DOM_CLASSINFO_MAP_ENTRY(nsITreeContentView)
DOM_CLASSINFO_MAP_ENTRY(nsITreeView)
DOM_CLASSINFO_MAP_END
#endif

#ifdef MOZ_XUL
DOM_CLASSINFO_MAP_BEGIN(XULTemplateBuilder, nsIXULTemplateBuilder)
DOM_CLASSINFO_MAP_ENTRY(nsIXULTemplateBuilder)
DOM_CLASSINFO_MAP_END
Expand Down Expand Up @@ -1628,6 +1598,9 @@ nsWindowSH::NameStructEnabled(JSContext* aCx, nsGlobalWindow *aWin,

#ifdef USE_CONTROLLERS_SHIM
static const JSClass ControllersShimClass = {
"Controllers", 0
};
static const JSClass XULControllersShimClass = {
"XULControllers", 0
};
#endif
Expand All @@ -1646,15 +1619,22 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
// Note: We use |obj| rather than |aWin| to get the principal here, because
// this is called during Window setup when the Document isn't necessarily
// hooked up yet.
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) &&
if ((id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) ||
id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS_CLASS)) &&
!xpc::IsXrayWrapper(obj) &&
!nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj)))
{
if (aWin->GetDoc()) {
aWin->GetDoc()->WarnOnceAbout(nsIDocument::eWindow_Controllers);
}
const JSClass* clazz;
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS)) {
clazz = &XULControllersShimClass;
} else {
clazz = &ControllersShimClass;
}
MOZ_ASSERT(JS_IsGlobalObject(obj));
JS::Rooted<JSObject*> shim(cx, JS_NewObject(cx, &ControllersShimClass));
JS::Rooted<JSObject*> shim(cx, JS_NewObject(cx, clazz));
if (NS_WARN_IF(!shim)) {
return NS_ERROR_OUT_OF_MEMORY;
}
Expand Down Expand Up @@ -2038,16 +2018,6 @@ nsDOMConstructorSH::HasInstance(nsIXPConnectWrappedNative *wrapper,
return wrapped->HasInstance(wrapper, cx, obj, val, bp, _retval);
}

NS_IMETHODIMP
nsNonDOMObjectSH::GetFlags(uint32_t *aFlags)
{
// This is NOT a DOM Object. Use this helper class for cases when you need
// to do something like implement nsISecurityCheckedComponent in a meaningful
// way.
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::SINGLETON_CLASSINFO;
return NS_OK;
}

// nsContentFrameMessageManagerSH

template<typename Super>
Expand Down
20 changes: 0 additions & 20 deletions dom/base/nsDOMClassInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,6 @@ class nsDOMConstructorSH : public nsDOMGenericSH
}
};

class nsNonDOMObjectSH : public nsDOMGenericSH
{
protected:
explicit nsNonDOMObjectSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
{
}

virtual ~nsNonDOMObjectSH()
{
}

public:
NS_IMETHOD GetFlags(uint32_t *aFlags) override;

static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsNonDOMObjectSH(aData);
}
};

template<typename Super>
class nsMessageManagerSH : public Super
{
Expand Down
5 changes: 0 additions & 5 deletions dom/base/nsDOMClassInfoID.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ enum nsDOMClassInfoID

// XUL classes
#ifdef MOZ_XUL
eDOMClassInfo_XULCommandDispatcher_id,
#endif
eDOMClassInfo_XULControllers_id,
#ifdef MOZ_XUL
eDOMClassInfo_TreeSelection_id,
eDOMClassInfo_TreeContentView_id,
#endif

Expand Down
7 changes: 4 additions & 3 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5127,9 +5127,10 @@ nsGlobalWindow::MayResolve(jsid aId)
return true;
}

if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS)) {
// We only resolve .controllers in release builds and on non-chrome windows,
// but let's not worry about any of that stuff.
if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) ||
aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS_CLASS)) {
// We only resolve .controllers/.Controllers in release builds and on non-chrome
// windows, but let's not worry about any of that stuff.
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions dom/bindings/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
addExternalIface('LoadInfo', nativeType='nsILoadInfo',
headerFile='nsILoadInfo.h', notflattened=True)
addExternalIface('MenuBuilder', nativeType='nsIMenuBuilder', notflattened=True)
addExternalIface('MozControllers', nativeType='nsIControllers')
addExternalIface('XULControllers', nativeType='nsIControllers', notflattened=True)
addExternalIface('MozFrameLoader', nativeType='nsIFrameLoader', notflattened=True)
addExternalIface('MozObserver', nativeType='nsIObserver', notflattened=True)
addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSource',
Expand All @@ -1742,7 +1742,6 @@ addExternalIface('MozWakeLockListener', headerFile='nsIDOMWakeLockListener.h')
addExternalIface('MozXULTemplateBuilder', nativeType='nsIXULTemplateBuilder')
addExternalIface('nsIBrowserDOMWindow', nativeType='nsIBrowserDOMWindow',
notflattened=True)
addExternalIface('nsIControllers', nativeType='nsIControllers')
addExternalIface('nsIDOMCrypto', nativeType='nsIDOMCrypto',
headerFile='Crypto.h')
addExternalIface('nsIFile', nativeType='nsIFile', notflattened=True)
Expand All @@ -1766,4 +1765,4 @@ addExternalIface('StackFrame', nativeType='nsIStackFrame',
headerFile='nsIException.h', notflattened=True)
addExternalIface('URI', nativeType='nsIURI', headerFile='nsIURI.h',
notflattened=True)
addExternalIface('XULCommandDispatcher')
addExternalIface('XULCommandDispatcher', notflattened=True)
4 changes: 2 additions & 2 deletions dom/locales/en-US/chrome/dom/dom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ Window_ContentWarning=window._content is deprecated. Please use window.content
# LOCALIZATION NOTE: Do not translate "XMLHttpRequest"
SyncXMLHttpRequestWarning=Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help http://xhr.spec.whatwg.org/
ImplicitMetaViewportTagFallback=No meta-viewport tag found. Please explicitly specify one to prevent unexpected behavioural changes in future versions. For more help https://developer.mozilla.org/en/docs/Mozilla/Mobile/Viewport_meta_tag
# LOCALIZATION NOTE: Do not translate "window.controllers"
Window_ControllersWarning=window.controllers is deprecated. Do not use it for UA detection.
# LOCALIZATION NOTE: Do not translate "window.controllers/Controllers"
Window_ControllersWarning=window.controllers/Controllers is deprecated. Do not use it for UA detection.
ImportXULIntoContentWarning=Importing XUL nodes into a content document is deprecated. This functionality may be removed soon.
XMLDocumentLoadPrincipalMismatch=Use of document.load forbidden on Documents that come from other Windows. Only the Window in which a Document was created is allowed to call .load on that Document. Preferably, use XMLHttpRequest instead.
# LOCALIZATION NOTE: Do not translate "IndexedDB".
Expand Down
8 changes: 0 additions & 8 deletions dom/tests/mochitest/general/test_interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ var interfaceNamesInGlobalScope =
"CompositionEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
"ConstantSourceNode",
// IMPORTANT: Do not change this list without review from a DOM peer!
"Controllers",
// IMPORTANT: Do not change this list without review from a DOM peer!
"ConvolverNode",
// IMPORTANT: Do not change this list without review from a DOM peer!
Expand Down Expand Up @@ -1156,8 +1154,6 @@ var interfaceNamesInGlobalScope =
{name: "TreeColumns", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TreeContentView", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TreeSelection", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
"TreeWalker",
// IMPORTANT: Do not change this list without review from a DOM peer!
Expand Down Expand Up @@ -1272,14 +1268,10 @@ var interfaceNamesInGlobalScope =
{name: "XULButtonElement", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULCheckboxElement", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULCommandDispatcher", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULCommandEvent", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULControlElement", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULControllers", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULDocument", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
Expand Down
4 changes: 2 additions & 2 deletions dom/webidl/HTMLInputElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum SelectionMode {
"preserve",
};

interface nsIControllers;
interface XULControllers;

[HTMLConstructor]
interface HTMLInputElement : HTMLElement {
Expand Down Expand Up @@ -144,7 +144,7 @@ partial interface HTMLInputElement {

partial interface HTMLInputElement {
[GetterThrows, ChromeOnly]
readonly attribute nsIControllers controllers;
readonly attribute XULControllers controllers;
// Binaryname because we have a FragmentOrElement function named "TextLength()".
[NeedsCallerType, BinaryName="inputTextLength"]
readonly attribute long textLength;
Expand Down
4 changes: 2 additions & 2 deletions dom/webidl/HTMLTextAreaElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

interface nsIEditor;
interface MozControllers;
interface XULControllers;

[HTMLConstructor]
interface HTMLTextAreaElement : HTMLElement {
Expand Down Expand Up @@ -81,7 +81,7 @@ partial interface HTMLTextAreaElement {
// Please make sure to update this list of nsIDOMHTMLTextAreaElement changes.

[Throws, ChromeOnly]
readonly attribute MozControllers controllers;
readonly attribute XULControllers controllers;
};

partial interface HTMLTextAreaElement {
Expand Down
3 changes: 2 additions & 1 deletion dom/webidl/Window.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface IID;
interface nsIBrowserDOMWindow;
interface nsIMessageBroadcaster;
interface nsIDOMCrypto;
interface XULControllers;

// http://www.whatwg.org/specs/web-apps/current-work/
[PrimaryGlobal, LegacyUnenumerableNamedProperties, NeedResolve]
Expand Down Expand Up @@ -263,7 +264,7 @@ partial interface Window {
[Throws, UnsafeInPrerendering, NeedsCallerType] void sizeToContent();

// XXX Shouldn't this be in nsIDOMChromeWindow?
[ChromeOnly, Replaceable, Throws] readonly attribute MozControllers controllers;
[ChromeOnly, Replaceable, Throws] readonly attribute XULControllers controllers;

[ChromeOnly, Throws] readonly attribute Element? realFrameElement;

Expand Down
6 changes: 3 additions & 3 deletions dom/webidl/XULElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/

interface MozControllers;
interface XULControllers;
interface MozFrameLoader;
interface MozRDFCompositeDataSource;
interface MozRDFResource;
Expand Down Expand Up @@ -88,8 +88,8 @@ interface XULElement : Element {
readonly attribute MozXULTemplateBuilder? builder;
[Throws]
readonly attribute MozRDFResource? resource;
[Throws]
readonly attribute MozControllers controllers;
[Throws, ChromeOnly]
readonly attribute XULControllers controllers;
[Throws]
readonly attribute BoxObject? boxObject;

Expand Down
2 changes: 0 additions & 2 deletions dom/xul/nsXULCommandDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsError.h"
#include "nsDOMClassInfoID.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/Element.h"
Expand All @@ -57,7 +56,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULCommandDispatcher)
NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandDispatcher)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXULCommandDispatcher)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XULCommandDispatcher)
NS_INTERFACE_MAP_END

NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULCommandDispatcher)
Expand Down
2 changes: 0 additions & 2 deletions dom/xul/nsXULControllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "nsIControllers.h"
#include "nsIDOMElement.h"
#include "nsXULControllers.h"
#include "nsDOMClassInfoID.h"
#include "nsIController.h"

//----------------------------------------------------------------------
Expand Down Expand Up @@ -79,7 +78,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULControllers)
NS_INTERFACE_MAP_ENTRY(nsIControllers)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllers)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XULControllers)
NS_INTERFACE_MAP_END

NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULControllers)
Expand Down
1 change: 1 addition & 0 deletions js/xpconnect/src/XPCJSRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const char* const XPCJSRuntime::mStrings[] = {
"__exposedProps__", // IDX_EXPOSEDPROPS
"eval", // IDX_EVAL
"controllers", // IDX_CONTROLLERS
"Controllers", // IDX_CONTROLLERS_CLASS
"realFrameElement", // IDX_REALFRAMEELEMENT
"length", // IDX_LENGTH
"name", // IDX_NAME
Expand Down
Loading

0 comments on commit 7753cb5

Please sign in to comment.