SandboxInitialiationParametersMac.mm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2013 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "SandboxInitializationParameters.h"
  27. namespace WebKit {
  28. SandboxInitializationParameters::SandboxInitializationParameters()
  29. : m_profileSelectionMode(UseDefaultSandboxProfilePath)
  30. {
  31. }
  32. SandboxInitializationParameters::~SandboxInitializationParameters()
  33. {
  34. for (size_t i = 0; i + 1 < m_namedParameters.size(); i += 2)
  35. fastFree(const_cast<char*>(m_namedParameters[i + 1]));
  36. }
  37. void SandboxInitializationParameters::appendPathInternal(const char* name, const char* path)
  38. {
  39. char normalizedPath[PATH_MAX];
  40. if (!realpath(path, normalizedPath))
  41. normalizedPath[0] = '\0';
  42. ASSERT(!(m_namedParameters.size() % 2));
  43. m_namedParameters.append(name);
  44. m_namedParameters.append(fastStrDup(normalizedPath));
  45. }
  46. void SandboxInitializationParameters::addConfDirectoryParameter(const char* name, int confID)
  47. {
  48. char path[PATH_MAX];
  49. if (confstr(confID, path, PATH_MAX) <= 0)
  50. path[0] = '\0';
  51. appendPathInternal(name, path);
  52. }
  53. void SandboxInitializationParameters::addPathParameter(const char* name, NSString *path)
  54. {
  55. appendPathInternal(name, [path length] ? [(NSString *)path fileSystemRepresentation] : "");
  56. }
  57. void SandboxInitializationParameters::addPathParameter(const char* name, const char* path)
  58. {
  59. appendPathInternal(name, path);
  60. }
  61. void SandboxInitializationParameters::addParameter(const char* name, const char* value)
  62. {
  63. m_namedParameters.append(name);
  64. m_namedParameters.append(fastStrDup(value));
  65. }
  66. const char* const* SandboxInitializationParameters::namedParameterArray() const
  67. {
  68. if (!(m_namedParameters.size() % 2))
  69. m_namedParameters.append(static_cast<const char*>(0));
  70. return m_namedParameters.data();
  71. }
  72. size_t SandboxInitializationParameters::count() const
  73. {
  74. return m_namedParameters.size() / 2;
  75. }
  76. const char* SandboxInitializationParameters::name(size_t index) const
  77. {
  78. ASSERT(index != m_namedParameters.size());
  79. return m_namedParameters[index * 2];
  80. }
  81. const char* SandboxInitializationParameters::value(size_t index) const
  82. {
  83. return m_namedParameters[index * 2 + 1];
  84. }
  85. } // namespace WebKit