OLD | NEW |
| (Empty) |
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/extension_info_ui.h" | |
6 | |
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/profiles/profile.h" | |
12 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" | |
13 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | |
14 #include "chrome/common/extensions/extension_constants.h" | |
15 #include "chrome/common/url_constants.h" | |
16 #include "chrome/grit/generated_resources.h" | |
17 #include "content/public/browser/web_ui.h" | |
18 #include "content/public/browser/web_ui_data_source.h" | |
19 #include "extensions/browser/extension_prefs.h" | |
20 #include "extensions/browser/extension_registry.h" | |
21 #include "extensions/common/extension.h" | |
22 #include "extensions/common/extension_icon_set.h" | |
23 #include "grit/browser_resources.h" | |
24 | |
25 namespace extensions { | |
26 | |
27 ExtensionInfoUI::ExtensionInfoUI(content::WebUI* web_ui, const GURL& url) | |
28 : content::WebUIController(web_ui), | |
29 source_(content::WebUIDataSource::Create( | |
30 chrome::kChromeUIExtensionInfoHost)) { | |
31 AddExtensionDataToSource(url.path().substr(1)); | |
32 | |
33 source_->AddLocalizedString("isRunning", | |
34 IDS_EXTENSION_SCRIPT_POPUP_IS_RUNNING); | |
35 source_->AddLocalizedString("lastUpdated", | |
36 IDS_EXTENSION_SCRIPT_POPUP_LAST_UPDATED); | |
37 source_->SetJsonPath("strings.js"); | |
38 | |
39 source_->AddResourcePath("extension_info.css", IDR_EXTENSION_INFO_CSS); | |
40 source_->AddResourcePath("extension_info.js", IDR_EXTENSION_INFO_JS); | |
41 source_->SetDefaultResource(IDR_EXTENSION_INFO_HTML); | |
42 | |
43 Profile* profile = Profile::FromWebUI(web_ui); | |
44 content::WebUIDataSource::Add(profile, source_); | |
45 } | |
46 | |
47 ExtensionInfoUI::~ExtensionInfoUI() { | |
48 } | |
49 | |
50 // static | |
51 GURL ExtensionInfoUI::GetURL(const std::string& extension_id) { | |
52 return GURL(base::StringPrintf( | |
53 "%s%s", chrome::kChromeUIExtensionInfoURL, extension_id.c_str())); | |
54 } | |
55 | |
56 void ExtensionInfoUI::AddExtensionDataToSource( | |
57 const std::string& extension_id) { | |
58 Profile* profile = Profile::FromWebUI(web_ui()); | |
59 const Extension* extension = | |
60 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID( | |
61 extension_id); | |
62 if (!extension) | |
63 return; | |
64 | |
65 base::DictionaryValue extension_data; | |
66 GetExtensionBasicInfo(extension, true, &extension_data); | |
67 source_->AddLocalizedStrings(extension_data); | |
68 | |
69 // Set the icon URL. | |
70 GURL icon = | |
71 ExtensionIconSource::GetIconURL(extension, | |
72 extension_misc::EXTENSION_ICON_MEDIUM, | |
73 ExtensionIconSet::MATCH_BIGGER, | |
74 false, NULL); | |
75 source_->AddString("icon", base::UTF8ToUTF16(icon.spec())); | |
76 // Set the last update time (the install time). | |
77 base::Time install_time = | |
78 ExtensionPrefs::Get(profile)->GetInstallTime(extension_id); | |
79 source_->AddString("installTime", base::TimeFormatShortDate(install_time)); | |
80 } | |
81 | |
82 } // namespace extensions | |
OLD | NEW |