AboutData.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (C) 2012 Sony Computer Entertainment Inc.
  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 COMPUTER, INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "AboutData.h"
  27. #include "MemoryCache.h"
  28. #include "TextEncoding.h"
  29. #include <wtf/text/Base64.h>
  30. #if OS(PSP2)
  31. extern "C" size_t malloc_max_inuse_size();
  32. extern "C" size_t malloc_current_inuse_size();
  33. #endif
  34. using namespace WebCore;
  35. static String htmlHeader(const KURL& aboutUrl);
  36. static String htmlBody(const KURL& aboutUrl);
  37. static String aboutManxBody();
  38. static String aboutMemoryBody();
  39. static String css();
  40. static const char* compassData();
  41. KURL createAboudDataUri(const KURL& aboutUrl)
  42. {
  43. if (aboutUrl.path() == "blank")
  44. return WebCore::KURL();
  45. if (aboutUrl.path() == "compass") {
  46. String url = "data:text/html;charset=utf-8;base64,";
  47. url.append(compassData());
  48. return KURL(KURL(), url, UTF8Encoding());
  49. }
  50. String html;
  51. html.append("<html><head>");
  52. html.append(htmlHeader(aboutUrl));
  53. html.append("<head/><body>");
  54. html.append(htmlBody(aboutUrl));
  55. html.append("</body></html>");
  56. String url = "data:text/html;charset=utf-8;base64,";
  57. url.append(base64Encode(html.ascii(), Base64DoNotInsertLFs));
  58. return KURL(KURL(), url, UTF8Encoding());
  59. }
  60. static String htmlHeader(const KURL& aboutUrl)
  61. {
  62. String header;
  63. header.append("<title>About</title>");
  64. header.append(css());
  65. return header;
  66. }
  67. static String htmlBody(const KURL& aboutUrl)
  68. {
  69. if (aboutUrl.path() == "memory")
  70. return aboutMemoryBody();
  71. return aboutManxBody();
  72. }
  73. static String aboutManxBody()
  74. {
  75. String body = "";
  76. return body;
  77. }
  78. static String mallocStatisticsTable()
  79. {
  80. size_t max = 0;
  81. size_t current = 0;
  82. #if OS(PSP2)
  83. max = malloc_max_inuse_size();
  84. current = malloc_current_inuse_size();
  85. #endif
  86. String table = "<table><tr><th>maxInUse</th><th>currentInUse</th></tr>";
  87. table.append("<tr><td>" + String::number(max) + "</td>");
  88. table.append("<td>" + String::number(current) + "</td></tr></table>");
  89. return table;
  90. }
  91. static String memoryCacheStatisticsHeader()
  92. {
  93. String row;
  94. row.append("<tr>");
  95. row.append("<th></th>");
  96. row.append("<th>count</th>");
  97. row.append("<th>size</th>");
  98. row.append("<th>liveSize</th>");
  99. row.append("<th>decodedSize</th>");
  100. row.append("<th>purgeableSize</th>");
  101. row.append("<th>purgedSize</th>");
  102. row.append("</tr>");
  103. return row;
  104. }
  105. static String memoryCacheStatisticsRow(const MemoryCache::TypeStatistic& statistic, const String& description)
  106. {
  107. String row;
  108. row.append("<tr>");
  109. row.append("<td>" + description + "</td>");
  110. row.append("<td>" + String::number(statistic.count) + "</td>");
  111. row.append("<td>" + String::number(statistic.size) + "</td>");
  112. row.append("<td>" + String::number(statistic.liveSize) + "</td>");
  113. row.append("<td>" + String::number(statistic.decodedSize) + "</td>");
  114. row.append("<td>" + String::number(statistic.purgeableSize) + "</td>");
  115. row.append("<td>" + String::number(statistic.purgedSize) + "</td>");
  116. row.append("</tr>");
  117. return row;
  118. }
  119. #define ADD_MEMORY_STATISTICS_ROW(x) body.append(memoryCacheStatisticsRow(statistic.x, #x));
  120. static String aboutMemoryBody()
  121. {
  122. String body;
  123. // FastMalloc
  124. body.append("<h3>malloc</h3>");
  125. body.append(mallocStatisticsTable());
  126. // MemoryCache
  127. body.append("<h3>MemoryCache</h3>");
  128. body.append("<table>");
  129. body.append(memoryCacheStatisticsHeader());
  130. MemoryCache::Statistics statistic = memoryCache()->getStatistics();
  131. ADD_MEMORY_STATISTICS_ROW(images);
  132. ADD_MEMORY_STATISTICS_ROW(cssStyleSheets);
  133. ADD_MEMORY_STATISTICS_ROW(scripts);
  134. ADD_MEMORY_STATISTICS_ROW(xslStyleSheets);
  135. ADD_MEMORY_STATISTICS_ROW(fonts);
  136. body.append("</table>");
  137. return body;
  138. }
  139. static String css()
  140. {
  141. String css;
  142. css.append("<style type=\"text/css\">");
  143. css.append("* { font-family: sans-serif }");
  144. css.append("table { border: 1px White solid); border-collapse: collapse); }");
  145. css.append("tr:nth-child(odd) { background-color:WhiteSmoke }");
  146. css.append("tr:nth-child(even) { background-color:White }");
  147. css.append("th { background-color:Gainsboro }");
  148. css.append("td { text-align:right; width:20em; padding:2px }");
  149. css.append("</style>");
  150. return css;
  151. }
  152. static const char* compassData()
  153. {
  154. return
  155. "PGh0bWw+PGhlYWQ+PG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRoPWRldmljZS13"
  156. "aWR0aCxpbml0aWFsLXNjYWxlPTEuMCx1c2VyLXNjYWxhYmxlPW5vOyI+PC9oZWFkPjxib2R5IHN0"
  157. "eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOmJsYWNrIj48ZGl2IHN0eWxlPSJ3aWR0aDoxMjg7dG9wOjUw"
  158. "JTtsZWZ0OjUwJTstd2Via2l0LXRyYW5zZm9ybTp0cmFuc2xhdGUoLTY0cHgsLTY0cHgpO3Bvc2l0"
  159. "aW9uOnJlbGF0aXZlIj48Y2FudmFzIGlkPSJiIiB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgc3R5"
  160. "bGU9InBvc2l0aW9uOmFic29sdXRlOyI+PC9jYW52YXM+PGNhbnZhcyBpZD0ibyIgd2lkdGg9IjE2"
  161. "IiBoZWlnaHQ9IjE2IiBzdHlsZT0icG9zaXRpb246YWJzb2x1dGU7Ij48L2NhbnZhcz48Y2FudmFz"
  162. "IGlkPSJnIiB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHN0eWxlPSJwb3NpdGlvbjphYnNvbHV0ZTsi"
  163. "PjwvY2FudmFzPjwvZGl2PjxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij52YXIgY29sb3I9"
  164. "J3JnYmEoNSwgMTg1LCA1LCAwLjcpJzt2YXIgY29udGV4dCA9IGRvY3VtZW50LmdldEVsZW1lbnRC"
  165. "eUlkKCdiJykuZ2V0Q29udGV4dCgnMmQnKTtjb250ZXh0LnN0cm9rZVN0eWxlPWNvbG9yO2NvbnRl"
  166. "eHQubGluZVdpZHRoID0gMjtjb250ZXh0LmJlZ2luUGF0aCgpO2NvbnRleHQuYXJjKDY0LCA2N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