1
0

jsapi2_omcom.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "./main.h"
  2. #include "./api__ml_online.h"
  3. #include "./jsapi2_omcom.h"
  4. #include "./navigation.h"
  5. #include <ifc_omservice.h>
  6. #include <browserView.h>
  7. #include "../Winamp/JSAPI.h"
  8. JSAPI2::OnlineServicesAPI::OnlineServicesAPI(const wchar_t *_key, JSAPI::ifc_info *_info)
  9. {
  10. info = _info;
  11. key = _key;
  12. refCount = 1;
  13. }
  14. #define DISP_TABLE \
  15. CHECK_ID(Login)\
  16. #define CHECK_ID(str) JSAPI_DISP_ENUMIFY(str),
  17. enum {
  18. DISP_TABLE
  19. };
  20. #undef CHECK_ID
  21. #define CHECK_ID(str) if (wcscmp(rgszNames[i], L## #str) == 0) { rgdispid[i] = JSAPI_DISP_ENUMIFY(str); continue; }
  22. HRESULT JSAPI2::OnlineServicesAPI::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::OnlineServicesAPI::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  37. {
  38. return E_NOTIMPL;
  39. }
  40. HRESULT JSAPI2::OnlineServicesAPI::GetTypeInfoCount(unsigned int FAR * pctinfo)
  41. {
  42. return E_NOTIMPL;
  43. }
  44. HRESULT JSAPI2::OnlineServicesAPI::Login(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  45. {
  46. JSAPI_VERIFY_METHOD(wFlags);
  47. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
  48. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
  49. JSAPI_INIT_RESULT(pvarResult, VT_BOOL);
  50. JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_FALSE);
  51. const wchar_t *url = JSAPI_PARAM(pdispparams, 1).bstrVal;
  52. // if (AGAVE_API_JSAPI2_SECURITY->GetActionAuthorization(L"onlineservices", L"login", key, info, JSAPI2::api_security::ACTION_DISALLOWED) == JSAPI2::api_security::ACTION_ALLOWED)
  53. {
  54. HWND hBrowser = info->GetHWND();
  55. if (NULL != hBrowser && IsWindow(hBrowser))
  56. {
  57. ifc_omservice *service;
  58. if (FALSE != BrowserControl_GetService(hBrowser, &service))
  59. {
  60. wchar_t szBuffer[4096] = {0};
  61. LPCWSTR navigateUrl;
  62. if (NULL != AGAVE_API_AUTH &&
  63. 0 == AGAVE_API_AUTH->ClientToWeb(GUID_NULL, url, szBuffer, ARRAYSIZE(szBuffer)))
  64. {
  65. navigateUrl = szBuffer;
  66. }
  67. else
  68. navigateUrl = url;
  69. BrowserControl_Navigate(hBrowser, navigateUrl, TRUE);
  70. JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_TRUE);
  71. service->Release();
  72. }
  73. }
  74. }
  75. return S_OK;
  76. }
  77. #undef CHECK_ID
  78. #define CHECK_ID(str) case JSAPI_DISP_ENUMIFY(str): return str(wFlags, pdispparams, pvarResult, puArgErr);
  79. HRESULT JSAPI2::OnlineServicesAPI::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  80. {
  81. switch (dispid)
  82. {
  83. DISP_TABLE
  84. }
  85. return DISP_E_MEMBERNOTFOUND;
  86. }
  87. STDMETHODIMP JSAPI2::OnlineServicesAPI::QueryInterface(REFIID riid, PVOID *ppvObject)
  88. {
  89. if (!ppvObject)
  90. return E_POINTER;
  91. else if (IsEqualIID(riid, IID_IDispatch))
  92. *ppvObject = (IDispatch *)this;
  93. else if (IsEqualIID(riid, IID_IUnknown))
  94. *ppvObject = this;
  95. else
  96. {
  97. *ppvObject = NULL;
  98. return E_NOINTERFACE;
  99. }
  100. AddRef();
  101. return S_OK;
  102. }
  103. ULONG JSAPI2::OnlineServicesAPI::AddRef(void)
  104. {
  105. return InterlockedIncrement(&refCount);
  106. }
  107. ULONG JSAPI2::OnlineServicesAPI::Release(void)
  108. {
  109. LONG lRef = InterlockedDecrement(&refCount);
  110. if (lRef == 0) delete this;
  111. return lRef;
  112. }