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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 1710013002: Cleanup HTMLMediaElement to use anonymous namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months 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 | « no previous file | 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) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 #include "public/platform/Platform.h" 80 #include "public/platform/Platform.h"
81 #include "public/platform/WebAudioSourceProvider.h" 81 #include "public/platform/WebAudioSourceProvider.h"
82 #include "public/platform/WebContentDecryptionModule.h" 82 #include "public/platform/WebContentDecryptionModule.h"
83 #include "public/platform/WebInbandTextTrack.h" 83 #include "public/platform/WebInbandTextTrack.h"
84 #include "wtf/CurrentTime.h" 84 #include "wtf/CurrentTime.h"
85 #include "wtf/MainThread.h" 85 #include "wtf/MainThread.h"
86 #include "wtf/MathExtras.h" 86 #include "wtf/MathExtras.h"
87 #include "wtf/text/CString.h" 87 #include "wtf/text/CString.h"
88 #include <limits> 88 #include <limits>
89 89
90 #ifndef LOG_MEDIA_EVENTS
91 // Default to not logging events because so many are generated they can overwhel m the rest of
92 // the logging.
93 #define LOG_MEDIA_EVENTS 0
94 #endif
95
96 #ifndef LOG_CACHED_TIME_WARNINGS
97 // Default to not logging warnings about excessive drift in the cached media tim e because it adds a
98 // fair amount of overhead and logging.
99 #define LOG_CACHED_TIME_WARNINGS 0
100 #endif
90 101
91 namespace blink { 102 namespace blink {
92 103
104 using namespace HTMLNames;
105
106 using WeakMediaElementSet = WillBeHeapHashSet<RawPtrWillBeWeakMember<HTMLMediaEl ement>>;
107 using DocumentElementSetMap = WillBeHeapHashMap<RawPtrWillBeWeakMember<Document> , WeakMediaElementSet>;
108
109 namespace {
110
111 // URL protocol used to signal that the media source API is being used.
112 const char mediaSourceBlobProtocol[] = "blob";
113
93 #if !LOG_DISABLED 114 #if !LOG_DISABLED
94 static String urlForLoggingMedia(const KURL& url) 115 String urlForLoggingMedia(const KURL& url)
95 { 116 {
96 static const unsigned maximumURLLengthForLogging = 128; 117 static const unsigned maximumURLLengthForLogging = 128;
97 118
98 if (url.string().length() < maximumURLLengthForLogging) 119 if (url.string().length() < maximumURLLengthForLogging)
99 return url.string(); 120 return url.string();
100 return url.string().substring(0, maximumURLLengthForLogging) + "..."; 121 return url.string().substring(0, maximumURLLengthForLogging) + "...";
101 } 122 }
102 123
103 static const char* boolString(bool val) 124 const char* boolString(bool val)
104 { 125 {
105 return val ? "true" : "false"; 126 return val ? "true" : "false";
106 } 127 }
107 #endif 128 #endif
108 129
109 #ifndef LOG_MEDIA_EVENTS 130 DocumentElementSetMap& documentToElementSetMap()
110 // Default to not logging events because so many are generated they can overwhel m the rest of
111 // the logging.
112 #define LOG_MEDIA_EVENTS 0
113 #endif
114
115 #ifndef LOG_CACHED_TIME_WARNINGS
116 // Default to not logging warnings about excessive drift in the cached media tim e because it adds a
117 // fair amount of overhead and logging.
118 #define LOG_CACHED_TIME_WARNINGS 0
119 #endif
120
121 // URL protocol used to signal that the media source API is being used.
122 static const char mediaSourceBlobProtocol[] = "blob";
123
124 using namespace HTMLNames;
125
126 typedef WillBeHeapHashSet<RawPtrWillBeWeakMember<HTMLMediaElement>> WeakMediaEle mentSet;
127 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<Document>, WeakMediaElementSet> DocumentElementSetMap;
128 static DocumentElementSetMap& documentToElementSetMap()
129 { 131 {
130 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<DocumentElementSetMap>, map, (ado ptPtrWillBeNoop(new DocumentElementSetMap()))); 132 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<DocumentElementSetMap>, map, (ado ptPtrWillBeNoop(new DocumentElementSetMap())));
131 return *map; 133 return *map;
132 } 134 }
133 135
134 static void addElementToDocumentMap(HTMLMediaElement* element, Document* documen t) 136 void addElementToDocumentMap(HTMLMediaElement* element, Document* document)
135 { 137 {
136 DocumentElementSetMap& map = documentToElementSetMap(); 138 DocumentElementSetMap& map = documentToElementSetMap();
137 WeakMediaElementSet set = map.take(document); 139 WeakMediaElementSet set = map.take(document);
138 set.add(element); 140 set.add(element);
139 map.add(document, set); 141 map.add(document, set);
140 } 142 }
141 143
142 static void removeElementFromDocumentMap(HTMLMediaElement* element, Document* do cument) 144 void removeElementFromDocumentMap(HTMLMediaElement* element, Document* document)
143 { 145 {
144 DocumentElementSetMap& map = documentToElementSetMap(); 146 DocumentElementSetMap& map = documentToElementSetMap();
145 WeakMediaElementSet set = map.take(document); 147 WeakMediaElementSet set = map.take(document);
146 set.remove(element); 148 set.remove(element);
147 if (!set.isEmpty()) 149 if (!set.isEmpty())
148 map.add(document, set); 150 map.add(document, set);
149 } 151 }
150 152
151 class AudioSourceProviderClientLockScope { 153 class AudioSourceProviderClientLockScope {
152 STACK_ALLOCATED(); 154 STACK_ALLOCATED();
153 public: 155 public:
154 AudioSourceProviderClientLockScope(HTMLMediaElement& element) 156 AudioSourceProviderClientLockScope(HTMLMediaElement& element)
155 : m_client(element.audioSourceNode()) 157 : m_client(element.audioSourceNode())
156 { 158 {
157 if (m_client) 159 if (m_client)
158 m_client->lock(); 160 m_client->lock();
159 } 161 }
160 ~AudioSourceProviderClientLockScope() 162 ~AudioSourceProviderClientLockScope()
161 { 163 {
162 if (m_client) 164 if (m_client)
163 m_client->unlock(); 165 m_client->unlock();
164 } 166 }
165 167
166 private: 168 private:
167 Member<AudioSourceProviderClient> m_client; 169 Member<AudioSourceProviderClient> m_client;
168 }; 170 };
169 171
170 static const AtomicString& AudioKindToString(WebMediaPlayerClient::AudioTrackKin d kind) 172 const AtomicString& AudioKindToString(WebMediaPlayerClient::AudioTrackKind kind)
171 { 173 {
172 switch (kind) { 174 switch (kind) {
173 case WebMediaPlayerClient::AudioTrackKindNone: 175 case WebMediaPlayerClient::AudioTrackKindNone:
174 return emptyAtom; 176 return emptyAtom;
175 case WebMediaPlayerClient::AudioTrackKindAlternative: 177 case WebMediaPlayerClient::AudioTrackKindAlternative:
176 return AudioTrack::alternativeKeyword(); 178 return AudioTrack::alternativeKeyword();
177 case WebMediaPlayerClient::AudioTrackKindDescriptions: 179 case WebMediaPlayerClient::AudioTrackKindDescriptions:
178 return AudioTrack::descriptionsKeyword(); 180 return AudioTrack::descriptionsKeyword();
179 case WebMediaPlayerClient::AudioTrackKindMain: 181 case WebMediaPlayerClient::AudioTrackKindMain:
180 return AudioTrack::mainKeyword(); 182 return AudioTrack::mainKeyword();
181 case WebMediaPlayerClient::AudioTrackKindMainDescriptions: 183 case WebMediaPlayerClient::AudioTrackKindMainDescriptions:
182 return AudioTrack::mainDescriptionsKeyword(); 184 return AudioTrack::mainDescriptionsKeyword();
183 case WebMediaPlayerClient::AudioTrackKindTranslation: 185 case WebMediaPlayerClient::AudioTrackKindTranslation:
184 return AudioTrack::translationKeyword(); 186 return AudioTrack::translationKeyword();
185 case WebMediaPlayerClient::AudioTrackKindCommentary: 187 case WebMediaPlayerClient::AudioTrackKindCommentary:
186 return AudioTrack::commentaryKeyword(); 188 return AudioTrack::commentaryKeyword();
187 } 189 }
188 190
189 ASSERT_NOT_REACHED(); 191 ASSERT_NOT_REACHED();
190 return emptyAtom; 192 return emptyAtom;
191 } 193 }
192 194
193 static const AtomicString& VideoKindToString(WebMediaPlayerClient::VideoTrackKin d kind) 195 const AtomicString& VideoKindToString(WebMediaPlayerClient::VideoTrackKind kind)
194 { 196 {
195 switch (kind) { 197 switch (kind) {
196 case WebMediaPlayerClient::VideoTrackKindNone: 198 case WebMediaPlayerClient::VideoTrackKindNone:
197 return emptyAtom; 199 return emptyAtom;
198 case WebMediaPlayerClient::VideoTrackKindAlternative: 200 case WebMediaPlayerClient::VideoTrackKindAlternative:
199 return VideoTrack::alternativeKeyword(); 201 return VideoTrack::alternativeKeyword();
200 case WebMediaPlayerClient::VideoTrackKindCaptions: 202 case WebMediaPlayerClient::VideoTrackKindCaptions:
201 return VideoTrack::captionsKeyword(); 203 return VideoTrack::captionsKeyword();
202 case WebMediaPlayerClient::VideoTrackKindMain: 204 case WebMediaPlayerClient::VideoTrackKindMain:
203 return VideoTrack::mainKeyword(); 205 return VideoTrack::mainKeyword();
204 case WebMediaPlayerClient::VideoTrackKindSign: 206 case WebMediaPlayerClient::VideoTrackKindSign:
205 return VideoTrack::signKeyword(); 207 return VideoTrack::signKeyword();
206 case WebMediaPlayerClient::VideoTrackKindSubtitles: 208 case WebMediaPlayerClient::VideoTrackKindSubtitles:
207 return VideoTrack::subtitlesKeyword(); 209 return VideoTrack::subtitlesKeyword();
208 case WebMediaPlayerClient::VideoTrackKindCommentary: 210 case WebMediaPlayerClient::VideoTrackKindCommentary:
209 return VideoTrack::commentaryKeyword(); 211 return VideoTrack::commentaryKeyword();
210 } 212 }
211 213
212 ASSERT_NOT_REACHED(); 214 ASSERT_NOT_REACHED();
213 return emptyAtom; 215 return emptyAtom;
214 } 216 }
215 217
216 static bool canLoadURL(const KURL& url, const ContentType& contentType, const St ring& keySystem) 218 bool canLoadURL(const KURL& url, const ContentType& contentType, const String& k eySystem)
217 { 219 {
218 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); 220 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs"));
219 221
220 String contentMIMEType = contentType.type().lower(); 222 String contentMIMEType = contentType.type().lower();
221 String contentTypeCodecs = contentType.parameter(codecs); 223 String contentTypeCodecs = contentType.parameter(codecs);
222 224
223 // If the MIME type is missing or is not meaningful, try to figure it out fr om the URL. 225 // If the MIME type is missing or is not meaningful, try to figure it out fr om the URL.
224 if (contentMIMEType.isEmpty() || contentMIMEType == "application/octet-strea m" || contentMIMEType == "text/plain") { 226 if (contentMIMEType.isEmpty() || contentMIMEType == "application/octet-strea m" || contentMIMEType == "text/plain") {
225 if (url.protocolIsData()) 227 if (url.protocolIsData())
226 contentMIMEType = mimeTypeFromDataURL(url.string()); 228 contentMIMEType = mimeTypeFromDataURL(url.string());
227 } 229 }
228 230
229 // If no MIME type is specified, always attempt to load. 231 // If no MIME type is specified, always attempt to load.
230 if (contentMIMEType.isEmpty()) 232 if (contentMIMEType.isEmpty())
231 return true; 233 return true;
232 234
233 // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream" 235 // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream"
234 // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows 236 // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
235 // it cannot render. 237 // it cannot render.
236 if (contentMIMEType != "application/octet-stream" || contentTypeCodecs.isEmp ty()) { 238 if (contentMIMEType != "application/octet-stream" || contentTypeCodecs.isEmp ty()) {
237 WebMimeRegistry::SupportsType supported = Platform::current()->mimeRegis try()->supportsMediaMIMEType(contentMIMEType, contentTypeCodecs, keySystem.lower ()); 239 WebMimeRegistry::SupportsType supported = Platform::current()->mimeRegis try()->supportsMediaMIMEType(contentMIMEType, contentTypeCodecs, keySystem.lower ());
238 return supported > WebMimeRegistry::IsNotSupported; 240 return supported > WebMimeRegistry::IsNotSupported;
239 } 241 }
240 242
241 return false; 243 return false;
242 } 244 }
243 245
246 } // anonymous namespace
247
244 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric) 248 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric)
245 { 249 {
246 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayHistogram, ("Blink.MediaEl ement.Autoplay", NumberOfAutoplayMetrics)); 250 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayHistogram, ("Blink.MediaEl ement.Autoplay", NumberOfAutoplayMetrics));
247 autoplayHistogram.count(metric); 251 autoplayHistogram.count(metric);
248 } 252 }
249 253
250 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType, const String& keySystem) 254 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType, const String& keySystem)
251 { 255 {
252 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); 256 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs"));
253 257
(...skipping 3377 matching lines...) Expand 10 before | Expand all | Expand 10 after
3631 { 3635 {
3632 visitor->trace(m_client); 3636 visitor->trace(m_client);
3633 } 3637 }
3634 3638
3635 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) 3639 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl)
3636 { 3640 {
3637 visitor->trace(m_client); 3641 visitor->trace(m_client);
3638 } 3642 }
3639 3643
3640 } // namespace blink 3644 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698