[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / public / browser / web_ui_data_source.h
blob5e0a2deb5680a34b4aa6e91bf182c97cb49a65e1
1 // Copyright (c) 2013 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_PUBLIC_BROWSER_WEB_UI_DATA_SOURCE_H_
6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_DATA_SOURCE_H_
8 #include "base/callback.h"
9 #include "base/strings/string16.h"
10 #include "content/common/content_export.h"
12 namespace base {
13 class DictionaryValue;
14 class RefCountedMemory;
17 namespace content {
18 class BrowserContext;
20 // A data source that can help with implementing the common operations needed by
21 // WebUI pages.
22 class WebUIDataSource {
23 public:
24 virtual ~WebUIDataSource() {}
26 CONTENT_EXPORT static WebUIDataSource* Create(const std::string& source_name);
28 // Adds the necessary resources for mojo bindings returning the
29 // WebUIDataSource that handles the resources. Callers do not own the return
30 // value.
31 CONTENT_EXPORT static WebUIDataSource* AddMojoDataSource(
32 BrowserContext* browser_context);
34 // Adds a WebUI data source to |browser_context|.
35 CONTENT_EXPORT static void Add(BrowserContext* browser_context,
36 WebUIDataSource* source);
38 // Adds a string keyed to its name to our dictionary.
39 virtual void AddString(const std::string& name,
40 const base::string16& value) = 0;
42 // Adds a string keyed to its name to our dictionary.
43 virtual void AddString(const std::string& name, const std::string& value) = 0;
45 // Adds a localized string with resource |ids| keyed to its name to our
46 // dictionary.
47 virtual void AddLocalizedString(const std::string& name, int ids) = 0;
49 // Add strings from |localized_strings| to our dictionary.
50 virtual void AddLocalizedStrings(
51 const base::DictionaryValue& localized_strings) = 0;
53 // Adds a boolean keyed to its name to our dictionary.
54 virtual void AddBoolean(const std::string& name, bool value) = 0;
56 // Sets the path which will return the JSON strings.
57 virtual void SetJsonPath(const std::string& path) = 0;
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;
62 // Sets the resource to returned when no other paths match.
63 virtual void SetDefaultResource(int resource_id) = 0;
65 // Used as a parameter to GotDataCallback. The caller has to run this callback
66 // with the result for the path that they filtered, passing ownership of the
67 // memory.
68 typedef base::Callback<void(base::RefCountedMemory*)> GotDataCallback;
70 // Used by SetRequestFilter. The string parameter is the path of the request.
71 // If the callee doesn't want to handle the data, false is returned. Otherwise
72 // true is returned and the GotDataCallback parameter is called either then or
73 // asynchronously with the response.
74 typedef base::Callback<bool(const std::string&, const GotDataCallback&)>
75 HandleRequestCallback;
77 // Allows a caller to add a filter for URL requests.
78 virtual void SetRequestFilter(const HandleRequestCallback& callback) = 0;
80 // The following map to methods on URLDataSource. See the documentation there.
81 // NOTE: it's not acceptable to call DisableContentSecurityPolicy for new
82 // pages, see URLDataSource::ShouldAddContentSecurityPolicy and talk to
83 // tsepez.
85 // Currently only used by embedders for WebUIs with multiple instances.
86 virtual void DisableReplaceExistingSource() = 0;
87 virtual void DisableContentSecurityPolicy() = 0;
88 virtual void OverrideContentSecurityPolicyObjectSrc(
89 const std::string& data) = 0;
90 virtual void OverrideContentSecurityPolicyFrameSrc(
91 const std::string& data) = 0;
92 virtual void DisableDenyXFrameOptions() = 0;
95 } // namespace content
97 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_DATA_SOURCE_H_