Merge from Chromium at DEPS revision 40.0.2214.10

This commit was generated by merge_to_master.py.

Change-Id: I1df6ee2e582be08580a20291e1a0b1c2c94ab24b
diff --git a/Source/core/html/shadow/MediaControlElements.cpp b/Source/core/html/shadow/MediaControlElements.cpp
index ecf4074..ce0549b 100644
--- a/Source/core/html/shadow/MediaControlElements.cpp
+++ b/Source/core/html/shadow/MediaControlElements.cpp
@@ -570,6 +570,7 @@
 MediaControlCastButtonElement::MediaControlCastButtonElement(MediaControls& mediaControls, bool isOverlayButton)
     : MediaControlInputElement(mediaControls, MediaCastOnButton), m_isOverlayButton(isOverlayButton)
 {
+    setIsPlayingRemotely(false);
 }
 
 PassRefPtrWillBeRawPtr<MediaControlCastButtonElement> MediaControlCastButtonElement::create(MediaControls& mediaControls, bool isOverlayButton)
@@ -601,7 +602,19 @@
 
 void MediaControlCastButtonElement::setIsPlayingRemotely(bool isPlayingRemotely)
 {
-    setDisplayType(isPlayingRemotely ? MediaCastOnButton : MediaCastOffButton);
+    if (isPlayingRemotely) {
+        if (m_isOverlayButton) {
+            setDisplayType(MediaOverlayCastOnButton);
+        } else {
+            setDisplayType(MediaCastOnButton);
+        }
+    } else {
+        if (m_isOverlayButton) {
+            setDisplayType(MediaOverlayCastOffButton);
+        } else {
+            setDisplayType(MediaCastOffButton);
+        }
+    }
 }
 
 bool MediaControlCastButtonElement::keepEventInNode(Event* event)
diff --git a/Source/core/inspector/InspectorTraceEvents.cpp b/Source/core/inspector/InspectorTraceEvents.cpp
index dd765e1..c0aec71 100644
--- a/Source/core/inspector/InspectorTraceEvents.cpp
+++ b/Source/core/inspector/InspectorTraceEvents.cpp
@@ -492,7 +492,6 @@
 const char InspectorLayerInvalidationTrackingEvent::RemovedFromSquashingLayer[] = "Removed the layer from a squashing layer";
 const char InspectorLayerInvalidationTrackingEvent::ReflectionLayerChanged[] = "Reflection layer change";
 const char InspectorLayerInvalidationTrackingEvent::NewCompositedLayer[] = "Assigned a new composited layer";
-const char InspectorLayerInvalidationTrackingEvent::AncestorRequiresNewLayer[] = "A new composited layer is needed based on the RenderLayer's compositing ancestor's properties";
 
 PassRefPtr<TraceEvent::ConvertableToTraceFormat> InspectorLayerInvalidationTrackingEvent::data(const RenderLayer* layer, const char* reason)
 {
diff --git a/Source/core/inspector/InspectorTraceEvents.h b/Source/core/inspector/InspectorTraceEvents.h
index 2629ca1..9c9f40c 100644
--- a/Source/core/inspector/InspectorTraceEvents.h
+++ b/Source/core/inspector/InspectorTraceEvents.h
@@ -186,7 +186,6 @@
     static const char RemovedFromSquashingLayer[];
     static const char ReflectionLayerChanged[];
     static const char NewCompositedLayer[];
-    static const char AncestorRequiresNewLayer[];
 
     static PassRefPtr<TraceEvent::ConvertableToTraceFormat> data(const RenderLayer*, const char* reason);
 };
diff --git a/Source/core/paint/BoxPainter.cpp b/Source/core/paint/BoxPainter.cpp
index fb79cb9..2a9a2b6 100644
--- a/Source/core/paint/BoxPainter.cpp
+++ b/Source/core/paint/BoxPainter.cpp
@@ -547,10 +547,6 @@
     if (!m_renderBox.layer() || m_renderBox.layer()->compositingState() != PaintsIntoOwnBacking)
         return;
 
-    // We should never have this state in this function. A layer with a mask
-    // should have always created its own backing if it became composited.
-    ASSERT(m_renderBox.layer()->compositingState() != HasOwnBackingButPaintsIntoAncestor);
-
     LayoutRect paintRect = LayoutRect(paintOffset, m_renderBox.size());
     paintInfo.context->fillRect(pixelSnappedIntRect(paintRect), Color::black);
 }
diff --git a/Source/core/paint/ImagePainter.cpp b/Source/core/paint/ImagePainter.cpp
index 447ccd5..04ebee1 100644
--- a/Source/core/paint/ImagePainter.cpp
+++ b/Source/core/paint/ImagePainter.cpp
@@ -200,4 +200,17 @@
     InspectorInstrumentation::didPaintImage(&m_renderImage);
 }
 
+void ImagePainter::paintBoxDecorationBackground(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
+{
+    // Don't anti-alias the background of an image. See crbug.com/423834 for the reason why.
+    // However, don't turn off anti-aliasing for subclasses such as video.
+    bool shouldAntialias = !m_renderImage.isRenderImage();
+
+    bool oldShouldAntialias = paintInfo.context->shouldAntialias();
+
+    paintInfo.context->setShouldAntialias(shouldAntialias);
+    BoxPainter(m_renderImage).paintBoxDecorationBackground(paintInfo, paintOffset);
+    paintInfo.context->setShouldAntialias(oldShouldAntialias);
+}
+
 } // namespace blink
diff --git a/Source/core/paint/ImagePainter.h b/Source/core/paint/ImagePainter.h
index f3e2ced..2831801 100644
--- a/Source/core/paint/ImagePainter.h
+++ b/Source/core/paint/ImagePainter.h
@@ -17,9 +17,10 @@
 public:
     ImagePainter(RenderImage& renderImage) : m_renderImage(renderImage) { }
 
-    void paint(PaintInfo&, const LayoutPoint&);
-    void paintReplaced(PaintInfo&, const LayoutPoint&);
-    void paintIntoRect(GraphicsContext*, const LayoutRect&);
+    void paint(PaintInfo&, const LayoutPoint& paintOffset);
+    void paintReplaced(PaintInfo&, const LayoutPoint& paintOffset);
+    void paintIntoRect(GraphicsContext*, const LayoutRect& paintOffset);
+    void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint& paintOffset);
 
 private:
     void paintAreaElementFocusRing(PaintInfo&);
diff --git a/Source/core/paint/LayerPainter.cpp b/Source/core/paint/LayerPainter.cpp
index 00cc876..1ca2e32 100644
--- a/Source/core/paint/LayerPainter.cpp
+++ b/Source/core/paint/LayerPainter.cpp
@@ -502,7 +502,6 @@
     DisableCompositingQueryAsserts disabler;
 
     return m_renderLayer.compositingState() == NotComposited
-        || m_renderLayer.compositingState() == HasOwnBackingButPaintsIntoAncestor
         || (paintingInfo.paintBehavior & PaintBehaviorFlattenCompositingLayers)
         || ((paintFlags & PaintLayerPaintingReflection) && !m_renderLayer.has3DTransform())
         || paintForFixedRootBackground(&m_renderLayer, paintFlags);
diff --git a/Source/core/rendering/RenderImage.cpp b/Source/core/rendering/RenderImage.cpp
index 6278c97..d22459a 100644
--- a/Source/core/rendering/RenderImage.cpp
+++ b/Source/core/rendering/RenderImage.cpp
@@ -280,6 +280,11 @@
     ImagePainter(*this).paint(paintInfo, paintOffset);
 }
 
+void RenderImage::paintBoxDecorationBackground(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
+{
+    ImagePainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset);
+}
+
 void RenderImage::areaElementFocusChanged(HTMLAreaElement* areaElement)
 {
     ASSERT(areaElement->imageElement() == node());
diff --git a/Source/core/rendering/RenderImage.h b/Source/core/rendering/RenderImage.h
index 6c5c128..8a12af1 100644
--- a/Source/core/rendering/RenderImage.h
+++ b/Source/core/rendering/RenderImage.h
@@ -81,6 +81,8 @@
     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) override;
 
     virtual void paint(PaintInfo&, const LayoutPoint&) override final;
+    virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&) override final;
+
     virtual void layout() override;
     virtual bool updateImageLoadingPriorities() override final;
 
diff --git a/Source/core/rendering/RenderLayer.cpp b/Source/core/rendering/RenderLayer.cpp
index df23cdb..4fc9077 100644
--- a/Source/core/rendering/RenderLayer.cpp
+++ b/Source/core/rendering/RenderLayer.cpp
@@ -652,7 +652,7 @@
 
     m_hasNonCompositedChild = false;
     for (RenderLayer* child = firstChild(); child; child = child->nextSibling()) {
-        if (child->compositingState() == NotComposited || child->compositingState() == HasOwnBackingButPaintsIntoAncestor) {
+        if (child->compositingState() == NotComposited) {
             m_hasNonCompositedChild = true;
             return;
         }
@@ -2398,9 +2398,6 @@
     if (!m_compositedLayerMapping)
         return NotComposited;
 
-    if (compositedLayerMapping()->paintsIntoCompositedAncestor())
-        return HasOwnBackingButPaintsIntoAncestor;
-
     return PaintsIntoOwnBacking;
 }
 
@@ -2493,15 +2490,6 @@
     return m_compositedLayerMapping && m_compositedLayerMapping->hasChildClippingMaskLayer();
 }
 
-bool RenderLayer::clipsCompositingDescendantsWithBorderRadius() const
-{
-    RenderStyle* style = renderer()->style();
-    if (!style)
-        return false;
-
-    return compositor()->clipsCompositingDescendants(this) && style->hasBorderRadius();
-}
-
 bool RenderLayer::paintsWithTransform(PaintBehavior paintBehavior) const
 {
     return transform() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || compositingState() != PaintsIntoOwnBacking);
diff --git a/Source/core/rendering/RenderLayer.h b/Source/core/rendering/RenderLayer.h
index 6a447be..9fe19f8 100644
--- a/Source/core/rendering/RenderLayer.h
+++ b/Source/core/rendering/RenderLayer.h
@@ -304,8 +304,6 @@
     bool hasCompositedClippingMask() const;
     bool needsCompositedScrolling() const { return m_scrollableArea && m_scrollableArea->needsCompositedScrolling(); }
 
-    bool clipsCompositingDescendantsWithBorderRadius() const;
-
     // Computes the position of the given render object in the space of |paintInvalidationContainer|.
     // FIXME: invert the logic to have paint invalidation containers take care of painting objects into them, rather than the reverse.
     // This will allow us to clean up this static method messiness.
diff --git a/Source/core/rendering/RenderMediaControls.cpp b/Source/core/rendering/RenderMediaControls.cpp
index 9124b87..71201e5 100644
--- a/Source/core/rendering/RenderMediaControls.cpp
+++ b/Source/core/rendering/RenderMediaControls.cpp
@@ -345,15 +345,24 @@
     if (!mediaElement)
         return false;
 
-    static Image* mediaCastOnButton = platformResource("mediaplayerCastOn");
-    static Image* mediaCastOffButton = platformResource("mediaplayerCastOff");
+    static Image* mediaCastOn = platformResource("mediaplayerCastOn");
+    static Image* mediaCastOff = platformResource("mediaplayerCastOff");
+    // To ensure that the overlaid cast button is visible when overlaid on pale videos we use a
+    // different version of it for the overlaid case with a semi-opaque background.
+    static Image* mediaOverlayCastOff = platformResource("mediaplayerOverlayCastOff");
 
-    if (mediaElement->isPlayingRemotely()) {
-        return paintMediaButton(paintInfo.context, rect, mediaCastOnButton);
+    switch (mediaControlElementType(object->node())) {
+    case MediaCastOnButton:
+    case MediaOverlayCastOnButton:
+        return paintMediaButton(paintInfo.context, rect, mediaCastOn);
+    case MediaCastOffButton:
+        return paintMediaButton(paintInfo.context, rect, mediaCastOff);
+    case MediaOverlayCastOffButton:
+        return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff);
+    default:
+        ASSERT_NOT_REACHED();
+        return false;
     }
-
-    return paintMediaButton(paintInfo.context, rect, mediaCastOffButton);
-
 }
 
 bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
diff --git a/Source/core/rendering/RenderTreeAsText.cpp b/Source/core/rendering/RenderTreeAsText.cpp
index 6c73353..9544861 100644
--- a/Source/core/rendering/RenderTreeAsText.cpp
+++ b/Source/core/rendering/RenderTreeAsText.cpp
@@ -556,8 +556,6 @@
                 << l.compositedLayerMapping()->compositedBounds()
                 << ", drawsContent="
                 << l.compositedLayerMapping()->mainGraphicsLayer()->drawsContent()
-                << ", paints into ancestor="
-                << l.compositedLayerMapping()->paintsIntoCompositedAncestor()
                 << (l.shouldIsolateCompositedDescendants() ? ", isolatesCompositedBlending" : "")
                 << ")";
         }
diff --git a/Source/core/rendering/compositing/CompositedLayerMapping.cpp b/Source/core/rendering/compositing/CompositedLayerMapping.cpp
index eb1ccfc..3cf7bbc 100644
--- a/Source/core/rendering/compositing/CompositedLayerMapping.cpp
+++ b/Source/core/rendering/compositing/CompositedLayerMapping.cpp
@@ -164,8 +164,6 @@
     , m_contentOffsetInCompositingLayerDirty(false)
     , m_pendingUpdateScope(GraphicsLayerUpdateNone)
     , m_isMainFrameRenderViewLayer(false)
-    , m_requiresOwnBackingStoreForIntrinsicReasons(false)
-    , m_requiresOwnBackingStoreForAncestorReasons(false)
     , m_backgroundLayerPaintsFixedRootBackground(false)
     , m_scrollingContentsAreEmpty(false)
 {
@@ -1146,7 +1144,7 @@
 
     const IntRect blockSelectionGapsBounds = m_owningLayer.blockSelectionGapsBounds();
     const bool shouldDrawContent = !blockSelectionGapsBounds.isEmpty();
-    m_scrollingBlockSelectionLayer->setDrawsContent(!paintsIntoCompositedAncestor() && shouldDrawContent);
+    m_scrollingBlockSelectionLayer->setDrawsContent(shouldDrawContent);
     if (!shouldDrawContent)
         return;
     // FIXME: Remove the flooredIntSize conversion. crbug.com/414283.
@@ -1168,7 +1166,7 @@
         // m_scrollingLayer never has backing store.
         // m_scrollingContentsLayer only needs backing store if the scrolled contents need to paint.
         m_scrollingContentsAreEmpty = !m_owningLayer.hasVisibleContent() || !(renderer()->hasBackground() || paintsChildren());
-        m_scrollingContentsLayer->setDrawsContent(!paintsIntoCompositedAncestor() && !m_scrollingContentsAreEmpty);
+        m_scrollingContentsLayer->setDrawsContent(!m_scrollingContentsAreEmpty);
         updateScrollingBlockSelection();
     }
 
@@ -1193,10 +1191,10 @@
         m_backgroundLayer->setDrawsContent(hasPaintedContent);
 
     if (m_maskLayer)
-        m_maskLayer->setDrawsContent(!paintsIntoCompositedAncestor());
+        m_maskLayer->setDrawsContent(true);
 
     if (m_childClippingMaskLayer)
-        m_childClippingMaskLayer->setDrawsContent(!paintsIntoCompositedAncestor());
+        m_childClippingMaskLayer->setDrawsContent(true);
 }
 
 void CompositedLayerMapping::updateChildrenTransform()
@@ -1700,7 +1698,7 @@
         // contribute to. This whole confusion can be avoided by specifying
         // explicitly the composited ancestor where we would stop accumulating
         // opacity.
-        if (curr->compositingState() == PaintsIntoOwnBacking || curr->compositingState() == HasOwnBackingButPaintsIntoAncestor)
+        if (curr->compositingState() == PaintsIntoOwnBacking)
             break;
 
         finalOpacity *= curr->renderer()->opacity();
@@ -1765,7 +1763,7 @@
 
 bool CompositedLayerMapping::containsPaintedContent() const
 {
-    if (paintsIntoCompositedAncestor() || m_owningLayer.isReflection())
+    if (m_owningLayer.isReflection())
         return false;
 
     if (renderer()->isImage() && isDirectlyCompositedImage())
@@ -1952,49 +1950,6 @@
     return m_childTransformLayer.get();
 }
 
-bool CompositedLayerMapping::updateRequiresOwnBackingStoreForAncestorReasons(const RenderLayer* compositingAncestorLayer)
-{
-    unsigned previousRequiresOwnBackingStoreForAncestorReasons = m_requiresOwnBackingStoreForAncestorReasons;
-    bool previousPaintsIntoCompositedAncestor = paintsIntoCompositedAncestor();
-    bool canPaintIntoAncestor = compositingAncestorLayer
-        && (compositingAncestorLayer->compositedLayerMapping()->mainGraphicsLayer()->drawsContent()
-            || compositingAncestorLayer->compositedLayerMapping()->paintsIntoCompositedAncestor());
-
-    m_requiresOwnBackingStoreForAncestorReasons = !canPaintIntoAncestor;
-    if (paintsIntoCompositedAncestor() != previousPaintsIntoCompositedAncestor) {
-        // Back out the change temporarily while invalidating with respect to the old container.
-        m_requiresOwnBackingStoreForAncestorReasons = !m_requiresOwnBackingStoreForAncestorReasons;
-        compositor()->paintInvalidationOnCompositingChange(&m_owningLayer);
-        m_requiresOwnBackingStoreForAncestorReasons = !m_requiresOwnBackingStoreForAncestorReasons;
-    }
-
-    return m_requiresOwnBackingStoreForAncestorReasons != previousRequiresOwnBackingStoreForAncestorReasons;
-}
-
-bool CompositedLayerMapping::updateRequiresOwnBackingStoreForIntrinsicReasons()
-{
-    unsigned previousRequiresOwnBackingStoreForIntrinsicReasons = m_requiresOwnBackingStoreForIntrinsicReasons;
-    bool previousPaintsIntoCompositedAncestor = paintsIntoCompositedAncestor();
-    RenderObject* renderer = m_owningLayer.renderer();
-    m_requiresOwnBackingStoreForIntrinsicReasons = m_owningLayer.isRootLayer()
-        || (m_owningLayer.compositingReasons() & CompositingReasonComboReasonsThatRequireOwnBacking)
-        || m_owningLayer.transform()
-        || m_owningLayer.clipsCompositingDescendantsWithBorderRadius() // FIXME: Revisit this if the paintsIntoCompositedAncestor state is removed.
-        || renderer->isTransparent()
-        || renderer->hasMask()
-        || renderer->hasReflection()
-        || renderer->hasFilter();
-
-    if (paintsIntoCompositedAncestor() != previousPaintsIntoCompositedAncestor) {
-        // Back out the change temporarily while invalidating with respect to the old container.
-        m_requiresOwnBackingStoreForIntrinsicReasons = !m_requiresOwnBackingStoreForIntrinsicReasons;
-        compositor()->paintInvalidationOnCompositingChange(&m_owningLayer);
-        m_requiresOwnBackingStoreForIntrinsicReasons = !m_requiresOwnBackingStoreForIntrinsicReasons;
-    }
-
-    return m_requiresOwnBackingStoreForIntrinsicReasons != previousRequiresOwnBackingStoreForIntrinsicReasons;
-}
-
 void CompositedLayerMapping::setBlendMode(WebBlendMode blendMode)
 {
     if (m_ancestorClippingLayer) {
@@ -2028,7 +1983,6 @@
 void CompositedLayerMapping::setContentsNeedDisplay()
 {
     // FIXME: need to split out paint invalidations for the background.
-    ASSERT(!paintsIntoCompositedAncestor());
     ApplyToGraphicsLayers(this, SetContentsNeedsDisplayFunctor(), ApplyToContentLayers);
 }
 
@@ -2050,8 +2004,6 @@
 void CompositedLayerMapping::setContentsNeedDisplayInRect(const LayoutRect& r, PaintInvalidationReason invalidationReason)
 {
     // FIXME: need to split out paint invalidations for the background.
-    ASSERT(!paintsIntoCompositedAncestor());
-
     SetContentsNeedsDisplayInRectFunctor functor = {
         pixelSnappedIntRect(r.location() + m_owningLayer.subpixelAccumulation(), r.size()),
         invalidationReason
@@ -2099,8 +2051,6 @@
 void CompositedLayerMapping::doPaintTask(const GraphicsLayerPaintInfo& paintInfo, const PaintLayerFlags& paintLayerFlags, GraphicsContext* context,
     const IntRect& clip) // In the coords of rootLayer.
 {
-    RELEASE_ASSERT(paintInfo.renderLayer->compositingState() == PaintsIntoGroupedBacking || !paintsIntoCompositedAncestor());
-
     FontCachePurgePreventer fontCachePurgePreventer;
 
     // Note carefully: in theory it is appropriate to invoke context->save() here
diff --git a/Source/core/rendering/compositing/CompositedLayerMapping.h b/Source/core/rendering/compositing/CompositedLayerMapping.h
index dae7e41..7565b18 100644
--- a/Source/core/rendering/compositing/CompositedLayerMapping.h
+++ b/Source/core/rendering/compositing/CompositedLayerMapping.h
@@ -116,19 +116,6 @@
     // Contains the bottommost layer in the hierarchy that can contain the children transform.
     GraphicsLayer* layerForChildrenTransform() const;
 
-    // Returns true for a composited layer that has no backing store of its own, so
-    // paints into some ancestor layer.
-    bool paintsIntoCompositedAncestor() const { return !(m_requiresOwnBackingStoreForAncestorReasons || m_requiresOwnBackingStoreForIntrinsicReasons); }
-
-    // Updates whether a backing store is needed based on the layer's compositing ancestor's
-    // properties; returns true if the need for a backing store for ancestor reasons changed.
-    bool updateRequiresOwnBackingStoreForAncestorReasons(const RenderLayer* compositingAncestor);
-
-    // Updates whether a backing store is needed for intrinsic reasons (that is, based on the
-    // layer's own properties or compositing reasons); returns true if the intrinsic need for
-    // a backing store changed.
-    bool updateRequiresOwnBackingStoreForIntrinsicReasons();
-
     void setSquashingContentsNeedDisplay();
     void setContentsNeedDisplay();
     // r is in the coordinate space of the layer's render object
@@ -421,8 +408,7 @@
 
     unsigned m_pendingUpdateScope : 2;
     unsigned m_isMainFrameRenderViewLayer : 1;
-    unsigned m_requiresOwnBackingStoreForIntrinsicReasons : 1;
-    unsigned m_requiresOwnBackingStoreForAncestorReasons : 1;
+
     unsigned m_backgroundLayerPaintsFixedRootBackground : 1;
     unsigned m_scrollingContentsAreEmpty : 1;
 };
diff --git a/Source/core/rendering/compositing/CompositingLayerAssigner.cpp b/Source/core/rendering/compositing/CompositingLayerAssigner.cpp
index e95e56e..44727ed 100644
--- a/Source/core/rendering/compositing/CompositingLayerAssigner.cpp
+++ b/Source/core/rendering/compositing/CompositingLayerAssigner.cpp
@@ -275,8 +275,8 @@
     }
 
     if (m_layerSquashingEnabled) {
-        // At this point, if the layer is to be "separately" composited, then its backing becomes the most recent in paint-order.
-        if (layer->compositingState() == PaintsIntoOwnBacking || layer->compositingState() == HasOwnBackingButPaintsIntoAncestor) {
+        // At this point, if the layer is to be separately composited, then its backing becomes the most recent in paint-order.
+        if (layer->compositingState() == PaintsIntoOwnBacking) {
             ASSERT(!requiresSquashing(layer->compositingReasons()));
             squashingState.updateSquashingStateForNewMapping(layer->compositedLayerMapping(), layer->hasCompositedLayerMapping());
         }
diff --git a/Source/core/rendering/compositing/CompositingState.h b/Source/core/rendering/compositing/CompositingState.h
index 9e2cb4b..b56514b 100644
--- a/Source/core/rendering/compositing/CompositingState.h
+++ b/Source/core/rendering/compositing/CompositingState.h
@@ -11,17 +11,11 @@
     // The layer paints into its enclosing composited ancestor.
     NotComposited = 0,
 
-    // The layer is composited, but its contents still paint into enclosing composited ancestor.
-    // In this state, paint invalidations must be sent to the enclosing composited ancestor.
-    // Typically this happens when a layer's properties need to be represented in the compositor
-    // output data structures, but it doesn't actually have any other reasons to be composited.
-    HasOwnBackingButPaintsIntoAncestor = 1,
-
-    PaintsIntoOwnBacking = 2,
+    PaintsIntoOwnBacking = 1,
 
     // In this state, the RenderLayer subtree paints into a backing that is shared by
     // several RenderLayer subtrees.
-    PaintsIntoGroupedBacking = 3
+    PaintsIntoGroupedBacking = 2
 };
 
 } // namespace blink
diff --git a/Source/core/rendering/compositing/GraphicsLayerUpdater.cpp b/Source/core/rendering/compositing/GraphicsLayerUpdater.cpp
index aa37e4a..709fe4a 100644
--- a/Source/core/rendering/compositing/GraphicsLayerUpdater.cpp
+++ b/Source/core/rendering/compositing/GraphicsLayerUpdater.cpp
@@ -97,12 +97,6 @@
             const RenderLayer* compositingContainer = context.compositingContainer(layer);
             ASSERT(compositingContainer == layer.enclosingLayerWithCompositedLayerMapping(ExcludeSelf));
 
-            if (mapping->updateRequiresOwnBackingStoreForAncestorReasons(compositingContainer)) {
-                TRACE_LAYER_INVALIDATION(&layer, InspectorLayerInvalidationTrackingEvent::AncestorRequiresNewLayer);
-                layersNeedingPaintInvalidation.append(&layer);
-                updateType = ForceUpdate;
-            }
-
             if (mapping->updateGraphicsLayerConfiguration())
                 m_needsRebuildTree = true;
 
diff --git a/Source/core/rendering/compositing/RenderLayerCompositor.cpp b/Source/core/rendering/compositing/RenderLayerCompositor.cpp
index 009eadc..7631e23 100644
--- a/Source/core/rendering/compositing/RenderLayerCompositor.cpp
+++ b/Source/core/rendering/compositing/RenderLayerCompositor.cpp
@@ -459,11 +459,6 @@
         break;
     }
 
-    if (layer->hasCompositedLayerMapping() && layer->compositedLayerMapping()->updateRequiresOwnBackingStoreForIntrinsicReasons()) {
-        compositedLayerMappingChanged = true;
-        layer->compositedLayerMapping()->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree);
-    }
-
     if (compositedLayerMappingChanged && layer->renderer()->isRenderPart()) {
         RenderLayerCompositor* innerCompositor = frameContentsCompositor(toRenderPart(layer->renderer()));
         if (innerCompositor && innerCompositor->staleInCompositingMode())
diff --git a/Source/modules/serviceworkers/Body.h b/Source/modules/serviceworkers/Body.h
index 6aa5d1c..d5b03b5 100644
--- a/Source/modules/serviceworkers/Body.h
+++ b/Source/modules/serviceworkers/Body.h
@@ -43,6 +43,9 @@
     ScriptPromise json(ScriptState*);
     ScriptPromise text(ScriptState*);
 
+    // Sets the bodyUsed flag to true. This signifies that the contents of the
+    // body have been consumed and cannot be accessed again.
+    void setBodyUsed();
     bool bodyUsed() const;
 
     // ActiveDOMObject override.
@@ -55,10 +58,6 @@
     // Copy constructor for clone() implementations
     explicit Body(const Body&);
 
-    // Sets the bodyUsed flag to true. This signifies that the contents of the
-    // body have been consumed and cannot be accessed again.
-    void setBodyUsed();
-
 private:
     ScriptPromise readAsync(ScriptState*, ResponseType);
     void resolveJSON();
diff --git a/Source/modules/serviceworkers/Cache.cpp b/Source/modules/serviceworkers/Cache.cpp
index a0c1a73..9f63334 100644
--- a/Source/modules/serviceworkers/Cache.cpp
+++ b/Source/modules/serviceworkers/Cache.cpp
@@ -315,13 +315,22 @@
     return promise;
 }
 
-ScriptPromise Cache::putImpl(ScriptState* scriptState, const Request* request, Response* response)
+ScriptPromise Cache::putImpl(ScriptState* scriptState, Request* request, Response* response)
 {
     KURL url(KURL(), request->url());
     if (!url.protocolIsInHTTPFamily())
         return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Request scheme '" + url.protocol() + "' is unsupported"));
     if (request->method() != "GET")
         return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Request method '" + request->method() + "' is unsupported"));
+    if (request->hasBody() && request->bodyUsed())
+        return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Request body is already used"));
+    if (response->hasBody() && response->bodyUsed())
+        return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Response body is already used"));
+
+    if (request->hasBody())
+        request->setBodyUsed();
+    if (response->hasBody())
+        response->setBodyUsed();
 
     WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1));
     batchOperations[0].operationType = WebServiceWorkerCache::OperationTypePut;
diff --git a/Source/modules/serviceworkers/Cache.h b/Source/modules/serviceworkers/Cache.h
index 444bbd1..0962771 100644
--- a/Source/modules/serviceworkers/Cache.h
+++ b/Source/modules/serviceworkers/Cache.h
@@ -58,7 +58,7 @@
     ScriptPromise addImpl(ScriptState*, const Request*);
     ScriptPromise addAllImpl(ScriptState*, const Vector<const Request*>);
     ScriptPromise deleteImpl(ScriptState*, const Request*, const CacheQueryOptions&);
-    ScriptPromise putImpl(ScriptState*, const Request*, Response*);
+    ScriptPromise putImpl(ScriptState*, Request*, Response*);
     ScriptPromise keysImpl(ScriptState*);
     ScriptPromise keysImpl(ScriptState*, const Request*, const CacheQueryOptions&);
 
diff --git a/Source/modules/serviceworkers/CacheTest.cpp b/Source/modules/serviceworkers/CacheTest.cpp
index 0520a4e..87fad73 100644
--- a/Source/modules/serviceworkers/CacheTest.cpp
+++ b/Source/modules/serviceworkers/CacheTest.cpp
@@ -398,7 +398,7 @@
 
     request = newRequestFromUrl(url);
     ASSERT(request);
-    ScriptPromise putResult = cache->put(scriptState(), request, response);
+    ScriptPromise putResult = cache->put(scriptState(), request, response->clone());
     EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCalled());
     EXPECT_EQ(kNotImplementedString, getRejectString(putResult));
 
diff --git a/Source/modules/serviceworkers/Request.h b/Source/modules/serviceworkers/Request.h
index 04283ba..9448ffc 100644
--- a/Source/modules/serviceworkers/Request.h
+++ b/Source/modules/serviceworkers/Request.h
@@ -49,6 +49,7 @@
     void populateWebServiceWorkerRequest(WebServiceWorkerRequest&) const;
 
     void setBodyBlobHandle(PassRefPtr<BlobDataHandle>);
+    bool hasBody() const { return m_request->blobDataHandle(); }
 
     virtual void trace(Visitor*)  override;
 
diff --git a/Source/modules/serviceworkers/Response.h b/Source/modules/serviceworkers/Response.h
index 65d89ba..5ef005e 100644
--- a/Source/modules/serviceworkers/Response.h
+++ b/Source/modules/serviceworkers/Response.h
@@ -49,6 +49,8 @@
 
     void populateWebServiceWorkerResponse(WebServiceWorkerResponse&);
 
+    bool hasBody() const { return m_response->blobDataHandle(); }
+
     virtual void trace(Visitor*) override;
 
 private:
diff --git a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
index 8263534..4ced420 100644
--- a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
@@ -121,6 +121,12 @@
         return promise;
     }
 
+    KURL pageURL = KURL(KURL(), documentOrigin->toString());
+    if (!pageURL.protocolIsInHTTPFamily()) {
+        resolver->reject(DOMException::create(SecurityError, "The URL protocol of the current origin is not supported: " + pageURL.protocol()));
+        return promise;
+    }
+
     KURL patternURL = executionContext->completeURL(options.scope());
     patternURL.removeFragmentIdentifier();
     if (!documentOrigin->canRequest(patternURL)) {
@@ -174,6 +180,12 @@
         return promise;
     }
 
+    KURL pageURL = KURL(KURL(), documentOrigin->toString());
+    if (!pageURL.protocolIsInHTTPFamily()) {
+        resolver->reject(DOMException::create(SecurityError, "The URL protocol of the current origin is not supported: " + pageURL.protocol()));
+        return promise;
+    }
+
     KURL completedURL = executionContext->completeURL(documentURL);
     completedURL.removeFragmentIdentifier();
     if (!documentOrigin->canRequest(completedURL)) {
diff --git a/Source/platform/fonts/Font.cpp b/Source/platform/fonts/Font.cpp
index bc22d60..2bfc2c6 100644
--- a/Source/platform/fonts/Font.cpp
+++ b/Source/platform/fonts/Font.cpp
@@ -749,19 +749,19 @@
     return markFontData->fontMetrics().height();
 }
 
-static SkPaint textFillPaint(GraphicsContext* gc, const SimpleFontData* font)
+SkPaint Font::textFillPaint(GraphicsContext* gc, const SimpleFontData* font) const
 {
     SkPaint paint = gc->fillPaint();
-    font->platformData().setupPaint(&paint, gc);
+    font->platformData().setupPaint(&paint, gc, this);
     gc->adjustTextRenderMode(&paint);
     paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
     return paint;
 }
 
-static SkPaint textStrokePaint(GraphicsContext* gc, const SimpleFontData* font, bool isFilling)
+SkPaint Font::textStrokePaint(GraphicsContext* gc, const SimpleFontData* font, bool isFilling) const
 {
     SkPaint paint = gc->strokePaint();
-    font->platformData().setupPaint(&paint, gc);
+    font->platformData().setupPaint(&paint, gc, this);
     gc->adjustTextRenderMode(&paint);
     paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
     if (isFilling) {
@@ -779,9 +779,9 @@
     return paint;
 }
 
-static void paintGlyphs(GraphicsContext* gc, const SimpleFontData* font,
+void Font::paintGlyphs(GraphicsContext* gc, const SimpleFontData* font,
     const Glyph glyphs[], unsigned numGlyphs,
-    const SkPoint pos[], const FloatRect& textRect)
+    const SkPoint pos[], const FloatRect& textRect) const
 {
     TextDrawingModeFlags textMode = gc->textDrawingMode();
 
@@ -797,9 +797,9 @@
     }
 }
 
-static void paintGlyphsHorizontal(GraphicsContext* gc, const SimpleFontData* font,
+void Font::paintGlyphsHorizontal(GraphicsContext* gc, const SimpleFontData* font,
     const Glyph glyphs[], unsigned numGlyphs,
-    const SkScalar xpos[], SkScalar constY, const FloatRect& textRect)
+    const SkScalar xpos[], SkScalar constY, const FloatRect& textRect) const
 {
     TextDrawingModeFlags textMode = gc->textDrawingMode();
 
diff --git a/Source/platform/fonts/Font.h b/Source/platform/fonts/Font.h
index 33c1612..2c21fcc 100644
--- a/Source/platform/fonts/Font.h
+++ b/Source/platform/fonts/Font.h
@@ -141,6 +141,13 @@
     float buildGlyphBuffer(const TextRunPaintInfo&, GlyphBuffer&, ForTextEmphasisOrNot = NotForTextEmphasis) const;
     PassTextBlobPtr buildTextBlob(const GlyphBuffer&, float initialAdvance, const FloatRect& bounds,
         bool couldUseLCD) const;
+
+    SkPaint textFillPaint(GraphicsContext*, const SimpleFontData*) const;
+    SkPaint textStrokePaint(GraphicsContext*, const SimpleFontData*, bool isFilling) const;
+    void paintGlyphs(GraphicsContext*, const SimpleFontData*, const Glyph glyphs[], unsigned numGlyphs,
+        const SkPoint pos[], const FloatRect& textRect) const;
+    void paintGlyphsHorizontal(GraphicsContext*, const SimpleFontData*, const Glyph glyphs[], unsigned numGlyphs,
+        const SkScalar xpos[], SkScalar constY, const FloatRect& textRect) const;
     void drawGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, unsigned from, unsigned numGlyphs, const FloatPoint&, const FloatRect& textRect) const;
     void drawTextBlob(GraphicsContext*, const SkTextBlob*, const SkPoint& origin) const;
     float drawGlyphBuffer(GraphicsContext*, const TextRunPaintInfo&, const GlyphBuffer&, const FloatPoint&) const;
diff --git a/Source/platform/fonts/FontPlatformData.h b/Source/platform/fonts/FontPlatformData.h
index 1a44b36..51ed7a6 100644
--- a/Source/platform/fonts/FontPlatformData.h
+++ b/Source/platform/fonts/FontPlatformData.h
@@ -62,6 +62,7 @@
 
 namespace blink {
 
+class Font;
 class GraphicsContext;
 class HarfBuzzFace;
 
@@ -143,7 +144,7 @@
     // The returned styles are all actual styles without FontRenderStyle::NoPreference.
     const FontRenderStyle& fontRenderStyle() const { return m_style; }
 #endif
-    void setupPaint(SkPaint*, GraphicsContext* = 0) const;
+    void setupPaint(SkPaint*, GraphicsContext* = 0, const Font* = 0) const;
 
 #if OS(WIN)
     int paintTextFlags() const { return m_paintTextFlags; }
diff --git a/Source/platform/fonts/linux/FontPlatformDataLinux.cpp b/Source/platform/fonts/linux/FontPlatformDataLinux.cpp
index 0191a3d..a4eb172 100644
--- a/Source/platform/fonts/linux/FontPlatformDataLinux.cpp
+++ b/Source/platform/fonts/linux/FontPlatformDataLinux.cpp
@@ -72,8 +72,7 @@
     useSkiaSubpixelRendering = useSubpixelRendering;
 }
 
-void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext* context)
-    const
+void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext* context, const Font*) const
 {
     paint->setAntiAlias(m_style.useAntiAlias);
     paint->setHinting(static_cast<SkPaint::Hinting>(m_style.hintStyle));
diff --git a/Source/platform/fonts/mac/FontPlatformDataMac.mm b/Source/platform/fonts/mac/FontPlatformDataMac.mm
index 833692d..8fd334b 100644
--- a/Source/platform/fonts/mac/FontPlatformDataMac.mm
+++ b/Source/platform/fonts/mac/FontPlatformDataMac.mm
@@ -30,6 +30,7 @@
 
 #include "platform/LayoutTestSupport.h"
 #include "platform/RuntimeEnabledFeatures.h"
+#include "platform/fonts/Font.h"
 #import "platform/fonts/shaping/HarfBuzzFace.h"
 #include "third_party/skia/include/ports/SkTypeface_mac.h"
 
@@ -44,7 +45,7 @@
     return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
 }
 
-void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*) const
+void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*, const Font* font) const
 {
     bool shouldSmoothFonts = true;
     bool shouldAntialias = true;
@@ -61,10 +62,14 @@
     paint->setTypeface(typeface());
     paint->setFakeBoldText(m_syntheticBold);
     paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0);
-    paint->setAutohinted(false); // freetype specific
     paint->setLCDRenderText(shouldSmoothFonts);
     paint->setSubpixelText(useSubpixelText);
-    paint->setHinting(SkPaint::kNo_Hinting);
+
+    // When rendering using CoreGraphics, disable hinting when webkit-font-smoothing:antialiased or
+    // text-rendering:geometricPrecision is used.
+    // See crbug.com/152304
+    if (font && (font->fontDescription().fontSmoothing() == Antialiased || font->fontDescription().textRendering() == GeometricPrecision))
+        paint->setHinting(SkPaint::kNo_Hinting);
 }
 
 // These CoreText Text Spacing feature selectors are not defined in CoreText.
diff --git a/Source/platform/fonts/win/FontPlatformDataWin.cpp b/Source/platform/fonts/win/FontPlatformDataWin.cpp
index 621e252..50fc655 100644
--- a/Source/platform/fonts/win/FontPlatformDataWin.cpp
+++ b/Source/platform/fonts/win/FontPlatformDataWin.cpp
@@ -44,7 +44,7 @@
 // if available.
 const float kMaxSizeForEmbeddedBitmap = 24.0f;
 
-void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext* context) const
+void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext* context, const Font*) const
 {
     const float ts = m_textSize >= 0 ? m_textSize : 12;
     paint->setTextSize(SkFloatToScalar(m_textSize));
diff --git a/Source/web/LinkHighlight.cpp b/Source/web/LinkHighlight.cpp
index 5e16b12..cebb4c1 100644
--- a/Source/web/LinkHighlight.cpp
+++ b/Source/web/LinkHighlight.cpp
@@ -40,7 +40,6 @@
 #include "core/rendering/compositing/CompositedLayerMapping.h"
 #include "core/rendering/style/ShadowData.h"
 #include "platform/graphics/Color.h"
-#include "platform/graphics/DisplayList.h"
 #include "public/platform/Platform.h"
 #include "public/platform/WebCompositorAnimationCurve.h"
 #include "public/platform/WebCompositorSupport.h"
@@ -228,13 +227,6 @@
     bool pathHasChanged = !(newPath == m_path);
     if (pathHasChanged) {
         m_path = newPath;
-
-        GraphicsContext gc(0);
-        gc.beginRecording(boundingRect);
-        gc.setFillColor(m_node->renderer()->style()->tapHighlightColor());
-        gc.fillPath(m_path);
-        m_displayList = gc.endRecording();
-
         m_contentLayer->layer()->setBounds(enclosingIntRect(boundingRect).size());
     }
 
@@ -251,8 +243,9 @@
     GraphicsContext gc(canvas,
         contextStatus == WebContentLayerClient::GraphicsContextEnabled ? GraphicsContext::NothingDisabled : GraphicsContext::FullyDisabled);
     IntRect clipRect(IntPoint(webClipRect.x, webClipRect.y), IntSize(webClipRect.width, webClipRect.height));
-    m_displayList->setClip(clipRect);
-    gc.drawDisplayList(m_displayList.get());
+    gc.clip(clipRect);
+    gc.setFillColor(m_node->renderer()->style()->tapHighlightColor());
+    gc.fillPath(m_path);
 }
 
 void LinkHighlight::startHighlightAnimationIfNeeded()
diff --git a/Source/web/LinkHighlight.h b/Source/web/LinkHighlight.h
index 6fbd3de..4fc79aa 100644
--- a/Source/web/LinkHighlight.h
+++ b/Source/web/LinkHighlight.h
@@ -39,7 +39,6 @@
 
 namespace blink {
 
-class DisplayList;
 class Node;
 class RenderLayerModelObject;
 struct WebRect;
@@ -84,7 +83,6 @@
     OwnPtr<WebContentLayer> m_contentLayer;
     OwnPtr<WebLayer> m_clipLayer;
     Path m_path;
-    RefPtr<DisplayList> m_displayList;
 
     RefPtrWillBePersistent<Node> m_node;
     WebViewImpl* m_owningWebViewImpl;