]> khamidou — GitHub mirrors - electron.git/commitdiff
webview: adding page-title-set event
authorRobo <hop2deep@gmail.com>
Sun, 5 Apr 2015 09:20:42 +0000 (14:50 +0530)
committerRobo <hop2deep@gmail.com>
Sun, 5 Apr 2015 09:20:42 +0000 (14:50 +0530)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/lib/guest-view-manager.coffee
atom/renderer/lib/web-view/guest-view-internal.coffee
docs/api/web-view-tag.md
spec/fixtures/pages/a.html
spec/webview-spec.coffee

index a9538167519bc6549869453daf136655e4dcbc05..4c76f5349eb541f77721b8123b6fd4b65f05858f 100644 (file)
@@ -240,6 +240,11 @@ void WebContents::DidNavigateMainFrame(
     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 handled = true;
   IPC_BEGIN_MESSAGE_MAP(WebContents, message)
index d570078d4c3469ecad36b2b907218e6b8c5631ff..8e0d12801a9a897d480379f3f0b1504b894de421 100644 (file)
@@ -172,6 +172,7 @@ class WebContents : public mate::EventEmitter,
   void WebContentsDestroyed() override;
   void NavigationEntryCommitted(
       const content::LoadCommittedDetails& load_details) override;
+  void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
 
   // content::BrowserPluginGuestDelegate:
   void DidAttach(int guest_proxy_routing_id) final;
index d3ab506a0242644b933184dded2d7ceca3249faf..b7caac22ac6dab1b5e17a9121081f309d819f816 100644 (file)
@@ -14,6 +14,7 @@ supportedWebViewEvents = [
   'close'
   'crashed'
   'destroyed'
+  'page-title-set'
 ]
 
 nextInstanceId = 0
index 99401784f599f8c6cf878ee3bbec8891072d24cc..f150615b937a509debf00ed24e0f76d32a31e735 100644 (file)
@@ -15,6 +15,7 @@ WEB_VIEW_EVENTS =
   'close': []
   'crashed': []
   'destroyed': []
+  'page-title-set': ['title', 'explicitSet']
 
 dispatchEvent = (webView, event, args...) ->
   throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]?
index 40ccf1f174a6e992dd267250674fa1d54bcc9a56..b1fdf6449e90c2f8724c1bbb1a8006d0a9e99f0d 100644 (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.
 
+### 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
 
 * `level` Integer
index 6889ce235b999e8030b4b34664d8819c6586e498..a471ad292d87830f7f7c9f419d118901c231d8c3 100644 (file)
@@ -2,6 +2,7 @@
 <body>
 <script type="text/javascript" charset="utf-8">
   console.log('a');
+  document.title = "test"
 </script>
 </body>
 </html>
index 6419d4ab045232440ad3e051902c0fb13e39e543..55ca8dc9ec78a3bf4b73190de47455a3dbb27971 100644 (file)
@@ -142,3 +142,12 @@ describe '<webview> tag', ->
       webview.src = "file://#{fixtures}/pages/ipc-message.html"
       webview.setAttribute 'nodeintegration', 'on'
       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