Skip to content

Commit

Permalink
electron#10039 add BrowserView.fromId
Browse files Browse the repository at this point in the history
  • Loading branch information
liusy182 committed Jul 24, 2017
1 parent a43553a commit ae7c1ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion atom/browser/api/atom_api_browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void Initialize(v8::Local<v8::Object> exports,

mate::Dictionary browser_view(
isolate, BrowserView::GetConstructor(isolate)->GetFunction());

browser_view.SetMethod("fromId",
&mate::TrackableObject<BrowserView>::FromWeakMapID);
mate::Dictionary dict(isolate, exports);
dict.Set("BrowserView", browser_view);
}
Expand Down
8 changes: 8 additions & 0 deletions docs/api/browser-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ view.webContents.loadURL('https://electron.atom.io')
* `options` Object (optional)
* `webPreferences` Object (optional) - See [BrowserWindow](browser-window.md).

### Static Methods

#### `BrowserView.fromId(id)`

* `id` Integer

Returns `BrowserView` - The view with the given `id`.

### Instance Properties

Objects created with `new BrowserView` have the following properties:
Expand Down
10 changes: 10 additions & 0 deletions spec/api-browser-view-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ describe('BrowserView module', function () {
assert.ok(!view.webContents.getOwnerBrowserWindow())
})
})

describe('BrowserView.fromId()', function () {
it('returns the view with given id', function () {
view = new BrowserView()
w.setBrowserView(view)
assert.notEqual(view.id, null)
let view2 = BrowserView.fromId(view.id)
assert.equal(view2.webContents.id, view.webContents.id)
})
})
})

0 comments on commit ae7c1ae

Please sign in to comment.