Skip to content

app: add will-download event to defaultSession - #2650

Merged
zcbenz merged 2 commits into
electron:masterfrom
deepak1556:webcontents_download_event_patch
Sep 1, 2015
Merged

zcbenz merged 2 commits into
electron:masterfrom
deepak1556:webcontents_download_event_patch

Conversation

@deepak1556

Copy link
Copy Markdown
Member

Fixes #2491

Comment thread docs/api/web-view-tag.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra space here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

@hokein

hokein commented Aug 31, 2015

Copy link
Copy Markdown
Contributor

Great. 👍

@deepak1556
deepak1556 force-pushed the webcontents_download_event_patch branch from d144e9d to e6a5933 Compare August 31, 2015 06:15
@zcbenz

zcbenz commented Aug 31, 2015

Copy link
Copy Markdown
Contributor

The download manager is session wide, so one download from one WebContents will be populated to all WebContents in current implementation.

We can probably make it an event of Session instead of WebContents, and also pass the webContents to let users decide whether to handle it. And passing url directly as an argument can be a bad idea in this case, because it is not easy to see whether it is the url of webContents or the download item. So the final API can look like this:

app.defaultSession.on 'will-download', (event, webContents, item) ->
  console.log(item.url, item.mimeType, item.filename);

@zcbenz

zcbenz commented Aug 31, 2015

Copy link
Copy Markdown
Contributor

Adding this event to webview doesn't make much sense, because we can not prevent the default action in webview (renderer's callback is always called asynchronously).

@zcbenz

zcbenz commented Aug 31, 2015

Copy link
Copy Markdown
Contributor

Also we need to remove this from the observer list when the class is destroyed.

@zcbenz zcbenz closed this Aug 31, 2015
@zcbenz zcbenz reopened this Aug 31, 2015
@deepak1556
deepak1556 force-pushed the webcontents_download_event_patch branch from e6a5933 to aed487e Compare August 31, 2015 07:28
@deepak1556

Copy link
Copy Markdown
Member Author

@zcbenz have made the changes.

@deepak1556 deepak1556 changed the title webContents: add will-download event app: add will-download event to defaultSession Aug 31, 2015
Comment thread atom/browser/api/atom_api_session.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObjectTemplateBuilder creates a new ObjectTemplate every time and the call is very expensive, we should just use Dictionary in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@kjlaw89

kjlaw89 commented Aug 31, 2015

Copy link
Copy Markdown

@deepak1556 You're most awesome! Thanks for looking into this for us.

Comment thread atom/browser/api/atom_api_app.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The g_wrap_session should be called in Session::CreateFrom, and _setWrapSession should be implemented in atom_api_session.cc too, so we don't have to call it for every place that creates a session.

Also I still prefer implementing DefaultSession in C++, it would be very helpful when we need to get it in C++ code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if _setWrapSession is implemented in atom_api_session.cc then have to expose session as a builtin module to use on the js side, is that correct ? and yeah that would help us calling it in one place.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can expose it as a builtin module, but we should keep it undocumented for now before we have full support for multi-session.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, Thanks!

@deepak1556
deepak1556 force-pushed the webcontents_download_event_patch branch from cf77fd5 to 4062ca5 Compare September 1, 2015 11:21
@zcbenz

zcbenz commented Sep 1, 2015

Copy link
Copy Markdown
Contributor

Thanks!

zcbenz added a commit that referenced this pull request Sep 1, 2015
…atch

app: add will-download event to defaultSession
@zcbenz
zcbenz merged commit 4e7f568 into electron:master Sep 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants