Merge pull request #3645 from atom/fix-page-title-set
Delay the page-title-updated event to next tick
This commit is contained in:
commit
85b7aa6933
11 changed files with 30 additions and 37 deletions
|
@ -519,9 +519,10 @@ void WebContents::DidNavigateMainFrame(
|
|||
|
||||
void WebContents::TitleWasSet(content::NavigationEntry* entry,
|
||||
bool explicit_set) {
|
||||
// Back/Forward navigation may have pruned entries.
|
||||
if (entry)
|
||||
Emit("page-title-set", entry->GetTitle(), explicit_set);
|
||||
Emit("-page-title-updated", entry->GetTitle(), explicit_set);
|
||||
else
|
||||
Emit("-page-title-updated", "", explicit_set);
|
||||
}
|
||||
|
||||
void WebContents::DidUpdateFaviconURL(
|
||||
|
|
|
@ -161,11 +161,6 @@ Window::~Window() {
|
|||
Destroy();
|
||||
}
|
||||
|
||||
void Window::OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) {
|
||||
*prevent_default = Emit("page-title-updated", title);
|
||||
}
|
||||
|
||||
void Window::WillCloseWindow(bool* prevent_default) {
|
||||
*prevent_default = Emit("close");
|
||||
}
|
||||
|
|
|
@ -54,8 +54,6 @@ class Window : public mate::TrackableObject<Window>,
|
|||
virtual ~Window();
|
||||
|
||||
// NativeWindowObserver:
|
||||
void OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) override;
|
||||
void WillCloseWindow(bool* prevent_default) override;
|
||||
void OnWindowClosed() override;
|
||||
void OnWindowBlur() override;
|
||||
|
|
|
@ -31,6 +31,11 @@ BrowserWindow::_init = ->
|
|||
@webContents.on 'crashed', =>
|
||||
@emit 'crashed'
|
||||
|
||||
# Change window title to page title.
|
||||
@webContents.on 'page-title-updated', (event, title, explicitSet) =>
|
||||
@emit 'page-title-updated', event, title
|
||||
@setTitle title unless event.defaultPrevented
|
||||
|
||||
# Sometimes the webContents doesn't get focus when window is shown, so we have
|
||||
# to force focusing on webContents in this case. The safest way is to focus it
|
||||
# when we first start to load URL, if we do it earlier it won't have effect,
|
||||
|
|
|
@ -76,9 +76,15 @@ wrapWebContents = (webContents) ->
|
|||
# until next tick.
|
||||
setImmediate => @emit 'did-fail-load', 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 =
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -505,17 +505,6 @@ void NativeWindow::BeforeUnloadDialogCancelled() {
|
|||
window_unresposive_closure_.Cancel();
|
||||
}
|
||||
|
||||
void NativeWindow::TitleWasSet(content::NavigationEntry* entry,
|
||||
bool explicit_set) {
|
||||
bool prevent_default = false;
|
||||
std::string text = entry ? base::UTF16ToUTF8(entry->GetTitle()) : "";
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||
observers_,
|
||||
OnPageTitleUpdated(&prevent_default, text));
|
||||
if (!prevent_default && !is_closed_)
|
||||
SetTitle(text);
|
||||
}
|
||||
|
||||
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
|
||||
|
|
|
@ -262,7 +262,6 @@ class NativeWindow : public base::SupportsUserData,
|
|||
// content::WebContentsObserver:
|
||||
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
||||
void BeforeUnloadDialogCancelled() override;
|
||||
void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -21,10 +21,6 @@ class NativeWindowObserver {
|
|||
public:
|
||||
virtual ~NativeWindowObserver() {}
|
||||
|
||||
// Called when the web page of the window has updated it's document title.
|
||||
virtual void OnPageTitleUpdated(bool* prevent_default,
|
||||
const std::string& title) {}
|
||||
|
||||
// Called when the web page in window wants to create a popup window.
|
||||
virtual void WillCreatePopupWindow(const base::string16& frame_name,
|
||||
const GURL& target_url,
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
Loading…
Reference in a new issue