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/ui/webui/extensions/extensions_ui.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h"
9 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
10 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h"
11 #include "chrome/browser/ui/webui/metrics_handler.h"
12 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/web_ui.h"
14 #include "content/public/browser/web_ui_data_source.h"
15 #include "grit/browser_resources.h"
16 #include "grit/theme_resources.h"
17 #include "ui/base/resource/resource_bundle.h"
19 #if defined(OS_CHROMEOS)
20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
21 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h"
24 namespace extensions
{
28 content::WebUIDataSource
* CreateExtensionsHTMLSource() {
29 content::WebUIDataSource
* source
=
30 content::WebUIDataSource::Create(chrome::kChromeUIExtensionsFrameHost
);
32 source
->SetJsonPath("strings.js");
33 source
->AddResourcePath("extensions.js", IDR_EXTENSIONS_JS
);
34 source
->AddResourcePath("extension_command_list.js",
35 IDR_EXTENSION_COMMAND_LIST_JS
);
36 source
->AddResourcePath("extension_list.js", IDR_EXTENSION_LIST_JS
);
37 source
->SetDefaultResource(IDR_EXTENSIONS_HTML
);
38 source
->DisableDenyXFrameOptions();
44 ExtensionsUI::ExtensionsUI(content::WebUI
* web_ui
) : WebUIController(web_ui
) {
45 Profile
* profile
= Profile::FromWebUI(web_ui
);
46 content::WebUIDataSource
* source
= CreateExtensionsHTMLSource();
48 ExtensionSettingsHandler
* handler
= new ExtensionSettingsHandler();
49 handler
->GetLocalizedValues(source
);
50 web_ui
->AddMessageHandler(handler
);
52 ExtensionLoaderHandler
* extension_loader_handler
=
53 new ExtensionLoaderHandler(profile
);
54 extension_loader_handler
->GetLocalizedValues(source
);
55 web_ui
->AddMessageHandler(extension_loader_handler
);
57 InstallExtensionHandler
* install_extension_handler
=
58 new InstallExtensionHandler();
59 install_extension_handler
->GetLocalizedValues(source
);
60 web_ui
->AddMessageHandler(install_extension_handler
);
62 #if defined(OS_CHROMEOS)
63 chromeos::KioskAppsHandler
* kiosk_app_handler
=
64 new chromeos::KioskAppsHandler(
65 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(
67 kiosk_app_handler
->GetLocalizedValues(source
);
68 web_ui
->AddMessageHandler(kiosk_app_handler
);
71 web_ui
->AddMessageHandler(new MetricsHandler());
73 // Need to allow <object> elements so that the <extensionoptions> browser
74 // plugin can be loaded within chrome://extensions.
75 source
->OverrideContentSecurityPolicyObjectSrc("object-src 'self';");
77 content::WebUIDataSource::Add(profile
, source
);
80 ExtensionsUI::~ExtensionsUI() {}
83 base::RefCountedMemory
* ExtensionsUI::GetFaviconResourceBytes(
84 ui::ScaleFactor scale_factor
) {
85 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
86 return rb
.LoadDataResourceBytesForScale(IDR_EXTENSIONS_FAVICON
, scale_factor
);
89 } // namespace extensions