Cherry-pick: Set fullscreenEnabled to false when fullscreen is not supported.

NOTE: This cherry-pick will only be landed after
https://googleplex-android-review.git.corp.google.com/#/c/523938/

According to the latest version of the living standard,
fullscreenEnabled must be false if fullscreen is not supported:
http://fullscreen.spec.whatwg.org/

More details about the latest update to the standard:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=26479
https://github.com/whatwg/fullscreen/commit/d35a070d443632d0071b49318e40092667ac9801

Review URL: https://codereview.chromium.org/426593010

git-svn-id: svn://svn.chromium.org/blink/trunk@179520 bbb929c8-8fbe-4397-9dbb-9b2b20218538

Conflicts:
	Source/core/dom/FullscreenElementStack.cpp

Change-Id: If1c49841101721293de558b649a8a93c6f2772fc
diff --git a/LayoutTests/fullscreen/full-screen-not-enabled-when-unsupported-expected.txt b/LayoutTests/fullscreen/full-screen-not-enabled-when-unsupported-expected.txt
new file mode 100644
index 0000000..aebe249
--- /dev/null
+++ b/LayoutTests/fullscreen/full-screen-not-enabled-when-unsupported-expected.txt
@@ -0,0 +1,5 @@
+This tests that the fullscreenEnabled property is false when fullscreen is not supported as laid out in section 4 of the Fullscreen API living standard
+EXPECTED (document.webkitFullscreenEnabled == 'false') OK
+EXPECTED (iframe.contentDocument.webkitFullscreenEnabled == 'false') OK
+END OF TEST
+
diff --git a/LayoutTests/fullscreen/full-screen-not-enabled-when-unsupported.html b/LayoutTests/fullscreen/full-screen-not-enabled-when-unsupported.html
new file mode 100644
index 0000000..b173011
--- /dev/null
+++ b/LayoutTests/fullscreen/full-screen-not-enabled-when-unsupported.html
@@ -0,0 +1,17 @@
+<body>
+<div>This tests that the <code>fullscreenEnabled</code> property is false when fullscreen
+is not supported as laid out in section 4 of the 
+<a href="http://fullscreen.spec.whatwg.org/#api">Fullscreen API</a> living
+standard</div>
+<script src="full-screen-test.js"></script>
+<script>
+    window.internals.settings.setFullscreenSupported(false);
+    
+    testExpected('document.webkitFullscreenEnabled', false);
+
+    var iframe = document.documentElement.appendChild(document.createElement('iframe'));
+    iframe.setAttribute('allowfullscreen', 'true');
+    testExpected('iframe.contentDocument.webkitFullscreenEnabled', false);
+    endTest();
+</script>
+</body>
\ No newline at end of file
diff --git a/Source/core/dom/FullscreenElementStack.cpp b/Source/core/dom/FullscreenElementStack.cpp
index 80d76c5..cac4230 100644
--- a/Source/core/dom/FullscreenElementStack.cpp
+++ b/Source/core/dom/FullscreenElementStack.cpp
@@ -62,6 +62,20 @@
     return true;
 }
 
+static bool fullscreenIsSupported(const Document& document)
+{
+    // Fullscreen is supported if there is no previously-established user preference,
+    // security risk, or platform limitation.
+    return document.settings()->fullscreenSupported();
+}
+
+static bool fullscreenIsSupported(const Document& document, const Element& element)
+{
+    if (document.settings()->disallowFullscreenForNonMediaElements() && !isHTMLMediaElement(element))
+        return false;
+    return fullscreenIsSupported(document);
+}
+
 const char* FullscreenElementStack::supplementName()
 {
     return "FullscreenElementStack";
@@ -210,10 +224,8 @@
         if (!UserGestureIndicator::processingUserGesture())
             break;
 
-        // There is a previously-established user preference, security risk, or platform limitation.
-        if (!document()->settings()->fullscreenSupported())
-            break;
-        if (document()->settings()->disallowFullscreenForNonMediaElements() && !isHTMLMediaElement(element))
+        // Fullscreen is not supported.
+        if (document() && !fullscreenIsSupported(*document(), *element))
             break;
 
         // 2. Let doc be element's node document. (i.e. "this")
@@ -377,11 +389,11 @@
 
 bool FullscreenElementStack::webkitFullscreenEnabled(Document& document)
 {
-    // 4. The fullscreenEnabled attribute must return true if the context object and all ancestor
-    // browsing context's documents have their fullscreen enabled flag set, or false otherwise.
+    // 4. The fullscreenEnabled attribute must return true if the context object has its
+    //    fullscreen enabled flag set and fullscreen is supported, and false otherwise.
 
     // Top-level browsing contexts are implied to have their allowFullScreen attribute set.
-    return fullscreenIsAllowedForAllOwners(document);
+    return fullscreenIsAllowedForAllOwners(document) && fullscreenIsSupported(document);
 }
 
 void FullscreenElementStack::webkitWillEnterFullScreenForElement(Element* element)