diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 23:28:53 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 23:28:53 +0000 |
commit | 755e1b73a0b4894ecc36401fd042c744e7837844 (patch) | |
tree | 63fe18c53ff1e42368c0a38f5c8a4475aaceb7fe /chrome/browser/dom_ui | |
parent | 25bacf3dd25367f130baa92895a0c01c3d1d7e13 (diff) | |
download | chromium_src-755e1b73a0b4894ecc36401fd042c744e7837844.zip chromium_src-755e1b73a0b4894ecc36401fd042c744e7837844.tar.gz chromium_src-755e1b73a0b4894ecc36401fd042c744e7837844.tar.bz2 |
Reapply "Move the files in resources/shared/ into resources.pak"
Now with one line fix to fix the mac build.
BUG=35793,42770
TEST=none
TBR=tony
Review URL: http://codereview.chromium.org/2842025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50783 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/chrome_url_data_manager.cc | 15 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shared_resources_data_source.cc | 88 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shared_resources_data_source.h | 33 |
3 files changed, 123 insertions, 13 deletions
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc index a011801..c5aad64 100644 --- a/chrome/browser/dom_ui/chrome_url_data_manager.cc +++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc @@ -19,6 +19,7 @@ #include "chrome/browser/appcache/view_appcache_internals_job_factory.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/dom_ui/shared_resources_data_source.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/view_http_cache_job_factory.h" #include "chrome/common/chrome_paths.h" @@ -98,13 +99,7 @@ void RegisterURLRequestChromeJob() { chrome::kChromeUIDevToolsHost, inspector_dir); } - // Set up the chrome://resources/ source. - FilePath resources_dir; - if (PathService::Get(chrome::DIR_SHARED_RESOURCES, &resources_dir)) { - Singleton<ChromeURLDataManager>()->AddFileSource( - chrome::kChromeUIResourcesHost, resources_dir); - } - + SharedResourcesDataSource::Register(); URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, &ChromeURLDataManager::Factory); } @@ -115,12 +110,6 @@ void UnregisterURLRequestChromeJob() { Singleton<ChromeURLDataManager>()->RemoveFileSource( chrome::kChromeUIDevToolsHost); } - - FilePath resources_dir; - if (PathService::Get(chrome::DIR_SHARED_RESOURCES, &resources_dir)) { - Singleton<ChromeURLDataManager>()->RemoveFileSource( - chrome::kChromeUIResourcesHost); - } } // static diff --git a/chrome/browser/dom_ui/shared_resources_data_source.cc b/chrome/browser/dom_ui/shared_resources_data_source.cc new file mode 100644 index 0000000..d460cdd --- /dev/null +++ b/chrome/browser/dom_ui/shared_resources_data_source.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2010 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/dom_ui/shared_resources_data_source.h" + +#include "app/resource_bundle.h" +#include "base/singleton.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/dom_ui/chrome_url_data_manager.h" +#include "chrome/browser/io_thread.h" +#include "chrome/common/url_constants.h" +#include "grit/generated_resources.h" +#include "grit/shared_resources.h" +#include "grit/shared_resources_map.h" +#include "grit/app_resources.h" +#include "grit/theme_resources.h" +#include "net/base/mime_util.h" + +namespace { + +int PathToIDR(const std::string& path) { + int idr = -1; + if (path == "images/bookmark_bar_folder_mac.png") { + idr = IDR_BOOKMARK_BAR_FOLDER; + } else if (path == "images/folder_closed.png") { + idr = IDR_FOLDER_CLOSED; + } else if (path == "images/folder_closed_rtl.png") { + idr = IDR_FOLDER_CLOSED_RTL; + } else if (path == "images/folder_open.png") { + idr = IDR_FOLDER_OPEN; + } else if (path == "images/folder_open_rtl.png") { + idr = IDR_FOLDER_OPEN_RTL; + } 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 + +// static +void SharedResourcesDataSource::Register() { + SharedResourcesDataSource* source = new SharedResourcesDataSource(); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + Singleton<ChromeURLDataManager>::get(), + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(source))); +} + +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 { + std::string mime_type; + net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); + return mime_type; +} + diff --git a/chrome/browser/dom_ui/shared_resources_data_source.h b/chrome/browser/dom_ui/shared_resources_data_source.h new file mode 100644 index 0000000..0dfe83a --- /dev/null +++ b/chrome/browser/dom_ui/shared_resources_data_source.h @@ -0,0 +1,33 @@ +// Copyright (c) 2010 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 CHROME_BROWSER_DOM_UI_SHARED_RESOURCES_DATA_SOURCE_H_ +#define CHROME_BROWSER_DOM_UI_SHARED_RESOURCES_DATA_SOURCE_H_ + +#include "chrome/browser/dom_ui/chrome_url_data_manager.h" + +class GURL; +class URLRequest; +class URLRequestJob; + +// A DataSource for chrome://resources/ URLs. +class SharedResourcesDataSource : public ChromeURLDataManager::DataSource { + public: + // Registers an instance of this data source with the ChromeUrlDataManager. + static void Register(); + + // Overridden from ChromeURLDataManager::DataSource: + virtual void StartDataRequest(const std::string& path, + bool is_off_the_record, + int request_id); + virtual std::string GetMimeType(const std::string&) const; + + private: + SharedResourcesDataSource(); + ~SharedResourcesDataSource(); + + DISALLOW_COPY_AND_ASSIGN(SharedResourcesDataSource); +}; + +#endif // CHROME_BROWSER_DOM_UI_SHARED_RESOURCES_DATA_SOURCE_H_ |