JSAPI2_Creator.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include "main.h"
  2. #include "resource.h"
  3. #include "JSAPI2_Creator.h"
  4. #include "JSAPI2_TransportAPI.h"
  5. #include "JSAPI2_PlayerAPI.h"
  6. #include "JSAPI2_Downloader.h"
  7. #include "JSAPI2_SecurityAPI.h"
  8. #include "JSAPI2_Security.h"
  9. #include "JSAPI2_Bookmarks.h"
  10. #include "JSAPI2_Application.h"
  11. #include "JSAPI2_SkinAPI.h"
  12. #include "JSAPI2_MediaCore.h"
  13. #include "JSAPI2_AsyncDownloader.h"
  14. #include "api.h"
  15. #include "language.h"
  16. IDispatch *JSAPI2_Creator::CreateAPI(const wchar_t *name, const wchar_t *key, JSAPI::ifc_info *info)
  17. {
  18. if (!wcscmp(name, L"Transport"))
  19. return new JSAPI2::TransportAPI(key, info);
  20. else if (!wcscmp(name, L"PlayQueue"))
  21. return new JSAPI2::PlayerAPI(key, info);
  22. else if (!wcscmp(name, L"Downloader"))
  23. return new JSAPI2::DownloaderAPI(key, info);
  24. else if (!wcscmp(name, L"AsyncDownloader"))
  25. return new JSAPI2::AsyncDownloaderAPI(key, info);
  26. else if (!wcscmp(name, L"Security"))
  27. return new JSAPI2::SecurityAPI(key, info);
  28. else if (!wcscmp(name, L"Bookmarks"))
  29. return new JSAPI2::BookmarksAPI(key, info);
  30. else if (!wcscmp(name, L"Application"))
  31. return new JSAPI2::ApplicationAPI(key, info);
  32. else if (!wcscmp(name, L"Skin"))
  33. return new JSAPI2::SkinAPI(key, info);
  34. else if (!wcscmp(name, L"MediaCore"))
  35. return new JSAPI2::MediaCoreAPI(key, info);
  36. else
  37. return 0;
  38. }
  39. static int GetDescription(const wchar_t *group, const wchar_t *action, wchar_t *str, size_t str_len, int *flags)
  40. {
  41. if (!wcscmp(group, L"application"))
  42. {
  43. if (action && !wcscmp(action, L"launchurl"))
  44. {
  45. *flags = 0;
  46. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_APPLICATION_LAUNCHURL, NULL, 0));
  47. }
  48. else
  49. return 1;
  50. return 0;
  51. }
  52. else if (!wcscmp(group, L"transport"))
  53. {
  54. if (action && !wcscmp(action, L"events"))
  55. {
  56. *flags = 0;
  57. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_TRANSPORT_EVENTS, NULL, 0));
  58. }
  59. else if (action && !wcscmp(action, L"metadata"))
  60. {
  61. *flags = 0;
  62. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_TRANSPORT_METADATA, NULL, 0));
  63. }
  64. else if (action && !wcscmp(action, L"controls"))
  65. {
  66. *flags = 0;
  67. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_TRANSPORT_CONTROLS, NULL, 0));
  68. }
  69. else
  70. return 1;
  71. return 0;
  72. }
  73. else if(!wcscmp(group, L"player"))
  74. {
  75. if (action && !wcscmp(action, L"playlist"))
  76. {
  77. *flags = 0;
  78. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_PLAYER_PLAYLIST, NULL, 0));
  79. }
  80. else if (action && !wcscmp(action, L"metadata"))
  81. {
  82. *flags = 0;
  83. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_PLAYER_METADATA, NULL, 0));
  84. }
  85. else
  86. return 1;
  87. return 0;
  88. }
  89. else if (!wcscmp(group, L"downloader"))
  90. {
  91. if (action && !wcscmp(action, L"events"))
  92. {
  93. *flags = 0;
  94. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_DOWNLOADER_EVENTS, NULL, 0));
  95. }
  96. else if (action && !wcscmp(action, L"downloadmedia"))
  97. {
  98. *flags = 0;
  99. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_DOWNLOADER_DOWNLOADMEDIA, NULL, 0));
  100. }
  101. else
  102. return 1;
  103. return 0;
  104. }
  105. else if (!wcscmp(group, L"security"))
  106. {
  107. *flags = JSAPI2::svc_apicreator::AUTHORIZATION_FLAG_GROUP_ONLY;
  108. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_SECURITY_AUTH, NULL, 0));
  109. return 0;
  110. }
  111. else if (!wcscmp(group, L"bookmarks"))
  112. {
  113. *flags = JSAPI2::svc_apicreator::AUTHORIZATION_FLAG_GROUP_ONLY;
  114. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_BOOKMARKS_AUTH, NULL, 0));
  115. return 0;
  116. }
  117. else if (!wcscmp(group, L"skin"))
  118. {
  119. *flags = JSAPI2::svc_apicreator::AUTHORIZATION_FLAG_GROUP_ONLY;
  120. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_SKIN_AUTH, NULL, 0));
  121. return 0;
  122. }
  123. else if (!wcscmp(group, L"mediacore"))
  124. {
  125. if (action && !wcscmp(action, L"metadatahook"))
  126. {
  127. *flags = 0;
  128. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_MEDIACORE_METADATAHOOK, NULL, 0));
  129. }
  130. else if (action && !wcscmp(action, L"metadata"))
  131. {
  132. *flags = 0;
  133. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_MEDIACORE_METADATA, NULL, 0));
  134. }
  135. else if (action && !wcscmp(action, L"extensions"))
  136. {
  137. *flags = 0;
  138. StringCchCopyW(str, str_len, getStringW(IDS_SECURITY_MEDIACORE_EXTENSIONS, NULL, 0));
  139. }
  140. else
  141. return 1;
  142. return 0;
  143. }
  144. else
  145. return 1;
  146. }
  147. int JSAPI2_Creator::PromptForAuthorization(HWND parent, const wchar_t *group, const wchar_t *action, const wchar_t *authorization_key, JSAPI2::api_security::AuthorizationData *data)
  148. {
  149. int flags = 0;
  150. wchar_t display_str[1024] = {0};
  151. if (GetDescription(group, action, display_str, 1024, &flags) == 0)
  152. {
  153. const wchar_t *title_str = JSAPI2::security.GetAssociatedName(authorization_key);
  154. return JSAPI2::security.SecurityPrompt(parent, title_str, display_str, flags);
  155. }
  156. else
  157. return JSAPI2::svc_apicreator::AUTHORIZATION_UNDEFINED;
  158. }
  159. #define CBCLASS JSAPI2_Creator
  160. START_DISPATCH;
  161. CB(JSAPI2_SVC_APICREATOR_CREATEAPI, CreateAPI);
  162. CB(JSAPI2_SVC_APICREATOR_PROMPTFORAUTHORIZATION, PromptForAuthorization);
  163. END_DISPATCH;
  164. #undef CBCLASS
  165. static JSAPI2_Creator jsapi2_svc;
  166. static const char serviceName[] = "Winamp Javascript Objects";
  167. // {53CCACEF-1EFE-4060-8D09-329AD0D4F9C4}
  168. static const GUID jsapi2_factory_guid =
  169. { 0x53ccacef, 0x1efe, 0x4060, { 0x8d, 0x9, 0x32, 0x9a, 0xd0, 0xd4, 0xf9, 0xc4 } };
  170. FOURCC JSAPI2CreatorFactory::GetServiceType()
  171. {
  172. return jsapi2_svc.getServiceType();
  173. }
  174. const char *JSAPI2CreatorFactory::GetServiceName()
  175. {
  176. return serviceName;
  177. }
  178. GUID JSAPI2CreatorFactory::GetGUID()
  179. {
  180. return jsapi2_factory_guid;
  181. }
  182. void *JSAPI2CreatorFactory::GetInterface(int global_lock)
  183. {
  184. // if (global_lock)
  185. // WASABI_API_SVC->service_lock(this, (void *)ifc);
  186. return &jsapi2_svc;
  187. }
  188. int JSAPI2CreatorFactory::SupportNonLockingInterface()
  189. {
  190. return 1;
  191. }
  192. int JSAPI2CreatorFactory::ReleaseInterface(void *ifc)
  193. {
  194. //WASABI_API_SVC->service_unlock(ifc);
  195. return 1;
  196. }
  197. const char *JSAPI2CreatorFactory::GetTestString()
  198. {
  199. return 0;
  200. }
  201. int JSAPI2CreatorFactory::ServiceNotify(int msg, int param1, int param2)
  202. {
  203. return 1;
  204. }
  205. #define CBCLASS JSAPI2CreatorFactory
  206. START_DISPATCH;
  207. CB(WASERVICEFACTORY_GETSERVICETYPE, GetServiceType)
  208. CB(WASERVICEFACTORY_GETSERVICENAME, GetServiceName)
  209. CB(WASERVICEFACTORY_GETGUID, GetGUID)
  210. CB(WASERVICEFACTORY_GETINTERFACE, GetInterface)
  211. CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, SupportNonLockingInterface)
  212. CB(WASERVICEFACTORY_RELEASEINTERFACE, ReleaseInterface)
  213. CB(WASERVICEFACTORY_GETTESTSTRING, GetTestString)
  214. CB(WASERVICEFACTORY_SERVICENOTIFY, ServiceNotify)
  215. END_DISPATCH;
  216. #undef CBCLASS