Commit 989f5775 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Merge platform/media into data_resource_helper

These are helpers to retrieve resources from the bundle. We better
place them together.

Bug: none
Change-Id: I7613c84f7b36872b2fc8ed01e7a57e66e309f4b6
Reviewed-on: https://chromium-review.googlesource.com/c/1278958
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599698}
parent dcc6c2f2
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "third_party/blink/public/resources/grit/blink_resources.h" #include "third_party/blink/public/resources/grit/blink_resources.h"
#include "third_party/blink/renderer/platform/media/resource_bundle_helper.h" #include "third_party/blink/renderer/platform/data_resource_helper.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
namespace blink { namespace blink {
...@@ -115,7 +115,7 @@ String GetSourceText(const KURL& url) { ...@@ -115,7 +115,7 @@ String GetSourceText(const KURL& url) {
if (resource_id < 0) if (resource_id < 0)
return String(); return String();
return ResourceBundleHelper::GetResourceAsString(resource_id); return GetResourceAsString(resource_id);
} }
} // namespace layered_api } // namespace layered_api
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/modules/media_controls/resources/grit/media_controls_resources.h" #include "third_party/blink/renderer/modules/media_controls/resources/grit/media_controls_resources.h"
#include "third_party/blink/renderer/platform/media/resource_bundle_helper.h" #include "third_party/blink/renderer/platform/data_resource_helper.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
...@@ -31,7 +31,7 @@ MediaControlsResourceLoader::MediaControlsResourceLoader() ...@@ -31,7 +31,7 @@ MediaControlsResourceLoader::MediaControlsResourceLoader()
MediaControlsResourceLoader::~MediaControlsResourceLoader() = default; MediaControlsResourceLoader::~MediaControlsResourceLoader() = default;
String MediaControlsResourceLoader::GetMediaControlsCSS() const { String MediaControlsResourceLoader::GetMediaControlsCSS() const {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(
RuntimeEnabledFeatures::ModernMediaControlsEnabled() RuntimeEnabledFeatures::ModernMediaControlsEnabled()
? IDR_UASTYLE_MODERN_MEDIA_CONTROLS_CSS ? IDR_UASTYLE_MODERN_MEDIA_CONTROLS_CSS
: IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_CSS); : IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_CSS);
...@@ -40,56 +40,52 @@ String MediaControlsResourceLoader::GetMediaControlsCSS() const { ...@@ -40,56 +40,52 @@ String MediaControlsResourceLoader::GetMediaControlsCSS() const {
String MediaControlsResourceLoader::GetMediaControlsAndroidCSS() const { String MediaControlsResourceLoader::GetMediaControlsAndroidCSS() const {
if (RuntimeEnabledFeatures::ModernMediaControlsEnabled()) if (RuntimeEnabledFeatures::ModernMediaControlsEnabled())
return String(); return String();
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(
IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_ANDROID_CSS); IDR_UASTYLE_LEGACY_MEDIA_CONTROLS_ANDROID_CSS);
}; };
// static // static
String MediaControlsResourceLoader::GetShadowTimelineStyleSheet() { String MediaControlsResourceLoader::GetShadowTimelineStyleSheet() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(
IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_TIMELINE_CSS); IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_TIMELINE_CSS);
}; };
// static // static
String MediaControlsResourceLoader::GetShadowLoadingStyleSheet() { String MediaControlsResourceLoader::GetShadowLoadingStyleSheet() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(
IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_LOADING_CSS); IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_LOADING_CSS);
}; };
// static // static
String MediaControlsResourceLoader::GetJumpSVGImage() { String MediaControlsResourceLoader::GetJumpSVGImage() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(IDR_MODERN_MEDIA_CONTROLS_JUMP_SVG);
IDR_MODERN_MEDIA_CONTROLS_JUMP_SVG);
}; };
// static // static
String MediaControlsResourceLoader::GetArrowRightSVGImage() { String MediaControlsResourceLoader::GetArrowRightSVGImage() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(IDR_MODERN_MEDIA_CONTROLS_ARROW_RIGHT_SVG);
IDR_MODERN_MEDIA_CONTROLS_ARROW_RIGHT_SVG);
}; };
// static // static
String MediaControlsResourceLoader::GetArrowLeftSVGImage() { String MediaControlsResourceLoader::GetArrowLeftSVGImage() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(IDR_MODERN_MEDIA_CONTROLS_ARROW_LEFT_SVG);
IDR_MODERN_MEDIA_CONTROLS_ARROW_LEFT_SVG);
}; };
// static // static
String MediaControlsResourceLoader::GetScrubbingMessageStyleSheet() { String MediaControlsResourceLoader::GetScrubbingMessageStyleSheet() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(
IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_SCRUBBING_MESSAGE_CSS); IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_SCRUBBING_MESSAGE_CSS);
}; };
// static // static
String MediaControlsResourceLoader::GetAnimatedArrowStyleSheet() { String MediaControlsResourceLoader::GetAnimatedArrowStyleSheet() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(
IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_ANIMATED_ARROW_CSS); IDR_SHADOWSTYLE_MODERN_MEDIA_CONTROLS_ANIMATED_ARROW_CSS);
}; };
// static // static
String MediaControlsResourceLoader::GetMediaInterstitialsStyleSheet() { String MediaControlsResourceLoader::GetMediaInterstitialsStyleSheet() {
return ResourceBundleHelper::UncompressResourceAsString( return UncompressResourceAsString(IDR_UASTYLE_MEDIA_INTERSTITIALS_CSS);
IDR_UASTYLE_MEDIA_INTERSTITIALS_CSS);
}; };
String MediaControlsResourceLoader::GetUAStyleSheet() { String MediaControlsResourceLoader::GetUAStyleSheet() {
......
...@@ -1440,7 +1440,6 @@ jumbo_component("platform") { ...@@ -1440,7 +1440,6 @@ jumbo_component("platform") {
"//third_party/blink/renderer/platform/heap", "//third_party/blink/renderer/platform/heap",
"//third_party/blink/renderer/platform/instrumentation", "//third_party/blink/renderer/platform/instrumentation",
"//third_party/blink/renderer/platform/loader", "//third_party/blink/renderer/platform/loader",
"//third_party/blink/renderer/platform/media",
"//third_party/blink/renderer/platform/network", "//third_party/blink/renderer/platform/network",
"//third_party/blink/renderer/platform/scheduler", "//third_party/blink/renderer/platform/scheduler",
] ]
...@@ -1463,6 +1462,8 @@ jumbo_component("platform") { ...@@ -1463,6 +1462,8 @@ jumbo_component("platform") {
"//third_party/blink/public/common", "//third_party/blink/public/common",
"//third_party/ced", "//third_party/ced",
"//third_party/icu", "//third_party/icu",
"//third_party/zlib/google:compression_utils",
"//ui/base:base",
"//ui/gfx", "//ui/gfx",
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
......
...@@ -80,4 +80,8 @@ specific_include_rules = { ...@@ -80,4 +80,8 @@ specific_include_rules = {
"ukm_time_aggregator_test.cc" : [ "ukm_time_aggregator_test.cc" : [
"+components/ukm/test_ukm_recorder.h" "+components/ukm/test_ukm_recorder.h"
], ],
"data_resource_helper.cc" : [
"+third_party/zlib/google/compression_utils.h",
"+ui/base/resource",
],
} }
...@@ -7,9 +7,22 @@ ...@@ -7,9 +7,22 @@
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_data.h" #include "third_party/blink/public/platform/web_data.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/zlib/google/compression_utils.h"
#include "ui/base/resource/resource_bundle.h"
namespace blink { namespace blink {
namespace {
std::string GetResourceById(int resource_id) {
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
return bundle
.GetRawDataResourceForScale(resource_id, bundle.GetMaxScaleFactor())
.as_string();
}
} // namespace
String GetDataResourceAsASCIIString(const char* resource) { String GetDataResourceAsASCIIString(const char* resource) {
StringBuilder builder; StringBuilder builder;
const WebData& resource_data = Platform::Current()->GetDataResource(resource); const WebData& resource_data = Platform::Current()->GetDataResource(resource);
...@@ -27,4 +40,15 @@ String GetDataResourceAsASCIIString(const char* resource) { ...@@ -27,4 +40,15 @@ String GetDataResourceAsASCIIString(const char* resource) {
return data_string; return data_string;
} }
String GetResourceAsString(int resource_id) {
return String::FromUTF8(GetResourceById(resource_id).c_str());
};
String UncompressResourceAsString(int resource_id) {
std::string uncompressed;
CHECK(
compression::GzipUncompress(GetResourceById(resource_id), &uncompressed));
return String::FromUTF8(uncompressed.c_str());
}
} // namespace blink } // namespace blink
...@@ -10,8 +10,20 @@ ...@@ -10,8 +10,20 @@
namespace blink { namespace blink {
// Helper functions providing access to ui::ResourceBundle in Blink.
// Returns the contents of a resource as a string specified by the
// resource name.
PLATFORM_EXPORT String GetDataResourceAsASCIIString(const char* resource); PLATFORM_EXPORT String GetDataResourceAsASCIIString(const char* resource);
// Returns the contents of a resource as a string specified by the
// resource id from Grit.
PLATFORM_EXPORT String GetResourceAsString(int resource_id);
// Uncompresses a gzipped resource and returns it as a string. The resource
// is specified by the resource id from Grit.
PLATFORM_EXPORT String UncompressResourceAsString(int resource_id);
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_DATA_RESOURCE_HELPER_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_DATA_RESOURCE_HELPER_H_
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/blink/renderer/platform/platform.gni")
blink_platform_sources("media") {
sources = [
"resource_bundle_helper.cc",
"resource_bundle_helper.h",
]
deps = [
"//third_party/zlib/google:compression_utils",
"//ui/base:base",
]
}
include_rules = [
# Don't depend on platform/.
"-third_party/blink/renderer/platform",
# Module.
"+third_party/blink/renderer/platform/media",
# Dependencies.
"+third_party/blink/renderer/platform/platform_export.h",
"+third_party/blink/renderer/platform/wtf",
"+third_party/zlib/google/compression_utils.h",
"+ui/base/resource",
]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/media/resource_bundle_helper.h"
#include "third_party/zlib/google/compression_utils.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/resource_handle.h"
namespace {
std::string GetResource(int resource_id) {
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
return bundle
.GetRawDataResourceForScale(resource_id, bundle.GetMaxScaleFactor())
.as_string();
}
} // namespace.
namespace blink {
String ResourceBundleHelper::GetResourceAsString(int resource_id) {
return String::FromUTF8(GetResource(resource_id).c_str());
};
String ResourceBundleHelper::UncompressResourceAsString(int resource_id) {
std::string uncompressed;
CHECK(compression::GzipUncompress(GetResource(resource_id), &uncompressed));
return String::FromUTF8(uncompressed.c_str());
}
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_MEDIA_RESOURCE_BUNDLE_HELPER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_MEDIA_RESOURCE_BUNDLE_HELPER_H_
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
// Provides access to ui::ResourceBundle in Blink. This
// allows Blink to directly load resources from the bundle.
class ResourceBundleHelper {
STATIC_ONLY(ResourceBundleHelper);
public:
// Returns the contents of a resource as a string specified by the
// resource id from Grit.
static PLATFORM_EXPORT String GetResourceAsString(int resource_id);
// Uncompresses a gzipped resource and returns it as a string. The resource
// is specified by the resource id from Grit.
static PLATFORM_EXPORT String UncompressResourceAsString(int resource_id);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_MEDIA_RESOURCE_BUNDLE_HELPER_H_
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