File: chrome_shell_delegate.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (552 lines) | stat: -rw-r--r-- 21,239 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/ash/shell_delegate/chrome_shell_delegate.h"

#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "ash/accelerators/accelerator_prefs_delegate.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_switches.h"
#include "ash/game_dashboard/game_dashboard_delegate.h"
#include "ash/public/cpp/app_types_util.h"
#include "ash/public/cpp/assistant/assistant_state.h"
#include "ash/public/cpp/new_window_delegate.h"
#include "ash/public/cpp/tab_strip_delegate.h"
#include "ash/shell_delegate.h"
#include "ash/webui/settings/public/constants/routes.mojom.h"
#include "ash/webui/settings/public/constants/setting.mojom-shared.h"
#include "ash/wm/window_pin_util.h"
#include "ash/wm/window_state.h"
#include "base/check.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "cc/input/touch_action.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/ash/api/tasks/chrome_tasks_delegate.h"
#include "chrome/browser/ash/arc/arc_util.h"
#include "chrome/browser/ash/arc/locked_fullscreen/arc_locked_fullscreen_manager.h"
#include "chrome/browser/ash/arc/session/arc_service_launcher.h"
#include "chrome/browser/ash/assistant/assistant_util.h"
#include "chrome/browser/ash/file_manager/path_util.h"
#include "chrome/browser/ash/multidevice_setup/multidevice_setup_service_factory.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/ash/scanner/chrome_scanner_delegate.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_ash.h"
#include "chrome/browser/feedback/feedback_uploader_chrome.h"
#include "chrome/browser/feedback/feedback_uploader_factory_chrome.h"
#include "chrome/browser/global_features.h"
#include "chrome/browser/nearby_sharing/nearby_share_delegate_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sessions/session_restore.h"
#include "chrome/browser/ui/ash/accelerator/chrome_accelerator_prefs_delegate.h"
#include "chrome/browser/ui/ash/accessibility/chrome_accessibility_delegate.h"
#include "chrome/browser/ui/ash/back_gesture/back_gesture_contextual_nudge_delegate.h"
#include "chrome/browser/ui/ash/boca/chrome_tab_strip_delegate.h"
#include "chrome/browser/ui/ash/capture_mode/chrome_capture_mode_delegate.h"
#include "chrome/browser/ui/ash/clipboard/clipboard_history_controller_delegate_impl.h"
#include "chrome/browser/ui/ash/desks/chrome_saved_desk_delegate.h"
#include "chrome/browser/ui/ash/focus_mode/chrome_focus_mode_delegate.h"
#include "chrome/browser/ui/ash/game_dashboard/chrome_game_dashboard_delegate.h"
#include "chrome/browser/ui/ash/global_media_controls/media_notification_provider_impl.h"
#include "chrome/browser/ui/ash/keyboard/chrome_keyboard_ui.h"
#include "chrome/browser/ui/ash/session/session_util.h"
#include "chrome/browser/ui/ash/shell_delegate/tab_scrubber.h"
#include "chrome/browser/ui/ash/user_education/chrome_user_education_delegate.h"
#include "chrome/browser/ui/ash/wm/coral_delegate_impl.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/webui/ash/diagnostics_dialog/diagnostics_dialog.h"
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui_layout.h"
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui_util.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/ash/components/audio/system_sounds_delegate_impl.h"
#include "chromeos/ash/components/browser_context_helper/browser_context_helper.h"
#include "chromeos/ash/components/specialized_features/feedback.h"
#include "chromeos/ash/services/multidevice_setup/multidevice_setup_service.h"
#include "components/ui_devtools/devtools_server.h"
#include "components/user_manager/user_manager.h"
#include "components/version_info/channel.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/device_service.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/media_session_service.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/common/constants.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_buffer.h"
#include "url/gurl.h"

namespace {

const char kKeyboardShortcutHelpPageUrl[] =
    "https://support.google.com/chromebook/answer/183101";

// Browser tests are always started with --disable-logging-redirect, so we need
// independent option here.
std::optional<bool> disable_logging_redirect_for_testing;

// Returns the TabStripModel that associates with |window| if the given |window|
// contains a browser frame, otherwise returns nullptr.
TabStripModel* GetTabstripModelForWindowIfAny(aura::Window* window) {
  BrowserView* browser_view =
      BrowserView::GetBrowserViewForNativeWindow(window);
  return browser_view ? browser_view->browser()->tab_strip_model() : nullptr;
}

content::WebContents* GetActiveWebContentsForNativeBrowserWindow(
    gfx::NativeWindow window) {
  if (!window) {
    return nullptr;
  }

  TabStripModel* tab_strip_model = GetTabstripModelForWindowIfAny(window);
  return tab_strip_model ? tab_strip_model->GetActiveWebContents() : nullptr;
}

feedback::FeedbackSource ToChromeFeedbackSource(
    ash::ShellDelegate::FeedbackSource source) {
  switch (source) {
    case ash::ShellDelegate::FeedbackSource::kGameDashboard:
      return feedback::FeedbackSource::kFeedbackSourceGameDashboard;
    case ash::ShellDelegate::FeedbackSource::kOverview:
      return feedback::FeedbackSource::kFeedbackSourceOverview;
    case ash::ShellDelegate::FeedbackSource::kWindowLayoutMenu:
      return feedback::FeedbackSource::kFeedbackSourceWindowLayoutMenu;
    case ash::ShellDelegate::FeedbackSource::kSunfish:
      return feedback::FeedbackSource::kFeedbackSourceSunfish;
  }
  NOTREACHED() << "Unable to retrieve feedback::FeedbackSource due to "
                  "unknown source type.";
}

}  // namespace

ChromeShellDelegate::ChromeShellDelegate() = default;

ChromeShellDelegate::~ChromeShellDelegate() = default;

bool ChromeShellDelegate::CanShowWindowForUser(
    const aura::Window* window) const {
  return ::CanShowWindowForUser(window,
                                base::BindRepeating(&GetActiveBrowserContext));
}

std::unique_ptr<ash::CaptureModeDelegate>
ChromeShellDelegate::CreateCaptureModeDelegate(PrefService* local_state) const {
  // TODO(crbug.com/403153076): Remove g_browser_process usage.
  ApplicationLocaleStorage* application_locale_storage =
      g_browser_process->GetFeatures()->application_locale_storage();

  return std::make_unique<ChromeCaptureModeDelegate>(
      local_state, application_locale_storage);
}

std::unique_ptr<ash::ClipboardHistoryControllerDelegate>
ChromeShellDelegate::CreateClipboardHistoryControllerDelegate() const {
  return std::make_unique<ClipboardHistoryControllerDelegateImpl>();
}

std::unique_ptr<ash::CoralDelegate> ChromeShellDelegate::CreateCoralDelegate()
    const {
  // TODO(crbug.com/403153076): Remove g_browser_process usage.
  ApplicationLocaleStorage* application_locale_storage =
      g_browser_process->GetFeatures()->application_locale_storage();
  variations::VariationsService* variations_service =
      g_browser_process->variations_service();
  return std::make_unique<CoralDelegateImpl>(application_locale_storage,
                                             variations_service);
}

std::unique_ptr<ash::GameDashboardDelegate>
ChromeShellDelegate::CreateGameDashboardDelegate() const {
  return std::make_unique<ChromeGameDashboardDelegate>();
}

std::unique_ptr<ash::AcceleratorPrefsDelegate>
ChromeShellDelegate::CreateAcceleratorPrefsDelegate() const {
  return std::make_unique<ChromeAcceleratorPrefsDelegate>();
}

ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
  return new ChromeAccessibilityDelegate;
}

std::unique_ptr<ash::BackGestureContextualNudgeDelegate>
ChromeShellDelegate::CreateBackGestureContextualNudgeDelegate(
    ash::BackGestureContextualNudgeController* controller) {
  return std::make_unique<BackGestureContextualNudgeDelegate>(controller);
}

std::unique_ptr<ash::MediaNotificationProvider>
ChromeShellDelegate::CreateMediaNotificationProvider() {
  return std::make_unique<ash::MediaNotificationProviderImpl>(
      GetMediaSessionService());
}

std::unique_ptr<ash::NearbyShareDelegate>
ChromeShellDelegate::CreateNearbyShareDelegate(
    ash::NearbyShareController* controller) const {
  return std::make_unique<NearbyShareDelegateImpl>(controller);
}

std::unique_ptr<ash::SavedDeskDelegate>
ChromeShellDelegate::CreateSavedDeskDelegate() const {
  return std::make_unique<ChromeSavedDeskDelegate>();
}

std::unique_ptr<ash::SystemSoundsDelegate>
ChromeShellDelegate::CreateSystemSoundsDelegate() const {
  return std::make_unique<SystemSoundsDelegateImpl>();
}

std::unique_ptr<ash::TabStripDelegate>
ChromeShellDelegate::CreateTabStripDelegate() const {
  return std::make_unique<ChromeTabStripDelegate>();
}

std::unique_ptr<ash::api::TasksDelegate>
ChromeShellDelegate::CreateTasksDelegate() const {
  return std::make_unique<ash::api::ChromeTasksDelegate>();
}

std::unique_ptr<ash::FocusModeDelegate>
ChromeShellDelegate::CreateFocusModeDelegate() const {
  return std::make_unique<ChromeFocusModeDelegate>();
}

std::unique_ptr<ash::UserEducationDelegate>
ChromeShellDelegate::CreateUserEducationDelegate() const {
  return std::make_unique<ChromeUserEducationDelegate>();
}

std::unique_ptr<ash::ScannerDelegate>
ChromeShellDelegate::CreateScannerDelegate() const {
  return std::make_unique<ChromeScannerDelegate>();
}

scoped_refptr<network::SharedURLLoaderFactory>
ChromeShellDelegate::GetBrowserProcessUrlLoaderFactory() const {
  return g_browser_process->shared_url_loader_factory();
}

void ChromeShellDelegate::OpenKeyboardShortcutHelpPage() const {
  ash::NewWindowDelegate::GetPrimary()->OpenUrl(
      GURL(kKeyboardShortcutHelpPageUrl),
      ash::NewWindowDelegate::OpenUrlFrom::kUserInteraction,
      ash::NewWindowDelegate::Disposition::kNewForegroundTab);
}

bool ChromeShellDelegate::CanGoBack(gfx::NativeWindow window) const {
  content::WebContents* contents =
      GetActiveWebContentsForNativeBrowserWindow(window);
  return contents ? contents->GetController().CanGoBack() : false;
}

void ChromeShellDelegate::SetTabScrubberEnabled(bool enabled) {
  ash::TabScrubber::GetInstance()->SetEnabled(enabled);
}

bool ChromeShellDelegate::AllowDefaultTouchActions(gfx::NativeWindow window) {
  content::WebContents* contents =
      GetActiveWebContentsForNativeBrowserWindow(window);
  if (!contents) {
    return true;
  }
  content::RenderWidgetHostView* render_widget_host_view =
      contents->GetRenderWidgetHostView();
  if (!render_widget_host_view) {
    return true;
  }
  content::RenderWidgetHost* render_widget_host =
      render_widget_host_view->GetRenderWidgetHost();
  if (!render_widget_host) {
    return true;
  }
  std::optional<cc::TouchAction> allowed_touch_action =
      render_widget_host->GetAllowedTouchAction();
  return allowed_touch_action.has_value()
             ? *allowed_touch_action != cc::TouchAction::kNone
             : true;
}

bool ChromeShellDelegate::ShouldWaitForTouchPressAck(gfx::NativeWindow window) {
  content::WebContents* contents =
      GetActiveWebContentsForNativeBrowserWindow(window);
  if (!contents) {
    return false;
  }
  content::RenderWidgetHostView* render_widget_host_view =
      contents->GetRenderWidgetHostView();
  if (!render_widget_host_view) {
    return false;
  }
  return !!render_widget_host_view->GetRenderWidgetHost();
}

bool ChromeShellDelegate::IsTabDrag(const ui::OSExchangeData& drop_data) {
  return tab_strip_ui::IsDraggedTab(drop_data);
}

int ChromeShellDelegate::GetBrowserWebUITabStripHeight() {
  return TabStripUILayout::GetContainerHeight();
}

void ChromeShellDelegate::BindFingerprint(
    mojo::PendingReceiver<device::mojom::Fingerprint> receiver) {
  content::GetDeviceService().BindFingerprint(std::move(receiver));
}

void ChromeShellDelegate::BindMultiDeviceSetup(
    mojo::PendingReceiver<ash::multidevice_setup::mojom::MultiDeviceSetup>
        receiver) {
  ash::multidevice_setup::MultiDeviceSetupService* service =
      ash::multidevice_setup::MultiDeviceSetupServiceFactory::GetForProfile(
          ProfileManager::GetPrimaryUserProfile());
  if (service) {
    service->BindMultiDeviceSetup(std::move(receiver));
  }
}

media_session::MediaSessionService*
ChromeShellDelegate::GetMediaSessionService() {
  return &content::GetMediaSessionService();
}

bool ChromeShellDelegate::IsSessionRestoreInProgress() const {
  // Must be called with an active user.
  const user_manager::User* active_user =
      user_manager::UserManager::Get()->GetActiveUser();
  CHECK(active_user);

  // User profile is not yet loaded. Consider loading user profile is part of
  // session restore.
  if (!active_user->is_profile_created()) {
    return true;
  }

  return SessionRestore::IsRestoring(Profile::FromBrowserContext(
      ash::BrowserContextHelper::Get()->GetBrowserContextByUser(active_user)));
}

void ChromeShellDelegate::SetUpEnvironmentForLockedFullscreen(
    const ash::WindowState& window_state) {
  bool locked = window_state.IsPinned();
  // Reset the clipboard and kill dev tools when entering or exiting locked
  // fullscreen (security concerns).
  ui::Clipboard::GetForCurrentThread()->Clear(ui::ClipboardBuffer::kCopyPaste);
  content::DevToolsAgentHost::DetachAllClients();

  // TODO(crbug.com/40195284): This might be interesting for DLP to change.
  // Disable both screenshots and video screen captures via the capture mode
  // feature.
  ChromeCaptureModeDelegate::Get()->SetIsScreenCaptureLocked(locked);

  // Get the primary profile as that's what ARC and Assistant are attached to.
  const Profile* const profile = ProfileManager::GetPrimaryUserProfile();
  // Commands below require profile.
  if (!profile) {
    return;
  }

  arc::ArcServiceLauncher* const arc_service_launcher =
      arc::ArcServiceLauncher::Get();
  if (arc_service_launcher &&
      arc_service_launcher->arc_locked_fullscreen_manager() &&
      !ash::IsArcWindow(window_state.window()) &&
      arc::IsArcAllowedForProfile(profile)) {
    arc_service_launcher->arc_locked_fullscreen_manager()
        ->UpdateForLockedFullscreenMode(locked);
  }

  if (assistant::IsAssistantAllowedForProfile(profile) ==
      ash::assistant::AssistantAllowedState::ALLOWED) {
    ash::AssistantState::Get()->NotifyLockedFullScreenStateChanged(locked);
  }

  // If a window is entering locked fullscreen, then we should close any
  // diagnostics dialog that may be open, since it would show on top of the
  // fullscreen window. There is no need to close it when leaving locked
  // fullscreen, since it is OK for the dialog to be open after exiting locked
  // fullscreen in case the dialog was somehow opened during locked fullscreen.
  if (locked) {
    ash::DiagnosticsDialog::MaybeCloseExistingDialog();
  }
}

bool ChromeShellDelegate::IsUiDevToolsStarted() const {
  return ChromeBrowserMainExtraPartsViews::Get()->GetUiDevToolsServerInstance();
}

void ChromeShellDelegate::StartUiDevTools() {
  ChromeBrowserMainExtraPartsViews::Get()->CreateUiDevTools();
}

void ChromeShellDelegate::StopUiDevTools() {
  ChromeBrowserMainExtraPartsViews::Get()->DestroyUiDevTools();
}

int ChromeShellDelegate::GetUiDevToolsPort() const {
  return ChromeBrowserMainExtraPartsViews::Get()
      ->GetUiDevToolsServerInstance()
      ->port();
}

bool ChromeShellDelegate::IsLoggingRedirectDisabled() const {
  if (disable_logging_redirect_for_testing.has_value()) {
    return disable_logging_redirect_for_testing.value();
  }

  return base::CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kDisableLoggingRedirect);
}

base::FilePath ChromeShellDelegate::GetPrimaryUserDownloadsFolder() const {
  const user_manager::User* primary_user =
      user_manager::UserManager::Get()->GetPrimaryUser();
  if (!primary_user) {
    return base::FilePath();
  }

  Profile* user_profile =
      ash::ProfileHelper::Get()->GetProfileByUser(primary_user);
  if (user_profile) {
    return file_manager::util::GetDownloadsFolderForProfile(user_profile);
  }

  return base::FilePath();
}

void ChromeShellDelegate::OpenFeedbackDialog(
    ShellDelegate::FeedbackSource source,
    const std::string& description_template,
    const std::string& category_tag) {
  chrome::OpenFeedbackDialog(/*browser=*/nullptr,
                             ToChromeFeedbackSource(source),
                             description_template, category_tag);
}

bool ChromeShellDelegate::SendSpecializedFeatureFeedback(
    const AccountId& account_id,
    int product_id,
    std::string description,
    std::optional<std::string> image,
    std::optional<std::string> image_mime_type) {
  // NOTE: `FeedbackUploaderFactoryChrome` (in //chrome/browser/feedback/)
  // returns different instances to `FeedbackUploaderFactory` (in
  // //components/feedback/content). The correct instance should be obtained
  // from `FeedbackUploaderFactoryChrome`.
  content::BrowserContext* browser_context =
      ash::BrowserContextHelper::Get()->GetBrowserContextByAccountId(
          account_id);
  if (!browser_context) {
    return false;
  }

  feedback::FeedbackUploaderChrome* uploader =
      feedback::FeedbackUploaderFactoryChrome::GetForBrowserContext(
          browser_context);
  if (!uploader) {
    return false;
  }

  specialized_features::SendFeedback(*uploader, product_id,
                                     std::move(description), std::move(image),
                                     std::move(image_mime_type));
  return true;
}

void ChromeShellDelegate::OpenProfileManager() {
  NOTREACHED();
}

// static
void ChromeShellDelegate::SetDisableLoggingRedirectForTesting(bool value) {
  disable_logging_redirect_for_testing = value;
}

// static
void ChromeShellDelegate::ResetDisableLoggingRedirectForTesting() {
  disable_logging_redirect_for_testing.reset();
}

const GURL& ChromeShellDelegate::GetLastCommittedURLForWindowIfAny(
    aura::Window* window) {
  // Get the web content if the window is a browser window.
  content::WebContents* contents =
      GetActiveWebContentsForNativeBrowserWindow(window);

  if (!contents) {
    // Get the web content if the window is an app window.
    Profile* profile = ProfileManager::GetLastUsedProfile();
    if (profile) {
      const extensions::AppWindow* app_window =
          extensions::AppWindowRegistry::Get(profile)
              ->GetAppWindowForNativeWindow(window);
      if (app_window) {
        contents = app_window->web_contents();
      }
    }
  }

  return contents ? contents->GetLastCommittedURL() : GURL::EmptyGURL();
}

version_info::Channel ChromeShellDelegate::GetChannel() {
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          ash::switches::kForceShowReleaseTrack)) {
    // Simulate a non-stable channel so the release track UI is visible.
    return version_info::Channel::BETA;
  }
  return chrome::GetChannel();
}

void ChromeShellDelegate::ForceSkipWarningUserOnClose(
    const std::vector<raw_ptr<aura::Window, VectorExperimental>>& windows) {
  for (aura::Window* window : windows) {
    BrowserView* browser_view =
        BrowserView::GetBrowserViewForNativeWindow(window);
    if (browser_view) {
      browser_view->browser()->set_force_skip_warning_user_on_close(true);
    }
  }
}

std::string ChromeShellDelegate::GetVersionString() {
  return std::string(version_info::GetVersionNumber());
}

void ChromeShellDelegate::OpenMultitaskingSettings() {
  chrome::SettingsWindowManager::GetInstance()->ShowOSSettings(
      ProfileManager::GetActiveUserProfile(),
      chromeos::settings::mojom::kSystemPreferencesSectionPath,
      chromeos::settings::mojom::Setting::kSnapWindowSuggestions);
}

bool ChromeShellDelegate::IsNoFirstRunSwitchOn() const {
  return base::CommandLine::ForCurrentProcess()->HasSwitch(
      ::switches::kNoFirstRun);
}