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

Side by Side Diff: ios/web/webui/web_ui_ios_data_source_impl.h

Issue 2954263003: Reland: Add support for $i18n{} localized strings to ios/web. (Closed)
Patch Set: Add missing chrome://flags webUI template keys. Created 3 years, 5 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
« no previous file with comments | « ios/web/public/web_ui_ios_data_source.h ('k') | ios/web/webui/web_ui_ios_data_source_impl.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #ifndef IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ 5 #ifndef IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_
6 #define IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ 6 #define IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "ios/web/public/url_data_source_ios.h" 15 #include "ios/web/public/url_data_source_ios.h"
16 #include "ios/web/public/web_ui_ios_data_source.h" 16 #include "ios/web/public/web_ui_ios_data_source.h"
17 #include "ios/web/webui/url_data_manager_ios.h" 17 #include "ios/web/webui/url_data_manager_ios.h"
18 #include "ios/web/webui/url_data_source_ios_impl.h" 18 #include "ios/web/webui/url_data_source_ios_impl.h"
19 #include "ui/base/template_expressions.h"
19 20
20 namespace web { 21 namespace web {
21 22
22 class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl, 23 class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl,
23 public WebUIIOSDataSource { 24 public WebUIIOSDataSource {
24 public: 25 public:
25 // WebUIIOSDataSource implementation: 26 // WebUIIOSDataSource implementation:
26 void AddString(const std::string& name, const base::string16& value) override; 27 void AddString(const std::string& name, const base::string16& value) override;
27 void AddString(const std::string& name, const std::string& value) override; 28 void AddString(const std::string& name, const std::string& value) override;
28 void AddLocalizedString(const std::string& name, int ids) override; 29 void AddLocalizedString(const std::string& name, int ids) override;
30 void AddLocalizedStrings(
31 const base::DictionaryValue& localized_strings) override;
29 void AddBoolean(const std::string& name, bool value) override; 32 void AddBoolean(const std::string& name, bool value) override;
30 void SetJsonPath(const std::string& path) override; 33 void SetJsonPath(const std::string& path) override;
31 void AddResourcePath(const std::string& path, int resource_id) override; 34 void AddResourcePath(const std::string& path, int resource_id) override;
32 void SetDefaultResource(int resource_id) override; 35 void SetDefaultResource(int resource_id) override;
33 void DisableDenyXFrameOptions() override; 36 void DisableDenyXFrameOptions() override;
34 37
35 protected: 38 protected:
36 ~WebUIIOSDataSourceImpl() override; 39 ~WebUIIOSDataSourceImpl() override;
37 40
38 // Completes a request by sending our dictionary of localized strings. 41 // Completes a request by sending our dictionary of localized strings.
39 void SendLocalizedStringsAsJSON( 42 void SendLocalizedStringsAsJSON(
40 const URLDataSourceIOS::GotDataCallback& callback); 43 const URLDataSourceIOS::GotDataCallback& callback);
41 44
42 // Completes a request by sending the file specified by |idr|. 45 // Completes a request to |path| by sending the file specified by |idr| as the
43 void SendFromResourceBundle(const URLDataSourceIOS::GotDataCallback& callback, 46 // response.
47 void SendFromResourceBundle(const std::string& path,
48 const URLDataSourceIOS::GotDataCallback& callback,
44 int idr); 49 int idr);
45 50
46 private: 51 private:
47 class InternalDataSource; 52 class InternalDataSource;
48 friend class InternalDataSource; 53 friend class InternalDataSource;
49 friend class WebUIIOSDataSourceTest; 54 friend class WebUIIOSDataSourceTest;
50 friend class WebUIIOSDataSource; 55 friend class WebUIIOSDataSource;
51 56
52 explicit WebUIIOSDataSourceImpl(const std::string& source_name); 57 explicit WebUIIOSDataSourceImpl(const std::string& source_name);
53 58
59 // Adds the locale to the load time data defaults. May be called repeatedly.
60 void EnsureLoadTimeDataDefaultsAdded();
61
54 // Methods that match URLDataSource which are called by 62 // Methods that match URLDataSource which are called by
55 // InternalDataSource. 63 // InternalDataSource.
56 std::string GetSource() const; 64 std::string GetSource() const;
57 std::string GetMimeType(const std::string& path) const; 65 std::string GetMimeType(const std::string& path) const;
58 void StartDataRequest(const std::string& path, 66 void StartDataRequest(const std::string& path,
59 const URLDataSourceIOS::GotDataCallback& callback); 67 const URLDataSourceIOS::GotDataCallback& callback);
60 68
61 // The name of this source. 69 // The name of this source.
62 // E.g., for favicons, this could be "favicon", which results in paths for 70 // E.g., for favicons, this could be "favicon", which results in paths for
63 // specific resources like "favicon/34" getting sent to this source. 71 // specific resources like "favicon/34" getting sent to this source.
64 std::string source_name_; 72 std::string source_name_;
65 int default_resource_; 73 int default_resource_;
66 std::string json_path_; 74 std::string json_path_;
67 std::map<std::string, int> path_to_idr_map_; 75 std::map<std::string, int> path_to_idr_map_;
76 // The replacements are initiallized in the main thread and then used in the
77 // IO thread. The map is safe to read from multiple threads as long as no
78 // futher changes are made to it after initialization.
79 ui::TemplateReplacements replacements_;
80 // The |replacements_| is intended to replace |localized_strings_|.
68 base::DictionaryValue localized_strings_; 81 base::DictionaryValue localized_strings_;
69 bool deny_xframe_options_; 82 bool deny_xframe_options_;
83 bool load_time_data_defaults_added_;
70 bool replace_existing_source_; 84 bool replace_existing_source_;
71 85
72 DISALLOW_COPY_AND_ASSIGN(WebUIIOSDataSourceImpl); 86 DISALLOW_COPY_AND_ASSIGN(WebUIIOSDataSourceImpl);
73 }; 87 };
74 88
75 } // web 89 } // web
76 90
77 #endif // IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_ 91 #endif // IOS_WEB_WEBUI_WEB_UI_IOS_DATA_SOURCE_IMPL_H_
OLDNEW
« no previous file with comments | « ios/web/public/web_ui_ios_data_source.h ('k') | ios/web/webui/web_ui_ios_data_source_impl.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698