One way to add a default theme in chromium

Source: Internet
Author: User

First of all, chromium in addition to the default theme, the others are installed in Chrome extension, so for a new theme, you need to set a theme ID, the subject ID can be set one by oneself, as long as the length of the same, but the subject ID will have a letter range limit, So you can find a ready-made ID, and then directly exchange a few letters of the location, the subsequent ID will not really use.

Src\chrome\browser\themes\theme_service.ccconst char* Themeservice::kdefaultthemeid = ""; Const char* ThemeService:: Knewdefaultthemeid = "NDOIPPCJLIPFDDFFDCIMAKHEBAEMNMGN";

In theme_service_factory.cc, set the default registration theme ID to the new theme ID.

src\chrome\browser\themes\theme_service_factory.cc  registry->registerstringpref (      prefs:: Kcurrentthemeid,  Themeservice::knewdefaultthemeid,      user_prefs::P refregistrysyncable::unsyncable_pref);

After Chrome is launched, the Themeservice::init function is called, which goes into the loadthemeprefs function, but after entering Loadthemeprefs, the topic is not loaded, because the current Current_ The ID equals knewdefaultthemeid,kcurrentthemepackfilename is empty. Themeservice will listen to the notification_extensions_ready signal, when the extension system starts, call Themeservice Onextensionserviceready function, Next, you can load the theme through the extension system. In the Onextensionserviceready function, the current value of Ready_ is false because no topic is loaded. Call the Migratetheme function to change the function to

void Themeservice::migratetheme () {//TODO (ERG): We need to pops up a dialog informing the U  Ser, 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::D Ir_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")); }  }}
Since the initial subject ID is Knewdefaultthemeid, you will need to load the topic extension from the given folder New_theme_dir. Migratetheme Run finished calling notifythemechanged, the topic loading is complete.


When you reset a theme, the Clearallthemedata function is called, which resets the theme ID and re-loads the topic.
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 ();}


One way to add a default theme in chromium

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.