Index: content/browser/resource_protocol.h |
diff --git a/content/browser/resource_protocol.h b/content/browser/resource_protocol.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e65c8ffb186ee0db113520a75c53fd1fa67a844d |
--- /dev/null |
+++ b/content/browser/resource_protocol.h |
@@ -0,0 +1,61 @@ |
+// 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_H_ |
+#define CONTENT_BROWSER_RESOURCE_PROTOCOL_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; |
+ |
+ public: |
+ // 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_; |
+ std::map<std::pair<std::string, std::string>, WebAccessibleResource> |
+ resources_; |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_RESOURCE_PROTOCOL_H_ |