1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/platform_util.h"
8 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_navigator.h"
12 #include "chrome/browser/ui/host_desktop.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "googleurl/src/gurl.h"
17 using content::BrowserThread
;
21 const char kGmailComposeUrl
[] =
22 "https://mail.google.com/mail/?extsrc=mailto&url=";
24 void OpenURL(const std::string
& url
) {
25 // TODO(beng): improve this to locate context from call stack.
26 Browser
* browser
= chrome::FindOrCreateTabbedBrowser(
27 ProfileManager::GetDefaultProfileOrOffTheRecord(),
28 chrome::HOST_DESKTOP_TYPE_ASH
);
29 chrome::NavigateParams
params(
30 browser
, GURL(url
), content::PAGE_TRANSITION_LINK
);
31 params
.disposition
= NEW_FOREGROUND_TAB
;
32 chrome::Navigate(¶ms
);
37 namespace platform_util
{
39 void ShowItemInFolder(const base::FilePath
& full_path
) {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
41 file_manager_util::ShowFileInFolder(full_path
);
44 void OpenItem(const base::FilePath
& full_path
) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
46 file_manager_util::ViewItem(full_path
);
49 void OpenExternal(const GURL
& url
) {
50 // This code should be obsolete since we have default handlers in ChromeOS
51 // which should handle this. However - there are two things which make it
52 // necessary to keep it in:
53 // a.) The user might have deleted the default handler in this session.
54 // In this case we would need to have this in place.
55 // b.) There are several code paths which are not clear if they would call
56 // this function directly and which would therefore break (e.g.
57 // "Browser::EmailPageLocation" (to name only one).
58 // As such we should keep this code here.
59 if (url
.SchemeIs("mailto")) {
60 std::string string_url
= kGmailComposeUrl
;
61 string_url
.append(url
.spec());
62 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
63 base::Bind(OpenURL
, string_url
));
67 } // namespace platform_util