Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/InProcessTabChildMessageManager.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 nsInProcessTabChildGlobal_h
8
#define nsInProcessTabChildGlobal_h
9
10
#include "mozilla/Attributes.h"
11
#include "mozilla/DOMEventTargetHelper.h"
12
#include "mozilla/RefPtr.h"
13
#include "mozilla/dom/ContentFrameMessageManager.h"
14
#include "nsCOMPtr.h"
15
#include "nsFrameMessageManager.h"
16
#include "nsIScriptContext.h"
17
#include "nsIScriptObjectPrincipal.h"
18
#include "nsIScriptContext.h"
19
#include "nsIClassInfo.h"
20
#include "nsIDocShell.h"
21
#include "nsCOMArray.h"
22
#include "nsIRunnable.h"
23
#include "nsWeakReference.h"
24
25
namespace mozilla {
26
class EventChainPreVisitor;
27
28
namespace dom {
29
30
/**
31
 * This class implements a ContentFrameMessageManager for use by frame loaders
32
 * in the parent process. It is bound to a DocShell rather than a TabChild, and
33
 * does not use any IPC infrastructure for its message passing.
34
 */
35
36
class InProcessTabChildMessageManager final : public ContentFrameMessageManager,
37
                                              public nsMessageManagerScriptExecutor,
38
                                              public nsIInProcessContentFrameMessageManager,
39
                                              public nsSupportsWeakReference,
40
                                              public mozilla::dom::ipc::MessageManagerCallback
41
{
42
  typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData;
43
44
private:
45
  InProcessTabChildMessageManager(nsIDocShell* aShell, nsIContent* aOwner,
46
                                  nsFrameMessageManager* aChrome);
47
48
public:
49
  static already_AddRefed<InProcessTabChildMessageManager> Create(nsIDocShell* aShell,
50
                                                                  nsIContent* aOwner,
51
                                                                  nsFrameMessageManager* aChrome)
52
0
  {
53
0
    RefPtr<InProcessTabChildMessageManager> mm =
54
0
      new InProcessTabChildMessageManager(aShell, aOwner, aChrome);
55
0
56
0
    NS_ENSURE_TRUE(mm->Init(), nullptr);
57
0
58
0
    return mm.forget();
59
0
  }
60
61
  NS_DECL_ISUPPORTS_INHERITED
62
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(InProcessTabChildMessageManager,
63
                                                         DOMEventTargetHelper)
64
65
  void MarkForCC();
66
67
  virtual JSObject* WrapObject(JSContext* aCx,
68
                               JS::Handle<JSObject*> aGivenProto) override;
69
70
  virtual already_AddRefed<nsPIDOMWindowOuter>
71
    GetContent(ErrorResult& aError) override;
72
  virtual already_AddRefed<nsIDocShell>
73
    GetDocShell(ErrorResult& aError) override
74
0
  {
75
0
    nsCOMPtr<nsIDocShell> docShell(mDocShell);
76
0
    return docShell.forget();
77
0
  }
78
  virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() override;
79
  virtual uint64_t ChromeOuterWindowID() override;
80
81
  NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
82
83
  NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
84
85
  void CacheFrameLoader(nsFrameLoader* aFrameLoader);
86
87
  /**
88
   * MessageManagerCallback methods that we override.
89
   */
90
  virtual bool DoSendBlockingMessage(JSContext* aCx,
91
                                      const nsAString& aMessage,
92
                                      StructuredCloneData& aData,
93
                                      JS::Handle<JSObject *> aCpows,
94
                                      nsIPrincipal* aPrincipal,
95
                                      nsTArray<StructuredCloneData>* aRetVal,
96
                                      bool aIsSync) override;
97
  virtual nsresult DoSendAsyncMessage(JSContext* aCx,
98
                                      const nsAString& aMessage,
99
                                      StructuredCloneData& aData,
100
                                      JS::Handle<JSObject *> aCpows,
101
                                      nsIPrincipal* aPrincipal) override;
102
103
  void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
104
105
  void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope);
106
  void FireUnloadEvent();
107
  void DisconnectEventListeners();
108
  void Disconnect();
109
  void SendMessageToParent(const nsString& aMessage, bool aSync,
110
                           const nsString& aJSON,
111
                           nsTArray<nsString>* aJSONRetVal);
112
  nsFrameMessageManager* GetInnerManager()
113
0
  {
114
0
    return static_cast<nsFrameMessageManager*>(mMessageManager.get());
115
0
  }
116
117
0
  void SetOwner(nsIContent* aOwner) { mOwner = aOwner; }
118
  nsFrameMessageManager* GetChromeMessageManager()
119
0
  {
120
0
    return mChromeMessageManager;
121
0
  }
122
  void SetChromeMessageManager(nsFrameMessageManager* aParent)
123
0
  {
124
0
    mChromeMessageManager = aParent;
125
0
  }
126
127
  already_AddRefed<nsFrameLoader> GetFrameLoader();
128
129
protected:
130
  virtual ~InProcessTabChildMessageManager();
131
132
  nsCOMPtr<nsIDocShell> mDocShell;
133
  bool mLoadingScript;
134
135
  // Is this the message manager for an in-process <iframe mozbrowser>? This
136
  // affects where events get sent, so it affects GetEventTargetParent.
137
  bool mIsBrowserFrame;
138
  bool mPreventEventsEscaping;
139
140
  // We keep a strong reference to the frameloader after we've started
141
  // teardown. This allows us to dispatch message manager messages during this
142
  // time.
143
  RefPtr<nsFrameLoader> mFrameLoader;
144
public:
145
  nsIContent* mOwner;
146
  nsFrameMessageManager* mChromeMessageManager;
147
};
148
149
} // namespace dom
150
} // namespace mozilla
151
152
#endif