From: Cheng Zhao Date: Mon, 4 Jan 2016 04:09:11 +0000 (+0800) Subject: Rename did-navigate-to-different-page to did-navigate X-Git-Tag: v0.36.3~21^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4844e68ba16a6c67f87ba654e489c29ed196e0dc;p=electron.git Rename did-navigate-to-different-page to did-navigate --- diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index bbf9d690..3f39519a 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -566,7 +566,7 @@ void WebContents::DidNavigateMainFrame( const content::LoadCommittedDetails& details, const content::FrameNavigateParams& params) { if (details.is_navigation_to_different_page()) - Emit("did-navigate-to-different-page", params.url); + Emit("did-navigate", params.url); else if (details.is_in_page) Emit("did-navigate-in-page", params.url); } diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 8009e920..c99bf575 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -18,7 +18,7 @@ supportedWebViewEvents = [ 'devtools-focused' 'new-window' 'will-navigate' - 'did-navigate-to-different-page' + 'did-navigate' 'did-navigate-in-page' 'close' 'crashed' @@ -57,7 +57,7 @@ createGuest = (embedder, params) -> guestInstances[id] = {guest, embedder} # Destroy guest when the embedder is gone or navigated. - destroyEvents = ['destroyed', 'crashed', 'did-navigate-to-different-page'] + destroyEvents = ['destroyed', 'crashed', 'did-navigate'] destroy = -> destroyGuest embedder, id if guestInstances[id]? for event in destroyEvents diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index 9c06ac1f..30fe3d2a 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -20,7 +20,7 @@ WEB_VIEW_EVENTS = 'devtools-focused': [] 'new-window': ['url', 'frameName', 'disposition', 'options'] 'will-navigate': ['url'] - 'did-navigate-to-different-page': ['url'] + 'did-navigate': ['url'] 'did-navigate-in-page': ['url'] 'close': [] 'crashed': [] diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 66e8483a..b399e143 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -129,27 +129,43 @@ Returns: * `event` Event * `url` String -Emitted when a user or the page wants to start navigation. It can happen when the -`window.location` object is changed or a user clicks a link in the page. +Emitted when a user or the page wants to start navigation. It can happen when +the `window.location` object is changed or a user clicks a link in the page. This event will not emit when the navigation is started programmatically with APIs like `webContents.loadURL` and `webContents.back`. -It is also not emitted during in-page navigation, such as clicking anchor links -or updating the `window.location.hash`. Use `did-navigate-in-page` for this purpose. +It is also not emitted for in-page navigations, such as clicking anchor links +or updating the `window.location.hash`. Use `did-navigate-in-page` event for +this purpose. Calling `event.preventDefault()` will prevent the navigation. -### Event: 'did-navigate-to-different-page' +### Event: 'did-navigate' -Emitted when the new page that was navigated to is different from the previous -page. +Returns: + +* `event` Event +* `url` String + +Emitted when a navigation is done. + +This event is not emitted for in-page navigations, such as clicking anchor links +or updating the `window.location.hash`. Use `did-navigate-in-page` event for +this purpose. ### Event: 'did-navigate-in-page' -Emitted when the page url changes but does not cause navigation outside of the page. -Examples of this occurring are when anchor links are clicked or when the -DOM `hashchange` event is triggered. +Returns: + +* `event` Event +* `url` String + +Emitted when an in-page navigation happened. + +When in-page navigation happens, the page URL changes but does not cause +navigation outside of the page. Examples of this occurring are when anchor links +are clicked or when the DOM `hashchange` event is triggered. ### Event: 'crashed' diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 26b08f10..8b8f5ffd 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -579,24 +579,44 @@ webview.addEventListener('new-window', function(e) { ### Event: 'will-navigate' Returns: + * `url` String -Emitted when a user or the page wants to start navigation. It can happen when the -`window.location` object is changed or a user clicks a link in the page. It not -emitted during in-page navigation such as clicking anchor links or updating the -`window.location.hash`. Use `did-navigate-in-page` for this purpose. +Emitted when a user or the page wants to start navigation. It can happen when +the `window.location` object is changed or a user clicks a link in the page. + +This event will not emit when the navigation is started programmatically with +APIs like `.loadURL` and `.back`. + +It is also not emitted during in-page navigation, such as clicking anchor links +or updating the `window.location.hash`. Use `did-navigate-in-page` event for +this purpose. + +Calling `event.preventDefault()` does __NOT__ have any effect. +### Event: 'did-navigate' -### Event: 'did-navigate-to-different-page' +Returns: + +* `url` String -Emitted when the new page that was navigated to is different from the previous -page. +Emitted when a navigation is done. + +This event is not emitted for in-page navigations, such as clicking anchor links +or updating the `window.location.hash`. Use `did-navigate-in-page` event for +this purpose. ### Event: 'did-navigate-in-page' -Emitted when the page url changes but does not cause navigation outside of the page. -Examples of this occurring are when anchor links are clicked or when the -DOM `hashchange` event is triggered. +Returns: + +* `url` String + +Emitted when an in-page navigation happened. + +When in-page navigation happens, the page URL changes but does not cause +navigation outside of the page. Examples of this occurring are when anchor links +are clicked or when the DOM `hashchange` event is triggered. ### Event: 'close' diff --git a/spec/webview-spec.coffee b/spec/webview-spec.coffee index 9801b69a..1dcf739e 100644 --- a/spec/webview-spec.coffee +++ b/spec/webview-spec.coffee @@ -280,25 +280,25 @@ describe ' tag', -> webview.src = "file://#{fixtures}/pages/webview-will-navigate.html" document.body.appendChild webview - describe 'did-navigate-to-different-page event', -> - page_url = "file://#{fixtures}/pages/webview-will-navigate.html" + describe 'did-navigate event', -> + pageUrl = "file://#{fixtures}/pages/webview-will-navigate.html" it 'emits when a url that leads to outside of the page is clicked', (done) -> - webview.addEventListener 'did-navigate-to-different-page', (e) -> - assert.equal e.url, page_url + webview.addEventListener 'did-navigate', (e) -> + assert.equal e.url, pageUrl done() - webview.src = page_url + webview.src = pageUrl document.body.appendChild webview describe 'did-navigate-in-page event', -> it 'emits when an anchor link is clicked', (done) -> - page_url = "file://#{fixtures}/pages/webview-did-navigate-in-page.html" + pageUrl = "file://#{fixtures}/pages/webview-did-navigate-in-page.html" webview.addEventListener 'did-navigate-in-page', (e) -> - assert.equal e.url, "#{page_url}#test_content" + assert.equal e.url, "#{pageUrl}#test_content" done() - webview.src = page_url + webview.src = pageUrl document.body.appendChild webview it 'emits when window.history.replaceState is called', (done) -> @@ -310,12 +310,12 @@ describe ' tag', -> document.body.appendChild webview it 'emits when window.location.hash is changed', (done) -> - page_url = "file://#{fixtures}/pages/webview-did-navigate-in-page-with-hash.html" + pageUrl = "file://#{fixtures}/pages/webview-did-navigate-in-page-with-hash.html" webview.addEventListener 'did-navigate-in-page', (e) -> - assert.equal e.url, "#{page_url}#test" + assert.equal e.url, "#{pageUrl}#test" done() - webview.src = page_url + webview.src = pageUrl document.body.appendChild webview describe 'close event', ->