1
0

JSAPI2_Bookmarks.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "JSAPI2_Bookmarks.h"
  2. #include "JSAPI2_Security.h"
  3. #include "main.h"
  4. #include "JSAPI.h"
  5. #include "../nu/AutoChar.h"
  6. JSAPI2::BookmarksAPI::BookmarksAPI(const wchar_t *_key, JSAPI::ifc_info *_info)
  7. {
  8. info = _info;
  9. key = _key;
  10. refCount = 1;
  11. }
  12. #define DISP_TABLE \
  13. CHECK_ID(Add)\
  14. #define CHECK_ID(str) JSAPI_DISP_ENUMIFY(str),
  15. enum {
  16. DISP_TABLE
  17. };
  18. #undef CHECK_ID
  19. #define CHECK_ID(str)\
  20. if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, rgszNames[i], -1, L## #str, -1))\
  21. { rgdispid[i] = JSAPI_DISP_ENUMIFY(str); continue; }
  22. HRESULT JSAPI2::BookmarksAPI::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  23. {
  24. bool unknowns = false;
  25. for (unsigned int i = 0;i != cNames;i++)
  26. {
  27. DISP_TABLE
  28. rgdispid[i] = DISPID_UNKNOWN;
  29. unknowns = true;
  30. }
  31. if (unknowns)
  32. return DISP_E_UNKNOWNNAME;
  33. else
  34. return S_OK;
  35. }
  36. HRESULT JSAPI2::BookmarksAPI::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  37. {
  38. return E_NOTIMPL;
  39. }
  40. HRESULT JSAPI2::BookmarksAPI::GetTypeInfoCount(unsigned int FAR * pctinfo)
  41. {
  42. return E_NOTIMPL;
  43. }
  44. HRESULT JSAPI2::BookmarksAPI::Add(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  45. {
  46. JSAPI_VERIFY_METHOD(wFlags);
  47. JSAPI_VERIFY_PARAMCOUNT_OPTIONAL(pdispparams, 1, 2);
  48. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
  49. JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 2, VT_BSTR, puArgErr);
  50. JSAPI_INIT_RESULT(pvarResult, VT_BOOL);
  51. if (security.GetActionAuthorization(L"bookmarks", L"add", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
  52. {
  53. JSAPI_SET_VARIANT(pvarResult, V_BOOL, VARIANT_TRUE);
  54. wchar_t *filename = JSAPI_PARAM(pdispparams, 1).bstrVal;
  55. wchar_t *title = JSAPI_PARAM_OPTIONAL(pdispparams, 2, bstrVal, 0);
  56. if (title)
  57. Bookmark_additem(filename, title);
  58. else if (filename)
  59. Bookmark_additem(filename, filename);
  60. else
  61. JSAPI_SET_VARIANT(pvarResult, V_BOOL, VARIANT_FALSE);
  62. }
  63. else
  64. {
  65. JSAPI_SET_VARIANT(pvarResult, V_BOOL, VARIANT_FALSE);
  66. }
  67. return S_OK;
  68. }
  69. #undef CHECK_ID
  70. #define CHECK_ID(str) case JSAPI_DISP_ENUMIFY(str): return str(wFlags, pdispparams, pvarResult, puArgErr);
  71. HRESULT JSAPI2::BookmarksAPI::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  72. {
  73. switch (dispid)
  74. {
  75. DISP_TABLE
  76. }
  77. return DISP_E_MEMBERNOTFOUND;
  78. }
  79. STDMETHODIMP JSAPI2::BookmarksAPI::QueryInterface(REFIID riid, PVOID *ppvObject)
  80. {
  81. if (!ppvObject)
  82. return E_POINTER;
  83. else if (IsEqualIID(riid, IID_IDispatch))
  84. *ppvObject = (IDispatch *)this;
  85. else if (IsEqualIID(riid, IID_IUnknown))
  86. *ppvObject = this;
  87. else
  88. {
  89. *ppvObject = NULL;
  90. return E_NOINTERFACE;
  91. }
  92. AddRef();
  93. return S_OK;
  94. }
  95. ULONG JSAPI2::BookmarksAPI::AddRef(void)
  96. {
  97. return InterlockedIncrement(&refCount);
  98. }
  99. ULONG JSAPI2::BookmarksAPI::Release(void)
  100. {
  101. LONG lRef = InterlockedDecrement(&refCount);
  102. if (lRef == 0) delete this;
  103. return lRef;
  104. }