blob: 5287693d525880af20f722f332c049f42096a8d5 [file] [log] [blame]
[email protected]7df1dad2012-02-27 11:19:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]14a000d2010-04-29 21:44:242// 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
asanka655d1112015-03-07 05:33:417#include "base/bind.h"
8#include "base/files/file_path.h"
Yeunjoo Choie409e8e2021-07-06 11:09:399#include "chrome/browser/ash/file_manager/open_util.h"
Yeunjoo Choi0a9c1d42021-03-31 01:38:5610#include "chrome/browser/ash/guest_os/guest_os_external_protocol_handler.h"
asanka655d1112015-03-07 05:33:4111#include "chrome/browser/platform_util_internal.h"
Sean Kau16b11ea62021-10-05 16:19:0412#include "chrome/browser/ui/ash/window_pin_util.h"
asanka655d1112015-03-07 05:33:4113#include "chrome/browser/ui/browser.h"
14#include "chrome/browser/ui/browser_finder.h"
asanka655d1112015-03-07 05:33:4115#include "chrome/browser/ui/browser_window.h"
16#include "chrome/browser/ui/simple_message_box.h"
Luciano Pacheco4152f9782019-03-15 21:34:2617#include "chromeos/strings/grit/chromeos_strings.h"
[email protected]c38831a12011-10-28 12:44:4918#include "content/public/browser/browser_thread.h"
Ivan Sandrkc8e238b62019-03-18 15:00:0219#include "ui/aura/window.h"
asanka655d1112015-03-07 05:33:4120#include "ui/base/l10n/l10n_util.h"
Luciano Pacheco4152f9782019-03-15 21:34:2621#include "ui/chromeos/strings/grit/ui_chromeos_strings.h"
[email protected]761fa4702013-07-02 15:25:1522#include "url/gurl.h"
[email protected]14a000d2010-04-29 21:44:2423
[email protected]631bb742011-11-02 11:29:3924using content::BrowserThread;
25
asanka655d1112015-03-07 05:33:4126namespace platform_util {
27
[email protected]7c3228a2011-11-11 21:35:2228namespace {
[email protected]14a000d2010-04-29 21:44:2429
asanka655d1112015-03-07 05:33:4130void 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
scottmg34c5dd882016-02-03 05:21:5460 Browser* browser = chrome::FindTabbedBrowser(profile, false);
estadee16f96ed2016-03-07 22:57:0561 chrome::ShowWarningMessageBox(
asanka655d1112015-03-07 05:33:4162 browser ? browser->window()->GetNativeWindow() : nullptr,
63 l10n_util::GetStringFUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE,
64 path.BaseName().AsUTF16Unsafe()),
estadee16f96ed2016-03-07 22:57:0565 l10n_util::GetStringUTF16(message_id));
asanka655d1112015-03-07 05:33:4166}
67
[email protected]7c3228a2011-11-11 21:35:2268} // namespace
69
asanka655d1112015-03-07 05:33:4170namespace internal {
71
72void DisableShellOperationsForTesting() {
73 file_manager::util::DisableShellOperationsForTesting();
74}
75
76} // namespace internal
[email protected]7c3228a2011-11-11 21:35:2277
[email protected]4d225de12013-12-13 09:29:1778void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
thestig00844cea2015-09-08 21:44:5279 DCHECK_CURRENTLY_ON(BrowserThread::UI);
asanka655d1112015-03-07 05:33:4180 file_manager::util::ShowItemInFolder(
81 profile, full_path,
Alexander Cooper71fa2b02020-07-16 17:49:3682 base::BindOnce(&ShowWarningOnOpenOperationResult, profile, full_path));
[email protected]7c3228a2011-11-11 21:35:2283}
84
asanka655d1112015-03-07 05:33:4185void OpenItem(Profile* profile,
86 const base::FilePath& full_path,
87 OpenItemType item_type,
Alexander Cooper71fa2b02020-07-16 17:49:3688 OpenOperationCallback callback) {
asanka655d1112015-03-07 05:33:4189 DCHECK_CURRENTLY_ON(BrowserThread::UI);
90 file_manager::util::OpenItem(
91 profile, full_path, item_type,
Alexander Cooper71fa2b02020-07-16 17:49:3692 callback.is_null() ? base::BindOnce(&ShowWarningOnOpenOperationResult,
93 profile, full_path)
94 : std::move(callback));
[email protected]7c3228a2011-11-11 21:35:2295}
96
[email protected]7f0a3efa2013-12-12 17:16:1297void OpenExternal(Profile* profile, const GURL& url) {
Joel Hockey48bf3852020-10-07 00:46:3998 // 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.
asanka655d1112015-03-07 05:33:41106 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Joel Hockey48bf3852020-10-07 00:46:39107 guest_os::Launch(profile, url);
[email protected]14a000d2010-04-29 21:44:24108}
109
Ivan Sandrkc8e238b62019-03-18 15:00:02110bool IsBrowserLockedFullscreen(const Browser* browser) {
Ivan Sandrkc8e238b62019-03-18 15:00:02111 aura::Window* window = browser->window()->GetNativeWindow();
112 // |window| can be nullptr inside of unit tests.
113 if (!window)
114 return false;
Sean Kau16b11ea62021-10-05 16:19:04115 return GetWindowPinType(window) == chromeos::WindowPinType::kTrustedPinned;
Ivan Sandrkc8e238b62019-03-18 15:00:02116}
117
[email protected]14a000d2010-04-29 21:44:24118} // namespace platform_util