blob: ae27115522b0025130385dc5bcdea14f4854110e [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]bc76cc52013-04-09 03:57:358#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
[email protected]4e8b38a2012-05-24 20:48:049#include "chrome/browser/profiles/profile_manager.h"
[email protected]d04f59d2012-07-13 23:07:5210#include "chrome/browser/ui/browser_finder.h"
[email protected]4e8b38a2012-05-24 20:48:0411#include "chrome/browser/ui/browser_navigator.h"
[email protected]3b14b7f22012-10-04 01:29:0912#include "chrome/browser/ui/host_desktop.h"
[email protected]b56e2e32012-05-11 21:18:0413#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]c38831a12011-10-28 12:44:4914#include "content/public/browser/browser_thread.h"
[email protected]761fa4702013-07-02 15:25:1515#include "url/gurl.h"
[email protected]14a000d2010-04-29 21:44:2416
[email protected]631bb742011-11-02 11:29:3917using content::BrowserThread;
18
[email protected]7c3228a2011-11-11 21:35:2219namespace {
[email protected]14a000d2010-04-29 21:44:2420
[email protected]7c3228a2011-11-11 21:35:2221const char kGmailComposeUrl[] =
[email protected]8ef47722010-05-13 23:43:4522 "https://mail.google.com/mail/?extsrc=mailto&url=";
23
[email protected]7c3228a2011-11-11 21:35:2224void OpenURL(const std::string& url) {
[email protected]4e8b38a2012-05-24 20:48:0425 // TODO(beng): improve this to locate context from call stack.
[email protected]7b0957f2012-12-26 22:23:0826 Browser* browser = chrome::FindOrCreateTabbedBrowser(
[email protected]3b14b7f22012-10-04 01:29:0927 ProfileManager::GetDefaultProfileOrOffTheRecord(),
28 chrome::HOST_DESKTOP_TYPE_ASH);
[email protected]d04f59d2012-07-13 23:07:5229 chrome::NavigateParams params(
30 browser, GURL(url), content::PAGE_TRANSITION_LINK);
[email protected]4e8b38a2012-05-24 20:48:0431 params.disposition = NEW_FOREGROUND_TAB;
[email protected]82f2a4d2013-07-02 19:31:4132 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:2833 chrome::Navigate(&params);
[email protected]8ef47722010-05-13 23:43:4534}
[email protected]14a000d2010-04-29 21:44:2435
[email protected]7c3228a2011-11-11 21:35:2236} // namespace
37
38namespace platform_util {
39
[email protected]650b2d52013-02-10 03:41:4540void ShowItemInFolder(const base::FilePath& full_path) {
[email protected]7c3228a2011-11-11 21:35:2241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]93869f3a2012-04-17 11:04:1242 file_manager_util::ShowFileInFolder(full_path);
[email protected]7c3228a2011-11-11 21:35:2243}
44
[email protected]650b2d52013-02-10 03:41:4545void OpenItem(const base::FilePath& full_path) {
[email protected]7c3228a2011-11-11 21:35:2246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]edf99a22013-01-22 12:39:2847 file_manager_util::ViewItem(full_path);
[email protected]7c3228a2011-11-11 21:35:2248}
49
[email protected]8ef47722010-05-13 23:43:4550void OpenExternal(const GURL& url) {
[email protected]899dfca2012-05-08 16:47:4051 // 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]8ef47722010-05-13 23:43:4560 if (url.SchemeIs("mailto")) {
61 std::string string_url = kGmailComposeUrl;
62 string_url.append(url.spec());
[email protected]7c3228a2011-11-11 21:35:2263 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
64 base::Bind(OpenURL, string_url));
[email protected]82f2a4d2013-07-02 19:31:4165 } else if (url.is_valid()) {
66 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
67 base::Bind(OpenURL, url.spec()));
[email protected]8ef47722010-05-13 23:43:4568 }
[email protected]14a000d2010-04-29 21:44:2469}
70
71} // namespace platform_util