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 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 const int bytes_read = | 31 const int bytes_read = |
32 base::ReadFile(local_path, &content[0], content.size()); | 32 base::ReadFile(local_path, &content[0], content.size()); |
33 | 33 |
34 if (bytes_read >= 0) { | 34 if (bytes_read >= 0) { |
35 net::SniffMimeType(&content[0], | 35 net::SniffMimeType(&content[0], |
36 bytes_read, | 36 bytes_read, |
37 net::FilePathToFileURL(local_path), | 37 net::FilePathToFileURL(local_path), |
38 std::string(), // type_hint (passes no hint) | 38 std::string(), // type_hint (passes no hint) |
39 result); | 39 result); |
40 | |
41 // If the extension is not .zip, do not handle the file as application/zip | |
42 // since it might be unknown internally zipped file. | |
43 if (*result == "application/zip" && | |
44 local_path.Extension() != FILE_PATH_LITERAL(".zip")) | |
benwells
2015/04/14 21:57:22
The logic of this flow is, I think:
- return the m
yawano
2015/04/15 03:41:34
Moving to OnSniffMimeTypeForNativeLocalPathComplet
| |
45 result->assign("application/octet-stream"); | |
benwells
2015/04/14 21:57:22
Why is the default application/octet-stream? Is th
yawano
2015/04/15 03:41:34
I think there is no default mime type. The default
| |
40 } | 46 } |
41 } | 47 } |
42 | 48 |
43 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
44 // Converts a result passed as a scoped pointer to a dereferenced value passed | 50 // Converts a result passed as a scoped pointer to a dereferenced value passed |
45 // to |callback|. | 51 // to |callback|. |
46 void OnGetMimeTypeFromFileForNonNativeLocalPathCompleted( | 52 void OnGetMimeTypeFromFileForNonNativeLocalPathCompleted( |
47 scoped_ptr<std::string> mime_type, | 53 scoped_ptr<std::string> mime_type, |
48 const base::Callback<void(const std::string&)>& callback) { | 54 const base::Callback<void(const std::string&)>& callback) { |
49 callback.Run(*mime_type); | 55 callback.Run(*mime_type); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); | 204 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); |
199 // Release the callback to avoid a circullar reference in case an instance | 205 // 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 | 206 // of this class is a member of a ref counted class, which instance is bound |
201 // to this callback. | 207 // to this callback. |
202 callback_ = CompletionCallback(); | 208 callback_ = CompletionCallback(); |
203 } | 209 } |
204 } | 210 } |
205 | 211 |
206 } // namespace app_file_handler_util | 212 } // namespace app_file_handler_util |
207 } // namespace extensions | 213 } // namespace extensions |
OLD | NEW |