Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Side by Side Diff: Source/core/loader/TextTrackLoader.cpp

Issue 52533003: Refactor TextTrackLoader to properly use the dataReceived callback (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cachedCueData
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/loader/TextTrackLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 #include "platform/SharedBuffer.h" 38 #include "platform/SharedBuffer.h"
39 #include "weborigin/SecurityOrigin.h" 39 #include "weborigin/SecurityOrigin.h"
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 TextTrackLoader::TextTrackLoader(TextTrackLoaderClient* client, Document& docume nt) 43 TextTrackLoader::TextTrackLoader(TextTrackLoaderClient* client, Document& docume nt)
44 : m_client(client) 44 : m_client(client)
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)
49 , m_newCuesAvailable(false) 48 , m_newCuesAvailable(false)
50 { 49 {
51 } 50 }
52 51
53 TextTrackLoader::~TextTrackLoader() 52 TextTrackLoader::~TextTrackLoader()
54 { 53 {
55 if (m_resource) 54 if (m_resource)
56 m_resource->removeClient(this); 55 m_resource->removeClient(this);
57 } 56 }
58 57
(...skipping 11 matching lines...) Expand all
70 } 69 }
71 70
72 void TextTrackLoader::cancelLoad() 71 void TextTrackLoader::cancelLoad()
73 { 72 {
74 if (m_resource) { 73 if (m_resource) {
75 m_resource->removeClient(this); 74 m_resource->removeClient(this);
76 m_resource = 0; 75 m_resource = 0;
77 } 76 }
78 } 77 }
79 78
80 void TextTrackLoader::processNewCueData(Resource* resource) 79 void TextTrackLoader::dataReceived(Resource* resource, const char* data, int len gth)
81 { 80 {
82 ASSERT(m_resource == resource); 81 ASSERT(m_resource == resource);
83 82
84 if (m_state == Failed || !resource->resourceBuffer()) 83 if (m_state == Failed)
85 return;
86
87 SharedBuffer* buffer = resource->resourceBuffer();
88 if (m_parseOffset == buffer->size())
89 return; 84 return;
90 85
91 if (!m_cueParser) 86 if (!m_cueParser)
92 m_cueParser = WebVTTParser::create(this, m_document); 87 m_cueParser = WebVTTParser::create(this, m_document);
93 88
94 const char* data; 89 m_cueParser->parseBytes(data, length);
95 unsigned length;
96
97 while ((length = buffer->getSomeData(data, m_parseOffset))) {
98 m_cueParser->parseBytes(data, length);
99 m_parseOffset += length;
100 }
101 }
102
103 void TextTrackLoader::dataReceived(Resource* resource, const char*, int)
104 {
105 ASSERT(m_resource == resource);
106
107 if (!resource->resourceBuffer())
108 return;
109
110 processNewCueData(resource);
111 } 90 }
112 91
113 void TextTrackLoader::corsPolicyPreventedLoad() 92 void TextTrackLoader::corsPolicyPreventedLoad()
114 { 93 {
115 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Cross-origin text track load d enied by Cross-Origin Resource Sharing policy.")); 94 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); 95 m_document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, conso leMessage);
117 m_state = Failed; 96 m_state = Failed;
118 } 97 }
119 98
120 void TextTrackLoader::notifyFinished(Resource* resource) 99 void TextTrackLoader::notifyFinished(Resource* resource)
121 { 100 {
122 ASSERT(m_resource == resource); 101 ASSERT(m_resource == resource);
123 102
124 if (!m_crossOriginMode.isNull() 103 if (!m_crossOriginMode.isNull()
125 && !m_document.securityOrigin()->canRequest(resource->response().url()) 104 && !m_document.securityOrigin()->canRequest(resource->response().url())
126 && !resource->passesAccessControlCheck(m_document.securityOrigin())) { 105 && !resource->passesAccessControlCheck(m_document.securityOrigin())) {
127 106
128 corsPolicyPreventedLoad(); 107 corsPolicyPreventedLoad();
129 } 108 }
130 109
131 if (m_state != Failed) { 110 if (m_state != Failed)
132 processNewCueData(resource); 111 m_state = resource->errorOccurred() ? Failed : Finished;
133 if (m_state != Failed)
134 m_state = resource->errorOccurred() ? Failed : Finished;
135 }
136 112
137 if (!m_cueLoadTimer.isActive()) 113 if (!m_cueLoadTimer.isActive())
138 m_cueLoadTimer.startOneShot(0); 114 m_cueLoadTimer.startOneShot(0);
139 115
140 cancelLoad(); 116 cancelLoad();
141 } 117 }
142 118
143 bool TextTrackLoader::load(const KURL& url, const String& crossOriginMode) 119 bool TextTrackLoader::load(const KURL& url, const String& crossOriginMode)
144 { 120 {
145 cancelLoad(); 121 cancelLoad();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 181 }
206 182
207 void TextTrackLoader::getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegi ons) 183 void TextTrackLoader::getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegi ons)
208 { 184 {
209 ASSERT(m_cueParser); 185 ASSERT(m_cueParser);
210 if (m_cueParser) 186 if (m_cueParser)
211 m_cueParser->getNewRegions(outputRegions); 187 m_cueParser->getNewRegions(outputRegions);
212 } 188 }
213 } 189 }
214 190
OLDNEW
« no previous file with comments | « Source/core/loader/TextTrackLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698