[email protected] | 7df1dad | 2012-02-27 11:19:51 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/platform_util.h" |
| 6 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 7 | #include "base/bind.h" |
| 8 | #include "base/files/file_path.h" |
Yeunjoo Choi | e409e8e | 2021-07-06 11:09:39 | [diff] [blame] | 9 | #include "chrome/browser/ash/file_manager/open_util.h" |
Yeunjoo Choi | 0a9c1d4 | 2021-03-31 01:38:56 | [diff] [blame] | 10 | #include "chrome/browser/ash/guest_os/guest_os_external_protocol_handler.h" |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 11 | #include "chrome/browser/platform_util_internal.h" |
Sean Kau | 16b11ea6 | 2021-10-05 16:19:04 | [diff] [blame] | 12 | #include "chrome/browser/ui/ash/window_pin_util.h" |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser.h" |
| 14 | #include "chrome/browser/ui/browser_finder.h" |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_window.h" |
| 16 | #include "chrome/browser/ui/simple_message_box.h" |
Luciano Pacheco | 4152f978 | 2019-03-15 21:34:26 | [diff] [blame] | 17 | #include "chromeos/strings/grit/chromeos_strings.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 18 | #include "content/public/browser/browser_thread.h" |
Ivan Sandrk | c8e238b6 | 2019-03-18 15:00:02 | [diff] [blame] | 19 | #include "ui/aura/window.h" |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 20 | #include "ui/base/l10n/l10n_util.h" |
Luciano Pacheco | 4152f978 | 2019-03-15 21:34:26 | [diff] [blame] | 21 | #include "ui/chromeos/strings/grit/ui_chromeos_strings.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 22 | #include "url/gurl.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 23 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 24 | using content::BrowserThread; |
| 25 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 26 | namespace platform_util { |
| 27 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 28 | namespace { |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 29 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 30 | void ShowWarningOnOpenOperationResult(Profile* profile, |
| 31 | const base::FilePath& path, |
| 32 | OpenOperationResult result) { |
| 33 | int message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; |
| 34 | switch (result) { |
| 35 | case OPEN_SUCCEEDED: |
| 36 | return; |
| 37 | |
| 38 | case OPEN_FAILED_PATH_NOT_FOUND: |
| 39 | message_id = IDS_FILE_BROWSER_ERROR_UNRESOLVABLE_FILE; |
| 40 | break; |
| 41 | |
| 42 | case OPEN_FAILED_INVALID_TYPE: |
| 43 | return; |
| 44 | |
| 45 | case OPEN_FAILED_NO_HANLDER_FOR_FILE_TYPE: |
| 46 | if (path.MatchesExtension(FILE_PATH_LITERAL(".dmg"))) |
| 47 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_DMG; |
| 48 | else if (path.MatchesExtension(FILE_PATH_LITERAL(".exe")) || |
| 49 | path.MatchesExtension(FILE_PATH_LITERAL(".msi"))) |
| 50 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_EXECUTABLE; |
| 51 | else |
| 52 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; |
| 53 | break; |
| 54 | |
| 55 | case OPEN_FAILED_FILE_ERROR: |
| 56 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; |
| 57 | break; |
| 58 | } |
| 59 | |
scottmg | 34c5dd88 | 2016-02-03 05:21:54 | [diff] [blame] | 60 | Browser* browser = chrome::FindTabbedBrowser(profile, false); |
estade | e16f96ed | 2016-03-07 22:57:05 | [diff] [blame] | 61 | chrome::ShowWarningMessageBox( |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 62 | browser ? browser->window()->GetNativeWindow() : nullptr, |
| 63 | l10n_util::GetStringFUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, |
| 64 | path.BaseName().AsUTF16Unsafe()), |
estade | e16f96ed | 2016-03-07 22:57:05 | [diff] [blame] | 65 | l10n_util::GetStringUTF16(message_id)); |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 66 | } |
| 67 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 68 | } // namespace |
| 69 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 70 | namespace internal { |
| 71 | |
| 72 | void DisableShellOperationsForTesting() { |
| 73 | file_manager::util::DisableShellOperationsForTesting(); |
| 74 | } |
| 75 | |
| 76 | } // namespace internal |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 77 | |
[email protected] | 4d225de1 | 2013-12-13 09:29:17 | [diff] [blame] | 78 | void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 79 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 80 | file_manager::util::ShowItemInFolder( |
| 81 | profile, full_path, |
Alexander Cooper | 71fa2b0 | 2020-07-16 17:49:36 | [diff] [blame] | 82 | base::BindOnce(&ShowWarningOnOpenOperationResult, profile, full_path)); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 83 | } |
| 84 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 85 | void OpenItem(Profile* profile, |
| 86 | const base::FilePath& full_path, |
| 87 | OpenItemType item_type, |
Alexander Cooper | 71fa2b0 | 2020-07-16 17:49:36 | [diff] [blame] | 88 | OpenOperationCallback callback) { |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 89 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 90 | file_manager::util::OpenItem( |
| 91 | profile, full_path, item_type, |
Alexander Cooper | 71fa2b0 | 2020-07-16 17:49:36 | [diff] [blame] | 92 | callback.is_null() ? base::BindOnce(&ShowWarningOnOpenOperationResult, |
| 93 | profile, full_path) |
| 94 | : std::move(callback)); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 95 | } |
| 96 | |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 97 | void OpenExternal(Profile* profile, const GURL& url) { |
Joel Hockey | 48bf385 | 2020-10-07 00:46:39 | [diff] [blame] | 98 | // This code is called either when: |
| 99 | // 1. ChromeAppDelegate::NewWindowContentsDelegate::OpenURLFromTab determines |
| 100 | // that the currently running chrome is not the system default browser. This |
| 101 | // should not happen for Chrome OS (crrev.com/c/2454769). |
| 102 | // 2. |url| uses a external protocol and either |
| 103 | // ExternalProtocolDialog::OnDialogAccepted invokes this, or the dialog has |
| 104 | // previously been accepted with "Always allow ..." and this is called from |
| 105 | // ChromeContentBrowserClient::HandleExternalProtocol. |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 106 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Joel Hockey | 48bf385 | 2020-10-07 00:46:39 | [diff] [blame] | 107 | guest_os::Launch(profile, url); |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 108 | } |
| 109 | |
Ivan Sandrk | c8e238b6 | 2019-03-18 15:00:02 | [diff] [blame] | 110 | bool IsBrowserLockedFullscreen(const Browser* browser) { |
Ivan Sandrk | c8e238b6 | 2019-03-18 15:00:02 | [diff] [blame] | 111 | aura::Window* window = browser->window()->GetNativeWindow(); |
| 112 | // |window| can be nullptr inside of unit tests. |
| 113 | if (!window) |
| 114 | return false; |
Sean Kau | 16b11ea6 | 2021-10-05 16:19:04 | [diff] [blame] | 115 | return GetWindowPinType(window) == chromeos::WindowPinType::kTrustedPinned; |
Ivan Sandrk | c8e238b6 | 2019-03-18 15:00:02 | [diff] [blame] | 116 | } |
| 117 | |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 118 | } // namespace platform_util |