WKURLSchemeTask.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2017 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import <WebKit/WKFoundation.h>
  26. #import <Foundation/Foundation.h>
  27. NS_ASSUME_NONNULL_BEGIN
  28. API_AVAILABLE(macos(10.13), ios(11.0))
  29. @protocol WKURLSchemeTask <NSObject>
  30. /*! @abstract The request to load for this task.
  31. */
  32. @property (nonatomic, readonly, copy) NSURLRequest *request;
  33. /*! @abstract Set the current response object for the task.
  34. @param response The response to use.
  35. @discussion This method must be called at least once for each URL scheme handler task.
  36. Cross-origin requests require CORS header fields.
  37. An exception will be thrown if you try to send a new response object after the task has already been completed.
  38. An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
  39. */
  40. - (void)didReceiveResponse:(NSURLResponse *)response;
  41. /*! @abstract Add received data to the task.
  42. @param data The data to add.
  43. @discussion After a URL scheme handler task's final response object is received you should
  44. start sending it data.
  45. Each time this method is called the data you send will be appended to all previous data.
  46. An exception will be thrown if you try to send the task any data before sending it a response.
  47. An exception will be thrown if you try to send the task any data after the task has already been completed.
  48. An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
  49. */
  50. - (void)didReceiveData:(NSData *)data;
  51. /*! @abstract Mark the task as successfully completed.
  52. @discussion An exception will be thrown if you try to finish the task before sending it a response.
  53. An exception will be thrown if you try to mark a task completed after it has already been marked completed or failed.
  54. An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
  55. */
  56. - (void)didFinish;
  57. /*! @abstract Mark the task as failed.
  58. @param error A description of the error that caused the task to fail.
  59. @discussion An exception will be thrown if you try to mark a task failed after it has already been marked completed or failed.
  60. An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
  61. */
  62. - (void)didFailWithError:(NSError *)error;
  63. @end
  64. NS_ASSUME_NONNULL_END