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

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 1049483003: [Extensions] Update extensions UI to observe events and add test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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/extensions/api/developer_private/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 return render_view_host->GetSiteInstance()->GetSiteURL().host(); 147 return render_view_host->GetSiteInstance()->GetSiteURL().host();
148 } 148 }
149 149
150 void BroadcastItemStateChanged(content::BrowserContext* browser_context, 150 void BroadcastItemStateChanged(content::BrowserContext* browser_context,
151 developer::EventType event_type, 151 developer::EventType event_type,
152 const std::string& item_id) { 152 const std::string& item_id) {
153 developer::EventData event_data; 153 developer::EventData event_data;
154 event_data.event_type = event_type; 154 event_data.event_type = event_type;
155 event_data.item_id = item_id; 155 event_data.item_id = item_id;
156 event_data.extension_info =
157 ExtensionInfoGenerator(browser_context).CreateExtensionInfo(item_id);
156 158
157 scoped_ptr<base::ListValue> args(new base::ListValue()); 159 scoped_ptr<base::ListValue> args(new base::ListValue());
158 args->Append(event_data.ToValue().release()); 160 args->Append(event_data.ToValue().release());
159 scoped_ptr<Event> event(new Event( 161 scoped_ptr<Event> event(new Event(
160 developer_private::OnItemStateChanged::kEventName, args.Pass())); 162 developer_private::OnItemStateChanged::kEventName, args.Pass()));
161 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass()); 163 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass());
162 } 164 }
163 165
164 std::string ReadFileToString(const base::FilePath& path) { 166 std::string ReadFileToString(const base::FilePath& path) {
165 std::string data; 167 std::string data;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 DeveloperPrivateGetExtensionInfoFunction:: 411 DeveloperPrivateGetExtensionInfoFunction::
410 ~DeveloperPrivateGetExtensionInfoFunction() { 412 ~DeveloperPrivateGetExtensionInfoFunction() {
411 } 413 }
412 414
413 ExtensionFunction::ResponseAction 415 ExtensionFunction::ResponseAction
414 DeveloperPrivateGetExtensionInfoFunction::Run() { 416 DeveloperPrivateGetExtensionInfoFunction::Run() {
415 scoped_ptr<developer::GetExtensionInfo::Params> params( 417 scoped_ptr<developer::GetExtensionInfo::Params> params(
416 developer::GetExtensionInfo::Params::Create(*args_)); 418 developer::GetExtensionInfo::Params::Create(*args_));
417 EXTENSION_FUNCTION_VALIDATE(params); 419 EXTENSION_FUNCTION_VALIDATE(params);
418 420
419 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); 421 scoped_ptr<developer::ExtensionInfo> info =
420 developer::ExtensionState state = developer::EXTENSION_STATE_ENABLED; 422 ExtensionInfoGenerator(browser_context()).CreateExtensionInfo(params->id);
421 const Extension* extension =
422 registry->enabled_extensions().GetByID(params->id);
423 if (!extension &&
424 (extension = registry->disabled_extensions().GetByID(params->id)) !=
425 nullptr) {
426 state = developer::EXTENSION_STATE_DISABLED;
427 } else if (!extension &&
428 (extension =
429 registry->terminated_extensions().GetByID(params->id)) !=
430 nullptr) {
431 state = developer::EXTENSION_STATE_TERMINATED;
432 }
433 423
434 if (!extension) 424 if (!info)
435 return RespondNow(Error(kNoSuchExtensionError)); 425 return RespondNow(Error(kNoSuchExtensionError));
436 426
437 return RespondNow(OneArgument(ExtensionInfoGenerator(browser_context()). 427 return RespondNow(OneArgument(info->ToValue().release()));
438 CreateExtensionInfo(*extension, state)->ToValue().release()));
439 } 428 }
440 429
441 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() {} 430 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() {}
442 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} 431 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {}
443 432
444 ExtensionFunction::ResponseAction DeveloperPrivateGetItemsInfoFunction::Run() { 433 ExtensionFunction::ResponseAction DeveloperPrivateGetItemsInfoFunction::Run() {
445 scoped_ptr<developer::GetItemsInfo::Params> params( 434 scoped_ptr<developer::GetItemsInfo::Params> params(
446 developer::GetItemsInfo::Params::Create(*args_)); 435 developer::GetItemsInfo::Params::Create(*args_));
447 EXTENSION_FUNCTION_VALIDATE(params); 436 EXTENSION_FUNCTION_VALIDATE(params);
448 437
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 } 1223 }
1235 error_console->RemoveErrors(ErrorMap::Filter( 1224 error_console->RemoveErrors(ErrorMap::Filter(
1236 properties.extension_id, type, error_ids, false)); 1225 properties.extension_id, type, error_ids, false));
1237 1226
1238 return RespondNow(NoArguments()); 1227 return RespondNow(NoArguments());
1239 } 1228 }
1240 1229
1241 } // namespace api 1230 } // namespace api
1242 1231
1243 } // namespace extensions 1232 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698