Chromium Code Reviews| Index: chrome/browser/extensions/extension_protocols.cc |
| diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc |
| index 9221c5c56b8d45a7d836cbdc79508b93290521a7..f653297a73034ca1f49d7c197a19b6786060fe36 100644 |
| --- a/chrome/browser/extensions/extension_protocols.cc |
| +++ b/chrome/browser/extensions/extension_protocols.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/message_loop.h" |
| #include "base/path_service.h" |
| #include "base/string_util.h" |
| +#include "base/stringprintf.h" |
| #include "base/threading/thread_restrictions.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/extensions/extension_info_map.h" |
| @@ -101,6 +102,42 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { |
| net::HttpResponseInfo response_info_; |
| }; |
| +class GeneratedBackgroundPageJob : public net::URLRequestSimpleJob { |
|
Matt Perry
2012/01/09 21:12:17
Please add a class comment
|
| + public: |
| + GeneratedBackgroundPageJob(net::URLRequest* request, |
| + const scoped_refptr<const Extension> extension, |
| + const std::string& content_security_policy) |
| + : net::URLRequestSimpleJob(request), |
| + extension_(extension) { |
| + response_info_.headers = BuildHttpHeaders(content_security_policy); |
| + } |
| + |
| + // Overridden from URLRequestSimpleJob: |
| + virtual bool GetData(std::string* mime_type, |
| + std::string* charset, |
| + std::string* data) const OVERRIDE { |
| + *mime_type = "text/html"; |
| + *charset = "utf-8"; |
| + |
| + *data = "<!DOCTYPE html>\n<body>\n"; |
| + for (size_t i = 0; i < extension_->background_scripts().size(); ++i) { |
| + *data += "<script src=\""; |
| + *data += extension_->background_scripts()[i]; |
| + *data += "\"></script>\n"; |
| + } |
| + |
| + return true; |
| + } |
| + |
| + virtual void GetResponseInfo(net::HttpResponseInfo* info) { |
| + *info = response_info_; |
| + } |
| + |
| + private: |
| + scoped_refptr<const Extension> extension_; |
| + net::HttpResponseInfo response_info_; |
| +}; |
| + |
| class URLRequestExtensionJob : public net::URLRequestFileJob { |
| public: |
| URLRequestExtensionJob(net::URLRequest* request, |
| @@ -221,6 +258,13 @@ ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const { |
| if (extension) |
| content_security_policy = extension->content_security_policy(); |
| + std::string path = request->url().path(); |
| + if (path.size() > 1 && |
| + path.substr(1) == extension_filenames::kGeneratedBackgroundPageFilename) { |
| + return new GeneratedBackgroundPageJob( |
| + request, extension, content_security_policy); |
| + } |
| + |
| FilePath resources_path; |
| if (PathService::Get(chrome::DIR_RESOURCES, &resources_path) && |
| directory_path.DirName() == resources_path) { |