| 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" | |
| 16 #include "chrome/browser/extensions/crx_installer.h" | 15 #include "chrome/browser/extensions/crx_installer.h" |
| 17 #include "chrome/browser/extensions/extension_install_ui.h" | 16 #include "chrome/browser/extensions/extension_install_ui.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/plugin_prefs.h" | 18 #include "chrome/browser/plugin_prefs.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/simple_message_box.h" | 20 #include "chrome/browser/simple_message_box.h" |
| 22 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/common/extensions/file_browser_handler.h" | 24 #include "chrome/common/extensions/file_browser_handler.h" |
| 26 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/plugin_service.h" | 28 #include "content/public/browser/plugin_service.h" |
| 30 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 31 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 32 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
| 33 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "webkit/fileapi/file_system_context.h" | 34 #include "webkit/fileapi/file_system_context.h" |
| 36 #include "webkit/fileapi/file_system_mount_point_provider.h" | 35 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 37 #include "webkit/fileapi/file_system_util.h" | 36 #include "webkit/fileapi/file_system_util.h" |
| 38 #include "webkit/plugins/webplugininfo.h" | 37 #include "webkit/plugins/webplugininfo.h" |
| 39 | 38 |
| 40 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 41 #include "chrome/browser/chromeos/media/media_player.h" | 40 #include "chrome/browser/chromeos/media/media_player.h" |
| 42 #endif | 41 #endif |
| 43 | 42 |
| 44 using base::DictionaryValue; | |
| 45 using base::ListValue; | |
| 46 using content::BrowserContext; | 43 using content::BrowserContext; |
| 47 using content::BrowserThread; | 44 using content::BrowserThread; |
| 48 using content::PluginService; | 45 using content::PluginService; |
| 49 using content::UserMetricsAction; | 46 using content::UserMetricsAction; |
| 50 using file_handler_util::FileTaskExecutor; | 47 using file_handler_util::FileTaskExecutor; |
| 51 using gdata::GDataOperationRegistry; | |
| 52 | 48 |
| 53 #define FILEBROWSER_EXTENSON_ID "hhaomjibdihmijegdhdafkllkbggdgoj" | 49 #define FILEBROWSER_DOMAIN "hhaomjibdihmijegdhdafkllkbggdgoj" |
| 54 const char kFileBrowserDomain[] = FILEBROWSER_EXTENSON_ID; | 50 const char kFileBrowserDomain[] = FILEBROWSER_DOMAIN; |
| 55 | 51 |
| 56 const char kFileBrowserGalleryTaskId[] = "gallery"; | 52 const char kFileBrowserGalleryTaskId[] = "gallery"; |
| 57 const char kFileBrowserMountArchiveTaskId[] = "mount-archive"; | 53 const char kFileBrowserMountArchiveTaskId[] = "mount-archive"; |
| 58 | 54 |
| 59 namespace file_manager_util { | 55 namespace file_manager_util { |
| 60 namespace { | 56 namespace { |
| 61 | 57 |
| 62 #define FILEBROWSER_URL(PATH) \ | 58 #define FILEBROWSER_URL(PATH) \ |
| 63 ("chrome-extension://" FILEBROWSER_EXTENSON_ID "/" PATH) | 59 ("chrome-extension://" FILEBROWSER_DOMAIN "/" PATH) |
| 64 // This is the "well known" url for the file manager extension from | 60 // This is the "well known" url for the file manager extension from |
| 65 // browser/resources/file_manager. In the future we may provide a way to swap | 61 // browser/resources/file_manager. In the future we may provide a way to swap |
| 66 // out this file manager for an aftermarket part, but not yet. | 62 // out this file manager for an aftermarket part, but not yet. |
| 67 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL(""); | 63 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL(""); |
| 68 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); | 64 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); |
| 69 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); | 65 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); |
| 70 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); | 66 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); |
| 71 #undef FILEBROWSER_URL | 67 #undef FILEBROWSER_URL |
| 72 #undef FILEBROWSER_EXTENSON_ID | 68 #undef FILEBROWSER_DOMAIN |
| 73 | 69 |
| 74 const char kCRXExtension[] = ".crx"; | 70 const char kCRXExtension[] = ".crx"; |
| 75 const char kPdfExtension[] = ".pdf"; | 71 const char kPdfExtension[] = ".pdf"; |
| 76 // List of file extension we can open in tab. | 72 // List of file extension we can open in tab. |
| 77 const char* kBrowserSupportedExtensions[] = { | 73 const char* kBrowserSupportedExtensions[] = { |
| 78 #if defined(GOOGLE_CHROME_BUILD) | 74 #if defined(GOOGLE_CHROME_BUILD) |
| 79 ".pdf", | 75 ".pdf", |
| 80 #endif | 76 #endif |
| 81 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".txt", ".html", ".htm" | 77 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".txt", ".html", ".htm" |
| 82 }; | 78 }; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 type_str = "open-multi-file"; | 157 type_str = "open-multi-file"; |
| 162 break; | 158 break; |
| 163 | 159 |
| 164 default: | 160 default: |
| 165 NOTREACHED(); | 161 NOTREACHED(); |
| 166 } | 162 } |
| 167 | 163 |
| 168 return type_str; | 164 return type_str; |
| 169 } | 165 } |
| 170 | 166 |
| 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 | |
| 194 } // namespace | 167 } // namespace |
| 195 | 168 |
| 196 GURL GetFileBrowserExtensionUrl() { | 169 GURL GetFileBrowserExtensionUrl() { |
| 197 return GURL(kFileBrowserExtensionUrl); | 170 return GURL(kFileBrowserExtensionUrl); |
| 198 } | 171 } |
| 199 | 172 |
| 200 GURL GetFileBrowserUrl() { | 173 GURL GetFileBrowserUrl() { |
| 201 return GURL(kBaseFileBrowserUrl); | 174 return GURL(kBaseFileBrowserUrl); |
| 202 } | 175 } |
| 203 | 176 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) | 488 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) |
| 516 return false; | 489 return false; |
| 517 | 490 |
| 518 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); | 491 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); |
| 519 if (!plugin_prefs) | 492 if (!plugin_prefs) |
| 520 return false; | 493 return false; |
| 521 | 494 |
| 522 return plugin_prefs->IsPluginEnabled(plugin); | 495 return plugin_prefs->IsPluginEnabled(plugin); |
| 523 } | 496 } |
| 524 | 497 |
| 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 | |
| 539 } // namespace file_manager_util | 498 } // namespace file_manager_util |
| OLD | NEW |