Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_activity_ui.cc

Issue 15812004: Remove the Activity Log UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_activity_ui.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
11 #include "chrome/common/extensions/extension_constants.h"
12 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/web_ui.h"
14 #include "content/public/browser/web_ui_data_source.h"
15 #include "grit/browser_resources.h"
16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
18
19 ExtensionActivityUI::ExtensionActivityUI(content::WebUI* web_ui)
20 : WebUIController(web_ui), extension_(NULL) {
21 web_ui->OverrideTitle(l10n_util::GetStringUTF16(
22 IDS_EXTENSION_ACTIVITY_TITLE));
23
24 content::WebUIDataSource* source =
25 content::WebUIDataSource::Create(chrome::kChromeUIExtensionActivityHost);
26
27 // Localized strings.
28 source->AddLocalizedString("extensionActivity", IDS_EXTENSION_ACTIVITY_TITLE);
29 source->AddLocalizedString("extensionActivityApiCall",
30 IDS_EXTENSION_ACTIVITY_API_CALL);
31 source->AddLocalizedString("extensionActivityApiBlock",
32 IDS_EXTENSION_ACTIVITY_API_BLOCK);
33 source->AddLocalizedString("extensionActivityContentScript",
34 IDS_EXTENSION_ACTIVITY_CONTENT_SCRIPT);
35 source->AddLocalizedString("extensionActivityEventDispatch",
36 IDS_EXTENSION_ACTIVITY_EVENT_DISPATCH);
37 source->SetUseJsonJSFormatV2();
38 source->SetJsonPath("strings.js");
39
40 // Resources.
41 source->AddResourcePath("extension_activity.js", IDR_EXTENSION_ACTIVITY_JS);
42 source->SetDefaultResource(IDR_EXTENSION_ACTIVITY_HTML);
43 profile_ = Profile::FromWebUI(web_ui);
44 content::WebUIDataSource::Add(profile_, source);
45 // Callback handlers.
46 web_ui->RegisterMessageCallback("requestExtensionData",
47 base::Bind(&ExtensionActivityUI::HandleRequestExtensionData,
48 base::Unretained(this)));
49 }
50
51 ExtensionActivityUI::~ExtensionActivityUI() {
52 if (extension_)
53 extensions::ActivityLog::GetInstance(profile_)->RemoveObserver(
54 extension_, this);
55 }
56
57 void ExtensionActivityUI::HandleRequestExtensionData(
58 const base::ListValue* args) {
59 DCHECK_EQ(1U, args->GetSize());
60
61 std::string extension_id;
62 if (!args->GetString(0, &extension_id))
63 return;
64
65 ExtensionService* extension_service = profile_->GetExtensionService();
66 extension_ = extension_service->GetExtensionById(extension_id, false);
67 if (!extension_)
68 return;
69
70 GURL icon =
71 ExtensionIconSource::GetIconURL(extension_,
72 extension_misc::EXTENSION_ICON_MEDIUM,
73 ExtensionIconSet::MATCH_BIGGER,
74 false, NULL);
75
76 DictionaryValue* extension_data = new DictionaryValue(); // Owned by result.
77 extension_data->SetString("id", extension_->id());
78 extension_data->SetString("name", extension_->name());
79 extension_data->SetString("version", extension_->version()->GetString());
80 extension_data->SetString("description", extension_->description());
81 extension_data->SetString("icon", icon.spec());
82
83 DictionaryValue result;
84 result.Set("extension", extension_data);
85
86 web_ui()->CallJavascriptFunction("extension_activity.handleExtensionData",
87 result);
88
89 extensions::ActivityLog* activity_log =
90 extensions::ActivityLog::GetInstance(profile_);
91 activity_log->GetActions(
92 extension_->id(),
93 0, // today
94 base::Bind(&ExtensionActivityUI::FetchPreviousExtensionActivity,
95 base::Unretained(this)));
96 activity_log->AddObserver(extension_, this);
97 }
98
99 void ExtensionActivityUI::FetchPreviousExtensionActivity(
100 scoped_ptr<std::vector<scoped_refptr<extensions::Action> > > actions) {
101 // TODO(felt): Implement this to display previous activity.
102 }
103
104 void ExtensionActivityUI::OnExtensionActivity(
105 const extensions::Extension* extension,
106 extensions::ActivityLog::Activity activity,
107 const std::string& message) {
108 scoped_ptr<ListValue> messages_list(new ListValue());
109 messages_list->AppendString(message);
110
111 DictionaryValue result;
112 result.SetInteger("activity", activity);
113 result.Set("messages", messages_list.release());
114
115 web_ui()->CallJavascriptFunction("extension_activity.handleExtensionActivity",
116 result);
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698