]> khamidou — GitHub mirrors - electron.git/commitdiff
Move loading events to webContents.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 04:22:16 +0000 (12:22 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 04:22:16 +0000 (12:22 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_observer.h
spec/api-browser-window-spec.coffee

index 9205bdf8b4c0450affcd28a4c091417965c851ad..ac3ec4abf616db4ec40f8a562d628f0d18a44348 100644 (file)
@@ -34,6 +34,21 @@ void WebContents::RenderProcessGone(base::TerminationStatus status) {
   Emit("crashed");
 }
 
+void WebContents::DidFinishLoad(int64 frame_id,
+                                const GURL& validated_url,
+                                bool is_main_frame,
+                                content::RenderViewHost* render_view_host) {
+  Emit("did-finish-load");
+}
+
+void WebContents::DidStartLoading(content::RenderViewHost* render_view_host) {
+  Emit("did-start-loading");
+}
+
+void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) {
+  Emit("did-stop-loading");
+}
+
 void WebContents::WebContentsDestroyed(content::WebContents*) {
   // The RenderViewDeleted is not called when the WebContents is destroyed
   // directly.
index e9a22a00b720d023b93f7e66d2f91c8b32119d9b..5bdf3c0d645c11c231135ad43249644279c4b710 100644 (file)
@@ -41,6 +41,15 @@ class WebContents : public mate::EventEmitter,
   // content::WebContentsObserver implementations:
   virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
+  virtual void DidFinishLoad(
+      int64 frame_id,
+      const GURL& validated_url,
+      bool is_main_frame,
+      content::RenderViewHost* render_view_host) OVERRIDE;
+  virtual void DidStartLoading(
+      content::RenderViewHost* render_view_host) OVERRIDE;
+  virtual void DidStopLoading(
+      content::RenderViewHost* render_view_host) OVERRIDE;
   virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
 
  private:
index 24bd64811e123cb903af002ade2765ae97047e12..482382f230fcf3092e61c9f846e5925bc705e164 100644 (file)
@@ -87,12 +87,6 @@ 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 1cf9169a9f3774c08fdba741ac24599eb2f0c536..e406e83c0a7374fcfb4d0c450188b3db0594bd4e 100644 (file)
@@ -50,7 +50,6 @@ class Window : public mate::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 8e1daa4dfa0b3626a97b9a30989868a3bcaf3c81..cd5c7cd5a6b327bb887316e7b23609bf886cce7e 100644 (file)
@@ -424,13 +424,6 @@ void NativeWindow::DeactivateContents(content::WebContents* contents) {
   BlurWebView();
 }
 
-void NativeWindow::LoadingStateChanged(content::WebContents* source) {
-  bool is_loading = source->IsLoading();
-  FOR_EACH_OBSERVER(NativeWindowObserver,
-                    observers_,
-                    OnLoadingStateChanged(is_loading));
-}
-
 void NativeWindow::MoveContents(content::WebContents* source,
                                 const gfx::Rect& pos) {
   SetPosition(pos.origin());
index ba8beecb78ebdcaff8b46f8911148860755273ef..c6bd037e2875424ce84093eaee3f4bede1d04146 100644 (file)
@@ -219,7 +219,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual bool CanOverscrollContent() const OVERRIDE;
   virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
   virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
-  virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
   virtual void MoveContents(content::WebContents* source,
                             const gfx::Rect& pos) OVERRIDE;
   virtual void CloseContents(content::WebContents* source) OVERRIDE;
index 52700e5bfe65c598cce76a4caf822c05a563efda..a7cb41fdaeea84bf648c01c44a42c135e7ba6af2 100644 (file)
@@ -17,9 +17,6 @@ class NativeWindowObserver {
   virtual void OnPageTitleUpdated(bool* prevent_default,
                                   const std::string& title) {}
 
-  // 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.
   virtual void WillCloseWindow(bool* prevent_default) {}
 
index 343ba4645babe9dd48c387c5132af634ef6a7f63..87e3a5249cda7a02b891e7f0c99fc5d36768b9ab 100644 (file)
@@ -18,9 +18,8 @@ describe 'browser-window module', ->
 
   describe 'BrowserWindow.close()', ->
     it 'should emit unload handler', (done) ->
-      w.on 'loading-state-changed', (event, isLoading) ->
-        if (!isLoading)
-          w.close()
+      w.webContents.on 'did-finish-load', ->
+        w.close()
       w.on 'closed', ->
         test = path.join(fixtures, 'api', 'unload')
         content = fs.readFileSync(test)
@@ -32,9 +31,8 @@ describe 'browser-window module', ->
     it 'should emit beforeunload handler', (done) ->
       w.on 'onbeforeunload', ->
         done()
-      w.on 'loading-state-changed', (event, isLoading) ->
-        if (!isLoading)
-          w.close()
+      w.webContents.on 'did-finish-load', ->
+        w.close()
       w.loadUrl 'file://' + path.join(fixtures, 'api', 'beforeunload-false.html')
 
   describe 'window.close()', ->
@@ -53,18 +51,9 @@ describe 'browser-window module', ->
       w.loadUrl 'file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')
 
   describe 'BrowserWindow.loadUrl(url)', ->
-    it 'should emit loading-state-changed event', (done) ->
-      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
+    it 'should emit did-start-loading event', (done) ->
+      w.webContents.on 'did-start-loading', ->
+        done()
       w.loadUrl 'about:blank'
 
   describe 'BrowserWindow.focus()', ->