<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[163048] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/163048">163048</a></dd>
<dt>Author</dt> <dd>weinig@apple.com</dd>
<dt>Date</dt> <dd>2014-01-29 16:35:31 -0800 (Wed, 29 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>CaptionUserPreferences should not be on the PageGroup if they are not really per-PageGroup (Part 1)
https://bugs.webkit.org/show_bug.cgi?id=127666

Reviewed by Eric Carlson.

This patch:
- Makes CaptionUserPreferences a singleton (temporary) that is accessed
  via Page.
- Simplifies overriding system preferences by requiring that a Document be
  be passed so the correct Settings object can be obtained (and not just a 
  random one).
- Stops using UserStyleSheets for captions style injection, and instead
  adds a new style sheet to the DocumentStyleSheetCollection.
- Move caption style sheet creation into its own file - CaptionStyleSheetMediaAF.h/cpp

* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
Add new files.

* WebCore.exp.in:
Update exports.

* css/DocumentRuleSets.cpp:
* css/InspectorCSSOMWrappers.cpp:
* dom/Document.cpp:
* dom/DocumentStyleSheetCollection.cpp:
* dom/DocumentStyleSheetCollection.h:
Switch from using the user style sheet mechanism, which is meant for, you guessed it, users,
to an explicit caption style sheet.

* Modules/mediacontrols/MediaControlsHost.cpp:
* html/HTMLMediaElement.cpp:
* html/shadow/MediaControlElements.cpp:
Get the CaptionUserPreferences via the Page.

* page/CaptionStyleSheetMediaAF.cpp: Added.
* page/CaptionStyleSheetMediaAF.h: Added.
Move caption style sheet creation here. If the global style changes, the sheet is invalidated
and this is called again.

* page/CaptionUserPreferences.cpp:
* page/CaptionUserPreferences.h:
- Removes unused m_havePreferences member.
- Change userPrefersFoo() functions to take a Document&amp;. Use it to check its Settings.
- Remove setUserPrefersFoo() functions and just set the Settings directly.
- Move all the testing only pieces together.
        
* page/CaptionUserPreferencesMediaAF.cpp:
* page/CaptionUserPreferencesMediaAF.h:
- Extract caption style sheet creation into CaptionStyleSheetMediaAF.h/cpp
- Stop waiting for an interested party, and just register for appearance change
  notifications right away. Media elements are common enough that this should not
  make a difference.

* page/Page.cpp:
(WebCore::Page::updateStyleForAllPagesForCaptionPreferencesChanged):
Add helper to call captionPreferencesChanged() on all the Pages.

(WebCore::Page::captionPreferences):
Add accessor for the CaptionUserPreferences. Currently this returns a singleton, but I plan
to extract the singleton aspects of it into another class, and leave the per-Page parts here.

* page/Page.h:
* page/PageGroup.cpp:
* page/PageGroup.h:
Remove CaptionUserPreferences from here.

* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setShouldDisplayTrackKind):
(WebCore::InternalSettings::shouldDisplayTrackKind):
Override the settings for the page directly.

* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState):
(WebCore::Internals::Internals):
(WebCore::Internals::captionsStyleSheetOverride):
(WebCore::Internals::setCaptionsStyleSheetOverride):
(WebCore::Internals::setPrimaryAudioTrackLanguageOverride):
(WebCore::Internals::setCaptionDisplayMode):
Get the CaptionUserPreferences via the Page.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediacontrolsMediaControlsHostcpp">trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxproj">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorecssDocumentRuleSetscpp">trunk/Source/WebCore/css/DocumentRuleSets.cpp</a></li>
<li><a href="#trunkSourceWebCorecssInspectorCSSOMWrapperscpp">trunk/Source/WebCore/css/InspectorCSSOMWrappers.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumentStyleSheetCollectioncpp">trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumentStyleSheetCollectionh">trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlshadowMediaControlElementscpp">trunk/Source/WebCore/html/shadow/MediaControlElements.cpp</a></li>
<li><a href="#trunkSourceWebCorepageCaptionUserPreferencescpp">trunk/Source/WebCore/page/CaptionUserPreferences.cpp</a></li>
<li><a href="#trunkSourceWebCorepageCaptionUserPreferencesh">trunk/Source/WebCore/page/CaptionUserPreferences.h</a></li>
<li><a href="#trunkSourceWebCorepageCaptionUserPreferencesMediaAFcpp">trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp</a></li>
<li><a href="#trunkSourceWebCorepageCaptionUserPreferencesMediaAFh">trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h</a></li>
<li><a href="#trunkSourceWebCorepagePagecpp">trunk/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageh">trunk/Source/WebCore/page/Page.h</a></li>
<li><a href="#trunkSourceWebCorepagePageGroupcpp">trunk/Source/WebCore/page/PageGroup.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageGrouph">trunk/Source/WebCore/page/PageGroup.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalSettingscpp">trunk/Source/WebCore/testing/InternalSettings.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorepageCaptionStyleSheetMediaAFcpp">trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.cpp</a></li>
<li><a href="#trunkSourceWebCorepageCaptionStyleSheetMediaAFh">trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/ChangeLog        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -1,3 +1,87 @@
</span><ins>+2014-01-26  Sam Weinig  &lt;sam@webkit.org&gt;
+
+        CaptionUserPreferences should not be on the PageGroup if they are not really per-PageGroup (Part 1)
+        https://bugs.webkit.org/show_bug.cgi?id=127666
+
+        Reviewed by Eric Carlson.
+
+        This patch:
+        - Makes CaptionUserPreferences a singleton (temporary) that is accessed
+          via Page.
+        - Simplifies overriding system preferences by requiring that a Document be
+          be passed so the correct Settings object can be obtained (and not just a 
+          random one).
+        - Stops using UserStyleSheets for captions style injection, and instead
+          adds a new style sheet to the DocumentStyleSheetCollection.
+        - Move caption style sheet creation into its own file - CaptionStyleSheetMediaAF.h/cpp
+
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * WebCore.xcodeproj/project.pbxproj:
+        Add new files.
+
+        * WebCore.exp.in:
+        Update exports.
+
+        * css/DocumentRuleSets.cpp:
+        * css/InspectorCSSOMWrappers.cpp:
+        * dom/Document.cpp:
+        * dom/DocumentStyleSheetCollection.cpp:
+        * dom/DocumentStyleSheetCollection.h:
+        Switch from using the user style sheet mechanism, which is meant for, you guessed it, users,
+        to an explicit caption style sheet.
+
+        * Modules/mediacontrols/MediaControlsHost.cpp:
+        * html/HTMLMediaElement.cpp:
+        * html/shadow/MediaControlElements.cpp:
+        Get the CaptionUserPreferences via the Page.
+
+        * page/CaptionStyleSheetMediaAF.cpp: Added.
+        * page/CaptionStyleSheetMediaAF.h: Added.
+        Move caption style sheet creation here. If the global style changes, the sheet is invalidated
+        and this is called again.
+
+        * page/CaptionUserPreferences.cpp:
+        * page/CaptionUserPreferences.h:
+        - Removes unused m_havePreferences member.
+        - Change userPrefersFoo() functions to take a Document&amp;. Use it to check its Settings.
+        - Remove setUserPrefersFoo() functions and just set the Settings directly.
+        - Move all the testing only pieces together.
+        
+        * page/CaptionUserPreferencesMediaAF.cpp:
+        * page/CaptionUserPreferencesMediaAF.h:
+        - Extract caption style sheet creation into CaptionStyleSheetMediaAF.h/cpp
+        - Stop waiting for an interested party, and just register for appearance change
+          notifications right away. Media elements are common enough that this should not
+          make a difference.
+
+        * page/Page.cpp:
+        (WebCore::Page::updateStyleForAllPagesForCaptionPreferencesChanged):
+        Add helper to call captionPreferencesChanged() on all the Pages.
+
+        (WebCore::Page::captionPreferences):
+        Add accessor for the CaptionUserPreferences. Currently this returns a singleton, but I plan
+        to extract the singleton aspects of it into another class, and leave the per-Page parts here.
+
+        * page/Page.h:
+        * page/PageGroup.cpp:
+        * page/PageGroup.h:
+        Remove CaptionUserPreferences from here.
+
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::setShouldDisplayTrackKind):
+        (WebCore::InternalSettings::shouldDisplayTrackKind):
+        Override the settings for the page directly.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::resetToConsistentState):
+        (WebCore::Internals::Internals):
+        (WebCore::Internals::captionsStyleSheetOverride):
+        (WebCore::Internals::setCaptionsStyleSheetOverride):
+        (WebCore::Internals::setPrimaryAudioTrackLanguageOverride):
+        (WebCore::Internals::setCaptionDisplayMode):
+        Get the CaptionUserPreferences via the Page.
+
</ins><span class="cx"> 2014-01-29  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [MSE][Mac] In SourceBufferPrivateAVFObjC, only include those headers actually necessary to compile.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediacontrolsMediaControlsHostcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -82,8 +82,7 @@
</span><span class="cx">     if (!page)
</span><span class="cx">         return Vector&lt;RefPtr&lt;TextTrack&gt;&gt;();
</span><span class="cx"> 
</span><del>-    CaptionUserPreferences* captionPreferences = page-&gt;group().captionPreferences();
-    return captionPreferences-&gt;sortedTrackListForMenu(trackList);
</del><ins>+    return page-&gt;captionPreferences().sortedTrackListForMenu(trackList);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String MediaControlsHost::displayNameForTrack(TextTrack* track)
</span><span class="lines">@@ -95,8 +94,7 @@
</span><span class="cx">     if (!page)
</span><span class="cx">         return emptyString();
</span><span class="cx"> 
</span><del>-    CaptionUserPreferences* captionPreferences = page-&gt;group().captionPreferences();
-    return captionPreferences-&gt;displayNameForTrack(track);
</del><ins>+    return page-&gt;captionPreferences().displayNameForTrack(track);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TextTrack* MediaControlsHost::captionMenuOffItem()
</span><span class="lines">@@ -115,7 +113,7 @@
</span><span class="cx">     if (!page)
</span><span class="cx">         return emptyAtom;
</span><span class="cx"> 
</span><del>-    switch (page-&gt;group().captionPreferences()-&gt;captionDisplayMode()) {
</del><ins>+    switch (page-&gt;captionPreferences().captionDisplayMode()) {
</ins><span class="cx">     case CaptionUserPreferences::Automatic:
</span><span class="cx">         return automaticKeyword();
</span><span class="cx">     case CaptionUserPreferences::ForcedOnly:
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -3063,7 +3063,9 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><del>-__ZN7WebCore9PageGroup18captionPreferencesEv
</del><ins>+__ZN7WebCore22CaptionUserPreferences29setCaptionsStyleSheetOverrideERKN3WTF6StringE
+__ZN7WebCore4Page18captionPreferencesEv
+__ZNK7WebCore22CaptionUserPreferences26captionsStyleSheetOverrideEv
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO)
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -6984,6 +6984,12 @@
</span><span class="cx">     &lt;ClCompile Include=&quot;..\page\animation\AnimationController.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\page\AutoscrollController.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\page\BarProp.cpp&quot; /&gt;
</span><ins>+    &lt;ClCompile Include=&quot;..\page\CaptionStyleSheetMediaAF.cpp&quot;&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+      &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
+    &lt;/ClCompile&gt;
</ins><span class="cx">     &lt;ClCompile Include=&quot;..\page\CaptionUserPreferences.cpp&quot; /&gt;
</span><span class="cx">     &lt;ClCompile Include=&quot;..\page\CaptionUserPreferencesMediaAF.cpp&quot;&gt;
</span><span class="cx">       &lt;ExcludedFromBuild Condition=&quot;'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'&quot;&gt;true&lt;/ExcludedFromBuild&gt;
</span><span class="lines">@@ -18759,6 +18765,7 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\page\animation\AnimationControllerPrivate.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\page\AutoscrollController.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\page\BarProp.h&quot; /&gt;
</span><ins>+    &lt;ClInclude Include=&quot;..\page\CaptionStyleSheetMediaAF.h&quot; /&gt;
</ins><span class="cx">     &lt;ClInclude Include=&quot;..\page\CaptionUserPreferences.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\page\CaptionUserPreferencesMediaAF.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\page\Chrome.h&quot; /&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -6724,6 +6724,9 @@
</span><span class="cx">     &lt;ClCompile Include=&quot;..\platform\graphics\opengl\TemporaryOpenGLSetting.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;platform\graphics\opengl&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><ins>+    &lt;ClCompile Include=&quot;..\page\CaptionStyleSheetMediaAF.cpp&quot;&gt;
+      &lt;Filter&gt;page&lt;/Filter&gt;
+    &lt;/ClCompile&gt;
</ins><span class="cx">     &lt;ClCompile Include=&quot;..\page\CaptionUserPreferencesMediaAF.cpp&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;page&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClCompile&gt;
</span><span class="lines">@@ -14500,6 +14503,9 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\platform\graphics\opengl\GLPlatformSurface.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;platform\graphics\opengl&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span><ins>+    &lt;ClInclude Include=&quot;..\page\CaptionStyleSheetMediaAF.h&quot;&gt;
+      &lt;Filter&gt;page&lt;/Filter&gt;
+    &lt;/ClInclude&gt;
</ins><span class="cx">     &lt;ClInclude Include=&quot;..\page\CaptionUserPreferences.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;page&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -2293,6 +2293,8 @@
</span><span class="cx">                 7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */; };
</span><span class="cx">                 7CE6CBFB187F370700D46BF5 /* FormatConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE6CBFA187F370700D46BF5 /* FormatConverter.h */; };
</span><span class="cx">                 7CE6CBFD187F394900D46BF5 /* FormatConverter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */; };
</span><ins>+                7CFC30591895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFC30571895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp */; };
+                7CFC305A1895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CFC30581895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h */; };
</ins><span class="cx">                 7D741BDA177226AA00859170 /* CSSValueKeywords.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 6565814809D13043000E61D7 /* CSSValueKeywords.h */; };
</span><span class="cx">                 7E33CD01127F340D00BE8F17 /* PurgePriority.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E33CD00127F340D00BE8F17 /* PurgePriority.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 7E37EF2E1339208800B29250 /* SubresourceLoaderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E37EF2D1339208800B29250 /* SubresourceLoaderCF.cpp */; };
</span><span class="lines">@@ -9234,6 +9236,8 @@
</span><span class="cx">                 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDNScriptWhiteList.txt; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7CE6CBFA187F370700D46BF5 /* FormatConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormatConverter.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatConverter.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                7CFC30571895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CaptionStyleSheetMediaAF.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                7CFC30581895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CaptionStyleSheetMediaAF.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 7E33CD00127F340D00BE8F17 /* PurgePriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurgePriority.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7E37EF2D1339208800B29250 /* SubresourceLoaderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SubresourceLoaderCF.cpp; path = cf/SubresourceLoaderCF.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7E428CE413E3407F003B661C /* ResourceHandleIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceHandleIOS.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -16032,6 +16036,8 @@
</span><span class="cx">                                 079D0867162F20E800DB8658 /* CaptionUserPreferences.h */,
</span><span class="cx">                                 079D086A162F21F900DB8658 /* CaptionUserPreferencesMediaAF.cpp */,
</span><span class="cx">                                 079D0869162F21F900DB8658 /* CaptionUserPreferencesMediaAF.h */,
</span><ins>+                                7CFC30571895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp */,
+                                7CFC30581895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h */,
</ins><span class="cx">                                 14D8238A0AF92DF60004F057 /* Chrome.cpp */,
</span><span class="cx">                                 14D823500AF92A790004F057 /* Chrome.h */,
</span><span class="cx">                                 14D824060AF93AEB0004F057 /* ChromeClient.h */,
</span><span class="lines">@@ -22599,6 +22605,7 @@
</span><span class="cx">                                 FE115FAB167988CD00249134 /* AbstractDatabaseServer.h in Headers */,
</span><span class="cx">                                 9A528E8417D7F52F00AA9518 /* FloatingObjects.h in Headers */,
</span><span class="cx">                                 FE4AADEE16D2C37400026FFC /* AbstractSQLStatement.h in Headers */,
</span><ins>+                                7CFC305A1895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h in Headers */,
</ins><span class="cx">                                 6E84E9E117668BF100815B68 /* RasterShape.h in Headers */,
</span><span class="cx">                                 FE4AADEF16D2C37400026FFC /* AbstractSQLStatementBackend.h in Headers */,
</span><span class="cx">                                 41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */,
</span><span class="lines">@@ -27118,6 +27125,7 @@
</span><span class="cx">                                 A81369E1097374F600D74463 /* HTMLLegendElement.cpp in Sources */,
</span><span class="cx">                                 A8EA79FC0A1916DF00A8EF5F /* HTMLLIElement.cpp in Sources */,
</span><span class="cx">                                 A871DC210A15205700B12A68 /* HTMLLinkElement.cpp in Sources */,
</span><ins>+                                7CFC30591895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp in Sources */,
</ins><span class="cx">                                 A8EA7D320A19385500A8EF5F /* HTMLMapElement.cpp in Sources */,
</span><span class="cx">                                 A8EA7CAC0A192B9C00A8EF5F /* HTMLMarqueeElement.cpp in Sources */,
</span><span class="cx">                                 E44613A40CD6331000FADA75 /* HTMLMediaElement.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorecssDocumentRuleSetscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/DocumentRuleSets.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/DocumentRuleSets.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/css/DocumentRuleSets.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -51,6 +51,8 @@
</span><span class="cx">     OwnPtr&lt;RuleSet&gt; tempUserStyle = RuleSet::create();
</span><span class="cx">     if (CSSStyleSheet* pageUserSheet = styleSheetCollection.pageUserSheet())
</span><span class="cx">         tempUserStyle-&gt;addRulesFromSheet(&amp;pageUserSheet-&gt;contents(), medium, &amp;resolver);
</span><ins>+    if (CSSStyleSheet* captionsStyleSheet = styleSheetCollection.captionsStyleSheet())
+        tempUserStyle-&gt;addRulesFromSheet(&amp;captionsStyleSheet-&gt;contents(), medium, &amp;resolver);
</ins><span class="cx">     collectRulesFromUserStyleSheets(styleSheetCollection.injectedUserStyleSheets(), *tempUserStyle, medium, resolver);
</span><span class="cx">     collectRulesFromUserStyleSheets(styleSheetCollection.documentUserStyleSheets(), *tempUserStyle, medium, resolver);
</span><span class="cx">     if (tempUserStyle-&gt;ruleCount() &gt; 0 || tempUserStyle-&gt;pageRules().size() &gt; 0)
</span></span></pre></div>
<a id="trunkSourceWebCorecssInspectorCSSOMWrapperscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/InspectorCSSOMWrappers.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/InspectorCSSOMWrappers.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/css/InspectorCSSOMWrappers.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -107,6 +107,7 @@
</span><span class="cx"> {
</span><span class="cx">     collectFromStyleSheets(styleSheetCollection.activeAuthorStyleSheets());
</span><span class="cx">     collect(styleSheetCollection.pageUserSheet());
</span><ins>+    collect(styleSheetCollection.captionsStyleSheet());
</ins><span class="cx">     collectFromStyleSheets(styleSheetCollection.injectedUserStyleSheets());
</span><span class="cx">     collectFromStyleSheets(styleSheetCollection.documentUserStyleSheets());
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/dom/Document.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -748,6 +748,7 @@
</span><span class="cx">     if (inQuirksMode() != wasInQuirksMode) {
</span><span class="cx">         // All user stylesheets have to reparse using the different mode.
</span><span class="cx">         m_styleSheetCollection.clearPageUserSheet();
</span><ins>+        m_styleSheetCollection.invalidateCaptionsStyleSheet();
</ins><span class="cx">         m_styleSheetCollection.invalidateInjectedStyleSheetCache();
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="lines">@@ -4171,9 +4172,6 @@
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> void Document::registerForCaptionPreferencesChangedCallbacks(Element* e)
</span><span class="cx"> {
</span><del>-    if (page())
-        page()-&gt;group().captionPreferences()-&gt;setInterestedInCaptionPreferenceChanges();
-
</del><span class="cx">     m_captionPreferencesChangedElements.add(e);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -4184,9 +4182,11 @@
</span><span class="cx"> 
</span><span class="cx"> void Document::captionPreferencesChanged()
</span><span class="cx"> {
</span><del>-    HashSet&lt;Element*&gt;::iterator end = m_captionPreferencesChangedElements.end();
-    for (HashSet&lt;Element*&gt;::iterator it = m_captionPreferencesChangedElements.begin(); it != end; ++it)
-        (*it)-&gt;captionPreferencesChanged();
</del><ins>+    m_styleSheetCollection.invalidateCaptionsStyleSheet();
+    styleResolverChanged(DeferRecalcStyle);
+
+    for (auto* element : m_captionPreferencesChangedElements)
+        element-&gt;captionPreferencesChanged();
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentStyleSheetCollectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #include &quot;DocumentStyleSheetCollection.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CSSStyleSheet.h&quot;
</span><ins>+#include &quot;CaptionUserPreferences.h&quot;
</ins><span class="cx"> #include &quot;Element.h&quot;
</span><span class="cx"> #include &quot;HTMLIFrameElement.h&quot;
</span><span class="cx"> #include &quot;HTMLLinkElement.h&quot;
</span><span class="lines">@@ -118,6 +119,41 @@
</span><span class="cx">         m_document.styleResolverChanged(RecalcStyleImmediately);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+CSSStyleSheet* DocumentStyleSheetCollection::captionsStyleSheet()
+{
+    updateCaptionsStyleSheet();
+    return m_captionsStyleSheet.get();
+}
+
+void DocumentStyleSheetCollection::updateCaptionsStyleSheet()
+{
+    // Identify our override style sheet with a unique URL - a new scheme and a UUID.
+    DEFINE_STATIC_LOCAL(URL, captionsStyleSheetURL, (ParsedURLString, &quot;user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23&quot;));
+
+    if (m_captionsStyleSheet)
+        return;
+
+    Page* owningPage = m_document.page();
+    if (!owningPage)
+        return;
+    
+    String captionsStyleSheetText = owningPage-&gt;captionPreferences().captionsStyleSheet();
+    if (captionsStyleSheetText.isEmpty())
+        return;
+
+    // Parse the sheet and cache it.
+    m_captionsStyleSheet = CSSStyleSheet::createInline(m_document, captionsStyleSheetURL);
+    m_captionsStyleSheet-&gt;contents().parseString(captionsStyleSheetText);
+}
+
+void DocumentStyleSheetCollection::invalidateCaptionsStyleSheet()
+{
+    if (m_captionsStyleSheet) {
+        m_captionsStyleSheet = nullptr;
+        m_document.styleResolverChanged(DeferRecalcStyle);
+    }
+}
+
</ins><span class="cx"> const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; DocumentStyleSheetCollection::injectedUserStyleSheets() const
</span><span class="cx"> {
</span><span class="cx">     updateInjectedStyleSheetCache();
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentStyleSheetCollectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx">     const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; activeAuthorStyleSheets() const { return m_activeAuthorStyleSheets; }
</span><span class="cx"> 
</span><span class="cx">     CSSStyleSheet* pageUserSheet();
</span><ins>+    CSSStyleSheet* captionsStyleSheet();
</ins><span class="cx">     const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; documentUserStyleSheets() const { return m_userStyleSheets; }
</span><span class="cx">     const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; documentAuthorStyleSheets() const { return m_authorStyleSheets; }
</span><span class="cx">     const Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt;&amp; injectedUserStyleSheets() const;
</span><span class="lines">@@ -63,6 +64,10 @@
</span><span class="cx"> 
</span><span class="cx">     void clearPageUserSheet();
</span><span class="cx">     void updatePageUserSheet();
</span><ins>+    
+    void invalidateCaptionsStyleSheet();
+    void updateCaptionsStyleSheet();
+
</ins><span class="cx">     void invalidateInjectedStyleSheetCache();
</span><span class="cx">     void updateInjectedStyleSheetCache() const;
</span><span class="cx"> 
</span><span class="lines">@@ -141,6 +146,7 @@
</span><span class="cx">     int m_pendingStylesheets;
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;CSSStyleSheet&gt; m_pageUserSheet;
</span><ins>+    RefPtr&lt;CSSStyleSheet&gt; m_captionsStyleSheet;
</ins><span class="cx"> 
</span><span class="cx">     mutable Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; m_injectedUserStyleSheets;
</span><span class="cx">     mutable Vector&lt;RefPtr&lt;CSSStyleSheet&gt;&gt; m_injectedAuthorStyleSheets;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -379,7 +379,7 @@
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     document.registerForCaptionPreferencesChangedCallbacks(this);
</span><span class="cx">     if (document.page())
</span><del>-        m_captionDisplayMode = document.page()-&gt;group().captionPreferences()-&gt;captionDisplayMode();
</del><ins>+        m_captionDisplayMode = document.page()-&gt;captionPreferences().captionDisplayMode();
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -3424,7 +3424,7 @@
</span><span class="cx">     LOG(Media, &quot;HTMLMediaElement::configureTextTrackGroup&quot;);
</span><span class="cx"> 
</span><span class="cx">     Page* page = document().page();
</span><del>-    CaptionUserPreferences* captionPreferences = page? page-&gt;group().captionPreferences() : 0;
</del><ins>+    CaptionUserPreferences* captionPreferences = page ? &amp;page-&gt;captionPreferences() : nullptr;
</ins><span class="cx">     CaptionUserPreferences::CaptionDisplayMode displayMode = captionPreferences ? captionPreferences-&gt;captionDisplayMode() : CaptionUserPreferences::Automatic;
</span><span class="cx"> 
</span><span class="cx">     // First, find the track in the group that should be enabled (if any).
</span><span class="lines">@@ -3534,11 +3534,10 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    CaptionUserPreferences* captionPreferences = document().page() ? document().page()-&gt;group().captionPreferences() : 0;
-    if (!captionPreferences)
</del><ins>+    if (!document().page())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    CaptionUserPreferences::CaptionDisplayMode displayMode = captionPreferences-&gt;captionDisplayMode();
</del><ins>+    CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()-&gt;captionPreferences().captionDisplayMode();
</ins><span class="cx">     if (trackToSelect == TextTrack::captionMenuOffItem())
</span><span class="cx">         displayMode = CaptionUserPreferences::ForcedOnly;
</span><span class="cx">     else if (trackToSelect == TextTrack::captionMenuAutomaticItem())
</span><span class="lines">@@ -3546,13 +3545,13 @@
</span><span class="cx">     else {
</span><span class="cx">         displayMode = CaptionUserPreferences::AlwaysOn;
</span><span class="cx">         if (trackToSelect-&gt;language().length())
</span><del>-            captionPreferences-&gt;setPreferredLanguage(trackToSelect-&gt;language());
</del><ins>+            document().page()-&gt;captionPreferences().setPreferredLanguage(trackToSelect-&gt;language());
</ins><span class="cx">         
</span><span class="cx">         // Set m_captionDisplayMode here so we don't reconfigure again when the preference changed notification comes through.
</span><span class="cx">         m_captionDisplayMode = displayMode;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    captionPreferences-&gt;setCaptionDisplayMode(displayMode);
</del><ins>+    document().page()-&gt;captionPreferences().setCaptionDisplayMode(displayMode);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLMediaElement::configureTextTracks()
</span><span class="lines">@@ -5256,8 +5255,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (!document().page())
</span><span class="cx">         return;
</span><del>-
-    CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()-&gt;group().captionPreferences()-&gt;captionDisplayMode();
</del><ins>+    
+    CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()-&gt;captionPreferences().captionDisplayMode();
</ins><span class="cx">     if (m_captionDisplayMode == displayMode)
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlshadowMediaControlElementscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/shadow/MediaControlElements.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -820,7 +820,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (!document().page())
</span><span class="cx">         return;
</span><del>-    CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()-&gt;group().captionPreferences()-&gt;captionDisplayMode();
</del><ins>+    CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()-&gt;captionPreferences().captionDisplayMode();
</ins><span class="cx"> 
</span><span class="cx">     HTMLMediaElement* mediaElement = parentMediaElement(this);
</span><span class="cx">     if (!mediaElement)
</span><span class="lines">@@ -896,9 +896,10 @@
</span><span class="cx"> 
</span><span class="cx">     if (!document().page())
</span><span class="cx">         return;
</span><del>-    CaptionUserPreferences* captionPreferences = document().page()-&gt;group().captionPreferences();
-    Vector&lt;RefPtr&lt;TextTrack&gt;&gt; tracksForMenu = captionPreferences-&gt;sortedTrackListForMenu(trackList);
</del><span class="cx"> 
</span><ins>+    CaptionUserPreferences&amp; captionPreferences = document().page()-&gt;captionPreferences();
+    Vector&lt;RefPtr&lt;TextTrack&gt;&gt; tracksForMenu = captionPreferences.sortedTrackListForMenu(trackList);
+
</ins><span class="cx">     RefPtr&lt;Element&gt; captionsHeader = document().createElement(h3Tag, ASSERT_NO_EXCEPTION);
</span><span class="cx">     captionsHeader-&gt;appendChild(document().createTextNode(textTrackSubtitlesText()));
</span><span class="cx">     appendChild(captionsHeader);
</span><span class="lines">@@ -907,7 +908,7 @@
</span><span class="cx">     for (unsigned i = 0, length = tracksForMenu.size(); i &lt; length; ++i) {
</span><span class="cx">         RefPtr&lt;TextTrack&gt; textTrack = tracksForMenu[i];
</span><span class="cx">         RefPtr&lt;Element&gt; menuItem = document().createElement(liTag, ASSERT_NO_EXCEPTION);
</span><del>-        menuItem-&gt;appendChild(document().createTextNode(captionPreferences-&gt;displayNameForTrack(textTrack.get())));
</del><ins>+        menuItem-&gt;appendChild(document().createTextNode(captionPreferences.displayNameForTrack(textTrack.get())));
</ins><span class="cx">         captionsMenuList-&gt;appendChild(menuItem);
</span><span class="cx">         m_menuItems.append(menuItem);
</span><span class="cx">         m_menuToTrackMap.add(menuItem, textTrack);
</span><span class="lines">@@ -1331,7 +1332,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_videoDisplaySize.size().width());
</span><del>-    float fontScale = document().page()-&gt;group().captionPreferences()-&gt;captionFontSizeScaleAndImportance(m_fontSizeIsImportant);
</del><ins>+    float fontScale = document().page()-&gt;captionPreferences().captionFontSizeScaleAndImportance(m_fontSizeIsImportant);
</ins><span class="cx">     m_fontSize = lroundf(smallestDimension * fontScale);
</span><span class="cx">     
</span><span class="cx">     CueList activeCues = mediaElement-&gt;currentlyActiveCues();
</span></span></pre></div>
<a id="trunkSourceWebCorepageCaptionStyleSheetMediaAFcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.cpp (0 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.cpp                                (rev 0)
+++ trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -0,0 +1,364 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;CaptionStyleSheetMediaAF.h&quot;
+
+#if ENABLE(VIDEO_TRACK)
+
+#include &quot;CSSPropertyNames.h&quot;
+#include &quot;Color.h&quot;
+#include &quot;Logging.h&quot;
+#include &quot;SoftLinking.h&quot;
+#include &quot;TextTrackCue.h&quot;
+#include &lt;wtf/text/CString.h&gt;
+#include &lt;wtf/text/StringBuilder.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+#include &quot;CoreText/CoreText.h&quot;
+#include &lt;MediaAccessibility/MediaAccessibility.h&gt;
+#endif
+
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+
+#if !PLATFORM(WIN)
+#define SOFT_LINK_AVF_FRAMEWORK(Lib) SOFT_LINK_FRAMEWORK_OPTIONAL(Lib)
+#define SOFT_LINK_AVF(Lib, Name, Type) SOFT_LINK(Lib, Name, Type)
+#define SOFT_LINK_AVF_POINTER(Lib, Name, Type) SOFT_LINK_POINTER_OPTIONAL(Lib, Name, Type)
+#define SOFT_LINK_AVF_FRAMEWORK_IMPORT(Lib, Fun, ReturnType, Arguments, Signature) SOFT_LINK(Lib, Fun, ReturnType, Arguments, Signature)
+#else
+
+#ifdef DEBUG_ALL
+#define SOFT_LINK_AVF_FRAMEWORK(Lib) SOFT_LINK_DEBUG_LIBRARY(Lib)
+#else
+#define SOFT_LINK_AVF_FRAMEWORK(Lib) SOFT_LINK_LIBRARY(Lib)
+#endif
+
+#define SOFT_LINK_AVF(Lib, Name, Type) SOFT_LINK_DLL_IMPORT(Lib, Name, Type)
+#define SOFT_LINK_AVF_POINTER(Lib, Name, Type) SOFT_LINK_VARIABLE_DLL_IMPORT_OPTIONAL(Lib, Name, Type)
+#define SOFT_LINK_AVF_FRAMEWORK_IMPORT(Lib, Fun, ReturnType, Arguments, Signature) SOFT_LINK_DLL_IMPORT(Lib, Fun, ReturnType, __cdecl, Arguments, Signature)
+#endif
+
+SOFT_LINK_AVF_FRAMEWORK(MediaAccessibility)
+SOFT_LINK_AVF_FRAMEWORK(CoreText)
+
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyForegroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyBackgroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyWindowColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetForegroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetBackgroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetWindowOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetWindowRoundedCornerRadius, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyFontDescriptorForStyle, CTFontDescriptorRef, (MACaptionAppearanceDomain domain,  MACaptionAppearanceBehavior *behavior, MACaptionAppearanceFontStyle fontStyle), (domain, behavior, fontStyle))
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetTextEdgeStyle, MACaptionAppearanceTextEdgeStyle, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
+
+SOFT_LINK_AVF_FRAMEWORK_IMPORT(CoreText, CTFontDescriptorCopyAttribute,  CFTypeRef, (CTFontDescriptorRef descriptor, CFStringRef attribute), (descriptor, attribute));
+
+#if PLATFORM(WIN)
+// These are needed on Windows due to the way DLLs work. We do not need them on other platforms
+#define MACaptionAppearanceCopyForegroundColor softLink_MACaptionAppearanceCopyForegroundColor
+#define MACaptionAppearanceCopyBackgroundColor softLink_MACaptionAppearanceCopyBackgroundColor
+#define MACaptionAppearanceCopyWindowColor softLink_MACaptionAppearanceCopyWindowColor
+#define MACaptionAppearanceGetForegroundOpacity softLink_MACaptionAppearanceGetForegroundOpacity
+#define MACaptionAppearanceGetBackgroundOpacity softLink_MACaptionAppearanceGetBackgroundOpacity
+#define MACaptionAppearanceGetWindowOpacity softLink_MACaptionAppearanceGetWindowOpacity
+#define MACaptionAppearanceGetWindowRoundedCornerRadius softLink_MACaptionAppearanceGetWindowRoundedCornerRadius
+#define MACaptionAppearanceCopyFontDescriptorForStyle softLink_MACaptionAppearanceCopyFontDescriptorForStyle
+#define MACaptionAppearanceGetTextEdgeStyle softLink_MACaptionAppearanceGetTextEdgeStyle
+#define CTFontDescriptorCopyAttribute softLink_CTFontDescriptorCopyAttribute
+#endif
+
+SOFT_LINK_AVF_POINTER(CoreText, kCTFontNameAttribute, CFStringRef)
+#define kCTFontNameAttribute getkCTFontNameAttribute()
+#endif
+
+namespace WebCore {
+
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+
+static String captionsWindowCSS();
+static String captionsBackgroundCSS();
+static String captionsTextColorCSS();
+static Color captionsTextColor(bool&amp;);
+static String captionsDefaultFontCSS();
+static Color captionsEdgeColorForTextColor(const Color&amp;);
+static String windowRoundedCornerRadiusCSS();
+static String captionsTextEdgeCSS();
+static String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&amp;, const Color&amp;, bool);
+static String colorPropertyCSS(CSSPropertyID, const Color&amp;, bool);
+
+#endif
+
+String defaultCaptionsStyleSheet()
+{
+    StringBuilder captionsOverrideStyleSheet;
+
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+    if (!MediaAccessibilityLibrary())
+        return String();
+    
+    String captionsColor = captionsTextColorCSS();
+    String edgeStyle = captionsTextEdgeCSS();
+    String fontName = captionsDefaultFontCSS();
+    String background = captionsBackgroundCSS();
+    if (!background.isEmpty() || !captionsColor.isEmpty() || !edgeStyle.isEmpty() || !fontName.isEmpty()) {
+        captionsOverrideStyleSheet.append(&quot; video::&quot;);
+        captionsOverrideStyleSheet.append(TextTrackCue::cueShadowPseudoId());
+        captionsOverrideStyleSheet.append('{');
+        
+        if (!background.isEmpty())
+            captionsOverrideStyleSheet.append(background);
+        if (!captionsColor.isEmpty())
+            captionsOverrideStyleSheet.append(captionsColor);
+        if (!edgeStyle.isEmpty())
+            captionsOverrideStyleSheet.append(edgeStyle);
+        if (!fontName.isEmpty())
+            captionsOverrideStyleSheet.append(fontName);
+        
+        captionsOverrideStyleSheet.append('}');
+    }
+    
+    String windowColor = captionsWindowCSS();
+    String windowCornerRadius = windowRoundedCornerRadiusCSS();
+    if (!windowColor.isEmpty() || !windowCornerRadius.isEmpty()) {
+        captionsOverrideStyleSheet.append(&quot; video::&quot;);
+        captionsOverrideStyleSheet.append(TextTrackCueBox::textTrackCueBoxShadowPseudoId());
+        captionsOverrideStyleSheet.append('{');
+        
+        if (!windowColor.isEmpty())
+            captionsOverrideStyleSheet.append(windowColor);
+        if (!windowCornerRadius.isEmpty())
+            captionsOverrideStyleSheet.append(windowCornerRadius);
+        
+        captionsOverrideStyleSheet.append('}');
+    }
+#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+
+    LOG(Media, &quot;CaptionUserPreferencesMediaAF::captionsStyleSheetOverrideSetting sytle to:\n%s&quot;, captionsOverrideStyleSheet.toString().utf8().data());
+
+    return captionsOverrideStyleSheet.toString();
+}
+
+#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+
+String captionsWindowCSS()
+{
+    MACaptionAppearanceBehavior behavior;
+    RetainPtr&lt;CGColorRef&gt; color = adoptCF(MACaptionAppearanceCopyWindowColor(kMACaptionAppearanceDomainUser, &amp;behavior));
+
+    Color windowColor(color.get());
+    if (!windowColor.isValid())
+        windowColor = Color::transparent;
+
+    bool important = behavior == kMACaptionAppearanceBehaviorUseValue;
+    CGFloat opacity = MACaptionAppearanceGetWindowOpacity(kMACaptionAppearanceDomainUser, &amp;behavior);
+    if (!important)
+        important = behavior == kMACaptionAppearanceBehaviorUseValue;
+    String windowStyle = colorPropertyCSS(CSSPropertyBackgroundColor, Color(windowColor.red(), windowColor.green(), windowColor.blue(), static_cast&lt;int&gt;(opacity * 255)), important);
+
+    if (!opacity)
+        return windowStyle;
+
+    StringBuilder builder;
+    builder.append(windowStyle);
+    builder.append(getPropertyNameString(CSSPropertyPadding));
+    builder.append(&quot;: .4em !important;&quot;);
+
+    return builder.toString();
+}
+
+String captionsBackgroundCSS()
+{
+    // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-past-nodes
+    // and webkit-media-text-track-future-nodes.
+    DEFINE_STATIC_LOCAL(Color, defaultBackgroundColor, (Color(0, 0, 0, 0.8 * 255)));
+
+    MACaptionAppearanceBehavior behavior;
+
+    RetainPtr&lt;CGColorRef&gt; color = adoptCF(MACaptionAppearanceCopyBackgroundColor(kMACaptionAppearanceDomainUser, &amp;behavior));
+    Color backgroundColor(color.get());
+    if (!backgroundColor.isValid())
+        backgroundColor = defaultBackgroundColor;
+
+    bool important = behavior == kMACaptionAppearanceBehaviorUseValue;
+    CGFloat opacity = MACaptionAppearanceGetBackgroundOpacity(kMACaptionAppearanceDomainUser, &amp;behavior);
+    if (!important)
+        important = behavior == kMACaptionAppearanceBehaviorUseValue;
+    return colorPropertyCSS(CSSPropertyBackgroundColor, Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), static_cast&lt;int&gt;(opacity * 255)), important);
+}
+
+Color captionsTextColor(bool&amp; important)
+{
+    MACaptionAppearanceBehavior behavior;
+    RetainPtr&lt;CGColorRef&gt; color = adoptCF(MACaptionAppearanceCopyForegroundColor(kMACaptionAppearanceDomainUser, &amp;behavior));
+    Color textColor(color.get());
+    if (!textColor.isValid())
+        // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-container.
+        textColor = Color::white;
+    
+    important = behavior == kMACaptionAppearanceBehaviorUseValue;
+    CGFloat opacity = MACaptionAppearanceGetForegroundOpacity(kMACaptionAppearanceDomainUser, &amp;behavior);
+    if (!important)
+        important = behavior == kMACaptionAppearanceBehaviorUseValue;
+    return Color(textColor.red(), textColor.green(), textColor.blue(), static_cast&lt;int&gt;(opacity * 255));
+}
+    
+String captionsTextColorCSS()
+{
+    bool important;
+    Color textColor = captionsTextColor(important);
+
+    if (!textColor.isValid())
+        return emptyString();
+
+    return colorPropertyCSS(CSSPropertyColor, textColor, important);
+}
+    
+String windowRoundedCornerRadiusCSS()
+{
+    MACaptionAppearanceBehavior behavior;
+    CGFloat radius = MACaptionAppearanceGetWindowRoundedCornerRadius(kMACaptionAppearanceDomainUser, &amp;behavior);
+    if (!radius)
+        return emptyString();
+
+    StringBuilder builder;
+    builder.append(getPropertyNameString(CSSPropertyBorderRadius));
+    builder.append(String::format(&quot;:%.02fpx&quot;, radius));
+    if (behavior == kMACaptionAppearanceBehaviorUseValue)
+        builder.append(&quot; !important&quot;);
+    builder.append(';');
+
+    return builder.toString();
+}
+    
+Color captionsEdgeColorForTextColor(const Color&amp; textColor)
+{
+    int distanceFromWhite = differenceSquared(textColor, Color::white);
+    int distanceFromBlack = differenceSquared(textColor, Color::black);
+    
+    if (distanceFromWhite &lt; distanceFromBlack)
+        return textColor.dark();
+    
+    return textColor.light();
+}
+
+String cssPropertyWithTextEdgeColor(CSSPropertyID id, const String&amp; value, const Color&amp; textColor, bool important)
+{
+    StringBuilder builder;
+    
+    builder.append(getPropertyNameString(id));
+    builder.append(':');
+    builder.append(value);
+    builder.append(' ');
+    builder.append(captionsEdgeColorForTextColor(textColor).serialized());
+    if (important)
+        builder.append(&quot; !important&quot;);
+    builder.append(';');
+    
+    return builder.toString();
+}
+
+String colorPropertyCSS(CSSPropertyID id, const Color&amp; color, bool important)
+{
+    StringBuilder builder;
+    
+    builder.append(getPropertyNameString(id));
+    builder.append(':');
+    builder.append(color.serialized());
+    if (important)
+        builder.append(&quot; !important&quot;);
+    builder.append(';');
+    
+    return builder.toString();
+}
+
+String captionsTextEdgeCSS()
+{
+    DEFINE_STATIC_LOCAL(const String, edgeStyleRaised, (&quot; -.05em -.05em 0 &quot;, String::ConstructFromLiteral));
+    DEFINE_STATIC_LOCAL(const String, edgeStyleDepressed, (&quot; .05em .05em 0 &quot;, String::ConstructFromLiteral));
+    DEFINE_STATIC_LOCAL(const String, edgeStyleDropShadow, (&quot; .075em .075em 0 &quot;, String::ConstructFromLiteral));
+    DEFINE_STATIC_LOCAL(const String, edgeStyleUniform, (&quot; .03em &quot;, String::ConstructFromLiteral));
+
+    bool unused;
+    Color color = captionsTextColor(unused);
+    if (!color.isValid())
+        color.setNamedColor(&quot;black&quot;);
+    color = captionsEdgeColorForTextColor(color);
+
+    MACaptionAppearanceBehavior behavior;
+    MACaptionAppearanceTextEdgeStyle textEdgeStyle = MACaptionAppearanceGetTextEdgeStyle(kMACaptionAppearanceDomainUser, &amp;behavior);
+    switch (textEdgeStyle) {
+    case kMACaptionAppearanceTextEdgeStyleUndefined:
+    case kMACaptionAppearanceTextEdgeStyleNone:
+        return emptyString();
+            
+    case kMACaptionAppearanceTextEdgeStyleRaised:
+        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color, behavior == kMACaptionAppearanceBehaviorUseValue);
+    case kMACaptionAppearanceTextEdgeStyleDepressed:
+        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color, behavior == kMACaptionAppearanceBehaviorUseValue);
+    case kMACaptionAppearanceTextEdgeStyleDropShadow:
+        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color, behavior == kMACaptionAppearanceBehaviorUseValue);
+    case kMACaptionAppearanceTextEdgeStyleUniform:
+        return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, edgeStyleUniform, color, behavior == kMACaptionAppearanceBehaviorUseValue);
+            
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+    
+    return emptyString();
+}
+
+String captionsDefaultFontCSS()
+{
+    MACaptionAppearanceBehavior behavior;
+    
+    RetainPtr&lt;CTFontDescriptorRef&gt; font = adoptCF(MACaptionAppearanceCopyFontDescriptorForStyle(kMACaptionAppearanceDomainUser, &amp;behavior, kMACaptionAppearanceFontStyleDefault));
+    if (!font)
+        return emptyString();
+
+    RetainPtr&lt;CFTypeRef&gt; name = adoptCF(CTFontDescriptorCopyAttribute(font.get(), kCTFontNameAttribute));
+    if (!name)
+        return emptyString();
+    
+    StringBuilder builder;
+    
+    builder.append(getPropertyNameString(CSSPropertyFontFamily));
+    builder.append(&quot;: \&quot;&quot;);
+    builder.append(static_cast&lt;CFStringRef&gt;(name.get()));
+    builder.append('&quot;');
+    if (behavior == kMACaptionAppearanceBehaviorUseValue)
+        builder.append(&quot; !important&quot;);
+    builder.append(';');
+    
+    return builder.toString();
+}
+
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(VIDEO_TRACK)
</ins></span></pre></div>
<a id="trunkSourceWebCorepageCaptionStyleSheetMediaAFh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.h (0 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.h                                (rev 0)
+++ trunk/Source/WebCore/page/CaptionStyleSheetMediaAF.h        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CaptionStyleSheetMediaAF_h
+#define CaptionStyleSheetMediaAF_h
+
+#if ENABLE(VIDEO_TRACK)
+
+#include &lt;wtf/Forward.h&gt;
+
+namespace WebCore {
+
+String defaultCaptionsStyleSheet();
+
+}
+
+#endif // ENABLE(VIDEO_TRACK)
+#endif // CaptionStyleSheetMediaAF_h
</ins></span></pre></div>
<a id="trunkSourceWebCorepageCaptionUserPreferencescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/CaptionUserPreferences.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/CaptionUserPreferences.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/CaptionUserPreferences.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -28,21 +28,19 @@
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CaptionUserPreferences.h&quot;
</span><del>-#include &quot;DOMWrapperWorld.h&quot;
</del><ins>+
+#include &quot;HTMLMediaElement.h&quot;
</ins><span class="cx"> #include &quot;Page.h&quot;
</span><del>-#include &quot;PageGroup.h&quot;
</del><ins>+#include &quot;PageCache.h&quot;
</ins><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &quot;TextTrackList.h&quot;
</span><del>-#include &quot;UserStyleSheetTypes.h&quot;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-CaptionUserPreferences::CaptionUserPreferences(PageGroup&amp; group)
-    : m_pageGroup(group)
</del><ins>+CaptionUserPreferences::CaptionUserPreferences()
+    : m_timer(this, &amp;CaptionUserPreferences::timerFired)
</ins><span class="cx">     , m_displayMode(ForcedOnly)
</span><del>-    , m_timer(this, &amp;CaptionUserPreferences::timerFired)
</del><span class="cx">     , m_testingMode(false)
</span><del>-    , m_havePreferences(false)
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -57,7 +55,6 @@
</span><span class="cx"> 
</span><span class="cx"> void CaptionUserPreferences::notify()
</span><span class="cx"> {
</span><del>-    m_havePreferences = true;
</del><span class="cx">     if (!m_timer.isActive())
</span><span class="cx">         m_timer.startOneShot(0);
</span><span class="cx"> }
</span><span class="lines">@@ -70,75 +67,36 @@
</span><span class="cx"> void CaptionUserPreferences::setCaptionDisplayMode(CaptionUserPreferences::CaptionDisplayMode mode)
</span><span class="cx"> {
</span><span class="cx">     m_displayMode = mode;
</span><del>-    if (m_testingMode &amp;&amp; mode != AlwaysOn) {
-        setUserPrefersCaptions(false);
-        setUserPrefersSubtitles(false);
-    }
</del><span class="cx">     notify();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool CaptionUserPreferences::userPrefersCaptions() const
</del><ins>+bool CaptionUserPreferences::userPrefersCaptions(Document&amp; document) const
</ins><span class="cx"> {
</span><del>-    Page* page = *(m_pageGroup.pages().begin());
-    if (!page)
</del><ins>+    Settings* settings = document.settings();
+    if (!settings)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    return page-&gt;settings().shouldDisplayCaptions();
</del><ins>+    return settings-&gt;shouldDisplayCaptions();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CaptionUserPreferences::setUserPrefersCaptions(bool preference)
</del><ins>+bool CaptionUserPreferences::userPrefersSubtitles(Document&amp; document) const
</ins><span class="cx"> {
</span><del>-    Page* page = *(m_pageGroup.pages().begin());
-    if (!page)
-        return;
-
-    page-&gt;settings().setShouldDisplayCaptions(preference);
-    notify();
-}
-
-bool CaptionUserPreferences::userPrefersSubtitles() const
-{
-    Page* page = *(pageGroup().pages().begin());
-    if (!page)
</del><ins>+    Settings* settings = document.settings();
+    if (!settings)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    return page-&gt;settings().shouldDisplaySubtitles();
</del><ins>+    return settings-&gt;shouldDisplaySubtitles();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CaptionUserPreferences::setUserPrefersSubtitles(bool preference)
</del><ins>+bool CaptionUserPreferences::userPrefersTextDescriptions(Document&amp; document) const
</ins><span class="cx"> {
</span><del>-    Page* page = *(m_pageGroup.pages().begin());
-    if (!page)
-        return;
-
-    page-&gt;settings().setShouldDisplaySubtitles(preference);
-    notify();
-}
-
-bool CaptionUserPreferences::userPrefersTextDescriptions() const
-{
-    Page* page = *(m_pageGroup.pages().begin());
-    if (!page)
</del><ins>+    Settings* settings = document.settings();
+    if (!settings)
</ins><span class="cx">         return false;
</span><del>-    
-    return page-&gt;settings().shouldDisplayTextDescriptions();
-}
</del><span class="cx"> 
</span><del>-void CaptionUserPreferences::setUserPrefersTextDescriptions(bool preference)
-{
-    Page* page = *(m_pageGroup.pages().begin());
-    if (!page)
-        return;
-    
-    page-&gt;settings().setShouldDisplayTextDescriptions(preference);
-    notify();
</del><ins>+    return settings-&gt;shouldDisplayTextDescriptions();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CaptionUserPreferences::captionPreferencesChanged()
-{
-    m_pageGroup.captionPreferencesChanged();
-}
-
</del><span class="cx"> Vector&lt;String&gt; CaptionUserPreferences::preferredLanguages() const
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;String&gt; languages = userPreferredLanguages();
</span><span class="lines">@@ -196,19 +154,19 @@
</span><span class="cx">     return tracksForMenu;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-int CaptionUserPreferences::textTrackSelectionScore(TextTrack* track, HTMLMediaElement*) const
</del><ins>+int CaptionUserPreferences::textTrackSelectionScore(TextTrack* track, HTMLMediaElement* element) const
</ins><span class="cx"> {
</span><span class="cx">     int trackScore = 0;
</span><span class="cx"> 
</span><span class="cx">     if (track-&gt;kind() != TextTrack::captionsKeyword() &amp;&amp; track-&gt;kind() != TextTrack::subtitlesKeyword())
</span><span class="cx">         return trackScore;
</span><span class="cx">     
</span><del>-    if (!userPrefersSubtitles() &amp;&amp; !userPrefersCaptions())
</del><ins>+    if (!userPrefersSubtitles(element-&gt;document()) &amp;&amp; !userPrefersCaptions(element-&gt;document()))
</ins><span class="cx">         return trackScore;
</span><span class="cx">     
</span><del>-    if (track-&gt;kind() == TextTrack::subtitlesKeyword() &amp;&amp; userPrefersSubtitles())
</del><ins>+    if (track-&gt;kind() == TextTrack::subtitlesKeyword() &amp;&amp; userPrefersSubtitles(element-&gt;document()))
</ins><span class="cx">         trackScore = 1;
</span><del>-    else if (track-&gt;kind() == TextTrack::captionsKeyword() &amp;&amp; userPrefersCaptions())
</del><ins>+    else if (track-&gt;kind() == TextTrack::captionsKeyword() &amp;&amp; userPrefersCaptions(element-&gt;document()))
</ins><span class="cx">         trackScore = 1;
</span><span class="cx">     
</span><span class="cx">     return trackScore + textTrackLanguageSelectionScore(track, preferredLanguages());
</span><span class="lines">@@ -228,25 +186,23 @@
</span><span class="cx">     return (preferredLanguages.size() - languageMatchIndex) * 10;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String CaptionUserPreferences::captionsStyleSheet()
+{
+    if (!m_captionsStyleSheetOverride.isEmpty() || testingMode())
+        return m_captionsStyleSheetOverride;
+
+    return platformCaptionsStyleSheet();
+}
+
</ins><span class="cx"> void CaptionUserPreferences::setCaptionsStyleSheetOverride(const String&amp; override)
</span><span class="cx"> {
</span><span class="cx">     m_captionsStyleSheetOverride = override;
</span><del>-    updateCaptionStyleSheetOveride();
</del><ins>+    captionPreferencesChanged();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CaptionUserPreferences::updateCaptionStyleSheetOveride()
</del><ins>+String CaptionUserPreferences::captionsStyleSheetOverride() const
</ins><span class="cx"> {
</span><del>-    // Identify our override style sheet with a unique URL - a new scheme and a UUID.
-    DEFINE_STATIC_LOCAL(URL, captionsStyleSheetURL, (ParsedURLString, &quot;user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23&quot;));
-
-    m_pageGroup.removeUserStyleSheetFromWorld(mainThreadNormalWorld(), captionsStyleSheetURL);
-
-    String captionsOverrideStyleSheet = captionsStyleSheetOverride();
-    if (captionsOverrideStyleSheet.isEmpty())
-        return;
-
-    m_pageGroup.addUserStyleSheetToWorld(mainThreadNormalWorld(), captionsOverrideStyleSheet, captionsStyleSheetURL, Vector&lt;String&gt;(),
-        Vector&lt;String&gt;(), InjectInAllFrames, UserStyleAuthorLevel, InjectInExistingDocuments);
</del><ins>+    return m_captionsStyleSheetOverride;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String CaptionUserPreferences::primaryAudioTrackLanguageOverride() const
</span><span class="lines">@@ -255,7 +211,13 @@
</span><span class="cx">         return m_primaryAudioTrackLanguageOverride;
</span><span class="cx">     return defaultLanguage();
</span><span class="cx"> }
</span><del>-    
</del><ins>+
+void CaptionUserPreferences::captionPreferencesChanged()
+{
+    Page::updateStyleForAllPagesForCaptionPreferencesChanged();
+    pageCache()-&gt;markPagesForCaptionPreferencesChanged();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+} // namespace WebCore
+
</ins><span class="cx"> #endif // ENABLE(VIDEO_TRACK)
</span></span></pre></div>
<a id="trunkSourceWebCorepageCaptionUserPreferencesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/CaptionUserPreferences.h (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/CaptionUserPreferences.h        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/CaptionUserPreferences.h        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -43,69 +43,60 @@
</span><span class="cx"> 
</span><span class="cx"> class CaptionUserPreferences {
</span><span class="cx"> public:
</span><del>-    CaptionUserPreferences(PageGroup&amp;);
</del><ins>+    CaptionUserPreferences();
</ins><span class="cx">     virtual ~CaptionUserPreferences();
</span><span class="cx"> 
</span><ins>+    String captionsStyleSheet();
+
</ins><span class="cx">     enum CaptionDisplayMode {
</span><span class="cx">         Automatic,
</span><span class="cx">         ForcedOnly,
</span><span class="cx">         AlwaysOn
</span><span class="cx">     };
</span><ins>+
</ins><span class="cx">     virtual CaptionDisplayMode captionDisplayMode() const;
</span><span class="cx">     virtual void setCaptionDisplayMode(CaptionDisplayMode);
</span><span class="cx"> 
</span><span class="cx">     virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const;
</span><span class="cx">     virtual int textTrackLanguageSelectionScore(TextTrack*, const Vector&lt;String&gt;&amp;) const;
</span><ins>+    virtual bool userPrefersCaptions(Document&amp;) const;
+    virtual bool userPrefersSubtitles(Document&amp;) const;
+    virtual bool userPrefersTextDescriptions(Document&amp;) const;
</ins><span class="cx"> 
</span><del>-    virtual bool userPrefersCaptions() const;
-    virtual void setUserPrefersCaptions(bool);
-
-    virtual bool userPrefersSubtitles() const;
-    virtual void setUserPrefersSubtitles(bool preference);
-    
-    virtual bool userPrefersTextDescriptions() const;
-    virtual void setUserPrefersTextDescriptions(bool preference);
-
</del><span class="cx">     virtual float captionFontSizeScaleAndImportance(bool&amp; important) const { important = false; return 0.05f; }
</span><span class="cx"> 
</span><del>-    virtual String captionsStyleSheetOverride() const { return m_captionsStyleSheetOverride; }
-    virtual void setCaptionsStyleSheetOverride(const String&amp;);
-
-    virtual void setInterestedInCaptionPreferenceChanges() { }
-
-    virtual void captionPreferencesChanged();
-
</del><span class="cx">     virtual void setPreferredLanguage(const String&amp;);
</span><span class="cx">     virtual Vector&lt;String&gt; preferredLanguages() const;
</span><span class="cx"> 
</span><span class="cx">     virtual String displayNameForTrack(TextTrack*) const;
</span><span class="cx">     virtual Vector&lt;RefPtr&lt;TextTrack&gt;&gt; sortedTrackListForMenu(TextTrackList*);
</span><span class="cx"> 
</span><ins>+    void captionPreferencesChanged();
+
+    // These are used for testing mode only.
+    void setCaptionsStyleSheetOverride(const String&amp;);
+    String captionsStyleSheetOverride() const;
</ins><span class="cx">     void setPrimaryAudioTrackLanguageOverride(const String&amp; language) { m_primaryAudioTrackLanguageOverride = language;  }
</span><span class="cx">     String primaryAudioTrackLanguageOverride() const;
</span><del>-
-    virtual bool testingMode() const { return m_testingMode; }
-    virtual void setTestingMode(bool override) { m_testingMode = override; }
</del><ins>+    void setTestingMode(bool override) { m_testingMode = override; }
+    bool testingMode() const { return m_testingMode; }
</ins><span class="cx">     
</span><del>-    PageGroup&amp; pageGroup() const { return m_pageGroup; }
-
-protected:
-    void updateCaptionStyleSheetOveride();
-
</del><span class="cx"> private:
</span><span class="cx">     void timerFired(Timer&lt;CaptionUserPreferences&gt;&amp;);
</span><span class="cx">     void notify();
</span><span class="cx"> 
</span><del>-    PageGroup&amp; m_pageGroup;
-    CaptionDisplayMode m_displayMode;
</del><ins>+    virtual String platformCaptionsStyleSheet() { return String(); }
+
</ins><span class="cx">     Timer&lt;CaptionUserPreferences&gt; m_timer;
</span><ins>+
+    // These are used for testing mode only.
+    CaptionDisplayMode m_displayMode;
</ins><span class="cx">     String m_userPreferredLanguage;
</span><span class="cx">     String m_captionsStyleSheetOverride;
</span><span class="cx">     String m_primaryAudioTrackLanguageOverride;
</span><span class="cx">     bool m_testingMode;
</span><del>-    bool m_havePreferences;
</del><span class="cx"> };
</span><del>-    
</del><ins>+
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageCaptionUserPreferencesMediaAFcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -29,9 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CaptionUserPreferencesMediaAF.h&quot;
</span><span class="cx"> 
</span><del>-#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-#include &quot;CoreText/CoreText.h&quot;
-#endif
</del><ins>+#include &quot;CaptionStyleSheetMediaAF.h&quot;
</ins><span class="cx"> #include &quot;FloatConversion.h&quot;
</span><span class="cx"> #include &quot;HTMLMediaElement.h&quot;
</span><span class="cx"> #include &quot;URL.h&quot;
</span><span class="lines">@@ -42,7 +40,6 @@
</span><span class="cx"> #include &quot;SoftLinking.h&quot;
</span><span class="cx"> #include &quot;TextTrackCue.h&quot;
</span><span class="cx"> #include &quot;TextTrackList.h&quot;
</span><del>-#include &quot;UserStyleSheetTypes.h&quot;
</del><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="cx"> #include &lt;wtf/text/StringBuilder.h&gt;
</span><span class="lines">@@ -76,74 +73,51 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_AVF_FRAMEWORK(MediaAccessibility)
</span><del>-SOFT_LINK_AVF_FRAMEWORK(CoreText)
</del><span class="cx"> 
</span><span class="cx"> SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetDisplayType, MACaptionAppearanceDisplayType, (MACaptionAppearanceDomain domain), (domain))
</span><span class="cx"> SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceSetDisplayType, void, (MACaptionAppearanceDomain domain, MACaptionAppearanceDisplayType displayType), (domain, displayType))
</span><del>-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyForegroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyBackgroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyWindowColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetForegroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetBackgroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetWindowOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetWindowRoundedCornerRadius, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyFontDescriptorForStyle, CTFontDescriptorRef, (MACaptionAppearanceDomain domain,  MACaptionAppearanceBehavior *behavior, MACaptionAppearanceFontStyle fontStyle), (domain, behavior, fontStyle))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetRelativeCharacterSize, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
-SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetTextEdgeStyle, MACaptionAppearanceTextEdgeStyle, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
</del><span class="cx"> SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceAddSelectedLanguage, bool, (MACaptionAppearanceDomain domain, CFStringRef language), (domain, language));
</span><span class="cx"> SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopySelectedLanguages, CFArrayRef, (MACaptionAppearanceDomain domain), (domain));
</span><span class="cx"> SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics,  CFArrayRef, (MACaptionAppearanceDomain domain), (domain));
</span><ins>+SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetRelativeCharacterSize, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior))
</ins><span class="cx"> 
</span><del>-SOFT_LINK_AVF_FRAMEWORK_IMPORT(CoreText, CTFontDescriptorCopyAttribute,  CFTypeRef, (CTFontDescriptorRef descriptor, CFStringRef attribute), (descriptor, attribute));
-
</del><span class="cx"> #if PLATFORM(WIN)
</span><span class="cx"> // These are needed on Windows due to the way DLLs work. We do not need them on other platforms
</span><span class="cx"> #define MACaptionAppearanceGetDisplayType softLink_MACaptionAppearanceGetDisplayType
</span><span class="cx"> #define MACaptionAppearanceSetDisplayType softLink_MACaptionAppearanceSetDisplayType
</span><del>-#define MACaptionAppearanceCopyForegroundColor softLink_MACaptionAppearanceCopyForegroundColor
-#define MACaptionAppearanceCopyBackgroundColor softLink_MACaptionAppearanceCopyBackgroundColor
-#define MACaptionAppearanceCopyWindowColor softLink_MACaptionAppearanceCopyWindowColor
-#define MACaptionAppearanceGetForegroundOpacity softLink_MACaptionAppearanceGetForegroundOpacity
-#define MACaptionAppearanceGetBackgroundOpacity softLink_MACaptionAppearanceGetBackgroundOpacity
-#define MACaptionAppearanceGetWindowOpacity softLink_MACaptionAppearanceGetWindowOpacity
-#define MACaptionAppearanceGetWindowRoundedCornerRadius softLink_MACaptionAppearanceGetWindowRoundedCornerRadius
-#define MACaptionAppearanceCopyFontDescriptorForStyle softLink_MACaptionAppearanceCopyFontDescriptorForStyle
-#define MACaptionAppearanceGetRelativeCharacterSize softLink_MACaptionAppearanceGetRelativeCharacterSize
-#define MACaptionAppearanceGetTextEdgeStyle softLink_MACaptionAppearanceGetTextEdgeStyle
</del><span class="cx"> #define MACaptionAppearanceAddSelectedLanguage softLink_MACaptionAppearanceAddSelectedLanguage
</span><span class="cx"> #define MACaptionAppearanceCopySelectedLanguages softLink_MACaptionAppearanceCopySelectedLanguages
</span><span class="cx"> #define MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics softLink_MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics
</span><del>-#define CTFontDescriptorCopyAttribute softLink_CTFontDescriptorCopyAttribute
</del><ins>+#define MACaptionAppearanceGetRelativeCharacterSize softLink_MACaptionAppearanceGetRelativeCharacterSize
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_AVF_POINTER(MediaAccessibility, kMAXCaptionAppearanceSettingsChangedNotification, CFStringRef)
</span><span class="cx"> #define kMAXCaptionAppearanceSettingsChangedNotification getkMAXCaptionAppearanceSettingsChangedNotification()
</span><span class="cx"> 
</span><del>-SOFT_LINK_AVF_POINTER(CoreText, kCTFontNameAttribute, CFStringRef)
-#define kCTFontNameAttribute getkCTFontNameAttribute()
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
</span><span class="cx"> static void userCaptionPreferencesChangedNotificationCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void *, CFDictionaryRef)
</span><span class="cx"> {
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    static_cast&lt;CaptionUserPreferencesMediaAF*&gt;(observer)-&gt;captionPreferencesChanged();
</del><ins>+    static_cast&lt;CaptionUserPreferencesMediaAF*&gt;(observer)-&gt;captionApperenceChanged();
</ins><span class="cx"> #else
</span><span class="cx">     WebThreadRun(^{
</span><del>-        static_cast&lt;CaptionUserPreferencesMediaAF*&gt;(observer)-&gt;captionPreferencesChanged();
</del><ins>+        static_cast&lt;CaptionUserPreferencesMediaAF*&gt;(observer)-&gt;captionApperenceChanged();
</ins><span class="cx">     });
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF(PageGroup&amp; group)
-    : CaptionUserPreferences(group)
</del><ins>+CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF()
+{
</ins><span class="cx"> #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
</span><del>-    , m_listeningForPreferenceChanges(false)
</del><ins>+    if (MediaAccessibilityLibrary() &amp;&amp; kMAXCaptionAppearanceSettingsChangedNotification)
+        CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce);
</ins><span class="cx"> #endif
</span><del>-{
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CaptionUserPreferencesMediaAF::~CaptionUserPreferencesMediaAF()
</span><span class="lines">@@ -156,6 +130,15 @@
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
</span><span class="cx"> 
</span><ins>+void CaptionUserPreferencesMediaAF::captionApperenceChanged()
+{
+    // Invalidate the caption style sheet.
+    m_captionStyleSheet = String();
+
+    // Tell the base class to invalidate all the uses of it.
+    captionPreferencesChanged();
+}
+
</ins><span class="cx"> CaptionUserPreferences::CaptionDisplayMode CaptionUserPreferencesMediaAF::captionDisplayMode() const
</span><span class="cx"> {
</span><span class="cx">     if (testingMode() || !MediaAccessibilityLibrary())
</span><span class="lines">@@ -206,9 +189,9 @@
</span><span class="cx">     MACaptionAppearanceSetDisplayType(kMACaptionAppearanceDomainUser, displayType);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool CaptionUserPreferencesMediaAF::userPrefersCaptions() const
</del><ins>+bool CaptionUserPreferencesMediaAF::userPrefersCaptions(Document&amp; document) const
</ins><span class="cx"> {
</span><del>-    bool captionSetting = CaptionUserPreferences::userPrefersCaptions();
</del><ins>+    bool captionSetting = CaptionUserPreferences::userPrefersCaptions(document);
</ins><span class="cx">     if (captionSetting || testingMode() || !MediaAccessibilityLibrary())
</span><span class="cx">         return captionSetting;
</span><span class="cx">     
</span><span class="lines">@@ -216,9 +199,9 @@
</span><span class="cx">     return captioningMediaCharacteristics &amp;&amp; CFArrayGetCount(captioningMediaCharacteristics.get());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool CaptionUserPreferencesMediaAF::userPrefersSubtitles() const
</del><ins>+bool CaptionUserPreferencesMediaAF::userPrefersSubtitles(Document&amp; document) const
</ins><span class="cx"> {
</span><del>-    bool subtitlesSetting = CaptionUserPreferences::userPrefersSubtitles();
</del><ins>+    bool subtitlesSetting = CaptionUserPreferences::userPrefersSubtitles(document);
</ins><span class="cx">     if (subtitlesSetting || testingMode() || !MediaAccessibilityLibrary())
</span><span class="cx">         return subtitlesSetting;
</span><span class="cx">     
</span><span class="lines">@@ -226,222 +209,6 @@
</span><span class="cx">     return !(captioningMediaCharacteristics &amp;&amp; CFArrayGetCount(captioningMediaCharacteristics.get()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges()
-{
-    if (!MediaAccessibilityLibrary())
-        return;
-
-    if (!kMAXCaptionAppearanceSettingsChangedNotification)
-        return;
-
-    if (!m_listeningForPreferenceChanges) {
-        m_listeningForPreferenceChanges = true;
-        CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce);
-        updateCaptionStyleSheetOveride();
-    }
-}
-
-void CaptionUserPreferencesMediaAF::captionPreferencesChanged()
-{
-    if (m_listeningForPreferenceChanges)
-        updateCaptionStyleSheetOveride();
-
-    CaptionUserPreferences::captionPreferencesChanged();
-}
-
-String CaptionUserPreferencesMediaAF::captionsWindowCSS() const
-{
-    MACaptionAppearanceBehavior behavior;
-    RetainPtr&lt;CGColorRef&gt; color = adoptCF(MACaptionAppearanceCopyWindowColor(kMACaptionAppearanceDomainUser, &amp;behavior));
-
-    Color windowColor(color.get());
-    if (!windowColor.isValid())
-        windowColor = Color::transparent;
-
-    bool important = behavior == kMACaptionAppearanceBehaviorUseValue;
-    CGFloat opacity = MACaptionAppearanceGetWindowOpacity(kMACaptionAppearanceDomainUser, &amp;behavior);
-    if (!important)
-        important = behavior == kMACaptionAppearanceBehaviorUseValue;
-    String windowStyle = colorPropertyCSS(CSSPropertyBackgroundColor, Color(windowColor.red(), windowColor.green(), windowColor.blue(), static_cast&lt;int&gt;(opacity * 255)), important);
-
-    if (!opacity)
-        return windowStyle;
-
-    StringBuilder builder;
-    builder.append(windowStyle);
-    builder.append(getPropertyNameString(CSSPropertyPadding));
-    builder.append(&quot;: .4em !important;&quot;);
-
-    return builder.toString();
-}
-
-String CaptionUserPreferencesMediaAF::captionsBackgroundCSS() const
-{
-    // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-past-nodes
-    // and webkit-media-text-track-future-nodes.
-    DEFINE_STATIC_LOCAL(Color, defaultBackgroundColor, (Color(0, 0, 0, 0.8 * 255)));
-
-    MACaptionAppearanceBehavior behavior;
-
-    RetainPtr&lt;CGColorRef&gt; color = adoptCF(MACaptionAppearanceCopyBackgroundColor(kMACaptionAppearanceDomainUser, &amp;behavior));
-    Color backgroundColor(color.get());
-    if (!backgroundColor.isValid())
-        backgroundColor = defaultBackgroundColor;
-
-    bool important = behavior == kMACaptionAppearanceBehaviorUseValue;
-    CGFloat opacity = MACaptionAppearanceGetBackgroundOpacity(kMACaptionAppearanceDomainUser, &amp;behavior);
-    if (!important)
-        important = behavior == kMACaptionAppearanceBehaviorUseValue;
-    return colorPropertyCSS(CSSPropertyBackgroundColor, Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), static_cast&lt;int&gt;(opacity * 255)), important);
-}
-
-Color CaptionUserPreferencesMediaAF::captionsTextColor(bool&amp; important) const
-{
-    MACaptionAppearanceBehavior behavior;
-    RetainPtr&lt;CGColorRef&gt; color = adoptCF(MACaptionAppearanceCopyForegroundColor(kMACaptionAppearanceDomainUser, &amp;behavior));
-    Color textColor(color.get());
-    if (!textColor.isValid())
-        // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-container.
-        textColor = Color::white;
-    
-    important = behavior == kMACaptionAppearanceBehaviorUseValue;
-    CGFloat opacity = MACaptionAppearanceGetForegroundOpacity(kMACaptionAppearanceDomainUser, &amp;behavior);
-    if (!important)
-        important = behavior == kMACaptionAppearanceBehaviorUseValue;
-    return Color(textColor.red(), textColor.green(), textColor.blue(), static_cast&lt;int&gt;(opacity * 255));
-}
-    
-String CaptionUserPreferencesMediaAF::captionsTextColorCSS() const
-{
-    bool important;
-    Color textColor = captionsTextColor(important);
-
-    if (!textColor.isValid())
-        return emptyString();
-
-    return colorPropertyCSS(CSSPropertyColor, textColor, important);
-}
-    
-String CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS() const
-{
-    MACaptionAppearanceBehavior behavior;
-    CGFloat radius = MACaptionAppearanceGetWindowRoundedCornerRadius(kMACaptionAppearanceDomainUser, &amp;behavior);
-    if (!radius)
-        return emptyString();
-
-    StringBuilder builder;
-    builder.append(getPropertyNameString(CSSPropertyBorderRadius));
-    builder.append(String::format(&quot;:%.02fpx&quot;, radius));
-    if (behavior == kMACaptionAppearanceBehaviorUseValue)
-        builder.append(&quot; !important&quot;);
-    builder.append(';');
-
-    return builder.toString();
-}
-    
-Color CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor(const Color&amp; textColor) const
-{
-    int distanceFromWhite = differenceSquared(textColor, Color::white);
-    int distanceFromBlack = differenceSquared(textColor, Color::black);
-    
-    if (distanceFromWhite &lt; distanceFromBlack)
-        return textColor.dark();
-    
-    return textColor.light();
-}
-
-String CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor(CSSPropertyID id, const String&amp; value, const Color&amp; textColor, bool important) const
-{
-    StringBuilder builder;
-    
-    builder.append(getPropertyNameString(id));
-    builder.append(':');
-    builder.append(value);
-    builder.append(' ');
-    builder.append(captionsEdgeColorForTextColor(textColor).serialized());
-    if (important)
-        builder.append(&quot; !important&quot;);
-    builder.append(';');
-    
-    return builder.toString();
-}
-
-String CaptionUserPreferencesMediaAF::colorPropertyCSS(CSSPropertyID id, const Color&amp; color, bool important) const
-{
-    StringBuilder builder;
-    
-    builder.append(getPropertyNameString(id));
-    builder.append(':');
-    builder.append(color.serialized());
-    if (important)
-        builder.append(&quot; !important&quot;);
-    builder.append(';');
-    
-    return builder.toString();
-}
-
-String CaptionUserPreferencesMediaAF::captionsTextEdgeCSS() const
-{
-    DEFINE_STATIC_LOCAL(const String, edgeStyleRaised, (&quot; -.05em -.05em 0 &quot;, String::ConstructFromLiteral));
-    DEFINE_STATIC_LOCAL(const String, edgeStyleDepressed, (&quot; .05em .05em 0 &quot;, String::ConstructFromLiteral));
-    DEFINE_STATIC_LOCAL(const String, edgeStyleDropShadow, (&quot; .075em .075em 0 &quot;, String::ConstructFromLiteral));
-    DEFINE_STATIC_LOCAL(const String, edgeStyleUniform, (&quot; .03em &quot;, String::ConstructFromLiteral));
-
-    bool unused;
-    Color color = captionsTextColor(unused);
-    if (!color.isValid())
-        color.setNamedColor(&quot;black&quot;);
-    color = captionsEdgeColorForTextColor(color);
-
-    MACaptionAppearanceBehavior behavior;
-    MACaptionAppearanceTextEdgeStyle textEdgeStyle = MACaptionAppearanceGetTextEdgeStyle(kMACaptionAppearanceDomainUser, &amp;behavior);
-    switch (textEdgeStyle) {
-    case kMACaptionAppearanceTextEdgeStyleUndefined:
-    case kMACaptionAppearanceTextEdgeStyleNone:
-        return emptyString();
-            
-    case kMACaptionAppearanceTextEdgeStyleRaised:
-        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color, behavior == kMACaptionAppearanceBehaviorUseValue);
-    case kMACaptionAppearanceTextEdgeStyleDepressed:
-        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color, behavior == kMACaptionAppearanceBehaviorUseValue);
-    case kMACaptionAppearanceTextEdgeStyleDropShadow:
-        return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color, behavior == kMACaptionAppearanceBehaviorUseValue);
-    case kMACaptionAppearanceTextEdgeStyleUniform:
-        return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, edgeStyleUniform, color, behavior == kMACaptionAppearanceBehaviorUseValue);
-            
-    default:
-        ASSERT_NOT_REACHED();
-        break;
-    }
-    
-    return emptyString();
-}
-
-String CaptionUserPreferencesMediaAF::captionsDefaultFontCSS() const
-{
-    MACaptionAppearanceBehavior behavior;
-    
-    RetainPtr&lt;CTFontDescriptorRef&gt; font = adoptCF(MACaptionAppearanceCopyFontDescriptorForStyle(kMACaptionAppearanceDomainUser, &amp;behavior, kMACaptionAppearanceFontStyleDefault));
-    if (!font)
-        return emptyString();
-
-    RetainPtr&lt;CFTypeRef&gt; name = adoptCF(CTFontDescriptorCopyAttribute(font.get(), kCTFontNameAttribute));
-    if (!name)
-        return emptyString();
-    
-    StringBuilder builder;
-    
-    builder.append(getPropertyNameString(CSSPropertyFontFamily));
-    builder.append(&quot;: \&quot;&quot;);
-    builder.append(static_cast&lt;CFStringRef&gt;(name.get()));
-    builder.append('&quot;');
-    if (behavior == kMACaptionAppearanceBehaviorUseValue)
-        builder.append(&quot; !important&quot;);
-    builder.append(';');
-    
-    return builder.toString();
-}
-
</del><span class="cx"> float CaptionUserPreferencesMediaAF::captionFontSizeScaleAndImportance(bool&amp; important) const
</span><span class="cx"> {
</span><span class="cx">     if (testingMode() || !MediaAccessibilityLibrary())
</span><span class="lines">@@ -507,59 +274,7 @@
</span><span class="cx"> }
</span><span class="cx"> #endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
</span><span class="cx"> 
</span><del>-String CaptionUserPreferencesMediaAF::captionsStyleSheetOverride() const
-{
-    if (testingMode())
-        return CaptionUserPreferences::captionsStyleSheetOverride();
-    
-    StringBuilder captionsOverrideStyleSheet;
</del><span class="cx"> 
</span><del>-#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-    if (!MediaAccessibilityLibrary())
-        return CaptionUserPreferences::captionsStyleSheetOverride();
-    
-    String captionsColor = captionsTextColorCSS();
-    String edgeStyle = captionsTextEdgeCSS();
-    String fontName = captionsDefaultFontCSS();
-    String background = captionsBackgroundCSS();
-    if (!background.isEmpty() || !captionsColor.isEmpty() || !edgeStyle.isEmpty() || !fontName.isEmpty()) {
-        captionsOverrideStyleSheet.append(&quot; video::&quot;);
-        captionsOverrideStyleSheet.append(TextTrackCue::cueShadowPseudoId());
-        captionsOverrideStyleSheet.append('{');
-        
-        if (!background.isEmpty())
-            captionsOverrideStyleSheet.append(background);
-        if (!captionsColor.isEmpty())
-            captionsOverrideStyleSheet.append(captionsColor);
-        if (!edgeStyle.isEmpty())
-            captionsOverrideStyleSheet.append(edgeStyle);
-        if (!fontName.isEmpty())
-            captionsOverrideStyleSheet.append(fontName);
-        
-        captionsOverrideStyleSheet.append('}');
-    }
-    
-    String windowColor = captionsWindowCSS();
-    String windowCornerRadius = windowRoundedCornerRadiusCSS();
-    if (!windowColor.isEmpty() || !windowCornerRadius.isEmpty()) {
-        captionsOverrideStyleSheet.append(&quot; video::&quot;);
-        captionsOverrideStyleSheet.append(TextTrackCueBox::textTrackCueBoxShadowPseudoId());
-        captionsOverrideStyleSheet.append('{');
-        
-        if (!windowColor.isEmpty())
-            captionsOverrideStyleSheet.append(windowColor);
-        if (!windowCornerRadius.isEmpty())
-            captionsOverrideStyleSheet.append(windowCornerRadius);
-        
-        captionsOverrideStyleSheet.append('}');
-    }
-#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-
-    LOG(Media, &quot;CaptionUserPreferencesMediaAF::captionsStyleSheetOverrideSetting sytle to:\n%s&quot;, captionsOverrideStyleSheet.toString().utf8().data());
-
-    return captionsOverrideStyleSheet.toString();
-}
-
</del><span class="cx"> static String languageIdentifier(const String&amp; languageCode)
</span><span class="cx"> {
</span><span class="cx">     if (languageCode.isEmpty())
</span><span class="lines">@@ -635,6 +350,14 @@
</span><span class="cx">     return displayName.toString();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String CaptionUserPreferencesMediaAF::platformCaptionsStyleSheet()
+{
+    if (!m_captionStyleSheet)
+        m_captionStyleSheet = defaultCaptionsStyleSheet();
+
+    return m_captionStyleSheet;
+}
+
</ins><span class="cx"> String CaptionUserPreferencesMediaAF::displayNameForTrack(TextTrack* track) const
</span><span class="cx"> {
</span><span class="cx">     return trackDisplayName(track);
</span><span class="lines">@@ -644,7 +367,7 @@
</span><span class="cx"> {
</span><span class="cx">     CaptionDisplayMode displayMode = captionDisplayMode();
</span><span class="cx">     bool legacyOverride = mediaElement-&gt;webkitClosedCaptionsVisible();
</span><del>-    if (displayMode == AlwaysOn &amp;&amp; (!userPrefersSubtitles() &amp;&amp; !userPrefersCaptions() &amp;&amp; !legacyOverride))
</del><ins>+    if (displayMode == AlwaysOn &amp;&amp; (!userPrefersSubtitles(mediaElement-&gt;document()) &amp;&amp; !userPrefersCaptions(mediaElement-&gt;document()) &amp;&amp; !legacyOverride))
</ins><span class="cx">         return 0;
</span><span class="cx">     if (track-&gt;kind() != TextTrack::captionsKeyword() &amp;&amp; track-&gt;kind() != TextTrack::subtitlesKeyword() &amp;&amp; track-&gt;kind() != TextTrack::forcedKeyword())
</span><span class="cx">         return 0;
</span><span class="lines">@@ -704,7 +427,7 @@
</span><span class="cx"> 
</span><span class="cx">     int trackScore = 0;
</span><span class="cx"> 
</span><del>-    if (userPrefersCaptions()) {
</del><ins>+    if (userPrefersCaptions(mediaElement-&gt;document())) {
</ins><span class="cx">         // When the user prefers accessiblity tracks, rank is SDH, then CC, then subtitles.
</span><span class="cx">         if (track-&gt;kind() == track-&gt;subtitlesKeyword())
</span><span class="cx">             trackScore = 1;
</span><span class="lines">@@ -766,7 +489,7 @@
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;RefPtr&lt;TextTrack&gt;&gt; tracksForMenu;
</span><span class="cx">     HashSet&lt;String&gt; languagesIncluded;
</span><del>-    bool prefersAccessibilityTracks = userPrefersCaptions();
</del><ins>+    bool prefersAccessibilityTracks = userPrefersCaptions(trackList-&gt;mediaElement()-&gt;document());
</ins><span class="cx">     bool filterTrackList = shouldFilterTrackMenu();
</span><span class="cx"> 
</span><span class="cx">     for (unsigned i = 0, length = trackList-&gt;length(); i &lt; length; ++i) {
</span><span class="lines">@@ -848,7 +571,7 @@
</span><span class="cx"> 
</span><span class="cx">     return tracksForMenu;
</span><span class="cx"> }
</span><del>-    
</del><ins>+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(VIDEO_TRACK)
</span></span></pre></div>
<a id="trunkSourceWebCorepageCaptionUserPreferencesMediaAFh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -37,50 +37,35 @@
</span><span class="cx"> 
</span><span class="cx"> class CaptionUserPreferencesMediaAF : public CaptionUserPreferences {
</span><span class="cx"> public:
</span><del>-    CaptionUserPreferencesMediaAF(PageGroup&amp;);
</del><ins>+    CaptionUserPreferencesMediaAF();
</ins><span class="cx">     virtual ~CaptionUserPreferencesMediaAF();
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
</span><ins>+    void captionApperenceChanged();
+
</ins><span class="cx">     virtual CaptionDisplayMode captionDisplayMode() const override;
</span><span class="cx">     virtual void setCaptionDisplayMode(CaptionDisplayMode) override;
</span><span class="cx"> 
</span><del>-    virtual bool userPrefersCaptions() const override;
-    virtual bool userPrefersSubtitles() const override;
</del><ins>+    virtual bool userPrefersCaptions(Document&amp;) const override;
+    virtual bool userPrefersSubtitles(Document&amp;) const override;
</ins><span class="cx"> 
</span><span class="cx">     virtual float captionFontSizeScaleAndImportance(bool&amp;) const override;
</span><span class="cx"> 
</span><del>-    virtual void setInterestedInCaptionPreferenceChanges() override;
-
</del><span class="cx">     virtual void setPreferredLanguage(const String&amp;) override;
</span><span class="cx">     virtual Vector&lt;String&gt; preferredLanguages() const override;
</span><span class="cx"> 
</span><del>-    virtual void captionPreferencesChanged() override;
-
</del><span class="cx">     bool shouldFilterTrackMenu() const { return true; }
</span><span class="cx"> #else
</span><span class="cx">     bool shouldFilterTrackMenu() const { return false; }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    virtual String captionsStyleSheetOverride() const override;
</del><ins>+    virtual String platformCaptionsStyleSheet() override;
</ins><span class="cx">     virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const override;
</span><span class="cx">     virtual Vector&lt;RefPtr&lt;TextTrack&gt;&gt; sortedTrackListForMenu(TextTrackList*) override;
</span><span class="cx">     virtual String displayNameForTrack(TextTrack*) const override;
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-    String captionsWindowCSS() const;
-    String captionsBackgroundCSS() const;
-    String captionsTextColorCSS() const;
-    Color captionsTextColor(bool&amp;) const;
-    String captionsDefaultFontCSS() const;
-    Color captionsEdgeColorForTextColor(const Color&amp;) const;
-    String windowRoundedCornerRadiusCSS() const;
-    String captionsTextEdgeCSS() const;
-    String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&amp;, const Color&amp;, bool) const;
-    String colorPropertyCSS(CSSPropertyID, const Color&amp;, bool) const;
-
-    bool m_listeningForPreferenceChanges;
-#endif
</del><ins>+    String m_captionStyleSheet;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/Page.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -92,6 +92,14 @@
</span><span class="cx"> #include &lt;wtf/text/Base64.h&gt;
</span><span class="cx"> #include &lt;wtf/text/StringHash.h&gt;
</span><span class="cx"> 
</span><ins>+#if ENABLE(VIDEO_TRACK)
+#if (PLATFORM(MAC) &amp;&amp; !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+#include &quot;CaptionUserPreferencesMediaAF.h&quot;
+#else
+#include &quot;CaptionUserPreferences.h&quot;
+#endif
+#endif
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> static HashSet&lt;Page*&gt;* allPages;
</span><span class="lines">@@ -1493,6 +1501,28 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><ins>+CaptionUserPreferences&amp; Page::captionPreferences()
+{
+    // FIXME: This should not be a singleton.
+#if (PLATFORM(MAC) &amp;&amp; !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
+    static NeverDestroyed&lt;CaptionUserPreferencesMediaAF&gt; preferences;
+#else
+    static NeverDestroyed&lt;CaptionUserPreferences&gt; preferences;
+#endif
+
+    return preferences;
+}
+
+void Page::updateStyleForAllPagesForCaptionPreferencesChanged()
+{
+    if (!allPages)
+        return;
+
+    for (auto page : *allPages)
+        page-&gt;captionPreferencesChanged();
+}
+
+
</ins><span class="cx"> void Page::captionPreferencesChanged()
</span><span class="cx"> {
</span><span class="cx">     for (Frame* frame = &amp;mainFrame(); frame; frame = frame-&gt;tree().traverseNext())
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.h (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.h        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/Page.h        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -61,6 +61,7 @@
</span><span class="cx"> class AlternativeTextClient;
</span><span class="cx"> class BackForwardController;
</span><span class="cx"> class BackForwardClient;
</span><ins>+class CaptionUserPreferences;
</ins><span class="cx"> class Chrome;
</span><span class="cx"> class ChromeClient;
</span><span class="cx"> class ClientRectList;
</span><span class="lines">@@ -402,6 +403,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><ins>+    static void updateStyleForAllPagesForCaptionPreferencesChanged();
+    CaptionUserPreferences&amp; captionPreferences();
</ins><span class="cx">     void captionPreferencesChanged();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageGroupcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageGroup.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageGroup.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/PageGroup.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -42,14 +42,6 @@
</span><span class="cx"> #include &quot;VisitedLinkProvider.h&quot;
</span><span class="cx"> #include &lt;wtf/StdLibExtras.h&gt;
</span><span class="cx"> 
</span><del>-#if ENABLE(VIDEO_TRACK)
-#if (PLATFORM(MAC) &amp;&amp; !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-#include &quot;CaptionUserPreferencesMediaAF.h&quot;
-#else
-#include &quot;CaptionUserPreferences.h&quot;
-#endif
-#endif
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> static unsigned getUniqueIdentifier()
</span><span class="lines">@@ -310,26 +302,4 @@
</span><span class="cx">     m_userContentController-&gt;removeAllUserContent();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(VIDEO_TRACK)
-void PageGroup::captionPreferencesChanged()
-{
-    for (auto it = m_pages.begin(), end = m_pages.end(); it != end; ++it)
-        (*it)-&gt;captionPreferencesChanged();
-    pageCache()-&gt;markPagesForCaptionPreferencesChanged();
-}
-
-CaptionUserPreferences* PageGroup::captionPreferences()
-{
-    if (!m_captionPreferences) {
-#if (PLATFORM(MAC) &amp;&amp; !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
-        m_captionPreferences = std::make_unique&lt;CaptionUserPreferencesMediaAF&gt;(*this);
-#else
-        m_captionPreferences = std::make_unique&lt;CaptionUserPreferences&gt;(*this);
-#endif
-    }
-
-    return m_captionPreferences.get();
-}
-#endif
-
</del><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageGrouph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageGroup.h (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageGroup.h        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/page/PageGroup.h        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -45,11 +45,6 @@
</span><span class="cx">     class VisitedLinkProvider;
</span><span class="cx">     class UserContentController;
</span><span class="cx"> 
</span><del>-#if ENABLE(VIDEO_TRACK)
-    class CaptionPreferencesChangedListener;
-    class CaptionUserPreferences;
-#endif
-
</del><span class="cx">     class PageGroup : public Supplementable&lt;PageGroup&gt; {
</span><span class="cx">         WTF_MAKE_NONCOPYABLE(PageGroup); WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">     public:
</span><span class="lines">@@ -103,11 +98,6 @@
</span><span class="cx"> 
</span><span class="cx">         GroupSettings&amp; groupSettings() const { return *m_groupSettings; }
</span><span class="cx"> 
</span><del>-#if ENABLE(VIDEO_TRACK)
-        void captionPreferencesChanged();
-        CaptionUserPreferences* captionPreferences();
-#endif
-
</del><span class="cx">     private:
</span><span class="cx">         void addVisitedLink(LinkHash);
</span><span class="cx"> 
</span><span class="lines">@@ -126,10 +116,6 @@
</span><span class="cx">         RefPtr&lt;UserContentController&gt; m_userContentController;
</span><span class="cx"> 
</span><span class="cx">         const std::unique_ptr&lt;GroupSettings&gt; m_groupSettings;
</span><del>-
-#if ENABLE(VIDEO_TRACK)
-        std::unique_ptr&lt;CaptionUserPreferences&gt; m_captionPreferences;
-#endif
</del><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/InternalSettings.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -413,16 +413,12 @@
</span><span class="cx">     InternalSettingsGuardForSettings();
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><del>-    if (!page())
-        return;
-    CaptionUserPreferences* captionPreferences = page()-&gt;group().captionPreferences();
-
</del><span class="cx">     if (equalIgnoringCase(kind, &quot;Subtitles&quot;))
</span><del>-        captionPreferences-&gt;setUserPrefersSubtitles(enabled);
</del><ins>+        settings()-&gt;setShouldDisplaySubtitles(enabled);
</ins><span class="cx">     else if (equalIgnoringCase(kind, &quot;Captions&quot;))
</span><del>-        captionPreferences-&gt;setUserPrefersCaptions(enabled);
</del><ins>+        settings()-&gt;setShouldDisplayCaptions(enabled);
</ins><span class="cx">     else if (equalIgnoringCase(kind, &quot;TextDescriptions&quot;))
</span><del>-        captionPreferences-&gt;setUserPrefersTextDescriptions(enabled);
</del><ins>+        settings()-&gt;setShouldDisplayTextDescriptions(enabled);
</ins><span class="cx">     else
</span><span class="cx">         ec = SYNTAX_ERR;
</span><span class="cx"> #else
</span><span class="lines">@@ -436,16 +432,12 @@
</span><span class="cx">     InternalSettingsGuardForSettingsReturn(false);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><del>-    if (!page())
-        return false;
-    CaptionUserPreferences* captionPreferences = page()-&gt;group().captionPreferences();
-
</del><span class="cx">     if (equalIgnoringCase(kind, &quot;Subtitles&quot;))
</span><del>-        return captionPreferences-&gt;userPrefersSubtitles();
</del><ins>+        return settings()-&gt;shouldDisplaySubtitles();
</ins><span class="cx">     if (equalIgnoringCase(kind, &quot;Captions&quot;))
</span><del>-        return captionPreferences-&gt;userPrefersCaptions();
</del><ins>+        return settings()-&gt;shouldDisplayCaptions();
</ins><span class="cx">     if (equalIgnoringCase(kind, &quot;TextDescriptions&quot;))
</span><del>-        return captionPreferences-&gt;userPrefersTextDescriptions();
</del><ins>+        return settings()-&gt;shouldDisplayTextDescriptions();
</ins><span class="cx"> 
</span><span class="cx">     ec = SYNTAX_ERR;
</span><span class="cx">     return false;
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (163047 => 163048)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2014-01-30 00:31:05 UTC (rev 163047)
+++ trunk/Source/WebCore/testing/Internals.cpp        2014-01-30 00:35:31 UTC (rev 163048)
</span><span class="lines">@@ -281,8 +281,8 @@
</span><span class="cx">     page-&gt;inspectorController().setProfilerEnabled(false);
</span><span class="cx"> #endif
</span><span class="cx"> #if ENABLE(VIDEO_TRACK) &amp;&amp; !PLATFORM(WIN)
</span><del>-    page-&gt;group().captionPreferences()-&gt;setCaptionsStyleSheetOverride(emptyString());
-    page-&gt;group().captionPreferences()-&gt;setTestingMode(false);
</del><ins>+    page-&gt;captionPreferences().setCaptionsStyleSheetOverride(emptyString());
+    page-&gt;captionPreferences().setTestingMode(false);
</ins><span class="cx"> #endif
</span><span class="cx">     if (!page-&gt;mainFrame().editor().isContinuousSpellCheckingEnabled())
</span><span class="cx">         page-&gt;mainFrame().editor().toggleContinuousSpellChecking();
</span><span class="lines">@@ -302,7 +302,7 @@
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(VIDEO_TRACK) &amp;&amp; !PLATFORM(WIN)
</span><span class="cx">     if (document &amp;&amp; document-&gt;page())
</span><del>-        document-&gt;page()-&gt;group().captionPreferences()-&gt;setTestingMode(true);
</del><ins>+        document-&gt;page()-&gt;captionPreferences().setTestingMode(true);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_STREAM)
</span><span class="lines">@@ -2051,7 +2051,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK) &amp;&amp; !PLATFORM(WIN)
</span><del>-    return document-&gt;page()-&gt;group().captionPreferences()-&gt;captionsStyleSheetOverride();
</del><ins>+    return document-&gt;page()-&gt;captionPreferences().captionsStyleSheetOverride();
</ins><span class="cx"> #else
</span><span class="cx">     return emptyString();
</span><span class="cx"> #endif
</span><span class="lines">@@ -2066,7 +2066,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK) &amp;&amp; !PLATFORM(WIN)
</span><del>-    document-&gt;page()-&gt;group().captionPreferences()-&gt;setCaptionsStyleSheetOverride(override);
</del><ins>+    document-&gt;page()-&gt;captionPreferences().setCaptionsStyleSheetOverride(override);
</ins><span class="cx"> #else
</span><span class="cx">     UNUSED_PARAM(override);
</span><span class="cx"> #endif
</span><span class="lines">@@ -2081,7 +2081,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK) &amp;&amp; !PLATFORM(WIN)
</span><del>-    document-&gt;page()-&gt;group().captionPreferences()-&gt;setPrimaryAudioTrackLanguageOverride(language);
</del><ins>+    document-&gt;page()-&gt;captionPreferences().setPrimaryAudioTrackLanguageOverride(language);
</ins><span class="cx"> #else
</span><span class="cx">     UNUSED_PARAM(language);
</span><span class="cx"> #endif
</span><span class="lines">@@ -2096,14 +2096,18 @@
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="cx"> #if ENABLE(VIDEO_TRACK) &amp;&amp; !PLATFORM(WIN)
</span><del>-    CaptionUserPreferences* captionPreferences = document-&gt;page()-&gt;group().captionPreferences();
</del><ins>+    CaptionUserPreferences&amp; captionPreferences = document-&gt;page()-&gt;captionPreferences();
</ins><span class="cx">     
</span><del>-    if (equalIgnoringCase(mode, &quot;Automatic&quot;))
-        captionPreferences-&gt;setCaptionDisplayMode(CaptionUserPreferences::Automatic);
-    else if (equalIgnoringCase(mode, &quot;ForcedOnly&quot;))
-        captionPreferences-&gt;setCaptionDisplayMode(CaptionUserPreferences::ForcedOnly);
-    else if (equalIgnoringCase(mode, &quot;AlwaysOn&quot;))
-        captionPreferences-&gt;setCaptionDisplayMode(CaptionUserPreferences::AlwaysOn);
</del><ins>+    if (equalIgnoringCase(mode, &quot;Automatic&quot;)) {
+        captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::Automatic);
+        document-&gt;page()-&gt;settings().setShouldDisplayCaptions(false);
+        document-&gt;page()-&gt;settings().setShouldDisplaySubtitles(false);
+    } else if (equalIgnoringCase(mode, &quot;ForcedOnly&quot;)) {
+        captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::ForcedOnly);
+        document-&gt;page()-&gt;settings().setShouldDisplayCaptions(false);
+        document-&gt;page()-&gt;settings().setShouldDisplaySubtitles(false);
+    } else if (equalIgnoringCase(mode, &quot;AlwaysOn&quot;))
+        captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::AlwaysOn);
</ins><span class="cx">     else
</span><span class="cx">         ec = SYNTAX_ERR;
</span><span class="cx"> #else
</span></span></pre>
</div>
</div>

</body>
</html>