Commit 33cff1d8 authored by oshima@chromium.org's avatar oshima@chromium.org

Reduce the use of ui::ScaleFactor in webui/favicon

First step for renaming ui::ScaleFactor to ui::ResourceScaleFactor

BUG=372212
R=pkotwicz@chromium.org, sky@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271909 0039d316-1c4b-4281-b951-d872f2087c98
parent a686b386
...@@ -149,10 +149,11 @@ void LocalNtpSource::StartDataRequest( ...@@ -149,10 +149,11 @@ void LocalNtpSource::StartDataRequest(
callback.Run(base::RefCountedString::TakeString(&config_data_js)); callback.Run(base::RefCountedString::TakeString(&config_data_js));
return; return;
} }
ui::ScaleFactor scale_factor; float scale = 1.0f;
std::string filename; std::string filename;
webui::ParsePathAndScale( webui::ParsePathAndScale(
GURL(GetLocalNtpPath() + stripped_path), &filename, &scale_factor); GURL(GetLocalNtpPath() + stripped_path), &filename, &scale);
ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale);
for (size_t i = 0; i < arraysize(kResources); ++i) { for (size_t i = 0; i < arraysize(kResources); ++i) {
if (filename == kResources[i].filename) { if (filename == kResources[i].filename) {
scoped_refptr<base::RefCountedStaticMemory> response( scoped_refptr<base::RefCountedStaticMemory> response(
......
...@@ -79,6 +79,8 @@ void FaviconSource::StartDataRequest( ...@@ -79,6 +79,8 @@ void FaviconSource::StartDataRequest(
GURL url(parsed.url); GURL url(parsed.url);
ui::ScaleFactor scale_factor =
ui::GetSupportedScaleFactor(parsed.scale_factor);
if (parsed.is_icon_url) { if (parsed.is_icon_url) {
// TODO(michaelbai): Change GetRawFavicon to support combination of // TODO(michaelbai): Change GetRawFavicon to support combination of
// IconType. // IconType.
...@@ -86,11 +88,11 @@ void FaviconSource::StartDataRequest( ...@@ -86,11 +88,11 @@ void FaviconSource::StartDataRequest(
url, url,
favicon_base::FAVICON, favicon_base::FAVICON,
parsed.size_in_dip, parsed.size_in_dip,
parsed.scale_factor, scale_factor,
base::Bind(&FaviconSource::OnFaviconDataAvailable, base::Bind(&FaviconSource::OnFaviconDataAvailable,
base::Unretained(this), base::Unretained(this),
IconRequest( IconRequest(
callback, url, parsed.size_in_dip, parsed.scale_factor)), callback, url, parsed.size_in_dip, scale_factor)),
&cancelable_task_tracker_); &cancelable_task_tracker_);
} else { } else {
// Intercept requests for prepopulated pages. // Intercept requests for prepopulated pages.
...@@ -100,7 +102,7 @@ void FaviconSource::StartDataRequest( ...@@ -100,7 +102,7 @@ void FaviconSource::StartDataRequest(
callback.Run( callback.Run(
ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
history::kPrepopulatedPages[i].favicon_id, history::kPrepopulatedPages[i].favicon_id,
parsed.scale_factor)); scale_factor));
return; return;
} }
} }
...@@ -108,13 +110,13 @@ void FaviconSource::StartDataRequest( ...@@ -108,13 +110,13 @@ void FaviconSource::StartDataRequest(
favicon_service->GetRawFaviconForURL( favicon_service->GetRawFaviconForURL(
FaviconService::FaviconForURLParams(url, icon_types_, FaviconService::FaviconForURLParams(url, icon_types_,
parsed.size_in_dip), parsed.size_in_dip),
parsed.scale_factor, scale_factor,
base::Bind(&FaviconSource::OnFaviconDataAvailable, base::Bind(&FaviconSource::OnFaviconDataAvailable,
base::Unretained(this), base::Unretained(this),
IconRequest(callback, IconRequest(callback,
url, url,
parsed.size_in_dip, parsed.size_in_dip,
parsed.scale_factor)), scale_factor)),
&cancelable_task_tracker_); &cancelable_task_tracker_);
} }
} }
...@@ -192,9 +194,9 @@ void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { ...@@ -192,9 +194,9 @@ void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) {
default_favicons_[favicon_index].get(); default_favicons_[favicon_index].get();
if (!default_favicon) { if (!default_favicon) {
ui::ScaleFactor scale_factor = icon_request.scale_factor;
default_favicon = ResourceBundle::GetSharedInstance() default_favicon = ResourceBundle::GetSharedInstance()
.LoadDataResourceBytesForScale(resource_id, scale_factor); .LoadDataResourceBytesForScale(resource_id,
icon_request.scale_factor);
default_favicons_[favicon_index] = default_favicon; default_favicons_[favicon_index] = default_favicon;
} }
......
...@@ -62,14 +62,14 @@ IconLoader::IconSize SizeStringToIconSize(const std::string& size_string) { ...@@ -62,14 +62,14 @@ IconLoader::IconSize SizeStringToIconSize(const std::string& size_string) {
// Simple parser for data on the query. // Simple parser for data on the query.
void ParseQueryParams(const std::string& query, void ParseQueryParams(const std::string& query,
ui::ScaleFactor* scale_factor, float* scale_factor,
IconLoader::IconSize* icon_size) { IconLoader::IconSize* icon_size) {
typedef std::pair<std::string, std::string> KVPair; typedef std::pair<std::string, std::string> KVPair;
std::vector<KVPair> parameters; std::vector<KVPair> parameters;
if (icon_size) if (icon_size)
*icon_size = IconLoader::NORMAL; *icon_size = IconLoader::NORMAL;
if (scale_factor) if (scale_factor)
*scale_factor = ui::SCALE_FACTOR_100P; *scale_factor = 1.0f;
base::SplitStringIntoKeyValuePairs(query, '=', '&', &parameters); base::SplitStringIntoKeyValuePairs(query, '=', '&', &parameters);
for (std::vector<KVPair>::const_iterator iter = parameters.begin(); for (std::vector<KVPair>::const_iterator iter = parameters.begin();
iter != parameters.end(); ++iter) { iter != parameters.end(); ++iter) {
...@@ -82,7 +82,7 @@ void ParseQueryParams(const std::string& query, ...@@ -82,7 +82,7 @@ void ParseQueryParams(const std::string& query,
} // namespace } // namespace
FileIconSource::IconRequestDetails::IconRequestDetails() { FileIconSource::IconRequestDetails::IconRequestDetails() : scale_factor(1.0f) {
} }
FileIconSource::IconRequestDetails::~IconRequestDetails() { FileIconSource::IconRequestDetails::~IconRequestDetails() {
...@@ -94,7 +94,7 @@ FileIconSource::~FileIconSource() {} ...@@ -94,7 +94,7 @@ FileIconSource::~FileIconSource() {}
void FileIconSource::FetchFileIcon( void FileIconSource::FetchFileIcon(
const base::FilePath& path, const base::FilePath& path,
ui::ScaleFactor scale_factor, float scale_factor,
IconLoader::IconSize icon_size, IconLoader::IconSize icon_size,
const content::URLDataSource::GotDataCallback& callback) { const content::URLDataSource::GotDataCallback& callback) {
IconManager* im = g_browser_process->icon_manager(); IconManager* im = g_browser_process->icon_manager();
...@@ -103,9 +103,9 @@ void FileIconSource::FetchFileIcon( ...@@ -103,9 +103,9 @@ void FileIconSource::FetchFileIcon(
if (icon) { if (icon) {
scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
gfx::PNGCodec::EncodeBGRASkBitmap( gfx::PNGCodec::EncodeBGRASkBitmap(
icon->ToImageSkia()->GetRepresentation( icon->ToImageSkia()->GetRepresentation(scale_factor).sk_bitmap(),
ui::GetImageScale(scale_factor)).sk_bitmap(), false,
false, &icon_data->data()); &icon_data->data());
callback.Run(icon_data.get()); callback.Run(icon_data.get());
} else { } else {
...@@ -134,8 +134,8 @@ void FileIconSource::StartDataRequest( ...@@ -134,8 +134,8 @@ void FileIconSource::StartDataRequest(
const content::URLDataSource::GotDataCallback& callback) { const content::URLDataSource::GotDataCallback& callback) {
std::string query; std::string query;
base::FilePath file_path; base::FilePath file_path;
ui::ScaleFactor scale_factor;
IconLoader::IconSize icon_size; IconLoader::IconSize icon_size;
float scale_factor = 1.0f;
GetFilePathAndQuery(url_path, &file_path, &query); GetFilePathAndQuery(url_path, &file_path, &query);
ParseQueryParams(query, &scale_factor, &icon_size); ParseQueryParams(query, &scale_factor, &icon_size);
FetchFileIcon(file_path, scale_factor, icon_size, callback); FetchFileIcon(file_path, scale_factor, icon_size, callback);
...@@ -152,7 +152,7 @@ void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details, ...@@ -152,7 +152,7 @@ void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details,
scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
gfx::PNGCodec::EncodeBGRASkBitmap( gfx::PNGCodec::EncodeBGRASkBitmap(
icon->ToImageSkia()->GetRepresentation( icon->ToImageSkia()->GetRepresentation(
ui::GetImageScale(details.scale_factor)).sk_bitmap(), details.scale_factor).sk_bitmap(),
false, false,
&icon_data->data()); &icon_data->data());
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/icon_manager.h" #include "chrome/browser/icon_manager.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "ui/base/layout.h"
namespace gfx { namespace gfx {
class Image; class Image;
...@@ -40,7 +39,7 @@ class FileIconSource : public content::URLDataSource { ...@@ -40,7 +39,7 @@ class FileIconSource : public content::URLDataSource {
// testing. // testing.
virtual void FetchFileIcon( virtual void FetchFileIcon(
const base::FilePath& path, const base::FilePath& path,
ui::ScaleFactor scale_factor, float scale_factor,
IconLoader::IconSize icon_size, IconLoader::IconSize icon_size,
const content::URLDataSource::GotDataCallback& callback); const content::URLDataSource::GotDataCallback& callback);
...@@ -54,7 +53,7 @@ class FileIconSource : public content::URLDataSource { ...@@ -54,7 +53,7 @@ class FileIconSource : public content::URLDataSource {
content::URLDataSource::GotDataCallback callback; content::URLDataSource::GotDataCallback callback;
// The requested scale factor to respond with. // The requested scale factor to respond with.
ui::ScaleFactor scale_factor; float scale_factor;
}; };
// Called when favicon data is available from the history backend. // Called when favicon data is available from the history backend.
......
...@@ -22,7 +22,7 @@ class TestFileIconSource : public FileIconSource { ...@@ -22,7 +22,7 @@ class TestFileIconSource : public FileIconSource {
MOCK_METHOD4(FetchFileIcon, MOCK_METHOD4(FetchFileIcon,
void(const base::FilePath& path, void(const base::FilePath& path,
ui::ScaleFactor scale_factor, float scale_factor,
IconLoader::IconSize icon_size, IconLoader::IconSize icon_size,
const content::URLDataSource::GotDataCallback& callback)); const content::URLDataSource::GotDataCallback& callback));
...@@ -48,64 +48,51 @@ class FileIconSourceTest : public testing::Test { ...@@ -48,64 +48,51 @@ class FileIconSourceTest : public testing::Test {
const struct FetchFileIconExpectation { const struct FetchFileIconExpectation {
const char* request_path; const char* request_path;
const base::FilePath::CharType* unescaped_path; const base::FilePath::CharType* unescaped_path;
ui::ScaleFactor scale_factor; float scale_factor;
IconLoader::IconSize size; IconLoader::IconSize size;
} kBasicExpectations[] = { } kBasicExpectations[] = {
{ "foo?bar", FILE_PATH_LITERAL("foo"), ui::SCALE_FACTOR_100P, { "foo?bar", FILE_PATH_LITERAL("foo"), 1.0f, IconLoader::NORMAL },
IconLoader::NORMAL }, { "foo?bar&scale=2x", FILE_PATH_LITERAL("foo"), 2.0f, IconLoader::NORMAL },
{ "foo?bar&scale=2x", FILE_PATH_LITERAL("foo"), ui::SCALE_FACTOR_200P, { "foo?iconsize=small", FILE_PATH_LITERAL("foo"), 1.0f, IconLoader::SMALL },
IconLoader::NORMAL }, { "foo?iconsize=normal", FILE_PATH_LITERAL("foo"), 1.0f, IconLoader::NORMAL },
{ "foo?iconsize=small", FILE_PATH_LITERAL("foo"), ui::SCALE_FACTOR_100P, { "foo?iconsize=large", FILE_PATH_LITERAL("foo"), 1.0f, IconLoader::LARGE },
{ "foo?iconsize=asdf", FILE_PATH_LITERAL("foo"), 1.0f, IconLoader::NORMAL },
{ "foo?blah=b&iconsize=small", FILE_PATH_LITERAL("foo"), 1.0f,
IconLoader::SMALL }, IconLoader::SMALL },
{ "foo?iconsize=normal", FILE_PATH_LITERAL("foo"), ui::SCALE_FACTOR_100P, { "foo?blah&iconsize=small", FILE_PATH_LITERAL("foo"), 1.0f,
IconLoader::NORMAL }, IconLoader::SMALL },
{ "foo?iconsize=large", FILE_PATH_LITERAL("foo"), ui::SCALE_FACTOR_100P, { "a%3Fb%26c%3Dd.txt?iconsize=small", FILE_PATH_LITERAL("a?b&c=d.txt"), 1.0f,
IconLoader::LARGE },
{ "foo?iconsize=asdf", FILE_PATH_LITERAL("foo"), ui::SCALE_FACTOR_100P,
IconLoader::NORMAL },
{ "foo?blah=b&iconsize=small", FILE_PATH_LITERAL("foo"),
ui::SCALE_FACTOR_100P, IconLoader::SMALL },
{ "foo?blah&iconsize=small", FILE_PATH_LITERAL("foo"), ui::SCALE_FACTOR_100P,
IconLoader::SMALL }, IconLoader::SMALL },
{ "a%3Fb%26c%3Dd.txt?iconsize=small", FILE_PATH_LITERAL("a?b&c=d.txt"),
ui::SCALE_FACTOR_100P, IconLoader::SMALL },
{ "a%3Ficonsize%3Dsmall?iconsize=large", { "a%3Ficonsize%3Dsmall?iconsize=large",
FILE_PATH_LITERAL("a?iconsize=small"), ui::SCALE_FACTOR_100P, FILE_PATH_LITERAL("a?iconsize=small"), 1.0f, IconLoader::LARGE },
IconLoader::LARGE },
{ "o%40%23%24%25%26*()%20%2B%3D%3F%2C%3A%3B%22.jpg", { "o%40%23%24%25%26*()%20%2B%3D%3F%2C%3A%3B%22.jpg",
FILE_PATH_LITERAL("o@#$%&*() +=?,:;\".jpg"), ui::SCALE_FACTOR_100P, FILE_PATH_LITERAL("o@#$%&*() +=?,:;\".jpg"), 1.0f, IconLoader::NORMAL },
IconLoader::NORMAL },
#if defined(OS_WIN) #if defined(OS_WIN)
{ "c:/foo/bar/baz", FILE_PATH_LITERAL("c:\\foo\\bar\\baz"), { "c:/foo/bar/baz", FILE_PATH_LITERAL("c:\\foo\\bar\\baz"), 1.0f,
ui::SCALE_FACTOR_100P, IconLoader::NORMAL }, IconLoader::NORMAL },
{ "/foo?bar=asdf&asdf", FILE_PATH_LITERAL("\\foo"), ui::SCALE_FACTOR_100P, { "/foo?bar=asdf&asdf", FILE_PATH_LITERAL("\\foo"), 1.0f,
IconLoader::NORMAL }, IconLoader::NORMAL },
{ "c%3A%2Fusers%2Ffoo%20user%2Fbar.txt", { "c%3A%2Fusers%2Ffoo%20user%2Fbar.txt",
FILE_PATH_LITERAL("c:\\users\\foo user\\bar.txt"), ui::SCALE_FACTOR_100P, FILE_PATH_LITERAL("c:\\users\\foo user\\bar.txt"), 1.0f,
IconLoader::NORMAL }, IconLoader::NORMAL },
{ "c%3A%2Fusers%2F%C2%A9%202000.pdf", { "c%3A%2Fusers%2F%C2%A9%202000.pdf",
FILE_PATH_LITERAL("c:\\users\\\xa9 2000.pdf"), ui::SCALE_FACTOR_100P, FILE_PATH_LITERAL("c:\\users\\\xa9 2000.pdf"), 1.0f, IconLoader::NORMAL },
IconLoader::NORMAL },
{ "%E0%B6%9A%E0%B6%BB%E0%B7%9D%E0%B6%B8%E0%B7%8A", { "%E0%B6%9A%E0%B6%BB%E0%B7%9D%E0%B6%B8%E0%B7%8A",
FILE_PATH_LITERAL("\x0d9a\x0dbb\x0ddd\x0db8\x0dca"), ui::SCALE_FACTOR_100P, FILE_PATH_LITERAL("\x0d9a\x0dbb\x0ddd\x0db8\x0dca"), 1.0f,
IconLoader::NORMAL },
{ "%2Ffoo%2Fbar", FILE_PATH_LITERAL("\\foo\\bar"), ui::SCALE_FACTOR_100P,
IconLoader::NORMAL }, IconLoader::NORMAL },
{ "%2Ffoo%2Fbar", FILE_PATH_LITERAL("\\foo\\bar"), 1.0f, IconLoader::NORMAL },
{ "%2Fbaz%20(1).txt?iconsize=small", FILE_PATH_LITERAL("\\baz (1).txt"), { "%2Fbaz%20(1).txt?iconsize=small", FILE_PATH_LITERAL("\\baz (1).txt"),
ui::SCALE_FACTOR_100P, IconLoader::SMALL }, 1.0f, IconLoader::SMALL },
#else #else
{ "/foo/bar/baz", FILE_PATH_LITERAL("/foo/bar/baz"), ui::SCALE_FACTOR_100P, { "/foo/bar/baz", FILE_PATH_LITERAL("/foo/bar/baz"), 1.0f,
IconLoader::NORMAL },
{ "/foo?bar", FILE_PATH_LITERAL("/foo"), ui::SCALE_FACTOR_100P,
IconLoader::NORMAL }, IconLoader::NORMAL },
{ "/foo?bar", FILE_PATH_LITERAL("/foo"), 1.0f, IconLoader::NORMAL },
{ "%2Ffoo%2f%E0%B6%9A%E0%B6%BB%E0%B7%9D%E0%B6%B8%E0%B7%8A", { "%2Ffoo%2f%E0%B6%9A%E0%B6%BB%E0%B7%9D%E0%B6%B8%E0%B7%8A",
FILE_PATH_LITERAL("/foo/\xe0\xb6\x9a\xe0\xb6\xbb\xe0\xb7\x9d") FILE_PATH_LITERAL("/foo/\xe0\xb6\x9a\xe0\xb6\xbb\xe0\xb7\x9d")
FILE_PATH_LITERAL("\xe0\xb6\xb8\xe0\xb7\x8a"), ui::SCALE_FACTOR_100P, FILE_PATH_LITERAL("\xe0\xb6\xb8\xe0\xb7\x8a"), 1.0f, IconLoader::NORMAL },
IconLoader::NORMAL }, { "%2Ffoo%2Fbar", FILE_PATH_LITERAL("/foo/bar"), 1.0f, IconLoader::NORMAL },
{ "%2Ffoo%2Fbar", FILE_PATH_LITERAL("/foo/bar"), ui::SCALE_FACTOR_100P, { "%2Fbaz%20(1).txt?iconsize=small", FILE_PATH_LITERAL("/baz (1).txt"), 1.0f,
IconLoader::NORMAL }, IconLoader::SMALL },
{ "%2Fbaz%20(1).txt?iconsize=small", FILE_PATH_LITERAL("/baz (1).txt"),
ui::SCALE_FACTOR_100P, IconLoader::SMALL },
#endif #endif
}; };
......
...@@ -62,7 +62,7 @@ void ThemeSource::StartDataRequest( ...@@ -62,7 +62,7 @@ void ThemeSource::StartDataRequest(
int render_frame_id, int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) { const content::URLDataSource::GotDataCallback& callback) {
// Default scale factor if not specified. // Default scale factor if not specified.
ui::ScaleFactor scale_factor; float scale_factor = 1.0f;
std::string uncached_path; std::string uncached_path;
webui::ParsePathAndScale(GURL(GetThemePath() + path), webui::ParsePathAndScale(GURL(GetThemePath() + path),
&uncached_path, &uncached_path,
...@@ -137,18 +137,21 @@ bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const { ...@@ -137,18 +137,21 @@ bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const {
void ThemeSource::SendThemeBitmap( void ThemeSource::SendThemeBitmap(
const content::URLDataSource::GotDataCallback& callback, const content::URLDataSource::GotDataCallback& callback,
int resource_id, int resource_id,
ui::ScaleFactor scale_factor) { float scale_factor) {
ui::ScaleFactor resource_scale_factor =
ui::GetSupportedScaleFactor(scale_factor);
if (ThemeProperties::IsThemeableImage(resource_id)) { if (ThemeProperties::IsThemeableImage(resource_id)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
DCHECK(tp); DCHECK(tp);
scoped_refptr<base::RefCountedMemory> image_data(tp->GetRawData( scoped_refptr<base::RefCountedMemory> image_data(
resource_id, scale_factor)); tp->GetRawData(resource_id, resource_scale_factor));
callback.Run(image_data.get()); callback.Run(image_data.get());
} else { } else {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
callback.Run(rb.LoadDataResourceBytesForScale(resource_id, scale_factor)); callback.Run(
rb.LoadDataResourceBytesForScale(resource_id, resource_scale_factor));
} }
} }
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "ui/base/layout.h"
class Profile; class Profile;
...@@ -39,10 +38,9 @@ class ThemeSource : public content::URLDataSource { ...@@ -39,10 +38,9 @@ class ThemeSource : public content::URLDataSource {
private: private:
// Fetch and send the theme bitmap. // Fetch and send the theme bitmap.
void SendThemeBitmap( void SendThemeBitmap(const content::URLDataSource::GotDataCallback& callback,
const content::URLDataSource::GotDataCallback& callback, int resource_id,
int resource_id, float scale_factor);
ui::ScaleFactor scale_factor);
// The original profile (never an OTR profile). // The original profile (never an OTR profile).
Profile* profile_; Profile* profile_;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "components/favicon_base/favicon_types.h" #include "components/favicon_base/favicon_types.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "ui/base/layout.h"
#include "ui/base/webui/web_ui_util.h" #include "ui/base/webui/web_ui_util.h"
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
...@@ -39,7 +38,7 @@ bool ParseFaviconPath(const std::string& path, ...@@ -39,7 +38,7 @@ bool ParseFaviconPath(const std::string& path,
parsed->is_icon_url = false; parsed->is_icon_url = false;
parsed->url = ""; parsed->url = "";
parsed->size_in_dip = gfx::kFaviconSize; parsed->size_in_dip = gfx::kFaviconSize;
parsed->scale_factor = ui::SCALE_FACTOR_100P; parsed->scale_factor = 1.0f;
parsed->path_index = -1; parsed->path_index = -1;
if (path.empty()) if (path.empty())
...@@ -77,7 +76,6 @@ bool ParseFaviconPath(const std::string& path, ...@@ -77,7 +76,6 @@ bool ParseFaviconPath(const std::string& path,
// Only 64x64, 32x32 and 16x16 icons are supported. // Only 64x64, 32x32 and 16x16 icons are supported.
parsed->size_in_dip = gfx::kFaviconSize; parsed->size_in_dip = gfx::kFaviconSize;
} }
if (!scale_str.empty()) if (!scale_str.empty())
webui::ParseScaleFactor(scale_str, &parsed->scale_factor); webui::ParseScaleFactor(scale_str, &parsed->scale_factor);
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include <string> #include <string>
#include "ui/base/layout.h"
namespace chrome { namespace chrome {
struct ParsedFaviconPath { struct ParsedFaviconPath {
...@@ -22,7 +20,7 @@ struct ParsedFaviconPath { ...@@ -22,7 +20,7 @@ struct ParsedFaviconPath {
int size_in_dip; int size_in_dip;
// The scale factor of the requested favicon. // The scale factor of the requested favicon.
ui::ScaleFactor scale_factor; float scale_factor;
// The index of the first character (relative to the path) where the the URL // The index of the first character (relative to the path) where the the URL
// from which the favicon is being requested is located. // from which the favicon is being requested is located.
......
...@@ -58,7 +58,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) { ...@@ -58,7 +58,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) {
EXPECT_FALSE(parsed.is_icon_url); EXPECT_FALSE(parsed.is_icon_url);
EXPECT_EQ(url, parsed.url); EXPECT_EQ(url, parsed.url);
EXPECT_EQ(32, parsed.size_in_dip); EXPECT_EQ(32, parsed.size_in_dip);
EXPECT_EQ(ui::SCALE_FACTOR_100P, parsed.scale_factor); EXPECT_EQ(1.0f, parsed.scale_factor);
// Test parsing current 'size' parameter format. // Test parsing current 'size' parameter format.
const std::string path3 = "size/32@1.4x/" + url; const std::string path3 = "size/32@1.4x/" + url;
...@@ -66,7 +66,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) { ...@@ -66,7 +66,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) {
EXPECT_FALSE(parsed.is_icon_url); EXPECT_FALSE(parsed.is_icon_url);
EXPECT_EQ(url, parsed.url); EXPECT_EQ(url, parsed.url);
EXPECT_EQ(32, parsed.size_in_dip); EXPECT_EQ(32, parsed.size_in_dip);
EXPECT_EQ(ui::SCALE_FACTOR_140P, parsed.scale_factor); EXPECT_EQ(1.4f, parsed.scale_factor);
// Test that we pick the ui::ScaleFactor which is closest to the passed in // Test that we pick the ui::ScaleFactor which is closest to the passed in
// scale factor. // scale factor.
...@@ -75,7 +75,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) { ...@@ -75,7 +75,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) {
EXPECT_FALSE(parsed.is_icon_url); EXPECT_FALSE(parsed.is_icon_url);
EXPECT_EQ(url, parsed.url); EXPECT_EQ(url, parsed.url);
EXPECT_EQ(16, parsed.size_in_dip); EXPECT_EQ(16, parsed.size_in_dip);
EXPECT_EQ(ui::SCALE_FACTOR_140P, parsed.scale_factor); EXPECT_EQ(1.41f, parsed.scale_factor);
// Invalid cases. // Invalid cases.
const std::string path5 = "size/" + url; const std::string path5 = "size/" + url;
...@@ -91,7 +91,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) { ...@@ -91,7 +91,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParam) {
EXPECT_FALSE(parsed.is_icon_url); EXPECT_FALSE(parsed.is_icon_url);
EXPECT_EQ(path8, parsed.url); EXPECT_EQ(path8, parsed.url);
EXPECT_EQ(16, parsed.size_in_dip); EXPECT_EQ(16, parsed.size_in_dip);
EXPECT_EQ(ui::SCALE_FACTOR_100P, parsed.scale_factor); EXPECT_EQ(1.0f, parsed.scale_factor);
} }
// Test parsing path with the 'largest' parameter. // Test parsing path with the 'largest' parameter.
...@@ -155,7 +155,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParamAndUrlModifier) { ...@@ -155,7 +155,7 @@ TEST_F(FaviconUrlParserTest, ParsingSizeParamAndUrlModifier) {
EXPECT_FALSE(parsed.is_icon_url); EXPECT_FALSE(parsed.is_icon_url);
EXPECT_EQ("https://www.google.ca/", parsed.url); EXPECT_EQ("https://www.google.ca/", parsed.url);
EXPECT_EQ(32, parsed.size_in_dip); EXPECT_EQ(32, parsed.size_in_dip);
EXPECT_EQ(ui::SCALE_FACTOR_140P, parsed.scale_factor); EXPECT_EQ(1.4f, parsed.scale_factor);
const std::string path14 = const std::string path14 =
"largest/iconurl/http://www.google.com/favicon.ico"; "largest/iconurl/http://www.google.com/favicon.ico";
......
...@@ -76,8 +76,8 @@ WindowOpenDisposition GetDispositionFromClick(const base::ListValue* args, ...@@ -76,8 +76,8 @@ WindowOpenDisposition GetDispositionFromClick(const base::ListValue* args,
} }
bool ParseScaleFactor(const base::StringPiece& identifier, bool ParseScaleFactor(const base::StringPiece& identifier,
ui::ScaleFactor* scale_factor) { float* scale_factor) {
*scale_factor = ui::SCALE_FACTOR_100P; *scale_factor = 1.0f;
if (identifier.empty()) { if (identifier.empty()) {
LOG(WARNING) << "Invalid scale factor format: " << identifier; LOG(WARNING) << "Invalid scale factor format: " << identifier;
return false; return false;
...@@ -95,25 +95,24 @@ bool ParseScaleFactor(const base::StringPiece& identifier, ...@@ -95,25 +95,24 @@ bool ParseScaleFactor(const base::StringPiece& identifier,
LOG(WARNING) << "Invalid scale factor format: " << identifier; LOG(WARNING) << "Invalid scale factor format: " << identifier;
return false; return false;
} }
*scale_factor = scale;
*scale_factor = ui::GetSupportedScaleFactor(static_cast<float>(scale));
return true; return true;
} }
void ParsePathAndScale(const GURL& url, void ParsePathAndScale(const GURL& url,
std::string* path, std::string* path,
ui::ScaleFactor* scale_factor) { float* scale_factor) {
*path = net::UnescapeURLComponent(url.path().substr(1), *path = net::UnescapeURLComponent(url.path().substr(1),
(net::UnescapeRule::URL_SPECIAL_CHARS | (net::UnescapeRule::URL_SPECIAL_CHARS |
net::UnescapeRule::SPACES)); net::UnescapeRule::SPACES));
if (scale_factor) if (scale_factor)
*scale_factor = ui::SCALE_FACTOR_100P; *scale_factor = 1.0f;
// Detect and parse resource string ending in @<scale>x. // Detect and parse resource string ending in @<scale>x.
std::size_t pos = path->rfind('@'); std::size_t pos = path->rfind('@');
if (pos != std::string::npos) { if (pos != std::string::npos) {
base::StringPiece stripped_path(*path); base::StringPiece stripped_path(*path);
ui::ScaleFactor factor; float factor;
if (ParseScaleFactor(stripped_path.substr( if (ParseScaleFactor(stripped_path.substr(
pos + 1, stripped_path.length() - pos - 1), &factor)) { pos + 1, stripped_path.length() - pos - 1), &factor)) {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/values.h" #include "base/values.h"
#include "ui/base/layout.h"
#include "ui/base/ui_base_export.h" #include "ui/base/ui_base_export.h"
#include "ui/base/window_open_disposition.h" #include "ui/base/window_open_disposition.h"
...@@ -36,18 +35,15 @@ UI_BASE_EXPORT std::string GetBitmapDataUrlFromResource(int resource_id); ...@@ -36,18 +35,15 @@ UI_BASE_EXPORT std::string GetBitmapDataUrlFromResource(int resource_id);
UI_BASE_EXPORT WindowOpenDisposition UI_BASE_EXPORT WindowOpenDisposition
GetDispositionFromClick(const base::ListValue* args, int start_index); GetDispositionFromClick(const base::ListValue* args, int start_index);
// Given a scale factor such as "1x", "2x" or "1.99x", sets |scale_factor| to // Pares a formatted scale factor string into float and sets to |scale_factor|.
// the closest ScaleFactor enum value for this scale factor. If string can not
// be parsed, then |scale_factor| is set to SCALE_FACTOR_100P, and false is
// returned.
UI_BASE_EXPORT bool ParseScaleFactor(const base::StringPiece& identifier, UI_BASE_EXPORT bool ParseScaleFactor(const base::StringPiece& identifier,
ui::ScaleFactor* scale_factor); float* scale_factor);
// Parses a URL containing some path @{scale}x. If it does not contain a scale // Parses a URL containing some path @{scale}x. If it does not contain a scale
// factor then the default scale factor is returned. // factor then the default scale factor is returned.
UI_BASE_EXPORT void ParsePathAndScale(const GURL& url, UI_BASE_EXPORT void ParsePathAndScale(const GURL& url,
std::string* path, std::string* path,
ui::ScaleFactor* scale_factor); float* scale_factor);
// Helper function to set the font family, size, and text direction into the // Helper function to set the font family, size, and text direction into the
// given dictionary. // given dictionary.
......
...@@ -8,48 +8,47 @@ ...@@ -8,48 +8,47 @@
#include "url/gurl.h" #include "url/gurl.h"
TEST(WebUIUtilTest, ParsePathAndScale) { TEST(WebUIUtilTest, ParsePathAndScale) {
std::vector<ui::ScaleFactor> supported_scale_factors;
supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
supported_scale_factors.push_back(ui::SCALE_FACTOR_140P);
supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
ui::test::ScopedSetSupportedScaleFactors scoped_supported(
supported_scale_factors);
std::string path; std::string path;
ui::ScaleFactor factor;
float factor = 0;
GURL url("http://some/random/username@email/and/more"); GURL url("http://some/random/username@email/and/more");
webui::ParsePathAndScale(url, &path, &factor); webui::ParsePathAndScale(url, &path, &factor);
EXPECT_EQ("random/username@email/and/more", path); EXPECT_EQ("random/username@email/and/more", path);
EXPECT_EQ(ui::SCALE_FACTOR_100P, factor); EXPECT_EQ(1.0f, factor);
factor = 0;
GURL url2("http://some/random/username/and/more"); GURL url2("http://some/random/username/and/more");
webui::ParsePathAndScale(url2, &path, &factor); webui::ParsePathAndScale(url2, &path, &factor);
EXPECT_EQ("random/username/and/more", path); EXPECT_EQ("random/username/and/more", path);
EXPECT_EQ(ui::SCALE_FACTOR_100P, factor); EXPECT_EQ(1.0f, factor);
factor = 0;
GURL url3("http://some/random/username/and/more@2ax"); GURL url3("http://some/random/username/and/more@2ax");
webui::ParsePathAndScale(url3, &path, &factor); webui::ParsePathAndScale(url3, &path, &factor);
EXPECT_EQ("random/username/and/more@2ax", path); EXPECT_EQ("random/username/and/more@2ax", path);
EXPECT_EQ(ui::SCALE_FACTOR_100P, factor); EXPECT_EQ(1.0f, factor);
factor = 0;
GURL url4("http://some/random/username/and/more@x"); GURL url4("http://some/random/username/and/more@x");
webui::ParsePathAndScale(url4, &path, &factor); webui::ParsePathAndScale(url4, &path, &factor);
EXPECT_EQ("random/username/and/more@x", path); EXPECT_EQ("random/username/and/more@x", path);
EXPECT_EQ(ui::SCALE_FACTOR_100P, factor); EXPECT_EQ(1.0f, factor);
factor = 0;
GURL url5("http://some/random/username@email/and/more@2x"); GURL url5("http://some/random/username@email/and/more@2x");
webui::ParsePathAndScale(url5, &path, &factor); webui::ParsePathAndScale(url5, &path, &factor);
EXPECT_EQ("random/username@email/and/more", path); EXPECT_EQ("random/username@email/and/more", path);
EXPECT_EQ(ui::SCALE_FACTOR_200P, factor); EXPECT_EQ(2.0f, factor);
factor = 0;
GURL url6("http://some/random/username/and/more@1.4x"); GURL url6("http://some/random/username/and/more@1.4x");
webui::ParsePathAndScale(url6, &path, &factor); webui::ParsePathAndScale(url6, &path, &factor);
EXPECT_EQ("random/username/and/more", path); EXPECT_EQ("random/username/and/more", path);
EXPECT_EQ(ui::SCALE_FACTOR_140P, factor); EXPECT_EQ(1.4f, factor);
factor = 0;
GURL url7("http://some/random/username/and/more@1.3x"); GURL url7("http://some/random/username/and/more@1.3x");
webui::ParsePathAndScale(url7, &path, &factor); webui::ParsePathAndScale(url7, &path, &factor);
EXPECT_EQ("random/username/and/more", path); EXPECT_EQ("random/username/and/more", path);
EXPECT_EQ(ui::SCALE_FACTOR_140P, factor); EXPECT_EQ(1.3f, factor);
} }
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