| Index: chrome/browser/extensions/extension_protocols.cc
|
| diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
|
| index 02964fa0ac652bbafd6e86fba4b4f5ba056c73e2..2a740f12ad1874c2d5e8988725c43bd4cd2c37e5 100644
|
| --- a/chrome/browser/extensions/extension_protocols.cc
|
| +++ b/chrome/browser/extensions/extension_protocols.cc
|
| @@ -4,18 +4,67 @@
|
|
|
| #include "chrome/browser/extensions/extension_protocols.h"
|
|
|
| +#include <algorithm>
|
| +
|
| +#include "app/resource_bundle.h"
|
| +#include "base/file_path.h"
|
| +#include "base/logging.h"
|
| +#include "base/message_loop.h"
|
| +#include "base/path_service.h"
|
| #include "base/string_util.h"
|
| #include "chrome/browser/net/chrome_url_request_context.h"
|
| #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
|
| #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "chrome/common/extensions/extension_file_util.h"
|
| #include "chrome/common/extensions/extension_resource.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "googleurl/src/url_util.h"
|
| +#include "grit/bookmark_manager_resources_map.h"
|
| +#include "net/base/mime_util.h"
|
| #include "net/base/net_errors.h"
|
| -#include "net/url_request/url_request_file_job.h"
|
| #include "net/url_request/url_request_error_job.h"
|
| +#include "net/url_request/url_request_file_job.h"
|
| +#include "net/url_request/url_request_simple_job.h"
|
| +
|
| +namespace {
|
| +
|
| +class URLRequestResourceBundleJob : public URLRequestSimpleJob {
|
| + public:
|
| + explicit URLRequestResourceBundleJob(URLRequest* request,
|
| + const FilePath& filename, int resource_id)
|
| + : URLRequestSimpleJob(request),
|
| + filename_(filename),
|
| + resource_id_(resource_id) { }
|
| +
|
| + // URLRequestSimpleJob method.
|
| + virtual bool GetData(std::string* mime_type,
|
| + std::string* charset,
|
| + std::string* data) const {
|
| + const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + *data = rb.GetRawDataResource(resource_id_).as_string();
|
| + bool result = net::GetMimeTypeFromFile(filename_, mime_type);
|
| + if (StartsWithASCII(*mime_type, "text/", false)) {
|
| + // All of our HTML files should be UTF-8 and for other resource types
|
| + // (like images), charset doesn't matter.
|
| + DCHECK(IsStringUTF8(*data));
|
| + *charset = "utf-8";
|
| + }
|
| + return result;
|
| + }
|
| +
|
| + private:
|
| + virtual ~URLRequestResourceBundleJob() { }
|
| +
|
| + // We need the filename of the resource to determine the mime type.
|
| + FilePath filename_;
|
| +
|
| + // The resource bundle id to load.
|
| + int resource_id_;
|
| +};
|
| +
|
| +} // namespace
|
|
|
| // Factory registered with URLRequest to create URLRequestJobs for extension://
|
| // URLs.
|
| @@ -41,6 +90,26 @@ static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request,
|
| return NULL;
|
| }
|
|
|
| + FilePath resources_path;
|
| + if (PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_path) &&
|
| + directory_path.DirName() == resources_path.RemoveExtension()) {
|
| + FilePath relative_path = directory_path.BaseName().Append(
|
| + extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
|
| +
|
| + // TODO(tc): Make a map of FilePath -> resource ids so we don't have to
|
| + // covert to FilePaths all the time. This will be more useful as we add
|
| + // more resources.
|
| + for (size_t i = 0; i < kBookmarkManagerResourcesSize; ++i) {
|
| + FilePath bm_resource_path =
|
| + FilePath().AppendASCII(kBookmarkManagerResources[i].name);
|
| + if (relative_path == bm_resource_path) {
|
| + return new URLRequestResourceBundleJob(request, relative_path,
|
| + kBookmarkManagerResources[i].value);
|
| + }
|
| + }
|
| + }
|
| + // TODO(tc): Move all of these files into resources.pak so we don't break
|
| + // when updating on Linux.
|
| ExtensionResource resource(directory_path,
|
| extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
|
|
|
|
|