| Index: third_party/WebKit/Source/web/FullscreenController.cpp | 
| diff --git a/third_party/WebKit/Source/web/FullscreenController.cpp b/third_party/WebKit/Source/web/FullscreenController.cpp | 
| index cb8efeffd7bb3e843c17fa3f5debc2591e0afc5f..43de61c60785182df5bbe64b4ece6678b576d16e 100644 | 
| --- a/third_party/WebKit/Source/web/FullscreenController.cpp | 
| +++ b/third_party/WebKit/Source/web/FullscreenController.cpp | 
| @@ -37,8 +37,6 @@ | 
| #include "core/frame/PageScaleConstraintsSet.h" | 
| #include "core/html/HTMLMediaElement.h" | 
| #include "core/html/HTMLVideoElement.h" | 
| -#include "core/layout/LayoutFullScreen.h" | 
| -#include "platform/RuntimeEnabledFeatures.h" | 
| #include "public/platform/WebLayerTreeView.h" | 
| #include "public/web/WebFrameClient.h" | 
| #include "web/WebLocalFrameImpl.h" | 
| @@ -59,14 +57,7 @@ FullscreenController::FullscreenController(WebViewImpl* webViewImpl) | 
| m_isCancelingFullscreen(false) {} | 
|  | 
| void FullscreenController::didEnterFullscreen() { | 
| -  if (!m_provisionalFullscreenElement) | 
| -    return; | 
| - | 
| -  Element* element = m_provisionalFullscreenElement.release(); | 
| -  Document& document = element->document(); | 
| -  m_fullscreenFrame = document.frame(); | 
| - | 
| -  if (!m_fullscreenFrame) | 
| +  if (m_pendingFullscreenElements.isEmpty()) | 
| return; | 
|  | 
| if (!m_haveEnteredFullscreen) { | 
| @@ -78,14 +69,22 @@ void FullscreenController::didEnterFullscreen() { | 
| m_haveEnteredFullscreen = true; | 
| } | 
|  | 
| -  Fullscreen::from(document).didEnterFullscreenForElement(element); | 
| -  DCHECK_EQ(Fullscreen::currentFullScreenElementFrom(document), element); | 
| - | 
| -  if (isHTMLVideoElement(element)) { | 
| -    HTMLVideoElement* videoElement = toHTMLVideoElement(element); | 
| -    if (videoElement->usesOverlayFullscreenVideo() && | 
| -        m_webViewImpl->layerTreeView()) | 
| -      m_webViewImpl->layerTreeView()->setHasTransparentBackground(true); | 
| +  // TODO(foolip): Unprefixed requests | 
| +  HeapVector<Member<Element>> pendingFullscreenElements; | 
| +  pendingFullscreenElements.swap(m_pendingFullscreenElements); | 
| + | 
| +  for (Element* element : pendingFullscreenElements) { | 
| +    Fullscreen::didEnterFullscreenForElement(*element, | 
| +                                             Fullscreen::PrefixedRequest); | 
| + | 
| +    // TODO(foolip): this and the exit stuff has to be synced with animation | 
| +    // frames tasks too | 
| +    if (isHTMLVideoElement(element)) { | 
| +      HTMLVideoElement* videoElement = toHTMLVideoElement(element); | 
| +      if (videoElement->usesOverlayFullscreenVideo() && | 
| +          m_webViewImpl->layerTreeView()) | 
| +        m_webViewImpl->layerTreeView()->setHasTransparentBackground(true); | 
| +    } | 
| } | 
| } | 
|  | 
| @@ -97,30 +96,28 @@ void FullscreenController::didExitFullscreen() { | 
| updatePageScaleConstraints(true); | 
|  | 
| if (Document* document = m_fullscreenFrame->document()) { | 
| -    if (Fullscreen* fullscreen = Fullscreen::fromIfExists(*document)) { | 
| -      Element* element = fullscreen->currentFullScreenElement(); | 
| -      if (element) { | 
| -        // When the client exits from full screen we have to call | 
| -        // fullyExitFullscreen to notify the document. While doing that, | 
| -        // suppress notifications back to the client. | 
| -        m_isCancelingFullscreen = true; | 
| -        Fullscreen::fullyExitFullscreen(*document); | 
| -        m_isCancelingFullscreen = false; | 
| - | 
| -        // If the video used overlay fullscreen mode, the background was made | 
| -        // transparent. Restore the transparency. | 
| -        if (isHTMLVideoElement(element) && m_webViewImpl->layerTreeView()) | 
| -          m_webViewImpl->layerTreeView()->setHasTransparentBackground( | 
| -              m_webViewImpl->isTransparent()); | 
| - | 
| -        // We need to wait until style and layout are updated in order | 
| -        // to propertly restore scroll offsets since content may not be | 
| -        // overflowing in the same way until they do. | 
| -        if (m_haveEnteredFullscreen) | 
| -          m_needsScrollAndScaleRestore = true; | 
| - | 
| -        fullscreen->didExitFullscreen(); | 
| +    if (Element* element = Fullscreen::fullscreenElement(*document)) { | 
| +      // When the client exits from full screen we have to call | 
| +      // fullyExitFullscreen to notify the document. While doing that, suppress | 
| +      // notifications back to the client. | 
| +      m_isCancelingFullscreen = true; | 
| +      Fullscreen::fullyExitFullscreen(*document); | 
| +      m_isCancelingFullscreen = false; | 
| + | 
| +      // If the video used overlay fullscreen mode, the background was made | 
| +      // transparent. Restore the transparency. | 
| +      if (isHTMLVideoElement(element) && m_webViewImpl->layerTreeView()) { | 
| +        m_webViewImpl->layerTreeView()->setHasTransparentBackground( | 
| +            m_webViewImpl->isTransparent()); | 
| } | 
| + | 
| +      // We need to wait until style and layout are updated in order | 
| +      // to propertly restore scroll offsets since content may not be | 
| +      // overflowing in the same way until they do. | 
| +      if (m_haveEnteredFullscreen) | 
| +        m_needsScrollAndScaleRestore = true; | 
| + | 
| +      Fullscreen::didExitFullscreen(*document); | 
| } | 
| } | 
|  | 
| @@ -129,15 +126,10 @@ void FullscreenController::didExitFullscreen() { | 
| } | 
|  | 
| void FullscreenController::enterFullscreenForElement(Element* element) { | 
| -  // We are already transitioning to fullscreen for a different element. | 
| -  if (m_provisionalFullscreenElement) { | 
| -    m_provisionalFullscreenElement = element; | 
| -    return; | 
| -  } | 
| +  m_pendingFullscreenElements.append(element); | 
|  | 
| // We are already in fullscreen mode. | 
| if (m_fullscreenFrame) { | 
| -    m_provisionalFullscreenElement = element; | 
| didEnterFullscreen(); | 
| return; | 
| } | 
| @@ -161,15 +153,23 @@ void FullscreenController::enterFullscreenForElement(Element* element) { | 
| WebLocalFrameImpl* frame = | 
| WebLocalFrameImpl::fromFrame(element->document().frame()); | 
| if (frame && frame->client()) { | 
| -    if (!Fullscreen::from(element->document()).forCrossProcessDescendant()) | 
| -      frame->client()->enterFullscreen(); | 
| -    m_provisionalFullscreenElement = element; | 
| +    frame->client()->enterFullscreen(); | 
| +  } else { | 
| +    // TODO(foolip): now what? | 
| +    DCHECK(0); | 
| } | 
| } | 
|  | 
| void FullscreenController::exitFullscreenForElement(Element* element) { | 
| DCHECK(element); | 
|  | 
| +  // TODO(dsinclair): This should not be needed because we addToTopLayer | 
| +  // in Fullscreen::popFullscreenElementStack but, the WebView code doesn't | 
| +  // call Fullscreen::requestFullscreen() and, instead, just enters and | 
| +  // exists itself. This should be unified so there is one way to go | 
| +  // fullscreen.  crbug.com/538158 | 
| +  element->document().removeFromTopLayer(element); | 
| + | 
| // The client is exiting full screen, so don't send a notification. | 
| if (m_isCancelingFullscreen) | 
| return; | 
| @@ -186,10 +186,9 @@ void FullscreenController::updateSize() { | 
|  | 
| updatePageScaleConstraints(false); | 
|  | 
| -  LayoutFullScreen* layoutObject = | 
| -      Fullscreen::from(*m_fullscreenFrame->document()).fullScreenLayoutObject(); | 
| -  if (layoutObject) | 
| -    layoutObject->updateStyle(); | 
| +  Document* document = m_fullscreenFrame->document(); | 
| +  if (Element* fullscreenElement = Fullscreen::fullscreenElement(*document)) | 
| +    Fullscreen::didUpdateSize(*fullscreenElement); | 
| } | 
|  | 
| void FullscreenController::didUpdateLayout() { | 
| @@ -235,7 +234,7 @@ void FullscreenController::updatePageScaleConstraints(bool removeConstraints) { | 
| } | 
|  | 
| DEFINE_TRACE(FullscreenController) { | 
| -  visitor->trace(m_provisionalFullscreenElement); | 
| +  visitor->trace(m_pendingFullscreenElements); | 
| visitor->trace(m_fullscreenFrame); | 
| } | 
|  | 
|  |