IWebScriptObject.idl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) 2006, 2007, 2008 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 COMPUTER, INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef DO_NO_IMPORTS
  26. import "oaidl.idl";
  27. import "ocidl.idl";
  28. #endif
  29. /*!
  30. @class WebScriptObject
  31. @discussion WebScriptObjects are used to wrap script objects passed from
  32. script environments to Objective-C. WebScriptObjects cannot be created
  33. directly. In normal uses of WebKit, you gain access to the script
  34. environment using the "windowScriptObject" method on WebView.
  35. The following KVC methods are commonly used to access properties of the
  36. WebScriptObject:
  37. - (void)setValue:(id)value forKey:(NSString *)key
  38. - (id)valueForKey:(NSString *)key
  39. As it possible to remove attributes from web script objects the following
  40. additional method augments the basic KVC methods:
  41. - (void)removeWebScriptKey:(NSString *)name;
  42. Also the sparse array access allowed in web script objects doesn't map well to NSArray, so
  43. the following methods can be used to access index based properties:
  44. - (id)webScriptValueAtIndex:(unsigned int)index;
  45. - (void)setWebScriptValueAtIndex:(unsigned int)index value:(id)value;
  46. @interface WebScriptObject : NSObject
  47. */
  48. [
  49. object,
  50. oleautomation,
  51. uuid(7022340A-649C-43fc-9214-85CA7D3BE3C7),
  52. pointer_default(unique)
  53. ]
  54. interface IWebScriptObject : IUnknown
  55. {
  56. /*!
  57. @method throwException:
  58. @discussion Throws an exception in the current script execution context.
  59. @result Either NO if an exception could not be raised, YES otherwise.
  60. + (BOOL)throwException:(NSString *)exceptionMessage;
  61. */
  62. HRESULT throwException([in] BSTR exceptionMessage, [out, retval] BOOL* result);
  63. /*!
  64. @method callWebScriptMethod:withArguments:
  65. @param name The name of the method to call in the script environment.
  66. @param args The arguments to pass to the script environment.
  67. @discussion Calls the specified method in the script environment using the
  68. specified arguments.
  69. @result Returns the result of calling the script method.
  70. - (id)callWebScriptMethod:(NSString *)name withArguments:(NSArray *)args;
  71. */
  72. HRESULT callWebScriptMethod([in] BSTR name, [in, size_is(cArgs)] const VARIANT args[], [in] int cArgs, [out, retval] VARIANT* result);
  73. /*!
  74. @method evaluateWebScript:
  75. @param script The script to execute in the target script environment.
  76. @discussion The script will be executed in the target script environment. The format
  77. of the script is dependent of the target script environment.
  78. @result Returns the result of evaluating the script in the script environment.
  79. - (id)evaluateWebScript:(NSString *)script;
  80. */
  81. HRESULT evaluateWebScript([in] BSTR script, [out, retval] VARIANT* result);
  82. /*!
  83. @method removeWebScriptKey:
  84. @param name The name of the property to remove.
  85. @discussion Removes the property from the object in the script environment.
  86. - (void)removeWebScriptKey:(NSString *)name;
  87. */
  88. HRESULT removeWebScriptKey([in] BSTR name);
  89. /*!
  90. @method toString
  91. @discussion Converts the target object to a string representation. The coercion
  92. of non string objects type is dependent on the script environment.
  93. @result Returns the string representation of the object.
  94. - (NSString *)stringRepresentation;
  95. */
  96. HRESULT stringRepresentation([out, retval] BSTR* stringRepresentation);
  97. /*!
  98. @method propertyAtIndex:
  99. @param index The index of the property to return. Index based access is dependent
  100. @discussion Gets the value of the property at the specified index.
  101. @result The value of the property.
  102. - (id)webScriptValueAtIndex:(unsigned int)index;
  103. */
  104. HRESULT webScriptValueAtIndex([in] unsigned int index, [out, retval] VARIANT* result);
  105. /*!
  106. @method setPropertyAtIndex:value:
  107. @param index The index of the property to set.
  108. @param value The value of the property to set.
  109. @discussion Sets the property value at the specified index.
  110. - (void)setWebScriptValueAtIndex:(unsigned int)index value:(id)value;
  111. */
  112. HRESULT setWebScriptValueAtIndex([in] unsigned int index, [in] VARIANT val);
  113. /*!
  114. @method setException:
  115. @param description The description of the exception.
  116. @discussion Raises an exception in the script environment in the context of the
  117. current object.
  118. - (void)setException: (NSString *)description;
  119. */
  120. HRESULT setException([in] BSTR description);
  121. }