summaryrefslogtreecommitdiff
path: root/chromium/chrome/common/extensions/api/scripting.idl
blob: 4da3b226c0f0fc7c2a2db0eeb0ef3c2432500435 (plain)
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Use the <code>chrome.scripting</code> API to execute script in different
// contexts.
namespace scripting {
  callback InjectedFunction = void();

  // The origin for a style change.
  // See <href="https://developer.mozilla.org/en-US/docs/Glossary/Style_origin">style origins</href>
  // for more info.
  enum StyleOrigin {
    AUTHOR,
    USER
  };

  dictionary InjectionTarget {
    // The ID of the tab into which to inject.
    long tabId;

    // The <a href="https://developer.chrome.com/extensions/webNavigation#frame_ids">IDs</href>
    // of specific frames to inject into.
    long[]? frameIds;

    // Whether the script should inject into all frames within the tab. Defaults
    // to false.
    // This must not be true if <code>frameIds</code> is specified.
    boolean? allFrames;
  };

  dictionary ScriptInjection {
    // A JavaScript function to inject. This function will be serialized, and
    // then deserialized for injection. This means that any bound parameters
    // and execution context will be lost.
    // Exactly one of <code>files</code> and <code>function</code> must be
    // specified.
    [serializableFunction]InjectedFunction? function;

    // The path of the JS files to inject, relative to the extension's root
    // directory.
    // NOTE: Currently a maximum of one file is supported.
    // Exactly one of <code>files</code> and <code>function</code> must be
    // specified.
    DOMString[]? files;

    // Details specifying the target into which to inject the script.
    InjectionTarget target;
  };

  dictionary CSSInjection {
    // Details specifying the target into which to insert the CSS.
    InjectionTarget target;

    // A string containing the CSS to inject.
    // Exactly one of <code>files</code> and <code>css</code> must be
    // specified.
    DOMString? css;

    // The path of the CSS files to inject, relative to the extension's root
    // directory.
    // NOTE: Currently a maximum of one file is supported.
    // Exactly one of <code>files</code> and <code>css</code> must be
    // specified.
    DOMString[]? files;

    // The style origin for the injection. Defaults to <code>'AUTHOR'</code>.
    StyleOrigin? origin;
  };

  dictionary InjectionResult {
    // The result of the script execution.
    any? result;
  };

  callback ScriptInjectionCallback = void(InjectionResult[] results);

  callback CSSInjectionCallback = void();

  interface Functions {
    // Injects a script into a target context. The script will be run at
    // <code>document_end</code>.
    // |injection|: The details of the script which to inject.
    // |callback|: Invoked upon completion of the injection. The resulting
    // array contains the result of execution for each frame.
    static void executeScript(ScriptInjection injection,
                              optional ScriptInjectionCallback callback);

    // Inserts a CSS stylesheet into a target context.
    // |injection|: The details of the styles to insert.
    // |callback|: Invoked upon completion of the insertion.
    static void insertCSS(CSSInjection injection,
                          optional CSSInjectionCallback callback);
  };
};