Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/ipc/TabChild.h
Line
Count
Source (jump to first uncovered line)
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_TabChild_h
8
#define mozilla_dom_TabChild_h
9
10
#include "mozilla/dom/ContentFrameMessageManager.h"
11
#include "mozilla/dom/PBrowserChild.h"
12
#include "nsIWebNavigation.h"
13
#include "nsCOMPtr.h"
14
#include "nsAutoPtr.h"
15
#include "nsIWebBrowserChrome2.h"
16
#include "nsIEmbeddingSiteWindow.h"
17
#include "nsIWebBrowserChromeFocus.h"
18
#include "nsIDOMEventListener.h"
19
#include "nsIInterfaceRequestor.h"
20
#include "nsIWindowProvider.h"
21
#include "nsIDOMWindow.h"
22
#include "nsIDocShell.h"
23
#include "nsIInterfaceRequestorUtils.h"
24
#include "nsFrameMessageManager.h"
25
#include "nsIPresShell.h"
26
#include "nsWeakReference.h"
27
#include "nsITabChild.h"
28
#include "nsITooltipListener.h"
29
#include "mozilla/Attributes.h"
30
#include "mozilla/dom/TabContext.h"
31
#include "mozilla/dom/CoalescedMouseData.h"
32
#include "mozilla/dom/CoalescedWheelData.h"
33
#include "mozilla/DOMEventTargetHelper.h"
34
#include "mozilla/EventDispatcher.h"
35
#include "mozilla/EventForwards.h"
36
#include "mozilla/layers/CompositorTypes.h"
37
#include "mozilla/layers/APZCCallbackHelper.h"
38
#include "mozilla/layers/CompositorOptions.h"
39
#include "nsIWebBrowserChrome3.h"
40
#include "mozilla/dom/ipc/IdType.h"
41
#include "AudioChannelService.h"
42
#include "PuppetWidget.h"
43
#include "mozilla/layers/GeckoContentController.h"
44
#include "nsDeque.h"
45
#include "nsISHistoryListener.h"
46
47
class nsIDOMWindowUtils;
48
class nsIHttpChannel;
49
class nsISerialEventTarget;
50
class nsWebBrowser;
51
52
template<typename T> class nsTHashtable;
53
template<typename T> class nsPtrHashKey;
54
55
namespace mozilla {
56
class AbstractThread;
57
namespace layout {
58
class RenderFrameChild;
59
} // namespace layout
60
61
namespace layers {
62
class APZChild;
63
class APZEventState;
64
class AsyncDragMetrics;
65
class IAPZCTreeManager;
66
class ImageCompositeNotification;
67
class PCompositorBridgeChild;
68
} // namespace layers
69
70
namespace widget {
71
struct AutoCacheNativeKeyCommands;
72
} // namespace widget
73
74
namespace dom {
75
76
class TabChild;
77
class TabGroup;
78
class ClonedMessageData;
79
class CoalescedMouseData;
80
class CoalescedWheelData;
81
82
class TabChildMessageManager : public ContentFrameMessageManager,
83
                               public nsIMessageSender,
84
                               public DispatcherTrait,
85
                               public nsSupportsWeakReference
86
{
87
public:
88
  explicit TabChildMessageManager(TabChild* aTabChild);
89
90
  NS_DECL_ISUPPORTS_INHERITED
91
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TabChildMessageManager, DOMEventTargetHelper)
92
93
  void MarkForCC();
94
95
  JSObject* WrapObject(JSContext* aCx,
96
                       JS::Handle<JSObject*> aGivenProto) override;
97
98
  virtual already_AddRefed<nsPIDOMWindowOuter> GetContent(ErrorResult& aError) override;
99
  virtual already_AddRefed<nsIDocShell> GetDocShell(ErrorResult& aError) override;
100
  virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() override;
101
  virtual uint64_t ChromeOuterWindowID() override;
102
103
  NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
104
105
  void
106
  GetEventTargetParent(EventChainPreVisitor& aVisitor) override
107
  {
108
    aVisitor.mForceContentDispatch = true;
109
  }
110
111
  // Dispatch a runnable related to the global.
112
  virtual nsresult Dispatch(mozilla::TaskCategory aCategory,
113
                            already_AddRefed<nsIRunnable>&& aRunnable) override;
114
115
  virtual nsISerialEventTarget*
116
  EventTargetFor(mozilla::TaskCategory aCategory) const override;
117
118
  virtual AbstractThread*
119
  AbstractMainThreadFor(mozilla::TaskCategory aCategory) override;
120
121
  RefPtr<TabChild> mTabChild;
122
123
protected:
124
  ~TabChildMessageManager();
125
};
126
127
class ContentListener final : public nsIDOMEventListener
128
{
129
public:
130
  explicit ContentListener(TabChild* aTabChild) : mTabChild(aTabChild) {}
131
  NS_DECL_ISUPPORTS
132
  NS_DECL_NSIDOMEVENTLISTENER
133
protected:
134
  ~ContentListener() {}
135
  TabChild* mTabChild;
136
};
137
138
// This is base clase which helps to share Viewport and touch related
139
// functionality between b2g/android FF/embedlite clients implementation.
140
// It make sense to place in this class all helper functions, and functionality
141
// which could be shared between Cross-process/Cross-thread implmentations.
142
class TabChildBase : public nsISupports,
143
                     public nsMessageManagerScriptExecutor,
144
                     public ipc::MessageManagerCallback
145
{
146
protected:
147
  typedef mozilla::widget::PuppetWidget PuppetWidget;
148
149
public:
150
  TabChildBase();
151
152
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
153
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TabChildBase)
154
155
  JSObject* WrapObject(JSContext* aCx,
156
                       JS::Handle<JSObject*> aGivenProto)
157
  {
158
    return mTabChildMessageManager->WrapObject(aCx, aGivenProto);
159
  }
160
161
162
  virtual nsIWebNavigation* WebNavigation() const = 0;
163
  virtual PuppetWidget* WebWidget() = 0;
164
  nsIPrincipal* GetPrincipal() { return mPrincipal; }
165
  virtual bool DoUpdateZoomConstraints(const uint32_t& aPresShellId,
166
                                       const mozilla::layers::FrameMetrics::ViewID& aViewId,
167
                                       const Maybe<mozilla::layers::ZoomConstraints>& aConstraints) = 0;
168
169
  virtual ScreenIntSize GetInnerSize() = 0;
170
171
  // Get the Document for the top-level window in this tab.
172
  already_AddRefed<nsIDocument> GetDocument() const;
173
174
  // Get the pres-shell of the document for the top-level window in this tab.
175
  already_AddRefed<nsIPresShell> GetPresShell() const;
176
177
protected:
178
  virtual ~TabChildBase();
179
180
  // Wraps up a JSON object as a structured clone and sends it to the browser
181
  // chrome script.
182
  //
183
  // XXX/bug 780335: Do the work the browser chrome script does in C++ instead
184
  // so we don't need things like this.
185
  void DispatchMessageManagerMessage(const nsAString& aMessageName,
186
                                     const nsAString& aJSONData);
187
188
  void ProcessUpdateFrame(const mozilla::layers::FrameMetrics& aFrameMetrics);
189
190
  bool UpdateFrameHandler(const mozilla::layers::FrameMetrics& aFrameMetrics);
191
192
protected:
193
  RefPtr<TabChildMessageManager> mTabChildMessageManager;
194
  nsCOMPtr<nsIWebBrowserChrome3> mWebBrowserChrome;
195
};
196
197
class TabChild final : public TabChildBase,
198
                       public PBrowserChild,
199
                       public nsIWebBrowserChrome2,
200
                       public nsIEmbeddingSiteWindow,
201
                       public nsIWebBrowserChromeFocus,
202
                       public nsIInterfaceRequestor,
203
                       public nsIWindowProvider,
204
                       public nsSupportsWeakReference,
205
                       public nsITabChild,
206
                       public nsIObserver,
207
                       public TabContext,
208
                       public nsITooltipListener,
209
                       public mozilla::ipc::IShmemAllocator
210
{
211
  typedef mozilla::dom::ClonedMessageData ClonedMessageData;
212
  typedef mozilla::dom::CoalescedMouseData CoalescedMouseData;
213
  typedef mozilla::dom::CoalescedWheelData CoalescedWheelData;
214
  typedef mozilla::layout::RenderFrameChild RenderFrameChild;
215
  typedef mozilla::layers::APZEventState APZEventState;
216
  typedef mozilla::layers::SetAllowedTouchBehaviorCallback SetAllowedTouchBehaviorCallback;
217
  typedef mozilla::layers::TouchBehaviorFlags TouchBehaviorFlags;
218
219
public:
220
  /**
221
   * Find TabChild of aTabId in the same content process of the
222
   * caller.
223
   */
224
  static already_AddRefed<TabChild> FindTabChild(const TabId& aTabId);
225
226
  // Return a list of all active TabChildren.
227
  static nsTArray<RefPtr<TabChild>> GetAll();
228
229
public:
230
  /**
231
   * Create a new TabChild object.
232
   */
233
  TabChild(nsIContentChild* aManager,
234
           const TabId& aTabId,
235
           TabGroup* aTabGroup,
236
           const TabContext& aContext,
237
           uint32_t aChromeFlags);
238
239
  nsresult Init();
240
241
  /** Return a TabChild with the given attributes. */
242
  static already_AddRefed<TabChild>
243
  Create(nsIContentChild* aManager, const TabId& aTabId,
244
         const TabId& aSameTabGroupAs,
245
         const TabContext& aContext, uint32_t aChromeFlags);
246
247
  // Let managees query if it is safe to send messages.
248
0
  bool IsDestroyed() const{ return mDestroyed; }
249
250
  const TabId GetTabId() const
251
  {
252
    MOZ_ASSERT(mUniqueId != 0);
253
    return mUniqueId;
254
  }
255
256
  NS_DECL_ISUPPORTS_INHERITED
257
  NS_DECL_NSIWEBBROWSERCHROME
258
  NS_DECL_NSIWEBBROWSERCHROME2
259
  NS_DECL_NSIEMBEDDINGSITEWINDOW
260
  NS_DECL_NSIWEBBROWSERCHROMEFOCUS
261
  NS_DECL_NSIINTERFACEREQUESTOR
262
  NS_DECL_NSIWINDOWPROVIDER
263
  NS_DECL_NSITABCHILD
264
  NS_DECL_NSIOBSERVER
265
  NS_DECL_NSITOOLTIPLISTENER
266
267
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(TabChild, TabChildBase)
268
269
  FORWARD_SHMEM_ALLOCATOR_TO(PBrowserChild)
270
271
  TabChildMessageManager* GetMessageManager()
272
  {
273
    return mTabChildMessageManager;
274
  }
275
276
  /**
277
   * MessageManagerCallback methods that we override.
278
   */
279
  virtual bool DoSendBlockingMessage(JSContext* aCx,
280
                                     const nsAString& aMessage,
281
                                     StructuredCloneData& aData,
282
                                     JS::Handle<JSObject *> aCpows,
283
                                     nsIPrincipal* aPrincipal,
284
                                     nsTArray<StructuredCloneData>* aRetVal,
285
                                     bool aIsSync) override;
286
287
  virtual nsresult DoSendAsyncMessage(JSContext* aCx,
288
                                      const nsAString& aMessage,
289
                                      StructuredCloneData& aData,
290
                                      JS::Handle<JSObject *> aCpows,
291
                                      nsIPrincipal* aPrincipal) override;
292
293
  virtual bool
294
  DoUpdateZoomConstraints(const uint32_t& aPresShellId,
295
                          const ViewID& aViewId,
296
                          const Maybe<ZoomConstraints>& aConstraints) override;
297
298
  virtual mozilla::ipc::IPCResult RecvLoadURL(const nsCString& aURI,
299
                                              const ShowInfo& aInfo) override;
300
  virtual mozilla::ipc::IPCResult
301
  RecvShow(const ScreenIntSize& aSize,
302
           const ShowInfo& aInfo,
303
           const bool& aParentIsActive,
304
           const nsSizeMode& aSizeMode) override;
305
306
  virtual mozilla::ipc::IPCResult
307
  RecvInitRendering(const TextureFactoryIdentifier& aTextureFactoryIdentifier,
308
                    const layers::LayersId& aLayersId,
309
                    const mozilla::layers::CompositorOptions& aCompositorOptions,
310
                    const bool& aLayersConnected,
311
                    PRenderFrameChild* aRenderFrame) override;
312
313
  virtual mozilla::ipc::IPCResult
314
  RecvUpdateDimensions(const mozilla::dom::DimensionInfo& aDimensionInfo) override;
315
  virtual mozilla::ipc::IPCResult
316
  RecvSizeModeChanged(const nsSizeMode& aSizeMode) override;
317
318
  mozilla::ipc::IPCResult RecvActivate();
319
320
  mozilla::ipc::IPCResult RecvDeactivate();
321
322
  MOZ_CAN_RUN_SCRIPT
323
  virtual mozilla::ipc::IPCResult RecvMouseEvent(const nsString& aType,
324
                                                 const float& aX,
325
                                                 const float& aY,
326
                                                 const int32_t& aButton,
327
                                                 const int32_t& aClickCount,
328
                                                 const int32_t& aModifiers,
329
                                                 const bool& aIgnoreRootScrollFrame) override;
330
331
  virtual mozilla::ipc::IPCResult RecvRealMouseMoveEvent(const mozilla::WidgetMouseEvent& aEvent,
332
                                                         const ScrollableLayerGuid& aGuid,
333
                                                         const uint64_t& aInputBlockId) override;
334
335
  virtual mozilla::ipc::IPCResult
336
  RecvNormalPriorityRealMouseMoveEvent(const mozilla::WidgetMouseEvent& aEvent,
337
                                       const ScrollableLayerGuid& aGuid,
338
                                       const uint64_t& aInputBlockId) override;
339
340
  virtual mozilla::ipc::IPCResult RecvSynthMouseMoveEvent(const mozilla::WidgetMouseEvent& aEvent,
341
                                                          const ScrollableLayerGuid& aGuid,
342
                                                          const uint64_t& aInputBlockId) override;
343
  virtual mozilla::ipc::IPCResult
344
  RecvNormalPrioritySynthMouseMoveEvent(const mozilla::WidgetMouseEvent& aEvent,
345
                                        const ScrollableLayerGuid& aGuid,
346
                                        const uint64_t& aInputBlockId) override;
347
348
  virtual mozilla::ipc::IPCResult RecvRealMouseButtonEvent(const mozilla::WidgetMouseEvent& aEvent,
349
                                                           const ScrollableLayerGuid& aGuid,
350
                                                           const uint64_t& aInputBlockId) override;
351
  virtual mozilla::ipc::IPCResult
352
  RecvNormalPriorityRealMouseButtonEvent(const mozilla::WidgetMouseEvent& aEvent,
353
                                         const ScrollableLayerGuid& aGuid,
354
                                         const uint64_t& aInputBlockId) override;
355
356
  virtual mozilla::ipc::IPCResult RecvRealDragEvent(const WidgetDragEvent& aEvent,
357
                                                    const uint32_t& aDragAction,
358
                                                    const uint32_t& aDropEffect,
359
                                                    const nsCString& aPrincipalURISpec) override;
360
361
  virtual mozilla::ipc::IPCResult
362
  RecvRealKeyEvent(const mozilla::WidgetKeyboardEvent& aEvent) override;
363
364
  virtual mozilla::ipc::IPCResult
365
  RecvNormalPriorityRealKeyEvent(const mozilla::WidgetKeyboardEvent& aEvent) override;
366
367
  virtual mozilla::ipc::IPCResult RecvMouseWheelEvent(const mozilla::WidgetWheelEvent& aEvent,
368
                                                      const ScrollableLayerGuid& aGuid,
369
                                                      const uint64_t& aInputBlockId) override;
370
371
  virtual mozilla::ipc::IPCResult
372
  RecvNormalPriorityMouseWheelEvent(const mozilla::WidgetWheelEvent& aEvent,
373
                                    const ScrollableLayerGuid& aGuid,
374
                                    const uint64_t& aInputBlockId) override;
375
376
  virtual mozilla::ipc::IPCResult RecvRealTouchEvent(const WidgetTouchEvent& aEvent,
377
                                                     const ScrollableLayerGuid& aGuid,
378
                                                     const uint64_t& aInputBlockId,
379
                                                     const nsEventStatus& aApzResponse) override;
380
381
  virtual mozilla::ipc::IPCResult
382
  RecvNormalPriorityRealTouchEvent(const WidgetTouchEvent& aEvent,
383
                                   const ScrollableLayerGuid& aGuid,
384
                                   const uint64_t& aInputBlockId,
385
                                   const nsEventStatus& aApzResponse) override;
386
387
  virtual mozilla::ipc::IPCResult
388
  RecvRealTouchMoveEvent(const WidgetTouchEvent& aEvent,
389
                         const ScrollableLayerGuid& aGuid,
390
                         const uint64_t& aInputBlockId,
391
                         const nsEventStatus& aApzResponse) override;
392
393
  virtual mozilla::ipc::IPCResult
394
  RecvNormalPriorityRealTouchMoveEvent(const WidgetTouchEvent& aEvent,
395
                                       const ScrollableLayerGuid& aGuid,
396
                                       const uint64_t& aInputBlockId,
397
                                       const nsEventStatus& aApzResponse) override;
398
399
  virtual mozilla::ipc::IPCResult RecvNativeSynthesisResponse(const uint64_t& aObserverId,
400
                                                              const nsCString& aResponse) override;
401
402
  virtual mozilla::ipc::IPCResult RecvPluginEvent(const WidgetPluginEvent& aEvent) override;
403
404
  virtual mozilla::ipc::IPCResult
405
  RecvCompositionEvent(const mozilla::WidgetCompositionEvent& aEvent) override;
406
407
  virtual mozilla::ipc::IPCResult
408
  RecvNormalPriorityCompositionEvent(
409
    const mozilla::WidgetCompositionEvent& aEvent) override;
410
411
  virtual mozilla::ipc::IPCResult
412
  RecvSelectionEvent(const mozilla::WidgetSelectionEvent& aEvent) override;
413
414
  virtual mozilla::ipc::IPCResult
415
  RecvNormalPrioritySelectionEvent(
416
    const mozilla::WidgetSelectionEvent& aEvent) override;
417
418
  virtual mozilla::ipc::IPCResult
419
  RecvPasteTransferable(const IPCDataTransfer& aDataTransfer,
420
                        const bool& aIsPrivateData,
421
                        const IPC::Principal& aRequestingPrincipal,
422
                        const uint32_t& aContentPolicyType) override;
423
424
  virtual mozilla::ipc::IPCResult
425
  RecvActivateFrameEvent(const nsString& aType, const bool& aCapture) override;
426
427
  virtual mozilla::ipc::IPCResult RecvLoadRemoteScript(const nsString& aURL,
428
                                                       const bool& aRunInGlobalScope) override;
429
430
  virtual mozilla::ipc::IPCResult RecvAsyncMessage(const nsString& aMessage,
431
                                                   InfallibleTArray<CpowEntry>&& aCpows,
432
                                                   const IPC::Principal& aPrincipal,
433
                                                   const ClonedMessageData& aData) override;
434
  virtual mozilla::ipc::IPCResult
435
  RecvSwappedWithOtherRemoteLoader(const IPCTabContext& aContext) override;
436
437
  virtual PDocAccessibleChild*
438
  AllocPDocAccessibleChild(PDocAccessibleChild*, const uint64_t&,
439
                           const uint32_t&, const IAccessibleHolder&) override;
440
441
  virtual bool DeallocPDocAccessibleChild(PDocAccessibleChild*) override;
442
443
  virtual PColorPickerChild*
444
  AllocPColorPickerChild(const nsString& aTitle,
445
                         const nsString& aInitialColor) override;
446
447
  virtual bool DeallocPColorPickerChild(PColorPickerChild* aActor) override;
448
449
  virtual PFilePickerChild*
450
  AllocPFilePickerChild(const nsString& aTitle, const int16_t& aMode) override;
451
452
  virtual bool
453
  DeallocPFilePickerChild(PFilePickerChild* aActor) override;
454
455
  virtual PIndexedDBPermissionRequestChild*
456
  AllocPIndexedDBPermissionRequestChild(const Principal& aPrincipal) override;
457
458
  virtual bool
459
  DeallocPIndexedDBPermissionRequestChild(PIndexedDBPermissionRequestChild* aActor) override;
460
461
  virtual nsIWebNavigation* WebNavigation() const override
462
0
  {
463
0
    return mWebNav;
464
0
  }
465
466
0
  virtual PuppetWidget* WebWidget() override { return mPuppetWidget; }
467
468
  bool IsTransparent() const { return mIsTransparent; }
469
470
  void GetMaxTouchPoints(uint32_t* aTouchPoints)
471
  {
472
    *aTouchPoints = mMaxTouchPoints;
473
  }
474
475
  void SetMaxTouchPoints(uint32_t aMaxTouchPoints)
476
0
  {
477
0
    mMaxTouchPoints = aMaxTouchPoints;
478
0
  }
479
480
  hal::ScreenOrientation GetOrientation() const { return mOrientation; }
481
482
  void SetBackgroundColor(const nscolor& aColor);
483
484
  void NotifyPainted();
485
486
  void RequestEditCommands(nsIWidget::NativeKeyBindingsType aType,
487
                           const WidgetKeyboardEvent& aEvent,
488
                           nsTArray<CommandInt>& aCommands);
489
490
  /**
491
   * Signal to this TabChild that it should be made visible:
492
   * activated widget, retained layer tree, etc.  (Respectively,
493
   * made not visible.)
494
   */
495
  void MakeVisible();
496
  void MakeHidden();
497
  bool IsVisible();
498
499
  nsIContentChild* Manager() const { return mManager; }
500
501
  static inline TabChild*
502
  GetFrom(nsIDocShell* aDocShell)
503
  {
504
    if (!aDocShell) {
505
      return nullptr;
506
    }
507
508
    nsCOMPtr<nsITabChild> tc = aDocShell->GetTabChild();
509
    return static_cast<TabChild*>(tc.get());
510
  }
511
512
  static inline TabChild*
513
  GetFrom(mozIDOMWindow* aWindow)
514
  {
515
    nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
516
    nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav);
517
    return GetFrom(docShell);
518
  }
519
520
  static inline TabChild*
521
  GetFrom(mozIDOMWindowProxy* aWindow)
522
  {
523
    nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
524
    nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav);
525
    return GetFrom(docShell);
526
  }
527
528
  static TabChild* GetFrom(nsIPresShell* aPresShell);
529
  static TabChild* GetFrom(layers::LayersId aLayersId);
530
531
0
  layers::LayersId GetLayersId() { return mLayersId; }
532
  Maybe<bool> IsLayersConnected() { return mLayersConnected; }
533
534
  void DidComposite(mozilla::layers::TransactionId aTransactionId,
535
                    const TimeStamp& aCompositeStart,
536
                    const TimeStamp& aCompositeEnd);
537
538
  void DidRequestComposite(const TimeStamp& aCompositeReqStart,
539
                           const TimeStamp& aCompositeReqEnd);
540
541
  void ClearCachedResources();
542
  void InvalidateLayers();
543
  void ReinitRendering();
544
  void ReinitRenderingForDeviceReset();
545
546
  static inline TabChild* GetFrom(nsIDOMWindow* aWindow)
547
  {
548
    nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
549
    nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav);
550
    return GetFrom(docShell);
551
  }
552
553
  virtual mozilla::ipc::IPCResult RecvUIResolutionChanged(const float& aDpi,
554
                                                          const int32_t& aRounding,
555
                                                          const double& aScale) override;
556
557
  virtual mozilla::ipc::IPCResult
558
  RecvThemeChanged(nsTArray<LookAndFeelInt>&& aLookAndFeelIntCache) override;
559
560
  virtual mozilla::ipc::IPCResult
561
  RecvHandleAccessKey(const WidgetKeyboardEvent& aEvent,
562
                      nsTArray<uint32_t>&& aCharCodes) override;
563
564
  virtual mozilla::ipc::IPCResult RecvSetUseGlobalHistory(const bool& aUse) override;
565
566
  virtual mozilla::ipc::IPCResult RecvHandledWindowedPluginKeyEvent(
567
    const mozilla::NativeEventData& aKeyEventData,
568
    const bool& aIsConsumed) override;
569
570
  virtual mozilla::ipc::IPCResult RecvPrint(const uint64_t& aOuterWindowID,
571
                                            const PrintData& aPrintData) override;
572
573
  virtual mozilla::ipc::IPCResult RecvUpdateNativeWindowHandle(const uintptr_t& aNewHandle) override;
574
575
  /**
576
   * Native widget remoting protocol for use with windowed plugins with e10s.
577
   */
578
  PPluginWidgetChild* AllocPPluginWidgetChild() override;
579
580
  bool DeallocPPluginWidgetChild(PPluginWidgetChild* aActor) override;
581
582
#ifdef XP_WIN
583
  nsresult CreatePluginWidget(nsIWidget* aParent, nsIWidget** aOut);
584
#endif
585
586
  virtual PPaymentRequestChild*
587
  AllocPPaymentRequestChild() override;
588
589
  virtual bool
590
  DeallocPPaymentRequestChild(PPaymentRequestChild* aActor) override;
591
592
  LayoutDeviceIntPoint GetClientOffset() const { return mClientOffset; }
593
  LayoutDeviceIntPoint GetChromeOffset() const { return mChromeOffset; };
594
595
  bool IPCOpen() const { return mIPCOpen; }
596
597
  bool ParentIsActive() const
598
0
  {
599
0
    return mParentIsActive;
600
0
  }
601
602
  const mozilla::layers::CompositorOptions& GetCompositorOptions() const;
603
  bool AsyncPanZoomEnabled() const;
604
605
  virtual ScreenIntSize GetInnerSize() override;
606
607
  // Call RecvShow(nsIntSize(0, 0)) and block future calls to RecvShow().
608
  void DoFakeShow(const TextureFactoryIdentifier& aTextureFactoryIdentifier,
609
                  const layers::LayersId& aLayersId,
610
                  const mozilla::layers::CompositorOptions& aCompositorOptions,
611
                  PRenderFrameChild* aRenderFrame,
612
                  const ShowInfo& aShowInfo);
613
614
  void ContentReceivedInputBlock(const ScrollableLayerGuid& aGuid,
615
                                 uint64_t aInputBlockId,
616
                                 bool aPreventDefault) const;
617
  void SetTargetAPZC(uint64_t aInputBlockId,
618
                    const nsTArray<ScrollableLayerGuid>& aTargets) const;
619
  MOZ_CAN_RUN_SCRIPT
620
  mozilla::ipc::IPCResult RecvHandleTap(const layers::GeckoContentController::TapType& aType,
621
                                        const LayoutDevicePoint& aPoint,
622
                                        const Modifiers& aModifiers,
623
                                        const ScrollableLayerGuid& aGuid,
624
                                        const uint64_t& aInputBlockId) override;
625
626
  MOZ_CAN_RUN_SCRIPT
627
  mozilla::ipc::IPCResult
628
  RecvNormalPriorityHandleTap(const layers::GeckoContentController::TapType& aType,
629
                              const LayoutDevicePoint& aPoint,
630
                              const Modifiers& aModifiers,
631
                              const ScrollableLayerGuid& aGuid,
632
                              const uint64_t& aInputBlockId) override;
633
634
  void SetAllowedTouchBehavior(uint64_t aInputBlockId,
635
                               const nsTArray<TouchBehaviorFlags>& aFlags) const;
636
637
  bool UpdateFrame(const FrameMetrics& aFrameMetrics);
638
  bool NotifyAPZStateChange(const ViewID& aViewId,
639
                            const layers::GeckoContentController::APZStateChange& aChange,
640
                            const int& aArg);
641
  void StartScrollbarDrag(const layers::AsyncDragMetrics& aDragMetrics);
642
  void ZoomToRect(const uint32_t& aPresShellId,
643
                  const FrameMetrics::ViewID& aViewId,
644
                  const CSSRect& aRect,
645
                  const uint32_t& aFlags);
646
647
  // Request that the docshell be marked as active.
648
  void PaintWhileInterruptingJS(const layers::LayersObserverEpoch& aEpoch,
649
                                bool aForceRepaint);
650
651
  layers::LayersObserverEpoch LayersObserverEpoch() const { return mLayersObserverEpoch; }
652
653
#if defined(XP_WIN) && defined(ACCESSIBILITY)
654
  uintptr_t GetNativeWindowHandle() const { return mNativeWindowHandle; }
655
#endif
656
657
  // These methods return `true` if this TabChild is currently awaiting a
658
  // Large-Allocation header.
659
  bool StopAwaitingLargeAlloc();
660
  bool IsAwaitingLargeAlloc();
661
662
  mozilla::dom::TabGroup* TabGroup();
663
664
#if defined(ACCESSIBILITY)
665
  void SetTopLevelDocAccessibleChild(PDocAccessibleChild* aTopLevelChild)
666
  {
667
    mTopLevelDocAccessibleChild = aTopLevelChild;
668
  }
669
670
  PDocAccessibleChild* GetTopLevelDocAccessibleChild()
671
  {
672
    return mTopLevelDocAccessibleChild;
673
  }
674
#endif
675
676
  void AddPendingDocShellBlocker();
677
  void RemovePendingDocShellBlocker();
678
679
  // The HANDLE object for the widget this TabChild in.
680
  WindowsHandle WidgetNativeData()
681
  {
682
    return mWidgetNativeData;
683
  }
684
685
  // Prepare to dispatch all coalesced mousemove events. We'll move all data
686
  // in mCoalescedMouseData to a nsDeque; then we start processing them. We
687
  // can't fetch the coalesced event one by one and dispatch it because we may
688
  // reentry the event loop and access to the same hashtable. It's called when
689
  // dispatching some mouse events other than mousemove.
690
  void FlushAllCoalescedMouseData();
691
  void ProcessPendingCoalescedMouseDataAndDispatchEvents();
692
693
  void HandleRealMouseButtonEvent(const WidgetMouseEvent& aEvent,
694
                                  const ScrollableLayerGuid& aGuid,
695
                                  const uint64_t& aInputBlockId);
696
697
  static bool HasVisibleTabs()
698
  {
699
    return sVisibleTabs && !sVisibleTabs->IsEmpty();
700
  }
701
702
  // Returns the set of TabChilds that are currently rendering layers. There
703
  // can be multiple TabChilds in this state if Firefox has multiple windows
704
  // open or is warming tabs up. There can also be zero TabChilds in this
705
  // state. Note that this function should only be called if HasVisibleTabs()
706
  // returns true.
707
  static const nsTHashtable<nsPtrHashKey<TabChild>>& GetVisibleTabs()
708
  {
709
    MOZ_ASSERT(HasVisibleTabs());
710
    return *sVisibleTabs;
711
  }
712
713
protected:
714
  virtual ~TabChild();
715
716
  virtual PRenderFrameChild* AllocPRenderFrameChild() override;
717
718
  virtual bool DeallocPRenderFrameChild(PRenderFrameChild* aFrame) override;
719
720
  virtual mozilla::ipc::IPCResult RecvDestroy() override;
721
722
  virtual mozilla::ipc::IPCResult RecvSetDocShellIsActive(const bool& aIsActive) override;
723
724
  virtual mozilla::ipc::IPCResult RecvRenderLayers(const bool& aEnabled, const bool& aForce, const layers::LayersObserverEpoch& aEpoch) override;
725
726
  virtual mozilla::ipc::IPCResult RecvNavigateByKey(const bool& aForward,
727
                                                    const bool& aForDocumentNavigation) override;
728
729
  virtual mozilla::ipc::IPCResult RecvRequestNotifyAfterRemotePaint() override;
730
731
  virtual mozilla::ipc::IPCResult RecvSuppressDisplayport(const bool& aEnabled) override;
732
733
  virtual mozilla::ipc::IPCResult RecvParentActivated(const bool& aActivated) override;
734
735
  virtual mozilla::ipc::IPCResult RecvSetKeyboardIndicators(const UIStateChangeType& aShowAccelerators,
736
                                                            const UIStateChangeType& aShowFocusRings) override;
737
738
  virtual mozilla::ipc::IPCResult RecvStopIMEStateManagement() override;
739
740
  virtual mozilla::ipc::IPCResult RecvAwaitLargeAlloc() override;
741
742
  virtual mozilla::ipc::IPCResult RecvSetWindowName(const nsString& aName) override;
743
744
  virtual mozilla::ipc::IPCResult RecvAllowScriptsToClose() override;
745
746
  virtual mozilla::ipc::IPCResult RecvSetOriginAttributes(const OriginAttributes& aOriginAttributes) override;
747
748
  virtual mozilla::ipc::IPCResult RecvSetWidgetNativeData(const WindowsHandle& aWidgetNativeData) override;
749
750
private:
751
  void HandleDoubleTap(const CSSPoint& aPoint, const Modifiers& aModifiers,
752
                       const ScrollableLayerGuid& aGuid);
753
754
  // Notify others that our TabContext has been updated.
755
  //
756
  // You should call this after calling TabContext::SetTabContext().  We also
757
  // call this during Init().
758
  //
759
  // @param aIsPreallocated  true if this is called for Preallocated Tab.
760
  void NotifyTabContextUpdated(bool aIsPreallocated);
761
762
  // Update the frameType on our docshell.
763
  void UpdateFrameType();
764
765
  void ActorDestroy(ActorDestroyReason why) override;
766
767
  bool InitTabChildMessageManager();
768
769
  void InitRenderingState(const TextureFactoryIdentifier& aTextureFactoryIdentifier,
770
                          const layers::LayersId& aLayersId,
771
                          const mozilla::layers::CompositorOptions& aCompositorOptions,
772
                          PRenderFrameChild* aRenderFrame);
773
  void InitAPZState();
774
775
  void DestroyWindow();
776
777
  void ApplyShowInfo(const ShowInfo& aInfo);
778
779
  bool HasValidInnerSize();
780
781
  void SetTabId(const TabId& aTabId);
782
783
  ScreenIntRect GetOuterRect();
784
785
  void SetUnscaledInnerSize(const CSSSize& aSize)
786
  {
787
    mUnscaledInnerSize = aSize;
788
  }
789
790
  bool SkipRepeatedKeyEvent(const WidgetKeyboardEvent& aEvent);
791
792
  void UpdateRepeatedKeyEventEndTime(const WidgetKeyboardEvent& aEvent);
793
794
  bool MaybeCoalesceWheelEvent(const WidgetWheelEvent& aEvent,
795
                               const ScrollableLayerGuid& aGuid,
796
                               const uint64_t& aInputBlockId,
797
                               bool* aIsNextWheelEvent);
798
799
  void MaybeDispatchCoalescedWheelEvent();
800
801
  /**
802
   * Dispatch aEvent on aEvent.mWidget.
803
   */
804
  nsEventStatus DispatchWidgetEventViaAPZ(WidgetGUIEvent& aEvent);
805
806
  void DispatchWheelEvent(const WidgetWheelEvent& aEvent,
807
                          const ScrollableLayerGuid& aGuid,
808
                          const uint64_t& aInputBlockId);
809
810
  void InternalSetDocShellIsActive(bool aIsActive);
811
812
  bool CreateRemoteLayerManager(mozilla::layers::PCompositorBridgeChild* aCompositorChild);
813
814
  class DelayedDeleteRunnable;
815
816
  TextureFactoryIdentifier mTextureFactoryIdentifier;
817
  RefPtr<nsWebBrowser> mWebBrowser;
818
  nsCOMPtr<nsIWebNavigation> mWebNav;
819
  RefPtr<mozilla::dom::TabGroup> mTabGroup;
820
  RefPtr<PuppetWidget> mPuppetWidget;
821
  nsCOMPtr<nsIURI> mLastURI;
822
  RenderFrameChild* mRemoteFrame;
823
  RefPtr<nsIContentChild> mManager;
824
  uint32_t mChromeFlags;
825
  uint32_t mMaxTouchPoints;
826
  layers::LayersId mLayersId;
827
  int64_t mBeforeUnloadListeners;
828
  CSSRect mUnscaledOuterRect;
829
  Maybe<bool> mLayersConnected;
830
  bool mDidFakeShow;
831
  bool mNotified;
832
  bool mTriedBrowserInit;
833
  hal::ScreenOrientation mOrientation;
834
835
  bool mIgnoreKeyPressEvent;
836
  RefPtr<APZEventState> mAPZEventState;
837
  SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback;
838
  bool mHasValidInnerSize;
839
  bool mDestroyed;
840
  // Position of client area relative to the outer window
841
  LayoutDeviceIntPoint mClientOffset;
842
  // Position of tab, relative to parent widget (typically the window)
843
  LayoutDeviceIntPoint mChromeOffset;
844
  TabId mUniqueId;
845
846
  // Whether or not this tab has siblings (other tabs in the same window).
847
  // This is one factor used when choosing to allow or deny a non-system
848
  // script's attempt to resize the window.
849
  bool mHasSiblings;
850
851
  // Holds the compositor options for the compositor rendering this tab,
852
  // once we find out which compositor that is.
853
  Maybe<mozilla::layers::CompositorOptions> mCompositorOptions;
854
855
  friend class ContentChild;
856
857
  bool mIsTransparent;
858
859
  bool mIPCOpen;
860
  bool mParentIsActive;
861
  CSSSize mUnscaledInnerSize;
862
  bool mDidSetRealShowInfo;
863
  bool mDidLoadURLInit;
864
  bool mAwaitingLA;
865
866
  bool mSkipKeyPress;
867
868
  // Store the end time of the handling of the last repeated keydown/keypress
869
  // event so that in case event handling takes time, some repeated events can
870
  // be skipped to not flood child process.
871
  mozilla::TimeStamp mRepeatedKeyEventTime;
872
873
  // Similar to mRepeatedKeyEventTime, store the end time (from parent process)
874
  // of handling the last repeated wheel event so that in case event handling
875
  // takes time, some repeated events can be skipped to not flood child process.
876
  mozilla::TimeStamp mLastWheelProcessedTimeFromParent;
877
  mozilla::TimeDuration mLastWheelProcessingDuration;
878
879
  // Hash table to track coalesced mousemove events for different pointers.
880
  nsClassHashtable<nsUint32HashKey, CoalescedMouseData> mCoalescedMouseData;
881
882
  nsDeque mToBeDispatchedMouseData;
883
884
  CoalescedWheelData mCoalescedWheelData;
885
  RefPtr<CoalescedMouseMoveFlusher> mCoalescedMouseEventFlusher;
886
887
  RefPtr<layers::IAPZCTreeManager> mApzcTreeManager;
888
889
  // The most recently seen layer observer epoch in RecvSetDocShellIsActive.
890
  layers::LayersObserverEpoch mLayersObserverEpoch;
891
892
#if defined(XP_WIN) && defined(ACCESSIBILITY)
893
  // The handle associated with the native window that contains this tab
894
  uintptr_t mNativeWindowHandle;
895
#endif // defined(XP_WIN)
896
897
#if defined(ACCESSIBILITY)
898
  PDocAccessibleChild* mTopLevelDocAccessibleChild;
899
#endif
900
  bool mCoalesceMouseMoveEvents;
901
902
  // In some circumstances, a DocShell might be in a state where it is
903
  // "blocked", and we should not attempt to change its active state or
904
  // the underlying PresShell state until the DocShell becomes unblocked.
905
  // It is possible, however, for the parent process to send commands to
906
  // change those states while the DocShell is blocked. We store those
907
  // states temporarily as "pending", and only apply them once the DocShell
908
  // is no longer blocked.
909
  bool mPendingDocShellIsActive;
910
  bool mPendingDocShellReceivedMessage;
911
  bool mPendingRenderLayers;
912
  bool mPendingRenderLayersReceivedMessage;
913
  layers::LayersObserverEpoch mPendingLayersObserverEpoch;
914
  // When mPendingDocShellBlockers is greater than 0, the DocShell is blocked,
915
  // and once it reaches 0, it is no longer blocked.
916
  uint32_t mPendingDocShellBlockers;
917
918
  WindowsHandle mWidgetNativeData;
919
920
  // This state is used to keep track of the current visible tabs (the ones rendering
921
  // layers). There may be more than one if there are multiple browser windows open, or
922
  // tabs are being warmed up. There may be none if this process does not host any
923
  // visible or warming tabs.
924
  static nsTHashtable<nsPtrHashKey<TabChild>>* sVisibleTabs;
925
926
  DISALLOW_EVIL_CONSTRUCTORS(TabChild);
927
};
928
929
} // namespace dom
930
} // namespace mozilla
931
932
#endif // mozilla_dom_TabChild_h