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:
bughit 2018-05-01 00:34:41 -04:00 committed by Cheng Zhao
parent c67d1b62e3
commit 55a7f6f0ce
5 changed files with 87 additions and 8 deletions

View file

@ -955,14 +955,31 @@ void WebContents::DidFinishNavigation(
if (!navigation_handle->IsErrorPage()) { if (!navigation_handle->IsErrorPage()) {
auto url = navigation_handle->GetURL(); auto url = navigation_handle->GetURL();
bool is_same_document = navigation_handle->IsSameDocument(); bool is_same_document = navigation_handle->IsSameDocument();
if (is_main_frame && !is_same_document) { if (is_same_document) {
Emit("did-navigate", url);
} else if (is_same_document) {
Emit("did-navigate-in-page", Emit("did-navigate-in-page",
url, url,
is_main_frame, is_main_frame,
frame_process_id, frame_process_id,
frame_routing_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 { } else {
auto url = navigation_handle->GetURL(); auto url = navigation_handle->GetURL();

View file

@ -67,6 +67,8 @@ Returns:
* `errorDescription` String * `errorDescription` String
* `validatedURL` String * `validatedURL` String
* `isMainFrame` Boolean * `isMainFrame` Boolean
* `frameProcessId` Integer
* `frameRoutingId` Integer
This event is like `did-finish-load` but emitted when the load failed or was This event is like `did-finish-load` but emitted when the load failed or was
cancelled, e.g. `window.stop()` is invoked. cancelled, e.g. `window.stop()` is invoked.
@ -78,6 +80,8 @@ Returns:
* `event` Event * `event` Event
* `isMainFrame` Boolean * `isMainFrame` Boolean
* `frameProcessId` Integer
* `frameRoutingId` Integer
Emitted when a frame has done navigation. Emitted when a frame has done navigation.
@ -195,14 +199,47 @@ this purpose.
Calling `event.preventDefault()` will prevent the navigation. 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' #### Event: 'did-navigate'
Returns: Returns:
* `event` Event * `event` Event
* `url` String * `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 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 or updating the `window.location.hash`. Use `did-navigate-in-page` event for
@ -215,8 +252,10 @@ Returns:
* `event` Event * `event` Event
* `url` String * `url` String
* `isMainFrame` Boolean * `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 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 navigation outside of the page. Examples of this occurring are when anchor links
@ -1439,7 +1478,14 @@ more details.
#### `contents.getOSProcessId()` #### `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 ### Instance Properties

View file

@ -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 would be returned if there's no such frame or if the frame is not in the current
renderer process. 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 ## Properties
### `webFrame.top` ### `webFrame.top`
@ -262,5 +271,10 @@ current renderer process.
### `webFrame.nextSibling` ### `webFrame.nextSibling`
A `WebFrame` representing next sibling frame, the property would be `null` if 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. 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`.

View file

@ -26,6 +26,7 @@ const supportedWebViewEvents = [
'will-navigate', 'will-navigate',
'did-start-navigation', 'did-start-navigation',
'did-navigate', 'did-navigate',
'did-frame-navigate',
'did-navigate-in-page', 'did-navigate-in-page',
'close', 'close',
'crashed', 'crashed',

View file

@ -23,7 +23,8 @@ const WEB_VIEW_EVENTS = {
'new-window': ['url', 'frameName', 'disposition', 'options'], 'new-window': ['url', 'frameName', 'disposition', 'options'],
'will-navigate': ['url'], 'will-navigate': ['url'],
'did-start-navigation': ['url', 'isInPlace', 'isMainFrame', 'frameProcessId', 'frameRoutingId'], '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'], 'did-navigate-in-page': ['url', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
'close': [], 'close': [],
'crashed': [], 'crashed': [],