michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set sw=4 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_tabs_TabParent_h michael@0: #define mozilla_tabs_TabParent_h michael@0: michael@0: #include "mozilla/EventForwards.h" michael@0: #include "mozilla/dom/PBrowserParent.h" michael@0: #include "mozilla/dom/PFilePickerParent.h" michael@0: #include "mozilla/dom/TabContext.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIAuthPromptProvider.h" michael@0: #include "nsIBrowserDOMWindow.h" michael@0: #include "nsISecureBrowserUI.h" michael@0: #include "nsITabParent.h" michael@0: #include "nsIXULBrowserWindow.h" michael@0: #include "Units.h" michael@0: #include "js/TypeDecls.h" michael@0: michael@0: class nsFrameLoader; michael@0: class nsIContent; michael@0: class nsIPrincipal; michael@0: class nsIURI; michael@0: class nsIWidget; michael@0: class nsILoadContext; michael@0: class CpowHolder; michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace layers { michael@0: struct FrameMetrics; michael@0: struct TextureFactoryIdentifier; michael@0: } michael@0: michael@0: namespace layout { michael@0: class RenderFrameParent; michael@0: } michael@0: michael@0: namespace dom { michael@0: michael@0: class ClonedMessageData; michael@0: class ContentParent; michael@0: class Element; michael@0: struct StructuredCloneData; michael@0: michael@0: class TabParent : public PBrowserParent michael@0: , public nsITabParent michael@0: , public nsIAuthPromptProvider michael@0: , public nsISecureBrowserUI michael@0: , public TabContext michael@0: { michael@0: typedef mozilla::dom::ClonedMessageData ClonedMessageData; michael@0: typedef mozilla::layout::ScrollingBehavior ScrollingBehavior; michael@0: michael@0: public: michael@0: // nsITabParent michael@0: NS_DECL_NSITABPARENT michael@0: michael@0: TabParent(ContentParent* aManager, const TabContext& aContext, uint32_t aChromeFlags); michael@0: virtual ~TabParent(); michael@0: Element* GetOwnerElement() const { return mFrameElement; } michael@0: void SetOwnerElement(Element* aElement); michael@0: michael@0: /** michael@0: * Get the mozapptype attribute from this TabParent's owner DOM element. michael@0: */ michael@0: void GetAppType(nsAString& aOut); michael@0: michael@0: /** michael@0: * Returns true iff this TabParent's nsIFrameLoader is visible. michael@0: * michael@0: * The frameloader's visibility can be independent of e.g. its docshell's michael@0: * visibility. michael@0: */ michael@0: bool IsVisible(); michael@0: michael@0: nsIBrowserDOMWindow *GetBrowserDOMWindow() { return mBrowserDOMWindow; } michael@0: void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) { michael@0: mBrowserDOMWindow = aBrowserDOMWindow; michael@0: } michael@0: michael@0: already_AddRefed GetLoadContext(); michael@0: michael@0: nsIXULBrowserWindow* GetXULBrowserWindow(); michael@0: michael@0: /** michael@0: * Return the TabParent that has decided it wants to capture an michael@0: * event series for fast-path dispatch to its subprocess, if one michael@0: * has. michael@0: * michael@0: * DOM event dispatch and widget are free to ignore capture michael@0: * requests from TabParents; the end result wrt remote content is michael@0: * (must be) always the same, albeit usually slower without michael@0: * subprocess capturing. This allows frontends/widget backends to michael@0: * "opt in" to faster cross-process dispatch. michael@0: */ michael@0: static TabParent* GetEventCapturer(); michael@0: /** michael@0: * If this is the current event capturer, give this a chance to michael@0: * capture the event. If it was captured, return true, false michael@0: * otherwise. Un-captured events should follow normal DOM michael@0: * dispatch; captured events should result in no further michael@0: * processing from the caller of TryCapture(). michael@0: * michael@0: * It's an error to call TryCapture() if this isn't the event michael@0: * capturer. michael@0: */ michael@0: bool TryCapture(const WidgetGUIEvent& aEvent); michael@0: michael@0: void Destroy(); michael@0: michael@0: virtual bool RecvMoveFocus(const bool& aForward) MOZ_OVERRIDE; michael@0: virtual bool RecvEvent(const RemoteDOMEvent& aEvent) MOZ_OVERRIDE; michael@0: virtual bool RecvReplyKeyEvent(const WidgetKeyboardEvent& event); michael@0: virtual bool RecvPRenderFrameConstructor(PRenderFrameParent* actor) MOZ_OVERRIDE; michael@0: virtual bool RecvInitRenderFrame(PRenderFrameParent* aFrame, michael@0: ScrollingBehavior* scrolling, michael@0: TextureFactoryIdentifier* identifier, michael@0: uint64_t* layersId, michael@0: bool *aSuccess) MOZ_OVERRIDE; michael@0: virtual bool RecvBrowserFrameOpenWindow(PBrowserParent* aOpener, michael@0: const nsString& aURL, michael@0: const nsString& aName, michael@0: const nsString& aFeatures, michael@0: bool* aOutWindowOpened) MOZ_OVERRIDE; michael@0: virtual bool AnswerCreateWindow(PBrowserParent** retval) MOZ_OVERRIDE; michael@0: virtual bool RecvSyncMessage(const nsString& aMessage, michael@0: const ClonedMessageData& aData, michael@0: const InfallibleTArray& aCpows, michael@0: const IPC::Principal& aPrincipal, michael@0: InfallibleTArray* aJSONRetVal) MOZ_OVERRIDE; michael@0: virtual bool AnswerRpcMessage(const nsString& aMessage, michael@0: const ClonedMessageData& aData, michael@0: const InfallibleTArray& aCpows, michael@0: const IPC::Principal& aPrincipal, michael@0: InfallibleTArray* aJSONRetVal) MOZ_OVERRIDE; michael@0: virtual bool RecvAsyncMessage(const nsString& aMessage, michael@0: const ClonedMessageData& aData, michael@0: const InfallibleTArray& aCpows, michael@0: const IPC::Principal& aPrincipal) MOZ_OVERRIDE; michael@0: virtual bool RecvNotifyIMEFocus(const bool& aFocus, michael@0: nsIMEUpdatePreference* aPreference, michael@0: uint32_t* aSeqno) MOZ_OVERRIDE; michael@0: virtual bool RecvNotifyIMETextChange(const uint32_t& aStart, michael@0: const uint32_t& aEnd, michael@0: const uint32_t& aNewEnd, michael@0: const bool& aCausedByComposition) MOZ_OVERRIDE; michael@0: virtual bool RecvNotifyIMESelectedCompositionRect(const uint32_t& aOffset, michael@0: const nsIntRect& aRect, michael@0: const nsIntRect& aCaretRect) MOZ_OVERRIDE; michael@0: virtual bool RecvNotifyIMESelection(const uint32_t& aSeqno, michael@0: const uint32_t& aAnchor, michael@0: const uint32_t& aFocus, michael@0: const bool& aCausedByComposition) MOZ_OVERRIDE; michael@0: virtual bool RecvNotifyIMETextHint(const nsString& aText) MOZ_OVERRIDE; michael@0: virtual bool RecvEndIMEComposition(const bool& aCancel, michael@0: nsString* aComposition) MOZ_OVERRIDE; michael@0: virtual bool RecvGetInputContext(int32_t* aIMEEnabled, michael@0: int32_t* aIMEOpen, michael@0: intptr_t* aNativeIMEContext) MOZ_OVERRIDE; michael@0: virtual bool RecvSetInputContext(const int32_t& aIMEEnabled, michael@0: const int32_t& aIMEOpen, michael@0: const nsString& aType, michael@0: const nsString& aInputmode, michael@0: const nsString& aActionHint, michael@0: const int32_t& aCause, michael@0: const int32_t& aFocusChange) MOZ_OVERRIDE; michael@0: virtual bool RecvRequestFocus(const bool& aCanRaise) MOZ_OVERRIDE; michael@0: virtual bool RecvSetCursor(const uint32_t& aValue) MOZ_OVERRIDE; michael@0: virtual bool RecvSetBackgroundColor(const nscolor& aValue) MOZ_OVERRIDE; michael@0: virtual bool RecvSetStatus(const uint32_t& aType, const nsString& aStatus) MOZ_OVERRIDE; michael@0: virtual bool RecvIsParentWindowMainWidgetVisible(bool* aIsVisible); michael@0: virtual bool RecvShowTooltip(const uint32_t& aX, const uint32_t& aY, const nsString& aTooltip); michael@0: virtual bool RecvHideTooltip(); michael@0: virtual bool RecvGetDPI(float* aValue) MOZ_OVERRIDE; michael@0: virtual bool RecvGetDefaultScale(double* aValue) MOZ_OVERRIDE; michael@0: virtual bool RecvGetWidgetNativeData(WindowsHandle* aValue) MOZ_OVERRIDE; michael@0: virtual bool RecvZoomToRect(const uint32_t& aPresShellId, michael@0: const ViewID& aViewId, michael@0: const CSSRect& aRect) MOZ_OVERRIDE; michael@0: virtual bool RecvUpdateZoomConstraints(const uint32_t& aPresShellId, michael@0: const ViewID& aViewId, michael@0: const bool& aIsRoot, michael@0: const ZoomConstraints& aConstraints) MOZ_OVERRIDE; michael@0: virtual bool RecvContentReceivedTouch(const ScrollableLayerGuid& aGuid, michael@0: const bool& aPreventDefault) MOZ_OVERRIDE; michael@0: michael@0: virtual PColorPickerParent* michael@0: AllocPColorPickerParent(const nsString& aTitle, const nsString& aInitialColor) MOZ_OVERRIDE; michael@0: virtual bool DeallocPColorPickerParent(PColorPickerParent* aColorPicker) MOZ_OVERRIDE; michael@0: michael@0: void LoadURL(nsIURI* aURI); michael@0: // XXX/cjones: it's not clear what we gain by hiding these michael@0: // message-sending functions under a layer of indirection and michael@0: // eating the return values michael@0: void Show(const nsIntSize& size); michael@0: void UpdateDimensions(const nsRect& rect, const nsIntSize& size); michael@0: void UpdateFrame(const layers::FrameMetrics& aFrameMetrics); michael@0: void AcknowledgeScrollUpdate(const ViewID& aScrollId, const uint32_t& aScrollGeneration); michael@0: void HandleDoubleTap(const CSSPoint& aPoint, michael@0: int32_t aModifiers, michael@0: const ScrollableLayerGuid& aGuid); michael@0: void HandleSingleTap(const CSSPoint& aPoint, michael@0: int32_t aModifiers, michael@0: const ScrollableLayerGuid& aGuid); michael@0: void HandleLongTap(const CSSPoint& aPoint, michael@0: int32_t aModifiers, michael@0: const ScrollableLayerGuid& aGuid); michael@0: void HandleLongTapUp(const CSSPoint& aPoint, michael@0: int32_t aModifiers, michael@0: const ScrollableLayerGuid& aGuid); michael@0: void NotifyAPZStateChange(ViewID aViewId, michael@0: APZStateChange aChange, michael@0: int aArg); michael@0: void Activate(); michael@0: void Deactivate(); michael@0: michael@0: bool MapEventCoordinatesForChildProcess(mozilla::WidgetEvent* aEvent); michael@0: void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint& aOffset, michael@0: mozilla::WidgetEvent* aEvent); michael@0: michael@0: virtual bool RecvRequestNativeKeyBindings(const mozilla::WidgetKeyboardEvent& aEvent, michael@0: MaybeNativeKeyBinding* aBindings) MOZ_OVERRIDE; michael@0: michael@0: void SendMouseEvent(const nsAString& aType, float aX, float aY, michael@0: int32_t aButton, int32_t aClickCount, michael@0: int32_t aModifiers, bool aIgnoreRootScrollFrame); michael@0: void SendKeyEvent(const nsAString& aType, int32_t aKeyCode, michael@0: int32_t aCharCode, int32_t aModifiers, michael@0: bool aPreventDefault); michael@0: bool SendRealMouseEvent(mozilla::WidgetMouseEvent& event); michael@0: bool SendMouseWheelEvent(mozilla::WidgetWheelEvent& event); michael@0: bool SendRealKeyEvent(mozilla::WidgetKeyboardEvent& event); michael@0: bool SendRealTouchEvent(WidgetTouchEvent& event); michael@0: bool SendHandleSingleTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); michael@0: bool SendHandleLongTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); michael@0: bool SendHandleLongTapUp(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); michael@0: bool SendHandleDoubleTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid); michael@0: michael@0: virtual PDocumentRendererParent* michael@0: AllocPDocumentRendererParent(const nsRect& documentRect, michael@0: const gfx::Matrix& transform, michael@0: const nsString& bgcolor, michael@0: const uint32_t& renderFlags, michael@0: const bool& flushLayout, michael@0: const nsIntSize& renderSize) MOZ_OVERRIDE; michael@0: virtual bool DeallocPDocumentRendererParent(PDocumentRendererParent* actor) MOZ_OVERRIDE; michael@0: michael@0: virtual PContentPermissionRequestParent* michael@0: AllocPContentPermissionRequestParent(const InfallibleTArray& aRequests, michael@0: const IPC::Principal& aPrincipal) MOZ_OVERRIDE; michael@0: virtual bool michael@0: DeallocPContentPermissionRequestParent(PContentPermissionRequestParent* actor) MOZ_OVERRIDE; michael@0: michael@0: virtual PFilePickerParent* michael@0: AllocPFilePickerParent(const nsString& aTitle, michael@0: const int16_t& aMode) MOZ_OVERRIDE; michael@0: virtual bool DeallocPFilePickerParent(PFilePickerParent* actor) MOZ_OVERRIDE; michael@0: michael@0: virtual POfflineCacheUpdateParent* michael@0: AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI, michael@0: const URIParams& aDocumentURI, michael@0: const bool& aStickDocument) MOZ_OVERRIDE; michael@0: virtual bool michael@0: RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor, michael@0: const URIParams& aManifestURI, michael@0: const URIParams& aDocumentURI, michael@0: const bool& stickDocument) MOZ_OVERRIDE; michael@0: virtual bool michael@0: DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor) MOZ_OVERRIDE; michael@0: michael@0: virtual bool RecvSetOfflinePermission(const IPC::Principal& principal) MOZ_OVERRIDE; michael@0: michael@0: bool GetGlobalJSObject(JSContext* cx, JSObject** globalp); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIAUTHPROMPTPROVIDER michael@0: NS_DECL_NSISECUREBROWSERUI michael@0: michael@0: static TabParent *GetIMETabParent() { return mIMETabParent; } michael@0: bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent); michael@0: bool SendCompositionEvent(mozilla::WidgetCompositionEvent& event); michael@0: bool SendTextEvent(mozilla::WidgetTextEvent& event); michael@0: bool SendSelectionEvent(mozilla::WidgetSelectionEvent& event); michael@0: michael@0: static TabParent* GetFrom(nsFrameLoader* aFrameLoader); michael@0: static TabParent* GetFrom(nsIContent* aContent); michael@0: michael@0: ContentParent* Manager() { return mManager; } michael@0: michael@0: /** michael@0: * Let managees query if Destroy() is already called so they don't send out michael@0: * messages when the PBrowser actor is being destroyed. michael@0: */ michael@0: bool IsDestroyed() const { return mIsDestroyed; } michael@0: michael@0: protected: michael@0: bool ReceiveMessage(const nsString& aMessage, michael@0: bool aSync, michael@0: const StructuredCloneData* aCloneData, michael@0: CpowHolder* aCpows, michael@0: nsIPrincipal* aPrincipal, michael@0: InfallibleTArray* aJSONRetVal = nullptr); michael@0: michael@0: virtual bool Recv__delete__() MOZ_OVERRIDE; michael@0: michael@0: virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; michael@0: michael@0: virtual PIndexedDBParent* AllocPIndexedDBParent( michael@0: const nsCString& aGroup, michael@0: const nsCString& aASCIIOrigin, michael@0: bool* /* aAllowed */) MOZ_OVERRIDE; michael@0: michael@0: virtual bool DeallocPIndexedDBParent(PIndexedDBParent* aActor) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvPIndexedDBConstructor(PIndexedDBParent* aActor, michael@0: const nsCString& aGroup, michael@0: const nsCString& aASCIIOrigin, michael@0: bool* aAllowed) MOZ_OVERRIDE; michael@0: michael@0: Element* mFrameElement; michael@0: nsCOMPtr mBrowserDOMWindow; michael@0: michael@0: bool AllowContentIME(); michael@0: nsIntPoint GetChildProcessOffset(); michael@0: michael@0: virtual PRenderFrameParent* AllocPRenderFrameParent() MOZ_OVERRIDE; michael@0: virtual bool DeallocPRenderFrameParent(PRenderFrameParent* aFrame) MOZ_OVERRIDE; michael@0: michael@0: // IME michael@0: static TabParent *mIMETabParent; michael@0: nsString mIMECacheText; michael@0: uint32_t mIMESelectionAnchor; michael@0: uint32_t mIMESelectionFocus; michael@0: bool mIMEComposing; michael@0: bool mIMECompositionEnding; michael@0: // Buffer to store composition text during ResetInputState michael@0: // Compositions in almost all cases are small enough for nsAutoString michael@0: nsAutoString mIMECompositionText; michael@0: uint32_t mIMECompositionStart; michael@0: uint32_t mIMESeqno; michael@0: michael@0: uint32_t mIMECompositionRectOffset; michael@0: nsIntRect mIMECompositionRect; michael@0: nsIntRect mIMECaretRect; michael@0: michael@0: // The number of event series we're currently capturing. michael@0: int32_t mEventCaptureDepth; michael@0: michael@0: nsRect mRect; michael@0: nsIntSize mDimensions; michael@0: ScreenOrientation mOrientation; michael@0: float mDPI; michael@0: CSSToLayoutDeviceScale mDefaultScale; michael@0: bool mShown; michael@0: bool mUpdatedDimensions; michael@0: michael@0: private: michael@0: already_AddRefed GetFrameLoader() const; michael@0: already_AddRefed GetWidget() const; michael@0: layout::RenderFrameParent* GetRenderFrame(); michael@0: nsRefPtr mManager; michael@0: void TryCacheDPIAndScale(); michael@0: michael@0: CSSPoint AdjustTapToChildWidget(const CSSPoint& aPoint); michael@0: michael@0: // When true, we create a pan/zoom controller for our frame and michael@0: // notify it of input events targeting us. michael@0: bool UseAsyncPanZoom(); michael@0: // If we have a render frame currently, notify it that we're about michael@0: // to dispatch |aEvent| to our child. If there's a relevant michael@0: // transform in place, |aEvent| will be transformed in-place so that michael@0: // it is ready to be dispatched to content. michael@0: // |aOutTargetGuid| will contain the identifier michael@0: // of the APZC instance that handled the event. aOutTargetGuid may be michael@0: // null. michael@0: void MaybeForwardEventToRenderFrame(WidgetInputEvent& aEvent, michael@0: ScrollableLayerGuid* aOutTargetGuid); michael@0: // The offset for the child process which is sampled at touch start. This michael@0: // means that the touch events are relative to where the frame was at the michael@0: // start of the touch. We need to look for a better solution to this michael@0: // problem see bug 872911. michael@0: LayoutDeviceIntPoint mChildProcessOffsetAtTouchStart; michael@0: // When true, we've initiated normal shutdown and notified our michael@0: // managing PContent. michael@0: bool mMarkedDestroying; michael@0: // When true, the TabParent is invalid and we should not send IPC messages michael@0: // anymore. michael@0: bool mIsDestroyed; michael@0: // Whether we have already sent a FileDescriptor for the app package. michael@0: bool mAppPackageFileDescriptorSent; michael@0: michael@0: uint32_t mChromeFlags; michael@0: michael@0: nsCOMPtr mLoadContext; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif