code_injection.mojom 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. module extensions.mojom;
  5. import "extensions/common/mojom/css_origin.mojom";
  6. import "extensions/common/mojom/execution_world.mojom";
  7. import "third_party/blink/public/mojom/script/script_evaluation_params.mojom";
  8. import "url/mojom/url.mojom";
  9. // A single JS source to execute in the renderer.
  10. struct JSSource {
  11. // The Javascript code to execute.
  12. string code;
  13. // The URL of the script that was injected, if any.
  14. url.mojom.Url script_url;
  15. };
  16. // A single CSS source to execute in the renderer.
  17. struct CSSSource {
  18. // The CSS code to insert.
  19. string code;
  20. // A generated injection key for the CSS, which can be used to remove it
  21. // later.
  22. string? key;
  23. };
  24. // A struct representing a collection of JS code to inject in the renderer.
  25. struct JSInjection {
  26. // The JS sources to execute.
  27. array<JSSource> sources;
  28. // The JS world into which to inject the scripts.
  29. ExecutionWorld world;
  30. // Whether the caller is interested in the result value. Manifest-declared
  31. // content scripts and executeScript() calls without a response callback
  32. // are examples of when this will be `kNoResult`.
  33. blink.mojom.WantResultOption wants_result;
  34. // Whether the code to be executed with synthesized user activation.
  35. blink.mojom.UserActivationOption user_gesture;
  36. // For scripts that evaluate to promises, whether to wait for the resolution
  37. // of the resulting promises.
  38. blink.mojom.PromiseResultOption wait_for_promise;
  39. };
  40. // A struct representing a collection of CSS code to insert in the renderer.
  41. struct CSSInjection {
  42. enum Operation {
  43. kAdd,
  44. kRemove,
  45. };
  46. // The CSS sources to insert.
  47. array<CSSSource> sources;
  48. // The origin of the CSS.
  49. CSSOrigin css_origin;
  50. // The type of operation to perform.
  51. Operation operation;
  52. };
  53. // A single CodeInjection, which is allowed to contain exactly one of
  54. // CSS and JS.
  55. union CodeInjection {
  56. CSSInjection css;
  57. JSInjection js;
  58. };