Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: chrome/browser/platform_util_chromeos.cc

Issue 352393002: Be explicit about target type in platform_util::OpenItem() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
9 #include "base/logging.h"
7 #include "chrome/browser/chromeos/file_manager/open_util.h" 10 #include "chrome/browser/chromeos/file_manager/open_util.h"
11 #include "chrome/browser/platform_util_internal.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_finder.h"
8 #include "chrome/browser/ui/browser_navigator.h" 14 #include "chrome/browser/ui/browser_navigator.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/simple_message_box.h"
17 #include "chrome/grit/generated_resources.h"
9 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "ui/base/l10n/l10n_util.h"
10 #include "url/gurl.h" 20 #include "url/gurl.h"
11 21
12 using content::BrowserThread; 22 using content::BrowserThread;
13 23
24 namespace platform_util {
25
14 namespace { 26 namespace {
15 27
16 const char kGmailComposeUrl[] = 28 const char kGmailComposeUrl[] =
17 "https://mail.google.com/mail/?extsrc=mailto&url="; 29 "https://mail.google.com/mail/?extsrc=mailto&url=";
18 30
31 void HandleOpenOperationResult(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
61 Browser* browser =
62 chrome::FindTabbedBrowser(profile, false, chrome::HOST_DESKTOP_TYPE_ASH);
63 chrome::ShowMessageBox(
64 browser ? browser->window()->GetNativeWindow() : NULL,
65 l10n_util::GetStringFUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE,
66 path.BaseName().AsUTF16Unsafe()),
67 l10n_util::GetStringUTF16(message_id), chrome::MESSAGE_BOX_TYPE_WARNING);
68 }
69
19 } // namespace 70 } // namespace
20 71
21 namespace platform_util { 72 namespace internal {
73 void DisableShellOperationsForTesting() {
74 file_manager::util::DisableShellOperationsForTesting();
75 }
76 }
22 77
23 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { 78 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25 file_manager::util::ShowItemInFolder(profile, full_path); 80 file_manager::util::ShowItemInFolder(
81 profile, full_path,
82 base::Bind(&HandleOpenOperationResult, profile, full_path));
26 } 83 }
27 84
28 void OpenItem(Profile* profile, const base::FilePath& full_path) { 85 void OpenFile(Profile* profile,
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 86 const base::FilePath& full_path,
30 file_manager::util::OpenItem(profile, full_path); 87 const OpenOperationCallback& callback) {
88 DCHECK_CURRENTLY_ON(BrowserThread::UI);
89 file_manager::util::OpenFile(
90 profile, full_path,
91 callback.is_null()
92 ? base::Bind(&HandleOpenOperationResult, profile, full_path)
93 : callback);
94 }
95
96 void OpenFolder(Profile* profile,
97 const base::FilePath& full_path,
98 const OpenOperationCallback& callback) {
99 DCHECK_CURRENTLY_ON(BrowserThread::UI);
100 file_manager::util::OpenFolder(
101 profile, full_path,
102 callback.is_null()
103 ? base::Bind(&HandleOpenOperationResult, profile, full_path)
104 : callback);
31 } 105 }
32 106
33 void OpenExternal(Profile* profile, const GURL& url) { 107 void OpenExternal(Profile* profile, const GURL& url) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 108 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35 109
36 // This code should be obsolete since we have default handlers in ChromeOS 110 // 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 111 // which should handle this. However - there are two things which make it
38 // necessary to keep it in: 112 // necessary to keep it in:
39 // a.) The user might have deleted the default handler in this session. 113 // a.) The user might have deleted the default handler in this session.
40 // In this case we would need to have this in place. 114 // 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 115 // 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. 116 // this function directly and which would therefore break (e.g.
43 // "Browser::EmailPageLocation" (to name only one). 117 // "Browser::EmailPageLocation" (to name only one).
44 // As such we should keep this code here. 118 // As such we should keep this code here.
45 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK); 119 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK);
46 params.disposition = NEW_FOREGROUND_TAB; 120 params.disposition = NEW_FOREGROUND_TAB;
47 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; 121 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH;
48 122
49 if (url.SchemeIs("mailto")) { 123 if (url.SchemeIs("mailto")) {
50 std::string string_url = kGmailComposeUrl; 124 std::string string_url = kGmailComposeUrl;
51 string_url.append(url.spec()); 125 string_url.append(url.spec());
52 params.url = GURL(url); 126 params.url = GURL(url);
53 } 127 }
54 128
55 chrome::Navigate(&params); 129 chrome::Navigate(&params);
56 } 130 }
57 131
58 } // namespace platform_util 132 } // namespace platform_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698