Commit bfc2c547 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Introduce blink::Platform::GetDataResource(int, ui::ScaleFactor) and UncompressDataResource(int)

This is a preparation to remove Platform::GetDataResource(name).
This CL has no behavior changes.

Bug: 983396
Change-Id: Ia93d07a632a0ffbe4560694a413245fd385a3e10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760585
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688443}
parent bbea1a51
...@@ -461,6 +461,23 @@ WebData BlinkPlatformImpl::GetDataResource(const char* name) { ...@@ -461,6 +461,23 @@ WebData BlinkPlatformImpl::GetDataResource(const char* name) {
return WebData(); return WebData();
} }
WebData BlinkPlatformImpl::GetDataResource(int resource_id,
ui::ScaleFactor scale_factor) {
base::StringPiece resource =
GetContentClient()->GetDataResource(resource_id, scale_factor);
return WebData(resource.data(), resource.size());
}
WebData BlinkPlatformImpl::UncompressDataResource(int resource_id) {
base::StringPiece resource =
GetContentClient()->GetDataResource(resource_id, ui::SCALE_FACTOR_NONE);
if (resource.empty())
return WebData(resource.data(), resource.size());
std::string uncompressed;
CHECK(compression::GzipUncompress(resource.as_string(), &uncompressed));
return WebData(uncompressed.data(), uncompressed.size());
}
WebString BlinkPlatformImpl::QueryLocalizedString( WebString BlinkPlatformImpl::QueryLocalizedString(
WebLocalizedString::Name name) { WebLocalizedString::Name name) {
int message_id = ToMessageID(name); int message_id = ToMessageID(name);
......
...@@ -43,6 +43,9 @@ class CONTENT_EXPORT BlinkPlatformImpl : public blink::Platform { ...@@ -43,6 +43,9 @@ class CONTENT_EXPORT BlinkPlatformImpl : public blink::Platform {
void RecordAction(const blink::UserMetricsAction&) override; void RecordAction(const blink::UserMetricsAction&) override;
blink::WebData GetDataResource(const char* name) override; blink::WebData GetDataResource(const char* name) override;
blink::WebData GetDataResource(int resource_id,
ui::ScaleFactor scale_factor) override;
blink::WebData UncompressDataResource(int resource_id) override;
blink::WebString QueryLocalizedString( blink::WebString QueryLocalizedString(
blink::WebLocalizedString::Name name) override; blink::WebLocalizedString::Name name) override;
blink::WebString QueryLocalizedString(blink::WebLocalizedString::Name name, blink::WebString QueryLocalizedString(blink::WebLocalizedString::Name name,
......
...@@ -51,6 +51,7 @@ include_rules = [ ...@@ -51,6 +51,7 @@ include_rules = [
"+ui/base/ime/text_input_action.h", "+ui/base/ime/text_input_action.h",
"+ui/base/page_transition_types.h", "+ui/base/page_transition_types.h",
"+ui/base/cursor/types", "+ui/base/cursor/types",
"+ui/base/resource/scale_factor.h",
"+ui/events/types", "+ui/events/types",
"+ui/gfx", "+ui/gfx",
"+url", "+url",
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include "third_party/blink/public/platform/web_url_error.h" #include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_loader.h" #include "third_party/blink/public/platform/web_url_loader.h"
#include "third_party/blink/public/platform/web_url_loader_factory.h" #include "third_party/blink/public/platform/web_url_loader_factory.h"
#include "ui/base/resource/scale_factor.h"
namespace base { namespace base {
class SingleThreadTaskRunner; class SingleThreadTaskRunner;
...@@ -408,8 +409,24 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -408,8 +409,24 @@ class BLINK_PLATFORM_EXPORT Platform {
// Resources ----------------------------------------------------------- // Resources -----------------------------------------------------------
// Returns a blob of data corresponding to the named resource. // Returns a blob of data corresponding to the named resource.
// This is deprecated. Use GetDataResource(int, ...) or
// UncompressDataResource(int).
// TODO(crbug.com/983396): Remove this.
virtual WebData GetDataResource(const char* name) { return WebData(); } virtual WebData GetDataResource(const char* name) { return WebData(); }
// Returns a blob of data corresponding to |resource_id|. This should not be
// used for resources which have compress="gzip" in *.grd.
virtual WebData GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE) {
return WebData();
}
// Gets a blob of data resource corresponding to |resource_id|, then
// uncompresses it. This should be used for resources which have
// compress="gzip" in *.grd.
virtual WebData UncompressDataResource(int resource_id) { return WebData(); }
// Decodes the in-memory audio file data and returns the linear PCM audio data // Decodes the in-memory audio file data and returns the linear PCM audio data
// in the |destination_bus|. // in the |destination_bus|.
// Returns true on success. // Returns true on success.
......
...@@ -121,6 +121,18 @@ WebData TestingPlatformSupport::GetDataResource(const char* name) { ...@@ -121,6 +121,18 @@ WebData TestingPlatformSupport::GetDataResource(const char* name) {
return old_platform_ ? old_platform_->GetDataResource(name) : WebData(); return old_platform_ ? old_platform_->GetDataResource(name) : WebData();
} }
WebData TestingPlatformSupport::GetDataResource(int resource_id,
ui::ScaleFactor scale_factor) {
return old_platform_
? old_platform_->GetDataResource(resource_id, scale_factor)
: WebData();
}
WebData TestingPlatformSupport::UncompressDataResource(int resource_id) {
return old_platform_ ? old_platform_->UncompressDataResource(resource_id)
: WebData();
}
InterfaceProvider* TestingPlatformSupport::GetInterfaceProvider() { InterfaceProvider* TestingPlatformSupport::GetInterfaceProvider() {
return interface_provider_.get(); return interface_provider_.get();
} }
......
...@@ -67,6 +67,9 @@ class TestingPlatformSupport : public Platform { ...@@ -67,6 +67,9 @@ class TestingPlatformSupport : public Platform {
return std::make_unique<CodeCacheLoaderMock>(); return std::make_unique<CodeCacheLoaderMock>();
} }
WebData GetDataResource(const char* name) override; WebData GetDataResource(const char* name) override;
WebData GetDataResource(int resource_id,
ui::ScaleFactor scale_factor) override;
WebData UncompressDataResource(int resource_id) override;
InterfaceProvider* GetInterfaceProvider() override; InterfaceProvider* GetInterfaceProvider() override;
bool IsThreadedAnimationEnabled() override; bool IsThreadedAnimationEnabled() override;
......
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