feat: emit devtools-open-url event for DevTools link selection (#36774)

* feat: emit event for DevTools link selection

* chore: devtools-open-in-new-tab -> devtools-open-url
This commit is contained in:
Shelley Vohr 2023-01-26 09:54:26 +01:00 committed by GitHub
parent 8d008c977d
commit 7d46d3ec9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 1 deletions

View file

@ -492,6 +492,14 @@ The `focus` and `blur` events of `WebContents` should only be used to detect
focus change between different `WebContents` and `BrowserView` in the same
window.
#### Event: 'devtools-open-url'
Returns:
* `url` string - URL of the link that was clicked or selected.
Emitted when a link is clicked in DevTools or 'Open in new tab' is selected for a link in its context menu.
#### Event: 'devtools-opened'
Emitted when DevTools is opened.

View file

@ -981,6 +981,14 @@ Returns:
Emitted when mouse moves over a link or the keyboard moves the focus to a link.
### Event: 'devtools-open-url'
Returns:
* `url` string - URL of the link that was clicked or selected.
Emitted when a link is clicked in DevTools or 'Open in new tab' is selected for a link in its context menu.
### Event: 'devtools-opened'
Emitted when DevTools is opened.

View file

@ -9,6 +9,7 @@ export const webViewEvents: Record<string, readonly string[]> = {
'dom-ready': [],
'console-message': ['level', 'message', 'line', 'sourceId'],
'context-menu': ['params'],
'devtools-open-url': ['url'],
'devtools-opened': [],
'devtools-closed': [],
'devtools-focused': [],

View file

@ -3825,6 +3825,10 @@ void WebContents::DevToolsStopIndexing(int request_id) {
devtools_indexing_jobs_.erase(it);
}
void WebContents::DevToolsOpenInNewTab(const std::string& url) {
Emit("devtools-open-url", url);
}
void WebContents::DevToolsSearchInPath(int request_id,
const std::string& file_system_path,
const std::string& query) {

View file

@ -704,6 +704,7 @@ class WebContents : public ExclusiveAccessContext,
void DevToolsIndexPath(int request_id,
const std::string& file_system_path,
const std::string& excluded_folders_message) override;
void DevToolsOpenInNewTab(const std::string& url) override;
void DevToolsStopIndexing(int request_id) override;
void DevToolsSearchInPath(int request_id,
const std::string& file_system_path,

View file

@ -723,7 +723,10 @@ void InspectableWebContents::SetIsDocked(DispatchCallback callback,
std::move(callback).Run(nullptr);
}
void InspectableWebContents::OpenInNewTab(const std::string& url) {}
void InspectableWebContents::OpenInNewTab(const std::string& url) {
if (delegate_)
delegate_->DevToolsOpenInNewTab(url);
}
void InspectableWebContents::ShowItemInFolder(
const std::string& file_system_path) {

View file

@ -31,6 +31,7 @@ class InspectableWebContentsDelegate {
virtual void DevToolsIndexPath(int request_id,
const std::string& file_system_path,
const std::string& excluded_folders) {}
virtual void DevToolsOpenInNewTab(const std::string& url) {}
virtual void DevToolsStopIndexing(int request_id) {}
virtual void DevToolsSearchInPath(int request_id,
const std::string& file_system_path,