application_host.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_REMOTE_COCOA_BROWSER_APPLICATION_HOST_H_
  5. #define COMPONENTS_REMOTE_COCOA_BROWSER_APPLICATION_HOST_H_
  6. #include "base/observer_list.h"
  7. #include "base/observer_list_types.h"
  8. #include "components/remote_cocoa/browser/remote_cocoa_browser_export.h"
  9. #include "components/remote_cocoa/common/application.mojom.h"
  10. #include "mojo/public/cpp/bindings/associated_remote.h"
  11. #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
  12. #include "ui/gfx/native_widget_types.h"
  13. namespace remote_cocoa {
  14. // This class is the browser-side component corresponding to the NSApplication
  15. // running in an app shim process. There exists one ApplicationHost per app shim
  16. // process.
  17. class REMOTE_COCOA_BROWSER_EXPORT ApplicationHost {
  18. public:
  19. class Observer : public base::CheckedObserver {
  20. public:
  21. virtual void OnApplicationHostDestroying(ApplicationHost* host) = 0;
  22. protected:
  23. ~Observer() override {}
  24. };
  25. ApplicationHost(
  26. mojo::PendingAssociatedReceiver<mojom::Application>* receiver);
  27. ~ApplicationHost();
  28. mojom::Application* GetApplication();
  29. void AddObserver(Observer* observer);
  30. void RemoveObserver(const Observer* observer);
  31. static ApplicationHost* GetForNativeView(gfx::NativeView view);
  32. private:
  33. mojo::AssociatedRemote<mojom::Application> application_remote_;
  34. base::ObserverList<Observer> observers_;
  35. };
  36. } // namespace remote_cocoa
  37. #endif // COMPONENTS_REMOTE_COCOA_BROWSER_APPLICATION_HOST_H_