[email protected] | 7df1dad | 2012-02-27 11:19:51 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 2 | // 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 | |||||
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | bc76cc5 | 2013-04-09 03:57:35 | [diff] [blame] | 8 | #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" |
[email protected] | 4e8b38a | 2012-05-24 20:48:04 | [diff] [blame] | 9 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | d04f59d | 2012-07-13 23:07:52 | [diff] [blame] | 10 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 4e8b38a | 2012-05-24 20:48:04 | [diff] [blame] | 11 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | 3b14b7f2 | 2012-10-04 01:29:09 | [diff] [blame] | 12 | #include "chrome/browser/ui/host_desktop.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 13 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 14 | #include "content/public/browser/browser_thread.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 15 | #include "url/gurl.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 16 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 17 | using content::BrowserThread; |
18 | |||||
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 19 | namespace { |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 20 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 21 | const char kGmailComposeUrl[] = |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 22 | "https://mail.google.com/mail/?extsrc=mailto&url="; |
23 | |||||
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 24 | void OpenURL(const std::string& url) { |
[email protected] | 4e8b38a | 2012-05-24 20:48:04 | [diff] [blame] | 25 | // TODO(beng): improve this to locate context from call stack. |
[email protected] | 7b0957f | 2012-12-26 22:23:08 | [diff] [blame] | 26 | Browser* browser = chrome::FindOrCreateTabbedBrowser( |
[email protected] | 3b14b7f2 | 2012-10-04 01:29:09 | [diff] [blame] | 27 | ProfileManager::GetDefaultProfileOrOffTheRecord(), |
28 | chrome::HOST_DESKTOP_TYPE_ASH); | ||||
[email protected] | d04f59d | 2012-07-13 23:07:52 | [diff] [blame] | 29 | chrome::NavigateParams params( |
30 | browser, GURL(url), content::PAGE_TRANSITION_LINK); | ||||
[email protected] | 4e8b38a | 2012-05-24 20:48:04 | [diff] [blame] | 31 | params.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 82f2a4d | 2013-07-02 19:31:41 | [diff] [blame] | 32 | params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 33 | chrome::Navigate(¶ms); |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 34 | } |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 35 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 36 | } // namespace |
37 | |||||
38 | namespace platform_util { | ||||
39 | |||||
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 40 | void ShowItemInFolder(const base::FilePath& full_path) { |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 41 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 93869f3a | 2012-04-17 11:04:12 | [diff] [blame] | 42 | file_manager_util::ShowFileInFolder(full_path); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 43 | } |
44 | |||||
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 45 | void OpenItem(const base::FilePath& full_path) { |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 46 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | edf99a2 | 2013-01-22 12:39:28 | [diff] [blame] | 47 | file_manager_util::ViewItem(full_path); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 48 | } |
49 | |||||
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 50 | void OpenExternal(const GURL& url) { |
[email protected] | 899dfca | 2012-05-08 16:47:40 | [diff] [blame] | 51 | // This code should be obsolete since we have default handlers in ChromeOS |
52 | // which should handle this. However - there are two things which make it | ||||
53 | // necessary to keep it in: | ||||
54 | // a.) The user might have deleted the default handler in this session. | ||||
55 | // In this case we would need to have this in place. | ||||
56 | // b.) There are several code paths which are not clear if they would call | ||||
57 | // this function directly and which would therefore break (e.g. | ||||
58 | // "Browser::EmailPageLocation" (to name only one). | ||||
59 | // As such we should keep this code here. | ||||
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 60 | if (url.SchemeIs("mailto")) { |
61 | std::string string_url = kGmailComposeUrl; | ||||
62 | string_url.append(url.spec()); | ||||
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 63 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
64 | base::Bind(OpenURL, string_url)); | ||||
[email protected] | 82f2a4d | 2013-07-02 19:31:41 | [diff] [blame] | 65 | } else if (url.is_valid()) { |
66 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | ||||
67 | base::Bind(OpenURL, url.spec())); | ||||
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 68 | } |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 69 | } |
70 | |||||
71 | } // namespace platform_util |