1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/ipc/TabParent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,405 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set sw=4 ts=8 et tw=80 : */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_tabs_TabParent_h 1.11 +#define mozilla_tabs_TabParent_h 1.12 + 1.13 +#include "mozilla/EventForwards.h" 1.14 +#include "mozilla/dom/PBrowserParent.h" 1.15 +#include "mozilla/dom/PFilePickerParent.h" 1.16 +#include "mozilla/dom/TabContext.h" 1.17 +#include "nsCOMPtr.h" 1.18 +#include "nsIAuthPromptProvider.h" 1.19 +#include "nsIBrowserDOMWindow.h" 1.20 +#include "nsISecureBrowserUI.h" 1.21 +#include "nsITabParent.h" 1.22 +#include "nsIXULBrowserWindow.h" 1.23 +#include "Units.h" 1.24 +#include "js/TypeDecls.h" 1.25 + 1.26 +class nsFrameLoader; 1.27 +class nsIContent; 1.28 +class nsIPrincipal; 1.29 +class nsIURI; 1.30 +class nsIWidget; 1.31 +class nsILoadContext; 1.32 +class CpowHolder; 1.33 + 1.34 +namespace mozilla { 1.35 + 1.36 +namespace layers { 1.37 +struct FrameMetrics; 1.38 +struct TextureFactoryIdentifier; 1.39 +} 1.40 + 1.41 +namespace layout { 1.42 +class RenderFrameParent; 1.43 +} 1.44 + 1.45 +namespace dom { 1.46 + 1.47 +class ClonedMessageData; 1.48 +class ContentParent; 1.49 +class Element; 1.50 +struct StructuredCloneData; 1.51 + 1.52 +class TabParent : public PBrowserParent 1.53 + , public nsITabParent 1.54 + , public nsIAuthPromptProvider 1.55 + , public nsISecureBrowserUI 1.56 + , public TabContext 1.57 +{ 1.58 + typedef mozilla::dom::ClonedMessageData ClonedMessageData; 1.59 + typedef mozilla::layout::ScrollingBehavior ScrollingBehavior; 1.60 + 1.61 +public: 1.62 + // nsITabParent 1.63 + NS_DECL_NSITABPARENT 1.64 + 1.65 + TabParent(ContentParent* aManager, const TabContext& aContext, uint32_t aChromeFlags); 1.66 + virtual ~TabParent(); 1.67 + Element* GetOwnerElement() const { return mFrameElement; } 1.68 + void SetOwnerElement(Element* aElement); 1.69 + 1.70 + /** 1.71 + * Get the mozapptype attribute from this TabParent's owner DOM element. 1.72 + */ 1.73 + void GetAppType(nsAString& aOut); 1.74 + 1.75 + /** 1.76 + * Returns true iff this TabParent's nsIFrameLoader is visible. 1.77 + * 1.78 + * The frameloader's visibility can be independent of e.g. its docshell's 1.79 + * visibility. 1.80 + */ 1.81 + bool IsVisible(); 1.82 + 1.83 + nsIBrowserDOMWindow *GetBrowserDOMWindow() { return mBrowserDOMWindow; } 1.84 + void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) { 1.85 + mBrowserDOMWindow = aBrowserDOMWindow; 1.86 + } 1.87 + 1.88 + already_AddRefed<nsILoadContext> GetLoadContext(); 1.89 + 1.90 + nsIXULBrowserWindow* GetXULBrowserWindow(); 1.91 + 1.92 + /** 1.93 + * Return the TabParent that has decided it wants to capture an 1.94 + * event series for fast-path dispatch to its subprocess, if one 1.95 + * has. 1.96 + * 1.97 + * DOM event dispatch and widget are free to ignore capture 1.98 + * requests from TabParents; the end result wrt remote content is 1.99 + * (must be) always the same, albeit usually slower without 1.100 + * subprocess capturing. This allows frontends/widget backends to 1.101 + * "opt in" to faster cross-process dispatch. 1.102 + */ 1.103 + static TabParent* GetEventCapturer(); 1.104 + /** 1.105 + * If this is the current event capturer, give this a chance to 1.106 + * capture the event. If it was captured, return true, false 1.107 + * otherwise. Un-captured events should follow normal DOM 1.108 + * dispatch; captured events should result in no further 1.109 + * processing from the caller of TryCapture(). 1.110 + * 1.111 + * It's an error to call TryCapture() if this isn't the event 1.112 + * capturer. 1.113 + */ 1.114 + bool TryCapture(const WidgetGUIEvent& aEvent); 1.115 + 1.116 + void Destroy(); 1.117 + 1.118 + virtual bool RecvMoveFocus(const bool& aForward) MOZ_OVERRIDE; 1.119 + virtual bool RecvEvent(const RemoteDOMEvent& aEvent) MOZ_OVERRIDE; 1.120 + virtual bool RecvReplyKeyEvent(const WidgetKeyboardEvent& event); 1.121 + virtual bool RecvPRenderFrameConstructor(PRenderFrameParent* actor) MOZ_OVERRIDE; 1.122 + virtual bool RecvInitRenderFrame(PRenderFrameParent* aFrame, 1.123 + ScrollingBehavior* scrolling, 1.124 + TextureFactoryIdentifier* identifier, 1.125 + uint64_t* layersId, 1.126 + bool *aSuccess) MOZ_OVERRIDE; 1.127 + virtual bool RecvBrowserFrameOpenWindow(PBrowserParent* aOpener, 1.128 + const nsString& aURL, 1.129 + const nsString& aName, 1.130 + const nsString& aFeatures, 1.131 + bool* aOutWindowOpened) MOZ_OVERRIDE; 1.132 + virtual bool AnswerCreateWindow(PBrowserParent** retval) MOZ_OVERRIDE; 1.133 + virtual bool RecvSyncMessage(const nsString& aMessage, 1.134 + const ClonedMessageData& aData, 1.135 + const InfallibleTArray<CpowEntry>& aCpows, 1.136 + const IPC::Principal& aPrincipal, 1.137 + InfallibleTArray<nsString>* aJSONRetVal) MOZ_OVERRIDE; 1.138 + virtual bool AnswerRpcMessage(const nsString& aMessage, 1.139 + const ClonedMessageData& aData, 1.140 + const InfallibleTArray<CpowEntry>& aCpows, 1.141 + const IPC::Principal& aPrincipal, 1.142 + InfallibleTArray<nsString>* aJSONRetVal) MOZ_OVERRIDE; 1.143 + virtual bool RecvAsyncMessage(const nsString& aMessage, 1.144 + const ClonedMessageData& aData, 1.145 + const InfallibleTArray<CpowEntry>& aCpows, 1.146 + const IPC::Principal& aPrincipal) MOZ_OVERRIDE; 1.147 + virtual bool RecvNotifyIMEFocus(const bool& aFocus, 1.148 + nsIMEUpdatePreference* aPreference, 1.149 + uint32_t* aSeqno) MOZ_OVERRIDE; 1.150 + virtual bool RecvNotifyIMETextChange(const uint32_t& aStart, 1.151 + const uint32_t& aEnd, 1.152 + const uint32_t& aNewEnd, 1.153 + const bool& aCausedByComposition) MOZ_OVERRIDE; 1.154 + virtual bool RecvNotifyIMESelectedCompositionRect(const uint32_t& aOffset, 1.155 + const nsIntRect& aRect, 1.156 + const nsIntRect& aCaretRect) MOZ_OVERRIDE; 1.157 + virtual bool RecvNotifyIMESelection(const uint32_t& aSeqno, 1.158 + const uint32_t& aAnchor, 1.159 + const uint32_t& aFocus, 1.160 + const bool& aCausedByComposition) MOZ_OVERRIDE; 1.161 + virtual bool RecvNotifyIMETextHint(const nsString& aText) MOZ_OVERRIDE; 1.162 + virtual bool RecvEndIMEComposition(const bool& aCancel, 1.163 + nsString* aComposition) MOZ_OVERRIDE; 1.164 + virtual bool RecvGetInputContext(int32_t* aIMEEnabled, 1.165 + int32_t* aIMEOpen, 1.166 + intptr_t* aNativeIMEContext) MOZ_OVERRIDE; 1.167 + virtual bool RecvSetInputContext(const int32_t& aIMEEnabled, 1.168 + const int32_t& aIMEOpen, 1.169 + const nsString& aType, 1.170 + const nsString& aInputmode, 1.171 + const nsString& aActionHint, 1.172 + const int32_t& aCause, 1.173 + const int32_t& aFocusChange) MOZ_OVERRIDE; 1.174 + virtual bool RecvRequestFocus(const bool& aCanRaise) MOZ_OVERRIDE; 1.175 + virtual bool RecvSetCursor(const uint32_t& aValue) MOZ_OVERRIDE; 1.176 + virtual bool RecvSetBackgroundColor(const nscolor& aValue) MOZ_OVERRIDE; 1.177 + virtual bool RecvSetStatus(const uint32_t& aType, const nsString& aStatus) MOZ_OVERRIDE; 1.178 + virtual bool RecvIsParentWindowMainWidgetVisible(bool* aIsVisible); 1.179 + virtual bool RecvShowTooltip(const uint32_t& aX, const uint32_t& aY, const nsString& aTooltip); 1.180 + virtual bool RecvHideTooltip(); 1.181 + virtual bool RecvGetDPI(float* aValue) MOZ_OVERRIDE; 1.182 + virtual bool RecvGetDefaultScale(double* aValue) MOZ_OVERRIDE; 1.183 + virtual bool RecvGetWidgetNativeData(WindowsHandle* aValue) MOZ_OVERRIDE; 1.184 + virtual bool RecvZoomToRect(const uint32_t& aPresShellId, 1.185 + const ViewID& aViewId, 1.186 + const CSSRect& aRect) MOZ_OVERRIDE; 1.187 + virtual bool RecvUpdateZoomConstraints(const uint32_t& aPresShellId, 1.188 + const ViewID& aViewId, 1.189 + const bool& aIsRoot, 1.190 + const ZoomConstraints& aConstraints) MOZ_OVERRIDE; 1.191 + virtual bool RecvContentReceivedTouch(const ScrollableLayerGuid& aGuid, 1.192 + const bool& aPreventDefault) MOZ_OVERRIDE; 1.193 + 1.194 + virtual PColorPickerParent* 1.195 + AllocPColorPickerParent(const nsString& aTitle, const nsString& aInitialColor) MOZ_OVERRIDE; 1.196 + virtual bool DeallocPColorPickerParent(PColorPickerParent* aColorPicker) MOZ_OVERRIDE; 1.197 + 1.198 + void LoadURL(nsIURI* aURI); 1.199 + // XXX/cjones: it's not clear what we gain by hiding these 1.200 + // message-sending functions under a layer of indirection and 1.201 + // eating the return values 1.202 + void Show(const nsIntSize& size); 1.203 + void UpdateDimensions(const nsRect& rect, const nsIntSize& size); 1.204 + void UpdateFrame(const layers::FrameMetrics& aFrameMetrics); 1.205 + void AcknowledgeScrollUpdate(const ViewID& aScrollId, const uint32_t& aScrollGeneration); 1.206 + void HandleDoubleTap(const CSSPoint& aPoint, 1.207 + int32_t aModifiers, 1.208 + const ScrollableLayerGuid& aGuid); 1.209 + void HandleSingleTap(const CSSPoint& aPoint, 1.210 + int32_t aModifiers, 1.211 + const ScrollableLayerGuid& aGuid); 1.212 + void HandleLongTap(const CSSPoint& aPoint, 1.213 + int32_t aModifiers, 1.214 + const ScrollableLayerGuid& aGuid); 1.215 + void HandleLongTapUp(const CSSPoint& aPoint, 1.216 + int32_t aModifiers, 1.217 + const ScrollableLayerGuid& aGuid); 1.218 + void NotifyAPZStateChange(ViewID aViewId, 1.219 + APZStateChange aChange, 1.220 + int aArg); 1.221 + void Activate(); 1.222 + void Deactivate(); 1.223 + 1.224 + bool MapEventCoordinatesForChildProcess(mozilla::WidgetEvent* aEvent); 1.225 + void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint& aOffset, 1.226 + mozilla::WidgetEvent* aEvent); 1.227 + 1.228 + virtual bool RecvRequestNativeKeyBindings(const mozilla::WidgetKeyboardEvent& aEvent, 1.229 + MaybeNativeKeyBinding* aBindings) MOZ_OVERRIDE; 1.230 + 1.231 + void SendMouseEvent(const nsAString& aType, float aX, float aY, 1.232 + int32_t aButton, int32_t aClickCount, 1.233 + int32_t aModifiers, bool aIgnoreRootScrollFrame); 1.234 + void SendKeyEvent(const nsAString& aType, int32_t aKeyCode, 1.235 + int32_t aCharCode, int32_t aModifiers, 1.236 + bool aPreventDefault); 1.237 + bool SendRealMouseEvent(mozilla::WidgetMouseEvent& event); 1.238 + bool SendMouseWheelEvent(mozilla::WidgetWheelEvent& event); 1.239 + bool SendRealKeyEvent(mozilla::WidgetKeyboardEvent& event); 1.240 + bool SendRealTouchEvent(WidgetTouchEvent& event); 1.241 + bool SendHandleSingleTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); 1.242 + bool SendHandleLongTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); 1.243 + bool SendHandleLongTapUp(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); 1.244 + bool SendHandleDoubleTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); 1.245 + 1.246 + virtual PDocumentRendererParent* 1.247 + AllocPDocumentRendererParent(const nsRect& documentRect, 1.248 + const gfx::Matrix& transform, 1.249 + const nsString& bgcolor, 1.250 + const uint32_t& renderFlags, 1.251 + const bool& flushLayout, 1.252 + const nsIntSize& renderSize) MOZ_OVERRIDE; 1.253 + virtual bool DeallocPDocumentRendererParent(PDocumentRendererParent* actor) MOZ_OVERRIDE; 1.254 + 1.255 + virtual PContentPermissionRequestParent* 1.256 + AllocPContentPermissionRequestParent(const InfallibleTArray<PermissionRequest>& aRequests, 1.257 + const IPC::Principal& aPrincipal) MOZ_OVERRIDE; 1.258 + virtual bool 1.259 + DeallocPContentPermissionRequestParent(PContentPermissionRequestParent* actor) MOZ_OVERRIDE; 1.260 + 1.261 + virtual PFilePickerParent* 1.262 + AllocPFilePickerParent(const nsString& aTitle, 1.263 + const int16_t& aMode) MOZ_OVERRIDE; 1.264 + virtual bool DeallocPFilePickerParent(PFilePickerParent* actor) MOZ_OVERRIDE; 1.265 + 1.266 + virtual POfflineCacheUpdateParent* 1.267 + AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI, 1.268 + const URIParams& aDocumentURI, 1.269 + const bool& aStickDocument) MOZ_OVERRIDE; 1.270 + virtual bool 1.271 + RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor, 1.272 + const URIParams& aManifestURI, 1.273 + const URIParams& aDocumentURI, 1.274 + const bool& stickDocument) MOZ_OVERRIDE; 1.275 + virtual bool 1.276 + DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor) MOZ_OVERRIDE; 1.277 + 1.278 + virtual bool RecvSetOfflinePermission(const IPC::Principal& principal) MOZ_OVERRIDE; 1.279 + 1.280 + bool GetGlobalJSObject(JSContext* cx, JSObject** globalp); 1.281 + 1.282 + NS_DECL_ISUPPORTS 1.283 + NS_DECL_NSIAUTHPROMPTPROVIDER 1.284 + NS_DECL_NSISECUREBROWSERUI 1.285 + 1.286 + static TabParent *GetIMETabParent() { return mIMETabParent; } 1.287 + bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent); 1.288 + bool SendCompositionEvent(mozilla::WidgetCompositionEvent& event); 1.289 + bool SendTextEvent(mozilla::WidgetTextEvent& event); 1.290 + bool SendSelectionEvent(mozilla::WidgetSelectionEvent& event); 1.291 + 1.292 + static TabParent* GetFrom(nsFrameLoader* aFrameLoader); 1.293 + static TabParent* GetFrom(nsIContent* aContent); 1.294 + 1.295 + ContentParent* Manager() { return mManager; } 1.296 + 1.297 + /** 1.298 + * Let managees query if Destroy() is already called so they don't send out 1.299 + * messages when the PBrowser actor is being destroyed. 1.300 + */ 1.301 + bool IsDestroyed() const { return mIsDestroyed; } 1.302 + 1.303 +protected: 1.304 + bool ReceiveMessage(const nsString& aMessage, 1.305 + bool aSync, 1.306 + const StructuredCloneData* aCloneData, 1.307 + CpowHolder* aCpows, 1.308 + nsIPrincipal* aPrincipal, 1.309 + InfallibleTArray<nsString>* aJSONRetVal = nullptr); 1.310 + 1.311 + virtual bool Recv__delete__() MOZ_OVERRIDE; 1.312 + 1.313 + virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; 1.314 + 1.315 + virtual PIndexedDBParent* AllocPIndexedDBParent( 1.316 + const nsCString& aGroup, 1.317 + const nsCString& aASCIIOrigin, 1.318 + bool* /* aAllowed */) MOZ_OVERRIDE; 1.319 + 1.320 + virtual bool DeallocPIndexedDBParent(PIndexedDBParent* aActor) MOZ_OVERRIDE; 1.321 + 1.322 + virtual bool 1.323 + RecvPIndexedDBConstructor(PIndexedDBParent* aActor, 1.324 + const nsCString& aGroup, 1.325 + const nsCString& aASCIIOrigin, 1.326 + bool* aAllowed) MOZ_OVERRIDE; 1.327 + 1.328 + Element* mFrameElement; 1.329 + nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow; 1.330 + 1.331 + bool AllowContentIME(); 1.332 + nsIntPoint GetChildProcessOffset(); 1.333 + 1.334 + virtual PRenderFrameParent* AllocPRenderFrameParent() MOZ_OVERRIDE; 1.335 + virtual bool DeallocPRenderFrameParent(PRenderFrameParent* aFrame) MOZ_OVERRIDE; 1.336 + 1.337 + // IME 1.338 + static TabParent *mIMETabParent; 1.339 + nsString mIMECacheText; 1.340 + uint32_t mIMESelectionAnchor; 1.341 + uint32_t mIMESelectionFocus; 1.342 + bool mIMEComposing; 1.343 + bool mIMECompositionEnding; 1.344 + // Buffer to store composition text during ResetInputState 1.345 + // Compositions in almost all cases are small enough for nsAutoString 1.346 + nsAutoString mIMECompositionText; 1.347 + uint32_t mIMECompositionStart; 1.348 + uint32_t mIMESeqno; 1.349 + 1.350 + uint32_t mIMECompositionRectOffset; 1.351 + nsIntRect mIMECompositionRect; 1.352 + nsIntRect mIMECaretRect; 1.353 + 1.354 + // The number of event series we're currently capturing. 1.355 + int32_t mEventCaptureDepth; 1.356 + 1.357 + nsRect mRect; 1.358 + nsIntSize mDimensions; 1.359 + ScreenOrientation mOrientation; 1.360 + float mDPI; 1.361 + CSSToLayoutDeviceScale mDefaultScale; 1.362 + bool mShown; 1.363 + bool mUpdatedDimensions; 1.364 + 1.365 +private: 1.366 + already_AddRefed<nsFrameLoader> GetFrameLoader() const; 1.367 + already_AddRefed<nsIWidget> GetWidget() const; 1.368 + layout::RenderFrameParent* GetRenderFrame(); 1.369 + nsRefPtr<ContentParent> mManager; 1.370 + void TryCacheDPIAndScale(); 1.371 + 1.372 + CSSPoint AdjustTapToChildWidget(const CSSPoint& aPoint); 1.373 + 1.374 + // When true, we create a pan/zoom controller for our frame and 1.375 + // notify it of input events targeting us. 1.376 + bool UseAsyncPanZoom(); 1.377 + // If we have a render frame currently, notify it that we're about 1.378 + // to dispatch |aEvent| to our child. If there's a relevant 1.379 + // transform in place, |aEvent| will be transformed in-place so that 1.380 + // it is ready to be dispatched to content. 1.381 + // |aOutTargetGuid| will contain the identifier 1.382 + // of the APZC instance that handled the event. aOutTargetGuid may be 1.383 + // null. 1.384 + void MaybeForwardEventToRenderFrame(WidgetInputEvent& aEvent, 1.385 + ScrollableLayerGuid* aOutTargetGuid); 1.386 + // The offset for the child process which is sampled at touch start. This 1.387 + // means that the touch events are relative to where the frame was at the 1.388 + // start of the touch. We need to look for a better solution to this 1.389 + // problem see bug 872911. 1.390 + LayoutDeviceIntPoint mChildProcessOffsetAtTouchStart; 1.391 + // When true, we've initiated normal shutdown and notified our 1.392 + // managing PContent. 1.393 + bool mMarkedDestroying; 1.394 + // When true, the TabParent is invalid and we should not send IPC messages 1.395 + // anymore. 1.396 + bool mIsDestroyed; 1.397 + // Whether we have already sent a FileDescriptor for the app package. 1.398 + bool mAppPackageFileDescriptorSent; 1.399 + 1.400 + uint32_t mChromeFlags; 1.401 + 1.402 + nsCOMPtr<nsILoadContext> mLoadContext; 1.403 +}; 1.404 + 1.405 +} // namespace dom 1.406 +} // namespace mozilla 1.407 + 1.408 +#endif