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_runtime/app_runtime_api.h" | 5 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/event_router.h" | 12 #include "chrome/browser/extensions/event_router.h" |
13 #include "chrome/browser/extensions/web_intent_callbacks.h" | 13 #include "chrome/browser/extensions/web_intent_callbacks.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_intents_dispatcher.h" | 17 #include "content/public/browser/web_intents_dispatcher.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "webkit/glue/web_intent_data.h" | 19 #include "webkit/glue/web_intent_data.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char kIntentIdKey[] = "intentId"; | 23 const char kIntentIdKey[] = "intentId"; |
24 const char kIntentSuccessKey[] = "success"; | 24 const char kIntentSuccessKey[] = "success"; |
25 const char kIntentDataKey[] = "data"; | 25 const char kIntentDataKey[] = "data"; |
26 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; | 26 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; |
| 27 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; |
27 | 28 |
28 const char kCallbackNotFoundError[] = | 29 const char kCallbackNotFoundError[] = |
29 "WebIntent callback not found; perhaps already responded to"; | 30 "WebIntent callback not found; perhaps already responded to"; |
30 | 31 |
31 } // anonymous namespace | 32 } // anonymous namespace |
32 | 33 |
33 namespace extensions { | 34 namespace extensions { |
34 | 35 |
35 // static. | 36 // static. |
36 void AppEventRouter::DispatchOnLaunchedEvent( | 37 void AppEventRouter::DispatchOnLaunchedEvent( |
37 Profile* profile, const Extension* extension) { | 38 Profile* profile, const Extension* extension) { |
38 scoped_ptr<ListValue> arguments(new ListValue()); | 39 scoped_ptr<ListValue> arguments(new ListValue()); |
39 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 40 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
40 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); | 41 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); |
41 } | 42 } |
42 | 43 |
43 // static. | 44 // static. |
| 45 void AppEventRouter::DispatchOnRestartedEvent( |
| 46 Profile* profile, const Extension* extension) { |
| 47 scoped_ptr<ListValue> arguments(new ListValue()); |
| 48 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 49 extension->id(), kOnRestartedEvent, arguments.Pass(), NULL, GURL()); |
| 50 } |
| 51 |
| 52 // static. |
44 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 53 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
45 Profile* profile, const Extension* extension, const string16& action, | 54 Profile* profile, const Extension* extension, const string16& action, |
46 const std::string& file_system_id, const std::string& base_name) { | 55 const std::string& file_system_id, const std::string& base_name) { |
47 scoped_ptr<ListValue> args(new ListValue()); | 56 scoped_ptr<ListValue> args(new ListValue()); |
48 DictionaryValue* launch_data = new DictionaryValue(); | 57 DictionaryValue* launch_data = new DictionaryValue(); |
49 DictionaryValue* intent = new DictionaryValue(); | 58 DictionaryValue* intent = new DictionaryValue(); |
50 intent->SetString("action", UTF16ToUTF8(action)); | 59 intent->SetString("action", UTF16ToUTF8(action)); |
51 intent->SetString("type", "chrome-extension://fileentry"); | 60 intent->SetString("type", "chrome-extension://fileentry"); |
52 launch_data->Set("intent", intent); | 61 launch_data->Set("intent", intent); |
53 args->Append(launch_data); | 62 args->Append(launch_data); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; | 151 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; |
143 | 152 |
144 std::string data; | 153 std::string data; |
145 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); | 154 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); |
146 | 155 |
147 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); | 156 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); |
148 return true; | 157 return true; |
149 } | 158 } |
150 | 159 |
151 } // namespace extensions | 160 } // namespace extensions |
OLD | NEW |