35 #include "loader.h" |
35 #include "loader.h" |
36 #include <wtf/Vector.h> |
36 #include <wtf/Vector.h> |
37 |
37 |
38 namespace WebCore { |
38 namespace WebCore { |
39 |
39 |
40 CachedScript::CachedScript(DocLoader* dl, const String& url, const String& charset) |
40 CachedScript::CachedScript(const String& url, const String& charset) |
41 : CachedResource(url, Script) |
41 : CachedResource(url, Script) |
42 , m_encoding(charset) |
42 , m_encoding(charset) |
|
43 , m_decodedDataDeletionTimer(this, &CachedScript::decodedDataDeletionTimerFired) |
43 { |
44 { |
44 // It's javascript we want. |
45 // It's javascript we want. |
45 // But some websites think their scripts are <some wrong mimetype here> |
46 // But some websites think their scripts are <some wrong mimetype here> |
46 // and refuse to serve them if we only accept application/x-javascript. |
47 // and refuse to serve them if we only accept application/x-javascript. |
47 setAccept("*/*"); |
48 setAccept("*/*"); |
48 // load the file |
49 |
49 cache()->loader()->load(dl, this, false); |
|
50 m_loading = true; |
|
51 if (!m_encoding.isValid()) |
50 if (!m_encoding.isValid()) |
52 m_encoding = Latin1Encoding(); |
51 m_encoding = Latin1Encoding(); |
53 } |
52 } |
54 |
53 |
55 CachedScript::~CachedScript() |
54 CachedScript::~CachedScript() |
56 { |
55 { |
|
56 destroyDecodedData(); |
|
57 m_decodedDataDeletionTimer.stop(); |
57 } |
58 } |
58 |
59 |
59 void CachedScript::ref(CachedResourceClient* c) |
60 void CachedScript::ref(CachedResourceClient* c) |
60 { |
61 { |
61 CachedResource::ref(c); |
62 CachedResource::ref(c); |
68 TextEncoding encoding(chs); |
69 TextEncoding encoding(chs); |
69 if (encoding.isValid()) |
70 if (encoding.isValid()) |
70 m_encoding = encoding; |
71 m_encoding = encoding; |
71 } |
72 } |
72 |
73 |
|
74 void CachedScript::allReferencesRemoved() |
|
75 { |
|
76 destroyDecodedData(); |
|
77 } |
|
78 |
|
79 const String& CachedScript::script() |
|
80 { |
|
81 if (!m_script && m_data) { |
|
82 m_script = m_encoding.decode(m_data->data(), encodedSize()); |
|
83 setDecodedSize(m_script.length() * sizeof(UChar)); |
|
84 } |
|
85 m_decodedDataDeletionTimer.startOneShot(0); |
|
86 return m_script; |
|
87 } |
|
88 |
73 void CachedScript::data(PassRefPtr<SharedBuffer> data, bool allDataReceived) |
89 void CachedScript::data(PassRefPtr<SharedBuffer> data, bool allDataReceived) |
74 { |
90 { |
75 if (!allDataReceived) |
|
76 return; |
|
77 |
|
78 m_data = data; |
91 m_data = data; |
79 setEncodedSize(m_data.get() ? m_data->size() : 0); |
92 setEncodedSize(m_data.get() ? m_data->size() : 0); |
80 if (m_data.get()) |
|
81 m_script = m_encoding.decode(m_data->data(), encodedSize()); |
|
82 m_loading = false; |
93 m_loading = false; |
83 checkNotify(); |
94 checkNotify(); |
84 } |
95 } |
85 |
96 |
86 void CachedScript::checkNotify() |
97 void CachedScript::checkNotify() |