[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] | c694427 | 2012-01-06 22:12:28 | [diff] [blame] | 8 | #include "base/callback.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 9 | #include "base/file_util.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 10 | #include "base/utf_string_conversions.h" |
[email protected] | 7df1dad | 2012-02-27 11:19:51 | [diff] [blame] | 11 | #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
[email protected] | 94bda20 | 2011-04-18 23:31:00 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame^] | 14 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 15 | #include "content/public/browser/browser_thread.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 16 | #include "googleurl/src/gurl.h" |
| 17 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 18 | using content::BrowserThread; |
| 19 | |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 20 | class Profile; |
| 21 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 22 | namespace { |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 23 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 24 | const char kGmailComposeUrl[] = |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 25 | "https://mail.google.com/mail/?extsrc=mailto&url="; |
| 26 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 27 | void OpenItemOnFileThread(const FilePath& full_path) { |
| 28 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 29 | base::Closure callback; |
| 30 | if (file_util::DirectoryExists(full_path)) |
[email protected] | 81c5dea | 2011-11-17 23:38:37 | [diff] [blame] | 31 | callback = base::Bind(&file_manager_util::ViewFolder, full_path); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 32 | else |
[email protected] | bea1766 | 2012-04-17 15:56:08 | [diff] [blame] | 33 | callback = base::Bind(&file_manager_util::ViewFile, full_path); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 34 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 37 | void OpenURL(const std::string& url) { |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 38 | Browser* browser = BrowserList::GetLastActive(); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 39 | browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 40 | } |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 41 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 42 | } // namespace |
| 43 | |
| 44 | namespace platform_util { |
| 45 | |
| 46 | void ShowItemInFolder(const FilePath& full_path) { |
| 47 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 93869f3a | 2012-04-17 11:04:12 | [diff] [blame] | 48 | file_manager_util::ShowFileInFolder(full_path); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void OpenItem(const FilePath& full_path) { |
| 52 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 53 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 54 | base::Bind(&OpenItemOnFileThread, full_path)); |
| 55 | } |
| 56 | |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 57 | void OpenExternal(const GURL& url) { |
[email protected] | 899dfca | 2012-05-08 16:47:40 | [diff] [blame] | 58 | // This code should be obsolete since we have default handlers in ChromeOS |
| 59 | // which should handle this. However - there are two things which make it |
| 60 | // necessary to keep it in: |
| 61 | // a.) The user might have deleted the default handler in this session. |
| 62 | // In this case we would need to have this in place. |
| 63 | // b.) There are several code paths which are not clear if they would call |
| 64 | // this function directly and which would therefore break (e.g. |
| 65 | // "Browser::EmailPageLocation" (to name only one). |
| 66 | // As such we should keep this code here. |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 67 | if (url.SchemeIs("mailto")) { |
| 68 | std::string string_url = kGmailComposeUrl; |
| 69 | string_url.append(url.spec()); |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 70 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 71 | base::Bind(OpenURL, string_url)); |
[email protected] | 8ef4772 | 2010-05-13 23:43:45 | [diff] [blame] | 72 | } |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | } // namespace platform_util |