Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when loadExtension fails #27588

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions shell/browser/extensions/electron_extension_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ void ElectronExtensionLoader::FinishExtensionLoad(
scoped_refptr<const Extension> extension = result.first;
if (extension) {
extension_registrar_.AddExtension(extension);
}

// Write extension install time to ExtensionPrefs. This is required by
// WebRequestAPI which calls extensions::ExtensionPrefs::GetInstallTime.
//
// Implementation for writing the pref was based on
// PreferenceAPIBase::SetExtensionControlledPref.
{
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser_context_);
ExtensionPrefs::ScopedDictionaryUpdate update(
extension_prefs, extension.get()->id(),
extensions::pref_names::kPrefPreferences);
auto preference = update.Create();
const base::Time install_time = base::Time().Now();
preference->SetString("install_time",
base::NumberToString(install_time.ToInternalValue()));
// Write extension install time to ExtensionPrefs. This is required by
// WebRequestAPI which calls extensions::ExtensionPrefs::GetInstallTime.
//
// Implementation for writing the pref was based on
// PreferenceAPIBase::SetExtensionControlledPref.
{
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser_context_);
ExtensionPrefs::ScopedDictionaryUpdate update(
extension_prefs, extension.get()->id(),
extensions::pref_names::kPrefPreferences);
auto preference = update.Create();
const base::Time install_time = base::Time().Now();
preference->SetString(
"install_time", base::NumberToString(install_time.ToInternalValue()));
}
}

std::move(cb).Run(extension.get(), result.second);
Expand Down
6 changes: 6 additions & 0 deletions spec-main/extensions-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ describe('chrome extensions', () => {
expect(bg).to.equal('red');
});

it('does not crash when failing to load an extension', async () => {
const customSession = session.fromPartition(`persist:${uuid.v4()}`);
const promise = customSession.loadExtension(path.join(fixtures, 'extensions', 'load-error'));
await expect(promise).to.eventually.be.rejected();
});

it('serializes a loaded extension', async () => {
const extensionPath = path.join(fixtures, 'extensions', 'red-bg');
const manifest = JSON.parse(fs.readFileSync(path.join(extensionPath, 'manifest.json'), 'utf-8'));
Expand Down
8 changes: 8 additions & 0 deletions spec-main/fixtures/extensions/load-error/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "load-error",
"version": "1.0",
"icons": {
"16": "/images/error.png"
},
"manifest_version": 2
}