Move loading events to webContents.

This commit is contained in:
Cheng Zhao 2014-04-25 12:22:16 +08:00
parent 744895f9d8
commit 4135040449
8 changed files with 31 additions and 36 deletions

View file

@ -34,6 +34,21 @@ void WebContents::RenderProcessGone(base::TerminationStatus status) {
Emit("crashed"); 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*) { void WebContents::WebContentsDestroyed(content::WebContents*) {
// The RenderViewDeleted is not called when the WebContents is destroyed // The RenderViewDeleted is not called when the WebContents is destroyed
// directly. // directly.

View file

@ -41,6 +41,15 @@ class WebContents : public mate::EventEmitter,
// content::WebContentsObserver implementations: // content::WebContentsObserver implementations:
virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE; virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
virtual void RenderProcessGone(base::TerminationStatus status) 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; virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
private: private:

View file

@ -87,12 +87,6 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
*prevent_default = Emit("page-title-updated", args); *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) { void Window::WillCloseWindow(bool* prevent_default) {
*prevent_default = Emit("close"); *prevent_default = Emit("close");
} }

View file

@ -50,7 +50,6 @@ class Window : public mate::EventEmitter,
// Implementations of NativeWindowObserver: // Implementations of NativeWindowObserver:
virtual void OnPageTitleUpdated(bool* prevent_default, virtual void OnPageTitleUpdated(bool* prevent_default,
const std::string& title) OVERRIDE; const std::string& title) OVERRIDE;
virtual void OnLoadingStateChanged(bool is_loading) OVERRIDE;
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE; virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
virtual void OnWindowClosed() OVERRIDE; virtual void OnWindowClosed() OVERRIDE;
virtual void OnWindowBlur() OVERRIDE; virtual void OnWindowBlur() OVERRIDE;

View file

@ -424,13 +424,6 @@ void NativeWindow::DeactivateContents(content::WebContents* contents) {
BlurWebView(); 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, void NativeWindow::MoveContents(content::WebContents* source,
const gfx::Rect& pos) { const gfx::Rect& pos) {
SetPosition(pos.origin()); SetPosition(pos.origin());

View file

@ -219,7 +219,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual bool CanOverscrollContent() const OVERRIDE; virtual bool CanOverscrollContent() const OVERRIDE;
virtual void ActivateContents(content::WebContents* contents) OVERRIDE; virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
virtual void MoveContents(content::WebContents* source, virtual void MoveContents(content::WebContents* source,
const gfx::Rect& pos) OVERRIDE; const gfx::Rect& pos) OVERRIDE;
virtual void CloseContents(content::WebContents* source) OVERRIDE; virtual void CloseContents(content::WebContents* source) OVERRIDE;

View file

@ -17,9 +17,6 @@ class NativeWindowObserver {
virtual void OnPageTitleUpdated(bool* prevent_default, virtual void OnPageTitleUpdated(bool* prevent_default,
const std::string& title) {} 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. // Called when the window is gonna closed.
virtual void WillCloseWindow(bool* prevent_default) {} virtual void WillCloseWindow(bool* prevent_default) {}

View file

@ -18,8 +18,7 @@ describe 'browser-window module', ->
describe 'BrowserWindow.close()', -> describe 'BrowserWindow.close()', ->
it 'should emit unload handler', (done) -> it 'should emit unload handler', (done) ->
w.on 'loading-state-changed', (event, isLoading) -> w.webContents.on 'did-finish-load', ->
if (!isLoading)
w.close() w.close()
w.on 'closed', -> w.on 'closed', ->
test = path.join(fixtures, 'api', 'unload') test = path.join(fixtures, 'api', 'unload')
@ -32,8 +31,7 @@ describe 'browser-window module', ->
it 'should emit beforeunload handler', (done) -> it 'should emit beforeunload handler', (done) ->
w.on 'onbeforeunload', -> w.on 'onbeforeunload', ->
done() done()
w.on 'loading-state-changed', (event, isLoading) -> w.webContents.on 'did-finish-load', ->
if (!isLoading)
w.close() w.close()
w.loadUrl 'file://' + path.join(fixtures, 'api', 'beforeunload-false.html') w.loadUrl 'file://' + path.join(fixtures, 'api', 'beforeunload-false.html')
@ -53,18 +51,9 @@ describe 'browser-window module', ->
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html') w.loadUrl 'file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')
describe 'BrowserWindow.loadUrl(url)', -> describe 'BrowserWindow.loadUrl(url)', ->
it 'should emit loading-state-changed event', (done) -> it 'should emit did-start-loading event', (done) ->
count = 0 w.webContents.on 'did-start-loading', ->
w.on 'loading-state-changed', (event, isLoading) ->
if count == 0
assert.equal isLoading, true
else if count == 1
assert.equal isLoading, false
done() done()
else
assert false
++count
w.loadUrl 'about:blank' w.loadUrl 'about:blank'
describe 'BrowserWindow.focus()', -> describe 'BrowserWindow.focus()', ->