frame.mojom 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/code_injection.mojom";
  6. import "extensions/common/mojom/host_id.mojom";
  7. import "extensions/common/mojom/injection_type.mojom";
  8. import "extensions/common/mojom/run_location.mojom";
  9. import "extensions/common/mojom/view_type.mojom";
  10. import "mojo/public/mojom/base/values.mojom";
  11. import "url/mojom/url.mojom";
  12. // Allows an extension to execute code in a tab.
  13. struct ExecuteCodeParams {
  14. // The ID of the requesting injection host.
  15. HostID host_id;
  16. // The CSS or JS to inject into the target.
  17. CodeInjection injection;
  18. // The webview guest source who calls to execute code.
  19. url.mojom.Url webview_src;
  20. // Whether to inject into about:blank (sub)frames.
  21. bool match_about_blank;
  22. // When to inject the code.
  23. RunLocation run_at;
  24. // Whether the request is coming from a <webview>.
  25. bool is_web_view;
  26. };
  27. // Parameters structure for LocalFrameHost.Request().
  28. struct RequestParams {
  29. // Message name.
  30. string name;
  31. // List of message arguments.
  32. mojo_base.mojom.ListValue arguments;
  33. // Extension ID this request was sent from. This can be empty, in the case
  34. // where we expose APIs to normal web pages using the extension function
  35. // system.
  36. string extension_id;
  37. // URL of the frame the request was sent from. This isn't necessarily an
  38. // extension url. Extension requests can also originate from content scripts,
  39. // in which case extension_id will indicate the ID of the associated
  40. // extension. Or, they can originate from hosted apps or normal web pages.
  41. url.mojom.Url source_url;
  42. // Unique request id to match requests and responses.
  43. int32 request_id;
  44. // True if request has a callback specified.
  45. bool has_callback;
  46. // True if request is executed in response to an explicit user gesture.
  47. bool user_gesture;
  48. // If this API call is for a service worker, then this is the worker thread
  49. // id. Otherwise, this is kMainThreadId.
  50. int32 worker_thread_id;
  51. // If this API call is for a service worker, then this is the service
  52. // worker version id. Otherwise, this is set to
  53. // blink::mojom::kInvalidServiceWorkerVersionId.
  54. int64 service_worker_version_id;
  55. };
  56. // Implemented in the renderer, this interface defines the local frame specific
  57. // methods.
  58. interface LocalFrame {
  59. // Sets the top-level frame to the provided name.
  60. SetFrameName(string frame_name);
  61. // Enables or disables spatial navigation.
  62. SetSpatialNavigationEnabled(bool spatial_nav_enabled);
  63. // Tells the render view what its tab ID is.
  64. SetTabId(int32 tab_id);
  65. // Notifies the renderer that its window has closed.
  66. AppWindowClosed(bool send_onclosed);
  67. // Tells the renderer which type this view is.
  68. NotifyRenderViewType(ViewType view_type);
  69. // Asks the renderer to invoke |function_name| with |args| in |module_name|.
  70. // If |extension_id| is non-empty, the function will be invoked only in
  71. // contexts owned by the extension. |args| is a list of primitive Value types
  72. // that are passed to the function.
  73. MessageInvoke(string extension_id,
  74. string module_name,
  75. string function_name,
  76. mojo_base.mojom.ListValue args);
  77. // Notifies the renderer that it should run some JavaScript code. The reply
  78. // is sent back to the browser to return the script running result. An empty
  79. // |error| implies success. |url| is the URL that the code executed on. It may
  80. // be empty if it's unsuccessful. We use an optional for |result| to
  81. // differentiate between no result (such as in the case of an error) and a
  82. // null result.
  83. ExecuteCode(ExecuteCodeParams param) =>
  84. (string error, url.mojom.Url url, mojo_base.mojom.Value? result);
  85. // Trigger to execute declarative content script under browser control.
  86. ExecuteDeclarativeScript(int32 tab_id,
  87. string extension_id,
  88. string script_id,
  89. url.mojom.Url url);
  90. // Tell the render view which browser window it's being attached to.
  91. UpdateBrowserWindowId(int32 window_id);
  92. };
  93. // Implemented in the browser, this interface defines the local frame host
  94. // specific methods.
  95. interface LocalFrameHost {
  96. // Requests permission for a script injection from the renderer to the
  97. // browser.
  98. // The reply is sent back to the renderer with |granted| for granting
  99. // permission for a script to run. If |granted| is false, the permission
  100. // should not be handled.
  101. RequestScriptInjectionPermission(string extension_id,
  102. InjectionType script_type,
  103. RunLocation run_location) => (bool granted);
  104. // Gets the install state for the app when a web page is checking if its app
  105. // is installed. The reply is sent back to the renderer with |state|.
  106. GetAppInstallState(url.mojom.Url url) => (string state);
  107. // Sends an extension API request to the browser.
  108. // The reply is sent back to the renderer with the response data (if any) is
  109. // one of the base::Value types, wrapped as the first element in a LIST
  110. // typed Value.
  111. [UnlimitedSize]
  112. Request(RequestParams params)
  113. => (bool success,
  114. mojo_base.mojom.ListValue response_wrapper,
  115. string error);
  116. // Notifies the browser process that a tab has started or stopped matching
  117. // certain conditions. This method is called by response to several events:
  118. //
  119. // * The WatchPages Mojo method was called, updating the set of
  120. // * conditions. A new page is loaded. This will be invoked after
  121. // mojom::FrameHost::DidCommitProvisionalLoad. Currently this only fires for
  122. // the main frame.
  123. // * Something changed on an existing frame causing the set of matching
  124. // searches to change.
  125. WatchedPageChange(array<string> css_selectors);
  126. };