1 /* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GeckoProcessManager_h
7 #define GeckoProcessManager_h
9 #include "WidgetUtils.h"
10 #include "nsAppShell.h"
11 #include "nsIObserver.h"
14 #include "mozilla/RefPtr.h"
15 #include "mozilla/dom/ContentProcessManager.h"
16 #include "mozilla/java/GeckoProcessManagerNatives.h"
20 class GeckoProcessManager final
21 : public java::GeckoProcessManager::Natives
<GeckoProcessManager
> {
22 using BaseNatives
= java::GeckoProcessManager::Natives
<GeckoProcessManager
>;
24 GeckoProcessManager() = delete;
26 static already_AddRefed
<nsIWidget
> GetWidget(int64_t aContentId
,
29 MOZ_ASSERT(NS_IsMainThread());
31 ContentProcessManager
* const cpm
= ContentProcessManager::GetSingleton();
32 NS_ENSURE_TRUE(cpm
, nullptr);
34 RefPtr
<BrowserParent
> tab
= cpm
->GetTopLevelBrowserParentByProcessAndTabId(
35 ContentParentId(aContentId
), TabId(aTabId
));
36 NS_ENSURE_TRUE(tab
, nullptr);
38 nsCOMPtr
<nsPIDOMWindowOuter
> domWin
= tab
->GetParentWindowOuter();
39 NS_ENSURE_TRUE(domWin
, nullptr);
41 return widget::WidgetUtils::DOMWindowToWidget(domWin
);
44 class ConnectionManager final
45 : public java::GeckoProcessManager::ConnectionManager::Natives
<
48 using BaseNatives
= java::GeckoProcessManager::ConnectionManager::Natives
<
51 virtual ~ConnectionManager() = default;
54 ConnectionManager() = default;
60 java::GeckoProcessManager::ConnectionManager::Param aInstance
);
61 void ObserveNetworkNotifications();
64 java::GeckoProcessManager::ConnectionManager::WeakRef mJavaConnMgr
;
70 static void GetEditableParent(jni::Object::Param aEditableChild
,
71 int64_t aContentId
, int64_t aTabId
) {
72 nsCOMPtr
<nsIWidget
> widget
= GetWidget(aContentId
, aTabId
);
73 if (RefPtr
<nsWindow
> window
= nsWindow::From(widget
)) {
74 java::GeckoProcessManager::SetEditableChildParent(
75 aEditableChild
, window
->GetEditableParent());
80 } // namespace mozilla
82 #endif // GeckoProcessManager_h