diff options
Diffstat (limited to 'www/chromium-uc/patches/extra/ungoogled-chromium/add-flag-for-close-confirmation.patch')
| -rw-r--r-- | www/chromium-uc/patches/extra/ungoogled-chromium/add-flag-for-close-confirmation.patch | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/www/chromium-uc/patches/extra/ungoogled-chromium/add-flag-for-close-confirmation.patch b/www/chromium-uc/patches/extra/ungoogled-chromium/add-flag-for-close-confirmation.patch new file mode 100644 index 0000000..56dc7e2 --- /dev/null +++ b/www/chromium-uc/patches/extra/ungoogled-chromium/add-flag-for-close-confirmation.patch | |||
| @@ -0,0 +1,186 @@ | |||
| 1 | --- chrome/browser/ui/browser.cc.orig | ||
| 2 | +++ chrome/browser/ui/browser.cc | ||
| 3 | @@ -140,6 +140,8 @@ | ||
| 4 | #include "chrome/browser/ui/tabs/tab_strip_model.h" | ||
| 5 | #include "chrome/browser/ui/tabs/tab_utils.h" | ||
| 6 | #include "chrome/browser/ui/ui_features.h" | ||
| 7 | +#include "chrome/browser/ui/views/frame/browser_view.h" | ||
| 8 | +#include "chrome/browser/ui/views/message_box_dialog.h" | ||
| 9 | #include "chrome/browser/ui/web_applications/app_browser_controller.h" | ||
| 10 | #include "chrome/browser/ui/web_applications/web_app_launch_utils.h" | ||
| 11 | #include "chrome/browser/ui/webui/signin/login_ui_service.h" | ||
| 12 | @@ -467,6 +469,7 @@ Browser::Browser(const CreateParams& par | ||
| 13 | omit_from_session_restore_(params.omit_from_session_restore), | ||
| 14 | should_trigger_session_restore_(params.should_trigger_session_restore), | ||
| 15 | cancel_download_confirmation_state_(NOT_PROMPTED), | ||
| 16 | + close_multitab_confirmation_state_(NOT_PROMPTED), | ||
| 17 | override_bounds_(params.initial_bounds), | ||
| 18 | initial_show_state_(params.initial_show_state), | ||
| 19 | initial_workspace_(params.initial_workspace), | ||
| 20 | @@ -830,7 +833,7 @@ Browser::WarnBeforeClosingResult Browser | ||
| 21 | // If the browser can close right away (there are no pending downloads we need | ||
| 22 | // to prompt about) then there's no need to warn. In the future, we might need | ||
| 23 | // to check other conditions as well. | ||
| 24 | - if (CanCloseWithInProgressDownloads()) | ||
| 25 | + if (CanCloseWithInProgressDownloads() && CanCloseWithMultipleTabs()) | ||
| 26 | return WarnBeforeClosingResult::kOkToClose; | ||
| 27 | |||
| 28 | DCHECK(!warn_before_closing_callback_) | ||
| 29 | @@ -860,6 +863,7 @@ bool Browser::TryToCloseWindow( | ||
| 30 | |||
| 31 | void Browser::ResetTryToCloseWindow() { | ||
| 32 | cancel_download_confirmation_state_ = NOT_PROMPTED; | ||
| 33 | + close_multitab_confirmation_state_ = NOT_PROMPTED; | ||
| 34 | unload_controller_.ResetTryToCloseWindow(); | ||
| 35 | } | ||
| 36 | |||
| 37 | @@ -2702,6 +2706,62 @@ bool Browser::CanCloseWithInProgressDown | ||
| 38 | return false; | ||
| 39 | } | ||
| 40 | |||
| 41 | +bool Browser::CanCloseWithMultipleTabs() { | ||
| 42 | + if (!base::CommandLine::ForCurrentProcess()->HasSwitch("close-confirmation")) | ||
| 43 | + return true; | ||
| 44 | + | ||
| 45 | + // If we've prompted, we need to hear from the user before we | ||
| 46 | + // can close. | ||
| 47 | + if (close_multitab_confirmation_state_ != NOT_PROMPTED) | ||
| 48 | + return close_multitab_confirmation_state_ != WAITING_FOR_RESPONSE; | ||
| 49 | + | ||
| 50 | + // If we're not running a full browser process with a profile manager | ||
| 51 | + // (testing), it's ok to close the browser. | ||
| 52 | + if (!g_browser_process->profile_manager()) | ||
| 53 | + return true; | ||
| 54 | + | ||
| 55 | + // Figure out how many windows are open total | ||
| 56 | + int total_window_count = 0; | ||
| 57 | + for (auto* browser : *BrowserList::GetInstance()) { | ||
| 58 | + // Don't count this browser window or any other in the process of closing. | ||
| 59 | + // Window closing may be delayed, and windows that are in the process of | ||
| 60 | + // closing don't count against our totals. | ||
| 61 | + if (browser == this || browser->IsAttemptingToCloseBrowser()) | ||
| 62 | + continue; | ||
| 63 | + total_window_count++; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + const auto flag_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("close-confirmation"); | ||
| 67 | + bool show_confirmation_last_window = flag_value == "last"; | ||
| 68 | + | ||
| 69 | + if (show_confirmation_last_window) { | ||
| 70 | + if (total_window_count >= 1 || this->tab_strip_model()->count() <= 1) | ||
| 71 | + return true; | ||
| 72 | + } else { | ||
| 73 | + if (total_window_count == 0) | ||
| 74 | + return true; | ||
| 75 | + if (this->tab_strip_model()->count() == 0) | ||
| 76 | + tab_strip_model_delegate_->AddTabAt(GURL(), -1, true); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + close_multitab_confirmation_state_ = WAITING_FOR_RESPONSE; | ||
| 80 | + | ||
| 81 | + // The dialog eats mouse events which results in the close button | ||
| 82 | + // getting stuck in the hover state. Reset the window controls to | ||
| 83 | + // prevent this. | ||
| 84 | + ((BrowserView*)window_)->frame()->non_client_view()->ResetWindowControls(); | ||
| 85 | + auto callback = base::BindOnce(&Browser::MultitabResponse, | ||
| 86 | + weak_factory_.GetWeakPtr()); | ||
| 87 | + MessageBoxDialog::Show(window_->GetNativeWindow(), | ||
| 88 | + u"Do you want to close this window?", std::u16string(), | ||
| 89 | + chrome::MESSAGE_BOX_TYPE_QUESTION, u"Close", u"Cancel", | ||
| 90 | + std::u16string(), std::move(callback)); | ||
| 91 | + | ||
| 92 | + // Return false so the browser does not close. We'll close if the user | ||
| 93 | + // confirms in the dialog. | ||
| 94 | + return false; | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { | ||
| 98 | if (cancel_downloads) { | ||
| 99 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; | ||
| 100 | @@ -2720,6 +2780,22 @@ void Browser::InProgressDownloadResponse | ||
| 101 | |||
| 102 | std::move(warn_before_closing_callback_) | ||
| 103 | .Run(WarnBeforeClosingResult::kDoNotClose); | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +void Browser::MultitabResponse(chrome::MessageBoxResult result) { | ||
| 107 | + if (result == chrome::MESSAGE_BOX_RESULT_YES) { | ||
| 108 | + close_multitab_confirmation_state_ = RESPONSE_RECEIVED; | ||
| 109 | + std::move(warn_before_closing_callback_) | ||
| 110 | + .Run(WarnBeforeClosingResult::kOkToClose); | ||
| 111 | + return; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + // Sets the confirmation state to NOT_PROMPTED so that if the user tries to | ||
| 115 | + // close again we'll show the warning again. | ||
| 116 | + close_multitab_confirmation_state_ = NOT_PROMPTED; | ||
| 117 | + | ||
| 118 | + std::move(warn_before_closing_callback_) | ||
| 119 | + .Run(WarnBeforeClosingResult::kDoNotClose); | ||
| 120 | } | ||
| 121 | |||
| 122 | void Browser::FinishWarnBeforeClosing(WarnBeforeClosingResult result) { | ||
| 123 | --- chrome/browser/ui/browser.h.orig | ||
| 124 | +++ chrome/browser/ui/browser.h | ||
| 125 | @@ -26,6 +26,7 @@ | ||
| 126 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_observer.h" | ||
| 127 | #include "chrome/browser/ui/browser_navigator_params.h" | ||
| 128 | #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" | ||
| 129 | +#include "chrome/browser/ui/simple_message_box.h" | ||
| 130 | #include "chrome/browser/ui/signin_view_controller.h" | ||
| 131 | #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | ||
| 132 | #include "chrome/browser/ui/unload_controller.h" | ||
| 133 | @@ -1008,12 +1009,17 @@ class Browser : public TabStripModelObse | ||
| 134 | // Returns true if the window can close, false otherwise. | ||
| 135 | bool CanCloseWithInProgressDownloads(); | ||
| 136 | |||
| 137 | + // Called when the window is closing to check if more than one tabs are open | ||
| 138 | + bool CanCloseWithMultipleTabs(); | ||
| 139 | + | ||
| 140 | // Called when the user has decided whether to proceed or not with the browser | ||
| 141 | // closure. |cancel_downloads| is true if the downloads should be canceled | ||
| 142 | // and the browser closed, false if the browser should stay open and the | ||
| 143 | // downloads running. | ||
| 144 | void InProgressDownloadResponse(bool cancel_downloads); | ||
| 145 | |||
| 146 | + void MultitabResponse(chrome::MessageBoxResult result); | ||
| 147 | + | ||
| 148 | // Called when all warnings have completed when attempting to close the | ||
| 149 | // browser directly (e.g. via hotkey, close button, terminate signal, etc.) | ||
| 150 | // Used as a WarnBeforeClosingCallback by ShouldCloseWindow(). | ||
| 151 | @@ -1176,6 +1182,8 @@ class Browser : public TabStripModelObse | ||
| 152 | // when the browser is closed with in-progress downloads. | ||
| 153 | CancelDownloadConfirmationState cancel_download_confirmation_state_; | ||
| 154 | |||
| 155 | + CancelDownloadConfirmationState close_multitab_confirmation_state_; | ||
| 156 | + | ||
| 157 | ///////////////////////////////////////////////////////////////////////////// | ||
| 158 | |||
| 159 | // Override values for the bounds of the window and its maximized or minimized | ||
| 160 | --- chrome/browser/ungoogled_flag_choices.h.orig | ||
| 161 | +++ chrome/browser/ungoogled_flag_choices.h | ||
| 162 | @@ -66,4 +66,13 @@ const FeatureEntry::Choice kCloseWindowW | ||
| 163 | "close-window-with-last-tab", | ||
| 164 | "never"}, | ||
| 165 | }; | ||
| 166 | +const FeatureEntry::Choice kCloseConfirmation[] = { | ||
| 167 | + {flags_ui::kGenericExperimentChoiceDefault, "", ""}, | ||
| 168 | + {"Show confirmation with last window", | ||
| 169 | + "close-confirmation", | ||
| 170 | + "last"}, | ||
| 171 | + {"Show confirmation with multiple windows", | ||
| 172 | + "close-confirmation", | ||
| 173 | + "multiple"}, | ||
| 174 | +}; | ||
| 175 | #endif // CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_ | ||
| 176 | --- chrome/browser/ungoogled_flag_entries.h.orig | ||
| 177 | +++ chrome/browser/ungoogled_flag_entries.h | ||
| 178 | @@ -80,4 +80,8 @@ | ||
| 179 | "Remove Grab Handle", | ||
| 180 | "Removes the reserved empty space in the tabstrip for moving the window. ungoogled-chromium flag", | ||
| 181 | kOsDesktop, SINGLE_VALUE_TYPE("remove-grab-handle")}, | ||
| 182 | + {"close-confirmation", | ||
| 183 | + "Close Confirmation", | ||
| 184 | + "Show a warning prompt when closing the browser window. ungoogled-chromium flag", | ||
| 185 | + kOsDesktop, MULTI_VALUE_TYPE(kCloseConfirmation)}, | ||
| 186 | #endif // CHROME_BROWSER_UNGOOGLED_FLAG_ENTRIES_H_ | ||
