1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8; -*- */
2 /* vim: set sw=2 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 #include "base/basictypes.h"
11 #include "AppProcessChecker.h"
12 #include "IDBFactory.h"
13 #include "IndexedDBParent.h"
14 #include "mozIApplication.h"
15 #include "mozilla/BrowserElementParent.h"
16 #include "mozilla/docshell/OfflineCacheUpdateParent.h"
17 #include "mozilla/dom/ContentParent.h"
18 #include "mozilla/dom/PContentPermissionRequestParent.h"
19 #include "mozilla/EventStateManager.h"
20 #include "mozilla/Hal.h"
21 #include "mozilla/ipc/DocumentRendererParent.h"
22 #include "mozilla/layers/CompositorParent.h"
23 #include "mozilla/layout/RenderFrameParent.h"
24 #include "mozilla/MouseEvents.h"
25 #include "mozilla/net/NeckoChild.h"
26 #include "mozilla/Preferences.h"
27 #include "mozilla/TextEvents.h"
28 #include "mozilla/TouchEvents.h"
29 #include "mozilla/unused.h"
31 #include "nsContentPermissionHelper.h"
32 #include "nsContentUtils.h"
34 #include "nsFocusManager.h"
35 #include "nsFrameLoader.h"
36 #include "nsIContent.h"
37 #include "nsIDocShell.h"
38 #include "nsIDocShellTreeOwner.h"
39 #include "nsIDOMElement.h"
40 #include "nsIDOMEvent.h"
41 #include "nsIDOMWindow.h"
42 #include "nsIDOMWindowUtils.h"
43 #include "nsIInterfaceRequestorUtils.h"
44 #include "nsILoadInfo.h"
45 #include "nsIPromptFactory.h"
47 #include "nsIWebBrowserChrome.h"
48 #include "nsIWindowCreator2.h"
49 #include "nsIXULBrowserWindow.h"
50 #include "nsIXULWindow.h"
51 #include "nsViewManager.h"
52 #include "nsIWidget.h"
53 #include "nsIWindowWatcher.h"
54 #include "nsPIDOMWindow.h"
55 #include "nsPIWindowWatcher.h"
56 #include "nsPrintfCString.h"
57 #include "nsServiceManagerUtils.h"
58 #include "nsThreadUtils.h"
59 #include "nsWindowWatcher.h"
60 #include "private/pprio.h"
61 #include "PermissionMessageUtils.h"
62 #include "StructuredCloneUtils.h"
63 #include "ColorPickerParent.h"
64 #include "JavaScriptParent.h"
65 #include "FilePickerParent.h"
67 #include "LoadContext.h"
69 #include "nsIAuthInformation.h"
70 #include "nsIAuthPromptCallback.h"
71 #include "nsAuthInformationHolder.h"
72 #include "nsICancelable.h"
76 using namespace mozilla::dom
;
77 using namespace mozilla::ipc
;
78 using namespace mozilla::layers
;
79 using namespace mozilla::layout
;
80 using namespace mozilla::services
;
81 using namespace mozilla::widget
;
82 using namespace mozilla::dom::indexedDB
;
83 using namespace mozilla::jsipc
;
85 // The flags passed by the webProgress notifications are 16 bits shifted
86 // from the ones registered by webProgressListeners.
87 #define NOTIFY_FLAG_SHIFT 16
89 class OpenFileAndSendFDRunnable
: public nsRunnable
92 nsRefPtr
<TabParent
> mTabParent
;
93 nsCOMPtr
<nsIEventTarget
> mEventTarget
;
97 OpenFileAndSendFDRunnable(const nsAString
& aPath
, TabParent
* aTabParent
)
98 : mPath(aPath
), mTabParent(aTabParent
), mFD(nullptr)
100 MOZ_ASSERT(NS_IsMainThread());
101 MOZ_ASSERT(!aPath
.IsEmpty());
102 MOZ_ASSERT(aTabParent
);
107 MOZ_ASSERT(NS_IsMainThread());
109 mEventTarget
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID
);
110 NS_ENSURE_TRUE_VOID(mEventTarget
);
112 nsresult rv
= mEventTarget
->Dispatch(this, NS_DISPATCH_NORMAL
);
113 NS_ENSURE_SUCCESS_VOID(rv
);
117 ~OpenFileAndSendFDRunnable()
122 // This shouldn't be called directly except by the event loop. Use Dispatch
123 // to start the sequence.
126 if (NS_IsMainThread()) {
139 MOZ_ASSERT(NS_IsMainThread());
140 MOZ_ASSERT(mTabParent
);
141 MOZ_ASSERT(mEventTarget
);
144 nsRefPtr
<TabParent
> tabParent
;
145 mTabParent
.swap(tabParent
);
147 using mozilla::ipc::FileDescriptor
;
149 FileDescriptor::PlatformHandleType handle
=
150 FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(mFD
));
152 // Our TabParent may have been destroyed already. If so, don't send any
153 // fds over, just go back to the IO thread and close them.
154 if (!tabParent
->IsDestroyed()) {
155 mozilla::unused
<< tabParent
->SendCacheFileDescriptor(mPath
,
156 FileDescriptor(handle
));
159 nsCOMPtr
<nsIEventTarget
> eventTarget
;
160 mEventTarget
.swap(eventTarget
);
162 if (NS_FAILED(eventTarget
->Dispatch(this, NS_DISPATCH_NORMAL
))) {
163 NS_WARNING("Failed to dispatch to stream transport service!");
165 // It's probably safer to take the main thread IO hit here rather
166 // than leak a file descriptor.
173 MOZ_ASSERT(!NS_IsMainThread());
176 nsCOMPtr
<nsIFile
> file
;
177 nsresult rv
= NS_NewLocalFile(mPath
, false, getter_AddRefs(file
));
178 NS_ENSURE_SUCCESS_VOID(rv
);
181 rv
= file
->OpenNSPRFileDesc(PR_RDONLY
, 0, &fd
);
182 NS_ENSURE_SUCCESS_VOID(rv
);
186 if (NS_FAILED(NS_DispatchToMainThread(this))) {
187 NS_WARNING("Failed to dispatch to main thread!");
195 // It's possible for this to happen on the main thread if the dispatch
196 // to the stream service fails after we've already opened the file so
197 // we can't assert the thread we're running on.
202 prrc
= PR_Close(mFD
);
203 if (prrc
!= PR_SUCCESS
) {
204 NS_ERROR("PR_Close() failed.");
213 TabParent
* sEventCapturer
;
215 TabParent
*TabParent::mIMETabParent
= nullptr;
217 NS_IMPL_ISUPPORTS(TabParent
,
219 nsIAuthPromptProvider
,
221 nsISupportsWeakReference
)
223 TabParent::TabParent(nsIContentParent
* aManager
, const TabContext
& aContext
, uint32_t aChromeFlags
)
224 : TabContext(aContext
)
225 , mFrameElement(nullptr)
226 , mIMESelectionAnchor(0)
227 , mIMESelectionFocus(0)
228 , mIMEComposing(false)
229 , mIMECompositionEnding(false)
230 , mIMECompositionStart(0)
232 , mIMECompositionRectOffset(0)
233 , mEventCaptureDepth(0)
240 , mUpdatedDimensions(false)
242 , mMarkedDestroying(false)
243 , mIsDestroyed(false)
244 , mAppPackageFileDescriptorSent(false)
245 , mChromeFlags(aChromeFlags
)
247 MOZ_ASSERT(aManager
);
250 TabParent::~TabParent()
255 TabParent::SetOwnerElement(Element
* aElement
)
257 mFrameElement
= aElement
;
258 TryCacheDPIAndScale();
262 TabParent::GetAppType(nsAString
& aOut
)
265 nsCOMPtr
<Element
> elem
= do_QueryInterface(mFrameElement
);
270 elem
->GetAttr(kNameSpaceID_None
, nsGkAtoms::mozapptype
, aOut
);
274 TabParent::IsVisible()
276 nsRefPtr
<nsFrameLoader
> frameLoader
= GetFrameLoader();
281 bool visible
= false;
282 frameLoader
->GetVisible(&visible
);
293 // If this fails, it's most likely due to a content-process crash,
294 // and auto-cleanup will kick in. Otherwise, the child side will
295 // destroy itself and send back __delete__().
296 unused
<< SendDestroy();
298 const InfallibleTArray
<PIndexedDBParent
*>& idbParents
=
299 ManagedPIndexedDBParent();
300 for (uint32_t i
= 0; i
< idbParents
.Length(); ++i
) {
301 static_cast<IndexedDBParent
*>(idbParents
[i
])->Disconnect();
304 const InfallibleTArray
<POfflineCacheUpdateParent
*>& ocuParents
=
305 ManagedPOfflineCacheUpdateParent();
306 for (uint32_t i
= 0; i
< ocuParents
.Length(); ++i
) {
307 nsRefPtr
<mozilla::docshell::OfflineCacheUpdateParent
> ocuParent
=
308 static_cast<mozilla::docshell::OfflineCacheUpdateParent
*>(ocuParents
[i
]);
309 ocuParent
->StopSendingMessagesToChild();
312 if (RenderFrameParent
* frame
= GetRenderFrame()) {
317 if (XRE_GetProcessType() == GeckoProcessType_Default
) {
318 Manager()->AsContentParent()->NotifyTabDestroying(this);
320 mMarkedDestroying
= true;
324 TabParent::Recv__delete__()
326 if (XRE_GetProcessType() == GeckoProcessType_Default
) {
327 Manager()->AsContentParent()->NotifyTabDestroyed(this, mMarkedDestroying
);
333 TabParent::ActorDestroy(ActorDestroyReason why
)
335 if (sEventCapturer
== this) {
336 sEventCapturer
= nullptr;
338 if (mIMETabParent
== this) {
339 mIMETabParent
= nullptr;
341 nsRefPtr
<nsFrameLoader
> frameLoader
= GetFrameLoader();
342 nsCOMPtr
<nsIObserverService
> os
= services::GetObserverService();
343 nsRefPtr
<nsFrameMessageManager
> fmm
;
345 fmm
= frameLoader
->GetFrameMessageManager();
346 nsCOMPtr
<Element
> frameElement(mFrameElement
);
347 ReceiveMessage(CHILD_PROCESS_SHUTDOWN_MESSAGE
, false, nullptr, nullptr,
349 frameLoader
->DestroyChild();
351 if (why
== AbnormalShutdown
&& os
) {
352 os
->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader
*, frameLoader
),
353 "oop-frameloader-crashed", nullptr);
354 nsContentUtils::DispatchTrustedEvent(frameElement
->OwnerDoc(), frameElement
,
355 NS_LITERAL_STRING("oop-browser-crashed"),
361 os
->NotifyObservers(NS_ISUPPORTS_CAST(nsITabParent
*, this), "ipc:browser-destroyed", nullptr);
369 TabParent::RecvMoveFocus(const bool& aForward
)
371 nsCOMPtr
<nsIFocusManager
> fm
= do_GetService(FOCUSMANAGER_CONTRACTID
);
373 nsCOMPtr
<nsIDOMElement
> dummy
;
374 uint32_t type
= aForward
? uint32_t(nsIFocusManager::MOVEFOCUS_FORWARD
)
375 : uint32_t(nsIFocusManager::MOVEFOCUS_BACKWARD
);
376 nsCOMPtr
<nsIDOMElement
> frame
= do_QueryInterface(mFrameElement
);
377 fm
->MoveFocus(nullptr, frame
, type
, nsIFocusManager::FLAG_BYKEY
,
378 getter_AddRefs(dummy
));
384 TabParent::RecvEvent(const RemoteDOMEvent
& aEvent
)
386 nsCOMPtr
<nsIDOMEvent
> event
= do_QueryInterface(aEvent
.mEvent
);
387 NS_ENSURE_TRUE(event
, true);
389 nsCOMPtr
<mozilla::dom::EventTarget
> target
= do_QueryInterface(mFrameElement
);
390 NS_ENSURE_TRUE(target
, true);
392 event
->SetOwner(target
);
395 target
->DispatchEvent(event
, &dummy
);
400 TabParent::AnswerCreateWindow(const uint32_t& aChromeFlags
,
401 const bool& aCalledFromJS
,
402 const bool& aPositionSpecified
,
403 const bool& aSizeSpecified
,
404 const nsString
& aURI
,
405 const nsString
& aName
,
406 const nsString
& aFeatures
,
407 const nsString
& aBaseURI
,
409 PBrowserParent
** aRetVal
)
411 if (IsBrowserOrApp()) {
416 nsCOMPtr
<nsPIWindowWatcher
> pwwatch
=
417 do_GetService(NS_WINDOWWATCHER_CONTRACTID
, &rv
);
418 NS_ENSURE_SUCCESS(rv
, false);
420 nsCOMPtr
<nsIContent
> frame(do_QueryInterface(mFrameElement
));
421 NS_ENSURE_TRUE(frame
, false);
423 nsCOMPtr
<nsIDOMWindow
> parent
= do_QueryInterface(frame
->OwnerDoc()->GetWindow());
424 NS_ENSURE_TRUE(parent
, false);
426 int32_t openLocation
=
427 nsWindowWatcher::GetWindowOpenLocation(parent
, aChromeFlags
, aCalledFromJS
,
428 aPositionSpecified
, aSizeSpecified
);
430 MOZ_ASSERT(openLocation
== nsIBrowserDOMWindow::OPEN_NEWTAB
||
431 openLocation
== nsIBrowserDOMWindow::OPEN_NEWWINDOW
);
433 *aWindowIsNew
= true;
435 // Opening new tabs is the easy case...
436 if (openLocation
== nsIBrowserDOMWindow::OPEN_NEWTAB
) {
437 NS_ENSURE_TRUE(mBrowserDOMWindow
, false);
439 nsCOMPtr
<nsIFrameLoaderOwner
> frameLoaderOwner
;
440 mBrowserDOMWindow
->OpenURIInFrame(nullptr, nullptr,
441 nsIBrowserDOMWindow::OPEN_NEWTAB
,
442 nsIBrowserDOMWindow::OPEN_NEW
,
443 getter_AddRefs(frameLoaderOwner
));
444 NS_ENSURE_TRUE(frameLoaderOwner
, false);
446 nsRefPtr
<nsFrameLoader
> frameLoader
= frameLoaderOwner
->GetFrameLoader();
447 NS_ENSURE_TRUE(frameLoader
, false);
449 *aRetVal
= frameLoader
->GetRemoteBrowser();
453 // WindowWatcher is going to expect a valid URI to open a window
454 // to. If it can't find one, it's going to attempt to figure one
455 // out on its own, which is problematic because it can't access
456 // the document for the remote browser we're opening. Luckily,
457 // TabChild has sent us a baseURI with which we can ensure that
458 // the URI we pass to WindowWatcher is valid.
459 nsCOMPtr
<nsIURI
> baseURI
;
460 rv
= NS_NewURI(getter_AddRefs(baseURI
), aBaseURI
);
461 NS_ENSURE_SUCCESS(rv
, false);
463 nsCOMPtr
<nsIURI
> finalURI
;
464 rv
= NS_NewURI(getter_AddRefs(finalURI
), NS_ConvertUTF16toUTF8(aURI
).get(), baseURI
);
465 NS_ENSURE_SUCCESS(rv
, false);
467 nsAutoCString finalURIString
;
468 finalURI
->GetSpec(finalURIString
);
470 nsCOMPtr
<nsIDOMWindow
> window
;
472 rv
= pwwatch
->OpenWindow2(parent
, finalURIString
.get(),
473 NS_ConvertUTF16toUTF8(aName
).get(),
474 NS_ConvertUTF16toUTF8(aFeatures
).get(), aCalledFromJS
,
475 false, false, this, nullptr, getter_AddRefs(window
));
476 NS_ENSURE_SUCCESS(rv
, false);
478 nsCOMPtr
<nsPIDOMWindow
> pwindow
= do_QueryInterface(window
);
479 NS_ENSURE_TRUE(pwindow
, false);
481 nsRefPtr
<nsIDocShell
> newDocShell
= pwindow
->GetDocShell();
482 NS_ENSURE_TRUE(newDocShell
, false);
484 nsCOMPtr
<nsITabParent
> newRemoteTab
= newDocShell
->GetOpenedRemote();
485 NS_ENSURE_TRUE(newRemoteTab
, false);
487 *aRetVal
= static_cast<TabParent
*>(newRemoteTab
.get());
492 TabParent::LoadURL(nsIURI
* aURI
)
504 NS_WARNING(nsPrintfCString("TabParent::LoadURL(%s) called before "
505 "Show(). Ignoring LoadURL.\n",
510 unused
<< SendLoadURL(spec
);
512 // If this app is a packaged app then we can speed startup by sending over
513 // the file descriptor for the "application.zip" file that it will
514 // invariably request. Only do this once.
515 if (!mAppPackageFileDescriptorSent
) {
516 mAppPackageFileDescriptorSent
= true;
518 nsCOMPtr
<mozIApplication
> app
= GetOwnOrContainingApp();
520 nsString manifestURL
;
521 nsresult rv
= app
->GetManifestURL(manifestURL
);
522 NS_ENSURE_SUCCESS_VOID(rv
);
524 if (StringBeginsWith(manifestURL
, NS_LITERAL_STRING("app:"))) {
526 rv
= app
->GetBasePath(basePath
);
527 NS_ENSURE_SUCCESS_VOID(rv
);
530 rv
= app
->GetId(appId
);
531 NS_ENSURE_SUCCESS_VOID(rv
);
533 nsCOMPtr
<nsIFile
> packageFile
;
534 rv
= NS_NewLocalFile(basePath
, false,
535 getter_AddRefs(packageFile
));
536 NS_ENSURE_SUCCESS_VOID(rv
);
538 rv
= packageFile
->Append(appId
);
539 NS_ENSURE_SUCCESS_VOID(rv
);
541 rv
= packageFile
->Append(NS_LITERAL_STRING("application.zip"));
542 NS_ENSURE_SUCCESS_VOID(rv
);
545 rv
= packageFile
->GetPath(path
);
546 NS_ENSURE_SUCCESS_VOID(rv
);
548 nsRefPtr
<OpenFileAndSendFDRunnable
> openFileRunnable
=
549 new OpenFileAndSendFDRunnable(path
, this);
550 openFileRunnable
->Dispatch();
557 TabParent::Show(const nsIntSize
& size
)
563 unused
<< SendShow(size
);
568 TabParent::UpdateDimensions(const nsIntRect
& rect
, const nsIntSize
& size
)
573 hal::ScreenConfiguration config
;
574 hal::GetCurrentScreenConfiguration(&config
);
575 ScreenOrientation orientation
= config
.orientation();
577 if (!mUpdatedDimensions
|| mOrientation
!= orientation
||
578 mDimensions
!= size
|| !mRect
.IsEqualEdges(rect
)) {
579 mUpdatedDimensions
= true;
582 mOrientation
= orientation
;
584 unused
<< SendUpdateDimensions(mRect
, mDimensions
, mOrientation
);
589 TabParent::UpdateFrame(const FrameMetrics
& aFrameMetrics
)
592 unused
<< SendUpdateFrame(aFrameMetrics
);
597 TabParent::UIResolutionChanged()
600 // TryCacheDPIAndScale()'s cache is keyed off of
601 // mDPI being greater than 0, so this invalidates it.
603 unused
<< SendUIResolutionChanged();
608 TabParent::AcknowledgeScrollUpdate(const ViewID
& aScrollId
, const uint32_t& aScrollGeneration
)
611 unused
<< SendAcknowledgeScrollUpdate(aScrollId
, aScrollGeneration
);
615 void TabParent::HandleDoubleTap(const CSSPoint
& aPoint
,
617 const ScrollableLayerGuid
&aGuid
)
620 unused
<< SendHandleDoubleTap(aPoint
, aGuid
);
624 void TabParent::HandleSingleTap(const CSSPoint
& aPoint
,
626 const ScrollableLayerGuid
&aGuid
)
628 // TODO Send the modifier data to TabChild for use in mouse events.
630 unused
<< SendHandleSingleTap(aPoint
, aGuid
);
634 void TabParent::HandleLongTap(const CSSPoint
& aPoint
,
636 const ScrollableLayerGuid
&aGuid
)
639 unused
<< SendHandleLongTap(aPoint
, aGuid
);
643 void TabParent::HandleLongTapUp(const CSSPoint
& aPoint
,
645 const ScrollableLayerGuid
&aGuid
)
648 unused
<< SendHandleLongTapUp(aPoint
, aGuid
);
652 void TabParent::NotifyAPZStateChange(ViewID aViewId
,
653 APZStateChange aChange
,
657 unused
<< SendNotifyAPZStateChange(aViewId
, aChange
, aArg
);
662 TabParent::Activate()
665 unused
<< SendActivate();
670 TabParent::Deactivate()
673 unused
<< SendDeactivate();
678 TabParent::Init(nsIDOMWindow
*window
)
684 TabParent::GetState(uint32_t *aState
)
686 NS_ENSURE_ARG(aState
);
687 NS_WARNING("SecurityState not valid here");
693 TabParent::SetDocShell(nsIDocShell
*aDocShell
)
695 NS_ENSURE_ARG(aDocShell
);
696 NS_WARNING("No mDocShell member in TabParent so there is no docShell to set");
700 PDocumentRendererParent
*
701 TabParent::AllocPDocumentRendererParent(const nsRect
& documentRect
,
702 const gfx::Matrix
& transform
,
703 const nsString
& bgcolor
,
704 const uint32_t& renderFlags
,
705 const bool& flushLayout
,
706 const nsIntSize
& renderSize
)
708 return new DocumentRendererParent();
712 TabParent::DeallocPDocumentRendererParent(PDocumentRendererParent
* actor
)
718 PContentPermissionRequestParent
*
719 TabParent::AllocPContentPermissionRequestParent(const InfallibleTArray
<PermissionRequest
>& aRequests
,
720 const IPC::Principal
& aPrincipal
)
722 return nsContentPermissionUtils::CreateContentPermissionRequestParent(aRequests
, mFrameElement
, aPrincipal
);
726 TabParent::DeallocPContentPermissionRequestParent(PContentPermissionRequestParent
* actor
)
733 TabParent::AllocPFilePickerParent(const nsString
& aTitle
, const int16_t& aMode
)
735 return new FilePickerParent(aTitle
, aMode
);
739 TabParent::DeallocPFilePickerParent(PFilePickerParent
* actor
)
746 TabParent::SendMouseEvent(const nsAString
& aType
, float aX
, float aY
,
747 int32_t aButton
, int32_t aClickCount
,
748 int32_t aModifiers
, bool aIgnoreRootScrollFrame
)
751 unused
<< PBrowserParent::SendMouseEvent(nsString(aType
), aX
, aY
,
752 aButton
, aClickCount
,
753 aModifiers
, aIgnoreRootScrollFrame
);
758 TabParent::SendKeyEvent(const nsAString
& aType
,
762 bool aPreventDefault
)
765 unused
<< PBrowserParent::SendKeyEvent(nsString(aType
), aKeyCode
, aCharCode
,
766 aModifiers
, aPreventDefault
);
771 TabParent::MapEventCoordinatesForChildProcess(WidgetEvent
* aEvent
)
773 nsRefPtr
<nsFrameLoader
> frameLoader
= GetFrameLoader();
777 LayoutDeviceIntPoint offset
=
778 EventStateManager::GetChildProcessOffset(frameLoader
, *aEvent
);
779 MapEventCoordinatesForChildProcess(offset
, aEvent
);
784 TabParent::MapEventCoordinatesForChildProcess(
785 const LayoutDeviceIntPoint
& aOffset
, WidgetEvent
* aEvent
)
787 if (aEvent
->mClass
!= eTouchEventClass
) {
788 aEvent
->refPoint
= aOffset
;
790 aEvent
->refPoint
= LayoutDeviceIntPoint();
791 // Then offset all the touch points by that distance, to put them
792 // in the space where top-left is 0,0.
793 const WidgetTouchEvent::TouchArray
& touches
=
794 aEvent
->AsTouchEvent()->touches
;
795 for (uint32_t i
= 0; i
< touches
.Length(); ++i
) {
796 Touch
* touch
= touches
[i
];
798 touch
->mRefPoint
+= LayoutDeviceIntPoint::ToUntyped(aOffset
);
804 bool TabParent::SendRealMouseEvent(WidgetMouseEvent
& event
)
809 nsEventStatus status
= MaybeForwardEventToRenderFrame(event
, nullptr);
810 if (status
== nsEventStatus_eConsumeNoDefault
||
811 !MapEventCoordinatesForChildProcess(&event
)) {
814 return PBrowserParent::SendRealMouseEvent(event
);
817 CSSPoint
TabParent::AdjustTapToChildWidget(const CSSPoint
& aPoint
)
819 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mFrameElement
);
821 if (!content
|| !content
->OwnerDoc()) {
825 nsIDocument
* doc
= content
->OwnerDoc();
826 if (!doc
|| !doc
->GetShell()) {
829 nsPresContext
* presContext
= doc
->GetShell()->GetPresContext();
831 return aPoint
+ CSSPoint(
832 presContext
->DevPixelsToFloatCSSPixels(mChildProcessOffsetAtTouchStart
.x
),
833 presContext
->DevPixelsToFloatCSSPixels(mChildProcessOffsetAtTouchStart
.y
));
836 bool TabParent::SendHandleSingleTap(const CSSPoint
& aPoint
, const ScrollableLayerGuid
& aGuid
)
842 return PBrowserParent::SendHandleSingleTap(AdjustTapToChildWidget(aPoint
), aGuid
);
845 bool TabParent::SendHandleLongTap(const CSSPoint
& aPoint
, const ScrollableLayerGuid
& aGuid
)
851 return PBrowserParent::SendHandleLongTap(AdjustTapToChildWidget(aPoint
), aGuid
);
854 bool TabParent::SendHandleLongTapUp(const CSSPoint
& aPoint
, const ScrollableLayerGuid
& aGuid
)
860 return PBrowserParent::SendHandleLongTapUp(AdjustTapToChildWidget(aPoint
), aGuid
);
863 bool TabParent::SendHandleDoubleTap(const CSSPoint
& aPoint
, const ScrollableLayerGuid
& aGuid
)
869 return PBrowserParent::SendHandleDoubleTap(AdjustTapToChildWidget(aPoint
), aGuid
);
872 bool TabParent::SendMouseWheelEvent(WidgetWheelEvent
& event
)
877 nsEventStatus status
= MaybeForwardEventToRenderFrame(event
, nullptr);
878 if (status
== nsEventStatus_eConsumeNoDefault
||
879 !MapEventCoordinatesForChildProcess(&event
)) {
882 return PBrowserParent::SendMouseWheelEvent(event
);
886 DoCommandCallback(mozilla::Command aCommand
, void* aData
)
888 static_cast<InfallibleTArray
<mozilla::CommandInt
>*>(aData
)->AppendElement(aCommand
);
892 TabParent::RecvRequestNativeKeyBindings(const WidgetKeyboardEvent
& aEvent
,
893 MaybeNativeKeyBinding
* aBindings
)
895 AutoInfallibleTArray
<mozilla::CommandInt
, 4> singleLine
;
896 AutoInfallibleTArray
<mozilla::CommandInt
, 4> multiLine
;
897 AutoInfallibleTArray
<mozilla::CommandInt
, 4> richText
;
899 *aBindings
= mozilla::void_t();
901 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
906 WidgetKeyboardEvent
localEvent(aEvent
);
908 if (NS_FAILED(widget
->AttachNativeKeyEvent(localEvent
))) {
912 widget
->ExecuteNativeKeyBinding(nsIWidget::NativeKeyBindingsForSingleLineEditor
,
913 localEvent
, DoCommandCallback
, &singleLine
);
914 widget
->ExecuteNativeKeyBinding(nsIWidget::NativeKeyBindingsForMultiLineEditor
,
915 localEvent
, DoCommandCallback
, &multiLine
);
916 widget
->ExecuteNativeKeyBinding(nsIWidget::NativeKeyBindingsForRichTextEditor
,
917 localEvent
, DoCommandCallback
, &richText
);
919 if (!singleLine
.IsEmpty() || !multiLine
.IsEmpty() || !richText
.IsEmpty()) {
920 *aBindings
= NativeKeyBinding(singleLine
, multiLine
, richText
);
926 bool TabParent::SendRealKeyEvent(WidgetKeyboardEvent
& event
)
931 MaybeForwardEventToRenderFrame(event
, nullptr);
932 if (!MapEventCoordinatesForChildProcess(&event
)) {
937 MaybeNativeKeyBinding bindings
;
939 if (event
.message
== NS_KEY_PRESS
) {
940 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
942 AutoInfallibleTArray
<mozilla::CommandInt
, 4> singleLine
;
943 AutoInfallibleTArray
<mozilla::CommandInt
, 4> multiLine
;
944 AutoInfallibleTArray
<mozilla::CommandInt
, 4> richText
;
946 widget
->ExecuteNativeKeyBinding(nsIWidget::NativeKeyBindingsForSingleLineEditor
,
947 event
, DoCommandCallback
, &singleLine
);
948 widget
->ExecuteNativeKeyBinding(nsIWidget::NativeKeyBindingsForMultiLineEditor
,
949 event
, DoCommandCallback
, &multiLine
);
950 widget
->ExecuteNativeKeyBinding(nsIWidget::NativeKeyBindingsForRichTextEditor
,
951 event
, DoCommandCallback
, &richText
);
953 if (!singleLine
.IsEmpty() || !multiLine
.IsEmpty() || !richText
.IsEmpty()) {
954 bindings
= NativeKeyBinding(singleLine
, multiLine
, richText
);
958 return PBrowserParent::SendRealKeyEvent(event
, bindings
);
961 bool TabParent::SendRealTouchEvent(WidgetTouchEvent
& event
)
966 if (event
.message
== NS_TOUCH_START
) {
967 // Adjust the widget coordinates to be relative to our frame.
968 nsRefPtr
<nsFrameLoader
> frameLoader
= GetFrameLoader();
971 sEventCapturer
= nullptr;
975 mChildProcessOffsetAtTouchStart
=
976 EventStateManager::GetChildProcessOffset(frameLoader
, event
);
978 MOZ_ASSERT((!sEventCapturer
&& mEventCaptureDepth
== 0) ||
979 (sEventCapturer
== this && mEventCaptureDepth
> 0));
980 // We want to capture all remaining touch events in this series
981 // for fast-path dispatch.
982 sEventCapturer
= this;
983 ++mEventCaptureDepth
;
986 // PresShell::HandleEventInternal adds touches on touch end/cancel. This
987 // confuses remote content and the panning and zooming logic into thinking
988 // that the added touches are part of the touchend/cancel, when actually
990 if (event
.message
== NS_TOUCH_END
|| event
.message
== NS_TOUCH_CANCEL
) {
991 for (int i
= event
.touches
.Length() - 1; i
>= 0; i
--) {
992 if (!event
.touches
[i
]->mChanged
) {
993 event
.touches
.RemoveElementAt(i
);
998 ScrollableLayerGuid guid
;
999 nsEventStatus status
= MaybeForwardEventToRenderFrame(event
, &guid
);
1001 if (status
== nsEventStatus_eConsumeNoDefault
|| mIsDestroyed
) {
1005 MapEventCoordinatesForChildProcess(mChildProcessOffsetAtTouchStart
, &event
);
1007 return (event
.message
== NS_TOUCH_MOVE
) ?
1008 PBrowserParent::SendRealTouchMoveEvent(event
, guid
) :
1009 PBrowserParent::SendRealTouchEvent(event
, guid
);
1012 /*static*/ TabParent
*
1013 TabParent::GetEventCapturer()
1015 return sEventCapturer
;
1019 TabParent::TryCapture(const WidgetGUIEvent
& aEvent
)
1021 MOZ_ASSERT(sEventCapturer
== this && mEventCaptureDepth
> 0);
1023 if (aEvent
.mClass
!= eTouchEventClass
) {
1024 // Only capture of touch events is implemented, for now.
1028 WidgetTouchEvent
event(*aEvent
.AsTouchEvent());
1030 bool isTouchPointUp
= (event
.message
== NS_TOUCH_END
||
1031 event
.message
== NS_TOUCH_CANCEL
);
1032 if (event
.message
== NS_TOUCH_START
|| isTouchPointUp
) {
1033 // Let the DOM see touch start/end events so that its touch-point
1034 // state stays consistent.
1035 if (isTouchPointUp
&& 0 == --mEventCaptureDepth
) {
1036 // All event series are un-captured, don't try to catch any
1038 sEventCapturer
= nullptr;
1043 SendRealTouchEvent(event
);
1048 TabParent::RecvSyncMessage(const nsString
& aMessage
,
1049 const ClonedMessageData
& aData
,
1050 const InfallibleTArray
<CpowEntry
>& aCpows
,
1051 const IPC::Principal
& aPrincipal
,
1052 InfallibleTArray
<nsString
>* aJSONRetVal
)
1054 // FIXME Permission check for TabParent in Content process
1055 nsIPrincipal
* principal
= aPrincipal
;
1056 if (Manager()->IsContentParent()) {
1057 ContentParent
* parent
= Manager()->AsContentParent();
1058 if (!ContentParent::IgnoreIPCPrincipal() &&
1059 parent
&& principal
&& !AssertAppPrincipal(parent
, principal
)) {
1064 StructuredCloneData cloneData
= ipc::UnpackClonedMessageDataForParent(aData
);
1065 CpowIdHolder
cpows(Manager()->GetCPOWManager(), aCpows
);
1066 return ReceiveMessage(aMessage
, true, &cloneData
, &cpows
, aPrincipal
, aJSONRetVal
);
1070 TabParent::AnswerRpcMessage(const nsString
& aMessage
,
1071 const ClonedMessageData
& aData
,
1072 const InfallibleTArray
<CpowEntry
>& aCpows
,
1073 const IPC::Principal
& aPrincipal
,
1074 InfallibleTArray
<nsString
>* aJSONRetVal
)
1076 // FIXME Permission check for TabParent in Content process
1077 nsIPrincipal
* principal
= aPrincipal
;
1078 if (Manager()->IsContentParent()) {
1079 ContentParent
* parent
= Manager()->AsContentParent();
1080 if (!ContentParent::IgnoreIPCPrincipal() &&
1081 parent
&& principal
&& !AssertAppPrincipal(parent
, principal
)) {
1086 StructuredCloneData cloneData
= ipc::UnpackClonedMessageDataForParent(aData
);
1087 CpowIdHolder
cpows(Manager()->GetCPOWManager(), aCpows
);
1088 return ReceiveMessage(aMessage
, true, &cloneData
, &cpows
, aPrincipal
, aJSONRetVal
);
1092 TabParent::RecvAsyncMessage(const nsString
& aMessage
,
1093 const ClonedMessageData
& aData
,
1094 const InfallibleTArray
<CpowEntry
>& aCpows
,
1095 const IPC::Principal
& aPrincipal
)
1097 // FIXME Permission check for TabParent in Content process
1098 nsIPrincipal
* principal
= aPrincipal
;
1099 if (Manager()->IsContentParent()) {
1100 ContentParent
* parent
= Manager()->AsContentParent();
1101 if (!ContentParent::IgnoreIPCPrincipal() &&
1102 parent
&& principal
&& !AssertAppPrincipal(parent
, principal
)) {
1107 StructuredCloneData cloneData
= ipc::UnpackClonedMessageDataForParent(aData
);
1108 CpowIdHolder
cpows(Manager()->GetCPOWManager(), aCpows
);
1109 return ReceiveMessage(aMessage
, false, &cloneData
, &cpows
, aPrincipal
, nullptr);
1113 TabParent::RecvSetCursor(const uint32_t& aCursor
, const bool& aForce
)
1115 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1118 widget
->ClearCachedCursor();
1120 widget
->SetCursor((nsCursor
) aCursor
);
1126 TabParent::RecvSetBackgroundColor(const nscolor
& aColor
)
1128 if (RenderFrameParent
* frame
= GetRenderFrame()) {
1129 frame
->SetBackgroundColor(aColor
);
1134 nsIXULBrowserWindow
*
1135 TabParent::GetXULBrowserWindow()
1137 nsCOMPtr
<nsIContent
> frame
= do_QueryInterface(mFrameElement
);
1142 nsCOMPtr
<nsIDocShell
> docShell
= frame
->OwnerDoc()->GetDocShell();
1147 nsCOMPtr
<nsIDocShellTreeOwner
> treeOwner
;
1148 docShell
->GetTreeOwner(getter_AddRefs(treeOwner
));
1153 nsCOMPtr
<nsIXULWindow
> window
= do_GetInterface(treeOwner
);
1158 nsCOMPtr
<nsIXULBrowserWindow
> xulBrowserWindow
;
1159 window
->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow
));
1160 return xulBrowserWindow
;
1164 TabParent::RecvSetStatus(const uint32_t& aType
, const nsString
& aStatus
)
1166 nsCOMPtr
<nsIXULBrowserWindow
> xulBrowserWindow
= GetXULBrowserWindow();
1167 if (!xulBrowserWindow
) {
1172 case nsIWebBrowserChrome::STATUS_SCRIPT
:
1173 xulBrowserWindow
->SetJSStatus(aStatus
);
1175 case nsIWebBrowserChrome::STATUS_LINK
:
1176 xulBrowserWindow
->SetOverLink(aStatus
, nullptr);
1183 TabParent::RecvShowTooltip(const uint32_t& aX
, const uint32_t& aY
, const nsString
& aTooltip
)
1185 nsCOMPtr
<nsIXULBrowserWindow
> xulBrowserWindow
= GetXULBrowserWindow();
1186 if (!xulBrowserWindow
) {
1190 xulBrowserWindow
->ShowTooltip(aX
, aY
, aTooltip
);
1195 TabParent::RecvHideTooltip()
1197 nsCOMPtr
<nsIXULBrowserWindow
> xulBrowserWindow
= GetXULBrowserWindow();
1198 if (!xulBrowserWindow
) {
1202 xulBrowserWindow
->HideTooltip();
1207 TabParent::RecvNotifyIMEFocus(const bool& aFocus
,
1208 nsIMEUpdatePreference
* aPreference
,
1211 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1213 *aPreference
= nsIMEUpdatePreference();
1217 *aSeqno
= mIMESeqno
;
1218 mIMETabParent
= aFocus
? this : nullptr;
1219 mIMESelectionAnchor
= 0;
1220 mIMESelectionFocus
= 0;
1221 widget
->NotifyIME(IMENotification(aFocus
? NOTIFY_IME_OF_FOCUS
:
1222 NOTIFY_IME_OF_BLUR
));
1225 *aPreference
= widget
->GetIMEUpdatePreference();
1227 mIMECacheText
.Truncate(0);
1233 TabParent::RecvNotifyIMETextChange(const uint32_t& aStart
,
1234 const uint32_t& aEnd
,
1235 const uint32_t& aNewEnd
,
1236 const bool& aCausedByComposition
)
1238 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1243 nsIMEUpdatePreference updatePreference
= widget
->GetIMEUpdatePreference();
1244 NS_ASSERTION(updatePreference
.WantTextChange(),
1245 "Don't call Send/RecvNotifyIMETextChange without NOTIFY_TEXT_CHANGE");
1246 MOZ_ASSERT(!aCausedByComposition
||
1247 updatePreference
.WantChangesCausedByComposition(),
1248 "The widget doesn't want text change notification caused by composition");
1251 IMENotification
notification(NOTIFY_IME_OF_TEXT_CHANGE
);
1252 notification
.mTextChangeData
.mStartOffset
= aStart
;
1253 notification
.mTextChangeData
.mOldEndOffset
= aEnd
;
1254 notification
.mTextChangeData
.mNewEndOffset
= aNewEnd
;
1255 notification
.mTextChangeData
.mCausedByComposition
= aCausedByComposition
;
1256 widget
->NotifyIME(notification
);
1261 TabParent::RecvNotifyIMESelectedCompositionRect(const uint32_t& aOffset
,
1262 const nsIntRect
& aRect
,
1263 const nsIntRect
& aCaretRect
)
1265 // add rect to cache for another query
1266 mIMECompositionRectOffset
= aOffset
;
1267 mIMECompositionRect
= aRect
;
1268 mIMECaretRect
= aCaretRect
;
1270 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1274 widget
->NotifyIME(IMENotification(NOTIFY_IME_OF_COMPOSITION_UPDATE
));
1279 TabParent::RecvNotifyIMESelection(const uint32_t& aSeqno
,
1280 const uint32_t& aAnchor
,
1281 const uint32_t& aFocus
,
1282 const bool& aCausedByComposition
)
1284 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1288 if (aSeqno
== mIMESeqno
) {
1289 mIMESelectionAnchor
= aAnchor
;
1290 mIMESelectionFocus
= aFocus
;
1291 const nsIMEUpdatePreference updatePreference
=
1292 widget
->GetIMEUpdatePreference();
1293 if (updatePreference
.WantSelectionChange() &&
1294 (updatePreference
.WantChangesCausedByComposition() ||
1295 !aCausedByComposition
)) {
1296 IMENotification
notification(NOTIFY_IME_OF_SELECTION_CHANGE
);
1297 notification
.mSelectionChangeData
.mCausedByComposition
=
1298 aCausedByComposition
;
1299 widget
->NotifyIME(notification
);
1306 TabParent::RecvNotifyIMETextHint(const nsString
& aText
)
1308 // Replace our cache with new text
1309 mIMECacheText
= aText
;
1314 TabParent::RecvRequestFocus(const bool& aCanRaise
)
1316 nsCOMPtr
<nsIFocusManager
> fm
= nsFocusManager::GetFocusManager();
1321 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mFrameElement
);
1322 if (!content
|| !content
->OwnerDoc()) {
1326 uint32_t flags
= nsIFocusManager::FLAG_NOSCROLL
;
1328 flags
|= nsIFocusManager::FLAG_RAISE
;
1330 nsCOMPtr
<nsIDOMElement
> node
= do_QueryInterface(mFrameElement
);
1331 fm
->SetFocus(node
, flags
);
1336 TabParent::GetChildProcessOffset()
1338 // The "toplevel widget" in child processes is always at position
1339 // 0,0. Map the event coordinates to match that.
1341 nsIntPoint
offset(0, 0);
1342 nsRefPtr
<nsFrameLoader
> frameLoader
= GetFrameLoader();
1346 nsIFrame
* targetFrame
= frameLoader
->GetPrimaryFrameOfOwningContent();
1351 // Find out how far we're offset from the nearest widget.
1352 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1356 nsPoint pt
= nsLayoutUtils::GetEventCoordinatesRelativeTo(widget
,
1360 return LayoutDeviceIntPoint::ToUntyped(LayoutDeviceIntPoint::FromAppUnitsToNearest(
1361 pt
, targetFrame
->PresContext()->AppUnitsPerDevPixel()));
1365 TabParent::RecvReplyKeyEvent(const WidgetKeyboardEvent
& event
)
1367 NS_ENSURE_TRUE(mFrameElement
, true);
1369 WidgetKeyboardEvent
localEvent(event
);
1370 // Set mNoCrossProcessBoundaryForwarding to avoid this event from
1371 // being infinitely redispatched and forwarded to the child again.
1372 localEvent
.mFlags
.mNoCrossProcessBoundaryForwarding
= true;
1374 // Here we convert the WidgetEvent that we received to an nsIDOMEvent
1375 // to be able to dispatch it to the <browser> element as the target element.
1376 nsIDocument
* doc
= mFrameElement
->OwnerDoc();
1377 nsIPresShell
* presShell
= doc
->GetShell();
1378 NS_ENSURE_TRUE(presShell
, true);
1379 nsPresContext
* presContext
= presShell
->GetPresContext();
1380 NS_ENSURE_TRUE(presContext
, true);
1382 EventDispatcher::Dispatch(mFrameElement
, presContext
, &localEvent
);
1387 * Try to answer query event using cached text.
1389 * For NS_QUERY_SELECTED_TEXT, fail if the cache doesn't contain the whole
1390 * selected range. (This shouldn't happen because PuppetWidget should have
1391 * already sent the whole selection.)
1393 * For NS_QUERY_TEXT_CONTENT, fail only if the cache doesn't overlap with
1394 * the queried range. Note the difference from above. We use
1395 * this behavior because a normal NS_QUERY_TEXT_CONTENT event is allowed to
1396 * have out-of-bounds offsets, so that widget can request content without
1397 * knowing the exact length of text. It's up to widget to handle cases when
1398 * the returned offset/length are different from the queried offset/length.
1400 * For NS_QUERY_TEXT_RECT, fail if cached offset/length aren't equals to input.
1401 * Cocoa widget always queries selected offset, so it works on it.
1403 * For NS_QUERY_CARET_RECT, fail if cached offset isn't equals to input
1406 TabParent::HandleQueryContentEvent(WidgetQueryContentEvent
& aEvent
)
1408 aEvent
.mSucceeded
= false;
1409 aEvent
.mWasAsync
= false;
1410 aEvent
.mReply
.mFocusedWidget
= nsCOMPtr
<nsIWidget
>(GetWidget()).get();
1412 switch (aEvent
.message
)
1414 case NS_QUERY_SELECTED_TEXT
:
1416 aEvent
.mReply
.mOffset
= std::min(mIMESelectionAnchor
, mIMESelectionFocus
);
1417 if (mIMESelectionAnchor
== mIMESelectionFocus
) {
1418 aEvent
.mReply
.mString
.Truncate(0);
1420 if (mIMESelectionAnchor
> mIMECacheText
.Length() ||
1421 mIMESelectionFocus
> mIMECacheText
.Length()) {
1424 uint32_t selLen
= mIMESelectionAnchor
> mIMESelectionFocus
?
1425 mIMESelectionAnchor
- mIMESelectionFocus
:
1426 mIMESelectionFocus
- mIMESelectionAnchor
;
1427 aEvent
.mReply
.mString
= Substring(mIMECacheText
,
1428 aEvent
.mReply
.mOffset
,
1431 aEvent
.mReply
.mReversed
= mIMESelectionFocus
< mIMESelectionAnchor
;
1432 aEvent
.mReply
.mHasSelection
= true;
1433 aEvent
.mSucceeded
= true;
1436 case NS_QUERY_TEXT_CONTENT
:
1438 uint32_t inputOffset
= aEvent
.mInput
.mOffset
,
1439 inputEnd
= inputOffset
+ aEvent
.mInput
.mLength
;
1441 if (inputEnd
> mIMECacheText
.Length()) {
1442 inputEnd
= mIMECacheText
.Length();
1444 if (inputEnd
< inputOffset
) {
1447 aEvent
.mReply
.mOffset
= inputOffset
;
1448 aEvent
.mReply
.mString
= Substring(mIMECacheText
,
1450 inputEnd
- inputOffset
);
1451 aEvent
.mSucceeded
= true;
1454 case NS_QUERY_TEXT_RECT
:
1456 if (aEvent
.mInput
.mOffset
!= mIMECompositionRectOffset
||
1457 aEvent
.mInput
.mLength
!= 1) {
1461 aEvent
.mReply
.mOffset
= mIMECompositionRectOffset
;
1462 aEvent
.mReply
.mRect
= mIMECompositionRect
- GetChildProcessOffset();
1463 aEvent
.mSucceeded
= true;
1466 case NS_QUERY_CARET_RECT
:
1468 if (aEvent
.mInput
.mOffset
!= mIMECompositionRectOffset
) {
1472 aEvent
.mReply
.mOffset
= mIMECompositionRectOffset
;
1473 aEvent
.mReply
.mRect
= mIMECaretRect
- GetChildProcessOffset();
1474 aEvent
.mSucceeded
= true;
1482 TabParent::SendCompositionEvent(WidgetCompositionEvent
& event
)
1487 mIMEComposing
= event
.message
!= NS_COMPOSITION_END
;
1488 mIMECompositionStart
= std::min(mIMESelectionAnchor
, mIMESelectionFocus
);
1489 if (mIMECompositionEnding
)
1491 event
.mSeqno
= ++mIMESeqno
;
1492 return PBrowserParent::SendCompositionEvent(event
);
1496 * During REQUEST_TO_COMMIT_COMPOSITION or REQUEST_TO_CANCEL_COMPOSITION,
1497 * widget usually sends a NS_TEXT_TEXT event to finalize or clear the
1498 * composition, respectively
1500 * Because the event will not reach content in time, we intercept it
1501 * here and pass the text as the EndIMEComposition return value
1504 TabParent::SendTextEvent(WidgetTextEvent
& event
)
1509 if (mIMECompositionEnding
) {
1510 mIMECompositionText
= event
.theText
;
1514 // We must be able to simulate the selection because
1515 // we might not receive selection updates in time
1516 if (!mIMEComposing
) {
1517 mIMECompositionStart
= std::min(mIMESelectionAnchor
, mIMESelectionFocus
);
1519 mIMESelectionAnchor
= mIMESelectionFocus
=
1520 mIMECompositionStart
+ event
.theText
.Length();
1522 event
.mSeqno
= ++mIMESeqno
;
1523 return PBrowserParent::SendTextEvent(event
);
1527 TabParent::SendSelectionEvent(WidgetSelectionEvent
& event
)
1532 mIMESelectionAnchor
= event
.mOffset
+ (event
.mReversed
? event
.mLength
: 0);
1533 mIMESelectionFocus
= event
.mOffset
+ (!event
.mReversed
? event
.mLength
: 0);
1534 event
.mSeqno
= ++mIMESeqno
;
1535 return PBrowserParent::SendSelectionEvent(event
);
1538 /*static*/ TabParent
*
1539 TabParent::GetFrom(nsFrameLoader
* aFrameLoader
)
1541 if (!aFrameLoader
) {
1544 PBrowserParent
* remoteBrowser
= aFrameLoader
->GetRemoteBrowser();
1545 return static_cast<TabParent
*>(remoteBrowser
);
1548 /*static*/ TabParent
*
1549 TabParent::GetFrom(nsIContent
* aContent
)
1551 nsCOMPtr
<nsIFrameLoaderOwner
> loaderOwner
= do_QueryInterface(aContent
);
1555 nsRefPtr
<nsFrameLoader
> frameLoader
= loaderOwner
->GetFrameLoader();
1556 return GetFrom(frameLoader
);
1560 TabParent::GetRenderFrame()
1562 if (ManagedPRenderFrameParent().IsEmpty()) {
1565 return static_cast<RenderFrameParent
*>(ManagedPRenderFrameParent()[0]);
1569 TabParent::RecvEndIMEComposition(const bool& aCancel
,
1570 nsString
* aComposition
)
1572 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1576 mIMECompositionEnding
= true;
1578 widget
->NotifyIME(IMENotification(aCancel
? REQUEST_TO_CANCEL_COMPOSITION
:
1579 REQUEST_TO_COMMIT_COMPOSITION
));
1581 mIMECompositionEnding
= false;
1582 *aComposition
= mIMECompositionText
;
1583 mIMECompositionText
.Truncate(0);
1588 TabParent::RecvGetInputContext(int32_t* aIMEEnabled
,
1590 intptr_t* aNativeIMEContext
)
1592 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1594 *aIMEEnabled
= IMEState::DISABLED
;
1595 *aIMEOpen
= IMEState::OPEN_STATE_NOT_SUPPORTED
;
1596 *aNativeIMEContext
= 0;
1600 InputContext context
= widget
->GetInputContext();
1601 *aIMEEnabled
= static_cast<int32_t>(context
.mIMEState
.mEnabled
);
1602 *aIMEOpen
= static_cast<int32_t>(context
.mIMEState
.mOpen
);
1603 *aNativeIMEContext
= reinterpret_cast<intptr_t>(context
.mNativeIMEContext
);
1608 TabParent::RecvSetInputContext(const int32_t& aIMEEnabled
,
1609 const int32_t& aIMEOpen
,
1610 const nsString
& aType
,
1611 const nsString
& aInputmode
,
1612 const nsString
& aActionHint
,
1613 const int32_t& aCause
,
1614 const int32_t& aFocusChange
)
1616 // mIMETabParent (which is actually static) tracks which if any TabParent has IMEFocus
1617 // When the input mode is set to anything but IMEState::DISABLED,
1618 // mIMETabParent should be set to this
1620 aIMEEnabled
!= static_cast<int32_t>(IMEState::DISABLED
) ? this : nullptr;
1621 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1622 if (!widget
|| !AllowContentIME())
1625 InputContext context
;
1626 context
.mIMEState
.mEnabled
= static_cast<IMEState::Enabled
>(aIMEEnabled
);
1627 context
.mIMEState
.mOpen
= static_cast<IMEState::Open
>(aIMEOpen
);
1628 context
.mHTMLInputType
.Assign(aType
);
1629 context
.mHTMLInputInputmode
.Assign(aInputmode
);
1630 context
.mActionHint
.Assign(aActionHint
);
1631 InputContextAction
action(
1632 static_cast<InputContextAction::Cause
>(aCause
),
1633 static_cast<InputContextAction::FocusChange
>(aFocusChange
));
1634 widget
->SetInputContext(context
, action
);
1636 nsCOMPtr
<nsIObserverService
> observerService
= mozilla::services::GetObserverService();
1637 if (!observerService
)
1641 state
.AppendInt(aIMEEnabled
);
1642 observerService
->NotifyObservers(nullptr, "ime-enabled-state-changed", state
.get());
1648 TabParent::RecvIsParentWindowMainWidgetVisible(bool* aIsVisible
)
1650 nsCOMPtr
<nsIContent
> frame
= do_QueryInterface(mFrameElement
);
1653 nsCOMPtr
<nsIDOMWindowUtils
> windowUtils
=
1654 do_QueryInterface(frame
->OwnerDoc()->GetWindow());
1655 nsresult rv
= windowUtils
->GetIsParentWindowMainWidgetVisible(aIsVisible
);
1656 return NS_SUCCEEDED(rv
);
1660 TabParent::RecvGetDPI(float* aValue
)
1662 TryCacheDPIAndScale();
1664 NS_ABORT_IF_FALSE(mDPI
> 0,
1665 "Must not ask for DPI before OwnerElement is received!");
1671 TabParent::RecvGetDefaultScale(double* aValue
)
1673 TryCacheDPIAndScale();
1675 NS_ABORT_IF_FALSE(mDefaultScale
.scale
> 0,
1676 "Must not ask for scale before OwnerElement is received!");
1677 *aValue
= mDefaultScale
.scale
;
1682 TabParent::RecvGetWidgetNativeData(WindowsHandle
* aValue
)
1684 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mFrameElement
);
1686 nsIPresShell
* shell
= content
->OwnerDoc()->GetShell();
1688 nsViewManager
* vm
= shell
->GetViewManager();
1689 nsCOMPtr
<nsIWidget
> widget
;
1690 vm
->GetRootWidget(getter_AddRefs(widget
));
1692 *aValue
= reinterpret_cast<WindowsHandle
>(
1693 widget
->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW
));
1702 TabParent::ReceiveMessage(const nsString
& aMessage
,
1704 const StructuredCloneData
* aCloneData
,
1706 nsIPrincipal
* aPrincipal
,
1707 InfallibleTArray
<nsString
>* aJSONRetVal
)
1709 nsRefPtr
<nsFrameLoader
> frameLoader
= GetFrameLoader();
1710 if (frameLoader
&& frameLoader
->GetFrameMessageManager()) {
1711 nsRefPtr
<nsFrameMessageManager
> manager
=
1712 frameLoader
->GetFrameMessageManager();
1714 manager
->ReceiveMessage(mFrameElement
,
1726 TabParent::AllocPIndexedDBParent(
1727 const nsCString
& aGroup
,
1728 const nsCString
& aASCIIOrigin
, bool* /* aAllowed */)
1730 return new IndexedDBParent(this);
1734 TabParent::DeallocPIndexedDBParent(PIndexedDBParent
* aActor
)
1741 TabParent::RecvPIndexedDBConstructor(PIndexedDBParent
* aActor
,
1742 const nsCString
& aGroup
,
1743 const nsCString
& aASCIIOrigin
,
1746 nsRefPtr
<IndexedDatabaseManager
> mgr
= IndexedDatabaseManager::GetOrCreate();
1747 NS_ENSURE_TRUE(mgr
, false);
1749 if (!IndexedDatabaseManager::IsMainProcess()) {
1750 NS_RUNTIMEABORT("Not supported yet!");
1755 // XXXbent Need to make sure we have a whitelist for chrome databases!
1757 // Verify that the child is requesting to access a database it's allowed to
1758 // see. (aASCIIOrigin here specifies a TabContext + a website origin, and
1759 // we're checking that the TabContext may access it.)
1761 // We have to check IsBrowserOrApp() because TabContextMayAccessOrigin will
1762 // fail if we're not a browser-or-app, since aASCIIOrigin will be a plain URI,
1763 // but TabContextMayAccessOrigin will construct an extended origin using
1764 // app-id 0. Note that as written below, we allow a non browser-or-app child
1765 // to read any database. That's a security hole, but we don't ship a
1766 // configuration which creates non browser-or-app children, so it's not a big
1768 if (!aASCIIOrigin
.EqualsLiteral("chrome") && IsBrowserOrApp() &&
1769 !IndexedDatabaseManager::TabContextMayAccessOrigin(*this, aASCIIOrigin
)) {
1771 NS_WARNING("App attempted to open databases that it does not have "
1772 "permission to access!");
1776 nsCOMPtr
<nsINode
> node
= do_QueryInterface(GetOwnerElement());
1777 NS_ENSURE_TRUE(node
, false);
1779 nsIDocument
* doc
= node
->GetOwnerDocument();
1780 NS_ENSURE_TRUE(doc
, false);
1782 nsCOMPtr
<nsPIDOMWindow
> window
= doc
->GetInnerWindow();
1783 NS_ENSURE_TRUE(window
, false);
1785 // Let's do a current inner check to see if the inner is active or is in
1786 // bf cache, and bail out if it's not active.
1787 nsCOMPtr
<nsPIDOMWindow
> outer
= doc
->GetWindow();
1788 if (!outer
|| outer
->GetCurrentInnerWindow() != window
) {
1793 NS_ASSERTION(Manager(), "Null manager?!");
1795 nsRefPtr
<IDBFactory
> factory
;
1796 rv
= IDBFactory::Create(window
, aGroup
, aASCIIOrigin
, Manager(),
1797 getter_AddRefs(factory
));
1798 NS_ENSURE_SUCCESS(rv
, false);
1805 IndexedDBParent
* actor
= static_cast<IndexedDBParent
*>(aActor
);
1806 actor
->mFactory
= factory
;
1807 actor
->mASCIIOrigin
= aASCIIOrigin
;
1813 // nsIAuthPromptProvider
1815 // This method is largely copied from nsDocShell::GetAuthPrompt
1817 TabParent::GetAuthPrompt(uint32_t aPromptReason
, const nsIID
& iid
,
1820 // we're either allowing auth, or it's a proxy request
1822 nsCOMPtr
<nsIPromptFactory
> wwatch
=
1823 do_GetService(NS_WINDOWWATCHER_CONTRACTID
, &rv
);
1824 NS_ENSURE_SUCCESS(rv
, rv
);
1826 nsCOMPtr
<nsIDOMWindow
> window
;
1827 nsCOMPtr
<nsIContent
> frame
= do_QueryInterface(mFrameElement
);
1829 window
= do_QueryInterface(frame
->OwnerDoc()->GetWindow());
1831 // Get an auth prompter for our window so that the parenting
1832 // of the dialogs works as it should when using tabs.
1833 return wwatch
->GetPrompt(window
, iid
,
1834 reinterpret_cast<void**>(aResult
));
1838 TabParent::AllocPColorPickerParent(const nsString
& aTitle
,
1839 const nsString
& aInitialColor
)
1841 return new ColorPickerParent(aTitle
, aInitialColor
);
1845 TabParent::DeallocPColorPickerParent(PColorPickerParent
* actor
)
1852 TabParent::AllocPRenderFrameParent(ScrollingBehavior
* aScrolling
,
1853 TextureFactoryIdentifier
* aTextureFactoryIdentifier
,
1854 uint64_t* aLayersId
, bool* aSuccess
)
1856 MOZ_ASSERT(ManagedPRenderFrameParent().IsEmpty());
1858 nsRefPtr
<nsFrameLoader
> frameLoader
= GetFrameLoader();
1859 *aScrolling
= UseAsyncPanZoom() ? ASYNC_PAN_ZOOM
: DEFAULT_SCROLLING
;
1860 return new RenderFrameParent(frameLoader
,
1862 aTextureFactoryIdentifier
, aLayersId
,
1867 TabParent::DeallocPRenderFrameParent(PRenderFrameParent
* aFrame
)
1873 mozilla::docshell::POfflineCacheUpdateParent
*
1874 TabParent::AllocPOfflineCacheUpdateParent(const URIParams
& aManifestURI
,
1875 const URIParams
& aDocumentURI
,
1876 const bool& aStickDocument
)
1878 nsRefPtr
<mozilla::docshell::OfflineCacheUpdateParent
> update
=
1879 new mozilla::docshell::OfflineCacheUpdateParent(OwnOrContainingAppId(),
1880 IsBrowserElement());
1881 // Use this reference as the IPDL reference.
1882 return update
.forget().take();
1886 TabParent::RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent
* aActor
,
1887 const URIParams
& aManifestURI
,
1888 const URIParams
& aDocumentURI
,
1889 const bool& aStickDocument
)
1893 nsRefPtr
<mozilla::docshell::OfflineCacheUpdateParent
> update
=
1894 static_cast<mozilla::docshell::OfflineCacheUpdateParent
*>(aActor
);
1896 nsresult rv
= update
->Schedule(aManifestURI
, aDocumentURI
, aStickDocument
);
1897 if (NS_FAILED(rv
) && !IsDestroyed()) {
1898 // Inform the child of failure.
1899 unused
<< update
->SendFinish(false, false);
1906 TabParent::DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent
* aActor
)
1908 // Reclaim the IPDL reference.
1909 nsRefPtr
<mozilla::docshell::OfflineCacheUpdateParent
> update
=
1911 static_cast<mozilla::docshell::OfflineCacheUpdateParent
*>(aActor
));
1916 TabParent::RecvSetOfflinePermission(const IPC::Principal
& aPrincipal
)
1918 nsIPrincipal
* principal
= aPrincipal
;
1919 nsContentUtils::MaybeAllowOfflineAppByDefault(principal
, nullptr);
1924 TabParent::AllowContentIME()
1926 nsFocusManager
* fm
= nsFocusManager::GetFocusManager();
1927 NS_ENSURE_TRUE(fm
, false);
1929 nsCOMPtr
<nsIContent
> focusedContent
= fm
->GetFocusedContent();
1930 if (focusedContent
&& focusedContent
->IsEditable())
1936 already_AddRefed
<nsFrameLoader
>
1937 TabParent::GetFrameLoader() const
1939 nsCOMPtr
<nsIFrameLoaderOwner
> frameLoaderOwner
= do_QueryInterface(mFrameElement
);
1940 return frameLoaderOwner
? frameLoaderOwner
->GetFrameLoader() : nullptr;
1944 TabParent::TryCacheDPIAndScale()
1950 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
1952 if (!widget
&& mFrameElement
) {
1953 // Even if we don't have a widget (e.g. because we're display:none), there's
1954 // probably a widget somewhere in the hierarchy our frame element lives in.
1955 widget
= nsContentUtils::WidgetForDocument(mFrameElement
->OwnerDoc());
1959 mDPI
= widget
->GetDPI();
1960 mDefaultScale
= widget
->GetDefaultScale();
1964 already_AddRefed
<nsIWidget
>
1965 TabParent::GetWidget() const
1967 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mFrameElement
);
1971 nsIFrame
*frame
= content
->GetPrimaryFrame();
1975 nsCOMPtr
<nsIWidget
> widget
= frame
->GetNearestWidget();
1976 return widget
.forget();
1980 TabParent::UseAsyncPanZoom()
1982 bool usingOffMainThreadCompositing
= !!CompositorParent::CompositorLoop();
1983 return (usingOffMainThreadCompositing
&& gfxPrefs::AsyncPanZoomEnabled() &&
1984 GetScrollingBehavior() == ASYNC_PAN_ZOOM
);
1988 TabParent::MaybeForwardEventToRenderFrame(WidgetInputEvent
& aEvent
,
1989 ScrollableLayerGuid
* aOutTargetGuid
)
1991 if (RenderFrameParent
* rfp
= GetRenderFrame()) {
1992 return rfp
->NotifyInputEvent(aEvent
, aOutTargetGuid
);
1994 return nsEventStatus_eIgnore
;
1998 TabParent::RecvBrowserFrameOpenWindow(PBrowserParent
* aOpener
,
1999 const nsString
& aURL
,
2000 const nsString
& aName
,
2001 const nsString
& aFeatures
,
2002 bool* aOutWindowOpened
)
2004 BrowserElementParent::OpenWindowResult opened
=
2005 BrowserElementParent::OpenWindowOOP(static_cast<TabParent
*>(aOpener
),
2006 this, aURL
, aName
, aFeatures
);
2007 *aOutWindowOpened
= (opened
!= BrowserElementParent::OPEN_WINDOW_CANCELLED
);
2012 TabParent::RecvPRenderFrameConstructor(PRenderFrameParent
* aActor
,
2013 ScrollingBehavior
* aScrolling
,
2014 TextureFactoryIdentifier
* aFactoryIdentifier
,
2015 uint64_t* aLayersId
,
2022 TabParent::RecvZoomToRect(const uint32_t& aPresShellId
,
2023 const ViewID
& aViewId
,
2024 const CSSRect
& aRect
)
2026 if (RenderFrameParent
* rfp
= GetRenderFrame()) {
2027 rfp
->ZoomToRect(aPresShellId
, aViewId
, aRect
);
2033 TabParent::RecvUpdateZoomConstraints(const uint32_t& aPresShellId
,
2034 const ViewID
& aViewId
,
2035 const bool& aIsRoot
,
2036 const ZoomConstraints
& aConstraints
)
2038 if (RenderFrameParent
* rfp
= GetRenderFrame()) {
2039 rfp
->UpdateZoomConstraints(aPresShellId
, aViewId
, aIsRoot
, aConstraints
);
2045 TabParent::RecvContentReceivedTouch(const ScrollableLayerGuid
& aGuid
,
2046 const bool& aPreventDefault
)
2048 if (RenderFrameParent
* rfp
= GetRenderFrame()) {
2049 rfp
->ContentReceivedTouch(aGuid
, aPreventDefault
);
2054 already_AddRefed
<nsILoadContext
>
2055 TabParent::GetLoadContext()
2057 nsCOMPtr
<nsILoadContext
> loadContext
;
2059 loadContext
= mLoadContext
;
2061 loadContext
= new LoadContext(GetOwnerElement(),
2062 OwnOrContainingAppId(),
2063 true /* aIsContent */,
2064 mChromeFlags
& nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW
,
2065 mChromeFlags
& nsIWebBrowserChrome::CHROME_REMOTE_WINDOW
,
2066 IsBrowserElement());
2067 mLoadContext
= loadContext
;
2069 return loadContext
.forget();
2072 /* Be careful if you call this method while proceding a real touch event. For
2073 * example sending a touchstart during a real touchend may results into
2074 * a busted mEventCaptureDepth and following touch events may not do what you
2078 TabParent::InjectTouchEvent(const nsAString
& aType
,
2079 uint32_t* aIdentifiers
,
2084 float* aRotationAngles
,
2090 nsContentUtils::GetEventIdAndAtom(aType
, eTouchEventClass
, &msg
);
2091 if (msg
!= NS_TOUCH_START
&& msg
!= NS_TOUCH_MOVE
&&
2092 msg
!= NS_TOUCH_END
&& msg
!= NS_TOUCH_CANCEL
) {
2093 return NS_ERROR_FAILURE
;
2096 nsCOMPtr
<nsIWidget
> widget
= GetWidget();
2098 return NS_ERROR_FAILURE
;
2101 WidgetTouchEvent
event(true, msg
, widget
);
2102 event
.modifiers
= aModifiers
;
2103 event
.time
= PR_IntervalNow();
2105 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mFrameElement
);
2106 if (!content
|| !content
->OwnerDoc()) {
2107 return NS_ERROR_FAILURE
;
2110 nsIDocument
* doc
= content
->OwnerDoc();
2111 if (!doc
|| !doc
->GetShell()) {
2112 return NS_ERROR_FAILURE
;
2114 nsPresContext
* presContext
= doc
->GetShell()->GetPresContext();
2116 event
.touches
.SetCapacity(aCount
);
2117 for (uint32_t i
= 0; i
< aCount
; ++i
) {
2118 LayoutDeviceIntPoint pt
=
2119 LayoutDeviceIntPoint::FromAppUnitsRounded(
2120 CSSPoint::ToAppUnits(CSSPoint(aXs
[i
], aYs
[i
])),
2121 presContext
->AppUnitsPerDevPixel());
2123 nsRefPtr
<Touch
> t
= new Touch(aIdentifiers
[i
],
2124 LayoutDeviceIntPoint::ToUntyped(pt
),
2125 nsIntPoint(aRxs
[i
], aRys
[i
]),
2129 // Consider all injected touch events as changedTouches. For more details
2130 // about the meaning of changedTouches for each event, see
2131 // https://developer.mozilla.org/docs/Web/API/TouchEvent.changedTouches
2133 event
.touches
.AppendElement(t
);
2136 if ((msg
== NS_TOUCH_END
|| msg
== NS_TOUCH_CANCEL
) && sEventCapturer
) {
2137 WidgetGUIEvent
* guiEvent
= event
.AsGUIEvent();
2138 TryCapture(*guiEvent
);
2141 SendRealTouchEvent(event
);
2146 TabParent::GetUseAsyncPanZoom(bool* useAsyncPanZoom
)
2148 *useAsyncPanZoom
= UseAsyncPanZoom();
2153 TabParent::SetIsDocShellActive(bool isActive
)
2155 unused
<< SendSetIsDocShellActive(isActive
);
2160 TabParent::RecvRemotePaintIsReady()
2162 nsCOMPtr
<mozilla::dom::EventTarget
> target
= do_QueryInterface(mFrameElement
);
2164 NS_WARNING("Could not locate target for MozAfterRemotePaint message.");
2168 nsCOMPtr
<nsIDOMEvent
> event
;
2169 NS_NewDOMEvent(getter_AddRefs(event
), mFrameElement
, nullptr, nullptr);
2170 event
->InitEvent(NS_LITERAL_STRING("MozAfterRemotePaint"), false, false);
2171 event
->SetTrusted(true);
2172 event
->GetInternalNSEvent()->mFlags
.mOnlyChromeDispatch
= true;
2174 mFrameElement
->DispatchEvent(event
, &dummy
);
2178 class FakeChannel MOZ_FINAL
: public nsIChannel
,
2179 public nsIAuthPromptCallback
,
2180 public nsIInterfaceRequestor
,
2181 public nsILoadContext
2184 FakeChannel(const nsCString
& aUri
, uint64_t aCallbackId
, Element
* aElement
)
2185 : mCallbackId(aCallbackId
)
2186 , mElement(aElement
)
2188 NS_NewURI(getter_AddRefs(mUri
), aUri
);
2192 #define NO_IMPL { return NS_ERROR_NOT_IMPLEMENTED; }
2193 NS_IMETHOD
GetName(nsACString
&) NO_IMPL
2194 NS_IMETHOD
IsPending(bool*) NO_IMPL
2195 NS_IMETHOD
GetStatus(nsresult
*) NO_IMPL
2196 NS_IMETHOD
Cancel(nsresult
) NO_IMPL
2197 NS_IMETHOD
Suspend() NO_IMPL
2198 NS_IMETHOD
Resume() NO_IMPL
2199 NS_IMETHOD
GetLoadGroup(nsILoadGroup
**) NO_IMPL
2200 NS_IMETHOD
SetLoadGroup(nsILoadGroup
*) NO_IMPL
2201 NS_IMETHOD
SetLoadFlags(nsLoadFlags
) NO_IMPL
2202 NS_IMETHOD
GetLoadFlags(nsLoadFlags
*) NO_IMPL
2203 NS_IMETHOD
GetOriginalURI(nsIURI
**) NO_IMPL
2204 NS_IMETHOD
SetOriginalURI(nsIURI
*) NO_IMPL
2205 NS_IMETHOD
GetURI(nsIURI
** aUri
)
2211 NS_IMETHOD
GetOwner(nsISupports
**) NO_IMPL
2212 NS_IMETHOD
SetOwner(nsISupports
*) NO_IMPL
2213 NS_IMETHOD
GetLoadInfo(nsILoadInfo
** aLoadInfo
)
2215 NS_IF_ADDREF(*aLoadInfo
= mLoadInfo
);
2218 NS_IMETHOD
SetLoadInfo(nsILoadInfo
* aLoadInfo
)
2220 mLoadInfo
= aLoadInfo
;
2223 NS_IMETHOD
GetNotificationCallbacks(nsIInterfaceRequestor
** aRequestor
)
2225 NS_ADDREF(*aRequestor
= this);
2228 NS_IMETHOD
SetNotificationCallbacks(nsIInterfaceRequestor
*) NO_IMPL
2229 NS_IMETHOD
GetSecurityInfo(nsISupports
**) NO_IMPL
2230 NS_IMETHOD
GetContentType(nsACString
&) NO_IMPL
2231 NS_IMETHOD
SetContentType(const nsACString
&) NO_IMPL
2232 NS_IMETHOD
GetContentCharset(nsACString
&) NO_IMPL
2233 NS_IMETHOD
SetContentCharset(const nsACString
&) NO_IMPL
2234 NS_IMETHOD
GetContentLength(int64_t*) NO_IMPL
2235 NS_IMETHOD
SetContentLength(int64_t) NO_IMPL
2236 NS_IMETHOD
Open(nsIInputStream
**) NO_IMPL
2237 NS_IMETHOD
AsyncOpen(nsIStreamListener
*, nsISupports
*) NO_IMPL
2238 NS_IMETHOD
GetContentDisposition(uint32_t*) NO_IMPL
2239 NS_IMETHOD
SetContentDisposition(uint32_t) NO_IMPL
2240 NS_IMETHOD
GetContentDispositionFilename(nsAString
&) NO_IMPL
2241 NS_IMETHOD
SetContentDispositionFilename(const nsAString
&) NO_IMPL
2242 NS_IMETHOD
GetContentDispositionHeader(nsACString
&) NO_IMPL
2243 NS_IMETHOD
OnAuthAvailable(nsISupports
*aContext
, nsIAuthInformation
*aAuthInfo
);
2244 NS_IMETHOD
OnAuthCancelled(nsISupports
*aContext
, bool userCancel
);
2245 NS_IMETHOD
GetInterface(const nsIID
& uuid
, void **result
)
2247 return QueryInterface(uuid
, result
);
2249 NS_IMETHOD
GetAssociatedWindow(nsIDOMWindow
**) NO_IMPL
2250 NS_IMETHOD
GetTopWindow(nsIDOMWindow
**) NO_IMPL
2251 NS_IMETHOD
GetTopFrameElement(nsIDOMElement
** aElement
)
2253 nsCOMPtr
<nsIDOMElement
> elem
= do_QueryInterface(mElement
);
2254 elem
.forget(aElement
);
2257 NS_IMETHOD
GetNestedFrameId(uint64_t*) NO_IMPL
2258 NS_IMETHOD
IsAppOfType(uint32_t, bool*) NO_IMPL
2259 NS_IMETHOD
GetIsContent(bool*) NO_IMPL
2260 NS_IMETHOD
GetUsePrivateBrowsing(bool*) NO_IMPL
2261 NS_IMETHOD
SetUsePrivateBrowsing(bool) NO_IMPL
2262 NS_IMETHOD
SetPrivateBrowsing(bool) NO_IMPL
2263 NS_IMETHOD
GetIsInBrowserElement(bool*) NO_IMPL
2264 NS_IMETHOD
GetAppId(uint32_t*) NO_IMPL
2265 NS_IMETHOD
GetUseRemoteTabs(bool*) NO_IMPL
2266 NS_IMETHOD
SetRemoteTabs(bool) NO_IMPL
2272 nsCOMPtr
<nsIURI
> mUri
;
2273 uint64_t mCallbackId
;
2274 nsCOMPtr
<Element
> mElement
;
2275 nsCOMPtr
<nsILoadInfo
> mLoadInfo
;
2278 NS_IMPL_ISUPPORTS(FakeChannel
, nsIChannel
, nsIAuthPromptCallback
,
2279 nsIRequest
, nsIInterfaceRequestor
, nsILoadContext
);
2282 TabParent::RecvAsyncAuthPrompt(const nsCString
& aUri
,
2283 const nsString
& aRealm
,
2284 const uint64_t& aCallbackId
)
2286 nsCOMPtr
<nsIAuthPrompt2
> authPrompt
;
2287 GetAuthPrompt(nsIAuthPromptProvider::PROMPT_NORMAL
,
2288 NS_GET_IID(nsIAuthPrompt2
),
2289 getter_AddRefs(authPrompt
));
2290 nsRefPtr
<FakeChannel
> channel
= new FakeChannel(aUri
, aCallbackId
, mFrameElement
);
2291 uint32_t promptFlags
= nsIAuthInformation::AUTH_HOST
;
2293 nsRefPtr
<nsAuthInformationHolder
> holder
=
2294 new nsAuthInformationHolder(promptFlags
, aRealm
,
2297 uint32_t level
= nsIAuthPrompt2::LEVEL_NONE
;
2298 nsCOMPtr
<nsICancelable
> dummy
;
2300 authPrompt
->AsyncPromptAuth(channel
, channel
, nullptr,
2301 level
, holder
, getter_AddRefs(dummy
));
2307 FakeChannel::OnAuthAvailable(nsISupports
*aContext
, nsIAuthInformation
*aAuthInfo
)
2309 nsAuthInformationHolder
* holder
=
2310 static_cast<nsAuthInformationHolder
*>(aAuthInfo
);
2312 if (!net::gNeckoChild
->SendOnAuthAvailable(mCallbackId
,
2315 holder
->Domain())) {
2316 return NS_ERROR_FAILURE
;
2322 FakeChannel::OnAuthCancelled(nsISupports
*aContext
, bool userCancel
)
2324 if (!net::gNeckoChild
->SendOnAuthCancelled(mCallbackId
, userCancel
)) {
2325 return NS_ERROR_FAILURE
;
2332 } // namespace mozilla