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