-
Notifications
You must be signed in to change notification settings - Fork 114
Add support for installing / updating extensions #59
Conversation
@@ -0,0 +1,172 @@ | |||
// Copyright 2016 The Brave Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this to brave/browser in a follow-up? Trying to keep non-upstreamable stuff separate so we can split out the repos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
const content::NotificationDetails& details) { | ||
switch (type) { | ||
case extensions::NOTIFICATION_EXTENSION_ENABLED: { | ||
Emit("extension-enabled"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably have one for extension-disabled
as well, but maybe both should go in atom_api_extensions? Can also be follow-up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I don't even use this so I can remove it.
void Extension::Remove(const std::string& extension_id) { | ||
const extensions::Extension* extension = | ||
GetInstance()->extensions_.GetByID(extension_id); | ||
if (extension) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this just call Extension::Disable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I would disable in AtomExtensionSystem
because there is a check there to prevent uninstalling component extensions (like brave)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't NOTIFICATION_DISABLE_USER_EXTENSION_REQUEST handled in AtomExtensionSystem to disable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but there are other checks that should happen and I think it's better to keep all of that within AtomExtensionSystem
. See ExtensionService::UninstallExtension
and ExtensionService::UnloadExtension
. We don't need everything in there, but I think we should keep the basic structure the same because it's much easier to follow changes in libchromiumcontent that way
|
||
base::FilePath install_directory; | ||
PathService::Get(component_updater::DIR_COMPONENT_USER, &install_directory); | ||
extensions::file_util::UninstallExtension(install_directory, extension_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should run on the file thread and should probably also happen in AtomExtensionSystem
to prevent uninstall of component extensions. See ExtensionService::OnExtensionInstalled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k will move it.
&install_directory); | ||
std::string extension_id = extension->id(); | ||
auto registry = ExtensionRegistry::Get(browser_context_); | ||
registry->RemoveEnabled(extension_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if these methods should be called or not, but ExtensionRegistry::TriggerOnUninstalled
does. See ExtensionService::UninstallExtension
mate::Handle<UpdateClient> UpdateClient::Create( | ||
v8::Isolate* isolate, | ||
content::BrowserContext* browser_context) { | ||
return mate::CreateHandle(isolate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the update client should use chrome::GetBrowserContextRedirectedInIncognito
to make sure that there is only one per user since the extensions are shared across private and session contexts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually see above because I think using AtomBrowserCreateUpdateClient::CreateUpdateClient
is the right way to handle this
UpdateClient::UpdateClient(v8::Isolate* isolate, | ||
content::BrowserContext* browser_context) | ||
: browser_context_(browser_context) { | ||
cus_ = component_updater::ComponentUpdateServiceFactory( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is only supposed to be one component updater globally, but maybe this is ok for now with the change below that creates a shared update client for all contexts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's only used for the default session, even know it can be used for others as well (there would be no point). Is there a way to get the default session browser context as a singleton or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, there are two things going on here. The update client really should be retrieved from AtomBrowserCreateUpdateClient::CreateUpdateClient
with something like
return update_client::UpdateClientFactory(
make_scoped_refptr(new AtomUpdateClientConfig(GetOriginalContext(context))));
If you do that the UpdateServiceFactory::GetForBrowserContext(browser_context)
will work correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the component updater service itself can be initialized with the default browser context and in chrome it's attached to the BrowserProcess
e547c0c
to
67f2294
Compare
563ed2e
to
b478e10
Compare
@@ -148,7 +154,8 @@ bool BraveConfigurator::UseBackgroundDownloader() const { | |||
} | |||
|
|||
bool BraveConfigurator::UseCupSigning() const { | |||
return configurator_impl_.UseCupSigning(); | |||
// return configurator_impl_.UseCupSigning(); | |||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked with Yan and she said this is ok.
b478e10
to
65f790d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few small changes, otherwise ++
@@ -220,6 +220,26 @@ void Extension::Enable(const std::string& extension_id) { | |||
} | |||
|
|||
// static | |||
void Extension::Remove(const std::string& extension_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make this remove to be consistent?
// | ||
// If the return value is true, |deletion_done_callback| is invoked when | ||
// data deletion is done or at least is scheduled. | ||
bool UninstallExtension(const std::string& extension_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should also be a virtual method on the extension service so it can be called with
return extensions::ExtensionSystem::Get(context)
->extension_service()
->UninstallExtension(transient_extension_id, reason,
deletion_done_callback, error);
from atom_extensions_api_client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just remove uninstall and remove since they aren't used for now.
&install_directory); | ||
|
||
// Tell the backend to start deleting installed extensions on the file thread. | ||
BrowserThread::PostTask( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it could be a problem here if we don't use the blocking thread pool because the remove could still be in progress when the new install starts on an update
// Notify interested parties that we've uninstalled this extension. | ||
ExtensionRegistry::Get(browser_context_) | ||
->TriggerOnUninstalled(extension.get(), reason); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extension_prefs_->OnExtensionUninstalled(
extension->id(), extension->location(), external_uninstall);
content::Source<content::BrowserContext>(browser_context_), | ||
content::Details<const Extension>(extension)); | ||
} else { | ||
// All apps that are displayed in the launcher are ordered by their ordinals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this section should be left out because it deals with chrome apps, not extensions and app_sorting()
returns nullptr
@@ -59,6 +60,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() { | |||
extensions::StorageFrontend::GetFactoryInstance(); | |||
extensions::WebRequestAPI::GetFactoryInstance(); | |||
extensions::AtomExtensionSystemFactory::GetInstance(); | |||
extensions::UpdateServiceFactory::GetInstance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UpdateServiceFactory won't work correctly unless AtomExtensionBrowserClient
implements ExtensionsBrowserClient::CreateUpdateClient
return update_client::UpdateClientFactory(
make_scoped_refptr(new BraveUpdateClientConfig(context)));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually this doesn't appear to be implemented in chrome so we should probably remove it because it will pass nullptr
to the `UpdateService if it is called anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya this was left over from when I did have CreateUpdateClient which I didn't end up needing, removing.
1ea9e4b
to
76fc5ae
Compare
76fc5ae
to
d9e54c9
Compare
++ |
Auditors: @darkdh @bridiver