Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / extensions / extensions_ui.cc
blob551906a94aa6c331ee732fc5bfe07e807a423f7e
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/chrome_switches.h"
13 #include "chrome/common/url_constants.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/web_ui.h"
16 #include "content/public/browser/web_ui_data_source.h"
17 #include "grit/browser_resources.h"
18 #include "grit/theme_resources.h"
19 #include "ui/base/resource/resource_bundle.h"
21 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
23 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h"
24 #endif
26 namespace extensions {
28 namespace {
30 content::WebUIDataSource* CreateMdExtensionsSource() {
31 content::WebUIDataSource* source =
32 content::WebUIDataSource::Create(chrome::kChromeUIExtensionsHost);
34 source->SetJsonPath("strings.js");
36 source->AddLocalizedString("title",
37 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE);
38 source->AddLocalizedString("toolbarTitle", IDS_MD_EXTENSIONS_TOOLBAR_TITLE);
39 source->AddLocalizedString("search", IDS_MD_EXTENSIONS_SEARCH);
40 source->AddLocalizedString("sidebarExtensions",
41 IDS_MD_EXTENSIONS_SIDEBAR_EXTENSIONS);
42 source->AddLocalizedString("sidebarApps", IDS_MD_EXTENSIONS_SIDEBAR_APPS);
43 source->AddLocalizedString("sidebarWebsites",
44 IDS_MD_EXTENSIONS_SIDEBAR_WEBSITES);
45 source->AddLocalizedString("developerMode",
46 IDS_MD_EXTENSIONS_SIDEBAR_DEVELOPER_MODE);
47 source->AddLocalizedString("getMoreExtensions",
48 IDS_MD_EXTENSIONS_SIDEBAR_GET_MORE_EXTENSIONS);
49 source->AddLocalizedString("keyboardShortcuts",
50 IDS_MD_EXTENSIONS_SIDEBAR_KEYBOARD_SHORTCUTS);
52 source->AddResourcePath("manager.css", IDR_MD_EXTENSIONS_MANAGER_CSS);
53 source->AddResourcePath("manager.html", IDR_MD_EXTENSIONS_MANAGER_HTML);
54 source->AddResourcePath("manager.js", IDR_MD_EXTENSIONS_MANAGER_JS);
55 source->AddResourcePath("sidebar.css", IDR_MD_EXTENSIONS_SIDEBAR_CSS);
56 source->AddResourcePath("sidebar.html", IDR_MD_EXTENSIONS_SIDEBAR_HTML);
57 source->AddResourcePath("sidebar.js", IDR_MD_EXTENSIONS_SIDEBAR_JS);
58 source->AddResourcePath("toolbar.css", IDR_MD_EXTENSIONS_TOOLBAR_CSS);
59 source->AddResourcePath("toolbar.html", IDR_MD_EXTENSIONS_TOOLBAR_HTML);
60 source->AddResourcePath("toolbar.js", IDR_MD_EXTENSIONS_TOOLBAR_JS);
61 source->AddResourcePath("strings.html", IDR_MD_EXTENSIONS_STRINGS_HTML);
62 source->SetDefaultResource(IDR_MD_EXTENSIONS_EXTENSIONS_HTML);
64 return source;
67 content::WebUIDataSource* CreateExtensionsHTMLSource() {
68 content::WebUIDataSource* source =
69 content::WebUIDataSource::Create(chrome::kChromeUIExtensionsFrameHost);
71 source->SetJsonPath("strings.js");
72 source->AddResourcePath("extensions.js", IDR_EXTENSIONS_JS);
73 source->AddResourcePath("extension_command_list.js",
74 IDR_EXTENSION_COMMAND_LIST_JS);
75 source->AddResourcePath("extension_list.js", IDR_EXTENSION_LIST_JS);
76 source->SetDefaultResource(IDR_EXTENSIONS_HTML);
77 source->DisableDenyXFrameOptions();
78 return source;
81 } // namespace
83 ExtensionsUI::ExtensionsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
84 Profile* profile = Profile::FromWebUI(web_ui);
85 content::WebUIDataSource* source = nullptr;
87 if (::switches::MdExtensionsEnabled()) {
88 source = CreateMdExtensionsSource();
89 } else {
90 source = CreateExtensionsHTMLSource();
92 ExtensionSettingsHandler* handler = new ExtensionSettingsHandler();
93 handler->GetLocalizedValues(source);
94 web_ui->AddMessageHandler(handler);
96 ExtensionLoaderHandler* extension_loader_handler =
97 new ExtensionLoaderHandler(profile);
98 extension_loader_handler->GetLocalizedValues(source);
99 web_ui->AddMessageHandler(extension_loader_handler);
101 InstallExtensionHandler* install_extension_handler =
102 new InstallExtensionHandler();
103 install_extension_handler->GetLocalizedValues(source);
104 web_ui->AddMessageHandler(install_extension_handler);
106 #if defined(OS_CHROMEOS)
107 chromeos::KioskAppsHandler* kiosk_app_handler =
108 new chromeos::KioskAppsHandler(
109 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(
110 profile));
111 kiosk_app_handler->GetLocalizedValues(source);
112 web_ui->AddMessageHandler(kiosk_app_handler);
113 #endif
115 web_ui->AddMessageHandler(new MetricsHandler());
117 // Need to allow <object> elements so that the <extensionoptions> browser
118 // plugin can be loaded within chrome://extensions.
119 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';");
122 content::WebUIDataSource::Add(profile, source);
125 ExtensionsUI::~ExtensionsUI() {}
127 // static
128 base::RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes(
129 ui::ScaleFactor scale_factor) {
130 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
131 return rb.LoadDataResourceBytesForScale(IDR_EXTENSIONS_FAVICON, scale_factor);
134 } // namespace extensions