session.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict'
  2. const { EventEmitter } = require('events')
  3. const { app, deprecate } = require('electron')
  4. const { fromPartition, Session, Cookies, NetLog, Protocol } = process.electronBinding('session')
  5. // Public API.
  6. Object.defineProperties(exports, {
  7. defaultSession: {
  8. enumerable: true,
  9. get () { return fromPartition('') }
  10. },
  11. fromPartition: {
  12. enumerable: true,
  13. value: fromPartition
  14. }
  15. })
  16. Object.setPrototypeOf(Session.prototype, EventEmitter.prototype)
  17. Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype)
  18. Session.prototype._init = function () {
  19. app.emit('session-created', this)
  20. }
  21. Session.prototype.clearStorageData = deprecate.promisify(Session.prototype.clearStorageData)
  22. Session.prototype.clearHostResolverCache = deprecate.promisify(Session.prototype.clearHostResolverCache)
  23. Session.prototype.resolveProxy = deprecate.promisify(Session.prototype.resolveProxy)
  24. Session.prototype.setProxy = deprecate.promisify(Session.prototype.setProxy)
  25. Session.prototype.getCacheSize = deprecate.promisify(Session.prototype.getCacheSize)
  26. Session.prototype.clearCache = deprecate.promisify(Session.prototype.clearCache)
  27. Session.prototype.clearAuthCache = deprecate.promisify(Session.prototype.clearAuthCache)
  28. Session.prototype.getBlobData = deprecate.promisifyMultiArg(Session.prototype.getBlobData)
  29. Session.prototype.clearAuthCache = ((clearAuthCache) => function (...args) {
  30. if (args.length > 0) {
  31. deprecate.log(`The 'options' argument to 'clearAuthCache' is deprecated. Beginning with Electron 7, clearAuthCache will clear the entire auth cache unconditionally.`)
  32. }
  33. return clearAuthCache.apply(this, args)
  34. })(Session.prototype.clearAuthCache)
  35. Cookies.prototype.flushStore = deprecate.promisify(Cookies.prototype.flushStore)
  36. Cookies.prototype.get = deprecate.promisify(Cookies.prototype.get)
  37. Cookies.prototype.remove = deprecate.promisify(Cookies.prototype.remove)
  38. Cookies.prototype.set = deprecate.promisify(Cookies.prototype.set)
  39. NetLog.prototype.stopLogging = deprecate.promisify(NetLog.prototype.stopLogging)
  40. Protocol.prototype.isProtocolHandled = deprecate.promisify(Protocol.prototype.isProtocolHandled)