3af0431128cc1dd3d013cea05c296ef0f0e8618f
[platform/framework/web/crosswalk-tizen.git] /
1 /*
2  * Copyright (C) 2008, 2009 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 #ifndef ScriptSourceCode_h
32 #define ScriptSourceCode_h
33
34 #include "bindings/core/v8/ScriptStreamer.h"
35 #include "core/CoreExport.h"
36 #include "core/loader/resource/ScriptResource.h"
37 #include "platform/heap/Handle.h"
38 #include "platform/weborigin/KURL.h"
39 #include "wtf/text/TextPosition.h"
40 #include "wtf/text/WTFString.h"
41
42 namespace blink {
43
44 class CORE_EXPORT ScriptSourceCode final {
45   DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
46
47  public:
48   ScriptSourceCode();
49   // We lose the encoding information from ScriptResource.
50   // Not sure if that matters.
51   explicit ScriptSourceCode(ScriptResource*);
52   ScriptSourceCode(
53       const String&,
54       const KURL& = KURL(),
55       const TextPosition& startPosition = TextPosition::minimumPosition());
56   ScriptSourceCode(ScriptStreamer*, ScriptResource*);
57
58   ~ScriptSourceCode();
59   DECLARE_TRACE();
60
61   bool isEmpty() const { return m_source.isEmpty(); }
62
63   // The null value represents a missing script, created by the nullary
64   // constructor, and differs from the empty script.
65   bool isNull() const { return m_source.isNull(); }
66
67   const String& source() const { return m_source; }
68   ScriptResource* resource() const { return m_resource.get(); }
69   const KURL& url() const;
70   int startLine() const { return m_startPosition.m_line.oneBasedInt(); }
71   const TextPosition& startPosition() const { return m_startPosition; }
72   String sourceMapUrl() const;
73
74   ScriptStreamer* streamer() const { return m_streamer.get(); }
75
76  private:
77   void treatNullSourceAsEmpty();
78
79   String m_source;
80   Member<ScriptResource> m_resource;
81   Member<ScriptStreamer> m_streamer;
82   mutable KURL m_url;
83   TextPosition m_startPosition;
84 };
85
86 }  // namespace blink
87
88 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::ScriptSourceCode);
89
90 #endif  // ScriptSourceCode_h