/*jshint browser:true, nonew:false*/
/*global WebInspector:true*/
WebInspector.SourcesOverrides = function() {
  this._chromeSpecificsAreHidden = false;
  this._hideChromeSpecifics();
  this._overrideWatchExpression();
  this._hideContentsScript();
  this._disableAddFolderItem();
};

WebInspector.SourcesOverrides.prototype = {
  _hideChromeSpecifics: function() {
    if (WebInspector.panels.sources) {
      this._hideSourcesTabSpecifics();
    } else {
      WebInspector.inspectorView._tabbedPane.addEventListener(
        WebInspector.TabbedPane.EventTypes.TabSelected,
        function(event) {
          if (event.data.tabId == 'sources') setTimeout(this._hideSourcesTabSpecifics.bind(this));
        }, this);
    }
  },

  _hideSourcesTabSpecifics: function() {
    if (this._chromeSpecificsAreHidden) return;

    var panes = WebInspector.panels.sources.sidebarPanes;
    [
      panes.domBreakpoints.element,
      panes.domBreakpoints.titleElement.parentNode,
      panes.eventListenerBreakpoints.element,
      panes.eventListenerBreakpoints.titleElement.parentNode,
      panes.xhrBreakpoints.element,
      panes.xhrBreakpoints.titleElement.parentNode
    ].forEach(function(element) {
      element.classList.add('hidden');
    });
    this._chromeSpecificsAreHidden = true;
  },

  _overrideWatchExpression: function() {
    // Patch the expression used as an initial value for a new watch.
    // DevTools' value "\n" breaks the debugger protocol.
    WebInspector.WatchExpressionsSection.NewWatchExpression = ' ';
  },
  
  _hideContentsScript: function(){
    if (WebInspector.SourcesPanel._instanceObject) {
      WebInspector.SourcesPanel._instanceObject.registerRequiredCSS('node/sources/SourcesPanelOverrides.css');
    } else {
      sourcespanel_proto = WebInspector.SourcesPanel.prototype;
      sourcespanel_proto.oldWasShown = sourcespanel_proto.wasShown;
      sourcespanel_proto.wasShown = function(){
        this.registerRequiredCSS('node/sources/SourcesPanelOverrides.css');
        sourcespanel_proto.wasShown = sourcespanel_proto.oldWasShown;
        sourcespanel_proto.oldWasShown.call(this);
      };
    }
  },
  
  _disableAddFolderItem: function(){
    WebInspector.NavigatorView.prototype._appendAddFolderItem = function(){};
  }
};

new WebInspector.SourcesOverrides();

@@ -208,24 +208,37 @@
 pression();%0A
+%3C%3C%3C%3C%3C%3C%3C HEAD%0A
   this._hide
@@ -287,16 +287,130 @@
 Item();%0A
+=======%0A  this._overrideShortcutsRegistering();%0A%3E%3E%3E%3E%3E%3E%3E 4df7074... front-end: Fix double sending of %60togglePause%60%0A
 %7D;%0A%0AWebI
@@ -1655,24 +1655,37 @@
 = ' ';%0A  %7D,%0A
+%3C%3C%3C%3C%3C%3C%3C HEAD%0A
   %0A  _hideCo
@@ -2320,24 +2320,24 @@
 function()%7B%0A
-
     WebInspe
@@ -2402,16 +2402,791 @@
 on()%7B%7D;%0A
+=======%0A%0A  _overrideShortcutsRegistering: function() %7B%0A    // TODO(3y3): Check this before next front-end update.%0A    // If it wasn't fixed we need to deprecate it anyway and search other way to fix.%0A    setTimeout(function() %7B%0A      WebInspector.SourcesPanel.prototype._createButtonAndRegisterShortcutsForAction =%0A        function(buttonId, buttonTitle, actionId) %7B%0A          function handler() %7B%0A            WebInspector.actionRegistry.execute(actionId);%0A            return true;%0A          %7D%0A          var shortcuts = WebInspector.shortcutRegistry.shortcutDescriptorsForAction(actionId);%0A          return this._createButtonAndRegisterShortcuts(buttonId, buttonTitle, handler, shortcuts);%0A        %7D;%0A    %7D);%0A%3E%3E%3E%3E%3E%3E%3E 4df7074... front-end: Fix double sending of %60togglePause%60%0A
   %7D%0A%7D;%0A%0A

Fix double sending of `togglePause`