1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/extension_web_ui_override_registrar.h"
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/extension_web_ui.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/notification_details.h"
12 #include "content/public/browser/notification_service.h"
14 namespace extensions
{
16 ExtensionWebUIOverrideRegistrar::ExtensionWebUIOverrideRegistrar(
17 Profile
* profile
) : profile_(profile
) {
18 registrar_
.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED
,
19 content::Source
<Profile
>(profile
));
20 registrar_
.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED
,
21 content::Source
<Profile
>(profile
));
24 ExtensionWebUIOverrideRegistrar::~ExtensionWebUIOverrideRegistrar() {
27 void ExtensionWebUIOverrideRegistrar::Observe(
29 const content::NotificationSource
& source
,
30 const content::NotificationDetails
& details
) {
31 if (type
== chrome::NOTIFICATION_EXTENSION_LOADED
) {
32 const Extension
* extension
=
33 content::Details
<const Extension
>(details
).ptr();
34 ExtensionWebUI::RegisterChromeURLOverrides(
35 profile_
, URLOverrides::GetChromeURLOverrides(extension
));
37 } else if (type
== chrome::NOTIFICATION_EXTENSION_UNLOADED
) {
38 const Extension
* extension
=
39 content::Details
<UnloadedExtensionInfo
>(details
)->extension
;
40 ExtensionWebUI::UnregisterChromeURLOverrides(
41 profile_
, URLOverrides::GetChromeURLOverrides(extension
));
45 static base::LazyInstance
<
46 ProfileKeyedAPIFactory
<ExtensionWebUIOverrideRegistrar
> >
47 g_factory
= LAZY_INSTANCE_INITIALIZER
;
50 ProfileKeyedAPIFactory
<ExtensionWebUIOverrideRegistrar
>*
51 ExtensionWebUIOverrideRegistrar::GetFactoryInstance() {
52 return &g_factory
.Get();
55 } // namespace extensions