/
declarative_web_request.clj
68 lines (49 loc) · 3.18 KB
/
declarative_web_request.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
(ns chromex.ext.declarative-web-request
"Note: this API is currently on hold, without concrete plans to move to stable. Use the chrome.declarativeWebRequest API to
intercept, block, or modify requests in-flight. It is significantly faster than the chrome.webRequest API because you can
register rules that are evaluated in the browser rather than the JavaScript engine, which reduces roundtrip latencies and
allows higher efficiency.
* available since Chrome 71
* https://developer.chrome.com/extensions/declarativeWebRequest"
(: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)
; -- events -----------------------------------------------------------------------------------------------------------------
;
; docs: https://github.com/binaryage/chromex/#tapping-events
(defmacro tap-on-request-events
"
Events will be put on the |channel| with signature [::on-request []].
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/extensions/declarativeWebRequest#event-onRequest."
([channel & args] (apply gen-call :event ::on-request &form channel args)))
(defmacro tap-on-message-events
"Fired when a message is sent via 'declarativeWebRequest.SendMessageToExtension' from an action of the declarative web
request API.
Events will be put on the |channel| with signature [::on-message [details]] where:
|details| - https://developer.chrome.com/extensions/declarativeWebRequest#property-onMessage-details.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/extensions/declarativeWebRequest#event-onMessage."
([channel & args] (apply gen-call :event ::on-message &form channel args)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.ext.declarative-web-request namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.declarativeWebRequest",
:since "71",
:events
[{:id ::on-request, :name "onRequest"}
{:id ::on-message, :name "onMessage", :params [{:name "details", :type "object"}]}]})
; -- 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))