OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 IOS_INTERNAL_WEB_WEBUI_URL_DATA_MANAGER_BACKEND_IOS_H_ |
6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_ | 6 #define IOS_INTERNAL_WEB_WEBUI_URL_DATA_MANAGER_BACKEND_IOS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
15 #include "content/browser/webui/url_data_manager.h" | 15 #include "ios/web/public/url_data_source_ios.h" |
16 #include "content/public/browser/url_data_source.h" | 16 #include "ios/web/webui/url_data_manager_ios.h" |
17 #include "net/url_request/url_request_job_factory.h" | 17 #include "net/url_request/url_request_job_factory.h" |
18 | 18 |
19 class GURL; | 19 class GURL; |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class RefCountedMemory; | 22 class RefCountedMemory; |
23 } | 23 } |
24 | 24 |
25 namespace content { | 25 namespace web { |
26 | 26 class BrowserState; |
27 class AppCacheServiceImpl; | 27 class URLDataSourceIOSImpl; |
28 class ChromeBlobStorageContext; | |
29 class ResourceContext; | |
30 class URLDataManagerBackend; | |
31 class URLDataSourceImpl; | |
32 class URLRequestChromeJob; | 28 class URLRequestChromeJob; |
33 | 29 |
34 // URLDataManagerBackend is used internally by ChromeURLDataManager on the IO | 30 // URLDataManagerIOSBackend is used internally by URLDataManagerIOS on |
35 // thread. In most cases you can use the API in ChromeURLDataManager and ignore | 31 // the IO thread. In most cases you can use the API in URLDataManagerIOS |
36 // this class. URLDataManagerBackend is owned by ResourceContext. | 32 // and ignore this class. URLDataManagerIOSBackend is owned by BrowserState. |
37 class URLDataManagerBackend : public base::SupportsUserData::Data { | 33 class URLDataManagerIOSBackend : public base::SupportsUserData::Data { |
38 public: | 34 public: |
39 typedef int RequestID; | 35 typedef int RequestID; |
40 | 36 |
41 URLDataManagerBackend(); | 37 URLDataManagerIOSBackend(); |
42 ~URLDataManagerBackend() override; | 38 ~URLDataManagerIOSBackend() override; |
43 | 39 |
44 // Invoked to create the protocol handler for chrome://. |is_incognito| should | 40 // Invoked to create the protocol handler for chrome://. |is_incognito| should |
45 // be set for incognito profiles. Called on the UI thread. | 41 // be set for incognito browser states. Called on the UI thread. |
46 CONTENT_EXPORT static net::URLRequestJobFactory::ProtocolHandler* | 42 static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler( |
47 CreateProtocolHandler(content::ResourceContext* resource_context, | 43 BrowserState* browser_state); |
48 bool is_incognito, | |
49 AppCacheServiceImpl* appcache_service, | |
50 ChromeBlobStorageContext* blob_storage_context); | |
51 | 44 |
52 // Adds a DataSource to the collection of data sources. | 45 // Adds a DataSource to the collection of data sources. |
53 void AddDataSource(URLDataSourceImpl* source); | 46 void AddDataSource(URLDataSourceIOSImpl* source); |
54 | 47 |
55 // DataSource invokes this. Sends the data to the URLRequest. | 48 // DataSource invokes this. Sends the data to the URLRequest. |
56 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes); | 49 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes); |
57 | 50 |
58 static net::URLRequestJob* Factory(net::URLRequest* request, | 51 static net::URLRequestJob* Factory(net::URLRequest* request, |
59 const std::string& scheme); | 52 const std::string& scheme); |
60 | 53 |
61 private: | 54 private: |
62 friend class URLRequestChromeJob; | 55 friend class URLRequestChromeJob; |
63 | 56 |
64 typedef std::map<std::string, | 57 typedef std::map<std::string, scoped_refptr<URLDataSourceIOSImpl> > |
65 scoped_refptr<URLDataSourceImpl> > DataSourceMap; | 58 DataSourceMap; |
66 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap; | 59 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap; |
67 | 60 |
68 // Called by the job when it's starting up. | 61 // Called by the job when it's starting up. |
69 // Returns false if |url| is not a URL managed by this object. | 62 // Returns false if |url| is not a URL managed by this object. |
70 bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job); | 63 bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job); |
71 | 64 |
72 // Helper function to call StartDataRequest on |source|'s delegate. This is | 65 // Helper function to call StartDataRequest on |source|'s delegate. This is |
73 // needed because while we want to call URLDataSourceDelegate's method, we | 66 // needed because while we want to call URLDataSourceIOSDelegate's method, we |
74 // need to add a refcount on the source. | 67 // need to add a refcount on the source. |
75 static void CallStartRequest(scoped_refptr<URLDataSourceImpl> source, | 68 static void CallStartRequest(scoped_refptr<URLDataSourceIOSImpl> source, |
76 const std::string& path, | 69 const std::string& path, |
77 int render_process_id, | |
78 int render_frame_id, | |
79 int request_id); | 70 int request_id); |
80 | 71 |
81 // Remove a request from the list of pending requests. | 72 // Remove a request from the list of pending requests. |
82 void RemoveRequest(URLRequestChromeJob* job); | 73 void RemoveRequest(URLRequestChromeJob* job); |
83 | 74 |
84 // Returns true if the job exists in |pending_requests_|. False otherwise. | 75 // Returns true if the job exists in |pending_requests_|. False otherwise. |
85 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept | 76 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept |
86 // up to date. | 77 // up to date. |
87 bool HasPendingJob(URLRequestChromeJob* job) const; | 78 bool HasPendingJob(URLRequestChromeJob* job) const; |
88 | 79 |
89 // Look up the data source for the request. Returns the source if it is found, | 80 // Look up the data source for the request. Returns the source if it is found, |
90 // else NULL. | 81 // else NULL. |
91 URLDataSourceImpl* GetDataSourceFromURL(const GURL& url); | 82 URLDataSourceIOSImpl* GetDataSourceFromURL(const GURL& url); |
92 | 83 |
93 // Custom sources of data, keyed by source path (e.g. "favicon"). | 84 // Custom sources of data, keyed by source path (e.g. "favicon"). |
94 DataSourceMap data_sources_; | 85 DataSourceMap data_sources_; |
95 | 86 |
96 // All pending URLRequestChromeJobs, keyed by ID of the request. | 87 // All pending URLRequestChromeJobs, keyed by ID of the request. |
97 // URLRequestChromeJob calls into this object when it's constructed and | 88 // URLRequestChromeJob calls into this object when it's constructed and |
98 // destructed to ensure that the pointers in this map remain valid. | 89 // destructed to ensure that the pointers in this map remain valid. |
99 PendingRequestMap pending_requests_; | 90 PendingRequestMap pending_requests_; |
100 | 91 |
101 // The ID we'll use for the next request we receive. | 92 // The ID we'll use for the next request we receive. |
102 RequestID next_request_id_; | 93 RequestID next_request_id_; |
103 | 94 |
104 DISALLOW_COPY_AND_ASSIGN(URLDataManagerBackend); | 95 DISALLOW_COPY_AND_ASSIGN(URLDataManagerIOSBackend); |
105 }; | 96 }; |
106 | 97 |
107 // Creates protocol handler for chrome-devtools://. |is_incognito| should be | 98 } // namespace web |
108 // set for incognito profiles. | |
109 net::URLRequestJobFactory::ProtocolHandler* | |
110 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | |
111 bool is_incognito); | |
112 | 99 |
113 } // namespace content | 100 #endif // IOS_INTERNAL_WEB_WEBUI_URL_DATA_MANAGER_BACKEND_IOS_H_ |
114 | |
115 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_ | |
OLD | NEW |