| 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/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/web_intent_callbacks.h" | 14 #include "chrome/browser/extensions/web_intent_callbacks.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_intents_dispatcher.h" | 18 #include "content/public/browser/web_intents_dispatcher.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "webkit/glue/web_intent_data.h" | 20 #include "webkit/glue/web_intent_data.h" |
| 21 | 21 |
| 22 namespace extensions { |
| 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 const char kIntentIdKey[] = "intentId"; | 26 const char kIntentIdKey[] = "intentId"; |
| 25 const char kIntentSuccessKey[] = "success"; | 27 const char kIntentSuccessKey[] = "success"; |
| 26 const char kIntentDataKey[] = "data"; | 28 const char kIntentDataKey[] = "data"; |
| 27 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; | 29 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; |
| 28 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; | 30 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; |
| 29 | 31 |
| 30 const char kCallbackNotFoundError[] = | 32 const char kCallbackNotFoundError[] = |
| 31 "WebIntent callback not found; perhaps already responded to"; | 33 "WebIntent callback not found; perhaps already responded to"; |
| 32 | 34 |
| 33 void DispatchOnLaunchedEventImpl(const std::string& extension_id, | 35 void DispatchOnLaunchedEventImpl(const std::string& extension_id, |
| 34 scoped_ptr<base::ListValue> args, | 36 scoped_ptr<base::ListValue> args, |
| 35 Profile* profile) { | 37 Profile* profile) { |
| 36 extensions::ExtensionSystem* system = | 38 extensions::ExtensionSystem* system = |
| 37 extensions::ExtensionSystem::Get(profile); | 39 extensions::ExtensionSystem::Get(profile); |
| 38 // Special case: normally, extensions add their own lazy event listeners. | 40 // Special case: normally, extensions add their own lazy event listeners. |
| 39 // However, since the extension might have just been enabled, it hasn't had a | 41 // However, since the extension might have just been enabled, it hasn't had a |
| 40 // chance to register for events. So we register on its behalf. If the | 42 // chance to register for events. So we register on its behalf. If the |
| 41 // extension does not actually have a listener, the event will just be | 43 // extension does not actually have a listener, the event will just be |
| 42 // ignored (but an app that doesn't listen for the onLaunched event doesn't | 44 // ignored (but an app that doesn't listen for the onLaunched event doesn't |
| 43 // make sense anyway). | 45 // make sense anyway). |
| 44 system->event_router()->AddLazyEventListener(kOnLaunchedEvent, extension_id); | 46 system->event_router()->AddLazyEventListener(kOnLaunchedEvent, extension_id); |
| 45 system->event_router()->DispatchEventToExtension( | 47 scoped_ptr<Event> event(new Event(kOnLaunchedEvent, args.Pass())); |
| 46 extension_id, kOnLaunchedEvent, args.Pass(), profile, GURL()); | 48 event->restrict_to_profile = profile; |
| 49 system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); |
| 47 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent, | 50 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent, |
| 48 extension_id); | 51 extension_id); |
| 49 } | 52 } |
| 50 | 53 |
| 51 } // anonymous namespace | 54 } // anonymous namespace |
| 52 | 55 |
| 53 namespace extensions { | |
| 54 | |
| 55 // static. | 56 // static. |
| 56 void AppEventRouter::DispatchOnLaunchedEvent( | 57 void AppEventRouter::DispatchOnLaunchedEvent( |
| 57 Profile* profile, const Extension* extension) { | 58 Profile* profile, const Extension* extension) { |
| 58 scoped_ptr<ListValue> arguments(new ListValue()); | 59 scoped_ptr<ListValue> arguments(new ListValue()); |
| 59 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); | 60 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // static. | 63 // static. |
| 63 void AppEventRouter::DispatchOnRestartedEvent( | 64 void AppEventRouter::DispatchOnRestartedEvent( |
| 64 Profile* profile, const Extension* extension) { | 65 Profile* profile, const Extension* extension) { |
| 65 scoped_ptr<ListValue> arguments(new ListValue()); | 66 scoped_ptr<ListValue> arguments(new ListValue()); |
| 67 scoped_ptr<Event> event(new Event(kOnRestartedEvent, arguments.Pass())); |
| 68 event->restrict_to_profile = profile; |
| 66 extensions::ExtensionSystem::Get(profile)->event_router()-> | 69 extensions::ExtensionSystem::Get(profile)->event_router()-> |
| 67 DispatchEventToExtension(extension->id(), kOnRestartedEvent, | 70 DispatchEventToExtension(extension->id(), event.Pass()); |
| 68 arguments.Pass(), profile, GURL()); | |
| 69 } | 71 } |
| 70 | 72 |
| 71 // static. | 73 // static. |
| 72 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 74 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| 73 Profile* profile, const Extension* extension, const string16& action, | 75 Profile* profile, const Extension* extension, const string16& action, |
| 74 const std::string& handler_id, const std::string& mime_type, | 76 const std::string& handler_id, const std::string& mime_type, |
| 75 const std::string& file_system_id, const std::string& base_name) { | 77 const std::string& file_system_id, const std::string& base_name) { |
| 76 scoped_ptr<ListValue> args(new ListValue()); | 78 scoped_ptr<ListValue> args(new ListValue()); |
| 77 DictionaryValue* launch_data = new DictionaryValue(); | 79 DictionaryValue* launch_data = new DictionaryValue(); |
| 78 launch_data->SetString("id", handler_id); | 80 launch_data->SetString("id", handler_id); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 std::string data; | 170 std::string data; |
| 169 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); | 171 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); |
| 170 | 172 |
| 171 intents_dispatcher->SendReply(webkit_glue::WebIntentReply( | 173 intents_dispatcher->SendReply(webkit_glue::WebIntentReply( |
| 172 reply_type, UTF8ToUTF16(data))); | 174 reply_type, UTF8ToUTF16(data))); |
| 173 | 175 |
| 174 return true; | 176 return true; |
| 175 } | 177 } |
| 176 | 178 |
| 177 } // namespace extensions | 179 } // namespace extensions |
| OLD | NEW |