Index: content/browser/resource_protocol_handler.h |
diff --git a/content/browser/resource_protocol_handler.h b/content/browser/resource_protocol_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9676aa813b19d9658b62c98113e8df938e0aa1d3 |
--- /dev/null |
+++ b/content/browser/resource_protocol_handler.h |
@@ -0,0 +1,70 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_RESOURCE_PROTOCOL_HANDLER_H_ |
+#define CONTENT_BROWSER_RESOURCE_PROTOCOL_HANDLER_H_ |
+ |
+#include <map> |
+#include <utility> |
+ |
+#include "content/common/content_export.h" |
+#include "net/url_request/url_request_job_factory.h" |
+#include "ui/base/layout.h" |
+ |
+namespace content { |
+ |
+class ContentClient; |
+ |
+class CONTENT_EXPORT ResourceProtocolHandler |
+ : public net::URLRequestJobFactory::ProtocolHandler { |
+ public: |
+ // Uses the global content client to fetch resources. |
+ ResourceProtocolHandler(); |
+ |
+ // Uses the provided content client to fetch resources (for testing). |
+ ResourceProtocolHandler(ContentClient* content_client); |
+ |
+ ~ResourceProtocolHandler() override; |
+ |
+ // Registers a resource (specified by its resource ID and scale factor |
+ // as expected by ContentClient::GetDataResource) with the hostname |
+ // and path required to request it. This resource will be made |
+ // web-accessible, and served with the content type provided. |
+ // |
+ // Warning: calling this method exposes a resource to all web content. |
+ // Carefully consider whether the resource could be used for XSS before |
+ // registering it. |
+ void RegisterResource(const std::string& host, |
+ const std::string& path, |
+ int resource_id, |
+ ui::ScaleFactor scale_factor, |
+ const std::string& content_type); |
+ |
+ // Overridden from net::URLRequestJobFactory::ProtocolHandler: |
+ net::URLRequestJob* MaybeCreateJob( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const override; |
+ bool IsSafeRedirectTarget(const GURL& location) const override; |
+ |
+ // Public for the URLRequestJob subclass. |
+ struct WebAccessibleResource { |
+ int resource_id; |
+ ui::ScaleFactor scale_factor; |
+ std::string content_type; |
+ }; |
+ |
+ private: |
+ ContentClient* content_client_; |
+ |
+ // Map from (host, path) pairs to resource info. |
+ std::map<std::pair<std::string, std::string>, WebAccessibleResource> |
+ resources_; |
+}; |
+ |
+CONTENT_EXPORT void RegisterDefaultWebAccessibleResources( |
+ ResourceProtocolHandler* handler); |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_RESOURCE_PROTOCOL_HANDLER_H_ |