• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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.
4 
5 #include "chrome/browser/platform_util.h"
6 
7 #include "base/file_util.h"
8 #include "base/process_util.h"
9 #include "base/task.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/extensions/file_manager_util.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "content/browser/browser_thread.h"
16 #include "content/common/process_watcher.h"
17 #include "googleurl/src/gurl.h"
18 
19 class Profile;
20 
21 namespace platform_util {
22 
23 static const std::string kGmailComposeUrl =
24     "https://mail.google.com/mail/?extsrc=mailto&url=";
25 
26 // Opens file browser on UI thread.
OpenFileBrowserOnUIThread(const FilePath & dir)27 void OpenFileBrowserOnUIThread(const FilePath& dir) {
28   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
29 
30   Browser* browser = BrowserList::GetLastActive();
31   if (!browser)
32     return;
33   GURL url = FileManagerUtil::GetFileBrowserUrlWithParams(
34      SelectFileDialog::SELECT_NONE, string16(), dir, NULL, 0,
35      FilePath::StringType());
36   browser->ShowSingletonTab(url);
37 }
38 
ShowItemInFolder(const FilePath & full_path)39 void ShowItemInFolder(const FilePath& full_path) {
40   FilePath dir = full_path.DirName();
41   if (!file_util::DirectoryExists(dir))
42     return;
43 
44   if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
45     OpenFileBrowserOnUIThread(dir);
46   } else {
47     BrowserThread::PostTask(
48         BrowserThread::UI, FROM_HERE,
49         NewRunnableFunction(&OpenFileBrowserOnUIThread, dir));
50   }
51 }
52 
OpenItem(const FilePath & full_path)53 void OpenItem(const FilePath& full_path) {
54   FileManagerUtil::ViewItem(full_path, false);
55 }
56 
OpenURL(const std::string & url)57 static void OpenURL(const std::string& url) {
58   Browser* browser = BrowserList::GetLastActive();
59   browser->AddSelectedTabWithURL(GURL(url), PageTransition::LINK);
60 }
61 
OpenExternal(const GURL & url)62 void OpenExternal(const GURL& url) {
63   if (url.SchemeIs("mailto")) {
64     std::string string_url = kGmailComposeUrl;
65     string_url.append(url.spec());
66     BrowserThread::PostTask(
67         BrowserThread::UI, FROM_HERE, NewRunnableFunction(OpenURL, string_url));
68   }
69 }
70 
71 }  // namespace platform_util
72