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/api/app/app_api.h" | 5 #include "chrome/browser/extensions/api/app/app_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 AppNotificationManager* manager = | 115 AppNotificationManager* manager = |
116 profile()->GetExtensionService()->app_notification_manager(); | 116 profile()->GetExtensionService()->app_notification_manager(); |
117 manager->ClearAll(id); | 117 manager->ClearAll(id); |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 // static. | 121 // static. |
122 void AppEventRouter::DispatchOnLaunchedEvent( | 122 void AppEventRouter::DispatchOnLaunchedEvent( |
123 Profile* profile, const Extension* extension) { | 123 Profile* profile, const Extension* extension) { |
124 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 124 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
125 extension->id(), kOnLaunchedEvent, "[]", NULL, GURL()); | 125 extension->id(), kOnLaunchedEvent, NULL, NULL, GURL()); |
126 } | 126 } |
127 | 127 |
128 // static. | 128 // static. |
129 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 129 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
130 Profile* profile, const Extension* extension, const string16& action, | 130 Profile* profile, const Extension* extension, const string16& action, |
131 const std::string& file_system_id, const FilePath& base_name) { | 131 const std::string& file_system_id, const FilePath& base_name) { |
132 ListValue args; | 132 ListValue* args = new ListValue(); |
133 DictionaryValue* launch_data = new DictionaryValue(); | 133 DictionaryValue* launch_data = new DictionaryValue(); |
134 DictionaryValue* intent = new DictionaryValue(); | 134 DictionaryValue* intent = new DictionaryValue(); |
135 intent->SetString("action", UTF16ToUTF8(action)); | 135 intent->SetString("action", UTF16ToUTF8(action)); |
136 intent->SetString("type", "chrome-extension://fileentry"); | 136 intent->SetString("type", "chrome-extension://fileentry"); |
137 launch_data->Set("intent", intent); | 137 launch_data->Set("intent", intent); |
138 args.Append(launch_data); | 138 args->Append(launch_data); |
139 DictionaryValue* intent_data = new DictionaryValue(); | 139 DictionaryValue* intent_data = new DictionaryValue(); |
140 intent_data->SetString("format", "fileEntry"); | 140 intent_data->SetString("format", "fileEntry"); |
141 intent_data->SetString("fileSystemId", file_system_id); | 141 intent_data->SetString("fileSystemId", file_system_id); |
142 intent_data->SetString("baseName", base_name.value()); | 142 intent_data->SetString("baseName", base_name.value()); |
143 args.Append(intent_data); | 143 args->Append(intent_data); |
144 std::string json_args; | |
145 base::JSONWriter::Write(&args, &json_args); | |
146 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 144 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
147 extension->id(), kOnLaunchedEvent, json_args, NULL, GURL()); | 145 extension->id(), kOnLaunchedEvent, args, NULL, GURL()); |
148 } | 146 } |
149 | 147 |
150 // static. | 148 // static. |
151 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 149 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
152 Profile* profile, const Extension* extension, | 150 Profile* profile, const Extension* extension, |
153 const webkit_glue::WebIntentData web_intent_data) { | 151 const webkit_glue::WebIntentData web_intent_data) { |
154 ListValue args; | 152 ListValue* args = new ListValue(); |
155 DictionaryValue* launch_data = new DictionaryValue(); | 153 DictionaryValue* launch_data = new DictionaryValue(); |
156 DictionaryValue* intent = new DictionaryValue(); | 154 DictionaryValue* intent = new DictionaryValue(); |
157 intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); | 155 intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); |
158 intent->SetString("type", UTF16ToUTF8(web_intent_data.type)); | 156 intent->SetString("type", UTF16ToUTF8(web_intent_data.type)); |
159 launch_data->Set("intent", intent); | 157 launch_data->Set("intent", intent); |
160 args.Append(launch_data); | 158 args->Append(launch_data); |
161 DictionaryValue* intent_data; | 159 DictionaryValue* intent_data; |
162 switch (web_intent_data.data_type) { | 160 switch (web_intent_data.data_type) { |
163 case webkit_glue::WebIntentData::SERIALIZED: | 161 case webkit_glue::WebIntentData::SERIALIZED: |
164 intent_data = new DictionaryValue(); | 162 intent_data = new DictionaryValue(); |
165 intent_data->SetString("format", "serialized"); | 163 intent_data->SetString("format", "serialized"); |
166 intent_data->SetString("data", UTF16ToUTF8(web_intent_data.data)); | 164 intent_data->SetString("data", UTF16ToUTF8(web_intent_data.data)); |
167 args.Append(intent_data); | 165 args->Append(intent_data); |
168 break; | 166 break; |
169 case webkit_glue::WebIntentData::UNSERIALIZED: | 167 case webkit_glue::WebIntentData::UNSERIALIZED: |
170 intent->SetString("data", UTF16ToUTF8(web_intent_data.unserialized_data)); | 168 intent->SetString("data", UTF16ToUTF8(web_intent_data.unserialized_data)); |
171 break; | 169 break; |
172 case webkit_glue::WebIntentData::BLOB: | 170 case webkit_glue::WebIntentData::BLOB: |
173 intent_data = new DictionaryValue(); | 171 intent_data = new DictionaryValue(); |
174 intent_data->SetString("format", "blob"); | 172 intent_data->SetString("format", "blob"); |
175 intent_data->SetString("blobFileName", web_intent_data.blob_file.value()); | 173 intent_data->SetString("blobFileName", web_intent_data.blob_file.value()); |
176 intent_data->SetString("blobLength", | 174 intent_data->SetString("blobLength", |
177 base::Int64ToString(web_intent_data.blob_length)); | 175 base::Int64ToString(web_intent_data.blob_length)); |
178 args.Append(intent_data); | 176 args->Append(intent_data); |
179 break; | 177 break; |
180 default: | 178 default: |
181 NOTREACHED(); | 179 NOTREACHED(); |
182 break; | 180 break; |
183 } | 181 } |
184 std::string json_args; | |
185 base::JSONWriter::Write(&args, &json_args); | |
186 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 182 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
187 extension->id(), kOnLaunchedEvent, json_args, NULL, GURL()); | 183 extension->id(), kOnLaunchedEvent, args, NULL, GURL()); |
188 } | 184 } |
189 | 185 |
190 } // namespace extensions | 186 } // namespace extensions |
OLD | NEW |