/src/mozilla-central/dom/base/MozQueryInterface.h
Line | Count | Source |
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 "mozilla/ErrorResult.h" |
25 | | #include "nsID.h" |
26 | | |
27 | | namespace mozilla { |
28 | | namespace dom { |
29 | | |
30 | | class MozQueryInterface final : public NonRefcountedDOMObject |
31 | | { |
32 | | public: |
33 | | explicit MozQueryInterface(nsTArray<nsIID>&& aInterfaces) |
34 | | : mInterfaces(std::move(aInterfaces)) |
35 | 3 | {} |
36 | | |
37 | | bool QueriesTo(const nsIID& aIID) const; |
38 | | |
39 | | void LegacyCall(JSContext* cx, JS::Handle<JS::Value> thisv, nsIJSID* aIID, JS::MutableHandle<JS::Value> aResult, ErrorResult& aRv) const; |
40 | | |
41 | | nsISupports* GetParentObject() const { return nullptr; } |
42 | | |
43 | | bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector); |
44 | | |
45 | | private: |
46 | | nsTArray<nsIID> mInterfaces; |
47 | | }; |
48 | | |
49 | | } // namespace dom |
50 | | } // namespace mozilla |
51 | | |
52 | | #endif // mozilla_dom_MozQueryInterface |