首先,chromium除了默认主题外,其它都是以chrome拓展的方式安装的,所以对于一个新的主题,需要定一个主题id,这个主题id可以先自己定一个,只要长度一致就可以了,但是主题id会有字母范围的限制,所以可以找一个现成的id,然后直接交换几个字母的位置就可以,后继这个id并不会真正用到。
src\chrome\browser\themes\theme_service.cc const char* ThemeService::kDefaultThemeID = ""; const char* ThemeService::kNewDefaultThemeID = "ndoippcjlipfddffdcimakhebaemnmgn";
src\chrome\browser\themes\theme_service_factory.cc registry->RegisterStringPref( prefs::kCurrentThemeID, ThemeService::kNewDefaultThemeID, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
void ThemeService::MigrateTheme() { // TODO(erg): We need to pop up a dialog informing the user that their // theme is being migrated. ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->extension_service(); const Extension* extension = service ? service->GetExtensionById(GetThemeID(), false) : NULL; if (extension) { DLOG(ERROR) << "Migrating theme"; BuildFromExtension(extension); content::RecordAction(UserMetricsAction("Themes.Migrated")); } else { if (GetThemeID() == kNewDefaultThemeID) { base::FilePath dir_exe; PathService::Get(base::DIR_EXE, &dir_exe); base::FilePath new_theme_dir(dir_exe.value() + FILE_PATH_LITERAL("/new_theme")); extensions::UnpackedInstaller::Create(service)->Load(new_theme_dir); } else { DLOG(ERROR) << "Theme is mysteriously gone."; ClearAllThemeData(); content::RecordAction(UserMetricsAction("Themes.Gone")); } } }由于初始的主题id是kNewDefaultThemeID,会需要从给定文件夹new_theme_dir载入主题拓展。MigrateTheme运行完毕调用NotifyThemeChanged,主题加载完成。
void ThemeService::ClearAllThemeData() { if (!ready_) return; SwapThemeSupplier(NULL); FreePlatformCaches(); profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename); SaveThemeID(kNewDefaultThemeID); base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes, weak_ptr_factory_.GetWeakPtr(), true)); MigrateTheme(); }
原文地址:http://blog.csdn.net/ljm198745/article/details/44410757