Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / webui / web_ui_data_source_impl.h
blobd9f44887d1ce7b030359e073a16b737f63132b14
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_
6 #define CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/values.h"
15 #include "content/browser/webui/url_data_manager.h"
16 #include "content/browser/webui/url_data_source_impl.h"
17 #include "content/common/content_export.h"
18 #include "content/public/browser/url_data_source.h"
19 #include "content/public/browser/web_ui_data_source.h"
21 namespace content {
23 // A data source that can help with implementing the common operations
24 // needed by the chrome WEBUI settings/history/downloads pages.
25 class CONTENT_EXPORT WebUIDataSourceImpl
26 : public NON_EXPORTED_BASE(URLDataSourceImpl),
27 public NON_EXPORTED_BASE(WebUIDataSource) {
28 public:
29 // WebUIDataSource implementation:
30 void AddString(const std::string& name, const base::string16& value) override;
31 void AddString(const std::string& name, const std::string& value) override;
32 void AddLocalizedString(const std::string& name, int ids) override;
33 void AddLocalizedStrings(
34 const base::DictionaryValue& localized_strings) override;
35 void AddBoolean(const std::string& name, bool value) override;
36 void SetJsonPath(const std::string& path) override;
37 void AddResourcePath(const std::string& path, int resource_id) override;
38 void SetDefaultResource(int resource_id) override;
39 void SetRequestFilter(
40 const WebUIDataSource::HandleRequestCallback& callback) override;
41 void DisableReplaceExistingSource() override;
42 void DisableContentSecurityPolicy() override;
43 void OverrideContentSecurityPolicyObjectSrc(const std::string& data) override;
44 void OverrideContentSecurityPolicyFrameSrc(const std::string& data) override;
45 void DisableDenyXFrameOptions() override;
47 protected:
48 ~WebUIDataSourceImpl() override;
50 // Completes a request by sending our dictionary of localized strings.
51 void SendLocalizedStringsAsJSON(
52 const URLDataSource::GotDataCallback& callback);
54 // Completes a request by sending the file specified by |idr|.
55 void SendFromResourceBundle(
56 const URLDataSource::GotDataCallback& callback, int idr);
58 private:
59 class InternalDataSource;
60 friend class InternalDataSource;
61 friend class WebUIDataSource;
62 friend class WebUIDataSourceTest;
64 explicit WebUIDataSourceImpl(const std::string& source_name);
66 // Methods that match URLDataSource which are called by
67 // InternalDataSource.
68 std::string GetSource() const;
69 std::string GetMimeType(const std::string& path) const;
70 void StartDataRequest(
71 const std::string& path,
72 int render_process_id,
73 int render_frame_id,
74 const URLDataSource::GotDataCallback& callback);
76 void disable_set_font_strings_for_testing() {
77 disable_set_font_strings_ = true;
80 // The name of this source.
81 // E.g., for favicons, this could be "favicon", which results in paths for
82 // specific resources like "favicon/34" getting sent to this source.
83 std::string source_name_;
84 int default_resource_;
85 std::string json_path_;
86 std::map<std::string, int> path_to_idr_map_;
87 base::DictionaryValue localized_strings_;
88 WebUIDataSource::HandleRequestCallback filter_callback_;
89 bool add_csp_;
90 bool object_src_set_;
91 std::string object_src_;
92 bool frame_src_set_;
93 std::string frame_src_;
94 bool deny_xframe_options_;
95 bool disable_set_font_strings_;
96 bool replace_existing_source_;
98 DISALLOW_COPY_AND_ASSIGN(WebUIDataSourceImpl);
101 } // content
103 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_DATA_SOURCE_IMPL_H_