From: Cheng Zhao Date: Fri, 25 Apr 2014 04:22:16 +0000 (+0800) Subject: Move loading events to webContents. X-Git-Tag: v0.12.0~11^2~9 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4135040449bdb61da1d9b25204cca8167b70b239;p=electron.git Move loading events to webContents. --- diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9205bdf8..ac3ec4ab 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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. diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e9a22a00..5bdf3c0d 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -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: diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 24bd6481..482382f2 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -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"); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 1cf9169a..e406e83c 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -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; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 8e1daa4d..cd5c7cd5 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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()); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index ba8beecb..c6bd037e 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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; diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 52700e5b..a7cb41fd 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -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) {} diff --git a/spec/api-browser-window-spec.coffee b/spec/api-browser-window-spec.coffee index 343ba464..87e3a524 100644 --- a/spec/api-browser-window-spec.coffee +++ b/spec/api-browser-window-spec.coffee @@ -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()', ->