initial import
[vuplus_webkit] / Source / WebCore / inspector / front-end / UISourceCode.js
1 /*
2  * Copyright (C) 2011 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  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /**
32  * @constructor
33  */
34 WebInspector.UISourceCode = function(id, url, isContentScript, rawSourceCode, contentProvider)
35 {
36     this._id = id;
37     this._url = url;
38     this._isContentScript = isContentScript;
39     this._rawSourceCode = rawSourceCode;
40     this._contentProvider = contentProvider;
41     this._requestContentCallbacks = [];
42 }
43
44 WebInspector.UISourceCode.prototype = {
45     get id()
46     {
47         return this._id;
48     },
49
50     get url()
51     {
52         return this._url;
53     },
54
55     get isContentScript()
56     {
57         return this._isContentScript;
58     },
59
60     get rawSourceCode()
61     {
62         return this._rawSourceCode;
63     },
64
65     requestContent: function(callback)
66     {
67         if (this._contentLoaded) {
68             callback(this._mimeType, this._content);
69             return;
70         }
71
72         this._requestContentCallbacks.push(callback);
73         if (this._requestContentCallbacks.length === 1)
74             this._contentProvider.requestContent(this._didRequestContent.bind(this));
75     },
76
77     _didRequestContent: function(mimeType, content)
78     {
79         this._contentLoaded = true;
80         this._mimeType = mimeType;
81         this._content = content;
82
83         for (var i = 0; i < this._requestContentCallbacks.length; ++i)
84             this._requestContentCallbacks[i](mimeType, content);
85     }
86 }
87
88 /**
89  * @interface
90  */
91 WebInspector.ContentProvider = function() { }
92 WebInspector.ContentProvider.prototype = {
93     requestContent: function(callback) { }
94 }