Add ICU message format support
[chromium-blink-merge.git] / ios / web / public / url_data_source_ios.h
blobeb51f5fac300ff286d97aa8441dc495b4a7cfb6c
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.
5 #ifndef IOS_WEB_PUBLIC_URL_DATA_SOURCE_IOS_H_
6 #define IOS_WEB_PUBLIC_URL_DATA_SOURCE_IOS_H_
8 #include <string>
10 #include "base/callback.h"
12 namespace base {
13 class MessageLoop;
14 class RefCountedMemory;
17 namespace net {
18 class URLRequest;
21 namespace web {
22 class BrowserState;
24 // A URLDataSourceIOS is an object that can answer requests for WebUI data
25 // asynchronously. An implementation of URLDataSourceIOS should handle calls to
26 // StartDataRequest() by starting its (implementation-specific) asynchronous
27 // request for the data, then running the callback given in that method to
28 // notify.
29 class URLDataSourceIOS {
30 public:
31 // Adds a URL data source to |browser_state|.
32 static void Add(BrowserState* browser_state, URLDataSourceIOS* source);
34 virtual ~URLDataSourceIOS() {}
36 // The name of this source.
37 // E.g., for favicons, this could be "favicon", which results in paths for
38 // specific resources like "favicon/34" getting sent to this source. For
39 // sources where a scheme is used instead of the hostname as the unique
40 // identifier, the suffix "://" must be added to the return value, eg. for a
41 // URLDataSourceIOS which would display resources with URLs on the form
42 // your-scheme://anything , GetSource() must return "your-scheme://".
43 virtual std::string GetSource() const = 0;
45 // Used by StartDataRequest so that the child class can return the data when
46 // it's available.
47 typedef base::Callback<void(base::RefCountedMemory*)> GotDataCallback;
49 // Called by URLDataSourceIOS to request data at |path|. The string parameter
50 // is the path of the request. The child class should run |callback| when the
51 // data is available or if the request could not be satisfied. This can be
52 // called either in this callback or asynchronously with the response.
53 virtual void StartDataRequest(const std::string& path,
54 const GotDataCallback& callback) = 0;
56 // Return the mimetype that should be sent with this response, or empty
57 // string to specify no mime type.
58 virtual std::string GetMimeType(const std::string& path) const = 0;
60 // The following methods are all called on the IO thread.
62 // Returns true if the URLDataSourceIOS should replace an existing
63 // URLDataSourceIOS with the same name that has already been registered. The
64 // default is true.
66 // WARNING: this is invoked on the IO thread.
68 // TODO: nuke this and convert all callers to not replace.
69 virtual bool ShouldReplaceExistingSource() const;
71 // Returns true if responses from this URLDataSourceIOS can be cached.
72 virtual bool AllowCaching() const;
74 // By default, "object-src 'none';" is added to CSP. Override to change this.
75 virtual std::string GetContentSecurityPolicyObjectSrc() const;
77 // By default, the "X-Frame-Options: DENY" header is sent. To stop this from
78 // happening, return false. It is OK to return false as needed.
79 virtual bool ShouldDenyXFrameOptions() const;
81 // By default, only chrome: requests are allowed. Override in specific WebUI
82 // data sources to enable for additional schemes or to implement fancier
83 // access control. Typically used in concert with
84 // WebClient::GetAdditionalWebUISchemes() to permit additional WebUI scheme
85 // support for an embedder.
86 virtual bool ShouldServiceRequest(const net::URLRequest* request) const;
88 // Called to inform the source that StartDataRequest() will be called soon.
89 // Gives the source an opportunity to rewrite |path| to incorporate extra
90 // information from the URLRequest prior to serving.
91 virtual void WillServiceRequest(const net::URLRequest* request,
92 std::string* path) const {}
95 } // namespace web
97 #endif // IOS_WEB_PUBLIC_URL_DATA_SOURCE_IOS_H_