OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/platform_util.h" | 5 #include "chrome/browser/platform_util.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" |
7 #include "chrome/browser/chromeos/file_manager/open_util.h" | 9 #include "chrome/browser/chromeos/file_manager/open_util.h" |
| 10 #include "chrome/browser/platform_util_internal.h" |
| 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" |
8 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
| 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/simple_message_box.h" |
| 16 #include "chrome/grit/generated_resources.h" |
9 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "ui/base/l10n/l10n_util.h" |
10 #include "url/gurl.h" | 19 #include "url/gurl.h" |
11 | 20 |
12 using content::BrowserThread; | 21 using content::BrowserThread; |
13 | 22 |
| 23 namespace platform_util { |
| 24 |
14 namespace { | 25 namespace { |
15 | 26 |
16 const char kGmailComposeUrl[] = | 27 const char kGmailComposeUrl[] = |
17 "https://mail.google.com/mail/?extsrc=mailto&url="; | 28 "https://mail.google.com/mail/?extsrc=mailto&url="; |
18 | 29 |
| 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 |
| 60 Browser* browser = |
| 61 chrome::FindTabbedBrowser(profile, false, chrome::HOST_DESKTOP_TYPE_ASH); |
| 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 |
19 } // namespace | 69 } // namespace |
20 | 70 |
21 namespace platform_util { | 71 namespace internal { |
| 72 |
| 73 void DisableShellOperationsForTesting() { |
| 74 file_manager::util::DisableShellOperationsForTesting(); |
| 75 } |
| 76 |
| 77 } // namespace internal |
22 | 78 |
23 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { | 79 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
25 file_manager::util::ShowItemInFolder(profile, full_path); | 81 file_manager::util::ShowItemInFolder( |
| 82 profile, full_path, |
| 83 base::Bind(&ShowWarningOnOpenOperationResult, profile, full_path)); |
26 } | 84 } |
27 | 85 |
28 void OpenItem(Profile* profile, const base::FilePath& full_path) { | 86 void OpenItem(Profile* profile, |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 87 const base::FilePath& full_path, |
30 file_manager::util::OpenItem(profile, 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); |
31 } | 96 } |
32 | 97 |
33 void OpenExternal(Profile* profile, const GURL& url) { | 98 void OpenExternal(Profile* profile, const GURL& url) { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
35 | 100 |
36 // This code should be obsolete since we have default handlers in ChromeOS | 101 // This code should be obsolete since we have default handlers in ChromeOS |
37 // which should handle this. However - there are two things which make it | 102 // which should handle this. However - there are two things which make it |
38 // necessary to keep it in: | 103 // necessary to keep it in: |
39 // a.) The user might have deleted the default handler in this session. | 104 // a.) The user might have deleted the default handler in this session. |
40 // In this case we would need to have this in place. | 105 // In this case we would need to have this in place. |
41 // b.) There are several code paths which are not clear if they would call | 106 // b.) There are several code paths which are not clear if they would call |
42 // this function directly and which would therefore break (e.g. | 107 // this function directly and which would therefore break (e.g. |
43 // "Browser::EmailPageLocation" (to name only one). | 108 // "Browser::EmailPageLocation" (to name only one). |
44 // As such we should keep this code here. | 109 // As such we should keep this code here. |
45 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK); | 110 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK); |
46 params.disposition = NEW_FOREGROUND_TAB; | 111 params.disposition = NEW_FOREGROUND_TAB; |
47 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; | 112 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
48 | 113 |
49 if (url.SchemeIs("mailto")) { | 114 if (url.SchemeIs("mailto")) { |
50 std::string string_url = kGmailComposeUrl; | 115 std::string string_url = kGmailComposeUrl; |
51 string_url.append(url.spec()); | 116 string_url.append(url.spec()); |
52 params.url = GURL(url); | 117 params.url = GURL(url); |
53 } | 118 } |
54 | 119 |
55 chrome::Navigate(¶ms); | 120 chrome::Navigate(¶ms); |
56 } | 121 } |
57 | 122 |
58 } // namespace platform_util | 123 } // namespace platform_util |
OLD | NEW |