Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: content/browser/webui/shared_resources_data_source.cc

Issue 747923004: webui: minimize webui flicker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/webui/shared_resources_data_source.h" 5 #include "content/browser/webui/shared_resources_data_source.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/strings/string_piece.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
11 #include "content/public/common/content_client.h" 12 #include "content/public/common/content_client.h"
12 #include "content/public/common/url_constants.h" 13 #include "content/public/common/url_constants.h"
13 #include "net/base/mime_util.h" 14 #include "net/base/mime_util.h"
15 #include "ui/base/layout.h"
16 #include "ui/resources/grit/webui_resources.h"
14 #include "ui/resources/grit/webui_resources_map.h" 17 #include "ui/resources/grit/webui_resources_map.h"
15 18
19 namespace content {
20
16 namespace { 21 namespace {
17 22
18 const char kAppImagesPath[] = "images/apps/"; 23 const char kAppImagesPath[] = "images/apps/";
19 const char kAppImagesPath2x[] = "images/2x/apps/"; 24 const char kAppImagesPath2x[] = "images/2x/apps/";
20 25
21 const char kReplacement[] = "../../resources/default_100_percent/common/"; 26 const char kReplacement[] = "../../resources/default_100_percent/common/";
22 const char kReplacement2x[] = "../../resources/default_200_percent/common/"; 27 const char kReplacement2x[] = "../../resources/default_200_percent/common/";
23 28
24 // This entire method is a hack introduced to be able to handle apps images 29 // This entire method is a hack introduced to be able to handle apps images
25 // that exist in the ui/resources directory. From JS/CSS, we still load the 30 // that exist in the ui/resources directory. From JS/CSS, we still load the
(...skipping 30 matching lines...) Expand all
56 61
57 } // namespace 62 } // namespace
58 63
59 SharedResourcesDataSource::SharedResourcesDataSource() { 64 SharedResourcesDataSource::SharedResourcesDataSource() {
60 } 65 }
61 66
62 SharedResourcesDataSource::~SharedResourcesDataSource() { 67 SharedResourcesDataSource::~SharedResourcesDataSource() {
63 } 68 }
64 69
65 std::string SharedResourcesDataSource::GetSource() const { 70 std::string SharedResourcesDataSource::GetSource() const {
66 return content::kChromeUIResourcesHost; 71 return kChromeUIResourcesHost;
67 } 72 }
68 73
69 void SharedResourcesDataSource::StartDataRequest( 74 void SharedResourcesDataSource::StartDataRequest(
70 const std::string& path, 75 const std::string& path,
71 int render_process_id, 76 int render_process_id,
72 int render_frame_id, 77 int render_frame_id,
73 const content::URLDataSource::GotDataCallback& callback) { 78 const URLDataSource::GotDataCallback& callback) {
74 int idr = PathToIDR(path); 79 int idr = PathToIDR(path);
75 DCHECK_NE(-1, idr) << " path: " << path; 80 DCHECK_NE(-1, idr) << " path: " << path;
76 scoped_refptr<base::RefCountedStaticMemory> bytes( 81 scoped_refptr<base::RefCountedMemory> bytes;
77 content::GetContentClient()->GetDataResourceBytes(idr)); 82
83 ContentClient* content_client = GetContentClient();
84 if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) {
davidben 2014/11/25 22:29:34 It is also a little puzzling to me why this hooks
Dan Beam 2014/11/25 22:49:31 creis@ nor I know the preferred mechanism here (pa
85 std::vector<std::string> placeholders;
86 WebUITextStyles text_styles = content_client->GetWebUITextStyles();
87 placeholders.push_back(text_styles.text_direction); // $1
88 placeholders.push_back(text_styles.font_family); // $2
89 placeholders.push_back(text_styles.font_size); // $3
90
91 const std::string& chrome_shared =
92 content_client->GetDataResource(idr, ui::SCALE_FACTOR_NONE).as_string();
93 std::string replaced =
94 ReplaceStringPlaceholders(chrome_shared, placeholders, nullptr);
95 bytes = base::RefCountedString::TakeString(&replaced);
96 } else {
97 bytes = content_client->GetDataResourceBytes(idr);
98 }
78 99
79 callback.Run(bytes.get()); 100 callback.Run(bytes.get());
80 } 101 }
81 102
82 std::string SharedResourcesDataSource::GetMimeType( 103 std::string SharedResourcesDataSource::GetMimeType(
83 const std::string& path) const { 104 const std::string& path) const {
84 // Requests should not block on the disk! On POSIX this goes to disk. 105 // Requests should not block on the disk! On POSIX this goes to disk.
85 // http://code.google.com/p/chromium/issues/detail?id=59849 106 // http://code.google.com/p/chromium/issues/detail?id=59849
86 107
87 base::ThreadRestrictions::ScopedAllowIO allow_io; 108 base::ThreadRestrictions::ScopedAllowIO allow_io;
88 std::string mime_type; 109 std::string mime_type;
89 net::GetMimeTypeFromFile(base::FilePath().AppendASCII(path), &mime_type); 110 net::GetMimeTypeFromFile(base::FilePath().AppendASCII(path), &mime_type);
90 return mime_type; 111 return mime_type;
91 } 112 }
92 113
93 std::string 114 std::string
94 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin( 115 SharedResourcesDataSource::GetAccessControlAllowOriginForOrigin(
95 const std::string& origin) const { 116 const std::string& origin) const {
96 // For now we give access only for "chrome://*" origins. 117 // For now we give access only for "chrome://*" origins.
97 // According to CORS spec, Access-Control-Allow-Origin header doesn't support 118 // According to CORS spec, Access-Control-Allow-Origin header doesn't support
98 // wildcards, so we need to set its value explicitly by passing the |origin| 119 // wildcards, so we need to set its value explicitly by passing the |origin|
99 // back. 120 // back.
100 std::string allowed_origin_prefix = content::kChromeUIScheme; 121 std::string allowed_origin_prefix = kChromeUIScheme;
101 allowed_origin_prefix += "://"; 122 allowed_origin_prefix += "://";
102 if (origin.find(allowed_origin_prefix) != 0) 123 if (origin.find(allowed_origin_prefix) != 0)
103 return "none"; 124 return "none";
104 return origin; 125 return origin;
105 } 126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698