]> khamidou — GitHub mirrors - electron.git/commitdiff
Add more events for WebContents
authorCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 15:05:25 +0000 (23:05 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 15:05:25 +0000 (23:05 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
docs/api/browser-window.md

index c221a28580aa4512c201facf625a786cdab99b11..d85f91ebfb022344eb7683001f5c106e2302a6df 100644 (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)
index 90f45caf98261b99efe538a32c961689b0867d10..7dbc1ca815f17d68493912d35da5fe33b83e34e5 100644 (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;
index 94c638a779022add91e4863c4aecf23bcdcd8708..c34df9133fc740781918f27370d7f3241773179f 100644 (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