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/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 11 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/extensions/api/permissions.h" | 13 #include "chrome/common/extensions/api/permissions.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
19 #include "extensions/browser/extension_prefs.h" | 19 #include "extensions/browser/extension_prefs.h" |
20 #include "extensions/browser/extension_system.h" | |
21 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_messages.h" | 21 #include "extensions/common/extension_messages.h" |
23 #include "extensions/common/permissions/permissions_data.h" | 22 #include "extensions/common/permissions/permissions_data.h" |
24 | 23 |
25 using content::RenderProcessHost; | 24 using content::RenderProcessHost; |
26 using extensions::permissions_api_helpers::PackPermissionSet; | 25 using extensions::permissions_api_helpers::PackPermissionSet; |
27 | 26 |
28 namespace extensions { | 27 namespace extensions { |
29 | 28 |
30 namespace permissions = api::permissions; | 29 namespace permissions = api::permissions; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 const Extension* extension, const PermissionSet* permissions) { | 84 const Extension* extension, const PermissionSet* permissions) { |
86 ExtensionPrefs::Get(profile_)->SetActivePermissions( | 85 ExtensionPrefs::Get(profile_)->SetActivePermissions( |
87 extension->id(), permissions); | 86 extension->id(), permissions); |
88 PermissionsData::SetActivePermissions(extension, permissions); | 87 PermissionsData::SetActivePermissions(extension, permissions); |
89 } | 88 } |
90 | 89 |
91 void PermissionsUpdater::DispatchEvent( | 90 void PermissionsUpdater::DispatchEvent( |
92 const std::string& extension_id, | 91 const std::string& extension_id, |
93 const char* event_name, | 92 const char* event_name, |
94 const PermissionSet* changed_permissions) { | 93 const PermissionSet* changed_permissions) { |
95 if (!profile_ || | 94 if (!profile_ || !EventRouter::Get(profile_)) |
96 !ExtensionSystem::Get(profile_)->event_router()) | |
97 return; | 95 return; |
98 | 96 |
99 scoped_ptr<base::ListValue> value(new base::ListValue()); | 97 scoped_ptr<base::ListValue> value(new base::ListValue()); |
100 scoped_ptr<api::permissions::Permissions> permissions = | 98 scoped_ptr<api::permissions::Permissions> permissions = |
101 PackPermissionSet(changed_permissions); | 99 PackPermissionSet(changed_permissions); |
102 value->Append(permissions->ToValue().release()); | 100 value->Append(permissions->ToValue().release()); |
103 scoped_ptr<Event> event(new Event(event_name, value.Pass())); | 101 scoped_ptr<Event> event(new Event(event_name, value.Pass())); |
104 event->restrict_to_browser_context = profile_; | 102 event->restrict_to_browser_context = profile_; |
105 ExtensionSystem::Get(profile_)->event_router()-> | 103 EventRouter::Get(profile_) |
106 DispatchEventToExtension(extension_id, event.Pass()); | 104 ->DispatchEventToExtension(extension_id, event.Pass()); |
benwells
2014/04/16 04:43:03
Is this clang format?
limasdf
2014/04/16 04:50:20
It is automatically fixed by 'git cl format' when
| |
107 } | 105 } |
108 | 106 |
109 void PermissionsUpdater::NotifyPermissionsUpdated( | 107 void PermissionsUpdater::NotifyPermissionsUpdated( |
110 EventType event_type, | 108 EventType event_type, |
111 const Extension* extension, | 109 const Extension* extension, |
112 const PermissionSet* changed) { | 110 const PermissionSet* changed) { |
113 if (!changed || changed->IsEmpty()) | 111 if (!changed || changed->IsEmpty()) |
114 return; | 112 return; |
115 | 113 |
116 UpdatedExtensionPermissionsInfo::Reason reason; | 114 UpdatedExtensionPermissionsInfo::Reason reason; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 info.scriptable_hosts = changed->scriptable_hosts(); | 146 info.scriptable_hosts = changed->scriptable_hosts(); |
149 host->Send(new ExtensionMsg_UpdatePermissions(info)); | 147 host->Send(new ExtensionMsg_UpdatePermissions(info)); |
150 } | 148 } |
151 } | 149 } |
152 | 150 |
153 // Trigger the onAdded and onRemoved events in the extension. | 151 // Trigger the onAdded and onRemoved events in the extension. |
154 DispatchEvent(extension->id(), event_name, changed); | 152 DispatchEvent(extension->id(), event_name, changed); |
155 } | 153 } |
156 | 154 |
157 } // namespace extensions | 155 } // namespace extensions |
OLD | NEW |