Commit 18e58e4a authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

Media Controls: Enable Gzip of CSS resources.

When we moved the CSS files to use "chrome_html" so we can embed
images we had to remove gzip because Grit doesn't support the
compress attribute on <structure> tags. This adds support for
the compress attribute and re-enables gzip in the media controls.

BUG=762902

Change-Id: I304d4c28c800f4977aaa3d975c4a456722bf601e
Reviewed-on: https://chromium-review.googlesource.com/692020
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505996}
parent d0f023bd
...@@ -40,13 +40,10 @@ MediaControlsResourceLoader::~MediaControlsResourceLoader(){}; ...@@ -40,13 +40,10 @@ MediaControlsResourceLoader::~MediaControlsResourceLoader(){};
#pragma GCC diagnostic ignored "-Wunknown-pragmas" #pragma GCC diagnostic ignored "-Wunknown-pragmas"
#endif #endif
String MediaControlsResourceLoader::GetMediaControlsCSS() const { String MediaControlsResourceLoader::GetMediaControlsCSS() const {
if (RuntimeEnabledFeatures::ModernMediaControlsEnabled()) { return ResourceBundleHelper::UncompressResourceAsString(
return ResourceBundleHelper::GetResourceAsString( RuntimeEnabledFeatures::ModernMediaControlsEnabled()
IDR_UASTYLE_MODERN_MEDIA_CONTROLS_CSS); ? IDR_UASTYLE_MODERN_MEDIA_CONTROLS_CSS
} else { : IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_CSS);
return ResourceBundleHelper::GetResourceAsString(
IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_CSS);
}
}; };
String MediaControlsResourceLoader::GetMediaControlsAndroidCSS() const { String MediaControlsResourceLoader::GetMediaControlsAndroidCSS() const {
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
<structure type="chrome_scaled_image" name="IDR_LEGACY_MEDIAPLAYER_OVERFLOW_MENU_ICON" file="legacy/mediaplayer_overflow_menu.png" /> <structure type="chrome_scaled_image" name="IDR_LEGACY_MEDIAPLAYER_OVERFLOW_MENU_ICON" file="legacy/mediaplayer_overflow_menu.png" />
<structure type="chrome_scaled_image" name="IDR_LEGACY_MEDIAPLAYER_DOWNLOAD_ICON" file="legacy/mediaplayer_download.png" /> <structure type="chrome_scaled_image" name="IDR_LEGACY_MEDIAPLAYER_DOWNLOAD_ICON" file="legacy/mediaplayer_download.png" />
<structure type="chrome_scaled_image" name="IDR_LEGACY_MEDIAPLAYER_SUBTITLES_ICON" file="legacy/mediaplayer_subtitles_icon.png" /> <structure type="chrome_scaled_image" name="IDR_LEGACY_MEDIAPLAYER_SUBTITLES_ICON" file="legacy/mediaplayer_subtitles_icon.png" />
<structure type="chrome_html" name="IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_CSS" file="legacyMediaControls.css" flattenhtml="true" /> <structure type="chrome_html" name="IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_CSS" file="legacyMediaControls.css" flattenhtml="true" compress="gzip" />
<structure type="chrome_html" name="IDR_UASTYLE_MODERN_MEDIA_CONTROLS_CSS" file="modernMediaControls.css" flattenhtml="true" /> <structure type="chrome_html" name="IDR_UASTYLE_MODERN_MEDIA_CONTROLS_CSS" file="modernMediaControls.css" flattenhtml="true" compress="gzip" />
</structures> </structures>
<includes> <includes>
<include name="IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_ANDROID_CSS" file="legacyMediaControlsAndroid.css" type="BINDATA" compress="gzip" /> <include name="IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_ANDROID_CSS" file="legacyMediaControlsAndroid.css" type="BINDATA" compress="gzip" />
......
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
import ast import ast
import os import os
import sys
import types import types
from xml.sax import saxutils from xml.sax import saxutils
from grit import clique from grit import clique
from grit import exception from grit import exception
from grit import util from grit import util
import grit.format.gzip_string
class Node(object): class Node(object):
...@@ -606,6 +608,26 @@ class Node(object): ...@@ -606,6 +608,26 @@ class Node(object):
from the root node.''' from the root node.'''
return False return False
def CompressDataIfNeeded(self, data):
'''Compress data using the format specified in the compress attribute.
Args:
data: The data to compressed.
Returns:
The data in compressed format. If the format was unknown or not supported
on the target platform then returns the data uncompressed.
'''
if (self.attrs.get('compress') != 'gzip'
or self.GetRoot().target_platform == 'ios'):
return data
# We only use rsyncable compression on Linux.
# We exclude ChromeOS since ChromeOS bots are Linux based but do not have
# the --rsyncable option built in for gzip. See crbug.com/617950.
if sys.platform == 'linux2' and 'chromeos' not in self.GetRoot().defines:
return grit.format.gzip_string.GzipStringRsyncable(data)
return grit.format.gzip_string.GzipString(data)
class ContentNode(Node): class ContentNode(Node):
'''Convenience baseclass for nodes that can have content.''' '''Convenience baseclass for nodes that can have content.'''
......
...@@ -7,11 +7,9 @@ ...@@ -7,11 +7,9 @@
""" """
import os import os
import sys
from grit import exception from grit import exception
from grit import util from grit import util
import grit.format.gzip_string
import grit.format.html_inline import grit.format.html_inline
import grit.format.rc import grit.format.rc
import grit.format.rc_header import grit.format.rc_header
...@@ -97,19 +95,10 @@ class IncludeNode(base.Node): ...@@ -97,19 +95,10 @@ class IncludeNode(base.Node):
# Note that the minifier will only do anything if a minifier command # Note that the minifier will only do anything if a minifier command
# has been set in the command line. # has been set in the command line.
data = minifier.Minify(data, filename) data = minifier.Minify(data, filename)
use_gzip = self.attrs.get('compress', '') == 'gzip'
if use_gzip and self.GetRoot().target_platform != 'ios':
# We only use rsyncable compression on Linux.
# We exclude ChromeOS since ChromeOS bots are Linux based but do not have
# the --rsyncable option built in for gzip. See crbug.com/617950.
if sys.platform == 'linux2' and 'chromeos' not in self.GetRoot().defines:
data = grit.format.gzip_string.GzipStringRsyncable(data)
else:
data = grit.format.gzip_string.GzipString(data)
# Include does not care about the encoding, because it only returns binary # Include does not care about the encoding, because it only returns binary
# data. # data.
return id, data return id, self.CompressDataIfNeeded(data)
def Process(self, output_dir): def Process(self, output_dir):
"""Rewrite file references to be base64 encoded data URLs. The new file """Rewrite file references to be base64 encoded data URLs. The new file
......
...@@ -150,6 +150,7 @@ class StructureNode(base.Node): ...@@ -150,6 +150,7 @@ class StructureNode(base.Node):
# dependencies. # dependencies.
'sconsdep' : 'false', 'sconsdep' : 'false',
'variables': '', 'variables': '',
'compress': 'false',
} }
def IsExcludedFromRc(self): def IsExcludedFromRc(self):
...@@ -205,8 +206,10 @@ class StructureNode(base.Node): ...@@ -205,8 +206,10 @@ class StructureNode(base.Node):
id = id_map[self.GetTextualIds()[0]] id = id_map[self.GetTextualIds()[0]]
if self.ExpandVariables(): if self.ExpandVariables():
text = self.gatherer.GetText() text = self.gatherer.GetText()
return id, util.Encode(self._Substitute(text), encoding) data = util.Encode(self._Substitute(text), encoding)
return id, self.gatherer.GetData(lang, encoding) else:
data = self.gatherer.GetData(lang, encoding)
return id, self.CompressDataIfNeeded(data)
def GetHtmlResourceFilenames(self): def GetHtmlResourceFilenames(self):
"""Returns a set of all filenames inlined by this node.""" """Returns a set of all filenames inlined by this node."""
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
import os import os
import os.path import os.path
import sys import sys
import zlib
if __name__ == '__main__': if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
...@@ -64,6 +65,35 @@ class StructureUnittest(unittest.TestCase): ...@@ -64,6 +65,35 @@ class StructureUnittest(unittest.TestCase):
' Hello!\n' ' Hello!\n'
'</p>\n'), result) '</p>\n'), result)
def testCompressGzip(self):
test_data_root = util.PathFromRoot('grit/testdata')
root = util.ParseGrdForUnittest('''
<structures>
<structure name="TEST_TXT" file="test_text.txt"
compress="gzip" type="chrome_html" />
</structures>''', base_dir=test_data_root)
struct, = root.GetChildrenOfType(structure.StructureNode)
struct.RunPreSubstitutionGatherer()
_, compressed = struct.GetDataPackPair(lang='en', encoding=1)
decompressed_data = zlib.decompress(compressed, 16 + zlib.MAX_WBITS)
self.assertEqual(util.ReadFile(
os.path.join(test_data_root, "test_text.txt"), util.BINARY),
decompressed_data)
def testNotCompressed(self):
test_data_root = util.PathFromRoot('grit/testdata')
root = util.ParseGrdForUnittest('''
<structures>
<structure name="TEST_TXT" file="test_text.txt" type="chrome_html" />
</structures>''', base_dir=test_data_root)
struct, = root.GetChildrenOfType(structure.StructureNode)
struct.RunPreSubstitutionGatherer()
_, data = struct.GetDataPackPair(lang='en', encoding=1)
self.assertEqual(util.ReadFile(
os.path.join(test_data_root, "test_text.txt"), util.BINARY), data)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment