OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/extensions/file_manager_util.h" | 4 #include "chrome/browser/extensions/file_manager_util.h" |
5 | 5 |
6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/media/media_player.h" |
11 #include "chrome/browser/platform_util.h" | 12 #include "chrome/browser/platform_util.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/browser/ui/webui/mediaplayer_ui.h" | |
16 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
17 #include "content/browser/user_metrics.h" | 17 #include "content/browser/user_metrics.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "third_party/libjingle/source/talk/base/urlencode.h" | 19 #include "third_party/libjingle/source/talk/base/urlencode.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "webkit/fileapi/file_system_context.h" | 21 #include "webkit/fileapi/file_system_context.h" |
22 #include "webkit/fileapi/file_system_mount_point_provider.h" | 22 #include "webkit/fileapi/file_system_mount_point_provider.h" |
23 #include "webkit/fileapi/file_system_util.h" | 23 #include "webkit/fileapi/file_system_util.h" |
24 | 24 |
| 25 #define FILEBROWSER_URL(PATH) \ |
| 26 ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/" PATH) |
25 // This is the "well known" url for the file manager extension from | 27 // This is the "well known" url for the file manager extension from |
26 // browser/resources/file_manager. In the future we may provide a way to swap | 28 // browser/resources/file_manager. In the future we may provide a way to swap |
27 // out this file manager for an aftermarket part, but not yet. | 29 // out this file manager for an aftermarket part, but not yet. |
28 const char kBaseFileBrowserUrl[] = | 30 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); |
29 "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html"; | 31 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); |
| 32 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); |
| 33 #undef FILEBROWSER_URL |
| 34 |
30 // List of file extension we can open in tab. | 35 // List of file extension we can open in tab. |
31 const char* kBrowserSupportedExtensions[] = { | 36 const char* kBrowserSupportedExtensions[] = { |
32 ".jpg", ".jpeg", ".png", ".webp", ".gif", ".pdf", ".txt", ".html", ".htm" | 37 ".jpg", ".jpeg", ".png", ".webp", ".gif", ".pdf", ".txt", ".html", ".htm" |
33 }; | 38 }; |
34 // List of file extension that can be handled with the media player. | 39 // List of file extension that can be handled with the media player. |
35 const char* kAVExtensions[] = { | 40 const char* kAVExtensions[] = { |
36 ".webm", ".mp4", ".m4v", ".mov", ".ogm", ".ogv", ".ogx", | 41 ".webm", ".mp4", ".m4v", ".mov", ".ogm", ".ogv", ".ogx", |
37 ".mp3", ".m4a", ".ogg", ".oga", ".wav", | 42 ".mp3", ".m4a", ".ogg", ".oga", ".wav", |
38 /* TODO(zelidrag): Add unsupported ones as we enable them: | 43 /* TODO(zelidrag): Add unsupported ones as we enable them: |
39 ".3gp", ".mkv", ".avi", ".divx", ".xvid", ".wmv", ".asf", ".mpeg", ".mpg", | 44 ".3gp", ".mkv", ".avi", ".divx", ".xvid", ".wmv", ".asf", ".mpeg", ".mpg", |
(...skipping 18 matching lines...) Expand all Loading... |
58 } | 63 } |
59 return false; | 64 return false; |
60 } | 65 } |
61 | 66 |
62 // static | 67 // static |
63 GURL FileManagerUtil::GetFileBrowserUrl() { | 68 GURL FileManagerUtil::GetFileBrowserUrl() { |
64 return GURL(kBaseFileBrowserUrl); | 69 return GURL(kBaseFileBrowserUrl); |
65 } | 70 } |
66 | 71 |
67 // static | 72 // static |
| 73 GURL FileManagerUtil::GetMediaPlayerUrl() { |
| 74 return GURL(kMediaPlayerUrl); |
| 75 } |
| 76 |
| 77 // static |
| 78 GURL FileManagerUtil::GetMediaPlayerPlaylistUrl() { |
| 79 return GURL(kMediaPlayerPlaylistUrl); |
| 80 } |
| 81 |
| 82 // static |
68 bool FileManagerUtil::ConvertFileToFileSystemUrl( | 83 bool FileManagerUtil::ConvertFileToFileSystemUrl( |
69 Profile* profile, const FilePath& full_file_path, const GURL& origin_url, | 84 Profile* profile, const FilePath& full_file_path, const GURL& origin_url, |
70 GURL* url) { | 85 GURL* url) { |
71 fileapi::FileSystemPathManager* path_manager = | 86 fileapi::FileSystemPathManager* path_manager = |
72 profile->GetFileSystemContext()->path_manager(); | 87 profile->GetFileSystemContext()->path_manager(); |
73 fileapi::ExternalFileSystemMountPointProvider* provider = | 88 fileapi::ExternalFileSystemMountPointProvider* provider = |
74 path_manager->external_provider(); | 89 path_manager->external_provider(); |
75 if (!provider) | 90 if (!provider) |
76 return false; | 91 return false; |
77 | 92 |
78 // Find if this file path is managed by the external provider. | 93 // Find if this file path is managed by the external provider. |
79 std::vector<FilePath> root_dirs = provider->GetRootDirectories(); | 94 FilePath virtual_path; |
80 for (std::vector<FilePath>::iterator iter = root_dirs.begin(); | 95 if (!provider->GetVirtualPath(full_file_path, &virtual_path)) |
81 iter != root_dirs.end(); | 96 return false; |
82 ++iter) { | 97 |
83 FilePath path; | 98 GURL base_url = fileapi::GetFileSystemRootURI(origin_url, |
84 std::vector<FilePath::StringType> components; | 99 fileapi::kFileSystemTypeExternal); |
85 const FilePath& root_path = *iter; | 100 *url = GURL(base_url.spec() + virtual_path.value()); |
86 root_path.GetComponents(&components); | 101 return true; |
87 if (!components.size()) { | |
88 NOTREACHED(); | |
89 continue; | |
90 } | |
91 if (root_path.AppendRelativePath(full_file_path, &path)) { | |
92 GURL base_url = fileapi::GetFileSystemRootURI(origin_url, | |
93 fileapi::kFileSystemTypeExternal); | |
94 std::string final_url = base_url.spec(); | |
95 FilePath relative_path(components[components.size() - 1]); | |
96 *url = GURL(base_url.spec() + relative_path.Append(path).value()); | |
97 return true; | |
98 } | |
99 } | |
100 return false; | |
101 } | 102 } |
102 | 103 |
103 // static | 104 // static |
104 GURL FileManagerUtil::GetFileBrowserUrlWithParams( | 105 GURL FileManagerUtil::GetFileBrowserUrlWithParams( |
105 SelectFileDialog::Type type, | 106 SelectFileDialog::Type type, |
106 const string16& title, | 107 const string16& title, |
107 const FilePath& default_path, | 108 const FilePath& default_path, |
108 const SelectFileDialog::FileTypeInfo* file_types, | 109 const SelectFileDialog::FileTypeInfo* file_types, |
109 int file_type_index, | 110 int file_type_index, |
110 const FilePath::StringType& default_extension) { | 111 const FilePath::StringType& default_extension) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: | 245 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: |
245 type_str = "open-multi-file"; | 246 type_str = "open-multi-file"; |
246 break; | 247 break; |
247 | 248 |
248 default: | 249 default: |
249 NOTREACHED(); | 250 NOTREACHED(); |
250 } | 251 } |
251 | 252 |
252 return type_str; | 253 return type_str; |
253 } | 254 } |
OLD | NEW |