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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 launch_data->Set("items", items); | 87 launch_data->Set("items", items); |
88 args->Append(launch_data); | 88 args->Append(launch_data); |
89 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); | 89 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); |
90 } | 90 } |
91 | 91 |
92 // static. | 92 // static. |
93 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 93 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
94 Profile* profile, const Extension* extension, | 94 Profile* profile, const Extension* extension, |
95 content::WebIntentsDispatcher* intents_dispatcher, | 95 content::WebIntentsDispatcher* intents_dispatcher, |
96 content::WebContents* source) { | 96 content::WebContents* source) { |
| 97 #if defined(ENABLE_WEB_INTENTS) |
97 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); | 98 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); |
98 scoped_ptr<ListValue> args(new ListValue()); | 99 scoped_ptr<ListValue> args(new ListValue()); |
99 DictionaryValue* launch_data = new DictionaryValue(); | 100 DictionaryValue* launch_data = new DictionaryValue(); |
100 DictionaryValue* intent = new DictionaryValue(); | 101 DictionaryValue* intent = new DictionaryValue(); |
101 intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); | 102 intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); |
102 intent->SetString("type", UTF16ToUTF8(web_intent_data.type)); | 103 intent->SetString("type", UTF16ToUTF8(web_intent_data.type)); |
103 launch_data->Set("intent", intent); | 104 launch_data->Set("intent", intent); |
104 args->Append(launch_data); | 105 args->Append(launch_data); |
105 DictionaryValue* intent_data; | 106 DictionaryValue* intent_data; |
106 switch (web_intent_data.data_type) { | 107 switch (web_intent_data.data_type) { |
(...skipping 29 matching lines...) Expand all Loading... |
136 default: | 137 default: |
137 NOTREACHED(); | 138 NOTREACHED(); |
138 break; | 139 break; |
139 } | 140 } |
140 DCHECK(args->GetSize() == 2); // intent_id must be our third argument. | 141 DCHECK(args->GetSize() == 2); // intent_id must be our third argument. |
141 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); | 142 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); |
142 int intent_id = | 143 int intent_id = |
143 callbacks->RegisterCallback(extension, intents_dispatcher, source); | 144 callbacks->RegisterCallback(extension, intents_dispatcher, source); |
144 args->Append(base::Value::CreateIntegerValue(intent_id)); | 145 args->Append(base::Value::CreateIntegerValue(intent_id)); |
145 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); | 146 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); |
| 147 #endif |
146 } | 148 } |
147 | 149 |
148 bool AppRuntimePostIntentResponseFunction::RunImpl() { | 150 bool AppRuntimePostIntentResponseFunction::RunImpl() { |
| 151 #if defined(ENABLE_WEB_INTENTS) |
149 DictionaryValue* details = NULL; | 152 DictionaryValue* details = NULL; |
150 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 153 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
151 | 154 |
152 int intent_id = 0; | 155 int intent_id = 0; |
153 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); | 156 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); |
154 | 157 |
155 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); | 158 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); |
156 content::WebIntentsDispatcher* intents_dispatcher = | 159 content::WebIntentsDispatcher* intents_dispatcher = |
157 callbacks->RetrieveCallback(GetExtension(), intent_id); | 160 callbacks->RetrieveCallback(GetExtension(), intent_id); |
158 if (!intents_dispatcher) { | 161 if (!intents_dispatcher) { |
159 error_ = kCallbackNotFoundError; | 162 error_ = kCallbackNotFoundError; |
160 return false; | 163 return false; |
161 } | 164 } |
162 | 165 |
163 webkit_glue::WebIntentReplyType reply_type = | 166 webkit_glue::WebIntentReplyType reply_type = |
164 webkit_glue::WEB_INTENT_REPLY_FAILURE; | 167 webkit_glue::WEB_INTENT_REPLY_FAILURE; |
165 bool success; | 168 bool success; |
166 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIntentSuccessKey, &success)); | 169 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIntentSuccessKey, &success)); |
167 if (success) | 170 if (success) |
168 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; | 171 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; |
169 | 172 |
170 std::string data; | 173 std::string data; |
171 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); | 174 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); |
172 | 175 |
173 intents_dispatcher->SendReply(webkit_glue::WebIntentReply( | 176 intents_dispatcher->SendReply(webkit_glue::WebIntentReply( |
174 reply_type, UTF8ToUTF16(data))); | 177 reply_type, UTF8ToUTF16(data))); |
175 | 178 |
176 return true; | 179 return true; |
| 180 #else |
| 181 return false; |
| 182 #endif |
177 } | 183 } |
178 | 184 |
179 } // namespace extensions | 185 } // namespace extensions |
OLD | NEW |