1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set sw=4 ts=8 et 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/. */
7 #ifndef mozilla_tabs_TabParent_h
8 #define mozilla_tabs_TabParent_h
10 #include "base/basictypes.h"
12 #include "mozilla/dom/ContentParent.h"
13 #include "mozilla/dom/PBrowserParent.h"
14 #include "mozilla/dom/PContentDialogParent.h"
15 #include "mozilla/dom/TabContext.h"
16 #include "mozilla/ipc/GeckoChildProcessHost.h"
18 #include "nsIAuthPromptProvider.h"
19 #include "nsIBrowserDOMWindow.h"
20 #include "nsIDialogParamBlock.h"
21 #include "nsISecureBrowserUI.h"
22 #include "nsITabParent.h"
23 #include "nsWeakReference.h"
25 #include "js/TypeDecls.h"
28 class mozIApplication
;
37 struct TextureFactoryIdentifier
;
41 class RenderFrameParent
;
46 class ClonedMessageData
;
48 struct StructuredCloneData
;
50 class ContentDialogParent
: public PContentDialogParent
{};
52 class TabParent
: public PBrowserParent
54 , public nsIAuthPromptProvider
55 , public nsISecureBrowserUI
58 typedef mozilla::dom::ClonedMessageData ClonedMessageData
;
59 typedef mozilla::layout::ScrollingBehavior ScrollingBehavior
;
62 TabParent(ContentParent
* aManager
, const TabContext
& aContext
);
64 Element
* GetOwnerElement() const { return mFrameElement
; }
65 void SetOwnerElement(Element
* aElement
);
68 * Get the mozapptype attribute from this TabParent's owner DOM element.
70 void GetAppType(nsAString
& aOut
);
73 * Returns true iff this TabParent's nsIFrameLoader is visible.
75 * The frameloader's visibility can be independent of e.g. its docshell's
80 nsIBrowserDOMWindow
*GetBrowserDOMWindow() { return mBrowserDOMWindow
; }
81 void SetBrowserDOMWindow(nsIBrowserDOMWindow
* aBrowserDOMWindow
) {
82 mBrowserDOMWindow
= aBrowserDOMWindow
;
86 * Return the TabParent that has decided it wants to capture an
87 * event series for fast-path dispatch to its subprocess, if one
90 * DOM event dispatch and widget are free to ignore capture
91 * requests from TabParents; the end result wrt remote content is
92 * (must be) always the same, albeit usually slower without
93 * subprocess capturing. This allows frontends/widget backends to
94 * "opt in" to faster cross-process dispatch.
96 static TabParent
* GetEventCapturer();
98 * If this is the current event capturer, give this a chance to
99 * capture the event. If it was captured, return true, false
100 * otherwise. Un-captured events should follow normal DOM
101 * dispatch; captured events should result in no further
102 * processing from the caller of TryCapture().
104 * It's an error to call TryCapture() if this isn't the event
107 bool TryCapture(const nsGUIEvent
& aEvent
);
111 virtual bool RecvMoveFocus(const bool& aForward
);
112 virtual bool RecvEvent(const RemoteDOMEvent
& aEvent
);
113 virtual bool RecvPRenderFrameConstructor(PRenderFrameParent
* actor
,
114 ScrollingBehavior
* scrolling
,
115 TextureFactoryIdentifier
* identifier
,
117 virtual bool RecvBrowserFrameOpenWindow(PBrowserParent
* aOpener
,
118 const nsString
& aURL
,
119 const nsString
& aName
,
120 const nsString
& aFeatures
,
121 bool* aOutWindowOpened
);
122 virtual bool AnswerCreateWindow(PBrowserParent
** retval
);
123 virtual bool RecvSyncMessage(const nsString
& aMessage
,
124 const ClonedMessageData
& aData
,
125 const InfallibleTArray
<CpowEntry
>& aCpows
,
126 InfallibleTArray
<nsString
>* aJSONRetVal
);
127 virtual bool RecvAsyncMessage(const nsString
& aMessage
,
128 const ClonedMessageData
& aData
,
129 const InfallibleTArray
<CpowEntry
>& aCpows
);
130 virtual bool RecvNotifyIMEFocus(const bool& aFocus
,
131 nsIMEUpdatePreference
* aPreference
,
133 virtual bool RecvNotifyIMETextChange(const uint32_t& aStart
,
134 const uint32_t& aEnd
,
135 const uint32_t& aNewEnd
);
136 virtual bool RecvNotifyIMESelection(const uint32_t& aSeqno
,
137 const uint32_t& aAnchor
,
138 const uint32_t& aFocus
);
139 virtual bool RecvNotifyIMETextHint(const nsString
& aText
);
140 virtual bool RecvEndIMEComposition(const bool& aCancel
,
141 nsString
* aComposition
);
142 virtual bool RecvGetInputContext(int32_t* aIMEEnabled
,
144 intptr_t* aNativeIMEContext
);
145 virtual bool RecvSetInputContext(const int32_t& aIMEEnabled
,
146 const int32_t& aIMEOpen
,
147 const nsString
& aType
,
148 const nsString
& aInputmode
,
149 const nsString
& aActionHint
,
150 const int32_t& aCause
,
151 const int32_t& aFocusChange
);
152 virtual bool RecvSetCursor(const uint32_t& aValue
);
153 virtual bool RecvSetBackgroundColor(const nscolor
& aValue
);
154 virtual bool RecvSetStatus(const uint32_t& aType
, const nsString
& aStatus
);
155 virtual bool RecvGetDPI(float* aValue
);
156 virtual bool RecvGetDefaultScale(double* aValue
);
157 virtual bool RecvGetWidgetNativeData(WindowsHandle
* aValue
);
158 virtual bool RecvZoomToRect(const CSSRect
& aRect
);
159 virtual bool RecvUpdateZoomConstraints(const bool& aAllowZoom
,
160 const CSSToScreenScale
& aMinZoom
,
161 const CSSToScreenScale
& aMaxZoom
);
162 virtual bool RecvUpdateScrollOffset(const uint32_t& aPresShellId
, const ViewID
& aViewId
, const CSSIntPoint
& aScrollOffset
);
163 virtual bool RecvContentReceivedTouch(const bool& aPreventDefault
);
164 virtual PContentDialogParent
* AllocPContentDialogParent(const uint32_t& aType
,
165 const nsCString
& aName
,
166 const nsCString
& aFeatures
,
167 const InfallibleTArray
<int>& aIntParams
,
168 const InfallibleTArray
<nsString
>& aStringParams
);
169 virtual bool DeallocPContentDialogParent(PContentDialogParent
* aDialog
)
176 void LoadURL(nsIURI
* aURI
);
177 // XXX/cjones: it's not clear what we gain by hiding these
178 // message-sending functions under a layer of indirection and
179 // eating the return values
180 void Show(const nsIntSize
& size
);
181 void UpdateDimensions(const nsRect
& rect
, const nsIntSize
& size
);
182 void UpdateFrame(const layers::FrameMetrics
& aFrameMetrics
);
183 void HandleDoubleTap(const CSSIntPoint
& aPoint
);
184 void HandleSingleTap(const CSSIntPoint
& aPoint
);
185 void HandleLongTap(const CSSIntPoint
& aPoint
);
189 bool MapEventCoordinatesForChildProcess(nsEvent
* aEvent
);
190 void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint
& aOffset
,
193 void SendMouseEvent(const nsAString
& aType
, float aX
, float aY
,
194 int32_t aButton
, int32_t aClickCount
,
195 int32_t aModifiers
, bool aIgnoreRootScrollFrame
);
196 void SendKeyEvent(const nsAString
& aType
, int32_t aKeyCode
,
197 int32_t aCharCode
, int32_t aModifiers
,
198 bool aPreventDefault
);
199 bool SendRealMouseEvent(nsMouseEvent
& event
);
200 bool SendMouseWheelEvent(mozilla::widget::WheelEvent
& event
);
201 bool SendRealKeyEvent(nsKeyEvent
& event
);
202 bool SendRealTouchEvent(nsTouchEvent
& event
);
204 virtual PDocumentRendererParent
*
205 AllocPDocumentRendererParent(const nsRect
& documentRect
, const gfxMatrix
& transform
,
206 const nsString
& bgcolor
,
207 const uint32_t& renderFlags
, const bool& flushLayout
,
208 const nsIntSize
& renderSize
);
209 virtual bool DeallocPDocumentRendererParent(PDocumentRendererParent
* actor
);
211 virtual PContentPermissionRequestParent
*
212 AllocPContentPermissionRequestParent(const nsCString
& aType
, const nsCString
& aAccess
, const IPC::Principal
& aPrincipal
);
213 virtual bool DeallocPContentPermissionRequestParent(PContentPermissionRequestParent
* actor
);
215 virtual POfflineCacheUpdateParent
* AllocPOfflineCacheUpdateParent(
216 const URIParams
& aManifestURI
,
217 const URIParams
& aDocumentURI
,
218 const bool& stickDocument
) MOZ_OVERRIDE
;
219 virtual bool DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent
* actor
);
221 bool GetGlobalJSObject(JSContext
* cx
, JSObject
** globalp
);
224 NS_DECL_NSIAUTHPROMPTPROVIDER
225 NS_DECL_NSISECUREBROWSERUI
227 void HandleDelayedDialogs();
229 static TabParent
*GetIMETabParent() { return mIMETabParent
; }
230 bool HandleQueryContentEvent(nsQueryContentEvent
& aEvent
);
231 bool SendCompositionEvent(nsCompositionEvent
& event
);
232 bool SendTextEvent(nsTextEvent
& event
);
233 bool SendSelectionEvent(nsSelectionEvent
& event
);
235 static TabParent
* GetFrom(nsFrameLoader
* aFrameLoader
);
236 static TabParent
* GetFrom(nsIContent
* aContent
);
238 ContentParent
* Manager() { return mManager
; }
241 bool ReceiveMessage(const nsString
& aMessage
,
243 const StructuredCloneData
* aCloneData
,
245 InfallibleTArray
<nsString
>* aJSONRetVal
= nullptr);
247 virtual bool Recv__delete__() MOZ_OVERRIDE
;
249 virtual void ActorDestroy(ActorDestroyReason why
) MOZ_OVERRIDE
;
251 virtual PIndexedDBParent
* AllocPIndexedDBParent(
252 const nsCString
& aGroup
,
253 const nsCString
& aASCIIOrigin
,
254 bool* /* aAllowed */);
256 virtual bool DeallocPIndexedDBParent(PIndexedDBParent
* aActor
);
259 RecvPIndexedDBConstructor(PIndexedDBParent
* aActor
,
260 const nsCString
& aGroup
,
261 const nsCString
& aASCIIOrigin
,
264 Element
* mFrameElement
;
265 nsCOMPtr
<nsIBrowserDOMWindow
> mBrowserDOMWindow
;
267 struct DelayedDialogData
269 DelayedDialogData(PContentDialogParent
* aDialog
, uint32_t aType
,
270 const nsCString
& aName
,
271 const nsCString
& aFeatures
,
272 nsIDialogParamBlock
* aParams
)
273 : mDialog(aDialog
), mType(aType
), mName(aName
), mFeatures(aFeatures
),
276 PContentDialogParent
* mDialog
;
280 nsCOMPtr
<nsIDialogParamBlock
> mParams
;
282 InfallibleTArray
<DelayedDialogData
*> mDelayedDialogs
;
284 bool ShouldDelayDialogs();
285 bool AllowContentIME();
287 virtual PRenderFrameParent
* AllocPRenderFrameParent(ScrollingBehavior
* aScrolling
,
288 TextureFactoryIdentifier
* aTextureFactoryIdentifier
,
289 uint64_t* aLayersId
) MOZ_OVERRIDE
;
290 virtual bool DeallocPRenderFrameParent(PRenderFrameParent
* aFrame
) MOZ_OVERRIDE
;
293 static TabParent
*mIMETabParent
;
294 nsString mIMECacheText
;
295 uint32_t mIMESelectionAnchor
;
296 uint32_t mIMESelectionFocus
;
298 bool mIMECompositionEnding
;
299 // Buffer to store composition text during ResetInputState
300 // Compositions in almost all cases are small enough for nsAutoString
301 nsAutoString mIMECompositionText
;
302 uint32_t mIMECompositionStart
;
305 // The number of event series we're currently capturing.
306 int32_t mEventCaptureDepth
;
309 nsIntSize mDimensions
;
310 ScreenOrientation mOrientation
;
312 double mDefaultScale
;
314 bool mUpdatedDimensions
;
317 already_AddRefed
<nsFrameLoader
> GetFrameLoader() const;
318 already_AddRefed
<nsIWidget
> GetWidget() const;
319 layout::RenderFrameParent
* GetRenderFrame();
320 nsRefPtr
<ContentParent
> mManager
;
321 void TryCacheDPIAndScale();
323 // When true, we create a pan/zoom controller for our frame and
324 // notify it of input events targeting us.
325 bool UseAsyncPanZoom();
326 // If we have a render frame currently, notify it that we're about
327 // to dispatch |aEvent| to our child. If there's a relevant
328 // transform in place, |aOutEvent| is the transformed |aEvent| to
329 // dispatch to content.
330 void MaybeForwardEventToRenderFrame(const nsInputEvent
& aEvent
,
331 nsInputEvent
* aOutEvent
);
332 // The offset for the child process which is sampled at touch start. This
333 // means that the touch events are relative to where the frame was at the
334 // start of the touch. We need to look for a better solution to this
335 // problem see bug 872911.
336 LayoutDeviceIntPoint mChildProcessOffsetAtTouchStart
;
337 // When true, we've initiated normal shutdown and notified our
338 // managing PContent.
339 bool mMarkedDestroying
;
340 // When true, the TabParent is invalid and we should not send IPC messages
343 // Whether we have already sent a FileDescriptor for the app package.
344 bool mAppPackageFileDescriptorSent
;
348 } // namespace mozilla