|
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/. */ |
|
6 |
|
7 #ifndef mozilla_tabs_TabParent_h |
|
8 #define mozilla_tabs_TabParent_h |
|
9 |
|
10 #include "mozilla/EventForwards.h" |
|
11 #include "mozilla/dom/PBrowserParent.h" |
|
12 #include "mozilla/dom/PFilePickerParent.h" |
|
13 #include "mozilla/dom/TabContext.h" |
|
14 #include "nsCOMPtr.h" |
|
15 #include "nsIAuthPromptProvider.h" |
|
16 #include "nsIBrowserDOMWindow.h" |
|
17 #include "nsISecureBrowserUI.h" |
|
18 #include "nsITabParent.h" |
|
19 #include "nsIXULBrowserWindow.h" |
|
20 #include "Units.h" |
|
21 #include "js/TypeDecls.h" |
|
22 |
|
23 class nsFrameLoader; |
|
24 class nsIContent; |
|
25 class nsIPrincipal; |
|
26 class nsIURI; |
|
27 class nsIWidget; |
|
28 class nsILoadContext; |
|
29 class CpowHolder; |
|
30 |
|
31 namespace mozilla { |
|
32 |
|
33 namespace layers { |
|
34 struct FrameMetrics; |
|
35 struct TextureFactoryIdentifier; |
|
36 } |
|
37 |
|
38 namespace layout { |
|
39 class RenderFrameParent; |
|
40 } |
|
41 |
|
42 namespace dom { |
|
43 |
|
44 class ClonedMessageData; |
|
45 class ContentParent; |
|
46 class Element; |
|
47 struct StructuredCloneData; |
|
48 |
|
49 class TabParent : public PBrowserParent |
|
50 , public nsITabParent |
|
51 , public nsIAuthPromptProvider |
|
52 , public nsISecureBrowserUI |
|
53 , public TabContext |
|
54 { |
|
55 typedef mozilla::dom::ClonedMessageData ClonedMessageData; |
|
56 typedef mozilla::layout::ScrollingBehavior ScrollingBehavior; |
|
57 |
|
58 public: |
|
59 // nsITabParent |
|
60 NS_DECL_NSITABPARENT |
|
61 |
|
62 TabParent(ContentParent* aManager, const TabContext& aContext, uint32_t aChromeFlags); |
|
63 virtual ~TabParent(); |
|
64 Element* GetOwnerElement() const { return mFrameElement; } |
|
65 void SetOwnerElement(Element* aElement); |
|
66 |
|
67 /** |
|
68 * Get the mozapptype attribute from this TabParent's owner DOM element. |
|
69 */ |
|
70 void GetAppType(nsAString& aOut); |
|
71 |
|
72 /** |
|
73 * Returns true iff this TabParent's nsIFrameLoader is visible. |
|
74 * |
|
75 * The frameloader's visibility can be independent of e.g. its docshell's |
|
76 * visibility. |
|
77 */ |
|
78 bool IsVisible(); |
|
79 |
|
80 nsIBrowserDOMWindow *GetBrowserDOMWindow() { return mBrowserDOMWindow; } |
|
81 void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) { |
|
82 mBrowserDOMWindow = aBrowserDOMWindow; |
|
83 } |
|
84 |
|
85 already_AddRefed<nsILoadContext> GetLoadContext(); |
|
86 |
|
87 nsIXULBrowserWindow* GetXULBrowserWindow(); |
|
88 |
|
89 /** |
|
90 * Return the TabParent that has decided it wants to capture an |
|
91 * event series for fast-path dispatch to its subprocess, if one |
|
92 * has. |
|
93 * |
|
94 * DOM event dispatch and widget are free to ignore capture |
|
95 * requests from TabParents; the end result wrt remote content is |
|
96 * (must be) always the same, albeit usually slower without |
|
97 * subprocess capturing. This allows frontends/widget backends to |
|
98 * "opt in" to faster cross-process dispatch. |
|
99 */ |
|
100 static TabParent* GetEventCapturer(); |
|
101 /** |
|
102 * If this is the current event capturer, give this a chance to |
|
103 * capture the event. If it was captured, return true, false |
|
104 * otherwise. Un-captured events should follow normal DOM |
|
105 * dispatch; captured events should result in no further |
|
106 * processing from the caller of TryCapture(). |
|
107 * |
|
108 * It's an error to call TryCapture() if this isn't the event |
|
109 * capturer. |
|
110 */ |
|
111 bool TryCapture(const WidgetGUIEvent& aEvent); |
|
112 |
|
113 void Destroy(); |
|
114 |
|
115 virtual bool RecvMoveFocus(const bool& aForward) MOZ_OVERRIDE; |
|
116 virtual bool RecvEvent(const RemoteDOMEvent& aEvent) MOZ_OVERRIDE; |
|
117 virtual bool RecvReplyKeyEvent(const WidgetKeyboardEvent& event); |
|
118 virtual bool RecvPRenderFrameConstructor(PRenderFrameParent* actor) MOZ_OVERRIDE; |
|
119 virtual bool RecvInitRenderFrame(PRenderFrameParent* aFrame, |
|
120 ScrollingBehavior* scrolling, |
|
121 TextureFactoryIdentifier* identifier, |
|
122 uint64_t* layersId, |
|
123 bool *aSuccess) MOZ_OVERRIDE; |
|
124 virtual bool RecvBrowserFrameOpenWindow(PBrowserParent* aOpener, |
|
125 const nsString& aURL, |
|
126 const nsString& aName, |
|
127 const nsString& aFeatures, |
|
128 bool* aOutWindowOpened) MOZ_OVERRIDE; |
|
129 virtual bool AnswerCreateWindow(PBrowserParent** retval) MOZ_OVERRIDE; |
|
130 virtual bool RecvSyncMessage(const nsString& aMessage, |
|
131 const ClonedMessageData& aData, |
|
132 const InfallibleTArray<CpowEntry>& aCpows, |
|
133 const IPC::Principal& aPrincipal, |
|
134 InfallibleTArray<nsString>* aJSONRetVal) MOZ_OVERRIDE; |
|
135 virtual bool AnswerRpcMessage(const nsString& aMessage, |
|
136 const ClonedMessageData& aData, |
|
137 const InfallibleTArray<CpowEntry>& aCpows, |
|
138 const IPC::Principal& aPrincipal, |
|
139 InfallibleTArray<nsString>* aJSONRetVal) MOZ_OVERRIDE; |
|
140 virtual bool RecvAsyncMessage(const nsString& aMessage, |
|
141 const ClonedMessageData& aData, |
|
142 const InfallibleTArray<CpowEntry>& aCpows, |
|
143 const IPC::Principal& aPrincipal) MOZ_OVERRIDE; |
|
144 virtual bool RecvNotifyIMEFocus(const bool& aFocus, |
|
145 nsIMEUpdatePreference* aPreference, |
|
146 uint32_t* aSeqno) MOZ_OVERRIDE; |
|
147 virtual bool RecvNotifyIMETextChange(const uint32_t& aStart, |
|
148 const uint32_t& aEnd, |
|
149 const uint32_t& aNewEnd, |
|
150 const bool& aCausedByComposition) MOZ_OVERRIDE; |
|
151 virtual bool RecvNotifyIMESelectedCompositionRect(const uint32_t& aOffset, |
|
152 const nsIntRect& aRect, |
|
153 const nsIntRect& aCaretRect) MOZ_OVERRIDE; |
|
154 virtual bool RecvNotifyIMESelection(const uint32_t& aSeqno, |
|
155 const uint32_t& aAnchor, |
|
156 const uint32_t& aFocus, |
|
157 const bool& aCausedByComposition) MOZ_OVERRIDE; |
|
158 virtual bool RecvNotifyIMETextHint(const nsString& aText) MOZ_OVERRIDE; |
|
159 virtual bool RecvEndIMEComposition(const bool& aCancel, |
|
160 nsString* aComposition) MOZ_OVERRIDE; |
|
161 virtual bool RecvGetInputContext(int32_t* aIMEEnabled, |
|
162 int32_t* aIMEOpen, |
|
163 intptr_t* aNativeIMEContext) MOZ_OVERRIDE; |
|
164 virtual bool RecvSetInputContext(const int32_t& aIMEEnabled, |
|
165 const int32_t& aIMEOpen, |
|
166 const nsString& aType, |
|
167 const nsString& aInputmode, |
|
168 const nsString& aActionHint, |
|
169 const int32_t& aCause, |
|
170 const int32_t& aFocusChange) MOZ_OVERRIDE; |
|
171 virtual bool RecvRequestFocus(const bool& aCanRaise) MOZ_OVERRIDE; |
|
172 virtual bool RecvSetCursor(const uint32_t& aValue) MOZ_OVERRIDE; |
|
173 virtual bool RecvSetBackgroundColor(const nscolor& aValue) MOZ_OVERRIDE; |
|
174 virtual bool RecvSetStatus(const uint32_t& aType, const nsString& aStatus) MOZ_OVERRIDE; |
|
175 virtual bool RecvIsParentWindowMainWidgetVisible(bool* aIsVisible); |
|
176 virtual bool RecvShowTooltip(const uint32_t& aX, const uint32_t& aY, const nsString& aTooltip); |
|
177 virtual bool RecvHideTooltip(); |
|
178 virtual bool RecvGetDPI(float* aValue) MOZ_OVERRIDE; |
|
179 virtual bool RecvGetDefaultScale(double* aValue) MOZ_OVERRIDE; |
|
180 virtual bool RecvGetWidgetNativeData(WindowsHandle* aValue) MOZ_OVERRIDE; |
|
181 virtual bool RecvZoomToRect(const uint32_t& aPresShellId, |
|
182 const ViewID& aViewId, |
|
183 const CSSRect& aRect) MOZ_OVERRIDE; |
|
184 virtual bool RecvUpdateZoomConstraints(const uint32_t& aPresShellId, |
|
185 const ViewID& aViewId, |
|
186 const bool& aIsRoot, |
|
187 const ZoomConstraints& aConstraints) MOZ_OVERRIDE; |
|
188 virtual bool RecvContentReceivedTouch(const ScrollableLayerGuid& aGuid, |
|
189 const bool& aPreventDefault) MOZ_OVERRIDE; |
|
190 |
|
191 virtual PColorPickerParent* |
|
192 AllocPColorPickerParent(const nsString& aTitle, const nsString& aInitialColor) MOZ_OVERRIDE; |
|
193 virtual bool DeallocPColorPickerParent(PColorPickerParent* aColorPicker) MOZ_OVERRIDE; |
|
194 |
|
195 void LoadURL(nsIURI* aURI); |
|
196 // XXX/cjones: it's not clear what we gain by hiding these |
|
197 // message-sending functions under a layer of indirection and |
|
198 // eating the return values |
|
199 void Show(const nsIntSize& size); |
|
200 void UpdateDimensions(const nsRect& rect, const nsIntSize& size); |
|
201 void UpdateFrame(const layers::FrameMetrics& aFrameMetrics); |
|
202 void AcknowledgeScrollUpdate(const ViewID& aScrollId, const uint32_t& aScrollGeneration); |
|
203 void HandleDoubleTap(const CSSPoint& aPoint, |
|
204 int32_t aModifiers, |
|
205 const ScrollableLayerGuid& aGuid); |
|
206 void HandleSingleTap(const CSSPoint& aPoint, |
|
207 int32_t aModifiers, |
|
208 const ScrollableLayerGuid& aGuid); |
|
209 void HandleLongTap(const CSSPoint& aPoint, |
|
210 int32_t aModifiers, |
|
211 const ScrollableLayerGuid& aGuid); |
|
212 void HandleLongTapUp(const CSSPoint& aPoint, |
|
213 int32_t aModifiers, |
|
214 const ScrollableLayerGuid& aGuid); |
|
215 void NotifyAPZStateChange(ViewID aViewId, |
|
216 APZStateChange aChange, |
|
217 int aArg); |
|
218 void Activate(); |
|
219 void Deactivate(); |
|
220 |
|
221 bool MapEventCoordinatesForChildProcess(mozilla::WidgetEvent* aEvent); |
|
222 void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint& aOffset, |
|
223 mozilla::WidgetEvent* aEvent); |
|
224 |
|
225 virtual bool RecvRequestNativeKeyBindings(const mozilla::WidgetKeyboardEvent& aEvent, |
|
226 MaybeNativeKeyBinding* aBindings) MOZ_OVERRIDE; |
|
227 |
|
228 void SendMouseEvent(const nsAString& aType, float aX, float aY, |
|
229 int32_t aButton, int32_t aClickCount, |
|
230 int32_t aModifiers, bool aIgnoreRootScrollFrame); |
|
231 void SendKeyEvent(const nsAString& aType, int32_t aKeyCode, |
|
232 int32_t aCharCode, int32_t aModifiers, |
|
233 bool aPreventDefault); |
|
234 bool SendRealMouseEvent(mozilla::WidgetMouseEvent& event); |
|
235 bool SendMouseWheelEvent(mozilla::WidgetWheelEvent& event); |
|
236 bool SendRealKeyEvent(mozilla::WidgetKeyboardEvent& event); |
|
237 bool SendRealTouchEvent(WidgetTouchEvent& event); |
|
238 bool SendHandleSingleTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); |
|
239 bool SendHandleLongTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); |
|
240 bool SendHandleLongTapUp(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); |
|
241 bool SendHandleDoubleTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); |
|
242 |
|
243 virtual PDocumentRendererParent* |
|
244 AllocPDocumentRendererParent(const nsRect& documentRect, |
|
245 const gfx::Matrix& transform, |
|
246 const nsString& bgcolor, |
|
247 const uint32_t& renderFlags, |
|
248 const bool& flushLayout, |
|
249 const nsIntSize& renderSize) MOZ_OVERRIDE; |
|
250 virtual bool DeallocPDocumentRendererParent(PDocumentRendererParent* actor) MOZ_OVERRIDE; |
|
251 |
|
252 virtual PContentPermissionRequestParent* |
|
253 AllocPContentPermissionRequestParent(const InfallibleTArray<PermissionRequest>& aRequests, |
|
254 const IPC::Principal& aPrincipal) MOZ_OVERRIDE; |
|
255 virtual bool |
|
256 DeallocPContentPermissionRequestParent(PContentPermissionRequestParent* actor) MOZ_OVERRIDE; |
|
257 |
|
258 virtual PFilePickerParent* |
|
259 AllocPFilePickerParent(const nsString& aTitle, |
|
260 const int16_t& aMode) MOZ_OVERRIDE; |
|
261 virtual bool DeallocPFilePickerParent(PFilePickerParent* actor) MOZ_OVERRIDE; |
|
262 |
|
263 virtual POfflineCacheUpdateParent* |
|
264 AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI, |
|
265 const URIParams& aDocumentURI, |
|
266 const bool& aStickDocument) MOZ_OVERRIDE; |
|
267 virtual bool |
|
268 RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor, |
|
269 const URIParams& aManifestURI, |
|
270 const URIParams& aDocumentURI, |
|
271 const bool& stickDocument) MOZ_OVERRIDE; |
|
272 virtual bool |
|
273 DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor) MOZ_OVERRIDE; |
|
274 |
|
275 virtual bool RecvSetOfflinePermission(const IPC::Principal& principal) MOZ_OVERRIDE; |
|
276 |
|
277 bool GetGlobalJSObject(JSContext* cx, JSObject** globalp); |
|
278 |
|
279 NS_DECL_ISUPPORTS |
|
280 NS_DECL_NSIAUTHPROMPTPROVIDER |
|
281 NS_DECL_NSISECUREBROWSERUI |
|
282 |
|
283 static TabParent *GetIMETabParent() { return mIMETabParent; } |
|
284 bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent); |
|
285 bool SendCompositionEvent(mozilla::WidgetCompositionEvent& event); |
|
286 bool SendTextEvent(mozilla::WidgetTextEvent& event); |
|
287 bool SendSelectionEvent(mozilla::WidgetSelectionEvent& event); |
|
288 |
|
289 static TabParent* GetFrom(nsFrameLoader* aFrameLoader); |
|
290 static TabParent* GetFrom(nsIContent* aContent); |
|
291 |
|
292 ContentParent* Manager() { return mManager; } |
|
293 |
|
294 /** |
|
295 * Let managees query if Destroy() is already called so they don't send out |
|
296 * messages when the PBrowser actor is being destroyed. |
|
297 */ |
|
298 bool IsDestroyed() const { return mIsDestroyed; } |
|
299 |
|
300 protected: |
|
301 bool ReceiveMessage(const nsString& aMessage, |
|
302 bool aSync, |
|
303 const StructuredCloneData* aCloneData, |
|
304 CpowHolder* aCpows, |
|
305 nsIPrincipal* aPrincipal, |
|
306 InfallibleTArray<nsString>* aJSONRetVal = nullptr); |
|
307 |
|
308 virtual bool Recv__delete__() MOZ_OVERRIDE; |
|
309 |
|
310 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; |
|
311 |
|
312 virtual PIndexedDBParent* AllocPIndexedDBParent( |
|
313 const nsCString& aGroup, |
|
314 const nsCString& aASCIIOrigin, |
|
315 bool* /* aAllowed */) MOZ_OVERRIDE; |
|
316 |
|
317 virtual bool DeallocPIndexedDBParent(PIndexedDBParent* aActor) MOZ_OVERRIDE; |
|
318 |
|
319 virtual bool |
|
320 RecvPIndexedDBConstructor(PIndexedDBParent* aActor, |
|
321 const nsCString& aGroup, |
|
322 const nsCString& aASCIIOrigin, |
|
323 bool* aAllowed) MOZ_OVERRIDE; |
|
324 |
|
325 Element* mFrameElement; |
|
326 nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow; |
|
327 |
|
328 bool AllowContentIME(); |
|
329 nsIntPoint GetChildProcessOffset(); |
|
330 |
|
331 virtual PRenderFrameParent* AllocPRenderFrameParent() MOZ_OVERRIDE; |
|
332 virtual bool DeallocPRenderFrameParent(PRenderFrameParent* aFrame) MOZ_OVERRIDE; |
|
333 |
|
334 // IME |
|
335 static TabParent *mIMETabParent; |
|
336 nsString mIMECacheText; |
|
337 uint32_t mIMESelectionAnchor; |
|
338 uint32_t mIMESelectionFocus; |
|
339 bool mIMEComposing; |
|
340 bool mIMECompositionEnding; |
|
341 // Buffer to store composition text during ResetInputState |
|
342 // Compositions in almost all cases are small enough for nsAutoString |
|
343 nsAutoString mIMECompositionText; |
|
344 uint32_t mIMECompositionStart; |
|
345 uint32_t mIMESeqno; |
|
346 |
|
347 uint32_t mIMECompositionRectOffset; |
|
348 nsIntRect mIMECompositionRect; |
|
349 nsIntRect mIMECaretRect; |
|
350 |
|
351 // The number of event series we're currently capturing. |
|
352 int32_t mEventCaptureDepth; |
|
353 |
|
354 nsRect mRect; |
|
355 nsIntSize mDimensions; |
|
356 ScreenOrientation mOrientation; |
|
357 float mDPI; |
|
358 CSSToLayoutDeviceScale mDefaultScale; |
|
359 bool mShown; |
|
360 bool mUpdatedDimensions; |
|
361 |
|
362 private: |
|
363 already_AddRefed<nsFrameLoader> GetFrameLoader() const; |
|
364 already_AddRefed<nsIWidget> GetWidget() const; |
|
365 layout::RenderFrameParent* GetRenderFrame(); |
|
366 nsRefPtr<ContentParent> mManager; |
|
367 void TryCacheDPIAndScale(); |
|
368 |
|
369 CSSPoint AdjustTapToChildWidget(const CSSPoint& aPoint); |
|
370 |
|
371 // When true, we create a pan/zoom controller for our frame and |
|
372 // notify it of input events targeting us. |
|
373 bool UseAsyncPanZoom(); |
|
374 // If we have a render frame currently, notify it that we're about |
|
375 // to dispatch |aEvent| to our child. If there's a relevant |
|
376 // transform in place, |aEvent| will be transformed in-place so that |
|
377 // it is ready to be dispatched to content. |
|
378 // |aOutTargetGuid| will contain the identifier |
|
379 // of the APZC instance that handled the event. aOutTargetGuid may be |
|
380 // null. |
|
381 void MaybeForwardEventToRenderFrame(WidgetInputEvent& aEvent, |
|
382 ScrollableLayerGuid* aOutTargetGuid); |
|
383 // The offset for the child process which is sampled at touch start. This |
|
384 // means that the touch events are relative to where the frame was at the |
|
385 // start of the touch. We need to look for a better solution to this |
|
386 // problem see bug 872911. |
|
387 LayoutDeviceIntPoint mChildProcessOffsetAtTouchStart; |
|
388 // When true, we've initiated normal shutdown and notified our |
|
389 // managing PContent. |
|
390 bool mMarkedDestroying; |
|
391 // When true, the TabParent is invalid and we should not send IPC messages |
|
392 // anymore. |
|
393 bool mIsDestroyed; |
|
394 // Whether we have already sent a FileDescriptor for the app package. |
|
395 bool mAppPackageFileDescriptorSent; |
|
396 |
|
397 uint32_t mChromeFlags; |
|
398 |
|
399 nsCOMPtr<nsILoadContext> mLoadContext; |
|
400 }; |
|
401 |
|
402 } // namespace dom |
|
403 } // namespace mozilla |
|
404 |
|
405 #endif |