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/web_intent_callbacks.h" | 14 #include "chrome/browser/extensions/web_intent_callbacks.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_intents_dispatcher.h" | 18 #include "content/public/browser/web_intents_dispatcher.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "webkit/glue/web_intent_data.h" | 20 #include "webkit/glue/web_intent_data.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const char kIntentIdKey[] = "intentId"; | 24 const char kIntentIdKey[] = "intentId"; |
24 const char kIntentSuccessKey[] = "success"; | 25 const char kIntentSuccessKey[] = "success"; |
25 const char kIntentDataKey[] = "data"; | 26 const char kIntentDataKey[] = "data"; |
26 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; | 27 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; |
27 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; | 28 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; |
28 | 29 |
29 const char kCallbackNotFoundError[] = | 30 const char kCallbackNotFoundError[] = |
30 "WebIntent callback not found; perhaps already responded to"; | 31 "WebIntent callback not found; perhaps already responded to"; |
31 | 32 |
32 } // anonymous namespace | 33 } // anonymous namespace |
33 | 34 |
34 namespace extensions { | 35 namespace extensions { |
35 | 36 |
36 // static. | 37 // static. |
37 void AppEventRouter::DispatchOnLaunchedEvent( | 38 void AppEventRouter::DispatchOnLaunchedEvent( |
38 Profile* profile, const Extension* extension) { | 39 Profile* profile, const Extension* extension) { |
39 scoped_ptr<ListValue> arguments(new ListValue()); | 40 scoped_ptr<ListValue> arguments(new ListValue()); |
40 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 41 extensions::ExtensionSystem::Get(profile)->event_router()-> |
41 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); | 42 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, |
| 43 arguments.Pass(), NULL, GURL()); |
42 } | 44 } |
43 | 45 |
44 // static. | 46 // static. |
45 void AppEventRouter::DispatchOnRestartedEvent( | 47 void AppEventRouter::DispatchOnRestartedEvent( |
46 Profile* profile, const Extension* extension) { | 48 Profile* profile, const Extension* extension) { |
47 scoped_ptr<ListValue> arguments(new ListValue()); | 49 scoped_ptr<ListValue> arguments(new ListValue()); |
48 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 50 extensions::ExtensionSystem::Get(profile)->event_router()-> |
49 extension->id(), kOnRestartedEvent, arguments.Pass(), NULL, GURL()); | 51 DispatchEventToExtension(extension->id(), kOnRestartedEvent, |
| 52 arguments.Pass(), NULL, GURL()); |
50 } | 53 } |
51 | 54 |
52 // static. | 55 // static. |
53 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 56 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
54 Profile* profile, const Extension* extension, const string16& action, | 57 Profile* profile, const Extension* extension, const string16& action, |
55 const std::string& file_system_id, const std::string& base_name) { | 58 const std::string& file_system_id, const std::string& base_name) { |
56 scoped_ptr<ListValue> args(new ListValue()); | 59 scoped_ptr<ListValue> args(new ListValue()); |
57 DictionaryValue* launch_data = new DictionaryValue(); | 60 DictionaryValue* launch_data = new DictionaryValue(); |
58 DictionaryValue* intent = new DictionaryValue(); | 61 DictionaryValue* intent = new DictionaryValue(); |
59 intent->SetString("action", UTF16ToUTF8(action)); | 62 intent->SetString("action", UTF16ToUTF8(action)); |
60 intent->SetString("type", "chrome-extension://fileentry"); | 63 intent->SetString("type", "chrome-extension://fileentry"); |
61 launch_data->Set("intent", intent); | 64 launch_data->Set("intent", intent); |
62 args->Append(launch_data); | 65 args->Append(launch_data); |
63 DictionaryValue* intent_data = new DictionaryValue(); | 66 DictionaryValue* intent_data = new DictionaryValue(); |
64 intent_data->SetString("format", "fileEntry"); | 67 intent_data->SetString("format", "fileEntry"); |
65 intent_data->SetString("fileSystemId", file_system_id); | 68 intent_data->SetString("fileSystemId", file_system_id); |
66 intent_data->SetString("baseName", base_name); | 69 intent_data->SetString("baseName", base_name); |
67 // NOTE: This second argument is dropped before being dispatched to the client | 70 // NOTE: This second argument is dropped before being dispatched to the client |
68 // code. | 71 // code. |
69 args->Append(intent_data); | 72 args->Append(intent_data); |
70 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 73 extensions::ExtensionSystem::Get(profile)->event_router()-> |
71 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); | 74 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(), |
| 75 NULL, GURL()); |
72 } | 76 } |
73 | 77 |
74 // static. | 78 // static. |
75 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 79 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
76 Profile* profile, const Extension* extension, | 80 Profile* profile, const Extension* extension, |
77 content::WebIntentsDispatcher* intents_dispatcher, | 81 content::WebIntentsDispatcher* intents_dispatcher, |
78 content::WebContents* source) { | 82 content::WebContents* source) { |
79 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); | 83 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); |
80 scoped_ptr<ListValue> args(new ListValue()); | 84 scoped_ptr<ListValue> args(new ListValue()); |
81 DictionaryValue* launch_data = new DictionaryValue(); | 85 DictionaryValue* launch_data = new DictionaryValue(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 break; | 121 break; |
118 default: | 122 default: |
119 NOTREACHED(); | 123 NOTREACHED(); |
120 break; | 124 break; |
121 } | 125 } |
122 DCHECK(args->GetSize() == 2); // intent_id must be our third argument. | 126 DCHECK(args->GetSize() == 2); // intent_id must be our third argument. |
123 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); | 127 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); |
124 int intent_id = | 128 int intent_id = |
125 callbacks->RegisterCallback(extension, intents_dispatcher, source); | 129 callbacks->RegisterCallback(extension, intents_dispatcher, source); |
126 args->Append(base::Value::CreateIntegerValue(intent_id)); | 130 args->Append(base::Value::CreateIntegerValue(intent_id)); |
127 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 131 extensions::ExtensionSystem::Get(profile)->event_router()-> |
128 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); | 132 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(), |
| 133 NULL, GURL()); |
129 } | 134 } |
130 | 135 |
131 bool AppRuntimePostIntentResponseFunction::RunImpl() { | 136 bool AppRuntimePostIntentResponseFunction::RunImpl() { |
132 DictionaryValue* details = NULL; | 137 DictionaryValue* details = NULL; |
133 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 138 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
134 | 139 |
135 int intent_id = 0; | 140 int intent_id = 0; |
136 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); | 141 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); |
137 | 142 |
138 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); | 143 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); |
(...skipping 12 matching lines...) Expand all Loading... |
151 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; | 156 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; |
152 | 157 |
153 std::string data; | 158 std::string data; |
154 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); | 159 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); |
155 | 160 |
156 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); | 161 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); |
157 return true; | 162 return true; |
158 } | 163 } |
159 | 164 |
160 } // namespace extensions | 165 } // namespace extensions |
OLD | NEW |