Merge pull request #1525 from deepak1556/dom_event_patch
webContents: providing dom-ready event
This commit is contained in:
commit
817dfbdc27
8 changed files with 52 additions and 0 deletions
|
@ -196,6 +196,12 @@ void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
|||
Emit("crashed");
|
||||
}
|
||||
|
||||
void WebContents::DocumentLoadedInFrame(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
if (!render_frame_host->GetParent())
|
||||
Emit("dom-ready");
|
||||
}
|
||||
|
||||
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url) {
|
||||
bool is_main_frame = !render_frame_host->GetParent();
|
||||
|
|
|
@ -145,6 +145,8 @@ class WebContents : public mate::EventEmitter,
|
|||
// content::WebContentsObserver:
|
||||
void RenderViewDeleted(content::RenderViewHost*) override;
|
||||
void RenderProcessGone(base::TerminationStatus status) override;
|
||||
void DocumentLoadedInFrame(
|
||||
content::RenderFrameHost* render_frame_host) override;
|
||||
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
const GURL& validated_url) override;
|
||||
void DidFailLoad(content::RenderFrameHost* render_frame_host,
|
||||
|
|
|
@ -10,6 +10,7 @@ supportedWebViewEvents = [
|
|||
'did-stop-loading'
|
||||
'did-get-response-details'
|
||||
'did-get-redirect-request'
|
||||
'dom-ready'
|
||||
'console-message'
|
||||
'new-window'
|
||||
'close'
|
||||
|
|
|
@ -12,6 +12,7 @@ WEB_VIEW_EVENTS =
|
|||
'did-get-response-details': ['status', 'newUrl', 'originalUrl',
|
||||
'httpResponseCode', 'requestMethod', 'referrer']
|
||||
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
|
||||
'dom-ready': []
|
||||
'console-message': ['level', 'message', 'line', 'sourceId']
|
||||
'new-window': ['url', 'frameName', 'disposition']
|
||||
'close': []
|
||||
|
|
|
@ -663,6 +663,12 @@ Emitted when details regarding a requested resource is available.
|
|||
|
||||
Emitted when a redirect was received while requesting a resource.
|
||||
|
||||
### Event: 'dom-ready'
|
||||
|
||||
* `event` Event
|
||||
|
||||
Emitted when document in the given frame is loaded.
|
||||
|
||||
### Event: 'page-favicon-updated'
|
||||
|
||||
* `event` Event
|
||||
|
|
|
@ -333,6 +333,10 @@ Fired when details regarding a requested resource is available.
|
|||
|
||||
Fired when a redirect was received while requesting a resource.
|
||||
|
||||
### dom-ready
|
||||
|
||||
Fired when document in the given frame is loaded.
|
||||
|
||||
### page-title-set
|
||||
|
||||
* `title` String
|
||||
|
|
|
@ -2,6 +2,8 @@ assert = require 'assert'
|
|||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
remote = require 'remote'
|
||||
http = require 'http'
|
||||
url = require 'url'
|
||||
|
||||
BrowserWindow = remote.require 'browser-window'
|
||||
|
||||
|
@ -222,3 +224,22 @@ describe 'browser-window module', ->
|
|||
assert.equal url, 'https://www.github.com/'
|
||||
done()
|
||||
w.loadUrl "file://#{fixtures}/pages/will-navigate.html"
|
||||
|
||||
describe 'dom-ready event', ->
|
||||
it 'emits when document is loaded', (done) ->
|
||||
server = http.createServer (req, res) ->
|
||||
action = url.parse(req.url, true).pathname
|
||||
if action == '/logo.png'
|
||||
img = fs.readFileSync(path.join(fixtures, 'assets', 'logo.png'))
|
||||
res.writeHead(200, {'Content-Type': 'image/png'})
|
||||
setTimeout ->
|
||||
res.end(img, 'binary')
|
||||
, 2000
|
||||
server.close()
|
||||
server.listen 62542, '127.0.0.1'
|
||||
remote.require('ipc').on 'dom-ready', (e, state) ->
|
||||
assert.equal state, 'interactive'
|
||||
done()
|
||||
w.webContents.on 'did-finish-load', ->
|
||||
w.close()
|
||||
w.loadUrl "file://#{fixtures}/pages/f.html"
|
||||
|
|
11
spec/fixtures/pages/f.html
vendored
Normal file
11
spec/fixtures/pages/f.html
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
<html>
|
||||
<body>
|
||||
<img src='http://127.0.0.1:62542/logo.png' />
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
var remote = require('remote')
|
||||
remote.getCurrentWindow().webContents.on('dom-ready', function() {
|
||||
require('ipc').send('dom-ready', document.readyState);
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue