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

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

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

Powered by Google App Engine
This is Rietveld 408576698