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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 , m_document(document) | 45 , m_document(document) |
46 , m_cueLoadTimer(this, &TextTrackLoader::cueLoadTimerFired) | 46 , m_cueLoadTimer(this, &TextTrackLoader::cueLoadTimerFired) |
47 , m_state(Idle) | 47 , m_state(Idle) |
48 , m_parseOffset(0) | 48 , m_parseOffset(0) |
49 , m_newCuesAvailable(false) | 49 , m_newCuesAvailable(false) |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 TextTrackLoader::~TextTrackLoader() | 53 TextTrackLoader::~TextTrackLoader() |
54 { | 54 { |
55 if (m_cachedCueData) | 55 if (m_resource) |
56 m_cachedCueData->removeClient(this); | 56 m_resource->removeClient(this); |
57 } | 57 } |
58 | 58 |
59 void TextTrackLoader::cueLoadTimerFired(Timer<TextTrackLoader>* timer) | 59 void TextTrackLoader::cueLoadTimerFired(Timer<TextTrackLoader>* timer) |
60 { | 60 { |
61 ASSERT_UNUSED(timer, timer == &m_cueLoadTimer); | 61 ASSERT_UNUSED(timer, timer == &m_cueLoadTimer); |
62 | 62 |
63 if (m_newCuesAvailable) { | 63 if (m_newCuesAvailable) { |
64 m_newCuesAvailable = false; | 64 m_newCuesAvailable = false; |
65 m_client->newCuesAvailable(this); | 65 m_client->newCuesAvailable(this); |
66 } | 66 } |
67 | 67 |
68 if (m_state >= Finished) | 68 if (m_state >= Finished) |
69 m_client->cueLoadingCompleted(this, m_state == Failed); | 69 m_client->cueLoadingCompleted(this, m_state == Failed); |
70 } | 70 } |
71 | 71 |
72 void TextTrackLoader::cancelLoad() | 72 void TextTrackLoader::cancelLoad() |
73 { | 73 { |
74 if (m_cachedCueData) { | 74 if (m_resource) { |
75 m_cachedCueData->removeClient(this); | 75 m_resource->removeClient(this); |
76 m_cachedCueData = 0; | 76 m_resource = 0; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 void TextTrackLoader::processNewCueData(Resource* resource) | 80 void TextTrackLoader::processNewCueData(Resource* resource) |
81 { | 81 { |
82 ASSERT(m_cachedCueData == resource); | 82 ASSERT(m_resource == resource); |
83 | 83 |
84 if (m_state == Failed || !resource->resourceBuffer()) | 84 if (m_state == Failed || !resource->resourceBuffer()) |
85 return; | 85 return; |
86 | 86 |
87 SharedBuffer* buffer = resource->resourceBuffer(); | 87 SharedBuffer* buffer = resource->resourceBuffer(); |
88 if (m_parseOffset == buffer->size()) | 88 if (m_parseOffset == buffer->size()) |
89 return; | 89 return; |
90 | 90 |
91 if (!m_cueParser) | 91 if (!m_cueParser) |
92 m_cueParser = WebVTTParser::create(this, m_document); | 92 m_cueParser = WebVTTParser::create(this, m_document); |
93 | 93 |
94 const char* data; | 94 const char* data; |
95 unsigned length; | 95 unsigned length; |
96 | 96 |
97 while ((length = buffer->getSomeData(data, m_parseOffset))) { | 97 while ((length = buffer->getSomeData(data, m_parseOffset))) { |
98 m_cueParser->parseBytes(data, length); | 98 m_cueParser->parseBytes(data, length); |
99 m_parseOffset += length; | 99 m_parseOffset += length; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void TextTrackLoader::dataReceived(Resource* resource, const char*, int) | 103 void TextTrackLoader::dataReceived(Resource* resource, const char*, int) |
104 { | 104 { |
105 ASSERT(m_cachedCueData == resource); | 105 ASSERT(m_resource == resource); |
106 | 106 |
107 if (!resource->resourceBuffer()) | 107 if (!resource->resourceBuffer()) |
108 return; | 108 return; |
109 | 109 |
110 processNewCueData(resource); | 110 processNewCueData(resource); |
111 } | 111 } |
112 | 112 |
113 void TextTrackLoader::corsPolicyPreventedLoad() | 113 void TextTrackLoader::corsPolicyPreventedLoad() |
114 { | 114 { |
115 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Cross-origin text track load d
enied by Cross-Origin Resource Sharing policy.")); | 115 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Cross-origin text track load d
enied by Cross-Origin Resource Sharing policy.")); |
116 m_document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, conso
leMessage); | 116 m_document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, conso
leMessage); |
117 m_state = Failed; | 117 m_state = Failed; |
118 } | 118 } |
119 | 119 |
120 void TextTrackLoader::notifyFinished(Resource* resource) | 120 void TextTrackLoader::notifyFinished(Resource* resource) |
121 { | 121 { |
122 ASSERT(m_cachedCueData == resource); | 122 ASSERT(m_resource == resource); |
123 | 123 |
124 if (!m_crossOriginMode.isNull() | 124 if (!m_crossOriginMode.isNull() |
125 && !m_document.securityOrigin()->canRequest(resource->response().url()) | 125 && !m_document.securityOrigin()->canRequest(resource->response().url()) |
126 && !resource->passesAccessControlCheck(m_document.securityOrigin())) { | 126 && !resource->passesAccessControlCheck(m_document.securityOrigin())) { |
127 | 127 |
128 corsPolicyPreventedLoad(); | 128 corsPolicyPreventedLoad(); |
129 } | 129 } |
130 | 130 |
131 if (m_state != Failed) { | 131 if (m_state != Failed) { |
132 processNewCueData(resource); | 132 processNewCueData(resource); |
(...skipping 22 matching lines...) Expand all Loading... |
155 updateRequestForAccessControl(cueRequest.mutableResourceRequest(), m_doc
ument.securityOrigin(), allowCredentials); | 155 updateRequestForAccessControl(cueRequest.mutableResourceRequest(), m_doc
ument.securityOrigin(), allowCredentials); |
156 } else { | 156 } else { |
157 // Cross-origin resources that are not suitably CORS-enabled may not loa
d. | 157 // Cross-origin resources that are not suitably CORS-enabled may not loa
d. |
158 if (!m_document.securityOrigin()->canRequest(url)) { | 158 if (!m_document.securityOrigin()->canRequest(url)) { |
159 corsPolicyPreventedLoad(); | 159 corsPolicyPreventedLoad(); |
160 return false; | 160 return false; |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 ResourceFetcher* fetcher = m_document.fetcher(); | 164 ResourceFetcher* fetcher = m_document.fetcher(); |
165 m_cachedCueData = fetcher->fetchTextTrack(cueRequest); | 165 m_resource = fetcher->fetchTextTrack(cueRequest); |
166 if (m_cachedCueData) | 166 if (m_resource) |
167 m_cachedCueData->addClient(this); | 167 m_resource->addClient(this); |
168 | 168 |
169 m_client->cueLoadingStarted(this); | 169 m_client->cueLoadingStarted(this); |
170 | 170 |
171 return true; | 171 return true; |
172 } | 172 } |
173 | 173 |
174 void TextTrackLoader::newCuesParsed() | 174 void TextTrackLoader::newCuesParsed() |
175 { | 175 { |
176 if (m_cueLoadTimer.isActive()) | 176 if (m_cueLoadTimer.isActive()) |
177 return; | 177 return; |
(...skipping 27 matching lines...) Expand all Loading... |
205 } | 205 } |
206 | 206 |
207 void TextTrackLoader::getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegi
ons) | 207 void TextTrackLoader::getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegi
ons) |
208 { | 208 { |
209 ASSERT(m_cueParser); | 209 ASSERT(m_cueParser); |
210 if (m_cueParser) | 210 if (m_cueParser) |
211 m_cueParser->getNewRegions(outputRegions); | 211 m_cueParser->getNewRegions(outputRegions); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
OLD | NEW |