Merge pull request #2424 from deepak1556/web_contents_patch

webcontents: minor patches
This commit is contained in:
Cheng Zhao 2015-08-06 09:52:16 +08:00
commit 20a8e7838f
9 changed files with 29 additions and 4 deletions

View file

@ -3,6 +3,7 @@ webContents = require 'web-contents'
webViewManager = null # Doesn't exist in early initialization. webViewManager = null # Doesn't exist in early initialization.
supportedWebViewEvents = [ supportedWebViewEvents = [
'load-commit'
'did-finish-load' 'did-finish-load'
'did-fail-load' 'did-fail-load'
'did-frame-finish-load' 'did-frame-finish-load'

View file

@ -5,7 +5,9 @@
#include "atom/browser/web_view_guest_delegate.h" #include "atom/browser/web_view_guest_delegate.h"
#include "atom/browser/api/atom_api_web_contents.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/guest_host.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
@ -128,6 +130,12 @@ void WebViewGuestDelegate::RenderViewReady() {
render_view_host_view->SetBackgroundColor(SK_ColorTRANSPARENT); 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) { void WebViewGuestDelegate::DidAttach(int guest_proxy_routing_id) {
api_web_contents_->Emit("did-attach"); api_web_contents_->Emit("did-attach");
} }

View file

@ -59,6 +59,9 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
protected: protected:
// content::WebContentsObserver: // content::WebContentsObserver:
void RenderViewReady() override; void RenderViewReady() override;
void DidCommitProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
const GURL& url, ui::PageTransition transition_type) override;
// content::BrowserPluginGuestDelegate: // content::BrowserPluginGuestDelegate:
void DidAttach(int guest_proxy_routing_id) final; void DidAttach(int guest_proxy_routing_id) final;

View file

@ -11,6 +11,7 @@ resolveUrl = (url) ->
# Window object returned by "window.open". # Window object returned by "window.open".
class BrowserWindowProxy class BrowserWindowProxy
constructor: (@guestId) -> constructor: (@guestId) ->
@closed = false
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', (guestId) => ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', (guestId) =>
if guestId is @guestId if guestId is @guestId
@closed = true @closed = true

View file

@ -4,6 +4,7 @@ webFrame = require 'web-frame'
requestId = 0 requestId = 0
WEB_VIEW_EVENTS = WEB_VIEW_EVENTS =
'load-commit': ['url', 'isMainFrame']
'did-finish-load': [] 'did-finish-load': []
'did-fail-load': ['errorCode', 'errorDescription'] 'did-fail-load': ['errorCode', 'errorDescription']
'did-frame-finish-load': ['isMainFrame'] 'did-frame-finish-load': ['isMainFrame']
@ -32,6 +33,7 @@ dispatchEvent = (webView, event, args...) ->
for f, i in WEB_VIEW_EVENTS[event] for f, i in WEB_VIEW_EVENTS[event]
domEvent[f] = args[i] domEvent[f] = args[i]
webView.dispatchEvent domEvent webView.dispatchEvent domEvent
webView.onLoadCommit domEvent if event == 'load-commit'
module.exports = module.exports =
registerEvents: (webView, viewInstanceId) -> registerEvents: (webView, viewInstanceId) ->

View file

@ -120,7 +120,7 @@ class SrcAttribute extends WebViewAttribute
'' ''
setValueIgnoreMutation: (value) -> setValueIgnoreMutation: (value) ->
WebViewAttribute::setValueIgnoreMutation value WebViewAttribute::setValueIgnoreMutation.call(this, value)
# takeRecords() is needed to clear queued up src mutations. Without it, it # 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 # 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 # mutation observer |observer|, and then get handled even though we do not

View file

@ -157,10 +157,10 @@ class WebViewImpl
enumerable: true enumerable: true
# Updates state upon loadcommit. # Updates state upon loadcommit.
onLoadCommit: (@baseUrlForDataUrl, @currentEntryIndex, @entryCount, @processId, url, isTopLevel) -> onLoadCommit: (webViewEvent) ->
oldValue = @webviewNode.getAttribute webViewConstants.ATTRIBUTE_SRC oldValue = @webviewNode.getAttribute webViewConstants.ATTRIBUTE_SRC
newValue = url newValue = webViewEvent.url
if isTopLevel and (oldValue != newValue) if webViewEvent.isMainFrame and (oldValue != newValue)
# Touching the src attribute triggers a navigation. To avoid # Touching the src attribute triggers a navigation. To avoid
# triggering a page reload on every guest-initiated navigation, # triggering a page reload on every guest-initiated navigation,
# we do not handle this mutation # we do not handle this mutation

View file

@ -335,6 +335,15 @@ examples.
## DOM events ## 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 ### did-finish-load
Fired when the navigation is done, i.e. the spinner of the tab will stop Fired when the navigation is done, i.e. the spinner of the tab will stop

View file

@ -37,6 +37,7 @@ describe 'chromium feature', ->
describe 'window.open', -> describe 'window.open', ->
it 'returns a BrowserWindowProxy object', -> it 'returns a BrowserWindowProxy object', ->
b = window.open 'about:blank', 'test', 'show=no' b = window.open 'about:blank', 'test', 'show=no'
assert.equal b.closed, false
assert.equal b.constructor.name, 'BrowserWindowProxy' assert.equal b.constructor.name, 'BrowserWindowProxy'
b.close() b.close()