| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/platform_util.h" | 5 #include "chrome/browser/platform_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 11 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 12 #include "chrome/browser/tabs/tab_strip_model.h" | 12 #include "chrome/browser/tabs/tab_strip_model.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 | 17 |
| 18 using content::BrowserThread; | 18 using content::BrowserThread; |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kGmailComposeUrl[] = | 24 const char kGmailComposeUrl[] = |
| 25 "https://mail.google.com/mail/?extsrc=mailto&url="; | 25 "https://mail.google.com/mail/?extsrc=mailto&url="; |
| 26 | 26 |
| 27 void OpenFileBrowserOnUIThread(const FilePath& dir) { | |
| 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 29 | |
| 30 Browser* browser = BrowserList::GetLastActive(); | |
| 31 if (!browser) | |
| 32 return; | |
| 33 | |
| 34 FilePath virtual_path; | |
| 35 if (!file_manager_util::ConvertFileToRelativeFileSystemPath( | |
| 36 browser->profile(), dir, &virtual_path)) { | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 GURL url = file_manager_util::GetFileBrowserUrlWithParams( | |
| 41 SelectFileDialog::SELECT_NONE, string16(), virtual_path, NULL, 0, | |
| 42 FilePath::StringType()); | |
| 43 browser->ShowSingletonTab(url); | |
| 44 } | |
| 45 | |
| 46 // file_util::DirectoryExists must be called on the FILE thread. | |
| 47 void ShowItemInFolderOnFileThread(const FilePath& full_path) { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
| 49 FilePath dir = full_path.DirName(); | |
| 50 if (file_util::DirectoryExists(dir)) { | |
| 51 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 52 base::Bind(&OpenFileBrowserOnUIThread, dir)); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void OpenItemOnFileThread(const FilePath& full_path) { | 27 void OpenItemOnFileThread(const FilePath& full_path) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 58 base::Closure callback; | 29 base::Closure callback; |
| 59 if (file_util::DirectoryExists(full_path)) | 30 if (file_util::DirectoryExists(full_path)) |
| 60 callback = base::Bind(&file_manager_util::ViewFolder, full_path); | 31 callback = base::Bind(&file_manager_util::ViewFolder, full_path); |
| 61 else | 32 else |
| 62 callback = base::Bind(&file_manager_util::ViewFile, full_path, false); | 33 callback = base::Bind(&file_manager_util::ViewFile, full_path, false); |
| 63 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 34 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| 64 } | 35 } |
| 65 | 36 |
| 66 void OpenURL(const std::string& url) { | 37 void OpenURL(const std::string& url) { |
| 67 Browser* browser = BrowserList::GetLastActive(); | 38 Browser* browser = BrowserList::GetLastActive(); |
| 68 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); | 39 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); |
| 69 } | 40 } |
| 70 | 41 |
| 71 } // namespace | 42 } // namespace |
| 72 | 43 |
| 73 namespace platform_util { | 44 namespace platform_util { |
| 74 | 45 |
| 75 void ShowItemInFolder(const FilePath& full_path) { | 46 void ShowItemInFolder(const FilePath& full_path) { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 77 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 48 file_manager_util::ShowFileInFolder(full_path); |
| 78 base::Bind(&ShowItemInFolderOnFileThread, full_path)); | |
| 79 } | 49 } |
| 80 | 50 |
| 81 void OpenItem(const FilePath& full_path) { | 51 void OpenItem(const FilePath& full_path) { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 83 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 53 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 84 base::Bind(&OpenItemOnFileThread, full_path)); | 54 base::Bind(&OpenItemOnFileThread, full_path)); |
| 85 } | 55 } |
| 86 | 56 |
| 87 void OpenExternal(const GURL& url) { | 57 void OpenExternal(const GURL& url) { |
| 88 if (url.SchemeIs("mailto")) { | 58 if (url.SchemeIs("mailto")) { |
| 89 std::string string_url = kGmailComposeUrl; | 59 std::string string_url = kGmailComposeUrl; |
| 90 string_url.append(url.spec()); | 60 string_url.append(url.spec()); |
| 91 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 61 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 92 base::Bind(OpenURL, string_url)); | 62 base::Bind(OpenURL, string_url)); |
| 93 } | 63 } |
| 94 } | 64 } |
| 95 | 65 |
| 96 } // namespace platform_util | 66 } // namespace platform_util |
| OLD | NEW |