cookies-tab.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const React = require("devtools/client/shared/vendor/react");
  6. const NetInfoGroupList = React.createFactory(require("./net-info-group-list"));
  7. const Spinner = React.createFactory(require("./spinner"));
  8. // Shortcuts
  9. const DOM = React.DOM;
  10. const PropTypes = React.PropTypes;
  11. /**
  12. * This template represents 'Cookies' tab displayed when the user
  13. * expands network log in the Console panel. It's responsible for rendering
  14. * sent and received cookies.
  15. */
  16. var CookiesTab = React.createClass({
  17. propTypes: {
  18. actions: PropTypes.shape({
  19. requestData: PropTypes.func.isRequired
  20. }),
  21. data: PropTypes.object.isRequired,
  22. },
  23. displayName: "CookiesTab",
  24. componentDidMount() {
  25. let { actions, data } = this.props;
  26. let requestCookies = data.request.cookies;
  27. let responseCookies = data.response.cookies;
  28. // TODO: use async action objects as soon as Redux is in place
  29. if (!requestCookies || !requestCookies.length) {
  30. actions.requestData("requestCookies");
  31. }
  32. if (!responseCookies || !responseCookies.length) {
  33. actions.requestData("responseCookies");
  34. }
  35. },
  36. render() {
  37. let { actions, data: file } = this.props;
  38. let requestCookies = file.request.cookies;
  39. let responseCookies = file.response.cookies;
  40. // The cookie panel displays two groups of cookies:
  41. // 1) Response Cookies
  42. // 2) Request Cookies
  43. let groups = [{
  44. key: "responseCookies",
  45. name: Locale.$STR("responseCookies"),
  46. params: responseCookies
  47. }, {
  48. key: "requestCookies",
  49. name: Locale.$STR("requestCookies"),
  50. params: requestCookies
  51. }];
  52. return (
  53. DOM.div({className: "cookiesTabBox"},
  54. DOM.div({className: "panelContent"},
  55. NetInfoGroupList({
  56. groups: groups
  57. })
  58. )
  59. )
  60. );
  61. }
  62. });
  63. // Exports from this module
  64. module.exports = CookiesTab;