blob: 6d62b2e95f7ac9f9414916718d239d34eca96c56 [file] [log] [blame]
[email protected]7df1dad2012-02-27 11:19:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]14a000d2010-04-29 21:44:242// 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
asanka655d1112015-03-07 05:33:417#include "base/bind.h"
8#include "base/files/file_path.h"
[email protected]473c9a4f2013-09-05 03:09:469#include "chrome/browser/chromeos/file_manager/open_util.h"
asanka655d1112015-03-07 05:33:4110#include "chrome/browser/platform_util_internal.h"
11#include "chrome/browser/ui/browser.h"
12#include "chrome/browser/ui/browser_finder.h"
[email protected]4e8b38a2012-05-24 20:48:0413#include "chrome/browser/ui/browser_navigator.h"
thestige80821242015-09-30 23:46:0814#include "chrome/browser/ui/browser_navigator_params.h"
asanka655d1112015-03-07 05:33:4115#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]c38831a12011-10-28 12:44:4918#include "content/public/browser/browser_thread.h"
asanka655d1112015-03-07 05:33:4119#include "ui/base/l10n/l10n_util.h"
[email protected]761fa4702013-07-02 15:25:1520#include "url/gurl.h"
[email protected]14a000d2010-04-29 21:44:2421
[email protected]631bb742011-11-02 11:29:3922using content::BrowserThread;
23
asanka655d1112015-03-07 05:33:4124namespace platform_util {
25
[email protected]7c3228a2011-11-11 21:35:2226namespace {
[email protected]14a000d2010-04-29 21:44:2427
[email protected]7c3228a2011-11-11 21:35:2228const char kGmailComposeUrl[] =
[email protected]8ef47722010-05-13 23:43:4529 "https://mail.google.com/mail/?extsrc=mailto&url=";
30
asanka655d1112015-03-07 05:33:4131void 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
scottmg34c5dd882016-02-03 05:21:5461 Browser* browser = chrome::FindTabbedBrowser(profile, false);
estadee16f96ed2016-03-07 22:57:0562 chrome::ShowWarningMessageBox(
asanka655d1112015-03-07 05:33:4163 browser ? browser->window()->GetNativeWindow() : nullptr,
64 l10n_util::GetStringFUTF16(IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE,
65 path.BaseName().AsUTF16Unsafe()),
estadee16f96ed2016-03-07 22:57:0566 l10n_util::GetStringUTF16(message_id));
asanka655d1112015-03-07 05:33:4167}
68
[email protected]7c3228a2011-11-11 21:35:2269} // namespace
70
asanka655d1112015-03-07 05:33:4171namespace internal {
72
73void DisableShellOperationsForTesting() {
74 file_manager::util::DisableShellOperationsForTesting();
75}
76
77} // namespace internal
[email protected]7c3228a2011-11-11 21:35:2278
[email protected]4d225de12013-12-13 09:29:1779void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
thestig00844cea2015-09-08 21:44:5280 DCHECK_CURRENTLY_ON(BrowserThread::UI);
asanka655d1112015-03-07 05:33:4181 file_manager::util::ShowItemInFolder(
82 profile, full_path,
83 base::Bind(&ShowWarningOnOpenOperationResult, profile, full_path));
[email protected]7c3228a2011-11-11 21:35:2284}
85
asanka655d1112015-03-07 05:33:4186void 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]7c3228a2011-11-11 21:35:2296}
97
[email protected]7f0a3efa2013-12-12 17:16:1298void OpenExternal(Profile* profile, const GURL& url) {
asanka655d1112015-03-07 05:33:4199 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]7f0a3efa2013-12-12 17:16:12100
[email protected]899dfca2012-05-08 16:47:40101 // 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 Defresnec6ccc77d2014-09-19 10:19:35110 chrome::NavigateParams params(profile, url, ui::PAGE_TRANSITION_LINK);
[email protected]7f0a3efa2013-12-12 17:16:12111 params.disposition = NEW_FOREGROUND_TAB;
[email protected]7f0a3efa2013-12-12 17:16:12112
[email protected]8ef47722010-05-13 23:43:45113 if (url.SchemeIs("mailto")) {
114 std::string string_url = kGmailComposeUrl;
115 string_url.append(url.spec());
[email protected]7f0a3efa2013-12-12 17:16:12116 params.url = GURL(url);
[email protected]8ef47722010-05-13 23:43:45117 }
[email protected]7f0a3efa2013-12-12 17:16:12118
119 chrome::Navigate(&params);
[email protected]14a000d2010-04-29 21:44:24120}
121
122} // namespace platform_util