Diff
Modified: trunk/Source/WebCore/ChangeLog (217773 => 217774)
--- trunk/Source/WebCore/ChangeLog 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/ChangeLog 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1,3 +1,109 @@
+2017-06-03 Darin Adler <[email protected]>
+
+ Streamline handling of attributes, using references as much as possible
+ https://bugs.webkit.org/show_bug.cgi?id=172899
+
+ Reviewed by Chris Dumez.
+
+ * accessibility/AccessibilityNodeObject.cpp:
+ (WebCore::AccessibilityNodeObject::valueForRange): Use reference to value of
+ attribute instead of copy to avoid reference count churn.
+ (WebCore::AccessibilityNodeObject::maxValueForRange): Ditto.
+ (WebCore::AccessibilityNodeObject::minValueForRange): Ditto.
+ * accessibility/AccessibilitySVGElement.cpp:
+ (WebCore::AccessibilitySVGElement::childElementWithMatchingLanguage): Ditto.
+ (WebCore::AccessibilitySVGElement::accessibilityDescription): Ditto.
+ * css/PropertySetCSSStyleDeclaration.cpp:
+ (WebCore::StyleAttributeMutationScope::StyleAttributeMutationScope): Ditto.
+
+ * editing/cocoa/DataDetection.mm:
+ (WebCore::DataDetection::shouldCancelDefaultAction): Use the
+ equalLettersIgnoringASCIICase function instead of using
+ both equalIgnoringASCIICase and convertToASCIILowercase.
+
+ * html/HTMLAudioElement.cpp:
+ (WebCore::HTMLAudioElement::HTMLAudioElement): Marked this inline since we
+ want it inlined the one place it's used.
+ (WebCore::HTMLAudioElement::create): Use auto and named the local variable
+ just element.
+ (WebCore::HTMLAudioElement::createForJSConstructor): Call create rather than
+ repeating the code from create. Use setAttributeWithoutSynchronization directly
+ rather than calling helper functions. Removed unneeded null check;
+ setAttributeWithoutSynchronization handles null by removing the attribute.
+ * html/HTMLAudioElement.h: Changed src argument of createForJSConstructor to
+ take AtomicString since that is what we need for an attribute value.
+ * html/HTMLAudioElement.idl: Use [AtomicString] for src argument.
+
+ * html/HTMLElement.cpp:
+ (WebCore::HTMLElement::directionality): Use reference to value of
+ attribute instead of copy to avoid reference count churn.
+ (WebCore::HTMLElement::shouldAutocorrect): Ditto.
+
+ * html/HTMLImageElement.cpp:
+ (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): Call the new
+ parsedMediaAttribute instead of the old mediaQuerySet function. Other than the
+ name, the only change is that the result is now a const pointer.
+
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::updateType): Removed unnecessary local variable,
+ resulting in code that is slightly cleaner and possibly eliminating reference
+ count chrun.
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::setSrc): Deleted.
+ (WebCore::HTMLMediaElement::selectNextSourceChild): Use parsedMediaAttribute and
+ removed rendudant direct check of whether mediaAttr is present. Changed logging to
+ get the media attribute directly rather than with a helper function. Changed type
+ to get the type attribute directly rather than with a helper function.
+ (WebCore::HTMLMediaElement::sourceWasAdded): Take a reference rather than a pointer.
+ (WebCore::HTMLMediaElement::sourceWasRemoved): Ditto.
+ (WebCore::HTMLMediaElement::doesHaveAttribute): Use reference to value of
+ attribute instead of copy to avoid reference count churn.
+ * html/HTMLMediaElement.h: Updated for the above.
+
+ * html/HTMLSourceElement.cpp:
+ (WebCore::HTMLSourceElement::insertedInto): Pass reference instead of pointer.
+ (WebCore::HTMLSourceElement::removedFrom): Ditto.
+ (WebCore::HTMLSourceElement::setSrc): Deleted.
+ (WebCore::HTMLSourceElement::media): Deleted.
+ (WebCore::HTMLSourceElement::setMedia): Deleted.
+ (WebCore::HTMLSourceElement::type): Deleted.
+ (WebCore::HTMLSourceElement::setType): Deleted.
+ (WebCore::HTMLSourceElement::parseAttribute): Clear out m_cachedParsedMediaAttribute.
+ This makes the parsing be lazy. The old code would parse the attribute value to make
+ a MediaQuerySet here, but we do it in parsedMediaAttribute now.
+ (WebCore::HTMLSourceElement::parsedMediaAttribute): Added. Creates a MediaQuerySet
+ if needed, and returns it or null.
+ * html/HTMLSourceElement.h: Removed include of MediaList.h. Removed unneeded media,
+ type, setSrc, setMedia, and setType functions. Replaced the mediaQuerySet function
+ with the parsedMediaAttribute, which returns a const pointer rather than non-const,
+ and is also non-inline because it lazily creates the MediaQuerySet as needed. Replaced
+ m_mediaQuerySet with m_cachedParsedMediaAttribute.
+ * html/HTMLSourceElement.idl: Use [Reflect] for both type and media.
+
+ * html/MediaDocument.cpp: Modernize the MediaDocumentParser constructor.
+ (WebCore::MediaDocumentParser::createDocumentStructure): Instead of setSrc, use
+ setAttributeWithoutSynchronization for the src attribute just as we do for all the
+ other attributes of the newly created video element.
+
+ * html/MediaElementSession.cpp:
+ (WebCore::MediaElementSession::wirelessVideoPlaybackDisabled): Use reference to
+ value of attribute instead of copy to avoid reference count churn.
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::defaultSubstituteDataForURL): Ditto.
+ * rendering/RenderThemeIOS.mm:
+ (WebCore::getAttachmentProgress): Ditto.
+ * rendering/RenderThemeMac.mm:
+ (WebCore::AttachmentLayout::layOutSubtitle): Ditto.
+ (WebCore::RenderThemeMac::paintAttachment): Ditto.
+ * svg/SVGHKernElement.cpp:
+ (WebCore::SVGHKernElement::buildHorizontalKerningPair): Ditto.
+ * svg/SVGVKernElement.cpp:
+ (WebCore::SVGVKernElement::buildVerticalKerningPair): Ditto.
+ * svg/animation/SVGSMILElement.cpp:
+ (WebCore::SVGSMILElement::buildPendingResource): Ditto. Also use parentElement
+ instead of writing out code that does exactly what it does.
+
2017-06-03 Sam Weinig <[email protected]>
Can't use Object.defineProperty() to add an item to a DOMStringMap or Storage
Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp (217773 => 217774)
--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -861,7 +861,7 @@
// In ARIA 1.1, the implicit value for aria-valuenow on a spin button is 0.
// For other roles, it is half way between aria-valuemin and aria-valuemax.
- auto value = getAttribute(aria_valuenowAttr);
+ auto& value = getAttribute(aria_valuenowAttr);
if (!value.isEmpty())
return value.toFloat();
@@ -879,7 +879,7 @@
if (!isRangeControl())
return 0.0f;
- auto value = getAttribute(aria_valuemaxAttr);
+ auto& value = getAttribute(aria_valuemaxAttr);
if (!value.isEmpty())
return value.toFloat();
@@ -899,7 +899,7 @@
if (!isRangeControl())
return 0.0f;
- auto value = getAttribute(aria_valueminAttr);
+ auto& value = getAttribute(aria_valueminAttr);
if (!value.isEmpty())
return value.toFloat();
Modified: trunk/Source/WebCore/accessibility/AccessibilitySVGElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/accessibility/AccessibilitySVGElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/accessibility/AccessibilitySVGElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -91,7 +91,7 @@
Vector<String> childLanguageCodes;
Vector<Element*> elements;
for (auto& child : children) {
- String lang = child.attributeWithoutSynchronization(SVGNames::langAttr);
+ auto& lang = child.attributeWithoutSynchronization(SVGNames::langAttr);
childLanguageCodes.append(lang);
elements.append(&child);
@@ -139,7 +139,7 @@
return titleChild->textContent();
if (is<SVGAElement>(element())) {
- String xlinkTitle = element()->attributeWithoutSynchronization(XLinkNames::titleAttr);
+ auto& xlinkTitle = element()->attributeWithoutSynchronization(XLinkNames::titleAttr);
if (!xlinkTitle.isEmpty())
return xlinkTitle;
}
Modified: trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp (217773 => 217774)
--- trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -37,8 +37,6 @@
namespace WebCore {
-namespace {
-
class StyleAttributeMutationScope {
WTF_MAKE_NONCOPYABLE(StyleAttributeMutationScope);
public:
@@ -88,7 +86,7 @@
m_mutationRecipients->enqueueMutationRecord(WTFMove(mutation));
}
if (m_customElement) {
- AtomicString newValue = m_customElement->getAttribute(HTMLNames::styleAttr);
+ auto& newValue = m_customElement->getAttribute(HTMLNames::styleAttr);
CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded(*m_customElement, HTMLNames::styleAttr, m_oldValue, newValue);
}
}
@@ -95,12 +93,12 @@
s_shouldDeliver = false;
if (!s_shouldNotifyInspector) {
- s_currentDecl = 0;
+ s_currentDecl = nullptr;
return;
}
// We have to clear internal state before calling Inspector's code.
PropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDecl;
- s_currentDecl = 0;
+ s_currentDecl = nullptr;
s_shouldNotifyInspector = false;
if (localCopyStyleDecl->parentElement())
InspectorInstrumentation::didInvalidateStyleAttr(localCopyStyleDecl->parentElement()->document(), *localCopyStyleDecl->parentElement());
@@ -128,12 +126,10 @@
};
unsigned StyleAttributeMutationScope::s_scopeCount = 0;
-PropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = 0;
+PropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = nullptr;
bool StyleAttributeMutationScope::s_shouldNotifyInspector = false;
bool StyleAttributeMutationScope::s_shouldDeliver = false;
-} // namespace
-
void PropertySetCSSStyleDeclaration::ref()
{
m_propertySet->ref();
@@ -316,7 +312,7 @@
DeprecatedCSSOMValue* PropertySetCSSStyleDeclaration::wrapForDeprecatedCSSOM(CSSValue* internalValue)
{
if (!internalValue)
- return 0;
+ return nullptr;
// The map is here to maintain the object identity of the CSSValues over multiple invocations.
// FIXME: It is likely that the identity is not important for web compatibility and this code should be removed.
@@ -332,7 +328,7 @@
StyleSheetContents* PropertySetCSSStyleDeclaration::contextStyleSheet() const
{
CSSStyleSheet* cssStyleSheet = parentStyleSheet();
- return cssStyleSheet ? &cssStyleSheet->contents() : 0;
+ return cssStyleSheet ? &cssStyleSheet->contents() : nullptr;
}
CSSParserContext PropertySetCSSStyleDeclaration::cssParserContext() const
Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (217773 => 217774)
--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2017-06-04 18:19:16 UTC (rev 217774)
@@ -204,10 +204,10 @@
#else
if (!is<HTMLAnchorElement>(element))
return false;
- if (!equalIgnoringASCIICase(element.attributeWithoutSynchronization(x_apple_data_detectorsAttr), "true"))
+ if (!equalLettersIgnoringASCIICase(element.attributeWithoutSynchronization(x_apple_data_detectorsAttr), "true"))
return false;
- String type = element.getAttribute(x_apple_data_detectors_typeAttr).convertToASCIILowercase();
- if (type == "misc" || type == "calendar-event" || type == "telephone")
+ auto& type = element.attributeWithoutSynchronization(x_apple_data_detectors_typeAttr);
+ if (equalLettersIgnoringASCIICase(type, "misc") || equalLettersIgnoringASCIICase(type, "calendar-event") || equalLettersIgnoringASCIICase(type, "telephone"))
return true;
return false;
#endif
Modified: trunk/Source/WebCore/html/HTMLAudioElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLAudioElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLAudioElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -24,7 +24,9 @@
*/
#include "config.h"
+
#if ENABLE(VIDEO)
+
#include "HTMLAudioElement.h"
#include "HTMLNames.h"
@@ -33,7 +35,7 @@
using namespace HTMLNames;
-HTMLAudioElement::HTMLAudioElement(const QualifiedName& tagName, Document& document, bool createdByParser)
+inline HTMLAudioElement::HTMLAudioElement(const QualifiedName& tagName, Document& document, bool createdByParser)
: HTMLMediaElement(tagName, document, createdByParser)
{
ASSERT(hasTagName(audioTag));
@@ -41,20 +43,19 @@
Ref<HTMLAudioElement> HTMLAudioElement::create(const QualifiedName& tagName, Document& document, bool createdByParser)
{
- Ref<HTMLAudioElement> audioElement = adoptRef(*new HTMLAudioElement(tagName, document, createdByParser));
- audioElement->suspendIfNeeded();
- return audioElement;
+ auto element = adoptRef(*new HTMLAudioElement(tagName, document, createdByParser));
+ element->suspendIfNeeded();
+ return element;
}
-Ref<HTMLAudioElement> HTMLAudioElement::createForJSConstructor(Document& document, const String& src)
+Ref<HTMLAudioElement> HTMLAudioElement::createForJSConstructor(Document& document, const AtomicString& src)
{
- Ref<HTMLAudioElement> audio = adoptRef(*new HTMLAudioElement(audioTag, document, false));
- audio->setPreload("auto");
- if (!src.isNull())
- audio->setSrc(src);
- audio->suspendIfNeeded();
- return audio;
+ auto element = create(audioTag, document, false);
+ element->setAttributeWithoutSynchronization(preloadAttr, "auto");
+ element->setAttributeWithoutSynchronization(srcAttr, src);
+ return element;
}
}
+
#endif
Modified: trunk/Source/WebCore/html/HTMLAudioElement.h (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLAudioElement.h 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLAudioElement.h 2017-06-04 18:19:16 UTC (rev 217774)
@@ -37,7 +37,7 @@
class HTMLAudioElement final : public HTMLMediaElement {
public:
static Ref<HTMLAudioElement> create(const QualifiedName&, Document&, bool);
- static Ref<HTMLAudioElement> createForJSConstructor(Document&, const String& src);
+ static Ref<HTMLAudioElement> createForJSConstructor(Document&, const AtomicString& src);
private:
HTMLAudioElement(const QualifiedName&, Document&, bool);
Modified: trunk/Source/WebCore/html/HTMLAudioElement.idl (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLAudioElement.idl 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLAudioElement.idl 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,6 +27,6 @@
EnabledAtRuntime=Audio,
Conditional=VIDEO,
ConstructorCallWith=Document,
- NamedConstructor=Audio(optional DOMString src)
+ NamedConstructor=Audio(optional [AtomicString] DOMString src)
] interface HTMLAudioElement : HTMLMediaElement {
};
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -814,7 +814,7 @@
// Skip elements with valid dir attribute
if (is<Element>(*node)) {
- AtomicString dirAttributeValue = downcast<Element>(*node).attributeWithoutSynchronization(dirAttr);
+ auto& dirAttributeValue = downcast<Element>(*node).attributeWithoutSynchronization(dirAttr);
if (isLTROrRTLIgnoringCase(dirAttributeValue) || equalLettersIgnoringASCIICase(dirAttributeValue, "auto")) {
node = NodeTraversal::nextSkippingChildren(*node, this);
continue;
@@ -1059,7 +1059,7 @@
bool HTMLElement::shouldAutocorrect() const
{
- auto autocorrectValue = attributeWithoutSynchronization(HTMLNames::autocorrectAttr);
+ auto& autocorrectValue = attributeWithoutSynchronization(HTMLNames::autocorrectAttr);
// Unrecognized values fall back to "on".
return !equalLettersIgnoringASCIICase(autocorrectValue, "off");
}
Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLImageElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -168,7 +168,7 @@
auto* documentElement = document().documentElement();
MediaQueryEvaluator evaluator { document().printing() ? "print" : "screen", document(), documentElement ? documentElement->computedStyle() : nullptr };
- auto* queries = source.mediaQuerySet();
+ auto* queries = source.parsedMediaAttribute();
auto evaluation = !queries || evaluator.evaluate(*queries, picture->viewportDependentResults());
if (picture->hasViewportDependentResults())
document().addViewportDependentPicture(*picture);
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -507,10 +507,9 @@
setAttributeWithoutSynchronization(valueAttr, m_valueIfDirty);
m_valueIfDirty = String();
}
- if (!didStoreValue && willStoreValue) {
- AtomicString valueString = attributeWithoutSynchronization(valueAttr);
- m_valueIfDirty = sanitizeValue(valueString);
- } else
+ if (!didStoreValue && willStoreValue)
+ m_valueIfDirty = sanitizeValue(attributeWithoutSynchronization(valueAttr));
+ else
updateValueIfNeeded();
setFormControlValueMatchesRenderer(false);
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1092,11 +1092,6 @@
return m_error.get();
}
-void HTMLMediaElement::setSrc(const String& url)
-{
- setAttributeWithoutSynchronization(srcAttr, url);
-}
-
void HTMLMediaElement::setSrcObject(MediaProvider&& mediaProvider)
{
// FIXME: Setting the srcObject attribute may cause other changes to the media element's internal state:
@@ -4288,20 +4283,17 @@
if (mediaURL.isEmpty())
goto CheckAgain;
- if (source->hasAttributeWithoutSynchronization(mediaAttr)) {
- auto media = source->mediaQuerySet();
+ if (auto* media = source->parsedMediaAttribute()) {
#if !LOG_DISABLED
if (shouldLog)
- LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'media' is %s", this, source->media().utf8().data());
+ LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'media' is %s", this, source->attributeWithoutSynchronization(mediaAttr).string().utf8().data());
#endif
- if (media) {
- auto* renderer = this->renderer();
- if (!MediaQueryEvaluator { "screen", document(), renderer ? &renderer->style() : nullptr }.evaluate(*media))
- goto CheckAgain;
- }
+ auto* renderer = this->renderer();
+ if (!MediaQueryEvaluator { "screen", document(), renderer ? &renderer->style() : nullptr }.evaluate(*media))
+ goto CheckAgain;
}
- type = source->type();
+ type = source->attributeWithoutSynchronization(typeAttr);
if (type.isEmpty() && mediaURL.protocolIsData())
type = mimeTypeFromDataURL(mediaURL);
if (!type.isEmpty()) {
@@ -4362,13 +4354,13 @@
return canUseSourceElement ? mediaURL : URL();
}
-void HTMLMediaElement::sourceWasAdded(HTMLSourceElement* source)
+void HTMLMediaElement::sourceWasAdded(HTMLSourceElement& source)
{
- LOG(Media, "HTMLMediaElement::sourceWasAdded(%p) - %p", this, source);
+ LOG(Media, "HTMLMediaElement::sourceWasAdded(%p) - %p", this, &source);
#if !LOG_DISABLED
- if (source->hasTagName(sourceTag)) {
- URL url = ""
+ if (source.hasTagName(sourceTag)) {
+ URL url = ""
LOG(Media, "HTMLMediaElement::sourceWasAdded(%p) - 'src' is %s", this, urlForLoggingMedia(url).utf8().data());
}
#endif
@@ -4381,14 +4373,14 @@
// attribute and whose networkState has the value NETWORK_EMPTY, the user agent must invoke
// the media element's resource selection algorithm.
if (networkState() == HTMLMediaElement::NETWORK_EMPTY) {
- m_nextChildNodeToConsider = source;
+ m_nextChildNodeToConsider = &source;
selectMediaResource();
return;
}
- if (m_currentSourceNode && source == m_currentSourceNode->nextSibling()) {
+ if (m_currentSourceNode && &source == m_currentSourceNode->nextSibling()) {
LOG(Media, "HTMLMediaElement::sourceWasAdded(%p) - <source> inserted immediately after current source", this);
- m_nextChildNodeToConsider = source;
+ m_nextChildNodeToConsider = &source;
return;
}
@@ -4406,29 +4398,29 @@
m_networkState = NETWORK_LOADING;
// 25. Jump back to the find next candidate step above.
- m_nextChildNodeToConsider = source;
+ m_nextChildNodeToConsider = &source;
scheduleNextSourceChild();
}
-void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement* source)
+void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement& source)
{
- LOG(Media, "HTMLMediaElement::sourceWasRemoved(%p) - %p", this, source);
+ LOG(Media, "HTMLMediaElement::sourceWasRemoved(%p) - %p", this, &source);
#if !LOG_DISABLED
- if (source->hasTagName(sourceTag)) {
- URL url = ""
+ if (source.hasTagName(sourceTag)) {
+ URL url = ""
LOG(Media, "HTMLMediaElement::sourceWasRemoved(%p) - 'src' is %s", this, urlForLoggingMedia(url).utf8().data());
}
#endif
- if (source != m_currentSourceNode && source != m_nextChildNodeToConsider)
+ if (&source != m_currentSourceNode && &source != m_nextChildNodeToConsider)
return;
- if (source == m_nextChildNodeToConsider) {
+ if (&source == m_nextChildNodeToConsider) {
if (m_currentSourceNode)
m_nextChildNodeToConsider = m_currentSourceNode->nextSibling();
LOG(Media, "HTMLMediaElement::sourceRemoved(%p) - m_nextChildNodeToConsider set to %p", this, m_nextChildNodeToConsider.get());
- } else if (source == m_currentSourceNode) {
+ } else if (&source == m_currentSourceNode) {
// Clear the current source node pointer, but don't change the movie as the spec says:
// 4.8.8 - Dynamically modifying a source element and its attribute when the element is already
// inserted in a video or audio element will have no effect.
@@ -7275,7 +7267,7 @@
{
QualifiedName attributeName(nullAtom, attribute, nullAtom);
- AtomicString elementValue = attributeWithoutSynchronization(attributeName);
+ auto& elementValue = attributeWithoutSynchronization(attributeName);
if (elementValue.isNull())
return false;
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2017-06-04 18:19:16 UTC (rev 217774)
@@ -184,7 +184,6 @@
// error state
WEBCORE_EXPORT MediaError* error() const;
- void setSrc(const String&);
const URL& currentSrc() const { return m_currentSrc; }
const MediaProvider& srcObject() const { return m_mediaProvider; }
@@ -411,8 +410,8 @@
MediaControls* mediaControls() const;
- void sourceWasRemoved(HTMLSourceElement*);
- void sourceWasAdded(HTMLSourceElement*);
+ void sourceWasRemoved(HTMLSourceElement&);
+ void sourceWasAdded(HTMLSourceElement&);
void privateBrowsingStateDidChange() override;
Modified: trunk/Source/WebCore/html/HTMLSourceElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLSourceElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLSourceElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,13 +29,15 @@
#include "Event.h"
#include "EventNames.h"
#include "HTMLDocument.h"
-#if ENABLE(VIDEO)
-#include "HTMLMediaElement.h"
-#endif
#include "HTMLNames.h"
#include "HTMLPictureElement.h"
#include "Logging.h"
+#include "MediaList.h"
+#if ENABLE(VIDEO)
+#include "HTMLMediaElement.h"
+#endif
+
namespace WebCore {
using namespace HTMLNames;
@@ -64,11 +66,10 @@
Node::InsertionNotificationRequest HTMLSourceElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
- Element* parent = parentElement();
- if (parent) {
+ if (auto* parent = parentElement()) {
#if ENABLE(VIDEO)
if (is<HTMLMediaElement>(*parent))
- downcast<HTMLMediaElement>(*parent).sourceWasAdded(this);
+ downcast<HTMLMediaElement>(*parent).sourceWasAdded(*this);
else
#endif
if (is<HTMLPictureElement>(*parent))
@@ -85,7 +86,7 @@
if (parent) {
#if ENABLE(VIDEO)
if (is<HTMLMediaElement>(*parent))
- downcast<HTMLMediaElement>(*parent).sourceWasRemoved(this);
+ downcast<HTMLMediaElement>(*parent).sourceWasRemoved(*this);
else
#endif
if (is<HTMLPictureElement>(*parent))
@@ -94,31 +95,6 @@
HTMLElement::removedFrom(removalRoot);
}
-void HTMLSourceElement::setSrc(const String& url)
-{
- setAttributeWithoutSynchronization(srcAttr, url);
-}
-
-String HTMLSourceElement::media() const
-{
- return attributeWithoutSynchronization(mediaAttr);
-}
-
-void HTMLSourceElement::setMedia(const String& media)
-{
- setAttributeWithoutSynchronization(mediaAttr, media);
-}
-
-String HTMLSourceElement::type() const
-{
- return attributeWithoutSynchronization(typeAttr);
-}
-
-void HTMLSourceElement::setType(const String& type)
-{
- setAttributeWithoutSynchronization(typeAttr, type);
-}
-
void HTMLSourceElement::scheduleErrorEvent()
{
LOG(Media, "HTMLSourceElement::scheduleErrorEvent - %p", this);
@@ -181,7 +157,7 @@
HTMLElement::parseAttribute(name, value);
if (name == srcsetAttr || name == sizesAttr || name == mediaAttr || name == typeAttr) {
if (name == mediaAttr)
- m_mediaQuerySet = MediaQuerySet::create(value);
+ m_cachedParsedMediaAttribute = std::nullopt;
auto* parent = parentNode();
if (is<HTMLPictureElement>(parent))
downcast<HTMLPictureElement>(*parent).sourcesChanged();
@@ -188,5 +164,16 @@
}
}
+const MediaQuerySet* HTMLSourceElement::parsedMediaAttribute() const
+{
+ if (!m_cachedParsedMediaAttribute) {
+ RefPtr<const MediaQuerySet> parsedAttribute;
+ auto& value = attributeWithoutSynchronization(mediaAttr);
+ if (!value.isNull())
+ parsedAttribute = MediaQuerySet::create(value);
+ m_cachedParsedMediaAttribute = WTFMove(parsedAttribute);
+ }
+ return m_cachedParsedMediaAttribute.value().get();
}
+}
Modified: trunk/Source/WebCore/html/HTMLSourceElement.h (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLSourceElement.h 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLSourceElement.h 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,26 +26,21 @@
#pragma once
#include "HTMLElement.h"
-#include "MediaList.h"
#include "Timer.h"
namespace WebCore {
-class HTMLSourceElement final : public HTMLElement, public ActiveDOMObject {
+class MediaQuerySet;
+
+class HTMLSourceElement final : public HTMLElement, private ActiveDOMObject {
public:
static Ref<HTMLSourceElement> create(Document&);
static Ref<HTMLSourceElement> create(const QualifiedName&, Document&);
- String media() const;
- String type() const;
- void setSrc(const String&);
- void setMedia(const String&);
- void setType(const String&);
-
void scheduleErrorEvent();
void cancelPendingErrorEvent();
- MediaQuerySet* mediaQuerySet() const { return m_mediaQuerySet.get(); }
+ const MediaQuerySet* parsedMediaAttribute() const;
private:
HTMLSourceElement(const QualifiedName&, Document&);
@@ -67,7 +62,7 @@
Timer m_errorEventTimer;
bool m_shouldRescheduleErrorEventOnResume { false };
- RefPtr<MediaQuerySet> m_mediaQuerySet;
+ mutable std::optional<RefPtr<const MediaQuerySet>> m_cachedParsedMediaAttribute;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/html/HTMLSourceElement.idl (217773 => 217774)
--- trunk/Source/WebCore/html/HTMLSourceElement.idl 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/HTMLSourceElement.idl 2017-06-04 18:19:16 UTC (rev 217774)
@@ -25,8 +25,8 @@
interface HTMLSourceElement : HTMLElement {
[Reflect, URL] attribute USVString src;
- attribute DOMString type;
+ [Reflect] attribute DOMString type;
[Reflect] attribute USVString srcset;
[Reflect] attribute DOMString sizes;
- attribute DOMString media;
+ [Reflect] attribute DOMString media;
};
Modified: trunk/Source/WebCore/html/MediaDocument.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/MediaDocument.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/MediaDocument.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -67,17 +67,15 @@
private:
MediaDocumentParser(MediaDocument& document)
- : RawDataDocumentParser(document)
- , m_mediaElement(0)
+ : RawDataDocumentParser { document }
+ , m_outgoingReferrer { document.outgoingReferrer() }
{
- m_outgoingReferrer = document.outgoingReferrer();
}
- void appendBytes(DocumentWriter&, const char*, size_t) override;
-
+ void appendBytes(DocumentWriter&, const char*, size_t) final;
void createDocumentStructure();
- HTMLMediaElement* m_mediaElement;
+ HTMLMediaElement* m_mediaElement { nullptr };
String m_outgoingReferrer;
};
@@ -111,7 +109,7 @@
videoElement->setAttributeWithoutSynchronization(controlsAttr, emptyAtom);
videoElement->setAttributeWithoutSynchronization(autoplayAttr, emptyAtom);
videoElement->setAttributeWithoutSynchronization(playsinlineAttr, emptyAtom);
- videoElement->setSrc(document.url());
+ videoElement->setAttributeWithoutSynchronization(srcAttr, document.url().string());
if (auto* loader = document.loader())
videoElement->setAttributeWithoutSynchronization(typeAttr, loader->responseMIMEType());
Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (217773 => 217774)
--- trunk/Source/WebCore/html/MediaElementSession.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -429,7 +429,7 @@
}
#if PLATFORM(IOS)
- String legacyAirplayAttributeValue = element.attributeWithoutSynchronization(HTMLNames::webkitairplayAttr);
+ auto& legacyAirplayAttributeValue = element.attributeWithoutSynchronization(HTMLNames::webkitairplayAttr);
if (equalLettersIgnoringASCIICase(legacyAirplayAttributeValue, "deny")) {
LOG(Media, "MediaElementSession::wirelessVideoPlaybackDisabled - returning TRUE because of legacy attribute");
return true;
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (217773 => 217774)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1306,9 +1306,9 @@
{
if (!shouldTreatURLAsSrcdocDocument(url))
return SubstituteData();
- String srcdoc = m_frame.ownerElement()->attributeWithoutSynchronization(srcdocAttr);
+ auto& srcdoc = m_frame.ownerElement()->attributeWithoutSynchronization(srcdocAttr);
ASSERT(!srcdoc.isNull());
- CString encodedSrcdoc = srcdoc.utf8();
+ CString encodedSrcdoc = srcdoc.string().utf8();
ResourceResponse response(URL(), ASCIILiteral("text/html"), encodedSrcdoc.length(), ASCIILiteral("UTF-8"));
return SubstituteData(SharedBuffer::create(encodedSrcdoc.data(), encodedSrcdoc.length()), URL(), response, SubstituteData::SessionHistoryVisibility::Hidden);
Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (217773 => 217774)
--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1599,7 +1599,7 @@
static BOOL getAttachmentProgress(const RenderAttachment& attachment, float& progress)
{
- String progressString = attachment.attachmentElement().attributeWithoutSynchronization(progressAttr);
+ auto& progressString = attachment.attachmentElement().attributeWithoutSynchronization(progressAttr);
if (progressString.isEmpty())
return NO;
bool validProgress;
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (217773 => 217774)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2017-06-04 18:19:16 UTC (rev 217774)
@@ -2345,8 +2345,7 @@
void AttachmentLayout::layOutSubtitle(const RenderAttachment& attachment)
{
- String subtitleText = attachment.attachmentElement().attributeWithoutSynchronization(subtitleAttr);
-
+ auto& subtitleText = attachment.attachmentElement().attributeWithoutSynchronization(subtitleAttr);
if (subtitleText.isEmpty())
return;
@@ -2594,7 +2593,7 @@
AttachmentLayout layout(attachment);
- String progressString = attachment.attachmentElement().attributeWithoutSynchronization(progressAttr);
+ auto& progressString = attachment.attachmentElement().attributeWithoutSynchronization(progressAttr);
bool validProgress = false;
float progress = 0;
if (!progressString.isEmpty())
Modified: trunk/Source/WebCore/svg/SVGHKernElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/svg/SVGHKernElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/svg/SVGHKernElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -43,10 +43,10 @@
bool SVGHKernElement::buildHorizontalKerningPair(SVGKerningPair& kerningPair) const
{
- String u1 = attributeWithoutSynchronization(SVGNames::u1Attr);
- String g1 = attributeWithoutSynchronization(SVGNames::g1Attr);
- String u2 = attributeWithoutSynchronization(SVGNames::u2Attr);
- String g2 = attributeWithoutSynchronization(SVGNames::g2Attr);
+ auto& u1 = attributeWithoutSynchronization(SVGNames::u1Attr);
+ auto& g1 = attributeWithoutSynchronization(SVGNames::g1Attr);
+ auto& u2 = attributeWithoutSynchronization(SVGNames::u2Attr);
+ auto& g2 = attributeWithoutSynchronization(SVGNames::g2Attr);
if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty()))
return false;
Modified: trunk/Source/WebCore/svg/SVGVKernElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/svg/SVGVKernElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/svg/SVGVKernElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -42,10 +42,10 @@
bool SVGVKernElement::buildVerticalKerningPair(SVGKerningPair& kerningPair) const
{
- String u1 = attributeWithoutSynchronization(SVGNames::u1Attr);
- String g1 = attributeWithoutSynchronization(SVGNames::g1Attr);
- String u2 = attributeWithoutSynchronization(SVGNames::u2Attr);
- String g2 = attributeWithoutSynchronization(SVGNames::g2Attr);
+ auto& u1 = attributeWithoutSynchronization(SVGNames::u1Attr);
+ auto& g1 = attributeWithoutSynchronization(SVGNames::g1Attr);
+ auto& u2 = attributeWithoutSynchronization(SVGNames::u2Attr);
+ auto& g2 = attributeWithoutSynchronization(SVGNames::g2Attr);
if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty()))
return false;
Modified: trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp (217773 => 217774)
--- trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp 2017-06-04 18:19:16 UTC (rev 217774)
@@ -176,12 +176,12 @@
}
String id;
- String href = ""
Element* target;
+ auto& href = ""
if (href.isEmpty())
- target = is<Element>(parentNode()) ? downcast<Element>(parentNode()) : nullptr;
+ target = parentElement();
else
- target = SVGURIReference::targetElementFromIRIString(href, document(), &id);
+ target = SVGURIReference::targetElementFromIRIString(href.string(), document(), &id);
SVGElement* svgTarget = is<SVGElement>(target) ? downcast<SVGElement>(target) : nullptr;
if (svgTarget && !svgTarget->isConnected())
Modified: trunk/Source/WebKit/mac/ChangeLog (217773 => 217774)
--- trunk/Source/WebKit/mac/ChangeLog 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebKit/mac/ChangeLog 2017-06-04 18:19:16 UTC (rev 217774)
@@ -1,3 +1,15 @@
+2017-06-03 Darin Adler <[email protected]>
+
+ Streamline handling of attributes, using references as much as possible
+ https://bugs.webkit.org/show_bug.cgi?id=172899
+
+ Reviewed by Chris Dumez.
+
+ * WebView/WebHTMLRepresentation.mm:
+ (matchLabelsAgainstElement): Added handling of nullptr since nothing guarantees the
+ passed in element can't be null. Removed unnecessary conversion from NSString to String
+ and then back to NSString.
+
2017-06-01 Andy Estes <[email protected]>
REGRESSION (r217626): ENABLE_APPLE_PAY_SESSION_V3 was disabled by mistake
Modified: trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm (217773 => 217774)
--- trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm 2017-06-04 18:00:01 UTC (rev 217773)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm 2017-06-04 18:19:16 UTC (rev 217774)
@@ -516,14 +516,17 @@
return nil;
}
-static NSString* matchLabelsAgainstElement(NSArray* labels, Element* element)
+static NSString *matchLabelsAgainstElement(NSArray *labels, Element* element)
{
+ if (!element)
+ return nil;
+
// Match against the name element, then against the id element if no match is found for the name element.
// See 7538330 for one popular site that benefits from the id element check.
- String resultFromNameAttribute = matchLabelsAgainstString(labels, element->attributeWithoutSynchronization(nameAttr));
- if (!resultFromNameAttribute.isEmpty())
+ auto resultFromNameAttribute = matchLabelsAgainstString(labels, element->attributeWithoutSynchronization(nameAttr));
+ if (resultFromNameAttribute.length)
return resultFromNameAttribute;
-
+
return matchLabelsAgainstString(labels, element->attributeWithoutSynchronization(idAttr));
}