Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / platform_util_chromeos.cc
blob077a044ccf5546f59ace81a92fa7f3a77299f871
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
3 // found in the LICENSE file.
5 #include "chrome/browser/platform_util.h"
7 #include "base/bind.h"
8 #include "base/files/file_path.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"
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"
17 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "url/gurl.h"
21 using content::BrowserThread;
23 namespace platform_util {
25 namespace {
27 const char kGmailComposeUrl[] =
28 "https://mail.google.com/mail/?extsrc=mailto&url=";
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;
38 case OPEN_FAILED_PATH_NOT_FOUND:
39 message_id = IDS_FILE_BROWSER_ERROR_UNRESOLVABLE_FILE;
40 break;
42 case OPEN_FAILED_INVALID_TYPE:
43 return;
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;
55 case OPEN_FAILED_FILE_ERROR:
56 message_id = IDS_FILE_BROWSER_ERROR_VIEWING_FILE;
57 break;
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);
69 } // namespace
71 namespace internal {
73 void DisableShellOperationsForTesting() {
74 file_manager::util::DisableShellOperationsForTesting();
77 } // namespace internal
79 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
80 DCHECK_CURRENTLY_ON(BrowserThread::UI);
81 file_manager::util::ShowItemInFolder(
82 profile, full_path,
83 base::Bind(&ShowWarningOnOpenOperationResult, profile, full_path));
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);
98 void OpenExternal(Profile* profile, const GURL& url) {
99 DCHECK_CURRENTLY_ON(BrowserThread::UI);
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.
110 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK);
111 params.disposition = NEW_FOREGROUND_TAB;
112 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH;
114 if (url.SchemeIs("mailto")) {
115 std::string string_url = kGmailComposeUrl;
116 string_url.append(url.spec());
117 params.url = GURL(url);
120 chrome::Navigate(&params);
123 } // namespace platform_util