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

Side by Side Diff: chrome/browser/extensions/extension_management_api.cc

Issue 8520035: Revert 110264 - Fix for management API related to escalated permissions disabled extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_management_api.h" 5 #include "chrome/browser/extensions/extension_management_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h"
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "chrome/browser/extensions/extension_event_names.h" 16 #include "chrome/browser/extensions/extension_event_names.h"
17 #include "chrome/browser/extensions/extension_event_router.h" 17 #include "chrome/browser/extensions/extension_event_router.h"
18 #include "chrome/browser/extensions/extension_management_api_constants.h"
19 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_updater.h" 19 #include "chrome/browser/extensions/extension_updater.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/webui/extension_icon_source.h" 22 #include "chrome/browser/ui/webui/extension_icon_source.h"
24 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_utility_messages.h" 24 #include "chrome/common/chrome_utility_messages.h"
26 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
27 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
28 #include "chrome/common/extensions/extension_error_utils.h" 27 #include "chrome/common/extensions/extension_error_utils.h"
29 #include "chrome/common/extensions/extension_icon_set.h" 28 #include "chrome/common/extensions/extension_icon_set.h"
30 #include "chrome/common/extensions/url_pattern.h" 29 #include "chrome/common/extensions/url_pattern.h"
31 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.h"
33 32
34 using base::IntToString; 33 using base::IntToString;
35 using content::BrowserThread; 34 using content::BrowserThread;
35 namespace events = extension_event_names;
36 36
37 namespace events = extension_event_names; 37 namespace {
38 namespace keys = extension_management_api_constants; 38
39 const char kAppLaunchUrlKey[] = "appLaunchUrl";
40 const char kDescriptionKey[] = "description";
41 const char kEnabledKey[] = "enabled";
42 const char kHomepageUrlKey[] = "homepageUrl";
43 const char kIconsKey[] = "icons";
44 const char kIdKey[] = "id";
45 const char kIsAppKey[] = "isApp";
46 const char kNameKey[] = "name";
47 const char kOfflineEnabledKey[] = "offlineEnabled";
48 const char kOptionsUrlKey[] = "optionsUrl";
49 const char kPermissionsKey[] = "permissions";
50 const char kMayDisableKey[] = "mayDisable";
51 const char kSizeKey[] = "size";
52 const char kUpdateUrlKey[] = "updateUrl";
53 const char kUrlKey[] = "url";
54 const char kVersionKey[] = "version";
55
56 const char kExtensionCreateError[] =
57 "Failed to create extension from manifest.";
58 const char kManifestParseError[] = "Failed to parse manifest.";
59 const char kNoExtensionError[] = "Failed to find extension with id *";
60 const char kNotAnAppError[] = "Extension * is not an App";
61 const char kUserCantDisableError[] = "Extension * can not be disabled by user";
62 }
39 63
40 ExtensionService* ExtensionManagementFunction::service() { 64 ExtensionService* ExtensionManagementFunction::service() {
41 return profile()->GetExtensionService(); 65 return profile()->GetExtensionService();
42 } 66 }
43 67
44 ExtensionService* AsyncExtensionManagementFunction::service() {
45 return profile()->GetExtensionService();
46 }
47
48 static DictionaryValue* CreateExtensionInfo(const Extension& extension, 68 static DictionaryValue* CreateExtensionInfo(const Extension& extension,
49 bool enabled, 69 bool enabled) {
50 bool permissions_escalated) {
51 DictionaryValue* info = new DictionaryValue(); 70 DictionaryValue* info = new DictionaryValue();
52 info->SetString(keys::kIdKey, extension.id()); 71 info->SetString(kIdKey, extension.id());
53 info->SetBoolean(keys::kIsAppKey, extension.is_app()); 72 info->SetBoolean(kIsAppKey, extension.is_app());
54 info->SetString(keys::kNameKey, extension.name()); 73 info->SetString(kNameKey, extension.name());
55 info->SetBoolean(keys::kEnabledKey, enabled); 74 info->SetBoolean(kEnabledKey, enabled);
56 if (!enabled) { 75 info->SetBoolean(kMayDisableKey,
57 const char* reason = permissions_escalated ? 76 Extension::UserMayDisable(extension.location()));
58 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; 77 info->SetBoolean(kOfflineEnabledKey, extension.offline_enabled());
59 info->SetString(keys::kDisabledReasonKey, reason); 78 info->SetString(kVersionKey, extension.VersionString());
79 info->SetString(kDescriptionKey, extension.description());
80 info->SetString(kOptionsUrlKey,
81 extension.options_url().possibly_invalid_spec());
82 info->SetString(kHomepageUrlKey,
83 extension.GetHomepageURL().possibly_invalid_spec());
84 if (!extension.update_url().is_empty()) {
85 info->SetString(kUpdateUrlKey,
86 extension.update_url().possibly_invalid_spec());
60 } 87 }
61 info->SetBoolean(keys::kMayDisableKey,
62 Extension::UserMayDisable(extension.location()));
63 info->SetBoolean(keys::kOfflineEnabledKey, extension.offline_enabled());
64 info->SetString(keys::kVersionKey, extension.VersionString());
65 info->SetString(keys::kDescriptionKey, extension.description());
66 info->SetString(keys::kOptionsUrlKey,
67 extension.options_url().possibly_invalid_spec());
68 info->SetString(keys::kHomepageUrlKey,
69 extension.GetHomepageURL().possibly_invalid_spec());
70 if (!extension.update_url().is_empty())
71 info->SetString(keys::kUpdateUrlKey,
72 extension.update_url().possibly_invalid_spec());
73 if (extension.is_app()) 88 if (extension.is_app())
74 info->SetString(keys::kAppLaunchUrlKey, 89 info->SetString(kAppLaunchUrlKey,
75 extension.GetFullLaunchURL().possibly_invalid_spec()); 90 extension.GetFullLaunchURL().possibly_invalid_spec());
76 91
77 const ExtensionIconSet::IconMap& icons = extension.icons().map(); 92 const ExtensionIconSet::IconMap& icons = extension.icons().map();
78 if (!icons.empty()) { 93 if (!icons.empty()) {
79 ListValue* icon_list = new ListValue(); 94 ListValue* icon_list = new ListValue();
80 std::map<int, std::string>::const_iterator icon_iter; 95 std::map<int, std::string>::const_iterator icon_iter;
81 for (icon_iter = icons.begin(); icon_iter != icons.end(); ++icon_iter) { 96 for (icon_iter = icons.begin(); icon_iter != icons.end(); ++icon_iter) {
82 DictionaryValue* icon_info = new DictionaryValue(); 97 DictionaryValue* icon_info = new DictionaryValue();
83 Extension::Icons size = static_cast<Extension::Icons>(icon_iter->first); 98 Extension::Icons size = static_cast<Extension::Icons>(icon_iter->first);
84 GURL url = ExtensionIconSource::GetIconURL( 99 GURL url = ExtensionIconSource::GetIconURL(
85 &extension, size, ExtensionIconSet::MATCH_EXACTLY, false, NULL); 100 &extension, size, ExtensionIconSet::MATCH_EXACTLY, false, NULL);
86 icon_info->SetInteger(keys::kSizeKey, icon_iter->first); 101 icon_info->SetInteger(kSizeKey, icon_iter->first);
87 icon_info->SetString(keys::kUrlKey, url.spec()); 102 icon_info->SetString(kUrlKey, url.spec());
88 icon_list->Append(icon_info); 103 icon_list->Append(icon_info);
89 } 104 }
90 info->Set("icons", icon_list); 105 info->Set("icons", icon_list);
91 } 106 }
92 107
93 const std::set<std::string> perms = 108 const std::set<std::string> perms =
94 extension.GetActivePermissions()->GetAPIsAsStrings(); 109 extension.GetActivePermissions()->GetAPIsAsStrings();
95 ListValue* permission_list = new ListValue(); 110 ListValue* permission_list = new ListValue();
96 if (!perms.empty()) { 111 if (!perms.empty()) {
97 std::set<std::string>::const_iterator perms_iter; 112 std::set<std::string>::const_iterator perms_iter;
(...skipping 19 matching lines...) Expand all
117 } 132 }
118 } 133 }
119 } 134 }
120 info->Set("hostPermissions", host_permission_list); 135 info->Set("hostPermissions", host_permission_list);
121 136
122 return info; 137 return info;
123 } 138 }
124 139
125 static void AddExtensionInfo(ListValue* list, 140 static void AddExtensionInfo(ListValue* list,
126 const ExtensionList& extensions, 141 const ExtensionList& extensions,
127 bool enabled, 142 bool enabled) {
128 ExtensionPrefs* prefs) {
129 for (ExtensionList::const_iterator i = extensions.begin(); 143 for (ExtensionList::const_iterator i = extensions.begin();
130 i != extensions.end(); ++i) { 144 i != extensions.end(); ++i) {
131 const Extension& extension = **i; 145 const Extension& extension = **i;
132 146
133 if (extension.location() == Extension::COMPONENT) 147 if (extension.location() == Extension::COMPONENT)
134 continue; // Skip built-in extensions. 148 continue; // Skip built-in extensions.
135 149
136 bool escalated = 150 list->Append(CreateExtensionInfo(extension, enabled));
137 prefs->DidExtensionEscalatePermissions(extension.id());
138 list->Append(CreateExtensionInfo(extension, enabled, escalated));
139 } 151 }
140 } 152 }
141 153
142 bool GetAllExtensionsFunction::RunImpl() { 154 bool GetAllExtensionsFunction::RunImpl() {
143 ListValue* result = new ListValue(); 155 ListValue* result = new ListValue();
144 result_.reset(result); 156 result_.reset(result);
145 157
146 ExtensionPrefs* prefs = service()->extension_prefs(); 158 AddExtensionInfo(result, *service()->extensions(), true);
147 AddExtensionInfo(result, *service()->extensions(), true, prefs); 159 AddExtensionInfo(result, *service()->disabled_extensions(), false);
148 AddExtensionInfo(
149 result, *service()->disabled_extensions(), false, prefs);
150 160
151 return true; 161 return true;
152 } 162 }
153 163
154 bool GetExtensionByIdFunction::RunImpl() { 164 bool GetExtensionByIdFunction::RunImpl() {
155 std::string extension_id; 165 std::string extension_id;
156 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); 166 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
157 const Extension* extension = service()->GetExtensionById(extension_id, true); 167 const Extension* extension = service()->GetExtensionById(extension_id, true);
158 if (!extension) { 168 if (!extension) {
159 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 169 error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError,
160 extension_id); 170 extension_id);
161 return false; 171 return false;
162 } 172 }
163 bool enabled = service()->IsExtensionEnabled(extension_id); 173 bool enabled = service()->IsExtensionEnabled(extension_id);
164 ExtensionPrefs* prefs = service()->extension_prefs(); 174 DictionaryValue* result = CreateExtensionInfo(*extension, enabled);
165 bool escalated = prefs->DidExtensionEscalatePermissions(extension_id);
166 DictionaryValue* result = CreateExtensionInfo(*extension, enabled, escalated);
167 result_.reset(result); 175 result_.reset(result);
168 176
169 return true; 177 return true;
170 } 178 }
171 179
172 bool GetPermissionWarningsByIdFunction::RunImpl() { 180 bool GetPermissionWarningsByIdFunction::RunImpl() {
173 std::string ext_id; 181 std::string ext_id;
174 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &ext_id)); 182 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &ext_id));
175 183
176 const Extension* extension = service()->GetExtensionById(ext_id, true); 184 const Extension* extension = service()->GetExtensionById(ext_id, true);
177 if (!extension) { 185 if (!extension) {
178 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 186 error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError,
179 ext_id); 187 ext_id);
180 return false; 188 return false;
181 } 189 }
182 190
183 ExtensionPermissionMessages warnings = extension->GetPermissionMessages(); 191 ExtensionPermissionMessages warnings = extension->GetPermissionMessages();
184 ListValue* result = new ListValue(); 192 ListValue* result = new ListValue();
185 for (ExtensionPermissionMessages::const_iterator i = warnings.begin(); 193 for (ExtensionPermissionMessages::const_iterator i = warnings.begin();
186 i < warnings.end(); ++i) 194 i < warnings.end(); ++i)
187 result->Append(Value::CreateStringValue(i->message())); 195 result->Append(Value::CreateStringValue(i->message()));
188 result_.reset(result); 196 result_.reset(result);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return handled; 235 return handled;
228 } 236 }
229 237
230 void OnJSONParseSucceeded(const ListValue& wrapper) { 238 void OnJSONParseSucceeded(const ListValue& wrapper) {
231 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 239 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
232 Value* value = NULL; 240 Value* value = NULL;
233 CHECK(wrapper.Get(0, &value)); 241 CHECK(wrapper.Get(0, &value));
234 if (value->IsType(Value::TYPE_DICTIONARY)) 242 if (value->IsType(Value::TYPE_DICTIONARY))
235 parsed_manifest_.reset(static_cast<DictionaryValue*>(value)->DeepCopy()); 243 parsed_manifest_.reset(static_cast<DictionaryValue*>(value)->DeepCopy());
236 else 244 else
237 error_ = keys::kManifestParseError; 245 error_ = kManifestParseError;
238 246
239 utility_host_ = NULL; // has already deleted itself 247 utility_host_ = NULL; // has already deleted itself
240 BrowserThread::PostTask( 248 BrowserThread::PostTask(
241 BrowserThread::UI, 249 BrowserThread::UI,
242 FROM_HERE, 250 FROM_HERE,
243 base::Bind(&SafeManifestJSONParser::ReportResultFromUIThread, this)); 251 base::Bind(&SafeManifestJSONParser::ReportResultFromUIThread, this));
244 } 252 }
245 253
246 void OnJSONParseFailed(const std::string& error) { 254 void OnJSONParseFailed(const std::string& error) {
247 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 255 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 303 }
296 304
297 void GetPermissionWarningsByManifestFunction::OnParseSuccess( 305 void GetPermissionWarningsByManifestFunction::OnParseSuccess(
298 DictionaryValue* parsed_manifest) { 306 DictionaryValue* parsed_manifest) {
299 CHECK(parsed_manifest); 307 CHECK(parsed_manifest);
300 308
301 scoped_refptr<Extension> extension = Extension::Create( 309 scoped_refptr<Extension> extension = Extension::Create(
302 FilePath(), Extension::INVALID, *parsed_manifest, 310 FilePath(), Extension::INVALID, *parsed_manifest,
303 Extension::STRICT_ERROR_CHECKS, &error_); 311 Extension::STRICT_ERROR_CHECKS, &error_);
304 if (!extension.get()) { 312 if (!extension.get()) {
305 OnParseFailure(keys::kExtensionCreateError); 313 OnParseFailure(kExtensionCreateError);
306 return; 314 return;
307 } 315 }
308 316
309 ExtensionPermissionMessages warnings = extension->GetPermissionMessages(); 317 ExtensionPermissionMessages warnings = extension->GetPermissionMessages();
310 ListValue* result = new ListValue(); 318 ListValue* result = new ListValue();
311 for (ExtensionPermissionMessages::const_iterator i = warnings.begin(); 319 for (ExtensionPermissionMessages::const_iterator i = warnings.begin();
312 i < warnings.end(); ++i) 320 i < warnings.end(); ++i)
313 result->Append(Value::CreateStringValue(i->message())); 321 result->Append(Value::CreateStringValue(i->message()));
314 result_.reset(result); 322 result_.reset(result);
315 SendResponse(true); 323 SendResponse(true);
316 324
317 // Matched with AddRef() in RunImpl(). 325 // Matched with AddRef() in RunImpl().
318 Release(); 326 Release();
319 } 327 }
320 328
321 void GetPermissionWarningsByManifestFunction::OnParseFailure( 329 void GetPermissionWarningsByManifestFunction::OnParseFailure(
322 const std::string& error) { 330 const std::string& error) {
323 error_ = error; 331 error_ = error;
324 SendResponse(false); 332 SendResponse(false);
325 333
326 // Matched with AddRef() in RunImpl(). 334 // Matched with AddRef() in RunImpl().
327 Release(); 335 Release();
328 } 336 }
329 337
330 bool LaunchAppFunction::RunImpl() { 338 bool LaunchAppFunction::RunImpl() {
331 std::string extension_id; 339 std::string extension_id;
332 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); 340 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
333 const Extension* extension = service()->GetExtensionById(extension_id, true); 341 const Extension* extension = service()->GetExtensionById(extension_id, true);
334 if (!extension) { 342 if (!extension) {
335 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 343 error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError,
336 extension_id); 344 extension_id);
337 return false; 345 return false;
338 } 346 }
339 if (!extension->is_app()) { 347 if (!extension->is_app()) {
340 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNotAnAppError, 348 error_ = ExtensionErrorUtils::FormatErrorMessage(kNotAnAppError,
341 extension_id); 349 extension_id);
342 return false; 350 return false;
343 } 351 }
344 352
345 // Look at prefs to find the right launch container. 353 // Look at prefs to find the right launch container.
346 // |default_pref_value| is set to LAUNCH_REGULAR so that if 354 // |default_pref_value| is set to LAUNCH_REGULAR so that if
347 // the user has not set a preference, we open the app in a tab. 355 // the user has not set a preference, we open the app in a tab.
348 extension_misc::LaunchContainer launch_container = 356 extension_misc::LaunchContainer launch_container =
349 service()->extension_prefs()->GetLaunchContainer( 357 service()->extension_prefs()->GetLaunchContainer(
350 extension, ExtensionPrefs::LAUNCH_DEFAULT); 358 extension, ExtensionPrefs::LAUNCH_DEFAULT);
351 Browser::OpenApplication(profile(), extension, launch_container, GURL(), 359 Browser::OpenApplication(profile(), extension, launch_container, GURL(),
352 NEW_FOREGROUND_TAB); 360 NEW_FOREGROUND_TAB);
353 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, 361 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram,
354 extension_misc::APP_LAUNCH_EXTENSION_API, 362 extension_misc::APP_LAUNCH_EXTENSION_API,
355 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); 363 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
356 364
357 return true; 365 return true;
358 } 366 }
359 367
360 SetEnabledFunction::SetEnabledFunction() {}
361
362 SetEnabledFunction::~SetEnabledFunction() {}
363
364 bool SetEnabledFunction::RunImpl() { 368 bool SetEnabledFunction::RunImpl() {
369 std::string extension_id;
365 bool enable; 370 bool enable;
366 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); 371 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
367 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); 372 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable));
368 373
369 const Extension* extension = service()->GetExtensionById(extension_id_, true); 374 const Extension* extension = service()->GetExtensionById(extension_id, true);
370 if (!extension) { 375 if (!extension) {
371 error_ = ExtensionErrorUtils::FormatErrorMessage( 376 error_ = ExtensionErrorUtils::FormatErrorMessage(
372 keys::kNoExtensionError, extension_id_); 377 kNoExtensionError, extension_id);
373 return false; 378 return false;
374 } 379 }
375 380
376 if (!Extension::UserMayDisable(extension->location())) { 381 if (!Extension::UserMayDisable(extension->location())) {
377 error_ = ExtensionErrorUtils::FormatErrorMessage( 382 error_ = ExtensionErrorUtils::FormatErrorMessage(
378 keys::kUserCantDisableError, extension_id_); 383 kUserCantDisableError, extension_id);
379 return false; 384 return false;
380 } 385 }
381 386
382 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); 387 if (!service()->IsExtensionEnabled(extension_id) && enable)
383 388 service()->EnableExtension(extension_id);
384 if (!currently_enabled && enable) { 389 else if (service()->IsExtensionEnabled(extension_id) && !enable)
385 ExtensionPrefs* prefs = service()->extension_prefs(); 390 service()->DisableExtension(extension_id);
386 if (prefs->DidExtensionEscalatePermissions(extension_id_)) {
387 if (!user_gesture()) {
388 error_ = keys::kGestureNeededForEscalationError;
389 return false;
390 }
391 AddRef(); // Matched in InstallUIProceed/InstallUIAbort
392 install_ui_.reset(new ExtensionInstallUI(profile_));
393 install_ui_->ConfirmReEnable(this, extension);
394 return true;
395 }
396 service()->EnableExtension(extension_id_);
397 } else if (currently_enabled && !enable) {
398 service()->DisableExtension(extension_id_);
399 }
400
401 BrowserThread::PostTask(
402 BrowserThread::UI,
403 FROM_HERE,
404 base::Bind(&SetEnabledFunction::SendResponse, this, true));
405 391
406 return true; 392 return true;
407 } 393 }
408 394
409 void SetEnabledFunction::InstallUIProceed() {
410 service()->EnableExtension(extension_id_);
411 SendResponse(true);
412 Release();
413 }
414
415 void SetEnabledFunction::InstallUIAbort(bool user_initiated) {
416 error_ = keys::kUserDidNotReEnableError;
417 SendResponse(false);
418 Release();
419 }
420
421 bool UninstallFunction::RunImpl() { 395 bool UninstallFunction::RunImpl() {
422 std::string extension_id; 396 std::string extension_id;
423 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); 397 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
424 398
425 if (!service()->GetExtensionById(extension_id, true)) { 399 if (!service()->GetExtensionById(extension_id, true)) {
426 error_ = ExtensionErrorUtils::FormatErrorMessage( 400 error_ = ExtensionErrorUtils::FormatErrorMessage(
427 keys::kNoExtensionError, extension_id); 401 kNoExtensionError, extension_id);
428 return false; 402 return false;
429 } 403 }
430 404
431 ExtensionPrefs* prefs = service()->extension_prefs(); 405 ExtensionPrefs* prefs = service()->extension_prefs();
432 406
433 if (!Extension::UserMayDisable( 407 if (!Extension::UserMayDisable(
434 prefs->GetInstalledExtensionInfo(extension_id)->extension_location)) { 408 prefs->GetInstalledExtensionInfo(extension_id)->extension_location)) {
435 error_ = ExtensionErrorUtils::FormatErrorMessage( 409 error_ = ExtensionErrorUtils::FormatErrorMessage(
436 keys::kUserCantDisableError, extension_id); 410 kUserCantDisableError, extension_id);
437 return false; 411 return false;
438 } 412 }
439 413
440 service()->UninstallExtension(extension_id, false /* external_uninstall */, 414 service()->UninstallExtension(extension_id, false /* external_uninstall */,
441 NULL); 415 NULL);
442 return true; 416 return true;
443 } 417 }
444 418
445 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile) 419 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile)
446 : profile_(profile) {} 420 : profile_(profile) {}
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 *content::Details<const std::string>(details).ptr())); 470 *content::Details<const std::string>(details).ptr()));
497 } else { 471 } else {
498 const Extension* extension = NULL; 472 const Extension* extension = NULL;
499 if (event_name == events::kOnExtensionDisabled) { 473 if (event_name == events::kOnExtensionDisabled) {
500 extension = content::Details<UnloadedExtensionInfo>(details)->extension; 474 extension = content::Details<UnloadedExtensionInfo>(details)->extension;
501 } else { 475 } else {
502 extension = content::Details<const Extension>(details).ptr(); 476 extension = content::Details<const Extension>(details).ptr();
503 } 477 }
504 CHECK(extension); 478 CHECK(extension);
505 ExtensionService* service = profile->GetExtensionService(); 479 ExtensionService* service = profile->GetExtensionService();
506 ExtensionPrefs* prefs = service->extension_prefs();
507 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; 480 bool enabled = service->GetExtensionById(extension->id(), false) != NULL;
508 bool escalated = prefs ->DidExtensionEscalatePermissions(extension->id()); 481 args.Append(CreateExtensionInfo(*extension, enabled));
509 args.Append(CreateExtensionInfo(*extension, enabled, escalated));
510 } 482 }
511 483
512 std::string args_json; 484 std::string args_json;
513 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 485 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
514 486
515 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 487 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
516 event_name, args_json, NULL, GURL()); 488 event_name, args_json, NULL, GURL());
517 } 489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698