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

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

Issue 275503003: Remove deprecated extension notification and deprecated extension_service functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/extensions/command_handler.h" 5 #include "chrome/browser/ui/webui/extensions/command_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/api/commands/command_service.h" 9 #include "chrome/browser/extensions/api/commands/command_service.h"
11 #include "chrome/browser/extensions/extension_commands_global_registry.h" 10 #include "chrome/browser/extensions/extension_commands_global_registry.h"
12 #include "chrome/browser/extensions/extension_keybinding_registry.h" 11 #include "chrome/browser/extensions/extension_keybinding_registry.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
15 #include "content/public/browser/web_ui.h" 13 #include "content/public/browser/web_ui.h"
16 #include "content/public/browser/web_ui_data_source.h" 14 #include "content/public/browser/web_ui_data_source.h"
15 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/extension_system.h" 16 #include "extensions/browser/extension_system.h"
18 #include "extensions/common/extension_set.h" 17 #include "extensions/common/extension_set.h"
19 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
21 20
22 namespace extensions { 21 namespace extensions {
23 22
24 CommandHandler::CommandHandler(Profile* profile) : profile_(profile) { 23 CommandHandler::CommandHandler(Profile* profile)
24 : profile_(profile), extension_registry_observer_(this) {
25 } 25 }
26 26
27 CommandHandler::~CommandHandler() { 27 CommandHandler::~CommandHandler() {
28 } 28 }
29 29
30 void CommandHandler::GetLocalizedValues(content::WebUIDataSource* source) { 30 void CommandHandler::GetLocalizedValues(content::WebUIDataSource* source) {
31 source->AddString("extensionCommandsOverlay", 31 source->AddString("extensionCommandsOverlay",
32 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_DIALOG_TITLE)); 32 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_DIALOG_TITLE));
33 source->AddString("extensionCommandsEmpty", 33 source->AddString("extensionCommandsEmpty",
34 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_EMPTY)); 34 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_EMPTY));
35 source->AddString("extensionCommandsInactive", 35 source->AddString("extensionCommandsInactive",
36 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_INACTIVE)); 36 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_INACTIVE));
37 source->AddString("extensionCommandsStartTyping", 37 source->AddString("extensionCommandsStartTyping",
38 l10n_util::GetStringUTF16(IDS_EXTENSION_TYPE_SHORTCUT)); 38 l10n_util::GetStringUTF16(IDS_EXTENSION_TYPE_SHORTCUT));
39 source->AddString("extensionCommandsDelete", 39 source->AddString("extensionCommandsDelete",
40 l10n_util::GetStringUTF16(IDS_EXTENSION_DELETE_SHORTCUT)); 40 l10n_util::GetStringUTF16(IDS_EXTENSION_DELETE_SHORTCUT));
41 source->AddString("extensionCommandsGlobal", 41 source->AddString("extensionCommandsGlobal",
42 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GLOBAL)); 42 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GLOBAL));
43 source->AddString("extensionCommandsRegular", 43 source->AddString("extensionCommandsRegular",
44 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_NOT_GLOBAL)); 44 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_NOT_GLOBAL));
45 source->AddString("ok", l10n_util::GetStringUTF16(IDS_OK)); 45 source->AddString("ok", l10n_util::GetStringUTF16(IDS_OK));
46 } 46 }
47 47
48 void CommandHandler::RegisterMessages() { 48 void CommandHandler::RegisterMessages() {
49 registrar_.Add(this, 49 extension_registry_observer_.Add(
50 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 50 extensions::ExtensionRegistry::Get(profile_));
Devlin 2014/05/19 16:04:11 This is all in extensions namespace, so please rem
limasdf 2014/05/20 04:04:49 Done.
51 content::Source<Profile>(profile_));
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
53 content::Source<Profile>(profile_));
54 51
55 web_ui()->RegisterMessageCallback("extensionCommandsRequestExtensionsData", 52 web_ui()->RegisterMessageCallback("extensionCommandsRequestExtensionsData",
56 base::Bind(&CommandHandler::HandleRequestExtensionsData, 53 base::Bind(&CommandHandler::HandleRequestExtensionsData,
57 base::Unretained(this))); 54 base::Unretained(this)));
58 web_ui()->RegisterMessageCallback("setShortcutHandlingSuspended", 55 web_ui()->RegisterMessageCallback("setShortcutHandlingSuspended",
59 base::Bind(&CommandHandler::HandleSetShortcutHandlingSuspended, 56 base::Bind(&CommandHandler::HandleSetShortcutHandlingSuspended,
60 base::Unretained(this))); 57 base::Unretained(this)));
61 web_ui()->RegisterMessageCallback("setExtensionCommandShortcut", 58 web_ui()->RegisterMessageCallback("setExtensionCommandShortcut",
62 base::Bind(&CommandHandler::HandleSetExtensionCommandShortcut, 59 base::Bind(&CommandHandler::HandleSetExtensionCommandShortcut,
63 base::Unretained(this))); 60 base::Unretained(this)));
64 web_ui()->RegisterMessageCallback("setCommandScope", 61 web_ui()->RegisterMessageCallback("setCommandScope",
65 base::Bind(&CommandHandler::HandleSetCommandScope, 62 base::Bind(&CommandHandler::HandleSetCommandScope,
66 base::Unretained(this))); 63 base::Unretained(this)));
67 } 64 }
68 65
69 void CommandHandler::Observe( 66 void CommandHandler::OnExtensionLoaded(content::BrowserContext* browser_context,
70 int type, 67 const extensions::Extension* extension) {
71 const content::NotificationSource& source,
72 const content::NotificationDetails& details) {
73 DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED ||
74 type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
75 UpdateCommandDataOnPage(); 68 UpdateCommandDataOnPage();
76 } 69 }
77 70
71 void CommandHandler::OnExtensionUnloaded(
72 content::BrowserContext* browser_context,
73 const extensions::Extension* extension,
74 extensions::UnloadedExtensionInfo::Reason reason) {
75 UpdateCommandDataOnPage();
76 }
77
78 void CommandHandler::UpdateCommandDataOnPage() { 78 void CommandHandler::UpdateCommandDataOnPage() {
79 base::DictionaryValue results; 79 base::DictionaryValue results;
80 GetAllCommands(&results); 80 GetAllCommands(&results);
81 web_ui()->CallJavascriptFunction( 81 web_ui()->CallJavascriptFunction(
82 "extensions.ExtensionCommandsOverlay.returnExtensionsData", results); 82 "extensions.ExtensionCommandsOverlay.returnExtensionsData", results);
83 } 83 }
84 84
85 void CommandHandler::HandleRequestExtensionsData(const base::ListValue* args) { 85 void CommandHandler::HandleRequestExtensionsData(const base::ListValue* args) {
86 UpdateCommandDataOnPage(); 86 UpdateCommandDataOnPage();
87 } 87 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ExtensionCommandsGlobalRegistry::SetShortcutHandlingSuspended(suspended); 134 ExtensionCommandsGlobalRegistry::SetShortcutHandlingSuspended(suspended);
135 } 135 }
136 } 136 }
137 137
138 void CommandHandler::GetAllCommands(base::DictionaryValue* commands) { 138 void CommandHandler::GetAllCommands(base::DictionaryValue* commands) {
139 base::ListValue* results = new base::ListValue; 139 base::ListValue* results = new base::ListValue;
140 140
141 Profile* profile = Profile::FromWebUI(web_ui()); 141 Profile* profile = Profile::FromWebUI(web_ui());
142 CommandService* command_service = CommandService::Get(profile); 142 CommandService* command_service = CommandService::Get(profile);
143 143
144 const ExtensionSet* extensions = extensions::ExtensionSystem::Get(profile)-> 144 const ExtensionSet& extensions =
145 extension_service()->extensions(); 145 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
146 for (ExtensionSet::const_iterator extension = extensions->begin(); 146 for (ExtensionSet::const_iterator extension = extensions.begin();
147 extension != extensions->end(); ++extension) { 147 extension != extensions.end();
148 ++extension) {
148 scoped_ptr<base::DictionaryValue> extension_dict(new base::DictionaryValue); 149 scoped_ptr<base::DictionaryValue> extension_dict(new base::DictionaryValue);
149 extension_dict->SetString("name", (*extension)->name()); 150 extension_dict->SetString("name", (*extension)->name());
150 extension_dict->SetString("id", (*extension)->id()); 151 extension_dict->SetString("id", (*extension)->id());
151 152
152 // Add the keybindings to a list structure. 153 // Add the keybindings to a list structure.
153 scoped_ptr<base::ListValue> extensions_list(new base::ListValue()); 154 scoped_ptr<base::ListValue> extensions_list(new base::ListValue());
154 155
155 bool active = false; 156 bool active = false;
156 157
157 extensions::Command browser_action; 158 extensions::Command browser_action;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (!extensions_list->empty()) { 193 if (!extensions_list->empty()) {
193 extension_dict->Set("commands", extensions_list.release()); 194 extension_dict->Set("commands", extensions_list.release());
194 results->Append(extension_dict.release()); 195 results->Append(extension_dict.release());
195 } 196 }
196 } 197 }
197 198
198 commands->Set("commands", results); 199 commands->Set("commands", results);
199 } 200 }
200 201
201 } // namespace extensions 202 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698