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

Side by Side Diff: ios/web/webui/shared_resources_data_source_ios.cc

Issue 1110213002: Upstream most of the iOS WebUI support in ios/web/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/web/webui/shared_resources_data_source_ios.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h"
9 #include "base/strings/string_util.h"
10 #include "base/threading/thread_restrictions.h"
11 #include "grit/webui_resources_map.h"
12 #include "ios/web/public/web_client.h"
13 #include "net/base/mime_util.h"
14 #include "ui/base/webui/web_ui_util.h"
15 #include "ui/resources/grit/webui_resources.h"
16
17 namespace web {
18
19 namespace {
20
21 // Value duplicated from content/public/common/url_constants.h
22 // TODO(stuartmorgan): Revisit how to share this in a more maintainable way.
23 const char kWebUIResourcesHost[] = "resources";
24
25 int PathToIDR(const std::string& path) {
26 int idr = -1;
27 for (size_t i = 0; i < kWebuiResourcesSize; ++i) {
28 if (path == kWebuiResources[i].name) {
29 idr = kWebuiResources[i].value;
30 break;
31 }
32 }
33
34 return idr;
35 }
36
37 } // namespace
38
39 SharedResourcesDataSourceIOS::SharedResourcesDataSourceIOS() {
40 }
41
42 SharedResourcesDataSourceIOS::~SharedResourcesDataSourceIOS() {
43 }
44
45 std::string SharedResourcesDataSourceIOS::GetSource() const {
46 return kWebUIResourcesHost;
47 }
48
49 void SharedResourcesDataSourceIOS::StartDataRequest(
50 const std::string& path,
51 const URLDataSourceIOS::GotDataCallback& callback) {
52 int idr = PathToIDR(path);
53 DCHECK_NE(-1, idr) << " path: " << path;
54 scoped_refptr<base::RefCountedMemory> bytes;
55
56 WebClient* web_client = GetWebClient();
57
58 if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) {
59 std::vector<std::string> placeholders;
60 placeholders.push_back(webui::GetTextDirection()); // $1
61 placeholders.push_back(webui::GetFontFamily()); // $2
62 placeholders.push_back(webui::GetFontSize()); // $3
63
64 const std::string& chrome_shared =
65 web_client->GetDataResource(idr, ui::SCALE_FACTOR_NONE).as_string();
66 std::string replaced =
67 ReplaceStringPlaceholders(chrome_shared, placeholders, nullptr);
68 bytes = base::RefCountedString::TakeString(&replaced);
69 } else {
70 bytes = web_client->GetDataResourceBytes(idr);
71 }
72
73 callback.Run(bytes.get());
74 }
75
76 std::string SharedResourcesDataSourceIOS::GetMimeType(
77 const std::string& path) const {
78 std::string mime_type;
79 net::GetMimeTypeFromFile(base::FilePath().AppendASCII(path), &mime_type);
80 return mime_type;
81 }
82
83 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698