new_window_delegate.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_PUBLIC_CPP_NEW_WINDOW_DELEGATE_H_
  5. #define ASH_PUBLIC_CPP_NEW_WINDOW_DELEGATE_H_
  6. #include <string>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "base/bind.h"
  9. class GURL;
  10. namespace aura {
  11. class Window;
  12. }
  13. namespace ui {
  14. class OSExchangeData;
  15. }
  16. namespace ash {
  17. // A delegate interface that an ash user sends to ash to handle certain window
  18. // management responsibilities.
  19. class ASH_PUBLIC_EXPORT NewWindowDelegate {
  20. public:
  21. // Sources of feedback requests.
  22. enum FeedbackSource {
  23. kFeedbackSourceAsh,
  24. kFeedbackSourceAssistant,
  25. kFeedbackSourceQuickAnswers,
  26. kFeedbackSourceChannelIndicator,
  27. };
  28. virtual ~NewWindowDelegate();
  29. // Returns an instance connected to ash-chrome.
  30. static NewWindowDelegate* GetInstance();
  31. // Returns an instance connected to the primary browser.
  32. // Specifically, if Lacros is the primary browser, the instance connected
  33. // to the registered browser via crosapi.
  34. static NewWindowDelegate* GetPrimary();
  35. // Invoked when the user uses Ctrl+T to open a new tab.
  36. virtual void NewTab() = 0;
  37. // Invoked when the user uses Ctrl-N or Ctrl-Shift-N to open a new window. If
  38. // the |should_trigger_session_restore| is true, a new window opening should
  39. // be treated like the start of a session (with potential session restore,
  40. // startup URLs, etc.). Otherwise, don't restore the session.
  41. virtual void NewWindow(bool incognito,
  42. bool should_trigger_session_restore) = 0;
  43. using NewWindowForDetachingTabCallback =
  44. base::OnceCallback<void(aura::Window*)>;
  45. // Opens a new Browser window in response to a drag'n drop operation performed
  46. // by the user while in "tablet mode".
  47. virtual void NewWindowForDetachingTab(
  48. aura::Window* source_window,
  49. const ui::OSExchangeData& drop_data,
  50. NewWindowForDetachingTabCallback closure) = 0;
  51. // Opens the specified URL in a new tab.
  52. // If the |from| is kUserInteraction then the page will load with a user
  53. // activation. This means the page will be able to autoplay media without
  54. // restriction.
  55. // If the |from| is kArc, then the new window is annotated a special tag,
  56. // so that on requesting to opening ARC app from the page, confirmation
  57. // dialog will be skipped.
  58. // |Disposition| corresponds to the subset of |WindowOpenDisposition| that is
  59. // supported by crosapi.
  60. enum class OpenUrlFrom {
  61. kUnspecified,
  62. kUserInteraction,
  63. kArc,
  64. };
  65. enum class Disposition {
  66. kNewForegroundTab,
  67. kNewWindow,
  68. kSwitchToTab,
  69. };
  70. virtual void OpenUrl(const GURL& url,
  71. OpenUrlFrom from,
  72. Disposition disposition) = 0;
  73. // Invoked when an accelerator (calculator key) is used to open calculator.
  74. virtual void OpenCalculator() = 0;
  75. // Invoked when an accelerator is used to open the file manager.
  76. virtual void OpenFileManager() = 0;
  77. // Opens File Manager in the My files/Downloads folder.
  78. virtual void OpenDownloadsFolder() = 0;
  79. // Invoked when the user opens Crosh.
  80. virtual void OpenCrosh() = 0;
  81. // Invoked when an accelerator is used to open diagnostics.
  82. virtual void OpenDiagnostics() = 0;
  83. // Invoked when an accelerator is used to open help center.
  84. virtual void OpenGetHelp() = 0;
  85. // Invoked when the user uses Shift+Ctrl+T to restore the closed tab.
  86. virtual void RestoreTab() = 0;
  87. // Show the keyboard shortcut viewer.
  88. virtual void ShowKeyboardShortcutViewer() = 0;
  89. // Shows the task manager window.
  90. virtual void ShowTaskManager() = 0;
  91. // Opens the feedback page for "Report Issue".
  92. // |source| indicates the source of the feedback request, which is Ash by
  93. // default.
  94. // |description_template| is the preset description when the feedback dialog
  95. // is opened.
  96. virtual void OpenFeedbackPage(
  97. FeedbackSource source = kFeedbackSourceAsh,
  98. const std::string& description_template = std::string()) = 0;
  99. // Show the Personalization hub.
  100. virtual void OpenPersonalizationHub() = 0;
  101. protected:
  102. NewWindowDelegate();
  103. NewWindowDelegate(const NewWindowDelegate&) = delete;
  104. NewWindowDelegate& operator=(const NewWindowDelegate&) = delete;
  105. };
  106. // Interface to provide delegate instances for
  107. // NewWindowDelegate::GetInstance/GetPrimary methods.
  108. class ASH_PUBLIC_EXPORT NewWindowDelegateProvider {
  109. public:
  110. virtual ~NewWindowDelegateProvider();
  111. virtual NewWindowDelegate* GetInstance() = 0;
  112. virtual NewWindowDelegate* GetPrimary() = 0;
  113. protected:
  114. NewWindowDelegateProvider();
  115. NewWindowDelegateProvider(const NewWindowDelegateProvider&) = delete;
  116. NewWindowDelegateProvider& operator=(const NewWindowDelegateProvider&) =
  117. delete;
  118. };
  119. } // namespace ash
  120. #endif // ASH_PUBLIC_CPP_NEW_WINDOW_DELEGATE_H_