Deprecate the page-title-set event

We have two names for the same event, page-title-updated wins.
This commit is contained in:
Cheng Zhao 2015-12-01 18:50:56 +08:00
parent c95117fb22
commit e5974e44ed
6 changed files with 24 additions and 18 deletions

View file

@ -520,9 +520,9 @@ void WebContents::DidNavigateMainFrame(
void WebContents::TitleWasSet(content::NavigationEntry* entry,
bool explicit_set) {
if (entry)
Emit("-page-title-set", entry->GetTitle(), explicit_set);
Emit("-page-title-updated", entry->GetTitle(), explicit_set);
else
Emit("-page-title-set", "", explicit_set);
Emit("-page-title-updated", "", explicit_set);
}
void WebContents::DidUpdateFaviconURL(

View file

@ -32,7 +32,7 @@ BrowserWindow::_init = ->
@emit 'crashed'
# Change window title to page title.
@webContents.on 'page-title-set', (event, title, explicitSet) =>
@webContents.on 'page-title-updated', (event, title, explicitSet) =>
@emit 'page-title-updated', event, title
@setTitle title unless event.defaultPrevented

View file

@ -76,13 +76,15 @@ wrapWebContents = (webContents) ->
# until next tick.
setImmediate => @emit 'did-fail-load', args...
# Delays the page-title-set event to next tick.
webContents.on '-page-title-set', (args...) ->
setImmediate => @emit 'page-title-set', args...
# Delays the page-title-updated event to next tick.
webContents.on '-page-title-updated', (args...) ->
setImmediate => @emit 'page-title-updated', args...
# Deprecated.
deprecate.rename webContents, 'loadUrl', 'loadURL'
deprecate.rename webContents, 'getUrl', 'getURL'
deprecate.event webContents, 'page-title-set', 'page-title-updated', (args...) ->
@emit 'page-title-set', args...
webContents.printToPDF = (options, callback) ->
printingSetting =

View file

@ -19,7 +19,7 @@ supportedWebViewEvents = [
'gpu-crashed'
'plugin-crashed'
'destroyed'
'page-title-set'
'page-title-updated'
'page-favicon-updated'
'enter-html-full-screen'
'leave-html-full-screen'

View file

@ -21,23 +21,27 @@ WEB_VIEW_EVENTS =
'gpu-crashed': []
'plugin-crashed': ['name', 'version']
'destroyed': []
'page-title-set': ['title', 'explicitSet']
'page-title-updated': ['title', 'explicitSet']
'page-favicon-updated': ['favicons']
'enter-html-full-screen': []
'leave-html-full-screen': []
dispatchEvent = (webView, event, args...) ->
throw new Error("Unknown event #{event}") unless WEB_VIEW_EVENTS[event]?
domEvent = new Event(event)
for f, i in WEB_VIEW_EVENTS[event]
DEPRECATED_EVENTS =
'page-title-updated': 'page-title-set'
dispatchEvent = (webView, eventName, eventKey, args...) ->
if DEPRECATED_EVENTS[eventName]?
dispatchEvent webView, DEPRECATED_EVENTS[eventName], eventKey, args...
domEvent = new Event(eventName)
for f, i in WEB_VIEW_EVENTS[eventKey]
domEvent[f] = args[i]
webView.dispatchEvent domEvent
webView.onLoadCommit domEvent if event == 'load-commit'
webView.onLoadCommit domEvent if eventName is 'load-commit'
module.exports =
registerEvents: (webView, viewInstanceId) ->
ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, domEvent, args...) ->
dispatchEvent webView, domEvent, args...
ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, eventName, args...) ->
dispatchEvent webView, eventName, eventName, args...
ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}", (event, channel, args...) ->
domEvent = new Event('ipc-message')

View file

@ -452,15 +452,15 @@ Fired when a redirect was received while requesting a resource.
Fired when document in the given frame is loaded.
### Event: 'page-title-set'
### Event: 'page-title-updated'
Returns:
* `title` String
* `explicitSet` Boolean
Fired when page title is set during navigation. `explicitSet` is false when title is synthesised from file
url.
Fired when page title is set during navigation. `explicitSet` is false when
title is synthesised from file url.
### Event: 'page-favicon-updated'