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/extension_info_ui.h"
7 #include "base/i18n/time_formatting.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h"
11 #include "chrome/browser/extensions/extension_prefs.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
16 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
17 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/extensions/extension_icon_set.h"
19 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/web_ui.h"
21 #include "content/public/browser/web_ui_data_source.h"
22 #include "extensions/common/extension.h"
23 #include "grit/browser_resources.h"
24 #include "grit/generated_resources.h"
26 namespace extensions
{
28 ExtensionInfoUI::ExtensionInfoUI(content::WebUI
* web_ui
, const GURL
& url
)
29 : content::WebUIController(web_ui
),
30 source_(content::WebUIDataSource::Create(
31 chrome::kChromeUIExtensionInfoHost
)) {
32 AddExtensionDataToSource(url
.path().substr(1));
34 source_
->AddLocalizedString("isRunning",
35 IDS_EXTENSION_SCRIPT_POPUP_IS_RUNNING
);
36 source_
->AddLocalizedString("lastUpdated",
37 IDS_EXTENSION_SCRIPT_POPUP_LAST_UPDATED
);
38 source_
->SetUseJsonJSFormatV2();
39 source_
->SetJsonPath("strings.js");
41 source_
->AddResourcePath("extension_info.css", IDR_EXTENSION_INFO_CSS
);
42 source_
->AddResourcePath("extension_info.js", IDR_EXTENSION_INFO_JS
);
43 source_
->SetDefaultResource(IDR_EXTENSION_INFO_HTML
);
45 Profile
* profile
= Profile::FromWebUI(web_ui
);
46 content::WebUIDataSource::Add(profile
, source_
);
49 ExtensionInfoUI::~ExtensionInfoUI() {
53 GURL
ExtensionInfoUI::GetURL(const std::string
& extension_id
) {
54 return GURL(base::StringPrintf(
55 "%s%s", chrome::kChromeUIExtensionInfoURL
, extension_id
.c_str()));
58 void ExtensionInfoUI::AddExtensionDataToSource(
59 const std::string
& extension_id
) {
60 ExtensionService
* extension_service
= ExtensionSystem::Get(
61 Profile::FromWebUI(web_ui()))->extension_service();
62 const Extension
* extension
=
63 extension_service
->extensions()->GetByID(extension_id
);
67 base::DictionaryValue extension_data
;
68 GetExtensionBasicInfo(extension
, true, &extension_data
);
69 source_
->AddLocalizedStrings(extension_data
);
73 ExtensionIconSource::GetIconURL(extension
,
74 extension_misc::EXTENSION_ICON_MEDIUM
,
75 ExtensionIconSet::MATCH_BIGGER
,
77 source_
->AddString("icon", base::UTF8ToUTF16(icon
.spec()));
78 // Set the last update time (the install time).
79 base::Time install_time
= extension_service
->extension_prefs()->
80 GetInstallTime(extension_id
);
81 source_
->AddString("installTime", base::TimeFormatShortDate(install_time
));
84 } // namespace extensions