| 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 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 4 #include "chrome/browser/chromeos/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/path_service.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 14 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
| 15 #include "chrome/browser/extensions/crx_installer.h" | 16 #include "chrome/browser/extensions/crx_installer.h" |
| 16 #include "chrome/browser/extensions/extension_install_ui.h" | 17 #include "chrome/browser/extensions/extension_install_ui.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/plugin_prefs.h" | 19 #include "chrome/browser/plugin_prefs.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/simple_message_box.h" | 21 #include "chrome/browser/simple_message_box.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/common/extensions/file_browser_handler.h" | 25 #include "chrome/common/extensions/file_browser_handler.h" |
| 25 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/plugin_service.h" | 29 #include "content/public/browser/plugin_service.h" |
| 29 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "net/base/escape.h" | 32 #include "net/base/escape.h" |
| 32 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "webkit/fileapi/file_system_context.h" | 35 #include "webkit/fileapi/file_system_context.h" |
| 35 #include "webkit/fileapi/file_system_mount_point_provider.h" | 36 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 36 #include "webkit/fileapi/file_system_util.h" | 37 #include "webkit/fileapi/file_system_util.h" |
| 37 #include "webkit/plugins/webplugininfo.h" | 38 #include "webkit/plugins/webplugininfo.h" |
| 38 | 39 |
| 39 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
| 40 #include "chrome/browser/chromeos/media/media_player.h" | 41 #include "chrome/browser/chromeos/media/media_player.h" |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 44 using base::DictionaryValue; |
| 45 using base::ListValue; |
| 43 using content::BrowserContext; | 46 using content::BrowserContext; |
| 44 using content::BrowserThread; | 47 using content::BrowserThread; |
| 45 using content::PluginService; | 48 using content::PluginService; |
| 46 using content::UserMetricsAction; | 49 using content::UserMetricsAction; |
| 47 using file_handler_util::FileTaskExecutor; | 50 using file_handler_util::FileTaskExecutor; |
| 51 using gdata::GDataOperationRegistry; |
| 48 | 52 |
| 49 #define FILEBROWSER_DOMAIN "hhaomjibdihmijegdhdafkllkbggdgoj" | 53 #define FILEBROWSER_EXTENSON_ID "hhaomjibdihmijegdhdafkllkbggdgoj" |
| 50 const char kFileBrowserDomain[] = FILEBROWSER_DOMAIN; | 54 const char kFileBrowserDomain[] = FILEBROWSER_EXTENSON_ID; |
| 51 | 55 |
| 52 const char kFileBrowserGalleryTaskId[] = "gallery"; | 56 const char kFileBrowserGalleryTaskId[] = "gallery"; |
| 53 const char kFileBrowserMountArchiveTaskId[] = "mount-archive"; | 57 const char kFileBrowserMountArchiveTaskId[] = "mount-archive"; |
| 54 | 58 |
| 55 namespace file_manager_util { | 59 namespace file_manager_util { |
| 56 namespace { | 60 namespace { |
| 57 | 61 |
| 58 #define FILEBROWSER_URL(PATH) \ | 62 #define FILEBROWSER_URL(PATH) \ |
| 59 ("chrome-extension://" FILEBROWSER_DOMAIN "/" PATH) | 63 ("chrome-extension://" FILEBROWSER_EXTENSON_ID "/" PATH) |
| 60 // This is the "well known" url for the file manager extension from | 64 // This is the "well known" url for the file manager extension from |
| 61 // browser/resources/file_manager. In the future we may provide a way to swap | 65 // browser/resources/file_manager. In the future we may provide a way to swap |
| 62 // out this file manager for an aftermarket part, but not yet. | 66 // out this file manager for an aftermarket part, but not yet. |
| 63 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL(""); | 67 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL(""); |
| 64 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); | 68 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); |
| 65 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); | 69 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); |
| 66 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); | 70 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); |
| 67 #undef FILEBROWSER_URL | 71 #undef FILEBROWSER_URL |
| 68 #undef FILEBROWSER_DOMAIN | 72 #undef FILEBROWSER_EXTENSON_ID |
| 69 | 73 |
| 70 const char kCRXExtension[] = ".crx"; | 74 const char kCRXExtension[] = ".crx"; |
| 71 const char kPdfExtension[] = ".pdf"; | 75 const char kPdfExtension[] = ".pdf"; |
| 72 // List of file extension we can open in tab. | 76 // List of file extension we can open in tab. |
| 73 const char* kBrowserSupportedExtensions[] = { | 77 const char* kBrowserSupportedExtensions[] = { |
| 74 #if defined(GOOGLE_CHROME_BUILD) | 78 #if defined(GOOGLE_CHROME_BUILD) |
| 75 ".pdf", | 79 ".pdf", |
| 76 #endif | 80 #endif |
| 77 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".txt", ".html", ".htm" | 81 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".txt", ".html", ".htm" |
| 78 }; | 82 }; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 type_str = "open-multi-file"; | 161 type_str = "open-multi-file"; |
| 158 break; | 162 break; |
| 159 | 163 |
| 160 default: | 164 default: |
| 161 NOTREACHED(); | 165 NOTREACHED(); |
| 162 } | 166 } |
| 163 | 167 |
| 164 return type_str; | 168 return type_str; |
| 165 } | 169 } |
| 166 | 170 |
| 171 DictionaryValue* ProgessStatusToDictionaryValue( |
| 172 Profile* profile, |
| 173 const GURL& origin_url, |
| 174 const GDataOperationRegistry::ProgressStatus& status) { |
| 175 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
| 176 GURL file_url; |
| 177 if (file_manager_util::ConvertFileToFileSystemUrl(profile, |
| 178 FilePath(status.file_path), |
| 179 origin_url, |
| 180 &file_url)) { |
| 181 result->SetString("fileUrl", file_url.spec()); |
| 182 } |
| 183 |
| 184 result->SetString("transferState", |
| 185 GDataOperationRegistry::OperationTransferStateToString( |
| 186 status.transfer_state)); |
| 187 result->SetString("transferType", |
| 188 GDataOperationRegistry::OperationTypeToString(status.operation_type)); |
| 189 result->SetInteger("processed", static_cast<int>(status.progress_current)); |
| 190 result->SetInteger("total", static_cast<int>(status.progress_total)); |
| 191 return result.release(); |
| 192 } |
| 193 |
| 167 } // namespace | 194 } // namespace |
| 168 | 195 |
| 169 GURL GetFileBrowserExtensionUrl() { | 196 GURL GetFileBrowserExtensionUrl() { |
| 170 return GURL(kFileBrowserExtensionUrl); | 197 return GURL(kFileBrowserExtensionUrl); |
| 171 } | 198 } |
| 172 | 199 |
| 173 GURL GetFileBrowserUrl() { | 200 GURL GetFileBrowserUrl() { |
| 174 return GURL(kBaseFileBrowserUrl); | 201 return GURL(kBaseFileBrowserUrl); |
| 175 } | 202 } |
| 176 | 203 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) | 515 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) |
| 489 return false; | 516 return false; |
| 490 | 517 |
| 491 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); | 518 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); |
| 492 if (!plugin_prefs) | 519 if (!plugin_prefs) |
| 493 return false; | 520 return false; |
| 494 | 521 |
| 495 return plugin_prefs->IsPluginEnabled(plugin); | 522 return plugin_prefs->IsPluginEnabled(plugin); |
| 496 } | 523 } |
| 497 | 524 |
| 525 ListValue* ProgressStatusVectorToListValue( |
| 526 Profile* profile, const GURL& origin_url, |
| 527 const std::vector<GDataOperationRegistry::ProgressStatus>& list) { |
| 528 scoped_ptr<ListValue> result_list(new ListValue()); |
| 529 for (std::vector< |
| 530 GDataOperationRegistry::ProgressStatus>::const_iterator iter = |
| 531 list.begin(); |
| 532 iter != list.end(); ++iter) { |
| 533 result_list->Append( |
| 534 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); |
| 535 } |
| 536 return result_list.release(); |
| 537 } |
| 538 |
| 498 } // namespace file_manager_util | 539 } // namespace file_manager_util |
| OLD | NEW |