1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: set ts=8 sw=4 et tw=78:
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 
8 #include "ShimInterfaceInfo.h"
9 
10 #include "nsIBrowserBoxObject.h"
11 #include "nsIContainerBoxObject.h"
12 #include "nsIDOMAnimationEvent.h"
13 #include "nsIDOMAttr.h"
14 #include "nsIDOMBeforeUnloadEvent.h"
15 #include "nsIDOMCanvasRenderingContext2D.h"
16 #include "nsIDOMCDATASection.h"
17 #include "nsIDOMCharacterData.h"
18 #include "nsIDOMClientRect.h"
19 #include "nsIDOMClientRectList.h"
20 #include "nsIDOMClipboardEvent.h"
21 #include "nsIDOMCommandEvent.h"
22 #include "nsIDOMComment.h"
23 #include "nsIDOMCSSPrimitiveValue.h"
24 #include "nsIDOMCSSStyleDeclaration.h"
25 #include "nsIDOMCSSStyleSheet.h"
26 #include "nsIDOMCSSValue.h"
27 #include "nsIDOMCSSValueList.h"
28 #include "nsIDOMCustomEvent.h"
29 #include "nsIDOMDataContainerEvent.h"
30 #ifdef MOZ_WEBRTC
31 #include "nsIDOMDataChannel.h"
32 #endif
33 #include "nsIDOMDataTransfer.h"
34 #include "nsIDOMDOMCursor.h"
35 #include "nsIDOMDOMException.h"
36 #include "nsIDOMDOMRequest.h"
37 #include "nsIDOMDocument.h"
38 #include "nsIDOMDocumentFragment.h"
39 #include "nsIDOMDocumentType.h"
40 #include "nsIDOMDocumentXBL.h"
41 #include "nsIDOMDragEvent.h"
42 #include "nsIDOMElement.h"
43 #include "nsIDOMEvent.h"
44 #include "nsIDOMEventTarget.h"
45 #include "nsIDOMFileList.h"
46 #include "nsIDOMFocusEvent.h"
47 #include "nsIDOMFormData.h"
48 #include "nsIDOMGeoPositionError.h"
49 #include "nsIDOMHistory.h"
50 #include "nsIDOMHTMLAnchorElement.h"
51 #include "nsIDOMHTMLAppletElement.h"
52 #include "nsIDOMHTMLAreaElement.h"
53 #include "nsIDOMHTMLBaseElement.h"
54 #include "nsIDOMHTMLBodyElement.h"
55 #include "nsIDOMHTMLButtonElement.h"
56 #include "nsIDOMHTMLCanvasElement.h"
57 #include "nsIDOMHTMLCollection.h"
58 #include "nsIDOMHTMLDirectoryElement.h"
59 #include "nsIDOMHTMLDocument.h"
60 #include "nsIDOMHTMLElement.h"
61 #include "nsIDOMHTMLEmbedElement.h"
62 #include "nsIDOMHTMLFieldSetElement.h"
63 #include "nsIDOMHTMLFormElement.h"
64 #include "nsIDOMHTMLFrameElement.h"
65 #include "nsIDOMHTMLFrameSetElement.h"
66 #include "nsIDOMHTMLHRElement.h"
67 #include "nsIDOMHTMLHeadElement.h"
68 #include "nsIDOMHTMLHtmlElement.h"
69 #include "nsIDOMHTMLIFrameElement.h"
70 #include "nsIDOMHTMLImageElement.h"
71 #include "nsIDOMHTMLInputElement.h"
72 #include "nsIDOMHTMLLIElement.h"
73 #include "nsIDOMHTMLLabelElement.h"
74 #include "nsIDOMHTMLLinkElement.h"
75 #include "nsIDOMHTMLMapElement.h"
76 #include "nsIDOMHTMLMediaElement.h"
77 #include "nsIDOMHTMLMenuElement.h"
78 #include "nsIDOMHTMLMenuItemElement.h"
79 #include "nsIDOMHTMLMetaElement.h"
80 #include "nsIDOMHTMLOListElement.h"
81 #include "nsIDOMHTMLObjectElement.h"
82 #include "nsIDOMHTMLOptGroupElement.h"
83 #include "nsIDOMHTMLOptionElement.h"
84 #include "nsIDOMHTMLOptionsCollection.h"
85 #include "nsIDOMHTMLParagraphElement.h"
86 #include "nsIDOMHTMLPreElement.h"
87 #include "nsIDOMHTMLQuoteElement.h"
88 #include "nsIDOMHTMLScriptElement.h"
89 #include "nsIDOMHTMLSelectElement.h"
90 #include "nsIDOMHTMLSourceElement.h"
91 #include "nsIDOMHTMLStyleElement.h"
92 #include "nsIDOMHTMLTableCellElement.h"
93 #include "nsIDOMHTMLTextAreaElement.h"
94 #include "nsIDOMHTMLUListElement.h"
95 #include "nsIDOMKeyEvent.h"
96 #include "nsIDOMMediaList.h"
97 #include "nsIDOMMouseEvent.h"
98 #include "nsIDOMMouseScrollEvent.h"
99 #include "nsIDOMMutationEvent.h"
100 #include "nsIDOMMozNamedAttrMap.h"
101 #include "nsIDOMNode.h"
102 #include "nsIDOMNodeIterator.h"
103 #include "nsIDOMNotifyPaintEvent.h"
104 #include "nsIDOMNSEvent.h"
105 #include "nsIDOMOfflineResourceList.h"
106 #include "nsIDOMPaintRequest.h"
107 #include "nsIDOMParser.h"
108 #include "nsIDOMProcessingInstruction.h"
109 #include "nsIDOMRange.h"
110 #include "nsIDOMRect.h"
111 #include "nsIDOMScreen.h"
112 #include "nsIDOMScrollAreaEvent.h"
113 #include "nsIDOMSerializer.h"
114 #include "nsIDOMSimpleGestureEvent.h"
115 #include "nsIDOMStyleSheet.h"
116 #include "nsIDOMStyleSheetList.h"
117 #include "nsIDOMSVGElement.h"
118 #include "nsIDOMSVGLength.h"
119 #include "nsIDOMText.h"
120 #include "nsIDOMTimeEvent.h"
121 #include "nsIDOMTimeRanges.h"
122 #include "nsIDOMTransitionEvent.h"
123 #include "nsIDOMTreeWalker.h"
124 #include "nsIDOMUIEvent.h"
125 #include "nsIDOMValidityState.h"
126 #include "nsIDOMWheelEvent.h"
127 #include "nsIDOMXMLDocument.h"
128 #include "nsIDOMXPathEvaluator.h"
129 #include "nsIDOMXPathResult.h"
130 #include "nsIDOMXULCommandEvent.h"
131 #include "nsIDOMXULDocument.h"
132 #include "nsIDOMXULElement.h"
133 #include "nsIListBoxObject.h"
134 #include "nsIMenuBoxObject.h"
135 #include "nsIScrollBoxObject.h"
136 #include "nsISelection.h"
137 #include "nsITreeBoxObject.h"
138 #include "nsIXMLHttpRequest.h"
139 
140 #include "mozilla/dom/AnimationEventBinding.h"
141 #include "mozilla/dom/AttrBinding.h"
142 #include "mozilla/dom/BeforeUnloadEventBinding.h"
143 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
144 #include "mozilla/dom/CDATASectionBinding.h"
145 #include "mozilla/dom/CharacterDataBinding.h"
146 #include "mozilla/dom/DOMRectBinding.h"
147 #include "mozilla/dom/DOMRectListBinding.h"
148 #include "mozilla/dom/ClipboardEventBinding.h"
149 #include "mozilla/dom/CommandEventBinding.h"
150 #include "mozilla/dom/CommentBinding.h"
151 #include "mozilla/dom/ContainerBoxObjectBinding.h"
152 #include "mozilla/dom/CSSPrimitiveValueBinding.h"
153 #include "mozilla/dom/CSSStyleDeclarationBinding.h"
154 #include "mozilla/dom/CSSStyleSheetBinding.h"
155 #include "mozilla/dom/CSSValueBinding.h"
156 #include "mozilla/dom/CSSValueListBinding.h"
157 #include "mozilla/dom/CustomEventBinding.h"
158 #ifdef MOZ_WEBRTC
159 #include "mozilla/dom/DataChannelBinding.h"
160 #endif
161 #include "mozilla/dom/DataContainerEventBinding.h"
162 #include "mozilla/dom/DataTransferBinding.h"
163 #include "mozilla/dom/DOMCursorBinding.h"
164 #include "mozilla/dom/DOMExceptionBinding.h"
165 #include "mozilla/dom/DOMParserBinding.h"
166 #include "mozilla/dom/DOMRequestBinding.h"
167 #include "mozilla/dom/DocumentBinding.h"
168 #include "mozilla/dom/DocumentFragmentBinding.h"
169 #include "mozilla/dom/DocumentTypeBinding.h"
170 #include "mozilla/dom/DocumentBinding.h"
171 #include "mozilla/dom/DragEventBinding.h"
172 #include "mozilla/dom/ElementBinding.h"
173 #include "mozilla/dom/EventBinding.h"
174 #include "mozilla/dom/EventTargetBinding.h"
175 #include "mozilla/dom/FileListBinding.h"
176 #include "mozilla/dom/FocusEventBinding.h"
177 #include "mozilla/dom/FormDataBinding.h"
178 #include "mozilla/dom/HistoryBinding.h"
179 #include "mozilla/dom/HTMLAnchorElementBinding.h"
180 #include "mozilla/dom/HTMLAppletElementBinding.h"
181 #include "mozilla/dom/HTMLAreaElementBinding.h"
182 #include "mozilla/dom/HTMLBaseElementBinding.h"
183 #include "mozilla/dom/HTMLBodyElementBinding.h"
184 #include "mozilla/dom/HTMLButtonElementBinding.h"
185 #include "mozilla/dom/HTMLCanvasElementBinding.h"
186 #include "mozilla/dom/HTMLCollectionBinding.h"
187 #include "mozilla/dom/HTMLDirectoryElementBinding.h"
188 #include "mozilla/dom/HTMLDocumentBinding.h"
189 #include "mozilla/dom/HTMLElementBinding.h"
190 #include "mozilla/dom/HTMLEmbedElementBinding.h"
191 #include "mozilla/dom/HTMLFieldSetElementBinding.h"
192 #include "mozilla/dom/HTMLFormElementBinding.h"
193 #include "mozilla/dom/HTMLFrameElementBinding.h"
194 #include "mozilla/dom/HTMLFrameSetElementBinding.h"
195 #include "mozilla/dom/HTMLHRElementBinding.h"
196 #include "mozilla/dom/HTMLHeadElementBinding.h"
197 #include "mozilla/dom/HTMLHtmlElementBinding.h"
198 #include "mozilla/dom/HTMLIFrameElementBinding.h"
199 #include "mozilla/dom/HTMLImageElementBinding.h"
200 #include "mozilla/dom/HTMLInputElementBinding.h"
201 #include "mozilla/dom/HTMLLIElementBinding.h"
202 #include "mozilla/dom/HTMLLabelElementBinding.h"
203 #include "mozilla/dom/HTMLLinkElementBinding.h"
204 #include "mozilla/dom/HTMLMapElementBinding.h"
205 #include "mozilla/dom/HTMLMediaElementBinding.h"
206 #include "mozilla/dom/HTMLMenuElementBinding.h"
207 #include "mozilla/dom/HTMLMenuItemElementBinding.h"
208 #include "mozilla/dom/HTMLMetaElementBinding.h"
209 #include "mozilla/dom/HTMLOListElementBinding.h"
210 #include "mozilla/dom/HTMLObjectElementBinding.h"
211 #include "mozilla/dom/HTMLOptGroupElementBinding.h"
212 #include "mozilla/dom/HTMLOptionElementBinding.h"
213 #include "mozilla/dom/HTMLOptionsCollectionBinding.h"
214 #include "mozilla/dom/HTMLParagraphElementBinding.h"
215 #include "mozilla/dom/HTMLPreElementBinding.h"
216 #include "mozilla/dom/HTMLQuoteElementBinding.h"
217 #include "mozilla/dom/HTMLScriptElementBinding.h"
218 #include "mozilla/dom/HTMLSelectElementBinding.h"
219 #include "mozilla/dom/HTMLSourceElementBinding.h"
220 #include "mozilla/dom/HTMLStyleElementBinding.h"
221 #include "mozilla/dom/HTMLTableCellElementBinding.h"
222 #include "mozilla/dom/HTMLTextAreaElementBinding.h"
223 #include "mozilla/dom/HTMLUListElementBinding.h"
224 #include "mozilla/dom/KeyEventBinding.h"
225 #include "mozilla/dom/ListBoxObjectBinding.h"
226 #include "mozilla/dom/MediaListBinding.h"
227 #include "mozilla/dom/MessageEventBinding.h"
228 #include "mozilla/dom/MenuBoxObjectBinding.h"
229 #include "mozilla/dom/MouseEventBinding.h"
230 #include "mozilla/dom/MouseScrollEventBinding.h"
231 #include "mozilla/dom/MutationEventBinding.h"
232 #include "mozilla/dom/NamedNodeMapBinding.h"
233 #include "mozilla/dom/NodeIteratorBinding.h"
234 #include "mozilla/dom/NodeBinding.h"
235 #include "mozilla/dom/NotifyPaintEventBinding.h"
236 #include "mozilla/dom/EventBinding.h"
237 #include "mozilla/dom/OfflineResourceListBinding.h"
238 #include "mozilla/dom/PaintRequestBinding.h"
239 #include "mozilla/dom/PositionErrorBinding.h"
240 #include "mozilla/dom/ProcessingInstructionBinding.h"
241 #include "mozilla/dom/RangeBinding.h"
242 #include "mozilla/dom/RectBinding.h"
243 #include "mozilla/dom/ScreenBinding.h"
244 #include "mozilla/dom/ScrollBoxObjectBinding.h"
245 #include "mozilla/dom/SelectionBinding.h"
246 #include "mozilla/dom/ScrollAreaEventBinding.h"
247 #include "mozilla/dom/SimpleGestureEventBinding.h"
248 #include "mozilla/dom/StorageEventBinding.h"
249 #include "mozilla/dom/StyleSheetBinding.h"
250 #include "mozilla/dom/StyleSheetListBinding.h"
251 #include "mozilla/dom/SVGElementBinding.h"
252 #include "mozilla/dom/SVGLengthBinding.h"
253 #include "mozilla/dom/TextBinding.h"
254 #include "mozilla/dom/TimeEventBinding.h"
255 #include "mozilla/dom/TimeRangesBinding.h"
256 #include "mozilla/dom/TransitionEventBinding.h"
257 #include "mozilla/dom/TreeBoxObjectBinding.h"
258 #include "mozilla/dom/TreeWalkerBinding.h"
259 #include "mozilla/dom/UIEventBinding.h"
260 #include "mozilla/dom/ValidityStateBinding.h"
261 #include "mozilla/dom/WheelEventBinding.h"
262 #include "mozilla/dom/XMLDocumentBinding.h"
263 #include "mozilla/dom/XMLHttpRequestEventTargetBinding.h"
264 #include "mozilla/dom/XMLHttpRequestUploadBinding.h"
265 #include "mozilla/dom/XMLSerializerBinding.h"
266 #include "mozilla/dom/XPathEvaluatorBinding.h"
267 #include "mozilla/dom/XPathResultBinding.h"
268 #include "mozilla/dom/XULCommandEventBinding.h"
269 #include "mozilla/dom/XULDocumentBinding.h"
270 #include "mozilla/dom/XULElementBinding.h"
271 
272 using namespace mozilla;
273 
274 struct ComponentsInterfaceShimEntry {
275   constexpr
ComponentsInterfaceShimEntryComponentsInterfaceShimEntry276   ComponentsInterfaceShimEntry(const char* aName, const nsIID& aIID,
277                                const dom::NativePropertyHooks* aNativePropHooks)
278     : geckoName(aName), iid(aIID), nativePropHooks(aNativePropHooks) {}
279 
280   const char *geckoName;
281   const nsIID& iid;
282   const dom::NativePropertyHooks* nativePropHooks;
283 };
284 
285 #define DEFINE_SHIM_WITH_CUSTOM_INTERFACE(geckoName, domName) \
286   { #geckoName, NS_GET_IID(geckoName), \
287      mozilla::dom::domName ## Binding::sNativePropertyHooks }
288 #define DEFINE_SHIM(name) \
289   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOM ## name, name)
290 
291 /**
292  * These shim entries allow us to make old XPIDL interfaces implementing DOM
293  * APIs as non-scriptable in order to save some runtime memory on Firefox OS,
294  * without breaking the entries under Components.interfaces which might both
295  * be used by our code and add-ons.  Specifically, the shim entries provide
296  * the following:
297  *
298  * * Components.interfaces.nsIFoo entries.  These entries basically work
299  *   almost exactly as the usual ones that you would get through the
300  *   XPIDL machinery.  Specifically, they have the right name, they reflect
301  *   the right IID, and they will work properly when passed to QueryInterface.
302  *
303  * * Components.interfaces.nsIFoo.CONSTANT values.  These entries will have
304  *   the right name and the right value for most integer types.  Note that
305  *   support for non-numerical constants is untested and will probably not
306  *   work out of the box.
307  *
308  * FAQ:
309  * * When should I add an entry to the list here?
310  *   Only if you're making an XPIDL interfaces which has a corresponding
311  *   WebIDL interface non-scriptable.
312  * * When should I remove an entry from this list?
313  *   If you are completely removing an XPIDL interface from the code base.  If
314  *   you forget to do so, the compiler will remind you.
315  * * How should I add an entry to the list here?
316  *   First, make sure that the XPIDL interface in question is non-scriptable
317  *   and also has a corresponding WebIDL interface.  Then, add two include
318  *   entries above, one for the XPIDL interface and one for the WebIDL
319  *   interface, and add a shim entry below.  If the name of the XPIDL
320  *   interface only has an "nsIDOM" prefix prepended to the WebIDL name, you
321  *   can use the DEFINE_SHIM macro and pass in the name of the WebIDL
322  *   interface.  Otherwise, use DEFINE_SHIM_WITH_CUSTOM_INTERFACE.
323  */
324 
325 const ComponentsInterfaceShimEntry kComponentsInterfaceShimMap[] =
326 {
327   DEFINE_SHIM(AnimationEvent),
328   DEFINE_SHIM(Attr),
329   DEFINE_SHIM(BeforeUnloadEvent),
330   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIBrowserBoxObject, ContainerBoxObject),
331   DEFINE_SHIM(CanvasRenderingContext2D),
332   DEFINE_SHIM(CDATASection),
333   DEFINE_SHIM(CharacterData),
334   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMClientRect, DOMRectReadOnly),
335   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMClientRectList, DOMRectList),
336   DEFINE_SHIM(ClipboardEvent),
337   DEFINE_SHIM(CommandEvent),
338   DEFINE_SHIM(Comment),
339   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIContainerBoxObject, ContainerBoxObject),
340   DEFINE_SHIM(CSSPrimitiveValue),
341   DEFINE_SHIM(CSSStyleDeclaration),
342   DEFINE_SHIM(CSSStyleSheet),
343   DEFINE_SHIM(CSSValue),
344   DEFINE_SHIM(CSSValueList),
345   DEFINE_SHIM(CustomEvent),
346 #ifdef MOZ_WEBRTC
347   DEFINE_SHIM(DataChannel),
348 #endif
349   DEFINE_SHIM(DataContainerEvent),
350   DEFINE_SHIM(DataTransfer),
351   DEFINE_SHIM(DOMCursor),
352   DEFINE_SHIM(DOMException),
353   DEFINE_SHIM(DOMRequest),
354   DEFINE_SHIM(Document),
355   DEFINE_SHIM(DocumentFragment),
356   DEFINE_SHIM(DocumentType),
357   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMDocumentXBL, Document),
358   DEFINE_SHIM(DragEvent),
359   DEFINE_SHIM(Element),
360   DEFINE_SHIM(Event),
361   DEFINE_SHIM(EventTarget),
362   DEFINE_SHIM(FileList),
363   DEFINE_SHIM(FocusEvent),
364   DEFINE_SHIM(FormData),
365   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMGeoPositionError, PositionError),
366   DEFINE_SHIM(History),
367   DEFINE_SHIM(HTMLAnchorElement),
368   DEFINE_SHIM(HTMLAppletElement),
369   DEFINE_SHIM(HTMLAreaElement),
370   DEFINE_SHIM(HTMLBaseElement),
371   DEFINE_SHIM(HTMLBodyElement),
372   DEFINE_SHIM(HTMLButtonElement),
373   DEFINE_SHIM(HTMLCanvasElement),
374   DEFINE_SHIM(HTMLCollection),
375   DEFINE_SHIM(HTMLDirectoryElement),
376   DEFINE_SHIM(HTMLDocument),
377   DEFINE_SHIM(HTMLElement),
378   DEFINE_SHIM(HTMLEmbedElement),
379   DEFINE_SHIM(HTMLFieldSetElement),
380   DEFINE_SHIM(HTMLFormElement),
381   DEFINE_SHIM(HTMLFrameElement),
382   DEFINE_SHIM(HTMLFrameSetElement),
383   DEFINE_SHIM(HTMLHRElement),
384   DEFINE_SHIM(HTMLHeadElement),
385   DEFINE_SHIM(HTMLHtmlElement),
386   DEFINE_SHIM(HTMLIFrameElement),
387   DEFINE_SHIM(HTMLImageElement),
388   DEFINE_SHIM(HTMLInputElement),
389   DEFINE_SHIM(HTMLLIElement),
390   DEFINE_SHIM(HTMLLabelElement),
391   DEFINE_SHIM(HTMLLinkElement),
392   DEFINE_SHIM(HTMLMapElement),
393   DEFINE_SHIM(HTMLMediaElement),
394   DEFINE_SHIM(HTMLMenuElement),
395   DEFINE_SHIM(HTMLMenuItemElement),
396   DEFINE_SHIM(HTMLMetaElement),
397   DEFINE_SHIM(HTMLOListElement),
398   DEFINE_SHIM(HTMLObjectElement),
399   DEFINE_SHIM(HTMLOptGroupElement),
400   DEFINE_SHIM(HTMLOptionElement),
401   DEFINE_SHIM(HTMLOptionsCollection),
402   DEFINE_SHIM(HTMLParagraphElement),
403   DEFINE_SHIM(HTMLPreElement),
404   DEFINE_SHIM(HTMLQuoteElement),
405   DEFINE_SHIM(HTMLScriptElement),
406   DEFINE_SHIM(HTMLSelectElement),
407   DEFINE_SHIM(HTMLSourceElement),
408   DEFINE_SHIM(HTMLStyleElement),
409   DEFINE_SHIM(HTMLTableCellElement),
410   DEFINE_SHIM(HTMLTextAreaElement),
411   DEFINE_SHIM(HTMLUListElement),
412   DEFINE_SHIM(KeyEvent),
413   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIListBoxObject, ListBoxObject),
414   DEFINE_SHIM(MediaList),
415   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIMenuBoxObject, MenuBoxObject),
416   DEFINE_SHIM(MouseEvent),
417   DEFINE_SHIM(MouseScrollEvent),
418   DEFINE_SHIM(MutationEvent),
419   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMMozNamedAttrMap, NamedNodeMap),
420   DEFINE_SHIM(NodeIterator),
421   DEFINE_SHIM(Node),
422   DEFINE_SHIM(NotifyPaintEvent),
423   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMNSEvent, Event),
424   DEFINE_SHIM(OfflineResourceList),
425   DEFINE_SHIM(PaintRequest),
426   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMParser, DOMParser),
427   DEFINE_SHIM(ProcessingInstruction),
428   DEFINE_SHIM(Range),
429   DEFINE_SHIM(Rect),
430   DEFINE_SHIM(Screen),
431   DEFINE_SHIM(ScrollAreaEvent),
432   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIScrollBoxObject, ScrollBoxObject),
433   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMSerializer, XMLSerializer),
434   DEFINE_SHIM(SimpleGestureEvent),
435   DEFINE_SHIM(StyleSheet),
436   DEFINE_SHIM(StyleSheetList),
437   DEFINE_SHIM(SVGElement),
438   DEFINE_SHIM(SVGLength),
439   DEFINE_SHIM(Text),
440   DEFINE_SHIM(TimeEvent),
441   DEFINE_SHIM(TimeRanges),
442   DEFINE_SHIM(TransitionEvent),
443   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsITreeBoxObject, TreeBoxObject),
444   DEFINE_SHIM(TreeWalker),
445   DEFINE_SHIM(UIEvent),
446   DEFINE_SHIM(ValidityState),
447   DEFINE_SHIM(WheelEvent),
448   DEFINE_SHIM(XMLDocument),
449   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIXMLHttpRequestEventTarget, XMLHttpRequestEventTarget),
450   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIXMLHttpRequestUpload, XMLHttpRequestUpload),
451   DEFINE_SHIM(XPathEvaluator),
452   DEFINE_SHIM(XPathResult),
453   DEFINE_SHIM(XULCommandEvent),
454   DEFINE_SHIM(XULDocument),
455   DEFINE_SHIM(XULElement),
456   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsISelection, Selection),
457 };
458 
459 #undef DEFINE_SHIM
460 #undef DEFINE_SHIM_WITH_CUSTOM_INTERFACE
461 
NS_IMPL_ISUPPORTS(ShimInterfaceInfo,nsISupports,nsIInterfaceInfo)462 NS_IMPL_ISUPPORTS(ShimInterfaceInfo, nsISupports, nsIInterfaceInfo)
463 
464 already_AddRefed<ShimInterfaceInfo>
465 ShimInterfaceInfo::MaybeConstruct(const char* aName, JSContext* cx)
466 {
467     RefPtr<ShimInterfaceInfo> info;
468     for (uint32_t i = 0; i < ArrayLength(kComponentsInterfaceShimMap); ++i) {
469         if (!strcmp(aName, kComponentsInterfaceShimMap[i].geckoName)) {
470             const ComponentsInterfaceShimEntry& shimEntry =
471                 kComponentsInterfaceShimMap[i];
472             info = new ShimInterfaceInfo(shimEntry.iid,
473                                          shimEntry.geckoName,
474                                          shimEntry.nativePropHooks);
475             break;
476         }
477     }
478     return info.forget();
479 }
480 
ShimInterfaceInfo(const nsIID & aIID,const char * aName,const mozilla::dom::NativePropertyHooks * aNativePropHooks)481 ShimInterfaceInfo::ShimInterfaceInfo(const nsIID& aIID,
482                                      const char* aName,
483                                      const mozilla::dom::NativePropertyHooks* aNativePropHooks)
484     : mIID(aIID)
485     , mName(aName)
486     , mNativePropHooks(aNativePropHooks)
487 {
488 }
489 
490 NS_IMETHODIMP
GetName(char ** aName)491 ShimInterfaceInfo::GetName(char** aName)
492 {
493     *aName = ToNewCString(mName);
494     return NS_OK;
495 }
496 
497 NS_IMETHODIMP
GetInterfaceIID(nsIID ** aIID)498 ShimInterfaceInfo::GetInterfaceIID(nsIID** aIID)
499 {
500     *aIID = static_cast<nsIID*> (nsMemory::Clone(&mIID, sizeof(mIID)));
501     return NS_OK;
502 }
503 
504 NS_IMETHODIMP
IsScriptable(bool * aRetVal)505 ShimInterfaceInfo::IsScriptable(bool* aRetVal)
506 {
507     // This class should pretend that the interface is scriptable because
508     // that's what nsJSIID assumes.
509     *aRetVal = true;
510     return NS_OK;
511 }
512 
513 NS_IMETHODIMP
IsBuiltinClass(bool * aRetVal)514 ShimInterfaceInfo::IsBuiltinClass(bool* aRetVal)
515 {
516     *aRetVal = true;
517     return NS_OK;
518 }
519 
520 NS_IMETHODIMP
IsMainProcessScriptableOnly(bool * aRetVal)521 ShimInterfaceInfo::IsMainProcessScriptableOnly(bool* aRetVal)
522 {
523     *aRetVal = false;
524     return NS_OK;
525 }
526 
527 NS_IMETHODIMP
GetParent(nsIInterfaceInfo ** aParent)528 ShimInterfaceInfo::GetParent(nsIInterfaceInfo** aParent)
529 {
530     *aParent = nullptr;
531     return NS_OK;
532 }
533 
534 NS_IMETHODIMP
GetMethodCount(uint16_t * aCount)535 ShimInterfaceInfo::GetMethodCount(uint16_t* aCount)
536 {
537     // Pretend we don't have any methods.
538     *aCount = 0;
539     return NS_OK;
540 }
541 
542 NS_IMETHODIMP
GetConstantCount(uint16_t * aCount)543 ShimInterfaceInfo::GetConstantCount(uint16_t* aCount)
544 {
545     // We assume that we never have interfaces with more than UINT16_MAX
546     // constants defined on them.
547     uint16_t count = 0;
548 
549     // NOTE: The structure of this loop must be kept in sync with the loop
550     // in GetConstant.
551     const mozilla::dom::NativePropertyHooks* propHooks = mNativePropHooks;
552     do {
553         const mozilla::dom::NativeProperties* props[] = {
554             propHooks->mNativeProperties.regular,
555             propHooks->mNativeProperties.chromeOnly
556         };
557         for (size_t i = 0; i < ArrayLength(props); ++i) {
558             auto prop = props[i];
559             if (prop && prop->HasConstants()) {
560                 for (auto cs = prop->Constants()->specs; cs->name; ++cs) {
561                     // We have found one constant here.  We explicitly do not
562                     // bother calling isEnabled() here because it's OK to define
563                     // potentially extra constants on these shim interfaces.
564                     ++count;
565                 }
566             }
567         }
568     } while ((propHooks = propHooks->mProtoHooks));
569     *aCount = count;
570     return NS_OK;
571 }
572 
573 NS_IMETHODIMP
GetMethodInfo(uint16_t aIndex,const nsXPTMethodInfo ** aInfo)574 ShimInterfaceInfo::GetMethodInfo(uint16_t aIndex, const nsXPTMethodInfo** aInfo)
575 {
576     MOZ_ASSERT(false, "This should never be called");
577     return NS_ERROR_NOT_IMPLEMENTED;
578 }
579 
580 NS_IMETHODIMP
GetMethodInfoForName(const char * aName,uint16_t * aIndex,const nsXPTMethodInfo ** aInfo)581 ShimInterfaceInfo::GetMethodInfoForName(const char* aName, uint16_t* aIndex, const nsXPTMethodInfo** aInfo)
582 {
583     MOZ_ASSERT(false, "This should never be called");
584     return NS_ERROR_NOT_IMPLEMENTED;
585 }
586 
587 NS_IMETHODIMP
GetConstant(uint16_t aIndex,JS::MutableHandleValue aConstant,char ** aName)588 ShimInterfaceInfo::GetConstant(uint16_t aIndex, JS::MutableHandleValue aConstant,
589                                char** aName)
590 {
591     // We assume that we never have interfaces with more than UINT16_MAX
592     // constants defined on them.
593     uint16_t index = 0;
594 
595     // NOTE: The structure of this loop must be kept in sync with the loop
596     // in GetConstantCount.
597     const mozilla::dom::NativePropertyHooks* propHooks = mNativePropHooks;
598     do {
599         const mozilla::dom::NativeProperties* props[] = {
600             propHooks->mNativeProperties.regular,
601             propHooks->mNativeProperties.chromeOnly
602         };
603         for (size_t i = 0; i < ArrayLength(props); ++i) {
604             auto prop = props[i];
605             if (prop && prop->HasConstants()) {
606                 for (auto cs = prop->Constants()->specs; cs->name; ++cs) {
607                     // We have found one constant here.  We explicitly do not
608                     // bother calling isEnabled() here because it's OK to define
609                     // potentially extra constants on these shim interfaces.
610                     if (index == aIndex) {
611                         aConstant.set(cs->value);
612                         *aName = ToNewCString(nsDependentCString(cs->name));
613                         return NS_OK;
614                     }
615                     ++index;
616                 }
617             }
618         }
619     } while ((propHooks = propHooks->mProtoHooks));
620 
621     // aIndex was bigger than the number of constants we have.
622     return NS_ERROR_INVALID_ARG;
623 }
624 
625 NS_IMETHODIMP
GetInfoForParam(uint16_t aIndex,const nsXPTParamInfo * aParam,nsIInterfaceInfo ** aRetVal)626 ShimInterfaceInfo::GetInfoForParam(uint16_t aIndex, const nsXPTParamInfo* aParam, nsIInterfaceInfo** aRetVal)
627 {
628     MOZ_ASSERT(false, "This should never be called");
629     return NS_ERROR_NOT_IMPLEMENTED;
630 }
631 
632 NS_IMETHODIMP
GetIIDForParam(uint16_t aIndex,const nsXPTParamInfo * aParam,nsIID ** aRetVal)633 ShimInterfaceInfo::GetIIDForParam(uint16_t aIndex, const nsXPTParamInfo* aParam, nsIID** aRetVal)
634 {
635     MOZ_ASSERT(false, "This should never be called");
636     return NS_ERROR_NOT_IMPLEMENTED;
637 }
638 
639 NS_IMETHODIMP
GetTypeForParam(uint16_t aInex,const nsXPTParamInfo * aParam,uint16_t aDimension,nsXPTType * aRetVal)640 ShimInterfaceInfo::GetTypeForParam(uint16_t aInex, const nsXPTParamInfo* aParam, uint16_t aDimension, nsXPTType* aRetVal)
641 {
642     MOZ_ASSERT(false, "This should never be called");
643     return NS_ERROR_NOT_IMPLEMENTED;
644 }
645 
646 NS_IMETHODIMP
GetSizeIsArgNumberForParam(uint16_t aInex,const nsXPTParamInfo * aParam,uint16_t aDimension,uint8_t * aRetVal)647 ShimInterfaceInfo::GetSizeIsArgNumberForParam(uint16_t aInex, const nsXPTParamInfo* aParam, uint16_t aDimension, uint8_t* aRetVal)
648 {
649     MOZ_ASSERT(false, "This should never be called");
650     return NS_ERROR_NOT_IMPLEMENTED;
651 }
652 
653 NS_IMETHODIMP
GetInterfaceIsArgNumberForParam(uint16_t aInex,const nsXPTParamInfo * aParam,uint8_t * aRetVal)654 ShimInterfaceInfo::GetInterfaceIsArgNumberForParam(uint16_t aInex, const nsXPTParamInfo* aParam, uint8_t* aRetVal)
655 {
656     MOZ_ASSERT(false, "This should never be called");
657     return NS_ERROR_NOT_IMPLEMENTED;
658 }
659 
660 NS_IMETHODIMP
IsIID(const nsIID * aIID,bool * aRetVal)661 ShimInterfaceInfo::IsIID(const nsIID* aIID, bool* aRetVal)
662 {
663     *aRetVal = mIID.Equals(*aIID);
664     return NS_OK;
665 }
666 
667 NS_IMETHODIMP
GetNameShared(const char ** aName)668 ShimInterfaceInfo::GetNameShared(const char** aName)
669 {
670     *aName = mName.get();
671     return NS_OK;
672 }
673 
674 NS_IMETHODIMP
GetIIDShared(const nsIID ** aIID)675 ShimInterfaceInfo::GetIIDShared(const nsIID** aIID)
676 {
677     *aIID = &mIID;
678     return NS_OK;
679 }
680 
681 NS_IMETHODIMP
IsFunction(bool * aRetVal)682 ShimInterfaceInfo::IsFunction(bool* aRetVal)
683 {
684     *aRetVal = false;
685     return NS_OK;
686 }
687 
688 NS_IMETHODIMP
HasAncestor(const nsIID * aIID,bool * aRetVal)689 ShimInterfaceInfo::HasAncestor(const nsIID* aIID, bool* aRetVal)
690 {
691     *aRetVal = false;
692     return NS_OK;
693 }
694 
NS_IMETHODIMP_(nsresult)695 NS_IMETHODIMP_(nsresult)
696 ShimInterfaceInfo::GetIIDForParamNoAlloc(uint16_t aIndex, const nsXPTParamInfo* aInfo, nsIID* aIID)
697 {
698     MOZ_ASSERT(false, "This should never be called");
699     return NS_ERROR_NOT_IMPLEMENTED;
700 }
701