Move loading events to webContents.
This commit is contained in:
parent
744895f9d8
commit
4135040449
8 changed files with 31 additions and 36 deletions
|
@ -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.
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {}
|
||||
|
||||
|
|
|
@ -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()', ->
|
||||
|
|
Loading…
Reference in a new issue