Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/file_handlers/mime_util.h" | 5 #include "chrome/browser/extensions/api/file_handlers/mime_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 base::Bind(&OnGetMimeTypeFromFileForNonNativeLocalPathCompleted, | 75 base::Bind(&OnGetMimeTypeFromFileForNonNativeLocalPathCompleted, |
| 76 base::Passed(&mime_type_from_extension), | 76 base::Passed(&mime_type_from_extension), |
| 77 callback)); | 77 callback)); |
| 78 } | 78 } |
| 79 #endif | 79 #endif |
| 80 | 80 |
| 81 // Called when sniffing for MIME type in the native local file is completed. | 81 // Called when sniffing for MIME type in the native local file is completed. |
| 82 void OnSniffMimeTypeForNativeLocalPathCompleted( | 82 void OnSniffMimeTypeForNativeLocalPathCompleted( |
| 83 scoped_ptr<std::string> mime_type, | 83 scoped_ptr<std::string> mime_type, |
| 84 const base::Callback<void(const std::string&)>& callback) { | 84 const base::Callback<void(const std::string&)>& callback) { |
| 85 // Do not return application/zip as sniffed result. If the file has .zip | |
| 86 // extension, it should be already returned as application/zip. If the file | |
| 87 // does not have .zip extension and couldn't find mime type from the | |
| 88 // extension, it might be unknown internally zipped file. | |
| 89 if (*mime_type == "application/zip") { | |
| 90 callback.Run("application/octet-stream"); | |
| 91 return; | |
| 92 } | |
| 93 | |
| 85 callback.Run(*mime_type); | 94 callback.Run(*mime_type); |
| 86 } | 95 } |
| 87 | 96 |
| 88 } // namespace | 97 } // namespace |
| 89 | 98 |
| 90 // Handles response of net::GetMimeTypeFromFile for native file systems. If | 99 // Handles response of net::GetMimeTypeFromFile for native file systems. If |
| 91 // MIME type is available, then forwards it to |callback|. Otherwise, fallbacks | 100 // MIME type is available, then forwards it to |callback|. Otherwise, fallbacks |
| 92 // to sniffing. | 101 // to sniffing. |
| 93 void OnGetMimeTypeFromFileForNativeLocalPathCompleted( | 102 void OnGetMimeTypeFromFileForNativeLocalPathCompleted( |
| 94 const base::FilePath& local_path, | 103 const base::FilePath& local_path, |
| 95 scoped_ptr<std::string> mime_type, | 104 scoped_ptr<std::string> mime_type, |
| 96 const base::Callback<void(const std::string&)>& callback) { | 105 const base::Callback<void(const std::string&)>& callback) { |
| 97 if (!mime_type->empty()) { | 106 if (!mime_type->empty()) { |
| 98 callback.Run(*mime_type); | 107 callback.Run(*mime_type); |
| 99 return; | 108 return; |
| 100 } | 109 } |
| 101 | 110 |
| 102 scoped_ptr<std::string> sniffed_mime_type(new std::string); | 111 scoped_ptr<std::string> sniffed_mime_type(new std::string); |
|
benwells
2015/04/15 05:01:17
Can we initialize this to "application/octet-strea
yawano
2015/04/15 06:34:02
Done.
| |
| 103 std::string* const sniffed_mime_type_ptr = sniffed_mime_type.get(); | 112 std::string* const sniffed_mime_type_ptr = sniffed_mime_type.get(); |
| 104 BrowserThread::PostBlockingPoolTaskAndReply( | 113 BrowserThread::PostBlockingPoolTaskAndReply( |
| 105 FROM_HERE, | 114 FROM_HERE, |
| 106 base::Bind(&SniffMimeType, local_path, sniffed_mime_type_ptr), | 115 base::Bind(&SniffMimeType, local_path, sniffed_mime_type_ptr), |
| 107 base::Bind(&OnSniffMimeTypeForNativeLocalPathCompleted, | 116 base::Bind(&OnSniffMimeTypeForNativeLocalPathCompleted, |
| 108 base::Passed(&sniffed_mime_type), | 117 base::Passed(&sniffed_mime_type), |
| 109 callback)); | 118 callback)); |
| 110 } | 119 } |
| 111 | 120 |
| 112 // Fetches MIME type for a local path and returns it with a |callback|. | 121 // Fetches MIME type for a local path and returns it with a |callback|. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); | 207 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); |
| 199 // Release the callback to avoid a circullar reference in case an instance | 208 // Release the callback to avoid a circullar reference in case an instance |
| 200 // of this class is a member of a ref counted class, which instance is bound | 209 // of this class is a member of a ref counted class, which instance is bound |
| 201 // to this callback. | 210 // to this callback. |
| 202 callback_ = CompletionCallback(); | 211 callback_ = CompletionCallback(); |
| 203 } | 212 } |
| 204 } | 213 } |
| 205 | 214 |
| 206 } // namespace app_file_handler_util | 215 } // namespace app_file_handler_util |
| 207 } // namespace extensions | 216 } // namespace extensions |
| OLD | NEW |