| OLD | NEW |
| 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/permissions_updater.h" | 5 #include "chrome/browser/extensions/permissions_updater.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 10 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
| 11 #include "chrome/browser/extensions/extension_event_router.h" | 11 #include "chrome/browser/extensions/extension_event_router.h" |
| 12 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/extensions/api/permissions.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_messages.h" | 18 #include "chrome/common/extensions/extension_messages.h" |
| 18 #include "chrome/common/extensions/extension_permission_set.h" | 19 #include "chrome/common/extensions/extension_permission_set.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 21 | 22 |
| 22 using content::RenderProcessHost; | 23 using content::RenderProcessHost; |
| 23 using extensions::permissions_api::PackPermissionsToValue; | 24 using extensions::permissions_api_helpers::PackPermissionSet; |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const char kOnAdded[] = "permissions.onAdded"; | 30 const char kOnAdded[] = "permissions.onAdded"; |
| 30 const char kOnRemoved[] = "permissions.onRemoved"; | 31 const char kOnRemoved[] = "permissions.onRemoved"; |
| 31 | 32 |
| 32 } | 33 } |
| 33 | 34 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 90 } |
| 90 | 91 |
| 91 void PermissionsUpdater::DispatchEvent( | 92 void PermissionsUpdater::DispatchEvent( |
| 92 const std::string& extension_id, | 93 const std::string& extension_id, |
| 93 const char* event_name, | 94 const char* event_name, |
| 94 const ExtensionPermissionSet* changed_permissions) { | 95 const ExtensionPermissionSet* changed_permissions) { |
| 95 if (!profile_ || !profile_->GetExtensionEventRouter()) | 96 if (!profile_ || !profile_->GetExtensionEventRouter()) |
| 96 return; | 97 return; |
| 97 | 98 |
| 98 ListValue value; | 99 ListValue value; |
| 99 value.Append(PackPermissionsToValue(changed_permissions)); | 100 scoped_ptr<api::permissions::Permissions> permissions = |
| 101 PackPermissionSet(changed_permissions); |
| 102 value.Append(permissions->ToValue()); |
| 100 std::string json_value; | 103 std::string json_value; |
| 101 base::JSONWriter::Write(&value, false, &json_value); | 104 base::JSONWriter::Write(&value, false, &json_value); |
| 102 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 105 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
| 103 extension_id, event_name, json_value, profile_, GURL()); | 106 extension_id, event_name, json_value, profile_, GURL()); |
| 104 } | 107 } |
| 105 | 108 |
| 106 void PermissionsUpdater::NotifyPermissionsUpdated( | 109 void PermissionsUpdater::NotifyPermissionsUpdated( |
| 107 EventType event_type, | 110 EventType event_type, |
| 108 const Extension* extension, | 111 const Extension* extension, |
| 109 const ExtensionPermissionSet* changed) { | 112 const ExtensionPermissionSet* changed) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 149 |
| 147 // Trigger the onAdded and onRemoved events in the extension. | 150 // Trigger the onAdded and onRemoved events in the extension. |
| 148 DispatchEvent(extension->id(), event_name, changed); | 151 DispatchEvent(extension->id(), event_name, changed); |
| 149 } | 152 } |
| 150 | 153 |
| 151 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { | 154 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { |
| 152 return profile_->GetExtensionService()->extension_prefs(); | 155 return profile_->GetExtensionService()->extension_prefs(); |
| 153 } | 156 } |
| 154 | 157 |
| 155 } // namespace extensions | 158 } // namespace extensions |
| OLD | NEW |