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/system/system_api.h" | 5 #include "chrome/browser/extensions/system/system_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/event_router.h" | 9 #include "chrome/browser/extensions/event_router.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const char kUpdatingState[] = "Updating"; | 42 const char kUpdatingState[] = "Updating"; |
43 const char kNeedRestartState[] = "NeedRestart"; | 43 const char kNeedRestartState[] = "NeedRestart"; |
44 | 44 |
45 // Event names. | 45 // Event names. |
46 const char kOnBrightnessChanged[] = "systemPrivate.onBrightnessChanged"; | 46 const char kOnBrightnessChanged[] = "systemPrivate.onBrightnessChanged"; |
47 const char kOnVolumeChanged[] = "systemPrivate.onVolumeChanged"; | 47 const char kOnVolumeChanged[] = "systemPrivate.onVolumeChanged"; |
48 const char kOnScreenUnlocked[] = "systemPrivate.onScreenUnlocked"; | 48 const char kOnScreenUnlocked[] = "systemPrivate.onScreenUnlocked"; |
49 const char kOnWokeUp[] = "systemPrivate.onWokeUp"; | 49 const char kOnWokeUp[] = "systemPrivate.onWokeUp"; |
50 | 50 |
51 // Dispatches an extension event with |args| | 51 // Dispatches an extension event with |args| |
52 void DispatchEvent(const std::string& event_name, const ListValue& args) { | 52 void DispatchEvent(const std::string& event_name, base::Value* argument) { |
53 Profile* profile = ProfileManager::GetDefaultProfile(); | 53 Profile* profile = ProfileManager::GetDefaultProfile(); |
54 if (!profile) | 54 if (!profile) |
55 return; | 55 return; |
56 extensions::EventRouter* extension_event_router = | 56 extensions::EventRouter* extension_event_router = |
57 profile->GetExtensionEventRouter(); | 57 profile->GetExtensionEventRouter(); |
58 if (!extension_event_router) | 58 if (!extension_event_router) |
59 return; | 59 return; |
60 std::string json_args; | 60 |
61 base::JSONWriter::Write(&args, &json_args); | 61 scoped_ptr<base::ListValue> list_args(new base::ListValue()); |
| 62 list_args->Append(argument); |
62 extension_event_router->DispatchEventToRenderers( | 63 extension_event_router->DispatchEventToRenderers( |
63 event_name, json_args, NULL, GURL(), extensions::EventFilteringInfo()); | 64 event_name, list_args.Pass(), NULL, GURL(), |
| 65 extensions::EventFilteringInfo()); |
64 } | 66 } |
65 | 67 |
66 } // namespace | 68 } // namespace |
67 | 69 |
68 namespace extensions { | 70 namespace extensions { |
69 | 71 |
70 bool GetIncognitoModeAvailabilityFunction::RunImpl() { | 72 bool GetIncognitoModeAvailabilityFunction::RunImpl() { |
71 PrefService* prefs = profile_->GetPrefs(); | 73 PrefService* prefs = profile_->GetPrefs(); |
72 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); | 74 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); |
73 EXTENSION_FUNCTION_VALIDATE( | 75 EXTENSION_FUNCTION_VALIDATE( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 #endif | 134 #endif |
133 DictionaryValue* dict = new DictionaryValue(); | 135 DictionaryValue* dict = new DictionaryValue(); |
134 dict->SetString(kStateKey, state); | 136 dict->SetString(kStateKey, state); |
135 dict->SetDouble(kDownloadProgressKey, download_progress); | 137 dict->SetDouble(kDownloadProgressKey, download_progress); |
136 SetResult(dict); | 138 SetResult(dict); |
137 | 139 |
138 return true; | 140 return true; |
139 } | 141 } |
140 | 142 |
141 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { | 143 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { |
142 ListValue args; | |
143 DictionaryValue* dict = new DictionaryValue(); | 144 DictionaryValue* dict = new DictionaryValue(); |
144 dict->SetDouble(kVolumeKey, volume); | 145 dict->SetDouble(kVolumeKey, volume); |
145 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); | 146 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); |
146 args.Append(dict); | 147 DispatchEvent(kOnVolumeChanged, dict); |
147 DispatchEvent(kOnVolumeChanged, args); | |
148 } | 148 } |
149 | 149 |
150 void DispatchBrightnessChangedEvent(int brightness, bool user_initiated) { | 150 void DispatchBrightnessChangedEvent(int brightness, bool user_initiated) { |
151 ListValue args; | |
152 DictionaryValue* dict = new DictionaryValue(); | 151 DictionaryValue* dict = new DictionaryValue(); |
153 dict->SetInteger(kBrightnessKey, brightness); | 152 dict->SetInteger(kBrightnessKey, brightness); |
154 dict->SetBoolean(kUserInitiatedKey, user_initiated); | 153 dict->SetBoolean(kUserInitiatedKey, user_initiated); |
155 args.Append(dict); | 154 DispatchEvent(kOnBrightnessChanged, dict); |
156 DispatchEvent(kOnBrightnessChanged, args); | |
157 } | 155 } |
158 | 156 |
159 void DispatchScreenUnlockedEvent() { | 157 void DispatchScreenUnlockedEvent() { |
160 ListValue args; | 158 DispatchEvent(kOnScreenUnlocked, NULL); |
161 DispatchEvent(kOnScreenUnlocked, args); | |
162 } | 159 } |
163 | 160 |
164 void DispatchWokeUpEvent() { | 161 void DispatchWokeUpEvent() { |
165 ListValue args; | 162 DispatchEvent(kOnWokeUp, NULL); |
166 DispatchEvent(kOnWokeUp, args); | |
167 } | 163 } |
168 | 164 |
169 } // namespace extensions | 165 } // namespace extensions |
OLD | NEW |