]> khamidou — GitHub mirrors - electron.git/commitdiff
Add 'loading-state-changed' event for BrowserWindow.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 29 Aug 2013 03:47:07 +0000 (11:47 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 29 Aug 2013 03:47:07 +0000 (11:47 +0800)
It's required for testing the BrowserWindow class.

browser/api/atom_api_window.cc
browser/api/atom_api_window.h
browser/native_window_observer.h
docs/browser-window.md
spec/api/window.coffee

index df70545c005e595c6e9afaa281511f43225b3f18..4749f7ec04b0c6d05d63be5d147bfb85af7626e7 100644 (file)
@@ -56,6 +56,12 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
   *prevent_default = Emit("page-title-updated", &args);
 }
 
+void Window::OnLoadingStateChanged(bool is_loading) {
+  base::ListValue args;
+  args.AppendBoolean(is_loading);
+  Emit("loading-state-changed", &args);
+}
+
 void Window::WillCloseWindow(bool* prevent_default) {
   *prevent_default = Emit("close");
 }
index 48e7678924d759944477560c68dbaa961996e19f..1de71781eb58ef44c56f8ca5b8fad33626d7f0bc 100644 (file)
@@ -35,6 +35,7 @@ class Window : public EventEmitter,
   // Implementations of NativeWindowObserver.
   virtual void OnPageTitleUpdated(bool* prevent_default,
                                   const std::string& title) OVERRIDE;
+  virtual void OnLoadingStateChanged(bool is_loading) OVERRIDE;
   virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
   virtual void OnWindowClosed() OVERRIDE;
   virtual void OnWindowBlur() OVERRIDE;
index 54f8d01ddc475416368ee096ab34f0b21b3291ce..5d06f983bd55948961e363d9eba7f4661918bbf8 100644 (file)
@@ -17,7 +17,7 @@ class NativeWindowObserver {
   virtual void OnPageTitleUpdated(bool* prevent_default,
                                   const std::string& title) {}
 
-  // Called when the window is starting or is done loading a resource.
+  // Called when the window is starting or is done loading a page.
   virtual void OnLoadingStateChanged(bool is_loading) {}
 
   // Called when the window is gonna closed.
index f9fcc9bd9e9225504abfb2d1885c5826ff1541a0..f6a3fa9c963c2d8f0ea53308de9b384a2b8c3d53 100644 (file)
@@ -45,6 +45,13 @@ Creates a new `BrowserWindow` with native properties set by the `options`. Usual
 
 Emitted when the document changed its title, calling `event.preventDefault()` would prevent the native window's title to change.
 
+### Event: 'loading-state-changed'
+
+* `event` Event
+* `isLoading` Boolean
+
+Emitted when the window is starting or is done loading a page.
+
 ### Event: 'close'
 
 * `event` Event
@@ -325,4 +332,4 @@ Reloads current window.
 
 ### BrowserWindow.reloadIgnoringCache()
 
-Reloads current window and ignores cache.
\ No newline at end of file
+Reloads current window and ignores cache.
index a0c5e795e005cc07ffd6750d95d7310895dbc786..cd832e9618b00c04d540183c1f6128a67920ebfe 100644 (file)
@@ -31,3 +31,19 @@ describe 'window module', ->
         assert.equal String(content), 'close'
         done()
       w.loadUrl 'file://' + path.join(fixtures, 'api', 'close.html')
+
+  describe 'BrowserWindow.loadUrl(url)', ->
+    it 'should emit loading-state-changed event', (done) ->
+      w = new BrowserWindow(show: false)
+      count = 0
+      w.on 'loading-state-changed', (event, isLoading) ->
+        if count == 0
+          assert.equal isLoading, true
+        else if count == 1
+          assert.equal isLoading, false
+          done()
+        else
+          assert false
+
+        ++count
+      w.loadUrl 'about:blank'