• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
6 
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/webui/extensions/command_handler.h"
9 #include "chrome/browser/ui/webui/extensions/extension_error_handler.h"
10 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h"
11 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
12 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h"
13 #include "chrome/browser/ui/webui/extensions/pack_extension_handler.h"
14 #include "chrome/browser/ui/webui/metrics_handler.h"
15 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_data_source.h"
18 #include "grit/browser_resources.h"
19 #include "grit/theme_resources.h"
20 #include "ui/base/resource/resource_bundle.h"
21 
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h"
24 #endif
25 
26 namespace extensions {
27 
28 namespace {
29 
CreateExtensionsHTMLSource()30 content::WebUIDataSource* CreateExtensionsHTMLSource() {
31   content::WebUIDataSource* source =
32       content::WebUIDataSource::Create(chrome::kChromeUIExtensionsFrameHost);
33 
34   source->SetUseJsonJSFormatV2();
35   source->SetJsonPath("strings.js");
36   source->AddResourcePath("extensions.js", IDR_EXTENSIONS_JS);
37   source->AddResourcePath("extension_command_list.js",
38                           IDR_EXTENSION_COMMAND_LIST_JS);
39   source->AddResourcePath("extension_list.js", IDR_EXTENSION_LIST_JS);
40   source->SetDefaultResource(IDR_EXTENSIONS_HTML);
41   source->DisableDenyXFrameOptions();
42   return source;
43 }
44 
45 }  // namespace
46 
ExtensionsUI(content::WebUI * web_ui)47 ExtensionsUI::ExtensionsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
48   Profile* profile = Profile::FromWebUI(web_ui);
49   content::WebUIDataSource* source = CreateExtensionsHTMLSource();
50 
51   ExtensionSettingsHandler* handler = new ExtensionSettingsHandler();
52   handler->GetLocalizedValues(source);
53   web_ui->AddMessageHandler(handler);
54 
55   PackExtensionHandler* pack_handler = new PackExtensionHandler();
56   pack_handler->GetLocalizedValues(source);
57   web_ui->AddMessageHandler(pack_handler);
58 
59   CommandHandler* commands_handler = new CommandHandler(profile);
60   commands_handler->GetLocalizedValues(source);
61   web_ui->AddMessageHandler(commands_handler);
62 
63   ExtensionErrorHandler* extension_error_handler =
64       new ExtensionErrorHandler(profile);
65   extension_error_handler->GetLocalizedValues(source);
66   web_ui->AddMessageHandler(extension_error_handler);
67 
68   ExtensionLoaderHandler* extension_loader_handler =
69       new ExtensionLoaderHandler(profile);
70   extension_loader_handler->GetLocalizedValues(source);
71   web_ui->AddMessageHandler(extension_loader_handler);
72 
73   InstallExtensionHandler* install_extension_handler =
74       new InstallExtensionHandler();
75   install_extension_handler->GetLocalizedValues(source);
76   web_ui->AddMessageHandler(install_extension_handler);
77 
78 #if defined(OS_CHROMEOS)
79   chromeos::KioskAppsHandler* kiosk_app_handler =
80       new chromeos::KioskAppsHandler();
81   kiosk_app_handler->GetLocalizedValues(source);
82   web_ui->AddMessageHandler(kiosk_app_handler);
83 #endif
84 
85   web_ui->AddMessageHandler(new MetricsHandler());
86 
87   // Need to allow <object> elements so that the <extensionoptions> browser
88   // plugin can be loaded within chrome://extensions.
89   source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';");
90 
91   content::WebUIDataSource::Add(profile, source);
92 }
93 
~ExtensionsUI()94 ExtensionsUI::~ExtensionsUI() {}
95 
96 // static
GetFaviconResourceBytes(ui::ScaleFactor scale_factor)97 base::RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes(
98     ui::ScaleFactor scale_factor) {
99   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
100   return rb.LoadDataResourceBytesForScale(IDR_EXTENSIONS_FAVICON, scale_factor);
101 }
102 
103 }  // namespace extensions
104