OLD | NEW |
(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 CONTENT_BROWSER_RESOURCE_PROTOCOL_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_RESOURCE_PROTOCOL_HANDLER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <utility> |
| 10 |
| 11 #include "content/common/content_export.h" |
| 12 #include "net/url_request/url_request_job_factory.h" |
| 13 #include "ui/base/layout.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class ContentClient; |
| 18 |
| 19 class CONTENT_EXPORT ResourceProtocolHandler |
| 20 : public net::URLRequestJobFactory::ProtocolHandler { |
| 21 public: |
| 22 // Uses the global content client to fetch resources. |
| 23 ResourceProtocolHandler(); |
| 24 |
| 25 // Uses the provided content client to fetch resources (for testing). |
| 26 ResourceProtocolHandler(ContentClient* content_client); |
| 27 |
| 28 ~ResourceProtocolHandler() override; |
| 29 |
| 30 // Registers a resource (specified by its resource ID and scale factor |
| 31 // as expected by ContentClient::GetDataResource) with the hostname |
| 32 // and path required to request it. This resource will be made |
| 33 // web-accessible, and served with the content type provided. |
| 34 // |
| 35 // Warning: calling this method exposes a resource to all web content. |
| 36 // Carefully consider whether the resource could be used for XSS before |
| 37 // registering it. |
| 38 void RegisterResource(const std::string& host, |
| 39 const std::string& path, |
| 40 int resource_id, |
| 41 ui::ScaleFactor scale_factor, |
| 42 const std::string& content_type); |
| 43 |
| 44 // Overridden from net::URLRequestJobFactory::ProtocolHandler: |
| 45 net::URLRequestJob* MaybeCreateJob( |
| 46 net::URLRequest* request, |
| 47 net::NetworkDelegate* network_delegate) const override; |
| 48 bool IsSafeRedirectTarget(const GURL& location) const override; |
| 49 |
| 50 // Public for the URLRequestJob subclass. |
| 51 struct WebAccessibleResource { |
| 52 int resource_id; |
| 53 ui::ScaleFactor scale_factor; |
| 54 std::string content_type; |
| 55 }; |
| 56 |
| 57 private: |
| 58 ContentClient* content_client_; |
| 59 |
| 60 // Map from (host, path) pairs to resource info. |
| 61 std::map<std::pair<std::string, std::string>, WebAccessibleResource> |
| 62 resources_; |
| 63 }; |
| 64 |
| 65 CONTENT_EXPORT void RegisterDefaultWebAccessibleResources( |
| 66 ResourceProtocolHandler* handler); |
| 67 |
| 68 } // namespace content |
| 69 |
| 70 #endif // CONTENT_BROWSER_RESOURCE_PROTOCOL_HANDLER_H_ |
OLD | NEW |