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_settings_handler.h" 11 #include "chrome/browser/ui/webui/extensions/install_extension_handler.h" 12 #include "chrome/browser/ui/webui/extensions/pack_extension_handler.h" 13 #include "chrome/browser/ui/webui/metrics_handler.h" 14 #include "chrome/common/url_constants.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" 20 21 #if defined(OS_CHROMEOS) 22 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h" 23 #endif 24 25 namespace extensions { 26 27 namespace { 28 29 content::WebUIDataSource* CreateExtensionsHTMLSource() { 30 content::WebUIDataSource* source = 31 content::WebUIDataSource::Create(chrome::kChromeUIExtensionsFrameHost); 32 33 source->SetUseJsonJSFormatV2(); 34 source->SetJsonPath("strings.js"); 35 source->AddResourcePath("extensions.js", IDR_EXTENSIONS_JS); 36 source->AddResourcePath("extension_command_list.js", 37 IDR_EXTENSION_COMMAND_LIST_JS); 38 source->AddResourcePath("extension_list.js", IDR_EXTENSION_LIST_JS); 39 source->SetDefaultResource(IDR_EXTENSIONS_HTML); 40 source->DisableDenyXFrameOptions(); 41 return source; 42 } 43 44 } // namespace 45 46 ExtensionsUI::ExtensionsUI(content::WebUI* web_ui) : WebUIController(web_ui) { 47 Profile* profile = Profile::FromWebUI(web_ui); 48 content::WebUIDataSource* source = CreateExtensionsHTMLSource(); 49 50 ExtensionSettingsHandler* handler = new ExtensionSettingsHandler(); 51 handler->GetLocalizedValues(source); 52 web_ui->AddMessageHandler(handler); 53 54 PackExtensionHandler* pack_handler = new PackExtensionHandler(); 55 pack_handler->GetLocalizedValues(source); 56 web_ui->AddMessageHandler(pack_handler); 57 58 CommandHandler* commands_handler = new CommandHandler(profile); 59 commands_handler->GetLocalizedValues(source); 60 web_ui->AddMessageHandler(commands_handler); 61 62 ExtensionErrorHandler* extension_error_handler = 63 new ExtensionErrorHandler(profile); 64 extension_error_handler->GetLocalizedValues(source); 65 web_ui->AddMessageHandler(extension_error_handler); 66 67 InstallExtensionHandler* install_extension_handler = 68 new InstallExtensionHandler(); 69 install_extension_handler->GetLocalizedValues(source); 70 web_ui->AddMessageHandler(install_extension_handler); 71 72 #if defined(OS_CHROMEOS) 73 chromeos::KioskAppsHandler* kiosk_app_handler = 74 new chromeos::KioskAppsHandler(); 75 kiosk_app_handler->GetLocalizedValues(source); 76 web_ui->AddMessageHandler(kiosk_app_handler); 77 #endif 78 79 web_ui->AddMessageHandler(new MetricsHandler()); 80 81 content::WebUIDataSource::Add(profile, source); 82 } 83 84 ExtensionsUI::~ExtensionsUI() {} 85 86 // static 87 base::RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes( 88 ui::ScaleFactor scale_factor) { 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 90 return rb.LoadDataResourceBytesForScale(IDR_EXTENSIONS_FAVICON, scale_factor); 91 } 92 93 } // namespace extensions 94