Chromium Code Reviews| 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 void DisableShellOperationsForTesting() { | |
| 73 file_manager::util::DisableShellOperationsForTesting(); | |
| 74 } | |
| 75 } | |
|
mtomasz
2015/03/06 07:05:49
nit: // namespace internal
asanka
2015/03/06 21:09:40
Done.
| |
| 22 | 76 |
| 23 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { | 77 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
| 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 25 file_manager::util::ShowItemInFolder(profile, full_path); | 79 file_manager::util::ShowItemInFolder( |
| 80 profile, full_path, | |
| 81 base::Bind(&ShowWarningOnOpenOperationResult, profile, full_path)); | |
| 26 } | 82 } |
| 27 | 83 |
| 28 void OpenItem(Profile* profile, const base::FilePath& full_path) { | 84 void OpenItem(Profile* profile, |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 85 const base::FilePath& full_path, |
| 30 file_manager::util::OpenItem(profile, full_path); | 86 OpenItemType item_type, |
| 87 const OpenOperationCallback& callback) { | |
| 88 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 89 file_manager::util::OpenItem( | |
| 90 profile, full_path, item_type, | |
| 91 callback.is_null() | |
| 92 ? base::Bind(&ShowWarningOnOpenOperationResult, profile, full_path) | |
| 93 : callback); | |
| 31 } | 94 } |
| 32 | 95 |
| 33 void OpenExternal(Profile* profile, const GURL& url) { | 96 void OpenExternal(Profile* profile, const GURL& url) { |
| 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 35 | 98 |
| 36 // This code should be obsolete since we have default handlers in ChromeOS | 99 // 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 | 100 // which should handle this. However - there are two things which make it |
| 38 // necessary to keep it in: | 101 // necessary to keep it in: |
| 39 // a.) The user might have deleted the default handler in this session. | 102 // a.) The user might have deleted the default handler in this session. |
| 40 // In this case we would need to have this in place. | 103 // 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 | 104 // 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. | 105 // this function directly and which would therefore break (e.g. |
| 43 // "Browser::EmailPageLocation" (to name only one). | 106 // "Browser::EmailPageLocation" (to name only one). |
| 44 // As such we should keep this code here. | 107 // As such we should keep this code here. |
| 45 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK); | 108 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK); |
| 46 params.disposition = NEW_FOREGROUND_TAB; | 109 params.disposition = NEW_FOREGROUND_TAB; |
| 47 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; | 110 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| 48 | 111 |
| 49 if (url.SchemeIs("mailto")) { | 112 if (url.SchemeIs("mailto")) { |
| 50 std::string string_url = kGmailComposeUrl; | 113 std::string string_url = kGmailComposeUrl; |
| 51 string_url.append(url.spec()); | 114 string_url.append(url.spec()); |
| 52 params.url = GURL(url); | 115 params.url = GURL(url); |
| 53 } | 116 } |
| 54 | 117 |
| 55 chrome::Navigate(¶ms); | 118 chrome::Navigate(¶ms); |
| 56 } | 119 } |
| 57 | 120 |
| 58 } // namespace platform_util | 121 } // namespace platform_util |
| OLD | NEW |