| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 * @param {!WebInspector.NetworkRequest} request | 34 * @param {!WebInspector.NetworkRequest} request |
| 35 * @param {!WebInspector.ParsedJSON} parsedJSON | 35 * @param {!WebInspector.ParsedJSON} parsedJSON |
| 36 */ | 36 */ |
| 37 WebInspector.RequestJSONView = function(request, parsedJSON) | 37 WebInspector.RequestJSONView = function(request, parsedJSON) |
| 38 { | 38 { |
| 39 WebInspector.RequestView.call(this, request); | 39 WebInspector.RequestView.call(this, request); |
| 40 this._parsedJSON = parsedJSON; | 40 this._parsedJSON = parsedJSON; |
| 41 this.element.classList.add("json"); | 41 this.element.classList.add("json"); |
| 42 } | 42 } |
| 43 | 43 |
| 44 /** |
| 45 * @param {string} text |
| 46 * @return {?WebInspector.ParsedJSON} |
| 47 */ |
| 44 WebInspector.RequestJSONView.parseJSON = function(text) | 48 WebInspector.RequestJSONView.parseJSON = function(text) |
| 45 { | 49 { |
| 46 var prefix = ""; | 50 var prefix = ""; |
| 47 | 51 |
| 48 // Trim while(1), for(;;), weird numbers, etc. We need JSON start. | 52 // Trim while(1), for(;;), weird numbers, etc. We need JSON start. |
| 49 var start = /[{[]/.exec(text); | 53 var start = /[{[]/.exec(text); |
| 50 if (start && start.index) { | 54 if (start && start.index) { |
| 51 prefix = text.substring(0, start.index); | 55 prefix = text.substring(0, start.index); |
| 52 text = text.substring(start.index); | 56 text = text.substring(start.index); |
| 53 } | 57 } |
| 54 | 58 |
| 55 try { | 59 try { |
| 56 return new WebInspector.ParsedJSON(JSON.parse(text), prefix, ""); | 60 return new WebInspector.ParsedJSON(JSON.parse(text), prefix, ""); |
| 57 } catch (e) { | 61 } catch (e) { |
| 58 return; | 62 return null; |
| 59 } | 63 } |
| 60 } | 64 } |
| 61 | 65 |
| 66 /** |
| 67 * @param {string} text |
| 68 * @return {?WebInspector.ParsedJSON} |
| 69 */ |
| 62 WebInspector.RequestJSONView.parseJSONP = function(text) | 70 WebInspector.RequestJSONView.parseJSONP = function(text) |
| 63 { | 71 { |
| 64 // Taking everything between first and last parentheses | 72 // Taking everything between first and last parentheses |
| 65 var start = text.indexOf("("); | 73 var start = text.indexOf("("); |
| 66 var end = text.lastIndexOf(")"); | 74 var end = text.lastIndexOf(")"); |
| 67 if (start == -1 || end == -1 || end < start) | 75 if (start == -1 || end == -1 || end < start) |
| 68 return; | 76 return null; |
| 69 | 77 |
| 70 var prefix = text.substring(0, start + 1); | 78 var prefix = text.substring(0, start + 1); |
| 71 var suffix = text.substring(end); | 79 var suffix = text.substring(end); |
| 72 text = text.substring(start + 1, end); | 80 text = text.substring(start + 1, end); |
| 73 | 81 |
| 74 try { | 82 try { |
| 75 return new WebInspector.ParsedJSON(JSON.parse(text), prefix, suffix); | 83 return new WebInspector.ParsedJSON(JSON.parse(text), prefix, suffix); |
| 76 } catch (e) { | 84 } catch (e) { |
| 77 return; | 85 return null; |
| 78 } | 86 } |
| 79 } | 87 } |
| 80 | 88 |
| 81 WebInspector.RequestJSONView.prototype = { | 89 WebInspector.RequestJSONView.prototype = { |
| 82 /** | 90 /** |
| 83 * @return {boolean} | 91 * @return {boolean} |
| 84 */ | 92 */ |
| 85 hasContent: function() | 93 hasContent: function() |
| 86 { | 94 { |
| 87 return true; | 95 return true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 111 | 119 |
| 112 /** | 120 /** |
| 113 * @constructor | 121 * @constructor |
| 114 */ | 122 */ |
| 115 WebInspector.ParsedJSON = function(data, prefix, suffix) | 123 WebInspector.ParsedJSON = function(data, prefix, suffix) |
| 116 { | 124 { |
| 117 this.data = data; | 125 this.data = data; |
| 118 this.prefix = prefix; | 126 this.prefix = prefix; |
| 119 this.suffix = suffix; | 127 this.suffix = suffix; |
| 120 } | 128 } |
| OLD | NEW |