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 #ifndef IOS_WEB_PUBLIC_WEBUI_WEB_UI_IOS_DATA_SOURCE_H_
6 #define IOS_WEB_PUBLIC_WEBUI_WEB_UI_IOS_DATA_SOURCE_H_
7 
8 #include "base/callback.h"
9 #include "base/containers/span.h"
10 #include "base/strings/string16.h"
11 #include "base/supports_user_data.h"
12 
13 namespace base {
14 class DictionaryValue;
15 }
16 
17 namespace webui {
18 struct LocalizedString;
19 }
20 
21 namespace web {
22 class BrowserState;
23 
24 // A data source that can help with implementing the common operations needed by
25 // WebUIIOS pages.
26 class WebUIIOSDataSource : public base::SupportsUserData {
27  public:
~WebUIIOSDataSource()28   ~WebUIIOSDataSource() override {}
29 
30   static WebUIIOSDataSource* Create(const std::string& source_name);
31 
32   // Adds a WebUIIOS data source to |browser_state|.
33   static void Add(BrowserState* browser_state, WebUIIOSDataSource* source);
34 
35   // Adds a string keyed to its name to our dictionary.
36   virtual void AddString(const std::string& name,
37                          const base::string16& value) = 0;
38 
39   // Adds a string keyed to its name to our dictionary.
40   virtual void AddString(const std::string& name, const std::string& value) = 0;
41 
42   // Adds a localized string with resource |ids| keyed to its name to our
43   // dictionary.
44   virtual void AddLocalizedString(const std::string& name, int ids) = 0;
45 
46   virtual void AddLocalizedStrings(
47       const base::DictionaryValue& localized_strings) = 0;
48 
49   virtual void AddLocalizedStrings(
50       base::span<const webui::LocalizedString> strings) = 0;
51 
52   // Adds a boolean keyed to its name to our dictionary.
53   virtual void AddBoolean(const std::string& name, bool value) = 0;
54 
55   // Call this to enable a virtual "strings.js" (or "strings.m.js" for modules)
56   // URL that provides translations and dynamic data when requested.
57   virtual void UseStringsJs() = 0;
58 
59   // Adds a mapping between a path name and a resource to return.
60   virtual void AddResourcePath(const std::string& path, int resource_id) = 0;
61 
62   // Sets the resource to returned when no other paths match.
63   virtual void SetDefaultResource(int resource_id) = 0;
64 
65   // The following map to methods on URLDataSource. See the documentation there.
66   virtual void DisableDenyXFrameOptions() = 0;
67 };
68 
69 }  // namespace web
70 
71 #endif  // IOS_WEB_PUBLIC_WEBUI_WEB_UI_IOS_DATA_SOURCE_H_
72