webview: adding page-title-set event

This commit is contained in:
Robo 2015-04-05 14:50:42 +05:30
parent 5ff9588b48
commit 87af6f9c80
7 changed files with 26 additions and 0 deletions

View file

@ -240,6 +240,11 @@ void WebContents::DidNavigateMainFrame(
Emit("did-navigate-to-different-page"); Emit("did-navigate-to-different-page");
} }
void WebContents::TitleWasSet(content::NavigationEntry* entry,
bool explicit_set) {
Emit("page-title-set", entry->GetTitle(), explicit_set);
}
bool WebContents::OnMessageReceived(const IPC::Message& message) { bool WebContents::OnMessageReceived(const IPC::Message& message) {
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebContents, message) IPC_BEGIN_MESSAGE_MAP(WebContents, message)

View file

@ -172,6 +172,7 @@ class WebContents : public mate::EventEmitter,
void WebContentsDestroyed() override; void WebContentsDestroyed() override;
void NavigationEntryCommitted( void NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) override; const content::LoadCommittedDetails& load_details) override;
void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
// content::BrowserPluginGuestDelegate: // content::BrowserPluginGuestDelegate:
void DidAttach(int guest_proxy_routing_id) final; void DidAttach(int guest_proxy_routing_id) final;

View file

@ -14,6 +14,7 @@ supportedWebViewEvents = [
'close' 'close'
'crashed' 'crashed'
'destroyed' 'destroyed'
'page-title-set'
] ]
nextInstanceId = 0 nextInstanceId = 0

View file

@ -15,6 +15,7 @@ WEB_VIEW_EVENTS =
'close': [] 'close': []
'crashed': [] 'crashed': []
'destroyed': [] 'destroyed': []
'page-title-set': ['title', 'explicitSet']
dispatchEvent = (webView, event, args...) -> dispatchEvent = (webView, event, args...) ->
throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]? throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]?

View file

@ -310,6 +310,14 @@ Corresponds to the points in time when the spinner of the tab stops spinning.
Fired when a redirect was received while requesting a resource. Fired when a redirect was received while requesting a resource.
### page-title-set
* `title` String
* `explicitSet` Boolean
Fired when page ttile is set during navigation. `explicitSet` is false when title is synthesised from file
url.
### console-message ### console-message
* `level` Integer * `level` Integer

View file

@ -2,6 +2,7 @@
<body> <body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
console.log('a'); console.log('a');
document.title = "test"
</script> </script>
</body> </body>
</html> </html>

View file

@ -142,3 +142,12 @@ describe '<webview> tag', ->
webview.src = "file://#{fixtures}/pages/ipc-message.html" webview.src = "file://#{fixtures}/pages/ipc-message.html"
webview.setAttribute 'nodeintegration', 'on' webview.setAttribute 'nodeintegration', 'on'
document.body.appendChild webview document.body.appendChild webview
describe 'page-title-set event', ->
it 'emits when title is set', (done) ->
webview.addEventListener 'page-title-set', (e) ->
assert.equal e.title, 'test'
assert e.explicitSet
done()
webview.src = "file://#{fixtures}/pages/a.html"
document.body.appendChild webview