/
activity_log_private.clj
99 lines (74 loc) · 4.14 KB
/
activity_log_private.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(ns chromex.ext.activity-log-private
" * available since Chrome 31"
(:refer-clojure :only [defmacro defn apply declare meta let partial])
(:require [chromex.wrapgen :refer [gen-wrap-helper]]
[chromex.callgen :refer [gen-call-helper gen-tap-all-events-call]]))
(declare api-table)
(declare gen-call)
; -- functions --------------------------------------------------------------------------------------------------------------
(defmacro get-extension-activities
"Retrieves activity from the ActivityLog that matches the specified filter.
|filter| - Fill out the fields that you want to search for in the database.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - ?
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error."
([filter] (gen-call :function ::get-extension-activities &form filter)))
(defmacro delete-activities
"Deletes activities in the ActivityLog database specified in the array of activity IDs.
|activity-ids| - Erases only the activities which IDs are listed in the array."
([activity-ids] (gen-call :function ::delete-activities &form activity-ids)))
(defmacro delete-database
"Deletes the entire ActivityLog database."
([] (gen-call :function ::delete-database &form)))
(defmacro delete-urls
"Delete URLs in the ActivityLog database.
|urls| - Erases only the URLs listed; if empty, erases all URLs."
([urls] (gen-call :function ::delete-urls &form urls))
([] `(delete-urls :omit)))
; -- events -----------------------------------------------------------------------------------------------------------------
;
; docs: https://github.com/binaryage/chromex/#tapping-events
(defmacro tap-on-extension-activity-events
"Fired when a given extension performs another activity.
Events will be put on the |channel| with signature [::on-extension-activity [activity]] where:
|activity| - ?
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-extension-activity &form channel args)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.ext.activity-log-private namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.activityLogPrivate",
:since "31",
:functions
[{:id ::get-extension-activities,
:name "getExtensionActivities",
:callback? true,
:params
[{:name "filter", :type "activityLogPrivate.Filter"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "activityLogPrivate.ActivityResultSet"}]}}]}
{:id ::delete-activities,
:name "deleteActivities",
:since "34",
:params [{:name "activity-ids", :type "[array-of-strings]"}]}
{:id ::delete-database, :name "deleteDatabase"}
{:id ::delete-urls, :name "deleteUrls", :params [{:name "urls", :optional? true, :type "[array-of-strings]"}]}],
:events
[{:id ::on-extension-activity,
:name "onExtensionActivity",
:params [{:name "activity", :type "activityLogPrivate.ExtensionActivity"}]}]})
; -- helpers ----------------------------------------------------------------------------------------------------------------
; code generation for native API wrapper
(defmacro gen-wrap [kind item-id config & args]
(apply gen-wrap-helper api-table kind item-id config args))
; code generation for API call-site
(def gen-call (partial gen-call-helper api-table))