Commit 7b605646 authored by rpaquay@chromium.org's avatar rpaquay@chromium.org

Hook up runtime API to implement ExtensionRegistryObserver.

* Also open the extension "uninstall URL" only when uninstall is user initiated.

BUG=84556

Review URL: https://codereview.chromium.org/406063002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285079 0039d316-1c4b-4281-b951-d872f2087c98
parent 7571798a
......@@ -137,19 +137,13 @@ BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() {
}
RuntimeAPI::RuntimeAPI(content::BrowserContext* context)
: browser_context_(context), dispatch_chrome_updated_event_(false) {
: browser_context_(context),
dispatch_chrome_updated_event_(false),
extension_registry_observer_(this) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<BrowserContext>(context));
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<BrowserContext>(context));
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
content::Source<BrowserContext>(context));
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
content::Source<BrowserContext>(context));
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
delegate_ = ExtensionsBrowserClient::Get()->CreateRuntimeAPIDelegate(
browser_context_);
......@@ -167,36 +161,7 @@ RuntimeAPI::~RuntimeAPI() {
void RuntimeAPI::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSIONS_READY: {
OnExtensionsReady();
break;
}
case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
OnExtensionLoaded(extension);
break;
}
case chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
const Extension* extension =
content::Details<const InstalledExtensionInfo>(details)->extension;
OnExtensionInstalled(extension);
break;
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
OnExtensionUninstalled(extension);
break;
}
default:
NOTREACHED();
break;
}
}
void RuntimeAPI::OnExtensionsReady() {
DCHECK_EQ(chrome::NOTIFICATION_EXTENSIONS_READY, type);
// We're done restarting Chrome after an update.
dispatch_chrome_updated_event_ = false;
......@@ -212,7 +177,8 @@ void RuntimeAPI::OnExtensionsReady() {
extension_system->process_manager()->AddObserver(this);
}
void RuntimeAPI::OnExtensionLoaded(const Extension* extension) {
void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) {
if (!dispatch_chrome_updated_event_)
return;
......@@ -226,7 +192,12 @@ void RuntimeAPI::OnExtensionLoaded(const Extension* extension) {
true));
}
void RuntimeAPI::OnExtensionInstalled(const Extension* extension) {
void RuntimeAPI::OnExtensionWillBeInstalled(
content::BrowserContext* browser_context,
const Extension* extension,
bool is_update,
bool from_ephemeral,
const std::string& old_name) {
// Ephemeral apps are not considered to be installed and do not receive
// the onInstalled() event.
if (util::IsEphemeralApp(extension->id(), browser_context_))
......@@ -244,13 +215,17 @@ void RuntimeAPI::OnExtensionInstalled(const Extension* extension) {
false));
}
void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) {
void RuntimeAPI::OnExtensionUninstalled(
content::BrowserContext* browser_context,
const Extension* extension,
UninstallReason reason) {
// Ephemeral apps are not considered to be installed, so the uninstall URL
// is not invoked when they are removed.
if (util::IsEphemeralApp(extension->id(), browser_context_))
return;
RuntimeEventRouter::OnExtensionUninstalled(browser_context_, extension->id());
RuntimeEventRouter::OnExtensionUninstalled(
browser_context_, extension->id(), reason);
}
void RuntimeAPI::Shutdown() {
......@@ -412,7 +387,13 @@ void RuntimeEventRouter::DispatchOnRestartRequiredEvent(
// static
void RuntimeEventRouter::OnExtensionUninstalled(
content::BrowserContext* context,
const std::string& extension_id) {
const std::string& extension_id,
UninstallReason reason) {
if (!(reason == UNINSTALL_REASON_USER_INITIATED ||
reason == UNINSTALL_REASON_MANAGEMENT_API)) {
return;
}
GURL uninstall_url(
GetUninstallURL(ExtensionPrefs::Get(context), extension_id));
......
......@@ -7,11 +7,13 @@
#include <string>
#include "base/scoped_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/api/runtime/runtime_api_delegate.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/process_manager_observer.h"
#include "extensions/browser/update_observer.h"
#include "extensions/common/api/runtime.h"
......@@ -34,12 +36,14 @@ struct PlatformInfo;
class Extension;
class ExtensionHost;
class ExtensionRegistry;
// Runtime API dispatches onStartup, onInstalled, and similar events to
// extensions. There is one instance shared between a browser context and
// its related incognito instance.
class RuntimeAPI : public BrowserContextKeyedAPI,
public content::NotificationObserver,
public ExtensionRegistryObserver,
public UpdateObserver,
public ProcessManagerObserver {
public:
......@@ -63,10 +67,18 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
private:
friend class BrowserContextKeyedAPIFactory<RuntimeAPI>;
void OnExtensionsReady();
void OnExtensionLoaded(const Extension* extension);
void OnExtensionInstalled(const Extension* extension);
void OnExtensionUninstalled(const Extension* extension);
// ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) OVERRIDE;
virtual void OnExtensionWillBeInstalled(
content::BrowserContext* browser_context,
const Extension* extension,
bool is_update,
bool from_ephemeral,
const std::string& old_name) OVERRIDE;
virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
const Extension* extension,
UninstallReason reason) OVERRIDE;
// BrowserContextKeyedAPI implementation:
static const char* service_name() { return "RuntimeAPI"; }
......@@ -91,6 +103,10 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
content::NotificationRegistrar registrar_;
// Listen to extension notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(RuntimeAPI);
};
......@@ -124,7 +140,8 @@ class RuntimeEventRouter {
// Does any work needed at extension uninstall (e.g. load uninstall url).
static void OnExtensionUninstalled(content::BrowserContext* context,
const std::string& extension_id);
const std::string& extension_id,
UninstallReason reason);
};
class RuntimeGetBackgroundPageFunction : public UIThreadExtensionFunction {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment