PageRenderTime 96ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/chrome/chromeFiles/content/services.js

https://github.com/studgeek/WebStorm-Firefox-Connector
JavaScript | 129 lines | 108 code | 20 blank | 1 comment | 3 complexity | 73c244fb56f5da3ffcfcc0ef66c7609b MD5 | raw file
  1. JBExtension.isLoggingEnabled = true;
  2. JBExtension.isProcessingLogMessage = false;
  3. JBExtension.Services = {
  4. nsITransport: Components.interfaces.nsITransport,
  5. transportServiceInterface: Components.interfaces.nsISocketTransportService,
  6. jsdIDebuggerService: Components.interfaces.jsdIDebuggerService,
  7. jsdIExecutionHook: Components.interfaces.jsdIExecutionHook,
  8. jsdICallHook: Components.interfaces.jsdICallHook,
  9. jsdIScript: Components.interfaces.jsdIScript,
  10. jsdIValue: Components.interfaces.jsdIValue,
  11. jsdIFilter: Components.interfaces.jsdIFilter,
  12. nsISupports: Components.interfaces.nsISupports,
  13. nsICategoryManager: Components.interfaces.nsICategoryManager,
  14. nsIComponentRegistrar: Components.interfaces.nsIComponentRegistrar,
  15. nsIFactory: Components.interfaces.nsIFactory,
  16. nsIModule: Components.interfaces.nsIModule,
  17. nsIScriptError: Components.interfaces.nsIScriptError,
  18. nsIWebProgress: Components.interfaces.nsIWebProgress,
  19. nsILocalFile: Components.interfaces.nsILocalFile,
  20. nsIWebBrowserPersist: Components.interfaces.nsIWebBrowserPersist,
  21. nsIWebProgressListener: Components.interfaces.nsIWebProgressListener,
  22. nsIWebPageDescriptor: Components.interfaces.nsIWebPageDescriptor,
  23. getWindowMediator: function() {
  24. return Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  25. },
  26. getWindowWatcher: function() {
  27. return Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
  28. },
  29. getWebProgress: function() {
  30. return Components.classes["@mozilla.org/appshell/component/browser-status-filter;1"].getService(Components.interfaces.nsIWebProgress);
  31. },
  32. getConsoleService: function() {
  33. return Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  34. },
  35. getSocketTransportService: function() {
  36. return Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(this.transportServiceInterface);
  37. },
  38. getUtf8Converter: function () {
  39. var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].getService(Components.interfaces.nsIScriptableUnicodeConverter);
  40. converter.charset = "UTF-8";
  41. return converter;
  42. },
  43. getThreadService: function() {
  44. return Components.classes["@mozilla.org/thread-manager;1"].getService(Components.interfaces.nsIThreadManager);
  45. },
  46. getDebuggerService: function() {
  47. return Components.classes["@mozilla.org/js/jsd/debugger-service;1"].getService(this.jsdIDebuggerService);
  48. },
  49. getPrefBranch: function() {
  50. return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  51. },
  52. getCategoryService: function() {
  53. return Components.classes["@mozilla.org/categorymanager;1"].getService(this.nsICategoryManager);
  54. },
  55. getPromptService: function() {
  56. return Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  57. },
  58. createFile: function(path) {
  59. var file = Components.classes["@mozilla.org/file/local;1"].createInstance(this.nsILocalFile);
  60. file.initWithPath(path);
  61. return file;
  62. },
  63. createBinaryInput: function(input) {
  64. var binaryInput = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
  65. binaryInput.setInputStream(input);
  66. return binaryInput;
  67. },
  68. createFileOutputStream: function() {
  69. return Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
  70. },
  71. createConverterOutputStream: function() {
  72. return Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
  73. },
  74. getWebBrowser: function() {
  75. var win = this.getWindowMediator().getMostRecentWindow("navigator:browser");
  76. if (!win || !win.getBrowser) return null;
  77. return win.getBrowser();
  78. },
  79. createWebBrowserPersist: function(progressListener) {
  80. var persist = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].createInstance(this.nsIWebBrowserPersist);
  81. persist.persistFlags = this.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES
  82. | this.nsIWebBrowserPersist.PERSIST_FLAGS_DONT_FIXUP_LINKS
  83. | this.nsIWebBrowserPersist.PERSIST_FLAGS_DONT_CHANGE_FILENAMES
  84. | this.nsIWebBrowserPersist.PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS;
  85. persist.progressListener = progressListener;
  86. return persist;
  87. },
  88. createDocShell: function() {
  89. var docShellClass = Components.classes["@mozilla.org/docshell;1"];
  90. if (!docShellClass) {
  91. docShellClass = Components.classes["@mozilla.org/webshell;1"];
  92. }
  93. var docShell = docShellClass.createInstance();
  94. try {
  95. //to fix crashes in Firefox 5, see https://bugzilla.mozilla.org/show_bug.cgi?id=552193
  96. docShell.QueryInterface(Components.interfaces.nsIBaseWindow).create();
  97. }
  98. catch (e) {
  99. LOG(e);
  100. }
  101. return docShell;
  102. },
  103. createServerSocket: function(port) {
  104. var socket = Components.classes["@mozilla.org/network/server-socket;1"]
  105. .createInstance(Components.interfaces.nsIServerSocket);
  106. socket.init(port, false, -1);
  107. return socket;
  108. }
  109. }