assistant_web_ui_controller.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2019 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 ASH_ASSISTANT_ASSISTANT_WEB_UI_CONTROLLER_H_
  5. #define ASH_ASSISTANT_ASSISTANT_WEB_UI_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/assistant/assistant_web_view_delegate_impl.h"
  9. #include "ash/public/cpp/assistant/assistant_state.h"
  10. #include "ash/public/cpp/assistant/controller/assistant_controller.h"
  11. #include "ash/public/cpp/assistant/controller/assistant_controller_observer.h"
  12. #include "base/scoped_observation.h"
  13. #include "ui/views/widget/widget_observer.h"
  14. namespace ash {
  15. class AssistantWebContainerView;
  16. class AssistantWebContainerEventObserver;
  17. // The class to manage Assistant web container view.
  18. class ASH_EXPORT AssistantWebUiController : public views::WidgetObserver,
  19. public AssistantControllerObserver,
  20. public AssistantStateObserver {
  21. public:
  22. AssistantWebUiController();
  23. AssistantWebUiController(const AssistantWebUiController&) = delete;
  24. AssistantWebUiController& operator=(const AssistantWebUiController&) = delete;
  25. ~AssistantWebUiController() override;
  26. // views::WidgetObserver:
  27. void OnWidgetDestroying(views::Widget* widget) override;
  28. // AssistantControllerObserver:
  29. void OnAssistantControllerConstructed() override;
  30. void OnAssistantControllerDestroying() override;
  31. void OnDeepLinkReceived(
  32. assistant::util::DeepLinkType type,
  33. const std::map<std::string, std::string>& params) override;
  34. // AssistantStateObserver:
  35. void OnAssistantSettingsEnabled(bool enabled) override;
  36. void OnBackButtonPressed();
  37. AssistantWebContainerView* GetViewForTest();
  38. private:
  39. void ShowUi(const GURL& url);
  40. void CloseUi();
  41. // Constructs/resets |web_container_view_|.
  42. void CreateWebContainerView();
  43. void ResetWebContainerView();
  44. AssistantWebViewDelegateImpl view_delegate_;
  45. // Owned by view hierarchy.
  46. AssistantWebContainerView* web_container_view_ = nullptr;
  47. // Observes key press events on the |web_container_view_|.
  48. std::unique_ptr<AssistantWebContainerEventObserver> event_observer_;
  49. base::ScopedObservation<AssistantController, AssistantControllerObserver>
  50. assistant_controller_observation_{this};
  51. };
  52. } // namespace ash
  53. #endif // ASH_ASSISTANT_ASSISTANT_WEB_UI_CONTROLLER_H_