Chromium Code Reviews| 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" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 const char kIntentIdKey[] = "intentId"; | 24 const char kIntentIdKey[] = "intentId"; |
| 25 const char kIntentSuccessKey[] = "success"; | 25 const char kIntentSuccessKey[] = "success"; |
| 26 const char kIntentDataKey[] = "data"; | 26 const char kIntentDataKey[] = "data"; |
| 27 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; | 27 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; |
| 28 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; | 28 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; |
| 29 | 29 |
| 30 const char kCallbackNotFoundError[] = | 30 const char kCallbackNotFoundError[] = |
| 31 "WebIntent callback not found; perhaps already responded to"; | 31 "WebIntent callback not found; perhaps already responded to"; |
| 32 | 32 |
| 33 void DispatchOnLaunchedEventImpl(const std::string& extension_id, | |
| 34 scoped_ptr<base::ListValue> args, | |
| 35 Profile* profile) { | |
| 36 extensions::ExtensionSystem* system = | |
| 37 extensions::ExtensionSystem::Get(profile); | |
| 38 system->event_router()->AddLazyEventListener(kOnLaunchedEvent, extension_id); | |
|
Matt Perry
2012/11/29 22:03:21
add a comment explaining why this is necessary
Marijn Kruisselbrink
2012/11/30 00:51:20
Done.
| |
| 39 system->event_router()->DispatchEventToExtension( | |
| 40 extension_id, kOnLaunchedEvent, args.Pass(), profile, GURL()); | |
| 41 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent, | |
| 42 extension_id); | |
| 43 } | |
| 44 | |
| 33 } // anonymous namespace | 45 } // anonymous namespace |
| 34 | 46 |
| 35 namespace extensions { | 47 namespace extensions { |
| 36 | 48 |
| 37 // static. | 49 // static. |
| 38 void AppEventRouter::DispatchOnLaunchedEvent( | 50 void AppEventRouter::DispatchOnLaunchedEvent( |
| 39 Profile* profile, const Extension* extension) { | 51 Profile* profile, const Extension* extension) { |
| 40 scoped_ptr<ListValue> arguments(new ListValue()); | 52 scoped_ptr<ListValue> arguments(new ListValue()); |
| 41 extensions::ExtensionSystem::Get(profile)->event_router()-> | 53 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); |
| 42 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, | |
| 43 arguments.Pass(), profile, GURL()); | |
| 44 } | 54 } |
| 45 | 55 |
| 46 // static. | 56 // static. |
| 47 void AppEventRouter::DispatchOnRestartedEvent( | 57 void AppEventRouter::DispatchOnRestartedEvent( |
| 48 Profile* profile, const Extension* extension) { | 58 Profile* profile, const Extension* extension) { |
| 49 scoped_ptr<ListValue> arguments(new ListValue()); | 59 scoped_ptr<ListValue> arguments(new ListValue()); |
| 50 extensions::ExtensionSystem::Get(profile)->event_router()-> | 60 extensions::ExtensionSystem::Get(profile)->event_router()-> |
| 51 DispatchEventToExtension(extension->id(), kOnRestartedEvent, | 61 DispatchEventToExtension(extension->id(), kOnRestartedEvent, |
| 52 arguments.Pass(), profile, GURL()); | 62 arguments.Pass(), profile, GURL()); |
| 53 } | 63 } |
| 54 | 64 |
| 55 // static. | 65 // static. |
| 56 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 66 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| 57 Profile* profile, const Extension* extension, const string16& action, | 67 Profile* profile, const Extension* extension, const string16& action, |
| 58 const std::string& handler_id, const std::string& mime_type, | 68 const std::string& handler_id, const std::string& mime_type, |
| 59 const std::string& file_system_id, const std::string& base_name) { | 69 const std::string& file_system_id, const std::string& base_name) { |
| 60 scoped_ptr<ListValue> args(new ListValue()); | 70 scoped_ptr<ListValue> args(new ListValue()); |
| 61 DictionaryValue* launch_data = new DictionaryValue(); | 71 DictionaryValue* launch_data = new DictionaryValue(); |
| 62 launch_data->SetString("id", handler_id); | 72 launch_data->SetString("id", handler_id); |
| 63 DictionaryValue* launch_item = new DictionaryValue; | 73 DictionaryValue* launch_item = new DictionaryValue; |
| 64 launch_item->SetString("fileSystemId", file_system_id); | 74 launch_item->SetString("fileSystemId", file_system_id); |
| 65 launch_item->SetString("baseName", base_name); | 75 launch_item->SetString("baseName", base_name); |
| 66 launch_item->SetString("mimeType", mime_type); | 76 launch_item->SetString("mimeType", mime_type); |
| 67 ListValue* items = new ListValue; | 77 ListValue* items = new ListValue; |
| 68 items->Append(launch_item); | 78 items->Append(launch_item); |
| 69 launch_data->Set("items", items); | 79 launch_data->Set("items", items); |
| 70 args->Append(launch_data); | 80 args->Append(launch_data); |
| 71 extensions::ExtensionSystem::Get(profile)->event_router()-> | 81 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); |
| 72 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(), | |
| 73 profile, GURL()); | |
| 74 } | 82 } |
| 75 | 83 |
| 76 // static. | 84 // static. |
| 77 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 85 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 78 Profile* profile, const Extension* extension, | 86 Profile* profile, const Extension* extension, |
| 79 content::WebIntentsDispatcher* intents_dispatcher, | 87 content::WebIntentsDispatcher* intents_dispatcher, |
| 80 content::WebContents* source) { | 88 content::WebContents* source) { |
| 81 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); | 89 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); |
| 82 scoped_ptr<ListValue> args(new ListValue()); | 90 scoped_ptr<ListValue> args(new ListValue()); |
| 83 DictionaryValue* launch_data = new DictionaryValue(); | 91 DictionaryValue* launch_data = new DictionaryValue(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 break; | 127 break; |
| 120 default: | 128 default: |
| 121 NOTREACHED(); | 129 NOTREACHED(); |
| 122 break; | 130 break; |
| 123 } | 131 } |
| 124 DCHECK(args->GetSize() == 2); // intent_id must be our third argument. | 132 DCHECK(args->GetSize() == 2); // intent_id must be our third argument. |
| 125 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); | 133 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); |
| 126 int intent_id = | 134 int intent_id = |
| 127 callbacks->RegisterCallback(extension, intents_dispatcher, source); | 135 callbacks->RegisterCallback(extension, intents_dispatcher, source); |
| 128 args->Append(base::Value::CreateIntegerValue(intent_id)); | 136 args->Append(base::Value::CreateIntegerValue(intent_id)); |
| 129 extensions::ExtensionSystem::Get(profile)->event_router()-> | 137 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); |
| 130 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(), | |
| 131 profile, GURL()); | |
| 132 } | 138 } |
| 133 | 139 |
| 134 bool AppRuntimePostIntentResponseFunction::RunImpl() { | 140 bool AppRuntimePostIntentResponseFunction::RunImpl() { |
| 135 DictionaryValue* details = NULL; | 141 DictionaryValue* details = NULL; |
| 136 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 142 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| 137 | 143 |
| 138 int intent_id = 0; | 144 int intent_id = 0; |
| 139 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); | 145 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); |
| 140 | 146 |
| 141 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); | 147 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 154 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; | 160 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; |
| 155 | 161 |
| 156 std::string data; | 162 std::string data; |
| 157 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); | 163 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); |
| 158 | 164 |
| 159 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); | 165 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); |
| 160 return true; | 166 return true; |
| 161 } | 167 } |
| 162 | 168 |
| 163 } // namespace extensions | 169 } // namespace extensions |
| OLD | NEW |