зеркало из https://github.com/electron/electron.git
add did-frame-navigate event to WebContents (#12723)
* add did-frame-navigate event to WebContents, pass http response code to it and did-navigate * docs for frame routing id related api changes on WebFrame and WebContents
This commit is contained in:
Родитель
c67d1b62e3
Коммит
55a7f6f0ce
|
@ -955,14 +955,31 @@ void WebContents::DidFinishNavigation(
|
|||
if (!navigation_handle->IsErrorPage()) {
|
||||
auto url = navigation_handle->GetURL();
|
||||
bool is_same_document = navigation_handle->IsSameDocument();
|
||||
if (is_main_frame && !is_same_document) {
|
||||
Emit("did-navigate", url);
|
||||
} else if (is_same_document) {
|
||||
if (is_same_document) {
|
||||
Emit("did-navigate-in-page",
|
||||
url,
|
||||
is_main_frame,
|
||||
frame_process_id,
|
||||
frame_routing_id);
|
||||
} else {
|
||||
const net::HttpResponseHeaders* http_response
|
||||
= navigation_handle->GetResponseHeaders();
|
||||
std::string http_status_text;
|
||||
int http_response_code = -1;
|
||||
if (http_response) {
|
||||
http_status_text = http_response->GetStatusText();
|
||||
http_response_code = http_response->response_code();
|
||||
}
|
||||
Emit("did-frame-navigate",
|
||||
url,
|
||||
http_response_code,
|
||||
http_status_text,
|
||||
is_main_frame,
|
||||
frame_process_id,
|
||||
frame_routing_id);
|
||||
if (is_main_frame) {
|
||||
Emit("did-navigate", url, http_response_code, http_status_text);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto url = navigation_handle->GetURL();
|
||||
|
|
|
@ -67,6 +67,8 @@ Returns:
|
|||
* `errorDescription` String
|
||||
* `validatedURL` String
|
||||
* `isMainFrame` Boolean
|
||||
* `frameProcessId` Integer
|
||||
* `frameRoutingId` Integer
|
||||
|
||||
This event is like `did-finish-load` but emitted when the load failed or was
|
||||
cancelled, e.g. `window.stop()` is invoked.
|
||||
|
@ -78,6 +80,8 @@ Returns:
|
|||
|
||||
* `event` Event
|
||||
* `isMainFrame` Boolean
|
||||
* `frameProcessId` Integer
|
||||
* `frameRoutingId` Integer
|
||||
|
||||
Emitted when a frame has done navigation.
|
||||
|
||||
|
@ -195,14 +199,47 @@ this purpose.
|
|||
|
||||
Calling `event.preventDefault()` will prevent the navigation.
|
||||
|
||||
#### Event: 'did-start-navigation'
|
||||
|
||||
Returns:
|
||||
|
||||
* `url` String
|
||||
* `isInPlace` Boolean
|
||||
* `isMainFrame` Boolean
|
||||
* `frameProcessId` Integer
|
||||
* `frameRoutingId` Integer
|
||||
|
||||
Emitted when any frame (including main) starts navigating. `isInplace` will be
|
||||
`true` for in-page navigations.
|
||||
|
||||
#### Event: 'did-navigate'
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `url` String
|
||||
* `httpResponseCode` Integer - -1 for non HTTP navigations
|
||||
* `httpStatusText` String - empty for non HTTP navigations
|
||||
|
||||
Emitted when a navigation is done.
|
||||
Emitted when a main frame navigation is done.
|
||||
|
||||
This event is not emitted for in-page navigations, such as clicking anchor links
|
||||
or updating the `window.location.hash`. Use `did-navigate-in-page` event for
|
||||
this purpose.
|
||||
|
||||
#### Event: 'did-frame-navigate'
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `url` String
|
||||
* `httpResponseCode` Integer - -1 for non HTTP navigations
|
||||
* `httpStatusText` String - empty for non HTTP navigations,
|
||||
* `isMainFrame` Boolean
|
||||
* `frameProcessId` Integer
|
||||
* `frameRoutingId` Integer
|
||||
|
||||
Emitted when any frame navigation is done.
|
||||
|
||||
This event is not emitted for in-page navigations, such as clicking anchor links
|
||||
or updating the `window.location.hash`. Use `did-navigate-in-page` event for
|
||||
|
@ -215,8 +252,10 @@ Returns:
|
|||
* `event` Event
|
||||
* `url` String
|
||||
* `isMainFrame` Boolean
|
||||
* `frameProcessId` Integer
|
||||
* `frameRoutingId` Integer
|
||||
|
||||
Emitted when an in-page navigation happened.
|
||||
Emitted when an in-page navigation happened in any frame.
|
||||
|
||||
When in-page navigation happens, the page URL changes but does not cause
|
||||
navigation outside of the page. Examples of this occurring are when anchor links
|
||||
|
@ -1439,7 +1478,14 @@ more details.
|
|||
|
||||
#### `contents.getOSProcessId()`
|
||||
|
||||
Returns `Integer` - The `pid` of the associated renderer process.
|
||||
Returns `Integer` - The operating system `pid` of the associated renderer
|
||||
process.
|
||||
|
||||
#### `contents.getProcessId()`
|
||||
|
||||
Returns `Integer` - The chromium internal `pid` of the associated renderer. Can
|
||||
be compared to the `frameProcessId` passed by frame specific navigation events
|
||||
(e.g. `did-frame-navigate`)
|
||||
|
||||
### Instance Properties
|
||||
|
||||
|
|
|
@ -235,6 +235,15 @@ Returns `WebFrame` - A child of `webFrame` with the supplied `name`, `null`
|
|||
would be returned if there's no such frame or if the frame is not in the current
|
||||
renderer process.
|
||||
|
||||
### `webFrame.findFrameByRoutingId(routingId)`
|
||||
|
||||
* `routingId` Integer - A unique frame id in the current renderer process.
|
||||
Routing IDs can be retrieved from `WebFrame` instances (`webFrame.routingId`)
|
||||
and are also passed by frame specific `WebContents` navigation events (e.g.
|
||||
`did-frame-navigate`)
|
||||
|
||||
Returns `WebFrame` - that has the supplied `routingId`, `null` if not found.
|
||||
|
||||
## Properties
|
||||
|
||||
### `webFrame.top`
|
||||
|
@ -262,5 +271,10 @@ current renderer process.
|
|||
### `webFrame.nextSibling`
|
||||
|
||||
A `WebFrame` representing next sibling frame, the property would be `null` if
|
||||
`webFrame` is the last frame its parent or if the next sibling is not in the
|
||||
`webFrame` is the last frame in its parent or if the next sibling is not in the
|
||||
current renderer process.
|
||||
|
||||
### `webFrame.routingId`
|
||||
|
||||
A unique frame id in the current renderer process. Distinct WebFrame instances
|
||||
that refer to the same underlying frame will have the same `routingId`.
|
|
@ -26,6 +26,7 @@ const supportedWebViewEvents = [
|
|||
'will-navigate',
|
||||
'did-start-navigation',
|
||||
'did-navigate',
|
||||
'did-frame-navigate',
|
||||
'did-navigate-in-page',
|
||||
'close',
|
||||
'crashed',
|
||||
|
|
|
@ -23,7 +23,8 @@ const WEB_VIEW_EVENTS = {
|
|||
'new-window': ['url', 'frameName', 'disposition', 'options'],
|
||||
'will-navigate': ['url'],
|
||||
'did-start-navigation': ['url', 'isInPlace', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||
'did-navigate': ['url'],
|
||||
'did-navigate': ['url', 'httpResponseCode', 'httpStatusText'],
|
||||
'did-frame-navigate': ['url', 'httpResponseCode', 'httpStatusText', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||
'did-navigate-in-page': ['url', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||
'close': [],
|
||||
'crashed': [],
|
||||
|
|
Загрузка…
Ссылка в новой задаче