ProfilesPanelDescriptor.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2013 Google 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 are
  6. * met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above
  12. * copyright notice, this list of conditions and the following disclaimer
  13. * in the documentation and/or other materials provided with the
  14. * distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
  17. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
  20. * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /**
  29. * @constructor
  30. * @extends {WebInspector.PanelDescriptor}
  31. */
  32. WebInspector.ProfilesPanelDescriptor = function()
  33. {
  34. WebInspector.PanelDescriptor.call(this, "profiles", WebInspector.UIString("Profiles"), "ProfilesPanel", "ProfilesPanel.js");
  35. }
  36. WebInspector.ProfilesPanelDescriptor.prototype = {
  37. registerShortcuts: function()
  38. {
  39. var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Profiles Panel"));
  40. section.addAlternateKeys(WebInspector.ProfilesPanelDescriptor.ShortcutKeys.StartStopRecording, WebInspector.UIString("Start/stop recording"));
  41. },
  42. __proto__: WebInspector.PanelDescriptor.prototype
  43. }
  44. WebInspector.ProfilesPanelDescriptor.ShortcutKeys = {
  45. StartStopRecording: [
  46. WebInspector.KeyboardShortcut.makeDescriptor("e", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  47. ]
  48. }
  49. WebInspector.ProfilesPanelDescriptor.ProfileURLRegExp = /webkit-profile:\/\/(.+)\/(.+)/;
  50. WebInspector.ProfilesPanelDescriptor.UserInitiatedProfileName = "org.webkit.profiles.user-initiated";
  51. /**
  52. * @param {string} title
  53. * @return {boolean}
  54. */
  55. WebInspector.ProfilesPanelDescriptor.isUserInitiatedProfile = function(title)
  56. {
  57. return title.startsWith(WebInspector.ProfilesPanelDescriptor.UserInitiatedProfileName);
  58. }
  59. /**
  60. * @param {string} title
  61. * @return {number}
  62. * @throws {string}
  63. */
  64. WebInspector.ProfilesPanelDescriptor.userInitiatedProfileIndex = function(title)
  65. {
  66. if (!WebInspector.ProfilesPanelDescriptor.isUserInitiatedProfile(title))
  67. throw "Not user-initiated profile title.";
  68. var suffix = title.substring(WebInspector.ProfilesPanelDescriptor.UserInitiatedProfileName.length + 1);
  69. return parseInt(suffix, 10);
  70. }
  71. /**
  72. * @param {string} title
  73. * @return {string}
  74. */
  75. WebInspector.ProfilesPanelDescriptor.resolveProfileTitle = function(title)
  76. {
  77. if (!WebInspector.ProfilesPanelDescriptor.isUserInitiatedProfile(title))
  78. return title;
  79. return WebInspector.UIString("Profile %d", WebInspector.ProfilesPanelDescriptor.userInitiatedProfileIndex(title));
  80. }
  81. /**
  82. * @param {Event} event
  83. */
  84. WebInspector.ProfilesPanelDescriptor._openCPUProfile = function(event)
  85. {
  86. event.preventDefault();
  87. var panel = WebInspector.showPanel("profiles");
  88. var link = /** @type {!Element} */ (event.target);
  89. var view = /** @type {WebInspector.CPUProfileView} */ (panel.showProfile("CPU", link.profileUID));
  90. if (!view)
  91. return;
  92. if (typeof link.timeLeft === "number" && typeof link.timeRight === "number")
  93. view.selectRange(link.timeLeft, link.timeRight);
  94. }
  95. /**
  96. * @param {number} uid
  97. * @param {string} linkText
  98. * @param {number=} timeLeft
  99. * @param {number=} timeRight
  100. * @param {string=} tooltipText
  101. * @return {!Element}
  102. */
  103. WebInspector.ProfilesPanelDescriptor.linkifyCPUProfile = function(uid, linkText, timeLeft, timeRight, tooltipText)
  104. {
  105. var link = document.createElement("a");
  106. link.innerText = linkText;
  107. link.href = WebInspector.UIString("show CPU profile");
  108. link.target = "_blank";
  109. if (tooltipText)
  110. link.title = tooltipText;
  111. link.timeLeft = timeLeft;
  112. link.timeRight = timeRight;
  113. link.profileUID = uid;
  114. link.addEventListener("click", WebInspector.ProfilesPanelDescriptor._openCPUProfile, true);
  115. return link;
  116. }