| 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"; | |
| 28 | 27 |
| 29 const char kCallbackNotFoundError[] = | 28 const char kCallbackNotFoundError[] = |
| 30 "WebIntent callback not found; perhaps already responded to"; | 29 "WebIntent callback not found; perhaps already responded to"; |
| 31 | 30 |
| 32 } // anonymous namespace | 31 } // anonymous namespace |
| 33 | 32 |
| 34 namespace extensions { | 33 namespace extensions { |
| 35 | 34 |
| 36 // static. | 35 // static. |
| 37 void AppEventRouter::DispatchOnLaunchedEvent( | 36 void AppEventRouter::DispatchOnLaunchedEvent( |
| 38 Profile* profile, const Extension* extension) { | 37 Profile* profile, const Extension* extension) { |
| 39 scoped_ptr<ListValue> arguments(new ListValue()); | 38 scoped_ptr<ListValue> arguments(new ListValue()); |
| 40 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 39 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 41 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); | 40 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); |
| 42 } | 41 } |
| 43 | 42 |
| 44 // static. | 43 // 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. | |
| 53 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 44 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| 54 Profile* profile, const Extension* extension, const string16& action, | 45 Profile* profile, const Extension* extension, const string16& action, |
| 55 const std::string& file_system_id, const std::string& base_name) { | 46 const std::string& file_system_id, const std::string& base_name) { |
| 56 scoped_ptr<ListValue> args(new ListValue()); | 47 scoped_ptr<ListValue> args(new ListValue()); |
| 57 DictionaryValue* launch_data = new DictionaryValue(); | 48 DictionaryValue* launch_data = new DictionaryValue(); |
| 58 DictionaryValue* intent = new DictionaryValue(); | 49 DictionaryValue* intent = new DictionaryValue(); |
| 59 intent->SetString("action", UTF16ToUTF8(action)); | 50 intent->SetString("action", UTF16ToUTF8(action)); |
| 60 intent->SetString("type", "chrome-extension://fileentry"); | 51 intent->SetString("type", "chrome-extension://fileentry"); |
| 61 launch_data->Set("intent", intent); | 52 launch_data->Set("intent", intent); |
| 62 args->Append(launch_data); | 53 args->Append(launch_data); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; | 142 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; |
| 152 | 143 |
| 153 std::string data; | 144 std::string data; |
| 154 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); | 145 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); |
| 155 | 146 |
| 156 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); | 147 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); |
| 157 return true; | 148 return true; |
| 158 } | 149 } |
| 159 | 150 |
| 160 } // namespace extensions | 151 } // namespace extensions |
| OLD | NEW |