OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/file_system_provider/operations/get_metadata.h
" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
6 | 6 |
| 7 #include <algorithm> |
7 #include <string> | 8 #include <string> |
8 | 9 |
9 #include "chrome/common/extensions/api/file_system_provider.h" | 10 #include "chrome/common/extensions/api/file_system_provider.h" |
10 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 11 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
11 | 12 |
12 namespace chromeos { | 13 namespace chromeos { |
13 namespace file_system_provider { | 14 namespace file_system_provider { |
14 namespace operations { | 15 namespace operations { |
15 namespace { | 16 namespace { |
16 | 17 |
17 // Convert |value| into |output|. If parsing fails, then returns false. | 18 // Convert |value| into |output|. If parsing fails, then returns false. |
18 bool ConvertRequestValueToFileInfo(scoped_ptr<RequestValue> value, | 19 bool ConvertRequestValueToFileInfo(scoped_ptr<RequestValue> value, |
19 EntryMetadata* output) { | 20 EntryMetadata* output) { |
20 using extensions::api::file_system_provider::EntryMetadata; | 21 using extensions::api::file_system_provider::EntryMetadata; |
21 using extensions::api::file_system_provider_internal:: | 22 using extensions::api::file_system_provider_internal:: |
22 GetMetadataRequestedSuccess::Params; | 23 GetMetadataRequestedSuccess::Params; |
23 | 24 |
24 const Params* params = value->get_metadata_success_params(); | 25 const Params* params = value->get_metadata_success_params(); |
25 if (!params) | 26 if (!params) |
26 return false; | 27 return false; |
27 | 28 |
28 output->name = params->metadata.name; | 29 output->name = params->metadata.name; |
29 output->is_directory = params->metadata.is_directory; | 30 output->is_directory = params->metadata.is_directory; |
30 output->size = static_cast<int64>(params->metadata.size); | 31 output->size = static_cast<int64>(params->metadata.size); |
31 | 32 |
32 if (params->metadata.mime_type.get()) | |
33 output->mime_type = *params->metadata.mime_type.get(); | |
34 | |
35 std::string input_modification_time; | 33 std::string input_modification_time; |
36 if (!params->metadata.modification_time.additional_properties.GetString( | 34 if (!params->metadata.modification_time.additional_properties.GetString( |
37 "value", &input_modification_time)) { | 35 "value", &input_modification_time)) { |
38 return false; | 36 return false; |
39 } | 37 } |
40 | 38 |
41 // Allow to pass invalid modification time, since there is no way to verify | 39 // Allow to pass invalid modification time, since there is no way to verify |
42 // it easily on any earlier stage. | 40 // it easily on any earlier stage. |
43 base::Time::FromString(input_modification_time.c_str(), | 41 base::Time::FromString(input_modification_time.c_str(), |
44 &output->modification_time); | 42 &output->modification_time); |
45 | 43 |
| 44 if (params->metadata.mime_type.get()) |
| 45 output->mime_type = *params->metadata.mime_type.get(); |
| 46 |
| 47 if (params->metadata.thumbnail.get()) { |
| 48 // Sanity check for the thumbnail format. Note, that another, more granural |
| 49 // check is done in custom bindings. Note, this is an extra check only for |
| 50 // the security reasons. |
| 51 const std::string expected_prefix = "data:"; |
| 52 std::string thumbnail_prefix = |
| 53 params->metadata.thumbnail.get()->substr(0, expected_prefix.size()); |
| 54 std::transform(thumbnail_prefix.begin(), |
| 55 thumbnail_prefix.end(), |
| 56 thumbnail_prefix.begin(), |
| 57 ::tolower); |
| 58 |
| 59 if (expected_prefix != thumbnail_prefix) |
| 60 return false; |
| 61 |
| 62 output->thumbnail = *params->metadata.thumbnail.get(); |
| 63 } |
| 64 |
46 return true; | 65 return true; |
47 } | 66 } |
48 | 67 |
49 } // namespace | 68 } // namespace |
50 | 69 |
51 GetMetadata::GetMetadata( | 70 GetMetadata::GetMetadata( |
52 extensions::EventRouter* event_router, | 71 extensions::EventRouter* event_router, |
53 const ProvidedFileSystemInfo& file_system_info, | 72 const ProvidedFileSystemInfo& file_system_info, |
54 const base::FilePath& entry_path, | 73 const base::FilePath& entry_path, |
| 74 ProvidedFileSystemInterface::MetadataFieldMask fields, |
55 const ProvidedFileSystemInterface::GetMetadataCallback& callback) | 75 const ProvidedFileSystemInterface::GetMetadataCallback& callback) |
56 : Operation(event_router, file_system_info), | 76 : Operation(event_router, file_system_info), |
57 entry_path_(entry_path), | 77 entry_path_(entry_path), |
| 78 fields_(fields), |
58 callback_(callback) { | 79 callback_(callback) { |
59 } | 80 } |
60 | 81 |
61 GetMetadata::~GetMetadata() { | 82 GetMetadata::~GetMetadata() { |
62 } | 83 } |
63 | 84 |
64 bool GetMetadata::Execute(int request_id) { | 85 bool GetMetadata::Execute(int request_id) { |
65 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); | 86 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); |
66 values->SetString("entryPath", entry_path_.AsUTF8Unsafe()); | 87 values->SetString("entryPath", entry_path_.AsUTF8Unsafe()); |
| 88 values->SetBoolean( |
| 89 "thumbnail", |
| 90 (fields_ & ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL) != 0); |
| 91 |
67 return SendEvent( | 92 return SendEvent( |
68 request_id, | 93 request_id, |
69 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, | 94 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, |
70 values.Pass()); | 95 values.Pass()); |
71 } | 96 } |
72 | 97 |
73 void GetMetadata::OnSuccess(int /* request_id */, | 98 void GetMetadata::OnSuccess(int /* request_id */, |
74 scoped_ptr<RequestValue> result, | 99 scoped_ptr<RequestValue> result, |
75 bool has_more) { | 100 bool has_more) { |
76 EntryMetadata metadata; | 101 EntryMetadata metadata; |
(...skipping 11 matching lines...) Expand all Loading... |
88 | 113 |
89 void GetMetadata::OnError(int /* request_id */, | 114 void GetMetadata::OnError(int /* request_id */, |
90 scoped_ptr<RequestValue> /* result */, | 115 scoped_ptr<RequestValue> /* result */, |
91 base::File::Error error) { | 116 base::File::Error error) { |
92 callback_.Run(EntryMetadata(), error); | 117 callback_.Run(EntryMetadata(), error); |
93 } | 118 } |
94 | 119 |
95 } // namespace operations | 120 } // namespace operations |
96 } // namespace file_system_provider | 121 } // namespace file_system_provider |
97 } // namespace chromeos | 122 } // namespace chromeos |
OLD | NEW |