Backed out changeset 9157ea42ff41 (bug 914925) for Android/B2G test bustage.
[gecko.git] / dom / ipc / TabParent.h
blobdc2371862b9a82d838046aed0a5fc710699ab7a2
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"
17 #include "nsCOMPtr.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"
24 #include "Units.h"
25 #include "js/TypeDecls.h"
27 struct gfxMatrix;
28 class mozIApplication;
29 class nsFrameLoader;
30 class nsIURI;
31 class CpowHolder;
33 namespace mozilla {
35 namespace layers {
36 struct FrameMetrics;
37 struct TextureFactoryIdentifier;
40 namespace layout {
41 class RenderFrameParent;
44 namespace dom {
46 class ClonedMessageData;
47 class Element;
48 struct StructuredCloneData;
50 class ContentDialogParent : public PContentDialogParent {};
52 class TabParent : public PBrowserParent
53 , public nsITabParent
54 , public nsIAuthPromptProvider
55 , public nsISecureBrowserUI
56 , public TabContext
58 typedef mozilla::dom::ClonedMessageData ClonedMessageData;
59 typedef mozilla::layout::ScrollingBehavior ScrollingBehavior;
61 public:
62 TabParent(ContentParent* aManager, const TabContext& aContext);
63 virtual ~TabParent();
64 Element* GetOwnerElement() const { return mFrameElement; }
65 void SetOwnerElement(Element* aElement);
67 /**
68 * Get the mozapptype attribute from this TabParent's owner DOM element.
70 void GetAppType(nsAString& aOut);
72 /**
73 * Returns true iff this TabParent's nsIFrameLoader is visible.
75 * The frameloader's visibility can be independent of e.g. its docshell's
76 * visibility.
78 bool IsVisible();
80 nsIBrowserDOMWindow *GetBrowserDOMWindow() { return mBrowserDOMWindow; }
81 void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) {
82 mBrowserDOMWindow = aBrowserDOMWindow;
85 /**
86 * Return the TabParent that has decided it wants to capture an
87 * event series for fast-path dispatch to its subprocess, if one
88 * has.
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();
97 /**
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
105 * capturer.
107 bool TryCapture(const nsGUIEvent& aEvent);
109 void Destroy();
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,
116 uint64_t* layersId);
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,
132 uint32_t* aSeqno);
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,
143 int32_t* aIMEOpen,
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)
171 delete aDialog;
172 return true;
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);
186 void Activate();
187 void Deactivate();
189 bool MapEventCoordinatesForChildProcess(nsEvent* aEvent);
190 void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint& aOffset,
191 nsEvent* aEvent);
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);
223 NS_DECL_ISUPPORTS
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; }
240 protected:
241 bool ReceiveMessage(const nsString& aMessage,
242 bool aSync,
243 const StructuredCloneData* aCloneData,
244 CpowHolder* aCpows,
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);
258 virtual bool
259 RecvPIndexedDBConstructor(PIndexedDBParent* aActor,
260 const nsCString& aGroup,
261 const nsCString& aASCIIOrigin,
262 bool* aAllowed);
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),
274 mParams(aParams) {}
276 PContentDialogParent* mDialog;
277 uint32_t mType;
278 nsCString mName;
279 nsCString mFeatures;
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;
292 // IME
293 static TabParent *mIMETabParent;
294 nsString mIMECacheText;
295 uint32_t mIMESelectionAnchor;
296 uint32_t mIMESelectionFocus;
297 bool mIMEComposing;
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;
303 uint32_t mIMESeqno;
305 // The number of event series we're currently capturing.
306 int32_t mEventCaptureDepth;
308 nsRect mRect;
309 nsIntSize mDimensions;
310 ScreenOrientation mOrientation;
311 float mDPI;
312 double mDefaultScale;
313 bool mShown;
314 bool mUpdatedDimensions;
316 private:
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
341 // anymore.
342 bool mIsDestroyed;
343 // Whether we have already sent a FileDescriptor for the app package.
344 bool mAppPackageFileDescriptorSent;
347 } // namespace dom
348 } // namespace mozilla
350 #endif