Chromium Code Reviews| 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/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/process/kill.h" | 9 #include "base/process/kill.h" |
| 10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/platform_util_internal.h" | |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 using content::BrowserThread; | 16 using content::BrowserThread; |
| 16 | 17 |
| 18 namespace platform_util { | |
| 19 | |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 void XDGUtil(const std::string& util, const std::string& arg) { | 22 void XDGUtil(const std::string& util, const std::string& arg) { |
| 20 std::vector<std::string> argv; | 23 std::vector<std::string> argv; |
| 21 argv.push_back(util); | 24 argv.push_back(util); |
| 22 argv.push_back(arg); | 25 argv.push_back(arg); |
| 23 | 26 |
| 24 base::LaunchOptions options; | 27 base::LaunchOptions options; |
| 25 options.allow_new_privs = true; | 28 options.allow_new_privs = true; |
| 26 // xdg-open can fall back on mailcap which eventually might plumb through | 29 // xdg-open can fall back on mailcap which eventually might plumb through |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 43 } | 46 } |
| 44 | 47 |
| 45 void XDGOpen(const std::string& path) { | 48 void XDGOpen(const std::string& path) { |
| 46 XDGUtil("xdg-open", path); | 49 XDGUtil("xdg-open", path); |
| 47 } | 50 } |
| 48 | 51 |
| 49 void XDGEmail(const std::string& email) { | 52 void XDGEmail(const std::string& email) { |
| 50 XDGUtil("xdg-email", email); | 53 XDGUtil("xdg-email", email); |
| 51 } | 54 } |
| 52 | 55 |
| 53 // TODO(estade): It would be nice to be able to select the file in the file | |
| 54 // manager, but that probably requires extending xdg-open. For now just | |
| 55 // show the folder. | |
| 56 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { | |
| 57 base::FilePath dir = full_path.DirName(); | |
| 58 if (!base::DirectoryExists(dir)) | |
| 59 return; | |
| 60 | |
| 61 XDGOpen(dir.value()); | |
| 62 } | |
| 63 | |
| 64 } // namespace | 56 } // namespace |
| 65 | 57 |
| 66 namespace platform_util { | 58 namespace internal { |
| 59 | |
| 60 void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType) { | |
| 61 XDGOpen(path.value()); | |
|
rickyz (no longer on Chrome)
2015/02/04 23:19:30
Now that https://codereview.chromium.org/885423003
asanka
2015/02/05 18:07:25
Did so. PTAL?
| |
| 62 } | |
| 63 } | |
| 67 | 64 |
| 68 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { | 65 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 67 // TODO(estade): It would be nice to be able to select the file in the file |
| 71 base::Bind(&ShowItemInFolderOnFileThread, full_path)); | 68 // manager, but that probably requires extending xdg-open. For now just show |
| 72 } | 69 // the folder. |
| 73 | 70 OpenFolder(profile, full_path.DirName(), OpenOperationCallback()); |
| 74 void OpenItem(Profile* profile, const base::FilePath& full_path) { | |
| 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 76 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 77 base::Bind(&XDGOpen, full_path.value())); | |
| 78 } | 71 } |
| 79 | 72 |
| 80 void OpenExternal(Profile* profile, const GURL& url) { | 73 void OpenExternal(Profile* profile, const GURL& url) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 if (url.SchemeIs("mailto")) | 75 if (url.SchemeIs("mailto")) |
| 83 XDGEmail(url.spec()); | 76 XDGEmail(url.spec()); |
| 84 else | 77 else |
| 85 XDGOpen(url.spec()); | 78 XDGOpen(url.spec()); |
| 86 } | 79 } |
| 87 | 80 |
| 88 } // namespace platform_util | 81 } // namespace platform_util |
| OLD | NEW |