]> khamidou — GitHub mirrors - electron.git/commitdiff
webview: adding load-commit event
authorRobo <hop2deep@gmail.com>
Wed, 5 Aug 2015 11:50:23 +0000 (17:20 +0530)
committerRobo <hop2deep@gmail.com>
Wed, 5 Aug 2015 13:52:30 +0000 (19:22 +0530)
atom/browser/lib/guest-view-manager.coffee
atom/browser/web_view_guest_delegate.cc
atom/browser/web_view_guest_delegate.h
atom/renderer/lib/web-view/guest-view-internal.coffee
atom/renderer/lib/web-view/web-view-attributes.coffee
atom/renderer/lib/web-view/web-view.coffee
docs/api/web-view-tag.md

index 4385d389c39d5480e3d169490667e0e2fb05042a..971c15cb1b8552b155e4a5d678bbf2aa5e7c3259 100644 (file)
@@ -3,6 +3,7 @@ webContents = require 'web-contents'
 webViewManager = null  # Doesn't exist in early initialization.
 
 supportedWebViewEvents = [
+  'load-commit'
   'did-finish-load'
   'did-fail-load'
   'did-frame-finish-load'
index 98fa72da22d4c0c4dbff374f6c4079a197fbcbce..38f4da4c1f96235dd2ac918e43d959218f040768 100644 (file)
@@ -5,7 +5,9 @@
 #include "atom/browser/web_view_guest_delegate.h"
 
 #include "atom/browser/api/atom_api_web_contents.h"
+#include "atom/common/native_mate_converters/gurl_converter.h"
 #include "content/public/browser/guest_host.h"
+#include "content/public/browser/render_frame_host.h"
 #include "content/public/browser/render_view_host.h"
 #include "content/public/browser/render_widget_host_view.h"
 
@@ -128,6 +130,12 @@ void WebViewGuestDelegate::RenderViewReady() {
     render_view_host_view->SetBackgroundColor(SK_ColorTRANSPARENT);
 }
 
+void WebViewGuestDelegate::DidCommitProvisionalLoadForFrame(
+    content::RenderFrameHost* render_frame_host,
+    const GURL& url, ui::PageTransition transition_type) {
+  api_web_contents_->Emit("load-commit", url, !render_frame_host->GetParent());
+}
+
 void WebViewGuestDelegate::DidAttach(int guest_proxy_routing_id) {
   api_web_contents_->Emit("did-attach");
 }
index 267b5b248af69c118d354a2de8673a7aad621842..3312b46104a0c40c5036d303b234ab4a3c214730 100644 (file)
@@ -59,6 +59,9 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
  protected:
   // content::WebContentsObserver:
   void RenderViewReady() override;
+  void DidCommitProvisionalLoadForFrame(
+      content::RenderFrameHost* render_frame_host,
+      const GURL& url, ui::PageTransition transition_type) override;
 
   // content::BrowserPluginGuestDelegate:
   void DidAttach(int guest_proxy_routing_id) final;
index b62418d146d9c0fb09521b28572b24a696a426f3..44db5e304db403296ecc39905a5cc13bff428c2b 100644 (file)
@@ -4,6 +4,7 @@ webFrame = require 'web-frame'
 requestId = 0
 
 WEB_VIEW_EVENTS =
+  'load-commit': ['url', 'isMainFrame']
   'did-finish-load': []
   'did-fail-load': ['errorCode', 'errorDescription']
   'did-frame-finish-load': ['isMainFrame']
@@ -32,6 +33,7 @@ dispatchEvent = (webView, event, args...) ->
   for f, i in WEB_VIEW_EVENTS[event]
     domEvent[f] = args[i]
   webView.dispatchEvent domEvent
+  webView.onLoadCommit domEvent if event == 'load-commit'
 
 module.exports =
   registerEvents: (webView, viewInstanceId) ->
index 82229aae57b19b5efaef1981251670db10fb8227..acca826a9e3d255f5bae19de6c33cd6a1b518113 100644 (file)
@@ -120,7 +120,7 @@ class SrcAttribute extends WebViewAttribute
       ''
 
   setValueIgnoreMutation: (value) ->
-    WebViewAttribute::setValueIgnoreMutation value
+    WebViewAttribute::setValueIgnoreMutation.call(this, value)
     # takeRecords() is needed to clear queued up src mutations. Without it, it
     # is possible for this change to get picked up asyncronously by src's
     # mutation observer |observer|, and then get handled even though we do not
index eedee732938f95c3eea6ca9d800e22cbbd4f0381..35fbe17796f460537c3844ad7074acdf6c0855a2 100644 (file)
@@ -157,10 +157,10 @@ class WebViewImpl
       enumerable: true
 
   # Updates state upon loadcommit.
-  onLoadCommit: (@baseUrlForDataUrl, @currentEntryIndex, @entryCount, @processId, url, isTopLevel) ->
+  onLoadCommit: (webViewEvent) ->
     oldValue = @webviewNode.getAttribute webViewConstants.ATTRIBUTE_SRC
-    newValue = url
-    if isTopLevel and (oldValue != newValue)
+    newValue = webViewEvent.url
+    if webViewEvent.isMainFrame and (oldValue != newValue)
       # Touching the src attribute triggers a navigation. To avoid
       # triggering a page reload on every guest-initiated navigation,
       # we do not handle this mutation
index a74f5fb50c775654ce6853447069733be43afa25..07d84324dd4b7b206f76e038777b7299e2983d5d 100644 (file)
@@ -335,6 +335,15 @@ examples.
 
 ## DOM events
 
+### load-commit
+
+* `url` String
+* `isMainFrame` Boolean
+
+Fired when a load has committed. This includes navigation within the current
+document as well as subframe document-level loads, but does not include
+asynchronous resource loads.
+
 ### did-finish-load
 
 Fired when the navigation is done, i.e. the spinner of the tab will stop