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
3// found in the LICENSE file.
4
5// Multiply-included message file, so no include guard.
6
7#include <string>
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/files/file_path.h"
12#include "chrome/common/media_galleries/iphoto_library.h"
13#include "chrome/common/media_galleries/itunes_library.h"
14#include "chrome/common/media_galleries/metadata_types.h"
15#include "chrome/common/media_galleries/picasa_types.h"
16#include "ipc/ipc_message_macros.h"
17#include "ipc/ipc_platform_file.h"
18
19#if !defined(ENABLE_EXTENSIONS)
20#error "Extensions must be enabled"
21#endif
22
23#define IPC_MESSAGE_START ChromeUtilityExtensionsMsgStart
24
25#if defined(OS_MACOSX)
26IPC_STRUCT_TRAITS_BEGIN(iphoto::parser::Photo)
27  IPC_STRUCT_TRAITS_MEMBER(id)
28  IPC_STRUCT_TRAITS_MEMBER(location)
29  IPC_STRUCT_TRAITS_MEMBER(original_location)
30IPC_STRUCT_TRAITS_END()
31
32IPC_STRUCT_TRAITS_BEGIN(iphoto::parser::Library)
33  IPC_STRUCT_TRAITS_MEMBER(albums)
34  IPC_STRUCT_TRAITS_MEMBER(all_photos)
35IPC_STRUCT_TRAITS_END()
36#endif  // defined(OS_MACOSX)
37
38#if defined(OS_WIN) || defined(OS_MACOSX)
39IPC_STRUCT_TRAITS_BEGIN(itunes::parser::Track)
40  IPC_STRUCT_TRAITS_MEMBER(id)
41  IPC_STRUCT_TRAITS_MEMBER(location)
42IPC_STRUCT_TRAITS_END()
43
44IPC_STRUCT_TRAITS_BEGIN(picasa::AlbumInfo)
45  IPC_STRUCT_TRAITS_MEMBER(name)
46  IPC_STRUCT_TRAITS_MEMBER(timestamp)
47  IPC_STRUCT_TRAITS_MEMBER(uid)
48  IPC_STRUCT_TRAITS_MEMBER(path)
49IPC_STRUCT_TRAITS_END()
50
51// These files are opened read-only. Please see the constructor for
52// picasa::AlbumTableFiles for details.
53IPC_STRUCT_TRAITS_BEGIN(picasa::AlbumTableFilesForTransit)
54  IPC_STRUCT_TRAITS_MEMBER(indicator_file)
55  IPC_STRUCT_TRAITS_MEMBER(category_file)
56  IPC_STRUCT_TRAITS_MEMBER(date_file)
57  IPC_STRUCT_TRAITS_MEMBER(filename_file)
58  IPC_STRUCT_TRAITS_MEMBER(name_file)
59  IPC_STRUCT_TRAITS_MEMBER(token_file)
60  IPC_STRUCT_TRAITS_MEMBER(uid_file)
61IPC_STRUCT_TRAITS_END()
62
63IPC_STRUCT_TRAITS_BEGIN(picasa::FolderINIContents)
64  IPC_STRUCT_TRAITS_MEMBER(folder_path)
65  IPC_STRUCT_TRAITS_MEMBER(ini_contents)
66IPC_STRUCT_TRAITS_END()
67#endif  // defined(OS_WIN) || defined(OS_MACOSX)
68
69#if !defined(OS_ANDROID) && !defined(OS_IOS)
70IPC_STRUCT_TRAITS_BEGIN(metadata::AttachedImage)
71  IPC_STRUCT_TRAITS_MEMBER(type)
72  IPC_STRUCT_TRAITS_MEMBER(data)
73IPC_STRUCT_TRAITS_END()
74#endif  // !defined(OS_ANDROID) && !defined(OS_IOS)
75
76//------------------------------------------------------------------------------
77// Utility process messages:
78// These are messages from the browser to the utility process.
79
80// Tells the utility process to unpack the given extension file in its
81// directory and verify that it is valid.
82IPC_MESSAGE_CONTROL4(ChromeUtilityMsg_UnpackExtension,
83                     base::FilePath /* extension_filename */,
84                     std::string /* extension_id */,
85                     int /* Manifest::Location */,
86                     int /* InitFromValue flags */)
87
88IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_UnzipToDir,
89                     base::FilePath /* zip_file */,
90                     base::FilePath /* dir */)
91
92// Tell the utility process to decode the given image data, which is base64
93// encoded.
94IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_DecodeImageBase64,
95                     std::string)  // base64 encoded image contents
96
97// Tell the utility process to parse a JSON string into a Value object.
98IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseJSON,
99                     std::string /* JSON to parse */)
100
101#if defined(OS_WIN)
102// Tell the utility process to parse the iTunes preference XML file contents
103// and return the path to the iTunes directory.
104IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseITunesPrefXml,
105                     std::string /* XML to parse */)
106#endif  // defined(OS_WIN)
107
108#if defined(OS_MACOSX)
109// Tell the utility process to parse the iPhoto library XML file and
110// return the parse result as well as the iPhoto library as an iphoto::Library.
111IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseIPhotoLibraryXmlFile,
112                     IPC::PlatformFileForTransit /* XML file to parse */)
113#endif  // defined(OS_MACOSX)
114
115#if defined(OS_WIN) || defined(OS_MACOSX)
116// Tell the utility process to parse the iTunes library XML file and
117// return the parse result as well as the iTunes library as an itunes::Library.
118IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseITunesLibraryXmlFile,
119                     IPC::PlatformFileForTransit /* XML file to parse */)
120
121// Tells the utility process to parse the Picasa PMP database and return a
122// listing of the user's Picasa albums and folders, along with metadata.
123IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParsePicasaPMPDatabase,
124                     picasa::AlbumTableFilesForTransit /* album_table_files */)
125
126// Tells the utility process to index the Picasa user-created Album contents
127// by parsing all the INI files in Picasa Folders.
128IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_IndexPicasaAlbumsContents,
129                     picasa::AlbumUIDSet /* album_uids */,
130                     std::vector<picasa::FolderINIContents> /* folders_inis */)
131#endif  // defined(OS_WIN) || defined(OS_MACOSX)
132
133#if !defined(OS_ANDROID) && !defined(OS_IOS)
134// Tell the utility process to attempt to validate the passed media file. The
135// file will undergo basic sanity checks and will be decoded for up to
136// |milliseconds_of_decoding| wall clock time. It is still not safe to decode
137// the file in the browser process after this check.
138IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_CheckMediaFile,
139                     int64 /* milliseconds_of_decoding */,
140                     IPC::PlatformFileForTransit /* Media file to parse */)
141
142IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_ParseMediaMetadata,
143                     std::string /* mime_type */,
144                     int64 /* total_size */,
145                     bool /* get_attached_images */)
146
147IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_RequestBlobBytes_Finished,
148                     int64 /* request_id */,
149                     std::string /* bytes */)
150#endif  // !defined(OS_ANDROID) && !defined(OS_IOS)
151
152// Requests that the utility process write the contents of the source file to
153// the removable drive listed in the target file. The target will be restricted
154// to removable drives by the utility process.
155IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_ImageWriter_Write,
156                     base::FilePath /* source file */,
157                     base::FilePath /* target file */)
158
159// Requests that the utility process verify that the contents of the source file
160// was written to the target. As above the target will be restricted to
161// removable drives by the utility process.
162IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_ImageWriter_Verify,
163                     base::FilePath /* source file */,
164                     base::FilePath /* target file */)
165
166// Cancels a pending write or verify operation.
167IPC_MESSAGE_CONTROL0(ChromeUtilityMsg_ImageWriter_Cancel)
168
169//------------------------------------------------------------------------------
170// Utility process host messages:
171// These are messages from the utility process to the browser.
172
173// Reply when the utility process is done unpacking an extension.  |manifest|
174// is the parsed manifest.json file.
175// The unpacker should also have written out files containing the decoded
176// images and message catalogs from the extension. The data is written into a
177// DecodedImages struct into a file named kDecodedImagesFilename in the
178// directory that was passed in. This is done because the data is too large to
179// pass over IPC.
180IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_UnpackExtension_Succeeded,
181                     base::DictionaryValue /* manifest */)
182
183// Reply when the utility process has failed while unpacking an extension.
184// |error_message| is a user-displayable explanation of what went wrong.
185IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_UnpackExtension_Failed,
186                     base::string16 /* error_message, if any */)
187
188// Reply when the utility process is done unzipping a file. |unpacked_path|
189// is the directory which contains the unzipped contents.
190IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_UnzipToDir_Succeeded,
191                     base::FilePath /* unpacked_path */)
192
193// Reply when the utility process failed to unzip a file. |error| contains
194// an error string to be reported to the user.
195IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_UnzipToDir_Failed,
196                     std::string /* error */)
197
198// Reply when the utility process successfully parsed a JSON string.
199//
200// WARNING: The result can be of any Value subclass type, but we can't easily
201// pass indeterminate value types by const object reference with our IPC macros,
202// so we put the result Value into a ListValue. Handlers should examine the
203// first (and only) element of the ListValue for the actual result.
204IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_ParseJSON_Succeeded,
205                     base::ListValue)
206
207// Reply when the utility process failed in parsing a JSON string.
208IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_ParseJSON_Failed,
209                     std::string /* error message, if any*/)
210
211#if defined(OS_WIN)
212// Reply after parsing the iTunes preferences XML file contents with either the
213// path to the iTunes directory or an empty FilePath.
214IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_GotITunesDirectory,
215                     base::FilePath /* Path to iTunes library */)
216#endif  // defined(OS_WIN)
217
218#if defined(OS_MACOSX)
219// Reply after parsing the iPhoto library XML file with the parser result and
220// an iphoto::Library data structure.
221IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_GotIPhotoLibrary,
222                     bool /* Parser result */,
223                     iphoto::parser::Library /* iPhoto library */)
224#endif  // defined(OS_MACOSX)
225
226#if defined(OS_WIN) || defined(OS_MACOSX)
227// Reply after parsing the iTunes library XML file with the parser result and
228// an itunes::Library data structure.
229IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_GotITunesLibrary,
230                     bool /* Parser result */,
231                     itunes::parser::Library /* iTunes library */)
232
233// Reply after parsing the Picasa PMP Database with the parser result and a
234// listing of the user's Picasa albums and folders, along with metadata.
235IPC_MESSAGE_CONTROL3(ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished,
236                     bool /* parse_success */,
237                     std::vector<picasa::AlbumInfo> /* albums */,
238                     std::vector<picasa::AlbumInfo> /* folders */)
239
240// Reply after indexing the Picasa user-created Album contents by parsing all
241// the INI files in Picasa Folders.
242IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished,
243                     picasa::AlbumImagesMap /* albums_images */)
244#endif  // defined(OS_WIN) || defined(OS_MACOSX)
245
246#if !defined(OS_ANDROID) && !defined(OS_IOS)
247// Reply after checking the passed media file. A true result indicates that
248// the file appears to be a well formed media file.
249IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_CheckMediaFile_Finished,
250                     bool /* passed_checks */)
251
252IPC_MESSAGE_CONTROL3(
253    ChromeUtilityHostMsg_ParseMediaMetadata_Finished,
254    bool /* parse_success */,
255    base::DictionaryValue /* metadata */,
256    std::vector<metadata::AttachedImage> /* attached_images */)
257
258IPC_MESSAGE_CONTROL3(ChromeUtilityHostMsg_RequestBlobBytes,
259                     int64 /* request_id */,
260                     int64 /* start_byte */,
261                     int64 /* length */)
262#endif  // !defined(OS_ANDROID) && !defined(OS_IOS)
263
264// Reply when a write or verify operation succeeds.
265IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_ImageWriter_Succeeded)
266
267// Reply when a write or verify operation has been fully cancelled.
268IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_ImageWriter_Cancelled)
269
270// Reply when a write or verify operation fails to complete.
271IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_ImageWriter_Failed,
272                     std::string /* message */)
273
274// Periodic status update about the progress of an operation.
275IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_ImageWriter_Progress,
276                     int64 /* number of bytes processed */)
277
278#if defined(OS_WIN)
279// Get plain-text WiFi credentials from the system (requires UAC privilege
280// elevation).
281IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_GetWiFiCredentials,
282                     std::string /* ssid */)
283
284// Reply after getting WiFi credentials from the system. |success| is false if
285// error occurred.
286IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_GotWiFiCredentials,
287                     std::string /* key_data */,
288                     bool /* success */)
289#endif  // defined(OS_WIN)
290