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

Side by Side Diff: content/browser/webui/url_data_manager_backend.h

Issue 2860903006: Handle webuis when using the network service. (Closed)
Patch Set: review comments Created 3 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_ 5 #ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_
6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_ 6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/supports_user_data.h" 15 #include "base/supports_user_data.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "content/browser/webui/url_data_manager.h" 17 #include "content/browser/webui/url_data_manager.h"
18 #include "content/public/browser/url_data_source.h" 18 #include "content/public/browser/url_data_source.h"
19 #include "net/http/http_response_headers.h"
19 #include "net/url_request/url_request_job_factory.h" 20 #include "net/url_request/url_request_job_factory.h"
20 21
21 class GURL; 22 class GURL;
22 23
23 namespace base { 24 namespace base {
24 class RefCountedMemory; 25 class RefCountedMemory;
25 } 26 }
26 27
27 namespace content { 28 namespace content {
28 29
29 class ChromeBlobStorageContext; 30 class ChromeBlobStorageContext;
30 class ResourceContext; 31 class ResourceContext;
31 class URLDataManagerBackend; 32 class URLDataManagerBackend;
32 class URLDataSourceImpl; 33 class URLDataSourceImpl;
33 class URLRequestChromeJob; 34 class URLRequestChromeJob;
34 35
35 // URLDataManagerBackend is used internally by ChromeURLDataManager on the IO 36 // URLDataManagerBackend is used internally by ChromeURLDataManager on the IO
36 // thread. In most cases you can use the API in ChromeURLDataManager and ignore 37 // thread. In most cases you can use the API in ChromeURLDataManager and ignore
37 // this class. URLDataManagerBackend is owned by ResourceContext. 38 // this class. URLDataManagerBackend is owned by ResourceContext.
38 class URLDataManagerBackend : public base::SupportsUserData::Data { 39 class URLDataManagerBackend : public base::SupportsUserData::Data {
39 public: 40 public:
40 typedef int RequestID; 41 typedef int RequestID;
41 42
42 URLDataManagerBackend(); 43 URLDataManagerBackend();
43 ~URLDataManagerBackend() override; 44 ~URLDataManagerBackend() override;
44 45
45 // Invoked to create the protocol handler for chrome://. |is_incognito| should 46 // Invoked to create the protocol handler for chrome://. Called on the UI
scottmg 2017/05/05 22:38:10 Just to confirm, the is_incognito was being passed
jam 2017/05/05 23:25:07 Right
46 // be set for incognito profiles. Called on the UI thread. 47 // thread.
47 CONTENT_EXPORT static std::unique_ptr< 48 CONTENT_EXPORT static std::unique_ptr<
48 net::URLRequestJobFactory::ProtocolHandler> 49 net::URLRequestJobFactory::ProtocolHandler>
49 CreateProtocolHandler(content::ResourceContext* resource_context, 50 CreateProtocolHandler(ResourceContext* resource_context,
50 bool is_incognito,
51 ChromeBlobStorageContext* blob_storage_context); 51 ChromeBlobStorageContext* blob_storage_context);
52 52
53 // Adds a DataSource to the collection of data sources. 53 // Adds a DataSource to the collection of data sources.
54 void AddDataSource(URLDataSourceImpl* source); 54 void AddDataSource(URLDataSourceImpl* source);
55 55
56 void UpdateWebUIDataSource(const std::string& source_name, 56 void UpdateWebUIDataSource(const std::string& source_name,
57 const base::DictionaryValue& update); 57 const base::DictionaryValue& update);
58 58
59 // DataSource invokes this. Sends the data to the URLRequest. |bytes| may be 59 // DataSource invokes this. Sends the data to the URLRequest. |bytes| may be
60 // null, which signals an error handling the request. 60 // null, which signals an error handling the request.
61 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes); 61 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes);
62 62
63 static net::URLRequestJob* Factory(net::URLRequest* request, 63 // Look up the data source for the request. Returns the source if it is found,
64 const std::string& scheme); 64 // else NULL.
65 URLDataSourceImpl* GetDataSourceFromURL(const GURL& url);
66
67 // Creates and sets the response headers for the given request.
68 static scoped_refptr<net::HttpResponseHeaders> GetHeaders(
69 URLDataSourceImpl* source,
70 const std::string& path,
71 const std::string& origin);
72
73 // Returns whether |url| passes some sanity checks and is a valid GURL.
74 static bool CheckURLIsValid(const GURL& url);
75
76 // Parse |url| to get the path which will be used to resolve the request. The
77 // path is the remaining portion after the scheme and hostname.
78 static void URLToRequestPath(const GURL& url, std::string* path);
65 79
66 private: 80 private:
67 friend class URLRequestChromeJob; 81 friend class URLRequestChromeJob;
68 82
69 typedef std::map<std::string, 83 typedef std::map<std::string,
70 scoped_refptr<URLDataSourceImpl> > DataSourceMap; 84 scoped_refptr<URLDataSourceImpl> > DataSourceMap;
71 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap; 85 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap;
72 86
73 // Called by the job when it's starting up. 87 // Called by the job when it's starting up.
74 // Returns false if |url| is not a URL managed by this object. 88 // Returns false if |url| is not a URL managed by this object.
75 bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job); 89 bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job);
76 90
77 // Helper function to call StartDataRequest on |source|'s delegate. This is 91 // Helper function to call StartDataRequest on |source|'s delegate. This is
78 // needed because while we want to call URLDataSourceDelegate's method, we 92 // needed because while we want to call URLDataSourceDelegate's method, we
79 // need to add a refcount on the source. 93 // need to add a refcount on the source.
80 static void CallStartRequest( 94 static void CallStartRequest(
81 scoped_refptr<URLDataSourceImpl> source, 95 scoped_refptr<URLDataSourceImpl> source,
82 const std::string& path, 96 const std::string& path,
83 const ResourceRequestInfo::WebContentsGetter& wc_getter, 97 const ResourceRequestInfo::WebContentsGetter& wc_getter,
84 int request_id); 98 int request_id);
85 99
86 // Remove a request from the list of pending requests. 100 // Remove a request from the list of pending requests.
87 void RemoveRequest(URLRequestChromeJob* job); 101 void RemoveRequest(URLRequestChromeJob* job);
88 102
89 // Returns true if the job exists in |pending_requests_|. False otherwise. 103 // Returns true if the job exists in |pending_requests_|. False otherwise.
90 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept 104 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept
91 // up to date. 105 // up to date.
92 bool HasPendingJob(URLRequestChromeJob* job) const; 106 bool HasPendingJob(URLRequestChromeJob* job) const;
93 107
94 // Look up the data source for the request. Returns the source if it is found,
95 // else NULL.
96 URLDataSourceImpl* GetDataSourceFromURL(const GURL& url);
97
98 // Custom sources of data, keyed by source path (e.g. "favicon"). 108 // Custom sources of data, keyed by source path (e.g. "favicon").
99 DataSourceMap data_sources_; 109 DataSourceMap data_sources_;
100 110
101 // All pending URLRequestChromeJobs, keyed by ID of the request. 111 // All pending URLRequestChromeJobs, keyed by ID of the request.
102 // URLRequestChromeJob calls into this object when it's constructed and 112 // URLRequestChromeJob calls into this object when it's constructed and
103 // destructed to ensure that the pointers in this map remain valid. 113 // destructed to ensure that the pointers in this map remain valid.
104 PendingRequestMap pending_requests_; 114 PendingRequestMap pending_requests_;
105 115
106 // The ID we'll use for the next request we receive. 116 // The ID we'll use for the next request we receive.
107 RequestID next_request_id_; 117 RequestID next_request_id_;
108 118
109 DISALLOW_COPY_AND_ASSIGN(URLDataManagerBackend); 119 DISALLOW_COPY_AND_ASSIGN(URLDataManagerBackend);
110 }; 120 };
111 121
112 // Creates protocol handler for chrome-devtools://. |is_incognito| should be 122 // Creates protocol handler for chrome-devtools://.
113 // set for incognito profiles. 123 net::URLRequestJobFactory::ProtocolHandler* CreateDevToolsProtocolHandler(
114 net::URLRequestJobFactory::ProtocolHandler* 124 ResourceContext* resource_context);
115 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
116 bool is_incognito);
117 125
118 } // namespace content 126 } // namespace content
119 127
120 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_ 128 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698