InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HTTPAssetLinkResourceHandler.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Sanyam Jain
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // ADOBE CONFIDENTIAL
16 //
17 // Copyright 2016 Adobe
18 // All Rights Reserved.
19 //
20 // NOTICE: Adobe permits you to use, modify, and distribute this file in
21 // accordance with the terms of the Adobe license agreement accompanying
22 // it. If you have received this file from a source other than Adobe,
23 // then your use, modification, or distribution of it requires the prior
24 // written permission of Adobe.
25 //
26 //========================================================================================
27 
28 #ifndef __HTTPAssetLinkResourceHandler__
29 #define __HTTPAssetLinkResourceHandler__
30 
31 #include "CPMUnknown.h"
32 #include "LinksID.h"
33 
34 #include "ILinkResourceHandler.h"
35 #include "IHTTPLinkConnectionManager.h"
36 #include "IHTTPLinkManager.h"
37 #include "IHTTPLinkUtils.h"
38 
39 #include "FileTypeInfo.h"
40 #include "URICommonUtils.h"
41 
42 
43 // =============================================================================
44 // * HTTPAssetLinkResourceHandler
45 // =============================================================================
46 
50 class HTTPAssetLinkResourceHandler : public CPMUnknown<ILinkResourceHandler>
51 {
52 public:
54  typedef object_type data_type;
55 
58 
59  /*
60  @param UIDRef [IN] UIDRef of the Link Resource.
61  @param uri [IN] URI of the Link.
62  @return True if init is successful else false.
63  */
64  virtual bool Init(const UIDRef& ref, const URI& uri);
65 
66  /*
67  @param UIDRef [IN] UIDRef of the Link Resource.
68  @param uri [IN] URI of the Link.
69  @return true if the resource is Valid else false.
70  */
71  virtual bool IsResourceURIValid(const UIDRef& ref, const URI& uri) const;
72 
73  /*
74  @param UIDRef [IN] UIDRef of the Link Resource.
75  @param uri [IN] URI of the Link.
76  @return true if the resource'IDs are equivalent else false.
77  */
78  virtual bool AreResourceIdsEquivalent(const ILinkResource::ResourceId& id1, const ILinkResource::ResourceId& id2) const;
79 
80  /*
81  @param UIDRef [IN] UIDRef of the Link Resource.
82  @param uri [IN] URI of the Link.
83  @return the resource type
84  */
85  virtual FileTypeInfo GetResourceDataType(const UIDRef& ref, const URI& uri) const;
86 
87  /*
88  @param UIDRef [IN] UIDRef of the Link Resource.
89  @param uri [IN] URI of the Link.
90  @param bUIName [IN] true if we want to show the name to UI else false.
91  @return shortname of the resource
92  */
93  virtual WideString GetShortResourceName(const UIDRef& ref, const URI& uri, bool bUIName) const;
94 
95  /*
96  @param UIDRef [IN] UIDRef of the Link Resource.
97  @param uri [IN] URI of the Link.
98  @param bUIName [IN] true if we want to show the name to UI else false.
99  @return LongName of the resource
100  */
101  virtual WideString GetLongResourceName(const UIDRef& ref, const URI& uri, bool bUIName) const;
102 
103  /*
104  @param UIDRef [IN] UIDRef of the Link Resource.
105  @param state [IN] state of the resource.
106  @param storeState [IN] store state of the resource.
107  @return resource state as PMString
108  */
109  virtual PMString GetResourceStateInfo(const UIDRef& ref, const URI& uri, ILinkResource::ResourceState state, ILinkResource::ResourceStoreState storeState) const;
110 
111  /*
112  @param stamp1 [IN] resource1 stamp
113  @param stamp2 [IN] resource2 stamp
114  @return true if both stamps are equivalent.
115  */
116  virtual bool AreStampsEquivalent(const WideString& stamp1, const WideString& stamp2) const;
117 
118  /*
119  @param UIDRef [IN] UIDRef of the Link Resource.
120  @param uri [IN] URI of the Link.
121  @return true if we can read the resource else false.
122  */
123  virtual bool CanReadResource(const UIDRef& ref, const URI& uri) const;
124 
125  /*
126  @param UIDRef [IN] UIDRef of the Link Resource.
127  @param uri [IN] URI of the Link.
128  @return true if we can write the resource else false.
129  */
130  virtual bool CanWriteResource(const UIDRef& ref, const URI& uri) const;
131 
132  /*
133  @param UIDRef [IN] UIDRef of the Link Resource.
134  @param uri [IN] URI of the Link.
135  @return true if we can read and write the resource else false.
136  */
137  virtual bool CanReadWriteResource(const UIDRef& ref, const URI& uri) const;
138 
139  /*
140  @param UIDRef [IN] UIDRef of the Link Resource.
141  @param uri [IN] URI of the Link.
142  @param mode [IN] access mode for the resource
143  @return true if we can create the resource stream else false.
144  */
145  virtual bool CanCreateResourceStream(const UIDRef& ref, const URI& uri, ILinkResource::AccessMode mode) const;
146 
147  /*
148  @param UIDRef [IN] UIDRef of the Link Resource.
149  @param uri [IN] URI of the Link.
150  @return create the resource read stream.
151  */
152  virtual IPMStream* CreateResourceReadStream(const UIDRef& ref, const URI& uri) const;
153 
154  /*
155  @param UIDRef [IN] UIDRef of the Link Resource.
156  @param uri [IN] URI of the Link.
157  @return create the resource write stream.
158  */
159  virtual IPMStream* CreateResourceWriteStream(const UIDRef& ref, const URI& uri) const;
160 
161  /*
162  @param UIDRef [IN] UIDRef of the Link Resource.
163  @param uri [IN] URI of the Link.
164  @return create the resource read write stream.
165  */
166  virtual IPMStream* CreateResourceReadWriteStream(const UIDRef& ref, const URI& uri) const;
167 
168  /*
169  @param UIDRef [IN] UIDRef of the Link Resource.
170  @param uri [IN] URI of the Link.
171  @return true if can cache the resource else false.
172  */
173  virtual bool CanCacheResource(const UIDRef& ref, const URI& uri) const { return true; }
174 
175 
176  /*
177  @param UIDRef [IN] UIDRef of the Link Resource.
178  @param uri [IN] URI of the Link.
179  @return true if can embed the resource else false.
180  */
181  virtual bool CanEmbedResource(const UIDRef& ref, const URI& uri) const;
182 
183 
184  /*
185  @param UIDRef [IN] UIDRef of the Link Resource.
186  @param uri [IN] URI of the Link.
187  @return true if can unembed the resource else false.
188  */
189  virtual bool CanUnembedResource(const UIDRef& ref, const URI& uri) const { return true; }
190 
191 
192 
193  /*
194  @param UIDRef [IN] UIDRef of the Link Resource.
195  @param uri [IN] URI of the Link.
196  @return true if can copy the resource to file else false.
197  */
198  virtual bool CanCopyToFile(const UIDRef& ref, const URI& uri) const;
199 
200  /*
201  @param UIDRef [IN] UIDRef of the Link Resource.
202  @param uri [IN] URI of the Link.
203  @param file [OUT] file to copy
204  @return kSuccess if copy is success else kFailure.
205  */
206  virtual ErrorCode CopyToFile(const UIDRef& ref, const URI& uri, IDFile& file) const;
207 
208  /*
209  @param UIDRef [IN] UIDRef of the Link Resource.
210  @param uri [IN] URI of the Link.
211  @return true if can edit the resource else false.
212  */
213  virtual bool CanEditResource(const UIDRef& ref, const URI& uri) const;
214 
215  /*
216  @param UIDRef [IN] UIDRef of the Link Resource.
217  @param uri [IN] URI of the Link.
218  @param appInfo [IN] appinfo
219  @param errorString [OUT] output error string.
220  @return kSuccess on success else kFailure.
221  */
222  virtual ErrorCode EditResource(const UIDRef& ref, const URI& uri, const AppInfo& appInfo, PMString* errorString) const;
223 
224 
225  /*
226  @param UIDRef [IN] UIDRef of the Link Resource.
227  @param uri [IN] URI of the Link.
228  @return true if can reveal the resource else false.
229  */
230  virtual bool CanRevealResource(const UIDRef& ref, const URI& uri) const;
231 
232  /*
233  @param UIDRef [IN] UIDRef of the Link Resource.
234  @param uri [IN] URI of the Link.
235  @return true if revealing the resource else false.
236  */
237  virtual ErrorCode RevealResource(const UIDRef& ref, const URI& uri) const;
238 
239 
240  /*
241  @param UIDRef [IN] UIDRef of the Link Resource.
242  @param uri [IN] URI of the Link.
243  @return true if can reveal the resource in Bridge else false.
244  */
245  virtual bool CanRevealResourceInBridge(const UIDRef& ref, const URI& uri) const{ return false; }
246 
247  /*
248  @param UIDRef [IN] UIDRef of the Link Resource.
249  @param uri [IN] URI of the Link.
250  @return true if revealing the resource in bridge else false.
251  */
252  virtual ErrorCode RevealResourceInBridge(const UIDRef& ref, const URI& uri) const{ return kFailure; }
253 
254  /*
255  @param UIDRef [IN] UIDRef of the Link Resource.
256  @param uri [IN] URI of the Link.
257  @return true if can reveal the resource in CloudLibraries else false.
258  */
259  virtual bool CanRevealResourceInCloudLibraries(const UIDRef& ref, const URI& uri) const { return false; }
260 
261  /*
262  @param UIDRef [IN] UIDRef of the Link Resource.
263  @param uri [IN] URI of the Link.
264  @return true if revealing the resource in Cloud Lib else false.
265  */
266  virtual ErrorCode RevealResourceInCloudLibraries(const UIDRef& ref, const URI& uri) const { ASSERT_UNIMPLEMENTED(); return kFailure; }
267 
268  /*
269  @param UIDRef [IN] UIDRef of the Link Resource.
270  @param uri [IN] URI of the Link.
271  @param packet [OUT] filled XMPInfo packet
272  @return true on success else false.
273  */
274  virtual bool GetXMPPacketInfo(const UIDRef& resourceRef, const URI& uri, std::string& packet) const;
275 
276  /*
277  @param UIDRef [IN] UIDRef of the Link Resource.
278  @param uri [IN] URI of the Link.
279  @return true if Getting XMP info is allowed else false.
280  */
281  virtual bool CanGetXMPPacketInfo(const UIDRef& ref, const URI& uri) const;
282 
283  /*
284  @param UIDRef [IN] UIDRef of the Link Resource.
285  @param uri [IN] URI of the Link.
286  @return true if a FPO can be replaced else false.
287  */
288  virtual bool CanReplaceFPOWithOriginalResource(const UIDRef& ref, const URI& uri) const;
289 
290  /*
291  @param UIDRef [IN] UIDRef of the Link Resource.
292  @param uri [IN] URI of the Link.
293  @return true if original resource can be downloaded else false.
294  */
295  virtual bool CanDownloadOriginalResource(const UIDRef& ref, const URI& uri) const;
296 
297  /*
298  @param UIDRef [IN] UIDRef of the Link Resource.
299  @param uri [IN] URI of the Link.
300  @return KSuccess on success else kFailure.
301  */
302  virtual ErrorCode DownloadOriginalResource(const UIDRef& ref, const URI& uri) const;
303 
304  /*
305  @param UIDRef [IN] UIDRef of the Link Resource.
306  @param uri [IN] URI of the Link.
307  @param completionFunction [IN] download completion function.
308  @return KSuccess on AsyncDownloadOriginalResource success else kFailure.
309  */
310  virtual ErrorCode AsyncDownloadOriginalResource(const UIDRef& ref, const URI& uri, ILinkResource::DownloadCompletionFunction completionFunction) const;
311 
312  /*
313  @param UIDRef [IN] UIDRef of the Link Resource.
314  @param uri [IN] URI of the Link.
315  @param progress [IN] downloading progress.
316  @return ResourceDownloadState as output.
317  */
318  virtual ILinkResource::ResourceDownloadState GetResourceDownloadProgress(const UIDRef& ref, const URI& uri, PMReal& progress) const;
319 
320  /*
321  @param UIDRef [IN] UIDRef of the Link Resource.
322  @param uri [IN] URI of the Link.
323  @return true if it can provide IDFile corresponsing to uri.
324  */
325  virtual bool CanProvideFile(const UIDRef& ref, const URI& uri) const;
326 
327  /*
328  @param UIDRef [IN] UIDRef of the Link Resource.
329  @param uri [IN] URI of the Link.
330  @param idFile [OUT] resultant IDFile for uri.
331  @return kSuccess on success else kFailure.
332  */
333  virtual ErrorCode GetFile(const UIDRef& ref, const URI& uri, IDFile& idFile) const;
334 
335  /*
336  @param uri [IN] URI of the Link.
337  @return if URI is HTTPS supported or not.
338  */
339  virtual bool IsHTTPSSupportedURI(const URI& uri) const;
340 
341  /*
342  @return kSuccess if the handler can provide the current instance name
343  and want to show the instance name in links info in links panel
344  */
345  virtual bool canGetInstanceName() const { return false; }
346 
347  /*
348  @param uri [OUT] Instance name for the uri
349  @return kSuccess on success else kFailure.
350  */
351  virtual ErrorCode GetInstanceName(PMString &uri) const { return kFailure; }
352 
353 private:
354  // Prevent copy construction and assignment.
357 
358  std::shared_ptr<IHTTPLinkCachedAssetEntry> GetCachedAssetEntry(const UIDRef& ref,
360  bool16 shouldDownload = kTrue,
361  bool16 forceOriginalURI = kFalse,
362  IHTTPLinkResourceServerCache::AssetDownloadCompletionCallback completionFunction = NULL) const;
363 
364  static ILinkResource::ResourceDownloadState DownloadStateConverter(const HTTPLinkSubsystemTypes::HTTPAssetDownloadState downloadState);
365  static void DownloadCompletionCallback(const URI& inUri,
367  std::shared_ptr<IHTTPLinkCachedAssetEntry> cachedAssetEntry,
368  ILinkResource::DownloadCompletionFunction downloadCompletionFunction);
369 
370  static void HighResDrawingDownloadCompletionCallback(const UIDRef& ref,
371  const HTTPLinkSubsystemTypes::GUID guid,
372  const UID uid,
373  const URI& inUri,
375  std::shared_ptr<IHTTPLinkCachedAssetEntry> cachedAssetEntry);
376 
377  static uint32 PerformAssetsInvalidation(void* ptr);
378  static void StartAssetsInvalidationDelayTimer(uint32 delayTime);
379 
380 protected:
381 
386  bool fbInited;
387 
390 
397  mutable WideString fShortUINameCache;
398  mutable WideString fLongNameCache;
399  mutable WideString fLongUINameCache;
400 
401 };
402 
403 #endif // __HTTPAssetLinkResourceHandler__