Bug 1676529 [wpt PR 26467] - [LayoutNG] Find sibling spanners using the child iterato...
[gecko.git] / widget / android / GeckoProcessManager.h
blob70df87e2f0b35522124f06f85b7d9a91b3bbe8e5
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"
12 #include "nsWindow.h"
14 #include "mozilla/RefPtr.h"
15 #include "mozilla/dom/ContentProcessManager.h"
16 #include "mozilla/java/GeckoProcessManagerNatives.h"
18 namespace mozilla {
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,
27 int64_t aTabId) {
28 using namespace dom;
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<
46 ConnectionManager>,
47 public nsIObserver {
48 using BaseNatives = java::GeckoProcessManager::ConnectionManager::Natives<
49 ConnectionManager>;
51 virtual ~ConnectionManager() = default;
53 public:
54 ConnectionManager() = default;
56 NS_DECL_ISUPPORTS
57 NS_DECL_NSIOBSERVER
59 static void AttachTo(
60 java::GeckoProcessManager::ConnectionManager::Param aInstance);
61 void ObserveNetworkNotifications();
63 private:
64 java::GeckoProcessManager::ConnectionManager::WeakRef mJavaConnMgr;
67 public:
68 static void Init();
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