[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" |
[email protected] | 473c9a4f | 2013-09-05 03:09:46 | [diff] [blame] | 9 | #include "chrome/browser/chromeos/file_manager/open_util.h" |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 10 | #include "chrome/browser/platform_util_internal.h" |
| 11 | #include "chrome/browser/ui/browser.h" |
| 12 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 4e8b38a | 2012-05-24 20:48:04 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_navigator.h" |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser_navigator_params.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" |
| 17 | #include "chrome/grit/generated_resources.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 18 | #include "content/public/browser/browser_thread.h" |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 19 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 20 | #include "url/gurl.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 21 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 22 | using content::BrowserThread; |
| 23 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 24 | namespace platform_util { |
| 25 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 26 | namespace { |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 27 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 28 | const char kGmailComposeUrl[] = |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 29 | "https://mail.google.com/mail/?extsrc=mailto&url="; |
| 30 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 31 | void ShowWarningOnOpenOperationResult(Profile* profile, |
| 32 | const base::FilePath& path, |
| 33 | OpenOperationResult result) { |
| 34 | int message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; |
| 35 | switch (result) { |
| 36 | case OPEN_SUCCEEDED: |
| 37 | return; |
| 38 | |
| 39 | case OPEN_FAILED_PATH_NOT_FOUND: |
| 40 | message_id = IDS_FILE_BROWSER_ERROR_UNRESOLVABLE_FILE; |
| 41 | break; |
| 42 | |
| 43 | case OPEN_FAILED_INVALID_TYPE: |
| 44 | return; |
| 45 | |
| 46 | case OPEN_FAILED_NO_HANLDER_FOR_FILE_TYPE: |
| 47 | if (path.MatchesExtension(FILE_PATH_LITERAL(".dmg"))) |
| 48 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_DMG; |
| 49 | else if (path.MatchesExtension(FILE_PATH_LITERAL(".exe")) || |
| 50 | path.MatchesExtension(FILE_PATH_LITERAL(".msi"))) |
| 51 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_EXECUTABLE; |
| 52 | else |
| 53 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; |
| 54 | break; |
| 55 | |
| 56 | case OPEN_FAILED_FILE_ERROR: |
| 57 | message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; |
| 58 | break; |
| 59 | } |
| 60 | |
scottmg | 34c5dd88 | 2016-02-03 05:21:54 | [diff] [blame^] | 61 | Browser* browser = chrome::FindTabbedBrowser(profile, false); |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 62 | chrome::ShowMessageBox( |
| 63 | browser ? browser->window()->GetNativeWindow() : nullptr, |
| 64 | l10n_util::GetStringFUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, |
| 65 | path.BaseName().AsUTF16Unsafe()), |
| 66 | l10n_util::GetStringUTF16(message_id), chrome::MESSAGE_BOX_TYPE_WARNING); |
| 67 | } |
| 68 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 69 | } // namespace |
| 70 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 71 | namespace internal { |
| 72 | |
| 73 | void DisableShellOperationsForTesting() { |
| 74 | file_manager::util::DisableShellOperationsForTesting(); |
| 75 | } |
| 76 | |
| 77 | } // namespace internal |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 78 | |
[email protected] | 4d225de1 | 2013-12-13 09:29:17 | [diff] [blame] | 79 | void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 80 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 81 | file_manager::util::ShowItemInFolder( |
| 82 | profile, full_path, |
| 83 | base::Bind(&ShowWarningOnOpenOperationResult, profile, full_path)); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 84 | } |
| 85 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 86 | void OpenItem(Profile* profile, |
| 87 | const base::FilePath& full_path, |
| 88 | OpenItemType item_type, |
| 89 | const OpenOperationCallback& callback) { |
| 90 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 91 | file_manager::util::OpenItem( |
| 92 | profile, full_path, item_type, |
| 93 | callback.is_null() |
| 94 | ? base::Bind(&ShowWarningOnOpenOperationResult, profile, full_path) |
| 95 | : callback); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 96 | } |
| 97 | |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 98 | void OpenExternal(Profile* profile, const GURL& url) { |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 99 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 100 | |
[email protected] | 899dfca | 2012-05-08 16:47:40 | [diff] [blame] | 101 | // This code should be obsolete since we have default handlers in ChromeOS |
| 102 | // which should handle this. However - there are two things which make it |
| 103 | // necessary to keep it in: |
| 104 | // a.) The user might have deleted the default handler in this session. |
| 105 | // In this case we would need to have this in place. |
| 106 | // b.) There are several code paths which are not clear if they would call |
| 107 | // this function directly and which would therefore break (e.g. |
| 108 | // "Browser::EmailPageLocation" (to name only one). |
| 109 | // As such we should keep this code here. |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 110 | chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK); |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 111 | params.disposition = NEW_FOREGROUND_TAB; |
| 112 | params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| 113 | |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 114 | if (url.SchemeIs("mailto")) { |
| 115 | std::string string_url = kGmailComposeUrl; |
| 116 | string_url.append(url.spec()); |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 117 | params.url = GURL(url); |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 118 | } |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 119 | |
| 120 | chrome::Navigate(¶ms); |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | } // namespace platform_util |