diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-27 19:33:36 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-27 19:33:36 +0000 |
commit | fd42ac30f127624def51d949e21f9776b0e6d257 (patch) | |
tree | 690ae7b46b66bbc03051b460ca5ee66a6665554f /chrome/browser/ui/webui/shared_resources_data_source.cc | |
parent | 8ea6a9e57e924dabe697cbf73b6fda59c6297664 (diff) | |
download | chromium_src-fd42ac30f127624def51d949e21f9776b0e6d257.zip chromium_src-fd42ac30f127624def51d949e21f9776b0e6d257.tar.gz chromium_src-fd42ac30f127624def51d949e21f9776b0e6d257.tar.bz2 |
WebUI: Move the remaining files from chrome/browser/webui to chrome/browser/ui/webui. Final Part.
BUG=59946
TEST=trybots
Review URL: http://codereview.chromium.org/6594035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76191 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui/shared_resources_data_source.cc')
-rw-r--r-- | chrome/browser/ui/webui/shared_resources_data_source.cc | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/shared_resources_data_source.cc b/chrome/browser/ui/webui/shared_resources_data_source.cc new file mode 100644 index 0000000..dbcf43f --- /dev/null +++ b/chrome/browser/ui/webui/shared_resources_data_source.cc @@ -0,0 +1,83 @@ +// Copyright (c) 2011 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. + +#include "chrome/browser/ui/webui/shared_resources_data_source.h" + +#include <string> + +#include "base/singleton.h" +#include "base/threading/thread_restrictions.h" +#include "chrome/browser/browser_thread.h" +#include "chrome/browser/io_thread.h" +#include "chrome/browser/ui/webui/chrome_url_data_manager.h" +#include "chrome/common/url_constants.h" +#include "grit/app_resources.h" +#include "grit/generated_resources.h" +#include "grit/shared_resources.h" +#include "grit/shared_resources_map.h" +#include "grit/theme_resources.h" +#include "net/base/mime_util.h" +#include "ui/base/resource/resource_bundle.h" + +namespace { + +int PathToIDR(const std::string& path) { + int idr = -1; + if (path == "app/resources/folder_closed.png") { + idr = IDR_FOLDER_CLOSED; + } else if (path == "app/resources/folder_closed_rtl.png") { + idr = IDR_FOLDER_CLOSED_RTL; + } else if (path == "app/resources/folder_open.png") { + idr = IDR_FOLDER_OPEN; + } else if (path == "app/resources/folder_open_rtl.png") { + idr = IDR_FOLDER_OPEN_RTL; + } else if (path == "app/resources/throbber.png") { + idr = IDR_THROBBER; + } else { + // The name of the files in the grd list are prefixed with the following + // directory: + std::string key("shared/"); + key += path; + + for (size_t i = 0; i < kSharedResourcesSize; ++i) { + if (kSharedResources[i].name == key) { + idr = kSharedResources[i].value; + break; + } + } + } + + return idr; +} + +} // namespace + +SharedResourcesDataSource::SharedResourcesDataSource() + : DataSource(chrome::kChromeUIResourcesHost, NULL) { +} + +SharedResourcesDataSource::~SharedResourcesDataSource() { +} + +void SharedResourcesDataSource::StartDataRequest(const std::string& path, + bool is_off_the_record, + int request_id) { + int idr = PathToIDR(path); + DCHECK_NE(-1, idr); + const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + scoped_refptr<RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(idr)); + SendResponse(request_id, bytes); +} + +std::string SharedResourcesDataSource::GetMimeType( + const std::string& path) const { + // Requests should not block on the disk! On Windows this goes to the + // registry. + // http://code.google.com/p/chromium/issues/detail?id=59849 + base::ThreadRestrictions::ScopedAllowIO allow_io; + + std::string mime_type; + net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); + return mime_type; +} |