Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1729)

Unified Diff: chrome/common/resource_bundle_mac.mm

Issue 28171: Wire up resource bundles on the mac:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/resource_bundle_mac.mm
===================================================================
--- chrome/common/resource_bundle_mac.mm (revision 10335)
+++ chrome/common/resource_bundle_mac.mm (working copy)
@@ -4,7 +4,7 @@
#include "chrome/common/resource_bundle.h"
-#include <gtk/gtk.h>
+#include <Foundation/Foundation.h>
Mark Mentovai 2009/02/26 04:08:42 #import Cocoa headers.
TVL 2009/02/26 12:25:34 done (we don't want the min needed headers?)
#include "base/base_paths.h"
#include "base/data_pack.h"
@@ -29,45 +29,44 @@
resources_data_ = NULL;
}
+namespace {
+ base::DataPack* LoadResourceDataPack(NSString *name) {
Mark Mentovai 2009/02/26 04:08:42 There's no extra level of indentation in an namesp
TVL 2009/02/26 12:25:34 Done.
+ base::DataPack *resource_pack = NULL;
Mark Mentovai 2009/02/26 04:08:42 A pet peeve of mine is code that can't decide whet
TVL 2009/02/26 12:25:34 Done.
+
+ NSString *resource_path = [[NSBundle mainBundle] pathForResource:name
+ ofType:@"pak"];
+ if (resource_path) {
+ FilePath resources_pak_path([resource_path fileSystemRepresentation]);
+ resource_pack = new base::DataPack;
+ bool success = resource_pack->Load(resources_pak_path);
+ DCHECK(success) << "failed to load chrome.pak";
+ if (!success) {
+ delete resource_pack;
+ resource_pack = NULL;
+ }
+ }
+
+ return resource_pack;
+ }
+}
Mark Mentovai 2009/02/26 04:08:42 At the end of the namespace: } // namespace
TVL 2009/02/26 12:25:34 Done.
+
void ResourceBundle::LoadResources(const std::wstring& pref_locale) {
- FilePath resources_data_path;
- PathService::Get(base::DIR_EXE, &resources_data_path);
- resources_data_path = resources_data_path.Append(
- FILE_PATH_LITERAL("chrome.pak"));
+ DCHECK(pref_locale.size() == 0)
+ << "ignoring resource langage for cocoa's choice";
Mark Mentovai 2009/02/26 04:08:42 I have no idea what this message means or why it h
TVL 2009/02/26 12:25:34 Done.
+
DCHECK(resources_data_ == NULL) << "resource data already loaded!";
- resources_data_ = new base::DataPack;
- bool success = resources_data_->Load(resources_data_path);
- DCHECK(success) << "failed to load chrome.pak";
+ resources_data_ = LoadResourceDataPack(@"chrome");
+ DCHECK(resources_data_) << "failed to load chrome.pak";
- FilePath locale_path;
- PathService::Get(chrome::DIR_LOCALES, &locale_path);
- // TODO(tc): Handle other locales properly.
- NOTIMPLEMENTED() << " loading en-US strings only";
- locale_path = locale_path.Append(FILE_PATH_LITERAL("en-US.pak"));
DCHECK(locale_resources_data_ == NULL) << "locale data already loaded!";
- locale_resources_data_ = new base::DataPack;
- success = locale_resources_data_->Load(locale_path);
- DCHECK(success) << "failed to load locale pak file";
+ locale_resources_data_ = LoadResourceDataPack(@"locale");
+ DCHECK(locale_resources_data_) << "failed to load locale.pak";
}
-FilePath ResourceBundle::GetLocaleFilePath(const std::wstring& pref_locale) {
- FilePath locale_path;
- PathService::Get(chrome::DIR_LOCALES, &locale_path);
-
- const std::wstring app_locale = l10n_util::GetApplicationLocale(pref_locale);
- if (app_locale.empty())
- return FilePath();
-
- return locale_path.Append(WideToASCII(app_locale + L".pak"));
-}
-
void ResourceBundle::LoadThemeResources() {
- FilePath theme_data_path;
- PathService::Get(chrome::DIR_THEMES, &theme_data_path);
- theme_data_path = theme_data_path.Append(FILE_PATH_LITERAL("default.pak"));
- theme_data_ = new base::DataPack;
- bool success = theme_data_->Load(theme_data_path);
- DCHECK(success) << "failed to load theme data";
+ DCHECK(theme_data_ == NULL) << "theme data already loaded!";
+ theme_data_ = LoadResourceDataPack(@"theme");
+ DCHECK(theme_data_) << "failed to load theme.pak";
}
/* static */
@@ -116,27 +115,3 @@
data.length() / 2);
return UTF16ToWide(msg);
}
-
-GdkPixbuf* ResourceBundle::LoadPixbuf(int resource_id) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- std::vector<unsigned char> data;
- rb.LoadImageResourceBytes(resource_id, &data);
-
- GdkPixbufLoader* loader = gdk_pixbuf_loader_new();
- bool ok = gdk_pixbuf_loader_write(loader, static_cast<guint8*>(data.data()),
- data.size(), NULL);
- DCHECK(ok) << "failed to write " << resource_id;
- // Calling gdk_pixbuf_loader_close forces the data to be parsed by the
- // loader. We must do this before calling gdk_pixbuf_loader_get_pixbuf.
- ok = gdk_pixbuf_loader_close(loader, NULL);
- DCHECK(ok) << "close failed " << resource_id;
- GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
- DCHECK(pixbuf) << "failed to load " << resource_id << " " << data.size();
-
- // The pixbuf is owned by the loader, so add a ref so when we delete the
- // loader, the pixbuf still exists.
- g_object_ref(pixbuf);
- g_object_unref(loader);
-
- return pixbuf;
-}

Powered by Google App Engine
This is Rietveld 408576698