diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 00:45:34 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 00:45:34 +0000 |
commit | 1408c8297755306f0d688956fbc2f93fd6d692ac (patch) | |
tree | 50997a29208c8505961d7fd8634b7abd2a632c5c | |
parent | c01c61d5d1b86b72e4e1ee4a96870196a8057644 (diff) | |
download | chromium_src-1408c8297755306f0d688956fbc2f93fd6d692ac.zip chromium_src-1408c8297755306f0d688956fbc2f93fd6d692ac.tar.gz chromium_src-1408c8297755306f0d688956fbc2f93fd6d692ac.tar.bz2 |
Revert 50057 - Load net-internals from the newly created resources.pak file.
This patch also forces the loading of the optional DataPack for const correctness reasons
BUG=35793,42770
TEST=none
Review URL: http://codereview.chromium.org/2855003
TBR=erg@chromium.org
Review URL: http://codereview.chromium.org/2852011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50059 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | app/resource_bundle.cc | 28 | ||||
-rw-r--r-- | app/resource_bundle.h | 5 | ||||
-rw-r--r-- | base/data_pack.cc | 4 | ||||
-rw-r--r-- | base/data_pack.h | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/net_internals_ui.cc | 78 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 37 | ||||
-rw-r--r-- | chrome/common/chrome_paths.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_paths.h | 1 |
8 files changed, 91 insertions, 71 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc index d61e83d..dcf7fa8 100644 --- a/app/resource_bundle.cc +++ b/app/resource_bundle.cc @@ -105,17 +105,7 @@ SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( int resource_id) const { - RefCountedStaticMemory* bytes = - LoadResourceBytes(resources_data_, resource_id); - - // Check all our additional data packs for the resources if it wasn't loaded - // from our main source. - for (std::vector<LoadedDataPack*>::const_iterator it = data_packs_.begin(); - !bytes && it != data_packs_.end(); ++it) { - bytes = (*it)->GetStaticMemory(resource_id); - } - - return bytes; + return LoadResourceBytes(resources_data_, resource_id); } SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { @@ -208,8 +198,11 @@ const gfx::Font& ResourceBundle::GetFont(FontStyle style) { // LoadedDataPack implementation ResourceBundle::LoadedDataPack::LoadedDataPack(const FilePath& path) : path_(path) { - // Always preload the data packs so we can maintain constness. + // On unicies, we preload data packs so background updates don't cause us to + // load the wrong data. +#if defined(OS_POSIX) && !defined(OS_MACOSX) Load(); +#endif } void ResourceBundle::LoadedDataPack::Load() { @@ -219,12 +212,9 @@ void ResourceBundle::LoadedDataPack::Load() { CHECK(success) << "Failed to load " << path_.value(); } -bool ResourceBundle::LoadedDataPack::GetStringPiece( - int resource_id, base::StringPiece* data) const { +bool ResourceBundle::LoadedDataPack::GetStringPiece(int resource_id, + base::StringPiece* data) { + if (!data_pack_.get()) + Load(); return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data); } - -RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( - int resource_id) const { - return data_pack_->GetStaticMemory(resource_id); -} diff --git a/app/resource_bundle.h b/app/resource_bundle.h index 1d328a3..3a3e617 100644 --- a/app/resource_bundle.h +++ b/app/resource_bundle.h @@ -159,9 +159,8 @@ class ResourceBundle { // Helper class for managing data packs. class LoadedDataPack { public: - explicit LoadedDataPack(const FilePath& path); - bool GetStringPiece(int resource_id, base::StringPiece* data) const; - RefCountedStaticMemory* GetStaticMemory(int resource_id) const; + LoadedDataPack(const FilePath& path); + bool GetStringPiece(int resource_id, base::StringPiece* data); private: void Load(); diff --git a/base/data_pack.cc b/base/data_pack.cc index 06f2308..4e5a569 100644 --- a/base/data_pack.cc +++ b/base/data_pack.cc @@ -96,7 +96,7 @@ bool DataPack::Load(const FilePath& path) { return true; } -bool DataPack::GetStringPiece(uint32 resource_id, StringPiece* data) const { +bool DataPack::GetStringPiece(uint32 resource_id, StringPiece* data) { // It won't be hard to make this endian-agnostic, but it's not worth // bothering to do right now. #if defined(__BYTE_ORDER) @@ -119,7 +119,7 @@ bool DataPack::GetStringPiece(uint32 resource_id, StringPiece* data) const { return true; } -RefCountedStaticMemory* DataPack::GetStaticMemory(uint32 resource_id) const { +RefCountedStaticMemory* DataPack::GetStaticMemory(uint32 resource_id) { base::StringPiece piece; if (!GetStringPiece(resource_id, &piece)) return NULL; diff --git a/base/data_pack.h b/base/data_pack.h index f3f8481..8938491 100644 --- a/base/data_pack.h +++ b/base/data_pack.h @@ -35,12 +35,12 @@ class DataPack { // Get resource by id |resource_id|, filling in |data|. // The data is owned by the DataPack object and should not be modified. // Returns false if the resource id isn't found. - bool GetStringPiece(uint32 resource_id, StringPiece* data) const; + bool GetStringPiece(uint32 resource_id, StringPiece* data); // Like GetStringPiece(), but returns a reference to memory. This interface // is used for image data, while the StringPiece interface is usually used // for localization strings. - RefCountedStaticMemory* GetStaticMemory(uint32 resource_id) const; + RefCountedStaticMemory* GetStaticMemory(uint32 resource_id); // Writes a pack file containing |resources| to |path|. static bool WritePack(const FilePath& path, diff --git a/chrome/browser/dom_ui/net_internals_ui.cc b/chrome/browser/dom_ui/net_internals_ui.cc index 96ee59e..553d197 100644 --- a/chrome/browser/dom_ui/net_internals_ui.cc +++ b/chrome/browser/dom_ui/net_internals_ui.cc @@ -36,8 +36,6 @@ #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/url_constants.h" #include "grit/generated_resources.h" -#include "grit/net_internals_resources.h" -#include "grit/net_internals_resources_map.h" #include "net/base/escape.h" #include "net/base/host_resolver_impl.h" #include "net/base/net_errors.h" @@ -318,57 +316,51 @@ NetInternalsHTMLSource::NetInternalsHTMLSource() void NetInternalsHTMLSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { + // The provided |path| identifies a file in resources/net_internals/. + std::string data_string; + FilePath file_path; + PathService::Get(chrome::DIR_NET_INTERNALS, &file_path); + std::string filename; + // The provided "path" may contain a fragment, or query section. We only // care about the path itself, and will disregard anything else. - std::string filename = - GURL(std::string("chrome://net/") + path).path().substr(1); + filename = GURL(std::string("chrome://net/") + path).path().substr(1); + if (filename.empty()) filename = "index.html"; - // The name of the files in the grd list are prefixed with the following - // directory: - std::string key("net_internals/"); - key += filename; - - const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - for (size_t i = 0; i < kNetInternalsResourcesSize; ++i) { - if (kNetInternalsResources[i].name == key) { - scoped_refptr<RefCountedStaticMemory> bytes( - rb.LoadDataResourceBytes(kNetInternalsResources[i].value)); - if (bytes && bytes->front()) { - SendResponse(request_id, bytes); - return; - } - } + file_path = file_path.AppendASCII(filename); + + if (!file_util::ReadFileToString(file_path, &data_string)) { + LOG(WARNING) << "Could not read resource: " << file_path.value(); + data_string = StringPrintf("<p style='color:red'>Failed to read file " + "RESOURCES/net_internals/%s</p>", + EscapeForHTML(filename).c_str()); + + // During the transition from old implementation to new implementation, + // users may be entering the URLs for the old frontend. + data_string.append( + "<p>Note that the URL scheme for net-internals has changed because of " + "its new implementation (bug 37421):</p>" + "<ul>" + "<li>chrome://net-internals/proxyservice.* → " + "<a href='chrome://net-internals#proxy'>chrome://net-internals#proxy" + "</a></li>" + "<li>chrome://net-internals/hostresolver.* → <a href='chrome://net" + "-internals#dns'>chrome://net-internals#dns</a></li>" + "<li>chrome://net-internals/urlrequest.* → <a href='chrome://net-" + "internals#requests'>chrome://net-internals#requests</a></li>" + "<li>chrome://net-internals/ (overview for copy-pasting) → <a href" + "='chrome://net-internals#data'>chrome://net-internals#data</a></li>" + "<li>chrome://net-internals/view-cache/* → <a href=" + "'chrome://view-http-cache'>chrome://view-http-cache</a></li>" + "</ul>"); } - LOG(WARNING) << "Could not read resource: " << path; - std::string data_string = "<p style='color:red'>Failed to read resource"; - data_string.append(EscapeForHTML(filename)); - data_string.append("</p>"); - - // During the transition from old implementation to new implementation, - // users may be entering the URLs for the old frontend. - data_string.append( - "<p>Note that the URL scheme for net-internals has changed because of " - "its new implementation (bug 37421):</p>" - "<ul>" - "<li>chrome://net-internals/proxyservice.* → " - "<a href='chrome://net-internals#proxy'>chrome://net-internals#proxy" - "</a></li>" - "<li>chrome://net-internals/hostresolver.* → <a href='chrome://net" - "-internals#dns'>chrome://net-internals#dns</a></li>" - "<li>chrome://net-internals/urlrequest.* → <a href='chrome://net-" - "internals#requests'>chrome://net-internals#requests</a></li>" - "<li>chrome://net-internals/ (overview for copy-pasting) → <a href" - "='chrome://net-internals#data'>chrome://net-internals#data</a></li>" - "<li>chrome://net-internals/view-cache/* → <a href=" - "'chrome://view-http-cache'>chrome://view-http-cache</a></li>" - "</ul>"); - scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes); bytes->data.resize(data_string.size()); std::copy(data_string.begin(), data_string.end(), bytes->data.begin()); + SendResponse(request_id, bytes); } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 686d527..2604138 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -17,6 +17,7 @@ 'chrome_version_info', 'component_extensions', 'domui_shared_resources', + 'net_internals_resources', 'platform_locale_settings', 'profile_import', 'browser/sync/protocol/sync_proto.gyp:sync_proto_cpp', @@ -2671,9 +2672,8 @@ 'browser/zygote_host_linux.cc', 'browser/zygote_main_linux.cc', - # These files are generated by GRIT. + # This file is generated by GRIT. '<(grit_out_dir)/grit/theme_resources_map.cc', - '<(grit_out_dir)/grit/net_internals_resources_map.cc', ], 'conditions': [ ['javascript_engine=="v8"', { @@ -3540,6 +3540,39 @@ ], }, { + 'target_name': 'net_internals_resources', + 'type': 'none', + # TODO(eroman): Once the msvs port supports it, change this to recursively + # copy the entire directory instead of listing the files. + # http://code.google.com/p/gyp/issues/detail?id=143. + 'copies': [ + { + 'destination': '<(PRODUCT_DIR)/resources/net_internals', + 'files': [ + 'browser/resources/net_internals/dataview.js', + 'browser/resources/net_internals/detailsview.js', + 'browser/resources/net_internals/dnsview.js', + 'browser/resources/net_internals/httpcacheview.js', + 'browser/resources/net_internals/index.html', + 'browser/resources/net_internals/loggrouper.js', + 'browser/resources/net_internals/logviewpainter.js', + 'browser/resources/net_internals/main.css', + 'browser/resources/net_internals/main.js', + 'browser/resources/net_internals/proxyview.js', + 'browser/resources/net_internals/requestsview.js', + 'browser/resources/net_internals/resizableverticalsplitview.js', + 'browser/resources/net_internals/sourceentry.js', + 'browser/resources/net_internals/tabswitcherview.js', + 'browser/resources/net_internals/testview.js', + 'browser/resources/net_internals/timelineviewpainter.js', + 'browser/resources/net_internals/topmidbottomview.js', + 'browser/resources/net_internals/util.js', + 'browser/resources/net_internals/view.js', + ] + }, + ] + }, + { # Protobuf compiler / generate rule for feedback 'target_name': 'userfeedback_proto', 'type': 'none', diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index b0559688..9dca7e0 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -168,6 +168,11 @@ bool PathProvider(int key, FilePath* result) { return false; cur = cur.Append(FILE_PATH_LITERAL("inspector")); break; + case chrome::DIR_NET_INTERNALS: + if (!PathService::Get(chrome::DIR_RESOURCES, &cur)) + return false; + cur = cur.Append(FILE_PATH_LITERAL("net_internals")); + break; case chrome::DIR_APP_DICTIONARIES: #if defined(OS_LINUX) || defined(OS_MACOSX) // We can't write into the EXE dir on Linux, so keep dictionaries diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h index 258123d..69239ad 100644 --- a/chrome/common/chrome_paths.h +++ b/chrome/common/chrome_paths.h @@ -26,6 +26,7 @@ enum { // by DOMUI and component extensions. DIR_BOOKMARK_MANAGER, // Directory containing the bookmark manager. DIR_INSPECTOR, // Directory where web inspector is located. + DIR_NET_INTERNALS, // Directory where net internals is located. DIR_APP_DICTIONARIES, // Directory where the global dictionaries are. DIR_USER_DOCUMENTS, // Directory for a user's "My Documents". DIR_DEFAULT_DOWNLOADS_SAFE, // Directory for a user's |