| 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/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/path_service.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/plugin_prefs.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/simple_message_box.h" | 16 #include "chrome/browser/simple_message_box.h" |
| 15 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 18 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
| 22 #include "content/browser/plugin_service.h" |
| 19 #include "content/browser/user_metrics.h" | 23 #include "content/browser/user_metrics.h" |
| 20 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 21 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "webkit/fileapi/file_system_context.h" | 27 #include "webkit/fileapi/file_system_context.h" |
| 24 #include "webkit/fileapi/file_system_mount_point_provider.h" | 28 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 25 #include "webkit/fileapi/file_system_util.h" | 29 #include "webkit/fileapi/file_system_util.h" |
| 26 | 30 |
| 27 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 28 #include "chrome/browser/chromeos/media/media_player.h" | 32 #include "chrome/browser/chromeos/media/media_player.h" |
| 29 #endif | 33 #endif |
| 30 | 34 |
| 31 #define FILEBROWSER_DOMAIN "hhaomjibdihmijegdhdafkllkbggdgoj" | 35 #define FILEBROWSER_DOMAIN "hhaomjibdihmijegdhdafkllkbggdgoj" |
| 32 const char kFileBrowserDomain[] = FILEBROWSER_DOMAIN; | 36 const char kFileBrowserDomain[] = FILEBROWSER_DOMAIN; |
| 33 #define FILEBROWSER_URL(PATH) \ | 37 #define FILEBROWSER_URL(PATH) \ |
| 34 ("chrome-extension://" FILEBROWSER_DOMAIN "/" PATH) | 38 ("chrome-extension://" FILEBROWSER_DOMAIN "/" PATH) |
| 35 // This is the "well known" url for the file manager extension from | 39 // This is the "well known" url for the file manager extension from |
| 36 // browser/resources/file_manager. In the future we may provide a way to swap | 40 // browser/resources/file_manager. In the future we may provide a way to swap |
| 37 // out this file manager for an aftermarket part, but not yet. | 41 // out this file manager for an aftermarket part, but not yet. |
| 38 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL(""); | 42 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL(""); |
| 39 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); | 43 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); |
| 40 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); | 44 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); |
| 41 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); | 45 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); |
| 42 #undef FILEBROWSER_URL | 46 #undef FILEBROWSER_URL |
| 43 | 47 |
| 48 const char kPdfExtension[] = ".pdf"; |
| 44 // List of file extension we can open in tab. | 49 // List of file extension we can open in tab. |
| 45 const char* kBrowserSupportedExtensions[] = { | 50 const char* kBrowserSupportedExtensions[] = { |
| 46 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".pdf", ".txt", ".html", | 51 #if defined(GOOGLE_CHROME_BUILD) |
| 47 ".htm" | 52 ".pdf", |
| 53 #endif |
| 54 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".txt", ".html", ".htm" |
| 48 }; | 55 }; |
| 49 // List of file extension that can be handled with the media player. | 56 // List of file extension that can be handled with the media player. |
| 50 const char* kAVExtensions[] = { | 57 const char* kAVExtensions[] = { |
| 51 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 58 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 52 ".3gp", ".avi", ".mp3", ".mp4", ".m4v", ".mov", ".m4a", | 59 ".3gp", ".avi", ".mp3", ".mp4", ".m4v", ".mov", ".m4a", |
| 53 #endif | 60 #endif |
| 54 ".flac", ".ogm", ".ogv", ".ogx", ".ogg", ".oga", ".wav", ".webm", | 61 ".flac", ".ogm", ".ogv", ".ogx", ".ogg", ".oga", ".wav", ".webm", |
| 55 /* TODO(zelidrag): Add unsupported ones as we enable them: | 62 /* TODO(zelidrag): Add unsupported ones as we enable them: |
| 56 ".mkv", ".divx", ".xvid", ".wmv", ".asf", ".mpeg", ".mpg", | 63 ".mkv", ".divx", ".xvid", ".wmv", ".asf", ".mpeg", ".mpg", |
| 57 ".wma", ".aiff", | 64 ".wma", ".aiff", |
| (...skipping 20 matching lines...) Expand all Loading... |
| 78 | 85 |
| 79 bool IsSupportedAVExtension(const char* ext) { | 86 bool IsSupportedAVExtension(const char* ext) { |
| 80 for (size_t i = 0; i < arraysize(kAVExtensions); i++) { | 87 for (size_t i = 0; i < arraysize(kAVExtensions); i++) { |
| 81 if (base::strcasecmp(ext, kAVExtensions[i]) == 0) { | 88 if (base::strcasecmp(ext, kAVExtensions[i]) == 0) { |
| 82 return true; | 89 return true; |
| 83 } | 90 } |
| 84 } | 91 } |
| 85 return false; | 92 return false; |
| 86 } | 93 } |
| 87 | 94 |
| 95 // If pdf plugin is enabled, we should open pdf files in a tab. |
| 96 bool ShouldBeOpenedWithPdfPlugin(const char* ext) { |
| 97 if (base::strcasecmp(ext, kPdfExtension) != 0) |
| 98 return false; |
| 99 |
| 100 Browser* browser = BrowserList::GetLastActive(); |
| 101 if (!browser) |
| 102 return false; |
| 103 |
| 104 FilePath pdf_path; |
| 105 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 106 |
| 107 webkit::WebPluginInfo plugin; |
| 108 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) |
| 109 return false; |
| 110 |
| 111 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); |
| 112 if (!plugin_prefs) |
| 113 return false; |
| 114 |
| 115 return plugin_prefs->IsPluginEnabled(plugin); |
| 116 } |
| 117 |
| 88 // static | 118 // static |
| 89 GURL FileManagerUtil::GetFileBrowserExtensionUrl() { | 119 GURL FileManagerUtil::GetFileBrowserExtensionUrl() { |
| 90 return GURL(kFileBrowserExtensionUrl); | 120 return GURL(kFileBrowserExtensionUrl); |
| 91 } | 121 } |
| 92 | 122 |
| 93 // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last | 123 // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last |
| 94 // element's index is return (last element should have irrelevant value). | 124 // element's index is return (last element should have irrelevant value). |
| 95 int UMAExtensionIndex(const char *ext, | 125 int UMAExtensionIndex(const char *ext, |
| 96 const char** array, | 126 const char** array, |
| 97 size_t array_size) { | 127 size_t array_size) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 url += "#/" + EscapeUrlEncodedData(virtual_path.value(), false); | 249 url += "#/" + EscapeUrlEncodedData(virtual_path.value(), false); |
| 220 | 250 |
| 221 UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); | 251 UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); |
| 222 browser->ShowSingletonTabRespectRef(GURL(url)); | 252 browser->ShowSingletonTabRespectRef(GURL(url)); |
| 223 } | 253 } |
| 224 | 254 |
| 225 void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) { | 255 void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) { |
| 226 std::string ext = full_path.Extension(); | 256 std::string ext = full_path.Extension(); |
| 227 // For things supported natively by the browser, we should open it | 257 // For things supported natively by the browser, we should open it |
| 228 // in a tab. | 258 // in a tab. |
| 229 if (IsSupportedBrowserExtension(ext.data())) { | 259 if (IsSupportedBrowserExtension(ext.data()) || |
| 260 ShouldBeOpenedWithPdfPlugin(ext.data())) { |
| 230 std::string path; | 261 std::string path; |
| 231 path = "file://"; | 262 path = "file://"; |
| 232 path.append(EscapeUrlEncodedData(full_path.value(), false)); | 263 path.append(EscapeUrlEncodedData(full_path.value(), false)); |
| 233 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 264 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 234 bool result = BrowserThread::PostTask( | 265 bool result = BrowserThread::PostTask( |
| 235 BrowserThread::UI, FROM_HERE, | 266 BrowserThread::UI, FROM_HERE, |
| 236 base::Bind(&ViewItem, full_path, enqueue)); | 267 base::Bind(&ViewItem, full_path, enqueue)); |
| 237 DCHECK(result); | 268 DCHECK(result); |
| 238 return; | 269 return; |
| 239 } | 270 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: | 340 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: |
| 310 type_str = "open-multi-file"; | 341 type_str = "open-multi-file"; |
| 311 break; | 342 break; |
| 312 | 343 |
| 313 default: | 344 default: |
| 314 NOTREACHED(); | 345 NOTREACHED(); |
| 315 } | 346 } |
| 316 | 347 |
| 317 return type_str; | 348 return type_str; |
| 318 } | 349 } |
| OLD | NEW |