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

Side by Side Diff: ios/web/public/url_data_source_ios.h

Issue 1110213002: Upstream most of the iOS WebUI support in ios/web/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
(Empty)
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_URL_DATA_SOURCE_IOS_H_
6 #define IOS_WEB_PUBLIC_URL_DATA_SOURCE_IOS_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11
12 namespace base {
13 class MessageLoop;
14 class RefCountedMemory;
15 }
16
17 namespace net {
18 class URLRequest;
19 }
20
21 namespace web {
22 class BrowserState;
23
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);
33
34 virtual ~URLDataSourceIOS() {}
35
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;
44
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;
48
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;
55
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;
59
60 // The following methods are all called on the IO thread.
61
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.
65 //
66 // WARNING: this is invoked on the IO thread.
67 //
68 // TODO: nuke this and convert all callers to not replace.
69 virtual bool ShouldReplaceExistingSource() const;
70
71 // Returns true if responses from this URLDataSourceIOS can be cached.
72 virtual bool AllowCaching() const;
73
74 // By default, "object-src 'none';" is added to CSP. Override to change this.
75 virtual std::string GetContentSecurityPolicyObjectSrc() const;
76
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;
80
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;
87
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 {}
93 };
94
95 } // namespace web
96
97 #endif // IOS_WEB_PUBLIC_URL_DATA_SOURCE_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698