blob: 4f75cc1430a790cf240d9214db4f7761c91b6e79 [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
[email protected]7c3228a2011-11-11 21:35:227#include "base/bind.h"
[email protected]c6944272012-01-06 22:12:288#include "base/callback.h"
[email protected]14a000d2010-04-29 21:44:249#include "base/file_util.h"
[email protected]14a000d2010-04-29 21:44:2410#include "base/utf_string_conversions.h"
[email protected]7df1dad2012-02-27 11:19:5111#include "chrome/browser/chromeos/extensions/file_manager_util.h"
[email protected]94bda202011-04-18 23:31:0012#include "chrome/browser/ui/browser.h"
[email protected]71b73f02011-04-06 15:57:2913#include "chrome/browser/ui/browser_list.h"
[email protected]b56e2e32012-05-11 21:18:0414#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]c38831a12011-10-28 12:44:4915#include "content/public/browser/browser_thread.h"
[email protected]14a000d2010-04-29 21:44:2416#include "googleurl/src/gurl.h"
17
[email protected]631bb742011-11-02 11:29:3918using content::BrowserThread;
19
[email protected]14a000d2010-04-29 21:44:2420class Profile;
21
[email protected]7c3228a2011-11-11 21:35:2222namespace {
[email protected]14a000d2010-04-29 21:44:2423
[email protected]7c3228a2011-11-11 21:35:2224const char kGmailComposeUrl[] =
[email protected]8ef47722010-05-13 23:43:4525 "https://mail.google.com/mail/?extsrc=mailto&url=";
26
[email protected]7c3228a2011-11-11 21:35:2227void OpenItemOnFileThread(const FilePath& full_path) {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
29 base::Closure callback;
30 if (file_util::DirectoryExists(full_path))
[email protected]81c5dea2011-11-17 23:38:3731 callback = base::Bind(&file_manager_util::ViewFolder, full_path);
[email protected]7c3228a2011-11-11 21:35:2232 else
[email protected]bea17662012-04-17 15:56:0833 callback = base::Bind(&file_manager_util::ViewFile, full_path);
[email protected]7c3228a2011-11-11 21:35:2234 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
[email protected]14a000d2010-04-29 21:44:2435}
36
[email protected]7c3228a2011-11-11 21:35:2237void OpenURL(const std::string& url) {
[email protected]8ef47722010-05-13 23:43:4538 Browser* browser = BrowserList::GetLastActive();
[email protected]2905f742011-10-13 03:51:5839 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK);
[email protected]8ef47722010-05-13 23:43:4540}
[email protected]14a000d2010-04-29 21:44:2441
[email protected]7c3228a2011-11-11 21:35:2242} // namespace
43
44namespace platform_util {
45
46void ShowItemInFolder(const FilePath& full_path) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]93869f3a2012-04-17 11:04:1248 file_manager_util::ShowFileInFolder(full_path);
[email protected]7c3228a2011-11-11 21:35:2249}
50
51void 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]8ef47722010-05-13 23:43:4557void OpenExternal(const GURL& url) {
[email protected]899dfca2012-05-08 16:47:4058 // 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]8ef47722010-05-13 23:43:4567 if (url.SchemeIs("mailto")) {
68 std::string string_url = kGmailComposeUrl;
69 string_url.append(url.spec());
[email protected]7c3228a2011-11-11 21:35:2270 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
71 base::Bind(OpenURL, string_url));
[email protected]8ef47722010-05-13 23:43:4572 }
[email protected]14a000d2010-04-29 21:44:2473}
74
75} // namespace platform_util