目前还有问题的chromium添加扩展程序
旧代码没有在最新的chromium没有生效
我也是参考这个的 但是还有问题
1.Add your Chromium extension (.crx) file to a list of default extensions to bundle with mini installer 2.Find out the ID of that extension 3.Automate extension installation process 4.By pass Chrome Web Store check 5.Build mini installer to install your Chromium fork
1.
src\chrome\browser\extensions\default_extensions\BUILD.gn
if (is_win) { copy("default_extensions") { sources = [ "external_extensions.json", "tab_capture.crx" ] outputs = [ "$root_out_dir/extensions/{{source_file_part}}", ]
并且添加crx到src\chrome\browser\extensions\default_extensions\tab_capture.crx
2.把打包的crx扔到chromium去 复制下面的那个id保存下
3.src\extensions\common\extension.h
namespace extensions { extern const int kOurNumExtensions; extern const char* kOurExtensionIds[]; extern const char* kOurExtensionFilenames[];
src\extensions\common\extension.cc
namespace extensions { const char* kOurExtensionIds[] = { "aaaaaaaaaaaaaaaaaaaaaaaaaaa"}; // Assumed extension ID of tab_capture const char* kOurExtensionFilenames[] = { "tab_capture.crx"}; const int kOurNumExtensions = 1;
记得删除默认路径 因为是第一次创建目录的时候就会安装扩展程序
src\chrome\browser\ui\startup\startup_browser_creator.cc
// Add these header files cause we we will be using them #include "base/path_service.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_install_prompt.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/common/chrome_paths.h" #include "extensions/browser/extension_system.h" bool StartupBrowserCreator::LaunchBrowser( const base::CommandLine& command_line, Profile* profile, const base::FilePath& cur_dir, chrome::startup::IsProcessStartup process_startup, chrome::startup::IsFirstRun is_first_run) { // Omitted Chromium code in_synchronous_profile_launch_ = false; } // Install our extension base::FilePath extension_dir; if (first_run::IsChromeFirstRun() && base::PathService::Get(chrome::DIR_EXTERNAL_EXTENSIONS, &extension_dir)) { for (int i = 0; i < extensions::kOurNumExtensions; ++i) { base::FilePath file_to_install(extension_dir.AppendASCII( extensions::kOurExtensionFilenames[i])); std::unique_ptr<ExtensionInstallPrompt> prompt( new ExtensionInstallPrompt(chrome::FindBrowserWithProfile(profile)->tab_strip_model()->GetActiveWebContents())); scoped_refptr<extensions::CrxInstaller> crx_installer(extensions::CrxInstaller::Create( extensions::ExtensionSystem::Get(profile)->extension_service(), std::move(prompt))); crx_installer->set_error_on_unsupported_requirements(true); crx_installer->set_off_store_install_allow_reason( extensions::CrxInstaller::OffStoreInstallAllowedFromSettingsPage); crx_installer->set_install_immediately(true); crx_installer->InstallCrx(file_to_install); } } // End of install our extension // Chromium code profile_launch_observer.Get().AddLaunched(profile);
但是因为我们希望在没有交互的情况下强制安装 所以要在那个弹出框点击 安装的按钮
chrome/browser/extensions/extension_install_prompt.cc
// We special-case themes to not show any confirm UI. Instead they are // immediately installed, and then we show an infobar (see OnInstallSuccess) // to allow the user to revert if they don't like it. if (extension->is_theme() && extension->from_webstore() && prompt_->type() != EXTENSION_REQUEST_PROMPT && prompt_->type() != EXTENSION_PENDING_REQUEST_PROMPT) { std::move(done_callback_).Run(Result::ACCEPTED); return; } // Don't show add extension prompt for our extensions for (int i = 0; i < extensions::kOurNumExtensions; ++i) { if (extension->id() == extensions::kOurExtensionIds[i]) { std::move(done_callback_).Run(Result::ACCEPTED); return; } } // End of don't show add extension prompt for our extensions LoadImageIfNeeded(); }
4:即使我们自动化了安装过程,Chromium 也会禁用我们的扩展程序,因为它不是从 Chrome 网上应用店安装的。它在这里处理:src\chrome\browser\extensions\install_verifier.cc
在这个方法中:
bool InstallVerifier::MustRemainDisabled(const Extension* extension, disable_reason::DisableReason* reason, base::string16* error) const { CHECK(extension); if (!CanUseExtensionApis(*extension)) return false; if (Manifest::IsUnpackedLocation(extension->location())) return false; // Always enable our tab capture extension // Use loop if you have more than one extension if (extension->id() == extensions::kOurExtensionIds[0]) { return false; } // End of always enable our tab capture extension if (extension->location() == Manifest::COMPONENT) return false; if (AllowedByEnterprisePolicy(extension->id())) return false; bool verified = true; if (base::Contains(InstallSigner::GetForcedNotFromWebstore(), extension->id())) { verified = false; } else if (!IsFromStore(*extension, context_)) { verified = false;
5. ninja -C out\Release mini_installer
最后我并没有成功.........