| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef ScriptSourceCode_h | 31 #ifndef ScriptSourceCode_h |
| 32 #define ScriptSourceCode_h | 32 #define ScriptSourceCode_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/ScriptStreamer.h" | 34 #include "bindings/core/v8/ScriptStreamer.h" |
| 35 #include "core/fetch/ResourcePtr.h" | 35 #include "core/fetch/ResourcePtr.h" |
| 36 #include "core/fetch/ScriptResource.h" | 36 #include "core/fetch/ScriptResource.h" |
| 37 #include "platform/heap/Handle.h" |
| 37 #include "platform/weborigin/KURL.h" | 38 #include "platform/weborigin/KURL.h" |
| 38 #include "wtf/PassOwnPtr.h" | |
| 39 #include "wtf/text/TextPosition.h" | 39 #include "wtf/text/TextPosition.h" |
| 40 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 class ScriptSourceCode { | 44 template <class R> class ResourcePtr; |
| 45 class ScriptResource; |
| 46 |
| 47 class ScriptSourceCode final { |
| 48 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 45 public: | 49 public: |
| 46 ScriptSourceCode(const String& source, const KURL& url = KURL(), const TextP
osition& startPosition = TextPosition::minimumPosition()) | 50 ScriptSourceCode(); |
| 47 : m_source(source) | |
| 48 , m_resource(0) | |
| 49 , m_url(url) | |
| 50 , m_startPosition(startPosition) | |
| 51 { | |
| 52 if (!m_url.isEmpty()) | |
| 53 m_url.removeFragmentIdentifier(); | |
| 54 } | |
| 55 | |
| 56 // We lose the encoding information from ScriptResource. | 51 // We lose the encoding information from ScriptResource. |
| 57 // Not sure if that matters. | 52 // Not sure if that matters. |
| 58 ScriptSourceCode(ScriptResource* resource) | 53 explicit ScriptSourceCode(ScriptResource*); |
| 59 : m_source(resource->script()) | 54 ScriptSourceCode(const String&, const KURL& = KURL(), const TextPosition& st
artPosition = TextPosition::minimumPosition()); |
| 60 , m_resource(resource) | 55 ScriptSourceCode(PassRefPtrWillBeRawPtr<ScriptStreamer>, ScriptResource*); |
| 61 , m_startPosition(TextPosition::minimumPosition()) | |
| 62 { | |
| 63 } | |
| 64 | 56 |
| 65 ScriptSourceCode(PassRefPtr<ScriptStreamer> streamer, ScriptResource* resour
ce) | 57 ~ScriptSourceCode(); |
| 66 : m_source(resource->script()) | 58 void trace(Visitor*); |
| 67 , m_resource(resource) | |
| 68 , m_streamer(streamer) | |
| 69 , m_startPosition(TextPosition::minimumPosition()) | |
| 70 { | |
| 71 } | |
| 72 | 59 |
| 73 bool isEmpty() const { return m_source.isEmpty(); } | 60 bool isEmpty() const { return m_source.isEmpty(); } |
| 74 | 61 |
| 75 const String& source() const { return m_source; } | 62 const String& source() const { return m_source; } |
| 76 ScriptResource* resource() const { return m_resource.get(); } | 63 ScriptResource* resource() const { return m_resource.get(); } |
| 77 const KURL& url() const | 64 const KURL& url() const; |
| 78 { | |
| 79 if (m_url.isEmpty() && m_resource) { | |
| 80 m_url = m_resource->response().url(); | |
| 81 if (!m_url.isEmpty()) | |
| 82 m_url.removeFragmentIdentifier(); | |
| 83 } | |
| 84 return m_url; | |
| 85 } | |
| 86 int startLine() const { return m_startPosition.m_line.oneBasedInt(); } | 65 int startLine() const { return m_startPosition.m_line.oneBasedInt(); } |
| 87 const TextPosition& startPosition() const { return m_startPosition; } | 66 const TextPosition& startPosition() const { return m_startPosition; } |
| 88 | 67 |
| 89 ScriptStreamer* streamer() const { return m_streamer.get(); } | 68 ScriptStreamer* streamer() const { return m_streamer.get(); } |
| 90 | 69 |
| 91 private: | 70 private: |
| 92 String m_source; | 71 String m_source; |
| 93 ResourcePtr<ScriptResource> m_resource; | 72 ResourcePtr<ScriptResource> m_resource; |
| 94 RefPtr<ScriptStreamer> m_streamer; | 73 RefPtrWillBeMember<ScriptStreamer> m_streamer; |
| 95 mutable KURL m_url; | 74 mutable KURL m_url; |
| 96 TextPosition m_startPosition; | 75 TextPosition m_startPosition; |
| 97 }; | 76 }; |
| 98 | 77 |
| 99 } // namespace blink | 78 } // namespace blink |
| 100 | 79 |
| 80 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::ScriptSourceCode); |
| 81 |
| 101 #endif // ScriptSourceCode_h | 82 #endif // ScriptSourceCode_h |
| OLD | NEW |