Add more events for WebContents

This commit is contained in:
Cheng Zhao 2014-10-24 23:05:25 +08:00
parent 2d56067819
commit d63f44cd07
3 changed files with 60 additions and 5 deletions

View file

@ -15,6 +15,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/resource_request_details.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "native_mate/dictionary.h"
@ -117,6 +118,16 @@ void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
Emit("did-finish-load");
}
void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description) {
base::ListValue args;
args.AppendInteger(error_code);
args.AppendString(error_description);
Emit("did-fail-load", args);
}
void WebContents::DidStartLoading(content::RenderViewHost* render_view_host) {
Emit("did-start-loading");
}
@ -125,6 +136,17 @@ void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) {
Emit("did-stop-loading");
}
void WebContents::DidGetRedirectForResourceRequest(
content::RenderViewHost* render_view_host,
const content::ResourceRedirectDetails& details) {
base::ListValue args;
args.AppendString(details.url.spec());
args.AppendString(details.new_url.spec());
args.AppendBoolean(
details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME);
Emit("did-get-redirect-request", args);
}
bool WebContents::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebContents, message)

View file

@ -100,10 +100,17 @@ class WebContents : public mate::EventEmitter,
virtual void RenderProcessGone(base::TerminationStatus status) override;
virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
virtual void DidFailLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description) override;
virtual void DidStartLoading(
content::RenderViewHost* render_view_host) override;
virtual void DidStopLoading(
content::RenderViewHost* render_view_host) override;
virtual void DidGetRedirectForResourceRequest(
content::RenderViewHost* render_view_host,
const content::ResourceRedirectDetails& details) override;
virtual bool OnMessageReceived(const IPC::Message& message) override;
virtual void RenderViewReady() override;
virtual void WebContentsDestroyed() override;

View file

@ -512,14 +512,19 @@ A `WebContents` is responsible for rendering and controlling a web page.
`WebContents` is an
[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter).
### Event: 'crashed'
Emitted when the renderer process is crashed.
### Event: 'did-finish-load'
Emitted when the navigation is done, i.e. the spinner of the tab will stop
spinning, and the onload event was dispatched.
spinning, and the `onload` event was dispatched.
### Event: 'did-fail-load'
* `event` Event
* `errorCode` Integer
* `errorDescription` String
This event is like `did-finish-load`, but emitted when the load failed or was
cancelled, e.g. `window.stop()` is invoked.
### Event: 'did-frame-finish-load'
@ -530,8 +535,29 @@ Emitted when a frame has done navigation.
### Event: 'did-start-loading'
Corresponds to the points in time when the spinner of the tab starts spinning.
### Event: 'did-stop-loading'
Corresponds to the points in time when the spinner of the tab stops spinning.
### Event: 'did-get-redirect-request'
* `event` Event
* `oldUrl` String
* `newUrl` String
* `isMainFrame` Boolean
Emitted when a redirect was received while requesting a resource.
### Event: 'crashed'
Emitted when the renderer process is crashed.
### Event: 'destroyed'
Emitted when the WebContents is destroyed.
### WebContents.loadUrl(url)
* `url` URL