MozQueryInterface.h (1723B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_MozQueryInterface 8 #define mozilla_dom_MozQueryInterface 9 10 /** 11 * This class implements an optimized QueryInterface method for 12 * XPConnect-wrapped JS objects. 13 * 14 * For JavaScript callers, it behaves as an ordinary QueryInterface method, 15 * returning its `this` object or throwing depending on the interface it was 16 * passed. 17 * 18 * For native XPConnect callers, we bypass JSAPI entirely, and directly check 19 * whether the queried interface is in the interfaces list. 20 */ 21 22 #include "mozilla/dom/BindingDeclarations.h" 23 #include "mozilla/dom/NonRefcountedDOMObject.h" 24 #include "nsID.h" 25 26 namespace mozilla { 27 class ErrorResult; 28 29 namespace dom { 30 31 class MozQueryInterface final : public NonRefcountedDOMObject { 32 public: 33 explicit MozQueryInterface(nsTArray<nsIID>&& aInterfaces) 34 : mInterfaces(std::move(aInterfaces)) {} 35 36 bool QueriesTo(const nsIID& aIID) const; 37 38 void LegacyCall(JSContext* cx, JS::Handle<JS::Value> thisv, 39 JS::Handle<JS::Value> aIID, 40 JS::MutableHandle<JS::Value> aResult, ErrorResult& aRv) const; 41 42 nsISupports* GetParentObject() const { return nullptr; } 43 44 bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, 45 JS::MutableHandle<JSObject*> aReflector); 46 47 private: 48 nsTArray<nsIID> mInterfaces; 49 }; 50 51 } // namespace dom 52 } // namespace mozilla 53 54 #endif // mozilla_dom_MozQueryInterface