// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

WebInspector.BlackboxSupport = function()
{
}

/**
 * @param {string} url
 */
WebInspector.BlackboxSupport.blackboxURL = function(url)
{
    var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray();
    var name = new WebInspector.ParsedURL(url).lastPathComponent;
    var regexValue = "/" + name.escapeForRegExp() + (url.endsWith(name) ? "$" : "\\b");
    var found = false;
    for (var i = 0; i < regexPatterns.length; ++i) {
        var item = regexPatterns[i];
        if (item.pattern === regexValue) {
            item.disabled = false;
            found = true;
            break;
        }
    }
    if (!found)
        regexPatterns.push({ pattern: regexValue });
    WebInspector.settings.skipStackFramesPattern.setAsArray(regexPatterns);
}

/**
 * @param {string} url
 */
WebInspector.BlackboxSupport.unblackboxURL = function(url)
{
    var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray();
    for (var i = 0; i < regexPatterns.length; ++i) {
        var item = regexPatterns[i];
        if (item.disabled)
            continue;
        try {
            var regex = new RegExp(item.pattern);
            if (regex.test(url))
                item.disabled = true;
        } catch (e) {
        }
    }
    WebInspector.settings.skipStackFramesPattern.setAsArray(regexPatterns);
}

/**
 * @param {string} url
 * @return {boolean}
 */
WebInspector.BlackboxSupport.isBlackboxedURL = function(url)
{
    var regex = WebInspector.settings.skipStackFramesPattern.asRegExp();
    return (url && regex) ? regex.test(url) : false;
}

@@ -225,32 +225,52 @@
 am %7Bstring%7D url%0A
+ * @return %7Bstring%7D%0A
  */%0AWebInspector
@@ -286,27 +286,34 @@
 Support.
-blackboxURL
+_urlToRegExpString
  = funct
@@ -327,91 +327,8 @@
 )%0A%7B%0A
-    var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray();%0A
     
@@ -397,24 +397,14 @@
     
-var regexValue =
+return
  %22/%22
@@ -467,16 +467,267 @@
 %22%5C%5Cb%22);%0A
+%7D%0A%0A/**%0A * @param %7Bstring%7D url%0A */%0AWebInspector.BlackboxSupport.blackboxURL = function(url)%0A%7B%0A    var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray();%0A    var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url);%0A
     var 
@@ -1289,24 +1289,209 @@
 tAsArray();%0A
+    var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url);%0A    regexPatterns = regexPatterns.filter(function(item) %7B%0A        return item.pattern !== regexValue;%0A    %7D);%0A
     for (var

Remove autogenerated blackbox patterns upon Unblackbox user action.